blob: 267233750f553d7a5ca6bf042a24ed2666c8c769 [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;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700190 // True if the hidden state of this token was forced to false due to a transferred starting
191 // window.
192 private boolean mHiddenSetFromTransferredStartingWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800193 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700194 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
195 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800196
197 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700198 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800199
Wale Ogunwale571771c2016-08-26 13:18:50 -0700200 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800201 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800202
Craig Mautnerbb742462014-07-07 15:28:55 -0700203 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700204 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700205
Wale Ogunwale72919d22016-12-08 18:58:50 -0800206 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800207
Robert Carre12aece2016-02-02 22:43:27 -0800208 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700209 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700210 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800211
Jorim Jaggife762342016-10-13 14:33:27 +0200212 private boolean mLastContainsShowWhenLockedWindow;
213 private boolean mLastContainsDismissKeyguardWindow;
214
Jorim Jaggi0429f352015-12-22 16:29:16 +0100215 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700216 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100217
Wale Ogunwale6c459212017-05-17 08:56:03 -0700218 private boolean mDisablePreviewScreenshots;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100219
Wale Ogunwale034a8ec2017-09-02 17:14:40 -0700220 private Task mLastParent;
Robert Carred3e83b2017-04-21 13:26:55 -0700221
chaviwd3bf08d2017-08-01 17:24:59 -0700222 /**
223 * See {@link #canTurnScreenOn()}
224 */
225 private boolean mCanTurnScreenOn = true;
226
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200227 /**
228 * If we are running an animation, this determines the transition type. Must be one of
229 * AppTransition.TRANSIT_* constants.
230 */
231 private int mTransit;
232
233 /**
234 * If we are running an animation, this determines the flags during this animation. Must be a
235 * bitwise combination of AppTransition.TRANSIT_FLAG_* constants.
236 */
237 private int mTransitFlags;
238
239 /** Whether our surface was set to be showing in the last call to {@link #prepareSurfaces} */
Jorim Jaggifd1891462017-12-29 15:41:36 +0100240 private boolean mLastSurfaceShowing = true;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200241
Jorim Jaggi988f6682017-11-17 17:46:43 +0100242 private AppWindowThumbnail mThumbnail;
243
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000244 /** Have we been asked to have this token keep the screen frozen? */
245 private boolean mFreezingScreen;
246
247 /** Whether this token should be boosted at the top of all app window tokens. */
248 private boolean mNeedsZBoost;
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100249 private Letterbox mLetterbox;
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000250
chaviw23ee71c2017-12-18 11:29:41 -0800251 private final Point mTmpPoint = new Point();
chaviw23012112017-12-20 15:29:04 -0800252 private final Rect mTmpRect = new Rect();
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100253 private RemoteAnimationDefinition mRemoteAnimationDefinition;
chaviw23ee71c2017-12-18 11:29:41 -0800254
Wale Ogunwale72919d22016-12-08 18:58:50 -0800255 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
256 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
257 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800258 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Bryce Leef3c6a472017-11-14 14:53:06 -0800259 AppWindowContainerController controller) {
260 this(service, token, voiceInteraction, dc, fullscreen);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800261 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800262 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800263 mShowForAllUsers = showForAllUsers;
264 mTargetSdk = targetSdk;
265 mOrientation = orientation;
266 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
267 mLaunchTaskBehind = launchTaskBehind;
268 mAlwaysFocusable = alwaysFocusable;
269 mRotationAnimationHint = rotationAnimationHint;
270
271 // Application tokens start out hidden.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200272 setHidden(true);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800273 hiddenRequested = true;
274 }
275
276 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Bryce Leef3c6a472017-11-14 14:53:06 -0800277 DisplayContent dc, boolean fillsParent) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800278 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
279 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700280 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800281 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800282 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800283 mInputApplicationHandle = new InputApplicationHandle(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800284 }
285
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800286 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
287 firstWindowDrawn = true;
288
289 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700290 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800291
Jorim Jaggi02886a82016-12-06 09:10:06 -0800292 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800293 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
294 + win.mToken + ": first real window is shown, no animation");
295 // If this initial window is animating, stop it -- we will do an animation to reveal
296 // it from behind the starting window, so there is no need for it to also be doing its
297 // own stuff.
Jorim Jaggia5e10572017-11-15 14:36:26 +0100298 win.cancelAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800299 if (getController() != null) {
300 getController().removeStartingWindow();
301 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800302 }
303 updateReportedVisibilityLocked();
304 }
305
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800306 void updateReportedVisibilityLocked() {
307 if (appToken == null) {
308 return;
309 }
310
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700311 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700312 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800313
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700314 mReportedVisibilityResults.reset();
315
316 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700317 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700318 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800319 }
320
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700321 int numInteresting = mReportedVisibilityResults.numInteresting;
322 int numVisible = mReportedVisibilityResults.numVisible;
323 int numDrawn = mReportedVisibilityResults.numDrawn;
324 boolean nowGone = mReportedVisibilityResults.nowGone;
325
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700326 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200327 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting && !isHidden();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700328 if (!nowGone) {
329 // If the app is not yet gone, then it can only become visible/drawn.
330 if (!nowDrawn) {
331 nowDrawn = reportedDrawn;
332 }
333 if (!nowVisible) {
334 nowVisible = reportedVisible;
335 }
336 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800337 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800338 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800339 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700340 if (nowDrawn != reportedDrawn) {
341 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800342 if (controller != null) {
343 controller.reportWindowsDrawn();
344 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700345 }
346 reportedDrawn = nowDrawn;
347 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800348 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700349 if (DEBUG_VISIBILITY) Slog.v(TAG,
350 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800351 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800352 if (controller != null) {
353 if (nowVisible) {
354 controller.reportWindowsVisible();
355 } else {
356 controller.reportWindowsGone();
357 }
358 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800359 }
360 }
361
Wale Ogunwale89973222017-04-23 18:39:45 -0700362 boolean isClientHidden() {
363 return mClientHidden;
364 }
365
366 void setClientHidden(boolean hideClient) {
367 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
368 return;
369 }
Jorim Jaggi067b5bf2018-02-23 17:42:39 +0100370 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setClientHidden: " + this
371 + " clientHidden=" + hideClient + " Callers=" + Debug.getCallers(5));
Wale Ogunwale89973222017-04-23 18:39:45 -0700372 mClientHidden = hideClient;
373 sendAppVisibilityToClients();
374 }
375
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700376 boolean setVisibility(WindowManager.LayoutParams lp,
377 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
378
379 boolean delayed = false;
380 inPendingTransaction = false;
Wale Ogunwale9e4721f2017-05-23 19:37:30 -0700381 // Reset the state of mHiddenSetFromTransferredStartingWindow since visibility is actually
382 // been set by the app now.
383 mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700384
385 // Allow for state changes and animation to be applied if:
386 // * token is transitioning visibility state
387 // * or the token was marked as hidden and is exiting before we had a chance to play the
388 // transition animation
389 // * or this is an opening app and windows are being replaced.
390 boolean visibilityChanged = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200391 if (isHidden() == visible || (isHidden() && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700392 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700393 boolean changed = false;
394 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200395 "Changing app " + this + " hidden=" + isHidden() + " performLayout=" + performLayout);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700396
397 boolean runningAppAnimation = false;
398
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100399 if (transit != WindowManager.TRANSIT_UNSET) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200400 if (applyAnimationLocked(lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700401 delayed = runningAppAnimation = true;
402 }
403 final WindowState window = findMainWindow();
404 //TODO (multidisplay): Magnification is supported only for the default display.
405 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700406 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700407 accessibilityController.onAppWindowTransitionLocked(window, transit);
408 }
409 changed = true;
410 }
411
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700412 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700413 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700414 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700415 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700416 }
417
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200418 setHidden(!visible);
419 hiddenRequested = !visible;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700420 visibilityChanged = true;
421 if (!visible) {
422 stopFreezingScreen(true, true);
423 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700424 // If we are being set visible, and the starting window is not yet displayed,
425 // then make sure it doesn't get displayed.
426 if (startingWindow != null && !startingWindow.isDrawnLw()) {
427 startingWindow.mPolicyVisibility = false;
428 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700429 }
Jorim Jaggi38d44ec2017-06-14 16:04:59 -0700430
431 // We are becoming visible, so better freeze the screen with the windows that are
432 // getting visible so we also wait for them.
433 forAllWindows(mService::makeWindowFreezingScreenIfNeededLocked, true);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700434 }
435
436 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200437 + ": hidden=" + isHidden() + " hiddenRequested=" + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700438
439 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700440 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700441 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700442 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700443 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700444 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700445 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700446 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700447 }
448 }
449
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200450 if (isReallyAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700451 delayed = true;
452 }
453
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700454 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Jorim Jaggia5e10572017-11-15 14:36:26 +0100455 if ((mChildren.get(i)).isSelfOrChildAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700456 delayed = true;
457 }
458 }
459
460 if (visibilityChanged) {
461 if (visible && !delayed) {
462 // The token was made immediately visible, there will be no entrance animation.
463 // We need to inform the client the enter animation was finished.
464 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700465 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700466 }
Robert Carr61b81112017-07-17 18:08:15 -0700467
Jorim Jaggi110839b2018-01-22 12:49:04 +0100468 // If we're becoming visible, immediately change client visibility as well although it
469 // usually gets changed in AppWindowContainerController.setVisibility already. However,
470 // there seem to be some edge cases where we change our visibility but client visibility
471 // never gets updated.
472 // If we're becoming invisible, update the client visibility if we are not running an
473 // animation. Otherwise, we'll update client visibility in onAnimationFinished.
Jorim Jaggi3cad57f2018-02-20 18:32:01 +0100474 if (visible || !isReallyAnimating()) {
Jorim Jaggi110839b2018-01-22 12:49:04 +0100475 setClientHidden(!visible);
Jorim Jaggi4876b4a2018-01-11 15:43:49 +0100476 }
477
chaviwa953fcf2018-03-01 12:00:39 -0800478 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
479 // The token is not closing nor opening, so even if there is an animation set, that
480 // doesn't mean that it goes through the normal app transition cycle so we have
481 // to inform the docked controller about visibility change.
482 // TODO(multi-display): notify docked divider on all displays where visibility was
483 // affected.
484 mService.getDefaultDisplayContentLocked().getDockedDividerController()
485 .notifyAppVisibilityChanged();
486
487 // Take the screenshot before possibly hiding the WSA, otherwise the screenshot
488 // will not be taken.
489 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
490 }
491
Robert Carre7cc44d2017-03-20 19:04:30 -0700492 // If we are hidden but there is no delay needed we immediately
493 // apply the Surface transaction so that the ActivityManager
Robert Carr61b81112017-07-17 18:08:15 -0700494 // can have some guarantee on the Surface state following
495 // setting the visibility. This captures cases like dismissing
496 // the docked or pinned stack where there is no app transition.
497 //
498 // In the case of a "Null" animation, there will be
499 // no animation but there will still be a transition set.
500 // We still need to delay hiding the surface such that it
501 // can be synchronized with showing the next surface in the transition.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200502 if (isHidden() && !delayed && !mService.mAppTransition.isTransitionSet()) {
Robert Carr6914f082017-03-20 19:04:30 -0700503 SurfaceControl.openTransaction();
504 for (int i = mChildren.size() - 1; i >= 0; i--) {
505 mChildren.get(i).mWinAnimator.hide("immediately hidden");
506 }
507 SurfaceControl.closeTransaction();
508 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700509 }
510
511 return delayed;
512 }
513
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +0200514 /**
515 * @return The to top most child window for which {@link LayoutParams#isFullscreen()} returns
516 * true.
517 */
518 WindowState getTopFullscreenWindow() {
519 for (int i = mChildren.size() - 1; i >= 0; i--) {
520 final WindowState win = mChildren.get(i);
521 if (win != null && win.mAttrs.isFullscreen()) {
522 return win;
523 }
524 }
525 return null;
526 }
527
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800528 WindowState findMainWindow() {
Matthew Ng53e66b22018-01-12 17:13:13 -0800529 return findMainWindow(true);
530 }
531
532 /**
533 * Finds the main window that either has type base application or application starting if
534 * requested.
535 *
536 * @param includeStartingApp Allow to search application-starting windows to also be returned.
537 * @return The main window of type base application or application starting if requested.
538 */
539 WindowState findMainWindow(boolean includeStartingApp) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700540 WindowState candidate = null;
Matthew Ng53e66b22018-01-12 17:13:13 -0800541 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700542 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700543 final int type = win.mAttrs.type;
544 // No need to loop through child window as base application and starting types can't be
545 // child windows.
Matthew Ng53e66b22018-01-12 17:13:13 -0800546 if (type == TYPE_BASE_APPLICATION
547 || (includeStartingApp && type == TYPE_APPLICATION_STARTING)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700548 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900549 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700550 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800551 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700552 candidate = win;
553 } else {
554 return win;
555 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800556 }
557 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700558 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800559 }
560
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800561 boolean windowsAreFocusable() {
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700562 return getWindowConfiguration().canReceiveKeys() || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800563 }
564
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800565 AppWindowContainerController getController() {
566 final WindowContainerController controller = super.getController();
567 return controller != null ? (AppWindowContainerController) controller : null;
568 }
569
Wale Ogunwale571771c2016-08-26 13:18:50 -0700570 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700571 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700572 // If the app token isn't hidden then it is considered visible and there is no need to check
573 // its children windows to see if they are visible.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200574 return !isHidden();
Wale Ogunwale44f21802016-09-02 12:49:48 -0700575 }
576
577 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700578 void removeImmediately() {
579 onRemovedFromDisplay();
580 super.removeImmediately();
581 }
582
583 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700584 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800585 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800586 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800587 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800588 }
589
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700590 @Override
591 boolean checkCompleteDeferredRemoval() {
592 if (mIsExiting) {
593 removeIfPossible();
594 }
595 return super.checkCompleteDeferredRemoval();
596 }
597
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700598 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700599 if (mRemovingFromDisplay) {
600 return;
601 }
602 mRemovingFromDisplay = true;
603
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700604 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
605
Wale Ogunwale72919d22016-12-08 18:58:50 -0800606 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700607
608 mService.mOpeningApps.remove(this);
Jorim Jaggi45ca0542017-05-30 16:16:01 -0700609 mService.mUnknownAppVisibilityController.appRemovedOrHidden(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100610 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700611 waitingToShow = false;
612 if (mService.mClosingApps.contains(this)) {
613 delayed = true;
614 } else if (mService.mAppTransition.isTransitionSet()) {
615 mService.mClosingApps.add(this);
616 delayed = true;
617 }
618
619 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200620 + " animation=" + getAnimation() + " animating=" + isSelfAnimating());
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700621
622 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
623 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
624
Jorim Jaggi19be6052017-08-03 18:33:43 +0200625 if (startingData != null && getController() != null) {
626 getController().removeStartingWindow();
627 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800628
Winson Chung87e5d552017-04-05 11:49:38 -0700629 // If this window was animating, then we need to ensure that the app transition notifies
630 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
631 // add to that list now
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200632 if (isSelfAnimating()) {
Winson Chung87e5d552017-04-05 11:49:38 -0700633 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
634 }
635
Wale Ogunwalee287e192017-04-21 09:30:12 -0700636 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700637 if (delayed && !isEmpty()) {
638 // set the token aside because it has an active animation to be finished
639 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
640 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700641 if (stack != null) {
642 stack.mExitingAppTokens.add(this);
643 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700644 mIsExiting = true;
645 } else {
646 // Make sure there is no animation running on this token, so any windows associated
647 // with it will be removed as soon as their animations are complete
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200648 cancelAnimation();
Wale Ogunwale3106ae012017-05-16 08:56:37 -0700649 if (stack != null) {
650 stack.mExitingAppTokens.remove(this);
651 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700652 removeIfPossible();
653 }
654
655 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700656 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800657
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700658 if (mService.mFocusedApp == this) {
659 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
660 mService.mFocusedApp = null;
661 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
662 mService.mInputMonitor.setFocusedAppLw(null);
663 }
664
665 if (!delayed) {
666 updateReportedVisibilityLocked();
667 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700668
669 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700670 }
671
Chong Zhange05bcb12016-07-26 17:47:29 -0700672 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700673 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700674 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700675 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700676 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700677 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700678 if (wallpaperMightChange) {
679 requestUpdateWallpaperIfNeeded();
680 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700681 }
682
Robert Carre12aece2016-02-02 22:43:27 -0800683 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700684 destroySurfaces(false /*cleanupOnResume*/);
685 }
686
687 /**
688 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
689 * the client has finished with them.
690 *
691 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
692 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
693 * others so that they are ready to be reused. If set to false (common case), destroy all
694 * surfaces that's eligible, if the app is already stopped.
695 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700696 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700697 boolean destroyedSomething = false;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100698
699 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +0100700 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
Jorim Jaggia5e10572017-11-15 14:36:26 +0100701 for (int i = children.size() - 1; i >= 0; i--) {
702 final WindowState win = children.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700703 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800704 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700705 if (destroyedSomething) {
706 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700707 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100708 updateLetterbox(null);
Robert Carre12aece2016-02-02 22:43:27 -0800709 }
710 }
711
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800712 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700713 * Notify that the app is now resumed, and it was not stopped before, perform a clean
714 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800715 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700716 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700717 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700718 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700719 mAppStopped = false;
chaviwd3bf08d2017-08-01 17:24:59 -0700720 // Allow the window to turn the screen on once the app is resumed again.
721 setCanTurnScreenOn(true);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700722 if (!wasStopped) {
723 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800724 }
Robert Carre12aece2016-02-02 22:43:27 -0800725 }
726
Chong Zhangbef461f2015-10-27 11:38:24 -0700727 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700728 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
729 * keeping alive in case they were still being used.
730 */
731 void notifyAppStopped() {
732 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
733 mAppStopped = true;
734 destroySurfaces();
735 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800736 if (getController() != null) {
737 getController().removeStartingWindow();
738 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700739 }
740
Chong Zhang92147042016-05-09 12:47:11 -0700741 void clearAllDrawn() {
742 allDrawn = false;
743 deferClearAllDrawn = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700744 }
745
Bryce Lee6d410262017-02-28 15:30:17 -0800746 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800747 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800748 }
749
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800750 TaskStack getStack() {
751 final Task task = getTask();
752 if (task != null) {
753 return task.mStack;
754 } else {
755 return null;
756 }
757 }
758
Bryce Lee6d410262017-02-28 15:30:17 -0800759 @Override
760 void onParentSet() {
761 super.onParentSet();
762
Robert Carred3e83b2017-04-21 13:26:55 -0700763 final Task task = getTask();
764
Bryce Lee6d410262017-02-28 15:30:17 -0800765 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
766 // access visual elements like the {@link DisplayContent}. We must remove any associations
767 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800768 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800769 if (task == null) {
770 // It is possible we have been marked as a closing app earlier. We must remove ourselves
771 // from this list so we do not participate in any future animations.
772 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700773 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800774 task.mStack.mExitingAppTokens.remove(this);
775 }
Bryce Lee6d410262017-02-28 15:30:17 -0800776 }
Robert Carred3e83b2017-04-21 13:26:55 -0700777 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800778 }
779
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700780 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700781 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700782 if (startingWindow == win) {
783 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800784 if (getController() != null) {
785 getController().removeStartingWindow();
786 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700787 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700788 // If this is the last window and we had requested a starting transition window,
789 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800790 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700791 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700792 if (mHiddenSetFromTransferredStartingWindow) {
793 // We set the hidden state to false for the token from a transferred starting window.
794 // We now reset it back to true since the starting window was the last window in the
795 // token.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200796 setHidden(true);
Wale Ogunwale6c459212017-05-17 08:56:03 -0700797 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100798 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700799 // If this is the last window except for a starting transition window,
800 // we need to get rid of the starting transition.
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200801 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Last window, removing starting window "
802 + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800803 if (getController() != null) {
804 getController().removeStartingWindow();
805 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700806 }
807 }
808
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700809 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700810 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700811 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800812 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700813 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700814 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800815 // Set mDestroying, we don't want any animation or delayed removal here.
816 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700817 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700818 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800819 }
820 }
821 }
822
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700823 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700824 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700825 // No need to loop through child windows as the answer should be the same as that of the
826 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700827 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700828 return true;
829 }
830 }
831 return false;
832 }
833
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700834 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700835 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
836 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800837
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700838 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700839 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700840 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800841 }
Robert Carra1eb4392015-12-10 12:43:51 -0800842 }
843
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700844 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700845 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800846 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700847 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700848 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700849 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800850 }
851 }
852
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700853 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700854 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
855 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800856
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700857 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700858 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700859 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800860 }
861 }
862
Chong Zhang4d7369a2016-04-25 16:09:14 -0700863 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700864 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700865 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700866 w.requestUpdateWallpaperIfNeeded();
867 }
868 }
869
Chong Zhangd78ddb42016-03-02 17:01:14 -0800870 boolean isRelaunching() {
871 return mPendingRelaunchCount > 0;
872 }
873
Robert Carr68375192017-06-13 12:41:53 -0700874 boolean shouldFreezeBounds() {
875 final Task task = getTask();
876
877 // For freeform windows, we can't freeze the bounds at the moment because this would make
878 // the resizing unresponsive.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700879 if (task == null || task.inFreeformWindowingMode()) {
Robert Carr68375192017-06-13 12:41:53 -0700880 return false;
881 }
882
883 // We freeze the bounds while drag resizing to deal with the time between
884 // the divider/drag handle being released, and the handling it's new
885 // configuration. If we are relaunched outside of the drag resizing state,
886 // we need to be careful not to do this.
887 return getTask().isDragResizing();
888 }
889
Chong Zhangd78ddb42016-03-02 17:01:14 -0800890 void startRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700891 if (shouldFreezeBounds()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -0800892 freezeBounds();
893 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800894
895 // In the process of tearing down before relaunching, the app will
896 // try and clean up it's child surfaces. We need to prevent this from
897 // happening, so we sever the children, transfering their ownership
898 // from the client it-self to the parent surface (owned by us).
899 for (int i = mChildren.size() - 1; i >= 0; i--) {
900 final WindowState w = mChildren.get(i);
901 w.mWinAnimator.detachChildren();
902 }
903
Chong Zhangd78ddb42016-03-02 17:01:14 -0800904 mPendingRelaunchCount++;
905 }
906
907 void finishRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700908 unfreezeBounds();
909
Chong Zhangd78ddb42016-03-02 17:01:14 -0800910 if (mPendingRelaunchCount > 0) {
911 mPendingRelaunchCount--;
Bryce Lee081554b2017-05-25 07:52:12 -0700912 } else {
913 // Update keyguard flags upon finishing relaunch.
914 checkKeyguardFlagsChanged();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800915 }
916 }
917
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700918 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700919 if (mPendingRelaunchCount == 0) {
920 return;
921 }
Robert Carr68375192017-06-13 12:41:53 -0700922 unfreezeBounds();
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700923 mPendingRelaunchCount = 0;
924 }
925
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700926 /**
927 * Returns true if the new child window we are adding to this token is considered greater than
928 * the existing child window in this token in terms of z-order.
929 */
930 @Override
931 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
932 WindowState existingWindow) {
933 final int type1 = newWindow.mAttrs.type;
934 final int type2 = existingWindow.mAttrs.type;
935
936 // Base application windows should be z-ordered BELOW all other windows in the app token.
937 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
938 return false;
939 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
940 return true;
941 }
942
943 // Starting windows should be z-ordered ABOVE all other windows in the app token.
944 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
945 return true;
946 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
947 return false;
948 }
949
950 // Otherwise the new window is greater than the existing window.
951 return true;
952 }
953
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700954 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800955 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700956 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700957
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700958 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700959 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700960 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700961 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
962 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700963
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700964 // if we got a replacement window, reset the timeout to give drawing more time
965 if (gotReplacementWindow) {
966 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800967 }
Jorim Jaggife762342016-10-13 14:33:27 +0200968 checkKeyguardFlagsChanged();
969 }
970
971 @Override
972 void removeChild(WindowState child) {
973 super.removeChild(child);
974 checkKeyguardFlagsChanged();
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100975 updateLetterbox(child);
Robert Carra1eb4392015-12-10 12:43:51 -0800976 }
977
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700978 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700979 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700980 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700981 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800982 return true;
983 }
984 }
985 return false;
986 }
987
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700988 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700989 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700990 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800991 }
992 }
993
Winson Chung30480042017-01-26 10:55:34 -0800994 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800995 final Task currentTask = getTask();
996 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -0800997 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800998 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800999 }
Bryce Lee6d410262017-02-28 15:30:17 -08001000
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001001 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -08001002 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001003 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -08001004 + " belongs to a different stack than " + task);
1005 }
1006
Winson Chung30480042017-01-26 10:55:34 -08001007 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001008 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001009 final DisplayContent prevDisplayContent = getDisplayContent();
1010
Bryce Lee6d410262017-02-28 15:30:17 -08001011 mReparenting = true;
1012
Winson Chung30480042017-01-26 10:55:34 -08001013 getParent().removeChild(this);
1014 task.addChild(this, position);
1015
Bryce Lee6d410262017-02-28 15:30:17 -08001016 mReparenting = false;
1017
Winson Chung30480042017-01-26 10:55:34 -08001018 // Relayout display(s).
1019 final DisplayContent displayContent = task.getDisplayContent();
1020 displayContent.setLayoutNeeded();
1021 if (prevDisplayContent != displayContent) {
1022 onDisplayChanged(displayContent);
1023 prevDisplayContent.setLayoutNeeded();
1024 }
1025 }
1026
Jorim Jaggi0429f352015-12-22 16:29:16 +01001027 /**
1028 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
1029 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
1030 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
1031 * with a queue.
1032 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001033 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001034 final Task task = getTask();
1035 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001036
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001037 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001038 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001039 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001040 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001041 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001042 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001043 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001044 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001045 }
1046
1047 /**
1048 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
1049 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001050 private void unfreezeBounds() {
Robert Carr68375192017-06-13 12:41:53 -07001051 if (mFrozenBounds.isEmpty()) {
1052 return;
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001053 }
Robert Carr68375192017-06-13 12:41:53 -07001054 mFrozenBounds.remove();
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001055 if (!mFrozenMergedConfig.isEmpty()) {
1056 mFrozenMergedConfig.remove();
1057 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001058 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001059 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001060 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001061 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001062 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001063 }
1064
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001065 void setAppLayoutChanges(int changes, String reason) {
1066 if (!mChildren.isEmpty()) {
1067 final DisplayContent dc = getDisplayContent();
1068 dc.pendingLayoutChanges |= changes;
1069 if (DEBUG_LAYOUT_REPEATS) {
1070 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001071 }
1072 }
1073 }
1074
1075 void removeReplacedWindowIfNeeded(WindowState replacement) {
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 if (win.removeReplacedWindowIfNeeded(replacement)) {
1079 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001080 }
1081 }
1082 }
1083
1084 void startFreezingScreen() {
1085 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001086 + isHidden() + " freezing=" + mFreezingScreen + " hiddenRequested="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001087 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001088 if (!hiddenRequested) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001089 if (!mFreezingScreen) {
1090 mFreezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001091 mService.registerAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001092 mService.mAppsFreezingScreen++;
1093 if (mService.mAppsFreezingScreen == 1) {
Bryce Lee8f853582017-06-05 17:25:59 -07001094 mService.startFreezingDisplayLocked(false, 0, 0, getDisplayContent());
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001095 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1096 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001097 }
1098 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001099 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001100 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001101 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001102 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001103 }
1104 }
1105 }
1106
1107 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001108 if (!mFreezingScreen) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001109 return;
1110 }
1111 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001112 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001113 boolean unfrozeWindows = false;
1114 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001115 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001116 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001117 }
1118 if (force || unfrozeWindows) {
1119 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001120 mFreezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001121 mService.unregisterAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001122 mService.mAppsFreezingScreen--;
1123 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001124 }
1125 if (unfreezeSurfaceNow) {
1126 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001127 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001128 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001129 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001130 }
1131 }
1132
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001133 @Override
1134 public void onAppFreezeTimeout() {
1135 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1136 stopFreezingScreen(true, true);
1137 }
1138
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001139 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001140 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001141 if (fromToken == null) {
1142 return false;
1143 }
1144
1145 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001146 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001147 // In this case, the starting icon has already been displayed, so start
1148 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001149 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001150
1151 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1152 + " from " + fromToken + " to " + this);
1153
1154 final long origId = Binder.clearCallingIdentity();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001155 try {
1156 // Transfer the starting window over to the new token.
1157 startingData = fromToken.startingData;
1158 startingSurface = fromToken.startingSurface;
1159 startingDisplayed = fromToken.startingDisplayed;
1160 fromToken.startingDisplayed = false;
1161 startingWindow = tStartingWindow;
1162 reportedVisible = fromToken.reportedVisible;
1163 fromToken.startingData = null;
1164 fromToken.startingSurface = null;
1165 fromToken.startingWindow = null;
1166 fromToken.startingMoved = true;
1167 tStartingWindow.mToken = this;
1168 tStartingWindow.mAppToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001169
Peter Visontay3556a3b2017-11-01 17:23:17 +00001170 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1171 "Removing starting " + tStartingWindow + " from " + fromToken);
1172 fromToken.removeChild(tStartingWindow);
1173 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
1174 fromToken.mHiddenSetFromTransferredStartingWindow = false;
1175 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001176
Peter Visontay3556a3b2017-11-01 17:23:17 +00001177 // Propagate other interesting state between the tokens. If the old token is displayed,
1178 // we should immediately force the new one to be displayed. If it is animating, we need
1179 // to move that animation to the new one.
1180 if (fromToken.allDrawn) {
1181 allDrawn = true;
1182 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1183 }
1184 if (fromToken.firstWindowDrawn) {
1185 firstWindowDrawn = true;
1186 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001187 if (!fromToken.isHidden()) {
1188 setHidden(false);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001189 hiddenRequested = false;
1190 mHiddenSetFromTransferredStartingWindow = true;
1191 }
1192 setClientHidden(fromToken.mClientHidden);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001193
Jorim Jaggi980c9de2017-11-17 01:41:37 +01001194 transferAnimation(fromToken);
1195
1196 // When transferring an animation, we no longer need to apply an animation to the
1197 // the token we transfer the animation over. Thus, remove the animation from
1198 // pending opening apps.
1199 mService.mOpeningApps.remove(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001200
Peter Visontay3556a3b2017-11-01 17:23:17 +00001201 mService.updateFocusedWindowLocked(
1202 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
1203 getDisplayContent().setLayoutNeeded();
1204 mService.mWindowPlacerLocked.performSurfacePlacement();
1205 } finally {
1206 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001207 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001208 return true;
1209 } else if (fromToken.startingData != null) {
1210 // The previous app was getting ready to show a
1211 // starting window, but hasn't yet done so. Steal it!
1212 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1213 "Moving pending starting from " + fromToken + " to " + this);
1214 startingData = fromToken.startingData;
1215 fromToken.startingData = null;
1216 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001217 if (getController() != null) {
1218 getController().scheduleAddStartingWindow();
1219 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001220 return true;
1221 }
1222
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001223 // TODO: Transfer thumbnail
1224
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001225 return false;
1226 }
1227
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001228 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001229 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001230 }
1231
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001232 @Override
1233 void onAppTransitionDone() {
1234 sendingToBottom = false;
1235 }
1236
Wale Ogunwale51362492016-09-08 17:49:17 -07001237 /**
1238 * We override because this class doesn't want its children affecting its reported orientation
1239 * in anyway.
1240 */
1241 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001242 int getOrientation(int candidate) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001243 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1244 // Allow app to specify orientation regardless of its visibility state if the current
1245 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1246 // wants us to use the orientation of the app behind it.
1247 return mOrientation;
1248 }
1249
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001250 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1251 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1252 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001253 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee00d586d2017-07-28 20:48:43 -07001254 && (isVisible() || mService.mOpeningApps.contains(this) || isOnTop())) {
Bryce Leea163b762017-01-24 11:05:01 -08001255 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001256 }
Bryce Leea163b762017-01-24 11:05:01 -08001257
1258 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001259 }
1260
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001261 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1262 int getOrientationIgnoreVisibility() {
1263 return mOrientation;
1264 }
1265
Craig Mautnerdbb79912012-03-01 18:59:14 -08001266 @Override
Winson Chunge55c0192017-08-24 14:50:48 -07001267 public void onConfigurationChanged(Configuration newParentConfig) {
1268 final int prevWinMode = getWindowingMode();
1269 super.onConfigurationChanged(newParentConfig);
1270 final int winMode = getWindowingMode();
1271
1272 if (prevWinMode == winMode) {
1273 return;
1274 }
1275
1276 if (prevWinMode != WINDOWING_MODE_UNDEFINED && winMode == WINDOWING_MODE_PINNED) {
1277 // Entering PiP from fullscreen, reset the snap fraction
1278 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
1279 } else if (prevWinMode == WINDOWING_MODE_PINNED && winMode != WINDOWING_MODE_UNDEFINED) {
1280 // Leaving PiP to fullscreen, save the snap fraction based on the pre-animation bounds
1281 // for the next re-entry into PiP (assuming the activity is not hidden or destroyed)
1282 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
1283 if (pinnedStack != null) {
1284 mDisplayContent.mPinnedStackControllerLocked.saveReentrySnapFraction(this,
1285 pinnedStack.mPreAnimationBounds);
1286 }
1287 }
1288 }
1289
1290 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001291 void checkAppWindowsReadyToShow() {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001292 if (allDrawn == mLastAllDrawn) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001293 return;
1294 }
1295
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001296 mLastAllDrawn = allDrawn;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001297 if (!allDrawn) {
1298 return;
1299 }
1300
1301 // The token has now changed state to having all windows shown... what to do, what to do?
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001302 if (mFreezingScreen) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001303 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001304 stopFreezingScreen(false, true);
1305 if (DEBUG_ORIENTATION) Slog.i(TAG,
1306 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001307 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001308 // This will set mOrientationChangeComplete and cause a pass through layout.
1309 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001310 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001311 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001312 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001313
1314 // We can now show all of the drawn windows!
1315 if (!mService.mOpeningApps.contains(this)) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001316 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001317 }
1318 }
1319 }
1320
Matthew Ng5d23afa2017-06-21 16:16:24 -07001321 /**
Bryce Leed390deb2017-06-22 13:14:28 -07001322 * Returns whether the drawn window states of this {@link AppWindowToken} has considered every
1323 * child {@link WindowState}. A child is considered if it has been passed into
1324 * {@link #updateDrawnWindowStates(WindowState)} after being added. This is used to determine
1325 * whether states, such as {@code allDrawn}, can be set, which relies on state variables such as
1326 * {@code mNumInterestingWindows}, which depend on all {@link WindowState}s being considered.
1327 *
1328 * @return {@code true} If all children have been considered, {@code false}.
1329 */
1330 private boolean allDrawnStatesConsidered() {
Bryce Lee6311c4b2017-07-06 14:09:29 -07001331 for (int i = mChildren.size() - 1; i >= 0; --i) {
1332 final WindowState child = mChildren.get(i);
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001333 if (child.mightAffectAllDrawn() && !child.getDrawnStateEvaluated()) {
Bryce Leed390deb2017-06-22 13:14:28 -07001334 return false;
1335 }
1336 }
1337 return true;
1338 }
1339
1340 /**
Matthew Ng5d23afa2017-06-21 16:16:24 -07001341 * Determines if the token has finished drawing. This should only be called from
1342 * {@link DisplayContent#applySurfaceChangesTransaction}
1343 */
Matthew Ng498c71d2017-04-18 13:55:45 -07001344 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001345 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001346 // Number of drawn windows can be less when a window is being relaunched, wait for
Bryce Leed390deb2017-06-22 13:14:28 -07001347 // all windows to be launched and drawn for this token be considered all drawn.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001348 final int numInteresting = mNumInterestingWindows;
Bryce Leed390deb2017-06-22 13:14:28 -07001349
1350 // We must make sure that all present children have been considered (determined by
1351 // {@link #allDrawnStatesConsidered}) before evaluating whether everything has been
1352 // drawn.
1353 if (numInteresting > 0 && allDrawnStatesConsidered()
1354 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001355 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001356 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001357 allDrawn = true;
1358 // Force an additional layout pass where
1359 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001360 if (mDisplayContent != null) {
1361 mDisplayContent.setLayoutNeeded();
1362 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001363 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001364
Winson Chunge7ba6862017-05-24 12:13:33 -07001365 // Notify the pinned stack upon all windows drawn. If there was an animation in
1366 // progress then this signal will resume that animation.
Wale Ogunwale61911492017-10-11 08:50:50 -07001367 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
Winson Chunge7ba6862017-05-24 12:13:33 -07001368 if (pinnedStack != null) {
1369 pinnedStack.onAllWindowsDrawn();
Robert Carrecc06b32017-04-18 14:25:10 -07001370 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001371 }
1372 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001373 }
1374
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001375 /**
1376 * Updated this app token tracking states for interesting and drawn windows based on the window.
1377 *
1378 * @return Returns true if the input window is considered interesting and drawn while all the
1379 * windows in this app token where not considered drawn as of the last pass.
1380 */
1381 boolean updateDrawnWindowStates(WindowState w) {
Bryce Leed390deb2017-06-22 13:14:28 -07001382 w.setDrawnStateEvaluated(true /*evaluated*/);
1383
Jorim Jaggie4b0f282017-05-17 15:10:29 +02001384 if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001385 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001386 + " allDrawn=" + allDrawn + " freezingScreen=" + mFreezingScreen);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001387 }
1388
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001389 if (allDrawn && !mFreezingScreen) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001390 return false;
1391 }
1392
1393 if (mLastTransactionSequence != mService.mTransactionSequence) {
1394 mLastTransactionSequence = mService.mTransactionSequence;
Matthew Ng53e66b22018-01-12 17:13:13 -08001395 mNumDrawnWindows = 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001396 startingDisplayed = false;
Matthew Ng53e66b22018-01-12 17:13:13 -08001397
1398 // There is the main base application window, even if it is exiting, wait for it
1399 mNumInterestingWindows = findMainWindow(false /* includeStartingApp */) != null ? 1 : 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001400 }
1401
1402 final WindowStateAnimator winAnimator = w.mWinAnimator;
1403
1404 boolean isInterestingAndDrawn = false;
1405
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001406 if (!allDrawn && w.mightAffectAllDrawn()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001407 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1408 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001409 + ", isAnimationSet=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001410 if (!w.isDrawnLw()) {
1411 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1412 + " pv=" + w.mPolicyVisibility
1413 + " mDrawState=" + winAnimator.drawStateToString()
1414 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001415 + " a=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001416 }
1417 }
1418
1419 if (w != startingWindow) {
1420 if (w.isInteresting()) {
Matthew Ng53e66b22018-01-12 17:13:13 -08001421 // Add non-main window as interesting since the main app has already been added
1422 if (findMainWindow(false /* includeStartingApp */) != w) {
1423 mNumInterestingWindows++;
1424 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001425 if (w.isDrawnLw()) {
1426 mNumDrawnWindows++;
1427
1428 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1429 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001430 + " freezingScreen=" + mFreezingScreen
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001431 + " mAppFreezing=" + w.mAppFreezing);
1432
1433 isInterestingAndDrawn = true;
1434 }
1435 }
1436 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001437 if (getController() != null) {
1438 getController().reportStartingWindowDrawn();
1439 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001440 startingDisplayed = true;
1441 }
1442 }
1443
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001444 return isInterestingAndDrawn;
1445 }
1446
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001447 void updateLetterbox(WindowState winHint) {
1448 final WindowState w = findMainWindow();
1449 if (w != winHint && winHint != null && w != null) {
1450 return;
1451 }
1452 final boolean needsLetterbox = w != null && w.isLetterboxedAppWindow()
1453 && fillsParent() && w.hasDrawnLw();
1454 if (needsLetterbox) {
1455 if (mLetterbox == null) {
1456 mLetterbox = new Letterbox(() -> makeChildSurface(null));
1457 }
1458 mLetterbox.setDimensions(mPendingTransaction, getParent().getBounds(), w.mFrame);
1459 } else if (mLetterbox != null) {
1460 final SurfaceControl.Transaction t = new SurfaceControl.Transaction();
Adrian Roos2dfb7852018-01-15 13:41:37 +01001461 // Make sure we have a transaction here, in case we're called outside of a transaction.
1462 // This does not use mPendingTransaction, because SurfaceAnimator uses a
1463 // global transaction in onAnimationEnd.
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001464 SurfaceControl.openTransaction();
1465 try {
1466 mLetterbox.hide(t);
1467 } finally {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001468 SurfaceControl.mergeToGlobalTransaction(t);
1469 SurfaceControl.closeTransaction();
1470 }
1471 }
1472 }
1473
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001474 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001475 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001476 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1477 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1478 // TODO: Investigate if we need to continue to do this or if we can just process them
1479 // in-order.
1480 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001481 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001482 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001483 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001484 }
1485
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001486 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1487 boolean traverseTopToBottom) {
1488 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001489 }
1490
1491 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001492 AppWindowToken asAppWindowToken() {
1493 // I am an app window token!
1494 return this;
1495 }
1496
1497 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001498 boolean fillsParent() {
1499 return mFillsParent;
1500 }
1501
1502 void setFillsParent(boolean fillsParent) {
1503 mFillsParent = fillsParent;
1504 }
1505
Jorim Jaggife762342016-10-13 14:33:27 +02001506 boolean containsDismissKeyguardWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001507 // Window state is transient during relaunch. We are not guaranteed to be frozen during the
1508 // entirety of the relaunch.
1509 if (isRelaunching()) {
1510 return mLastContainsDismissKeyguardWindow;
1511 }
1512
Jorim Jaggife762342016-10-13 14:33:27 +02001513 for (int i = mChildren.size() - 1; i >= 0; i--) {
1514 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1515 return true;
1516 }
1517 }
1518 return false;
1519 }
1520
1521 boolean containsShowWhenLockedWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001522 // When we are relaunching, it is possible for us to be unfrozen before our previous
1523 // windows have been added back. Using the cached value ensures that our previous
1524 // showWhenLocked preference is honored until relaunching is complete.
1525 if (isRelaunching()) {
1526 return mLastContainsShowWhenLockedWindow;
1527 }
1528
Jorim Jaggife762342016-10-13 14:33:27 +02001529 for (int i = mChildren.size() - 1; i >= 0; i--) {
1530 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1531 return true;
1532 }
1533 }
Bryce Lee081554b2017-05-25 07:52:12 -07001534
Jorim Jaggife762342016-10-13 14:33:27 +02001535 return false;
1536 }
1537
1538 void checkKeyguardFlagsChanged() {
1539 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1540 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1541 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1542 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1543 mService.notifyKeyguardFlagsChanged(null /* callback */);
1544 }
1545 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1546 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1547 }
1548
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001549 WindowState getImeTargetBelowWindow(WindowState w) {
1550 final int index = mChildren.indexOf(w);
1551 if (index > 0) {
1552 final WindowState target = mChildren.get(index - 1);
1553 if (target.canBeImeTarget()) {
1554 return target;
1555 }
1556 }
1557 return null;
1558 }
1559
Winson Chungbe9be7f2017-06-28 10:55:22 -07001560 int getLowestAnimLayer() {
1561 for (int i = 0; i < mChildren.size(); i++) {
1562 final WindowState w = mChildren.get(i);
1563 if (w.mRemoved) {
1564 continue;
1565 }
1566 return w.mWinAnimator.mAnimLayer;
1567 }
1568 return Integer.MAX_VALUE;
1569 }
1570
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001571 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1572 WindowState candidate = null;
1573 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1574 final WindowState w = mChildren.get(i);
1575 if (w.mRemoved) {
1576 continue;
1577 }
1578 if (candidate == null || w.mWinAnimator.mAnimLayer >
1579 candidate.mWinAnimator.mAnimLayer) {
1580 candidate = w;
1581 }
1582 }
1583 return candidate;
1584 }
1585
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001586 /**
1587 * See {@link Activity#setDisablePreviewScreenshots}.
1588 */
1589 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001590 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001591 }
1592
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001593 /**
chaviwd3bf08d2017-08-01 17:24:59 -07001594 * Sets whether the current launch can turn the screen on. See {@link #canTurnScreenOn()}
1595 */
1596 void setCanTurnScreenOn(boolean canTurnScreenOn) {
1597 mCanTurnScreenOn = canTurnScreenOn;
1598 }
1599
1600 /**
1601 * Indicates whether the current launch can turn the screen on. This is to prevent multiple
1602 * relayouts from turning the screen back on. The screen should only turn on at most
1603 * once per activity resume.
1604 *
1605 * @return true if the screen can be turned on.
1606 */
1607 boolean canTurnScreenOn() {
1608 return mCanTurnScreenOn;
1609 }
1610
1611 /**
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001612 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1613 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1614 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1615 *
1616 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1617 * screenshot.
1618 */
1619 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001620 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001621 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001622 }
1623
chaviw23ee71c2017-12-18 11:29:41 -08001624 @Override
Jorim Jaggi596a1992017-12-29 14:48:02 +01001625 public SurfaceControl getAnimationLeashParent() {
Robert Carrb9506032018-02-13 13:54:00 -08001626 // All normal app transitions take place in an animation layer which is below the pinned
1627 // stack but may be above the parent stacks of the given animating apps.
1628 // For transitions in the pinned stack (menu activity) we just let them occur as a child
1629 // of the pinned stack.
1630 if (!inPinnedWindowingMode()) {
1631 return getAppAnimationLayer();
1632 } else {
1633 return getStack().getSurfaceControl();
1634 }
chaviw23ee71c2017-12-18 11:29:41 -08001635 }
1636
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001637 boolean applyAnimationLocked(WindowManager.LayoutParams lp, int transit, boolean enter,
1638 boolean isVoiceInteraction) {
1639
1640 if (mService.mDisableTransitionAnimation) {
1641 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1642 Slog.v(TAG_WM, "applyAnimation: transition animation is disabled. atoken=" + this);
1643 }
1644 cancelAnimation();
1645 return false;
1646 }
1647
1648 // Only apply an animation if the display isn't frozen. If it is frozen, there is no reason
1649 // to animate and it can cause strange artifacts when we unfreeze the display if some
1650 // different animation is running.
1651 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "AWT#applyAnimationLocked");
1652 if (okToAnimate()) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001653 final AnimationAdapter adapter;
1654 final TaskStack stack = getStack();
1655 mTmpPoint.set(0, 0);
1656 mTmpRect.setEmpty();
1657 if (stack != null) {
1658 stack.getRelativePosition(mTmpPoint);
1659 stack.getBounds(mTmpRect);
1660 mTmpRect.offsetTo(0, 0);
1661 }
1662 if (mService.mAppTransition.getRemoteAnimationController() != null) {
1663 adapter = mService.mAppTransition.getRemoteAnimationController()
1664 .createAnimationAdapter(this, mTmpPoint, mTmpRect);
1665 } else {
1666 final Animation a = loadAnimation(lp, transit, enter, isVoiceInteraction);
1667 if (a != null) {
1668 adapter = new LocalAnimationAdapter(
1669 new WindowAnimationSpec(a, mTmpPoint, mTmpRect,
1670 mService.mAppTransition.canSkipFirstFrame(),
1671 mService.mAppTransition.getAppStackClipMode()),
1672 mService.mSurfaceAnimationRunner);
1673 if (a.getZAdjustment() == Animation.ZORDER_TOP) {
1674 mNeedsZBoost = true;
1675 }
1676 mTransit = transit;
1677 mTransitFlags = mService.mAppTransition.getTransitFlags();
1678 } else {
1679 adapter = null;
chaviw23ee71c2017-12-18 11:29:41 -08001680 }
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001681 }
1682 if (adapter != null) {
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001683 startAnimation(getPendingTransaction(), adapter, !isVisible());
Jorim Jaggi82c17862018-02-21 17:50:18 +01001684 if (adapter.getShowWallpaper()) {
1685 mDisplayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
1686 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001687 }
1688 } else {
1689 cancelAnimation();
1690 }
1691 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
1692
1693 return isReallyAnimating();
1694 }
1695
1696 private Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
1697 boolean isVoiceInteraction) {
1698 final DisplayContent displayContent = getTask().getDisplayContent();
1699 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
1700 final int width = displayInfo.appWidth;
1701 final int height = displayInfo.appHeight;
1702 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG_WM,
1703 "applyAnimation: atoken=" + this);
1704
1705 // Determine the visible rect to calculate the thumbnail clip
1706 final WindowState win = findMainWindow();
1707 final Rect frame = new Rect(0, 0, width, height);
1708 final Rect displayFrame = new Rect(0, 0,
1709 displayInfo.logicalWidth, displayInfo.logicalHeight);
1710 final Rect insets = new Rect();
1711 final Rect stableInsets = new Rect();
1712 Rect surfaceInsets = null;
1713 final boolean freeform = win != null && win.inFreeformWindowingMode();
1714 if (win != null) {
1715 // Containing frame will usually cover the whole screen, including dialog windows.
1716 // For freeform workspace windows it will not cover the whole screen and it also
1717 // won't exactly match the final freeform window frame (e.g. when overlapping with
1718 // the status bar). In that case we need to use the final frame.
1719 if (freeform) {
1720 frame.set(win.mFrame);
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001721 } else if (win.isLetterboxedAppWindow()) {
1722 frame.set(getTask().getBounds());
Winson Chungc1674272018-02-21 10:15:17 -08001723 } else if (win.isDockedResizing()) {
1724 // If we are animating while docked resizing, then use the stack bounds as the
1725 // animation target (which will be different than the task bounds)
1726 frame.set(getTask().getParent().getBounds());
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001727 } else {
1728 frame.set(win.mContainingFrame);
1729 }
1730 surfaceInsets = win.getAttrs().surfaceInsets;
Adrian Roos20e07892018-02-23 19:12:01 +01001731 // XXX(b/72757033): These are insets relative to the window frame, but we're really
1732 // interested in the insets relative to the frame we chose in the if-blocks above.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001733 insets.set(win.mContentInsets);
1734 stableInsets.set(win.mStableInsets);
1735 }
1736
1737 if (mLaunchTaskBehind) {
1738 // Differentiate the two animations. This one which is briefly on the screen
1739 // gets the !enter animation, and the other activity which remains on the
1740 // screen gets the enter animation. Both appear in the mOpeningApps set.
1741 enter = false;
1742 }
1743 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG_WM, "Loading animation for app transition."
1744 + " transit=" + AppTransition.appTransitionToString(transit) + " enter=" + enter
1745 + " frame=" + frame + " insets=" + insets + " surfaceInsets=" + surfaceInsets);
1746 final Configuration displayConfig = displayContent.getConfiguration();
1747 final Animation a = mService.mAppTransition.loadAnimation(lp, transit, enter,
1748 displayConfig.uiMode, displayConfig.orientation, frame, displayFrame, insets,
1749 surfaceInsets, stableInsets, isVoiceInteraction, freeform, getTask().mTaskId);
1750 if (a != null) {
1751 if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this);
1752 final int containingWidth = frame.width();
1753 final int containingHeight = frame.height();
1754 a.initialize(containingWidth, containingHeight, width, height);
1755 a.scaleCurrentDuration(mService.getTransitionAnimationScaleLocked());
1756 }
1757 return a;
1758 }
1759
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001760 @Override
1761 protected void setLayer(Transaction t, int layer) {
1762 if (!mSurfaceAnimator.hasLeash()) {
1763 t.setLayer(mSurfaceControl, layer);
1764 }
1765 }
1766
1767 @Override
1768 protected void setRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) {
1769 if (!mSurfaceAnimator.hasLeash()) {
1770 t.setRelativeLayer(mSurfaceControl, relativeTo, layer);
1771 }
1772 }
1773
1774 @Override
1775 protected void reparentSurfaceControl(Transaction t, SurfaceControl newParent) {
1776 if (!mSurfaceAnimator.hasLeash()) {
1777 t.reparent(mSurfaceControl, newParent.getHandle());
1778 }
1779 }
1780
1781 @Override
1782 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001783 // The leash is parented to the animation layer. We need to preserve the z-order by using
1784 // the prefix order index, but we boost if necessary.
Robert Carrb9506032018-02-13 13:54:00 -08001785 int layer = 0;
1786 if (!inPinnedWindowingMode()) {
1787 layer = getPrefixOrderIndex();
1788 } else {
1789 // Pinned stacks have animations take place within themselves rather than an animation
1790 // layer so we need to preserve the order relative to the stack (e.g. the order of our
1791 // task/parent).
1792 layer = getParent().getPrefixOrderIndex();
1793 }
1794
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001795 if (mNeedsZBoost) {
1796 layer += Z_BOOST_BASE;
1797 }
1798 leash.setLayer(layer);
Robert Carr2f8aa392018-01-31 14:46:51 -08001799
1800 final DisplayContent dc = getDisplayContent();
1801 dc.assignStackOrdering(t);
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001802 }
1803
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001804 /**
1805 * This must be called while inside a transaction.
1806 */
1807 void showAllWindowsLocked() {
1808 forAllWindows(windowState -> {
1809 if (DEBUG_VISIBILITY) Slog.v(TAG, "performing show on: " + windowState);
1810 windowState.performShowLocked();
1811 }, false /* traverseTopToBottom */);
Jorim Jaggia5e10572017-11-15 14:36:26 +01001812 }
1813
1814 @Override
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001815 protected void onAnimationFinished() {
1816 super.onAnimationFinished();
1817
1818 mTransit = TRANSIT_UNSET;
1819 mTransitFlags = 0;
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001820 mNeedsZBoost = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001821
1822 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM | FINISH_LAYOUT_REDO_WALLPAPER,
1823 "AppWindowToken");
1824
Jorim Jaggi988f6682017-11-17 17:46:43 +01001825 clearThumbnail();
Jorim Jaggi3cad57f2018-02-20 18:32:01 +01001826 setClientHidden(hiddenRequested);
Jorim Jaggi988f6682017-11-17 17:46:43 +01001827
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001828 if (mService.mInputMethodTarget != null && mService.mInputMethodTarget.mAppToken == this) {
1829 getDisplayContent().computeImeTarget(true /* updateImeTarget */);
1830 }
1831
1832 if (DEBUG_ANIM) Slog.v(TAG, "Animation done in " + this
1833 + ": reportedVisible=" + reportedVisible
1834 + " okToDisplay=" + okToDisplay()
1835 + " okToAnimate=" + okToAnimate()
1836 + " startingDisplayed=" + startingDisplayed);
1837
1838 // WindowState.onExitAnimationDone might modify the children list, so make a copy and then
1839 // traverse the copy.
1840 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
1841 children.forEach(WindowState::onExitAnimationDone);
1842
1843 mService.mAppTransition.notifyAppTransitionFinishedLocked(token);
1844 scheduleAnimation();
1845 }
1846
1847 @Override
1848 boolean isAppAnimating() {
1849 return isSelfAnimating();
1850 }
1851
1852 @Override
1853 boolean isSelfAnimating() {
1854 // If we are about to start a transition, we also need to be considered animating.
1855 return isWaitingForTransitionStart() || isReallyAnimating();
1856 }
1857
1858 /**
1859 * @return True if and only if we are actually running an animation. Note that
1860 * {@link #isSelfAnimating} also returns true if we are waiting for an animation to
1861 * start.
1862 */
1863 private boolean isReallyAnimating() {
1864 return super.isSelfAnimating();
1865 }
1866
Jorim Jaggi988f6682017-11-17 17:46:43 +01001867 @Override
1868 void cancelAnimation() {
1869 super.cancelAnimation();
1870 clearThumbnail();
1871 }
1872
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001873 boolean isWaitingForTransitionStart() {
1874 return mService.mAppTransition.isTransitionSet()
1875 && (mService.mOpeningApps.contains(this) || mService.mClosingApps.contains(this));
1876 }
1877
1878 public int getTransit() {
1879 return mTransit;
1880 }
1881
1882 int getTransitFlags() {
1883 return mTransitFlags;
1884 }
1885
Jorim Jaggi988f6682017-11-17 17:46:43 +01001886 void attachThumbnailAnimation() {
1887 if (!isReallyAnimating()) {
1888 return;
1889 }
1890 final int taskId = getTask().mTaskId;
1891 final GraphicBuffer thumbnailHeader =
1892 mService.mAppTransition.getAppTransitionThumbnailHeader(taskId);
1893 if (thumbnailHeader == null) {
1894 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG, "No thumbnail header bitmap for: " + taskId);
1895 return;
1896 }
1897 clearThumbnail();
1898 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnailHeader);
1899 mThumbnail.startAnimation(getPendingTransaction(), loadThumbnailAnimation(thumbnailHeader));
1900 }
1901
Tony Mak64b8d562017-12-28 17:44:02 +00001902 /**
1903 * Attaches a surface with a thumbnail for the
1904 * {@link android.app.ActivityOptions#ANIM_OPEN_CROSS_PROFILE_APPS} animation.
1905 */
1906 void attachCrossProfileAppsThumbnailAnimation() {
1907 if (!isReallyAnimating()) {
1908 return;
1909 }
1910 clearThumbnail();
1911
1912 final WindowState win = findMainWindow();
1913 if (win == null) {
1914 return;
1915 }
1916 final Rect frame = win.mFrame;
1917 final int thumbnailDrawableRes = getTask().mUserId == mService.mCurrentUserId
1918 ? R.drawable.ic_account_circle
1919 : R.drawable.ic_corp_badge_no_background;
1920 final GraphicBuffer thumbnail =
1921 mService.mAppTransition
1922 .createCrossProfileAppsThumbnail(thumbnailDrawableRes, frame);
1923 if (thumbnail == null) {
1924 return;
1925 }
1926 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnail);
1927 final Animation animation =
1928 mService.mAppTransition.createCrossProfileAppsThumbnailAnimationLocked(win.mFrame);
1929 mThumbnail.startAnimation(getPendingTransaction(), animation, new Point(frame.left,
1930 frame.top));
1931 }
1932
Jorim Jaggi988f6682017-11-17 17:46:43 +01001933 private Animation loadThumbnailAnimation(GraphicBuffer thumbnailHeader) {
1934 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
1935
1936 // If this is a multi-window scenario, we use the windows frame as
1937 // destination of the thumbnail header animation. If this is a full screen
1938 // window scenario, we use the whole display as the target.
1939 WindowState win = findMainWindow();
1940 Rect appRect = win != null ? win.getContentFrameLw() :
1941 new Rect(0, 0, displayInfo.appWidth, displayInfo.appHeight);
1942 Rect insets = win != null ? win.mContentInsets : null;
1943 final Configuration displayConfig = mDisplayContent.getConfiguration();
1944 return mService.mAppTransition.createThumbnailAspectScaleAnimationLocked(
1945 appRect, insets, thumbnailHeader, getTask().mTaskId, displayConfig.uiMode,
1946 displayConfig.orientation);
1947 }
1948
1949 private void clearThumbnail() {
1950 if (mThumbnail == null) {
1951 return;
1952 }
1953 mThumbnail.destroy();
1954 mThumbnail = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001955 }
1956
Jorim Jaggif84e2f62018-01-16 14:17:59 +01001957 void registerRemoteAnimations(RemoteAnimationDefinition definition) {
1958 mRemoteAnimationDefinition = definition;
1959 }
1960
1961 RemoteAnimationDefinition getRemoteAnimationDefinition() {
1962 return mRemoteAnimationDefinition;
1963 }
1964
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001965 @Override
1966 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
1967 super.dump(pw, prefix, dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001968 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001969 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001970 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001971 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001972 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1973 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07001974 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
1975 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
1976 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001977 if (paused) {
1978 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001979 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001980 if (mAppStopped) {
1981 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1982 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001983 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001984 || allDrawn || mLastAllDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001985 pw.print(prefix); pw.print("mNumInterestingWindows=");
1986 pw.print(mNumInterestingWindows);
1987 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001988 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001989 pw.print(" allDrawn="); pw.print(allDrawn);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001990 pw.print(" lastAllDrawn="); pw.print(mLastAllDrawn);
Craig Mautner6fbda632012-07-03 09:26:39 -07001991 pw.println(")");
1992 }
1993 if (inPendingTransaction) {
1994 pw.print(prefix); pw.print("inPendingTransaction=");
1995 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001996 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001997 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001998 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1999 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08002000 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08002001 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002002 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002003 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07002004 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002005 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002006 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002007 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07002008 pw.print(" startingMoved="); pw.print(startingMoved);
2009 pw.println(" mHiddenSetFromTransferredStartingWindow="
2010 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002011 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01002012 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08002013 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002014 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08002015 }
2016 if (mPendingRelaunchCount != 0) {
2017 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01002018 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07002019 if (getController() != null) {
2020 pw.print(prefix); pw.print("controller="); pw.println(getController());
2021 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07002022 if (mRemovingFromDisplay) {
2023 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
2024 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002025 }
2026
2027 @Override
2028 void setHidden(boolean hidden) {
2029 super.setHidden(hidden);
Winson Chunge55c0192017-08-24 14:50:48 -07002030
2031 if (hidden) {
2032 // Once the app window is hidden, reset the last saved PiP snap fraction
2033 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
2034 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002035 scheduleAnimation();
2036 }
2037
2038 @Override
2039 void prepareSurfaces() {
2040 // isSelfAnimating also returns true when we are about to start a transition, so we need
2041 // to check super here.
2042 final boolean reallyAnimating = super.isSelfAnimating();
2043 final boolean show = !isHidden() || reallyAnimating;
2044 if (show && !mLastSurfaceShowing) {
2045 mPendingTransaction.show(mSurfaceControl);
2046 } else if (!show && mLastSurfaceShowing) {
2047 mPendingTransaction.hide(mSurfaceControl);
Jorim Jaggi4d1835d2017-08-31 17:28:27 +02002048 }
Jorim Jaggi988f6682017-11-17 17:46:43 +01002049 if (mThumbnail != null) {
2050 mThumbnail.setShowing(mPendingTransaction, show);
2051 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002052 mLastSurfaceShowing = show;
2053 super.prepareSurfaces();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002054 }
2055
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002056 boolean isFreezingScreen() {
2057 return mFreezingScreen;
2058 }
2059
2060 @Override
2061 boolean needsZBoost() {
2062 return mNeedsZBoost || super.needsZBoost();
2063 }
2064
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002065 @CallSuper
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002066 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002067 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002068 final long token = proto.start(fieldId);
2069 writeNameToProto(proto, NAME);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002070 super.writeToProto(proto, WINDOW_TOKEN, trim);
Vishnu Nair04ab4392018-01-10 11:00:06 -08002071 proto.write(LAST_SURFACE_SHOWING, mLastSurfaceShowing);
2072 proto.write(IS_WAITING_FOR_TRANSITION_START, isWaitingForTransitionStart());
2073 proto.write(IS_REALLY_ANIMATING, isReallyAnimating());
2074 if (mThumbnail != null){
2075 mThumbnail.writeToProto(proto, THUMBNAIL);
2076 }
2077 proto.write(FILLS_PARENT, mFillsParent);
2078 proto.write(APP_STOPPED, mAppStopped);
2079 proto.write(HIDDEN_REQUESTED, hiddenRequested);
2080 proto.write(CLIENT_HIDDEN, mClientHidden);
2081 proto.write(DEFER_HIDING_CLIENT, mDeferHidingClient);
2082 proto.write(REPORTED_DRAWN, reportedDrawn);
2083 proto.write(REPORTED_VISIBLE, reportedVisible);
2084 proto.write(NUM_INTERESTING_WINDOWS, mNumInterestingWindows);
2085 proto.write(NUM_DRAWN_WINDOWS, mNumDrawnWindows);
2086 proto.write(ALL_DRAWN, allDrawn);
2087 proto.write(LAST_ALL_DRAWN, mLastAllDrawn);
2088 proto.write(REMOVED, removed);
2089 if (startingWindow != null){
2090 startingWindow.writeIdentifierToProto(proto, STARTING_WINDOW);
2091 }
2092 proto.write(STARTING_DISPLAYED, startingDisplayed);
2093 proto.write(STARTING_MOVED, startingMoved);
2094 proto.write(HIDDEN_SET_FROM_TRANSFERRED_STARTING_WINDOW,
2095 mHiddenSetFromTransferredStartingWindow);
2096 for (Rect bounds : mFrozenBounds) {
2097 bounds.writeToProto(proto, FROZEN_BOUNDS);
2098 }
Steven Timotiusaf03df62017-07-18 16:56:43 -07002099 proto.end(token);
2100 }
2101
2102 void writeNameToProto(ProtoOutputStream proto, long fieldId) {
2103 if (appToken == null) {
2104 return;
2105 }
2106 try {
2107 proto.write(fieldId, appToken.getName());
2108 } catch (RemoteException e) {
2109 // This shouldn't happen, but in this case fall back to outputting nothing
2110 Slog.e(TAG, e.toString());
2111 }
2112 }
2113
2114 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002115 public String toString() {
2116 if (stringName == null) {
2117 StringBuilder sb = new StringBuilder();
2118 sb.append("AppWindowToken{");
2119 sb.append(Integer.toHexString(System.identityHashCode(this)));
2120 sb.append(" token="); sb.append(token); sb.append('}');
2121 stringName = sb.toString();
2122 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07002123 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002124 }
Adrian Roos20e07892018-02-23 19:12:01 +01002125
2126 Rect getLetterboxInsets() {
2127 if (mLetterbox != null) {
2128 return mLetterbox.getInsets();
2129 } else {
2130 return new Rect();
2131 }
2132 }
Jeff Browne9bdb312012-04-05 15:30:10 -07002133}