blob: 0ba5a56b6e67033bb9889b085881a1710a013551 [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;
Jorim Jaggic6976f02018-04-18 16:31:07 +020020import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
Winson Chunge55c0192017-08-24 14:50:48 -070021import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
Wale Ogunwale72919d22016-12-08 18:58:50 -080022import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
23import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070024import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
Wale Ogunwale51362492016-09-08 17:49:17 -070025import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020026import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070027import static android.view.Display.DEFAULT_DISPLAY;
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
Jorim Jaggic6976f02018-04-18 16:31:07 +020035import static android.view.WindowManager.TRANSIT_DOCK_TASK_FROM_RECENTS;
36import static android.view.WindowManager.TRANSIT_WALLPAPER_OPEN;
Adrian Roose99bc052017-11-20 17:55:31 +010037import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
38import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010039import static android.view.WindowManager.TRANSIT_UNSET;
Jorim Jaggic6976f02018-04-18 16:31:07 +020040import static com.android.server.wm.AppTransition.isKeyguardGoingAwayTransit;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080041import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080042import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
43import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070044import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070045import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
46import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080047import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020048import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070049import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080050import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
51import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
52import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
53import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070054import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070055import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070056import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070057import static com.android.server.wm.WindowManagerService.logWithStack;
Yi Jin6c6e9ca2018-03-20 16:53:35 -070058import static com.android.server.wm.AppWindowTokenProto.ALL_DRAWN;
59import static com.android.server.wm.AppWindowTokenProto.APP_STOPPED;
60import static com.android.server.wm.AppWindowTokenProto.CLIENT_HIDDEN;
61import static com.android.server.wm.AppWindowTokenProto.DEFER_HIDING_CLIENT;
62import static com.android.server.wm.AppWindowTokenProto.FILLS_PARENT;
63import static com.android.server.wm.AppWindowTokenProto.FROZEN_BOUNDS;
64import static com.android.server.wm.AppWindowTokenProto.HIDDEN_REQUESTED;
65import static com.android.server.wm.AppWindowTokenProto.HIDDEN_SET_FROM_TRANSFERRED_STARTING_WINDOW;
66import static com.android.server.wm.AppWindowTokenProto.IS_REALLY_ANIMATING;
67import static com.android.server.wm.AppWindowTokenProto.IS_WAITING_FOR_TRANSITION_START;
68import static com.android.server.wm.AppWindowTokenProto.LAST_ALL_DRAWN;
69import static com.android.server.wm.AppWindowTokenProto.LAST_SURFACE_SHOWING;
70import static com.android.server.wm.AppWindowTokenProto.NAME;
71import static com.android.server.wm.AppWindowTokenProto.NUM_DRAWN_WINDOWS;
72import static com.android.server.wm.AppWindowTokenProto.NUM_INTERESTING_WINDOWS;
73import static com.android.server.wm.AppWindowTokenProto.REMOVED;
74import static com.android.server.wm.AppWindowTokenProto.REPORTED_DRAWN;
75import static com.android.server.wm.AppWindowTokenProto.REPORTED_VISIBLE;
76import static com.android.server.wm.AppWindowTokenProto.STARTING_DISPLAYED;
77import static com.android.server.wm.AppWindowTokenProto.STARTING_MOVED;
78import static com.android.server.wm.AppWindowTokenProto.STARTING_WINDOW;
79import static com.android.server.wm.AppWindowTokenProto.THUMBNAIL;
80import static com.android.server.wm.AppWindowTokenProto.WINDOW_TOKEN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080081
Wale Ogunwale0d5609b2017-09-13 05:55:07 -070082import android.annotation.CallSuper;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020083import android.app.Activity;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070084import android.content.res.Configuration;
Jorim Jaggi988f6682017-11-17 17:46:43 +010085import android.graphics.GraphicBuffer;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020086import android.graphics.Point;
Jorim Jaggi0429f352015-12-22 16:29:16 +010087import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070088import android.os.Binder;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080089import android.os.Debug;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070090import android.os.IBinder;
Steven Timotiusaf03df62017-07-18 16:56:43 -070091import android.os.RemoteException;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020092import android.os.Trace;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080093import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -070094import android.util.proto.ProtoOutputStream;
Jorim Jaggif5f9e122017-10-24 18:21:09 +020095import android.view.DisplayInfo;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080096import android.view.IApplicationToken;
Jorim Jaggif84e2f62018-01-16 14:17:59 +010097import android.view.RemoteAnimationDefinition;
Robert Carr6914f082017-03-20 19:04:30 -070098import android.view.SurfaceControl;
Tony Mak64b8d562017-12-28 17:44:02 +000099import android.view.SurfaceControl.Transaction;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800100import android.view.WindowManager;
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +0200101import android.view.WindowManager.LayoutParams;
Tony Mak64b8d562017-12-28 17:44:02 +0000102import android.view.animation.Animation;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800103
Tony Mak64b8d562017-12-28 17:44:02 +0000104import com.android.internal.R;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800105import com.android.internal.util.ToBooleanFunction;
106import com.android.server.input.InputApplicationHandle;
Adrian Roose99bc052017-11-20 17:55:31 +0100107import com.android.server.policy.WindowManagerPolicy.StartingSurface;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800108import com.android.server.wm.WindowManagerService.H;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800109
110import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +0100111import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -0800112import java.util.ArrayList;
113
114class AppTokenList extends ArrayList<AppWindowToken> {
115}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800116
117/**
118 * Version of WindowToken that is specifically for a particular application (or
119 * really activity) that is displaying windows.
120 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700121class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800122 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
123
Jorim Jaggi619c9f72017-12-19 18:04:29 +0100124 /**
125 * Value to increment the z-layer when boosting a layer during animations. BOOST in l33tsp34k.
126 */
127 private static final int Z_BOOST_BASE = 800570000;
128
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800129 // Non-null only for application tokens.
130 final IApplicationToken appToken;
131
Wale Ogunwale72919d22016-12-08 18:58:50 -0800132 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700133
Wale Ogunwale51362492016-09-08 17:49:17 -0700134 /** @see WindowContainer#fillsParent() */
135 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -0800136 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800137 boolean mShowForAllUsers;
138 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -0700139
Bryce Lee6d410262017-02-28 15:30:17 -0800140 // Flag set while reparenting to prevent actions normally triggered by an individual parent
141 // change.
142 private boolean mReparenting;
143
Wale Ogunwalee287e192017-04-21 09:30:12 -0700144 // True if we are current in the process of removing this app token from the display
145 private boolean mRemovingFromDisplay = false;
146
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800147 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -0800148 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800149
150 // These are used for determining when all windows associated with
151 // an activity have been drawn, so they can be made visible together
152 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700153 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700154 private long mLastTransactionSequence = Long.MIN_VALUE;
155 private int mNumInterestingWindows;
156 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800157 boolean inPendingTransaction;
158 boolean allDrawn;
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000159 private boolean mLastAllDrawn;
160
Craig Mautner7636dfb2012-11-16 15:24:11 -0800161 // Set to true when this app creates a surface while in the middle of an animation. In that
162 // case do not clear allDrawn until the animation completes.
163 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800164
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800165 // Is this window's surface needed? This is almost like hidden, except
166 // it will sometimes be true a little earlier: when the token has
167 // been shown, but is still waiting for its app transition to execute
168 // before making its windows shown.
169 boolean hiddenRequested;
170
171 // Have we told the window clients to hide themselves?
Wale Ogunwale89973222017-04-23 18:39:45 -0700172 private boolean mClientHidden;
173
174 // If true we will defer setting mClientHidden to true and reporting to the client that it is
175 // hidden.
176 boolean mDeferHidingClient;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800177
178 // Last visibility state we reported to the app token.
179 boolean reportedVisible;
180
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700181 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700182 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700183
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800184 // Set to true when the token has been removed from the window mgr.
185 boolean removed;
186
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800187 // Information about an application starting window if displayed.
188 StartingData startingData;
189 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800190 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800191 boolean startingDisplayed;
192 boolean startingMoved;
Jorim Jaggi60f9c972018-02-01 19:21:07 +0100193
Wale Ogunwale6c459212017-05-17 08:56:03 -0700194 // True if the hidden state of this token was forced to false due to a transferred starting
195 // window.
196 private boolean mHiddenSetFromTransferredStartingWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800197 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700198 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
199 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800200
201 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700202 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800203
Wale Ogunwale571771c2016-08-26 13:18:50 -0700204 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800205 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800206
Craig Mautnerbb742462014-07-07 15:28:55 -0700207 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700208 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700209
Wale Ogunwale72919d22016-12-08 18:58:50 -0800210 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800211
Robert Carre12aece2016-02-02 22:43:27 -0800212 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700213 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700214 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800215
Jorim Jaggife762342016-10-13 14:33:27 +0200216 private boolean mLastContainsShowWhenLockedWindow;
217 private boolean mLastContainsDismissKeyguardWindow;
218
Jorim Jaggi0429f352015-12-22 16:29:16 +0100219 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700220 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100221
Wale Ogunwale6c459212017-05-17 08:56:03 -0700222 private boolean mDisablePreviewScreenshots;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100223
Wale Ogunwale034a8ec2017-09-02 17:14:40 -0700224 private Task mLastParent;
Robert Carred3e83b2017-04-21 13:26:55 -0700225
chaviwd3bf08d2017-08-01 17:24:59 -0700226 /**
227 * See {@link #canTurnScreenOn()}
228 */
229 private boolean mCanTurnScreenOn = true;
230
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200231 /**
232 * If we are running an animation, this determines the transition type. Must be one of
233 * AppTransition.TRANSIT_* constants.
234 */
235 private int mTransit;
236
237 /**
238 * If we are running an animation, this determines the flags during this animation. Must be a
239 * bitwise combination of AppTransition.TRANSIT_FLAG_* constants.
240 */
241 private int mTransitFlags;
242
243 /** Whether our surface was set to be showing in the last call to {@link #prepareSurfaces} */
Jorim Jaggifd1891462017-12-29 15:41:36 +0100244 private boolean mLastSurfaceShowing = true;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200245
Jorim Jaggi988f6682017-11-17 17:46:43 +0100246 private AppWindowThumbnail mThumbnail;
247
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000248 /** Have we been asked to have this token keep the screen frozen? */
249 private boolean mFreezingScreen;
250
251 /** Whether this token should be boosted at the top of all app window tokens. */
252 private boolean mNeedsZBoost;
Adrian Roos4d18a2e2017-12-19 19:08:05 +0100253 private Letterbox mLetterbox;
Jorim Jaggib0fc8172017-11-23 17:04:08 +0000254
chaviw23ee71c2017-12-18 11:29:41 -0800255 private final Point mTmpPoint = new Point();
chaviw23012112017-12-20 15:29:04 -0800256 private final Rect mTmpRect = new Rect();
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100257 private RemoteAnimationDefinition mRemoteAnimationDefinition;
Jorim Jaggi6de61012018-03-19 14:53:23 +0100258 private AnimatingAppWindowTokenRegistry mAnimatingAppWindowTokenRegistry;
chaviw23ee71c2017-12-18 11:29:41 -0800259
Wale Ogunwale72919d22016-12-08 18:58:50 -0800260 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
261 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
262 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800263 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Bryce Leef3c6a472017-11-14 14:53:06 -0800264 AppWindowContainerController controller) {
265 this(service, token, voiceInteraction, dc, fullscreen);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800266 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800267 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800268 mShowForAllUsers = showForAllUsers;
269 mTargetSdk = targetSdk;
270 mOrientation = orientation;
271 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
272 mLaunchTaskBehind = launchTaskBehind;
273 mAlwaysFocusable = alwaysFocusable;
274 mRotationAnimationHint = rotationAnimationHint;
275
276 // Application tokens start out hidden.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200277 setHidden(true);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800278 hiddenRequested = true;
279 }
280
281 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Bryce Leef3c6a472017-11-14 14:53:06 -0800282 DisplayContent dc, boolean fillsParent) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800283 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
284 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700285 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800286 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800287 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800288 mInputApplicationHandle = new InputApplicationHandle(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800289 }
290
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800291 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
292 firstWindowDrawn = true;
293
294 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700295 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800296
Jorim Jaggi02886a82016-12-06 09:10:06 -0800297 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800298 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
299 + win.mToken + ": first real window is shown, no animation");
300 // If this initial window is animating, stop it -- we will do an animation to reveal
301 // it from behind the starting window, so there is no need for it to also be doing its
302 // own stuff.
Jorim Jaggia5e10572017-11-15 14:36:26 +0100303 win.cancelAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800304 if (getController() != null) {
305 getController().removeStartingWindow();
306 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800307 }
308 updateReportedVisibilityLocked();
309 }
310
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800311 void updateReportedVisibilityLocked() {
312 if (appToken == null) {
313 return;
314 }
315
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700316 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700317 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800318
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700319 mReportedVisibilityResults.reset();
320
321 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700322 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700323 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800324 }
325
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700326 int numInteresting = mReportedVisibilityResults.numInteresting;
327 int numVisible = mReportedVisibilityResults.numVisible;
328 int numDrawn = mReportedVisibilityResults.numDrawn;
329 boolean nowGone = mReportedVisibilityResults.nowGone;
330
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700331 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200332 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting && !isHidden();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700333 if (!nowGone) {
334 // If the app is not yet gone, then it can only become visible/drawn.
335 if (!nowDrawn) {
336 nowDrawn = reportedDrawn;
337 }
338 if (!nowVisible) {
339 nowVisible = reportedVisible;
340 }
341 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800342 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800343 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800344 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700345 if (nowDrawn != reportedDrawn) {
346 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800347 if (controller != null) {
348 controller.reportWindowsDrawn();
349 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700350 }
351 reportedDrawn = nowDrawn;
352 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800353 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700354 if (DEBUG_VISIBILITY) Slog.v(TAG,
355 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800356 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800357 if (controller != null) {
358 if (nowVisible) {
359 controller.reportWindowsVisible();
360 } else {
361 controller.reportWindowsGone();
362 }
363 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800364 }
365 }
366
Wale Ogunwale89973222017-04-23 18:39:45 -0700367 boolean isClientHidden() {
368 return mClientHidden;
369 }
370
371 void setClientHidden(boolean hideClient) {
372 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
373 return;
374 }
Jorim Jaggi067b5bf2018-02-23 17:42:39 +0100375 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setClientHidden: " + this
376 + " clientHidden=" + hideClient + " Callers=" + Debug.getCallers(5));
Wale Ogunwale89973222017-04-23 18:39:45 -0700377 mClientHidden = hideClient;
378 sendAppVisibilityToClients();
379 }
380
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700381 boolean setVisibility(WindowManager.LayoutParams lp,
382 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
383
384 boolean delayed = false;
385 inPendingTransaction = false;
Wale Ogunwale9e4721f2017-05-23 19:37:30 -0700386 // Reset the state of mHiddenSetFromTransferredStartingWindow since visibility is actually
387 // been set by the app now.
388 mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700389
390 // Allow for state changes and animation to be applied if:
391 // * token is transitioning visibility state
392 // * or the token was marked as hidden and is exiting before we had a chance to play the
393 // transition animation
394 // * or this is an opening app and windows are being replaced.
395 boolean visibilityChanged = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200396 if (isHidden() == visible || (isHidden() && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700397 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700398 boolean changed = false;
399 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200400 "Changing app " + this + " hidden=" + isHidden() + " performLayout=" + performLayout);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700401
402 boolean runningAppAnimation = false;
403
Jorim Jaggif84e2f62018-01-16 14:17:59 +0100404 if (transit != WindowManager.TRANSIT_UNSET) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200405 if (applyAnimationLocked(lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700406 delayed = runningAppAnimation = true;
407 }
408 final WindowState window = findMainWindow();
409 //TODO (multidisplay): Magnification is supported only for the default display.
410 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700411 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700412 accessibilityController.onAppWindowTransitionLocked(window, transit);
413 }
414 changed = true;
415 }
416
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700417 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700418 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700419 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700420 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700421 }
422
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200423 setHidden(!visible);
424 hiddenRequested = !visible;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700425 visibilityChanged = true;
426 if (!visible) {
427 stopFreezingScreen(true, true);
428 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700429 // If we are being set visible, and the starting window is not yet displayed,
430 // then make sure it doesn't get displayed.
431 if (startingWindow != null && !startingWindow.isDrawnLw()) {
432 startingWindow.mPolicyVisibility = false;
433 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700434 }
Jorim Jaggi38d44ec2017-06-14 16:04:59 -0700435
436 // We are becoming visible, so better freeze the screen with the windows that are
437 // getting visible so we also wait for them.
438 forAllWindows(mService::makeWindowFreezingScreenIfNeededLocked, true);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700439 }
440
441 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200442 + ": hidden=" + isHidden() + " hiddenRequested=" + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700443
444 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700445 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700446 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700447 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700448 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700449 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700450 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700451 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700452 }
453 }
454
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200455 if (isReallyAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700456 delayed = true;
Jorim Jaggiab9fcb22018-03-15 23:46:12 +0100457 } else {
458
459 // We aren't animating anything, but exiting windows rely on the animation finished
460 // callback being called in case the AppWindowToken was pretending to be animating,
461 // which we might have done because we were in closing/opening apps list.
462 onAnimationFinished();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700463 }
464
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700465 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Jorim Jaggia5e10572017-11-15 14:36:26 +0100466 if ((mChildren.get(i)).isSelfOrChildAnimating()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700467 delayed = true;
468 }
469 }
470
471 if (visibilityChanged) {
472 if (visible && !delayed) {
473 // The token was made immediately visible, there will be no entrance animation.
474 // We need to inform the client the enter animation was finished.
475 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700476 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700477 }
Robert Carr61b81112017-07-17 18:08:15 -0700478
Jorim Jaggi110839b2018-01-22 12:49:04 +0100479 // If we're becoming visible, immediately change client visibility as well although it
480 // usually gets changed in AppWindowContainerController.setVisibility already. However,
481 // there seem to be some edge cases where we change our visibility but client visibility
482 // never gets updated.
483 // If we're becoming invisible, update the client visibility if we are not running an
484 // animation. Otherwise, we'll update client visibility in onAnimationFinished.
Jorim Jaggi3cad57f2018-02-20 18:32:01 +0100485 if (visible || !isReallyAnimating()) {
Jorim Jaggi110839b2018-01-22 12:49:04 +0100486 setClientHidden(!visible);
Jorim Jaggi4876b4a2018-01-11 15:43:49 +0100487 }
488
chaviwa953fcf2018-03-01 12:00:39 -0800489 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
490 // The token is not closing nor opening, so even if there is an animation set, that
491 // doesn't mean that it goes through the normal app transition cycle so we have
492 // to inform the docked controller about visibility change.
493 // TODO(multi-display): notify docked divider on all displays where visibility was
494 // affected.
495 mService.getDefaultDisplayContentLocked().getDockedDividerController()
496 .notifyAppVisibilityChanged();
497
498 // Take the screenshot before possibly hiding the WSA, otherwise the screenshot
499 // will not be taken.
500 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
501 }
502
Robert Carre7cc44d2017-03-20 19:04:30 -0700503 // If we are hidden but there is no delay needed we immediately
504 // apply the Surface transaction so that the ActivityManager
Robert Carr61b81112017-07-17 18:08:15 -0700505 // can have some guarantee on the Surface state following
506 // setting the visibility. This captures cases like dismissing
507 // the docked or pinned stack where there is no app transition.
508 //
509 // In the case of a "Null" animation, there will be
510 // no animation but there will still be a transition set.
511 // We still need to delay hiding the surface such that it
512 // can be synchronized with showing the next surface in the transition.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200513 if (isHidden() && !delayed && !mService.mAppTransition.isTransitionSet()) {
Robert Carr6914f082017-03-20 19:04:30 -0700514 SurfaceControl.openTransaction();
515 for (int i = mChildren.size() - 1; i >= 0; i--) {
516 mChildren.get(i).mWinAnimator.hide("immediately hidden");
517 }
518 SurfaceControl.closeTransaction();
519 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700520 }
521
522 return delayed;
523 }
524
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +0200525 /**
526 * @return The to top most child window for which {@link LayoutParams#isFullscreen()} returns
527 * true.
528 */
529 WindowState getTopFullscreenWindow() {
530 for (int i = mChildren.size() - 1; i >= 0; i--) {
531 final WindowState win = mChildren.get(i);
532 if (win != null && win.mAttrs.isFullscreen()) {
533 return win;
534 }
535 }
536 return null;
537 }
538
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800539 WindowState findMainWindow() {
Matthew Ng53e66b22018-01-12 17:13:13 -0800540 return findMainWindow(true);
541 }
542
543 /**
544 * Finds the main window that either has type base application or application starting if
545 * requested.
546 *
547 * @param includeStartingApp Allow to search application-starting windows to also be returned.
548 * @return The main window of type base application or application starting if requested.
549 */
550 WindowState findMainWindow(boolean includeStartingApp) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700551 WindowState candidate = null;
Matthew Ng53e66b22018-01-12 17:13:13 -0800552 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700553 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700554 final int type = win.mAttrs.type;
555 // No need to loop through child window as base application and starting types can't be
556 // child windows.
Matthew Ng53e66b22018-01-12 17:13:13 -0800557 if (type == TYPE_BASE_APPLICATION
558 || (includeStartingApp && type == TYPE_APPLICATION_STARTING)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700559 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900560 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700561 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800562 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700563 candidate = win;
564 } else {
565 return win;
566 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800567 }
568 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700569 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800570 }
571
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800572 boolean windowsAreFocusable() {
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700573 return getWindowConfiguration().canReceiveKeys() || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800574 }
575
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800576 AppWindowContainerController getController() {
577 final WindowContainerController controller = super.getController();
578 return controller != null ? (AppWindowContainerController) controller : null;
579 }
580
Wale Ogunwale571771c2016-08-26 13:18:50 -0700581 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700582 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700583 // If the app token isn't hidden then it is considered visible and there is no need to check
584 // its children windows to see if they are visible.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200585 return !isHidden();
Wale Ogunwale44f21802016-09-02 12:49:48 -0700586 }
587
588 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700589 void removeImmediately() {
590 onRemovedFromDisplay();
591 super.removeImmediately();
592 }
593
594 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700595 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800596 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800597 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800598 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800599 }
600
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700601 @Override
602 boolean checkCompleteDeferredRemoval() {
603 if (mIsExiting) {
604 removeIfPossible();
605 }
606 return super.checkCompleteDeferredRemoval();
607 }
608
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700609 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700610 if (mRemovingFromDisplay) {
611 return;
612 }
613 mRemovingFromDisplay = true;
614
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700615 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
616
Wale Ogunwale72919d22016-12-08 18:58:50 -0800617 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700618
619 mService.mOpeningApps.remove(this);
Jorim Jaggi45ca0542017-05-30 16:16:01 -0700620 mService.mUnknownAppVisibilityController.appRemovedOrHidden(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100621 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700622 waitingToShow = false;
623 if (mService.mClosingApps.contains(this)) {
624 delayed = true;
625 } else if (mService.mAppTransition.isTransitionSet()) {
626 mService.mClosingApps.add(this);
627 delayed = true;
628 }
629
630 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200631 + " animation=" + getAnimation() + " animating=" + isSelfAnimating());
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700632
633 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
634 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
635
Jorim Jaggi19be6052017-08-03 18:33:43 +0200636 if (startingData != null && getController() != null) {
637 getController().removeStartingWindow();
638 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800639
Winson Chung87e5d552017-04-05 11:49:38 -0700640 // If this window was animating, then we need to ensure that the app transition notifies
641 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
642 // add to that list now
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200643 if (isSelfAnimating()) {
Winson Chung87e5d552017-04-05 11:49:38 -0700644 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
645 }
646
Wale Ogunwalee287e192017-04-21 09:30:12 -0700647 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700648 if (delayed && !isEmpty()) {
649 // set the token aside because it has an active animation to be finished
650 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
651 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700652 if (stack != null) {
653 stack.mExitingAppTokens.add(this);
654 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700655 mIsExiting = true;
656 } else {
657 // Make sure there is no animation running on this token, so any windows associated
658 // with it will be removed as soon as their animations are complete
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200659 cancelAnimation();
Wale Ogunwale3106ae012017-05-16 08:56:37 -0700660 if (stack != null) {
661 stack.mExitingAppTokens.remove(this);
662 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700663 removeIfPossible();
664 }
665
666 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700667 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800668
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700669 if (mService.mFocusedApp == this) {
670 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
671 mService.mFocusedApp = null;
672 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
673 mService.mInputMonitor.setFocusedAppLw(null);
674 }
675
676 if (!delayed) {
677 updateReportedVisibilityLocked();
678 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700679
680 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700681 }
682
Chong Zhange05bcb12016-07-26 17:47:29 -0700683 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700684 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700685 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700686 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700687 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700688 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700689 if (wallpaperMightChange) {
690 requestUpdateWallpaperIfNeeded();
691 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700692 }
693
Robert Carre12aece2016-02-02 22:43:27 -0800694 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700695 destroySurfaces(false /*cleanupOnResume*/);
696 }
697
698 /**
699 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
700 * the client has finished with them.
701 *
702 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
703 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
704 * others so that they are ready to be reused. If set to false (common case), destroy all
705 * surfaces that's eligible, if the app is already stopped.
706 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700707 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700708 boolean destroyedSomething = false;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100709
710 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +0100711 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
Jorim Jaggia5e10572017-11-15 14:36:26 +0100712 for (int i = children.size() - 1; i >= 0; i--) {
713 final WindowState win = children.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700714 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800715 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700716 if (destroyedSomething) {
717 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700718 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Adrian Roos23df3a32018-03-15 15:41:13 +0100719 updateLetterboxSurface(null);
Robert Carre12aece2016-02-02 22:43:27 -0800720 }
721 }
722
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800723 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700724 * Notify that the app is now resumed, and it was not stopped before, perform a clean
725 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800726 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700727 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700728 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700729 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700730 mAppStopped = false;
chaviwd3bf08d2017-08-01 17:24:59 -0700731 // Allow the window to turn the screen on once the app is resumed again.
732 setCanTurnScreenOn(true);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700733 if (!wasStopped) {
734 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800735 }
Robert Carre12aece2016-02-02 22:43:27 -0800736 }
737
Chong Zhangbef461f2015-10-27 11:38:24 -0700738 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700739 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
740 * keeping alive in case they were still being used.
741 */
742 void notifyAppStopped() {
743 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
744 mAppStopped = true;
745 destroySurfaces();
746 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800747 if (getController() != null) {
748 getController().removeStartingWindow();
749 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700750 }
751
Chong Zhang92147042016-05-09 12:47:11 -0700752 void clearAllDrawn() {
753 allDrawn = false;
754 deferClearAllDrawn = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700755 }
756
Bryce Lee6d410262017-02-28 15:30:17 -0800757 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800758 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800759 }
760
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800761 TaskStack getStack() {
762 final Task task = getTask();
763 if (task != null) {
764 return task.mStack;
765 } else {
766 return null;
767 }
768 }
769
Bryce Lee6d410262017-02-28 15:30:17 -0800770 @Override
771 void onParentSet() {
772 super.onParentSet();
773
Robert Carred3e83b2017-04-21 13:26:55 -0700774 final Task task = getTask();
775
Bryce Lee6d410262017-02-28 15:30:17 -0800776 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
777 // access visual elements like the {@link DisplayContent}. We must remove any associations
778 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800779 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800780 if (task == null) {
781 // It is possible we have been marked as a closing app earlier. We must remove ourselves
782 // from this list so we do not participate in any future animations.
783 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700784 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800785 task.mStack.mExitingAppTokens.remove(this);
786 }
Bryce Lee6d410262017-02-28 15:30:17 -0800787 }
Jorim Jaggi6de61012018-03-19 14:53:23 +0100788 final TaskStack stack = getStack();
789
790 // If we reparent, make sure to remove ourselves from the old animation registry.
791 if (mAnimatingAppWindowTokenRegistry != null) {
792 mAnimatingAppWindowTokenRegistry.notifyFinished(this);
793 }
794 mAnimatingAppWindowTokenRegistry = stack != null
795 ? stack.getAnimatingAppWindowTokenRegistry()
796 : null;
797
Robert Carred3e83b2017-04-21 13:26:55 -0700798 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800799 }
800
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700801 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700802 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700803 if (startingWindow == win) {
804 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800805 if (getController() != null) {
806 getController().removeStartingWindow();
807 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700808 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700809 // If this is the last window and we had requested a starting transition window,
810 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800811 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700812 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700813 if (mHiddenSetFromTransferredStartingWindow) {
814 // We set the hidden state to false for the token from a transferred starting window.
815 // We now reset it back to true since the starting window was the last window in the
816 // token.
Jorim Jaggif5f9e122017-10-24 18:21:09 +0200817 setHidden(true);
Wale Ogunwale6c459212017-05-17 08:56:03 -0700818 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100819 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700820 // If this is the last window except for a starting transition window,
821 // we need to get rid of the starting transition.
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200822 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Last window, removing starting window "
823 + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800824 if (getController() != null) {
825 getController().removeStartingWindow();
826 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700827 }
828 }
829
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700830 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700831 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700832 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800833 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700834 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700835 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800836 // Set mDestroying, we don't want any animation or delayed removal here.
837 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700838 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700839 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800840 }
841 }
842 }
843
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700844 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700845 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700846 // No need to loop through child windows as the answer should be the same as that of the
847 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700848 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700849 return true;
850 }
851 }
852 return false;
853 }
854
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700855 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700856 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
857 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800858
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700859 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700860 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700861 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800862 }
Robert Carra1eb4392015-12-10 12:43:51 -0800863 }
864
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700865 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700866 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800867 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700868 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700869 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700870 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800871 }
872 }
873
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700874 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700875 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
876 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800877
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700878 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700879 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700880 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800881 }
882 }
883
Chong Zhang4d7369a2016-04-25 16:09:14 -0700884 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700885 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700886 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700887 w.requestUpdateWallpaperIfNeeded();
888 }
889 }
890
Chong Zhangd78ddb42016-03-02 17:01:14 -0800891 boolean isRelaunching() {
892 return mPendingRelaunchCount > 0;
893 }
894
Robert Carr68375192017-06-13 12:41:53 -0700895 boolean shouldFreezeBounds() {
896 final Task task = getTask();
897
898 // For freeform windows, we can't freeze the bounds at the moment because this would make
899 // the resizing unresponsive.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700900 if (task == null || task.inFreeformWindowingMode()) {
Robert Carr68375192017-06-13 12:41:53 -0700901 return false;
902 }
903
904 // We freeze the bounds while drag resizing to deal with the time between
905 // the divider/drag handle being released, and the handling it's new
906 // configuration. If we are relaunched outside of the drag resizing state,
907 // we need to be careful not to do this.
908 return getTask().isDragResizing();
909 }
910
Chong Zhangd78ddb42016-03-02 17:01:14 -0800911 void startRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700912 if (shouldFreezeBounds()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -0800913 freezeBounds();
914 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800915
916 // In the process of tearing down before relaunching, the app will
917 // try and clean up it's child surfaces. We need to prevent this from
918 // happening, so we sever the children, transfering their ownership
919 // from the client it-self to the parent surface (owned by us).
Robert Carr29daa922018-04-27 11:56:48 -0700920 detachChildren();
921
922 mPendingRelaunchCount++;
923 }
924
925 void detachChildren() {
Robert Carrfd8e93b2018-05-10 13:40:25 -0700926 SurfaceControl.openTransaction();
Robert Carrd5c7dd62017-03-08 10:39:30 -0800927 for (int i = mChildren.size() - 1; i >= 0; i--) {
928 final WindowState w = mChildren.get(i);
929 w.mWinAnimator.detachChildren();
930 }
Robert Carrfd8e93b2018-05-10 13:40:25 -0700931 SurfaceControl.closeTransaction();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800932 }
933
934 void finishRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700935 unfreezeBounds();
936
Chong Zhangd78ddb42016-03-02 17:01:14 -0800937 if (mPendingRelaunchCount > 0) {
938 mPendingRelaunchCount--;
Bryce Lee081554b2017-05-25 07:52:12 -0700939 } else {
940 // Update keyguard flags upon finishing relaunch.
941 checkKeyguardFlagsChanged();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800942 }
943 }
944
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700945 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700946 if (mPendingRelaunchCount == 0) {
947 return;
948 }
Robert Carr68375192017-06-13 12:41:53 -0700949 unfreezeBounds();
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700950 mPendingRelaunchCount = 0;
951 }
952
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700953 /**
954 * Returns true if the new child window we are adding to this token is considered greater than
955 * the existing child window in this token in terms of z-order.
956 */
957 @Override
958 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
959 WindowState existingWindow) {
960 final int type1 = newWindow.mAttrs.type;
961 final int type2 = existingWindow.mAttrs.type;
962
963 // Base application windows should be z-ordered BELOW all other windows in the app token.
964 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
965 return false;
966 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
967 return true;
968 }
969
970 // Starting windows should be z-ordered ABOVE all other windows in the app token.
971 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
972 return true;
973 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
974 return false;
975 }
976
977 // Otherwise the new window is greater than the existing window.
978 return true;
979 }
980
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700981 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800982 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700983 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700984
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700985 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700986 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700987 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700988 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
989 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700990
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700991 // if we got a replacement window, reset the timeout to give drawing more time
992 if (gotReplacementWindow) {
993 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800994 }
Jorim Jaggife762342016-10-13 14:33:27 +0200995 checkKeyguardFlagsChanged();
996 }
997
998 @Override
999 void removeChild(WindowState child) {
1000 super.removeChild(child);
1001 checkKeyguardFlagsChanged();
Adrian Roos23df3a32018-03-15 15:41:13 +01001002 updateLetterboxSurface(child);
Robert Carra1eb4392015-12-10 12:43:51 -08001003 }
1004
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001005 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001006 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001007 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001008 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -08001009 return true;
1010 }
1011 }
1012 return false;
1013 }
1014
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001015 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001016 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001017 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -08001018 }
1019 }
1020
Winson Chung30480042017-01-26 10:55:34 -08001021 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001022 final Task currentTask = getTask();
1023 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -08001024 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001025 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001026 }
Bryce Lee6d410262017-02-28 15:30:17 -08001027
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001028 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -08001029 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001030 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -08001031 + " belongs to a different stack than " + task);
1032 }
1033
Winson Chung30480042017-01-26 10:55:34 -08001034 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001035 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001036 final DisplayContent prevDisplayContent = getDisplayContent();
1037
Bryce Lee6d410262017-02-28 15:30:17 -08001038 mReparenting = true;
1039
Winson Chung30480042017-01-26 10:55:34 -08001040 getParent().removeChild(this);
1041 task.addChild(this, position);
1042
Bryce Lee6d410262017-02-28 15:30:17 -08001043 mReparenting = false;
1044
Winson Chung30480042017-01-26 10:55:34 -08001045 // Relayout display(s).
1046 final DisplayContent displayContent = task.getDisplayContent();
1047 displayContent.setLayoutNeeded();
1048 if (prevDisplayContent != displayContent) {
1049 onDisplayChanged(displayContent);
1050 prevDisplayContent.setLayoutNeeded();
1051 }
1052 }
1053
Jorim Jaggi0429f352015-12-22 16:29:16 +01001054 /**
1055 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
1056 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
1057 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
1058 * with a queue.
1059 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001060 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001061 final Task task = getTask();
1062 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001063
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001064 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001065 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001066 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001067 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001068 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001069 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001070 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001071 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001072 }
1073
1074 /**
1075 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
1076 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001077 private void unfreezeBounds() {
Robert Carr68375192017-06-13 12:41:53 -07001078 if (mFrozenBounds.isEmpty()) {
1079 return;
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001080 }
Robert Carr68375192017-06-13 12:41:53 -07001081 mFrozenBounds.remove();
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001082 if (!mFrozenMergedConfig.isEmpty()) {
1083 mFrozenMergedConfig.remove();
1084 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001085 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001086 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001087 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001088 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001089 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001090 }
1091
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001092 void setAppLayoutChanges(int changes, String reason) {
1093 if (!mChildren.isEmpty()) {
1094 final DisplayContent dc = getDisplayContent();
1095 dc.pendingLayoutChanges |= changes;
1096 if (DEBUG_LAYOUT_REPEATS) {
1097 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001098 }
1099 }
1100 }
1101
1102 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001103 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001104 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001105 if (win.removeReplacedWindowIfNeeded(replacement)) {
1106 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001107 }
1108 }
1109 }
1110
1111 void startFreezingScreen() {
1112 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001113 + isHidden() + " freezing=" + mFreezingScreen + " hiddenRequested="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001114 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001115 if (!hiddenRequested) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001116 if (!mFreezingScreen) {
1117 mFreezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001118 mService.registerAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001119 mService.mAppsFreezingScreen++;
1120 if (mService.mAppsFreezingScreen == 1) {
Robert Carrae606b42018-02-15 15:36:23 -08001121 mService.startFreezingDisplayLocked(0, 0, getDisplayContent());
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001122 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1123 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001124 }
1125 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001126 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001127 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001128 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001129 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001130 }
1131 }
1132 }
1133
1134 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001135 if (!mFreezingScreen) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001136 return;
1137 }
1138 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001139 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001140 boolean unfrozeWindows = false;
1141 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001142 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001143 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001144 }
1145 if (force || unfrozeWindows) {
1146 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001147 mFreezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001148 mService.unregisterAppFreezeListener(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001149 mService.mAppsFreezingScreen--;
1150 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001151 }
1152 if (unfreezeSurfaceNow) {
1153 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001154 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001155 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001156 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001157 }
1158 }
1159
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001160 @Override
1161 public void onAppFreezeTimeout() {
1162 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1163 stopFreezingScreen(true, true);
1164 }
1165
Jorim Jaggi60f9c972018-02-01 19:21:07 +01001166 /**
1167 * Tries to transfer the starting window from a token that's above ourselves in the task but
1168 * not visible anymore. This is a common scenario apps use: Trampoline activity T start main
1169 * activity M in the same task. Now, when reopening the task, T starts on top of M but then
1170 * immediately finishes after, so we have to transfer T to M.
1171 */
1172 void transferStartingWindowFromHiddenAboveTokenIfNeeded() {
1173 final Task task = getTask();
1174 for (int i = task.mChildren.size() - 1; i >= 0; i--) {
1175 final AppWindowToken fromToken = task.mChildren.get(i);
1176 if (fromToken == this) {
1177 return;
1178 }
1179 if (fromToken.hiddenRequested && transferStartingWindow(fromToken.token)) {
1180 return;
1181 }
1182 }
1183 }
1184
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001185 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001186 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001187 if (fromToken == null) {
1188 return false;
1189 }
1190
1191 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001192 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001193 // In this case, the starting icon has already been displayed, so start
1194 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001195 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001196
1197 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1198 + " from " + fromToken + " to " + this);
1199
1200 final long origId = Binder.clearCallingIdentity();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001201 try {
1202 // Transfer the starting window over to the new token.
1203 startingData = fromToken.startingData;
1204 startingSurface = fromToken.startingSurface;
1205 startingDisplayed = fromToken.startingDisplayed;
1206 fromToken.startingDisplayed = false;
1207 startingWindow = tStartingWindow;
1208 reportedVisible = fromToken.reportedVisible;
1209 fromToken.startingData = null;
1210 fromToken.startingSurface = null;
1211 fromToken.startingWindow = null;
1212 fromToken.startingMoved = true;
1213 tStartingWindow.mToken = this;
1214 tStartingWindow.mAppToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001215
Peter Visontay3556a3b2017-11-01 17:23:17 +00001216 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1217 "Removing starting " + tStartingWindow + " from " + fromToken);
1218 fromToken.removeChild(tStartingWindow);
1219 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
1220 fromToken.mHiddenSetFromTransferredStartingWindow = false;
1221 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001222
Peter Visontay3556a3b2017-11-01 17:23:17 +00001223 // Propagate other interesting state between the tokens. If the old token is displayed,
1224 // we should immediately force the new one to be displayed. If it is animating, we need
1225 // to move that animation to the new one.
1226 if (fromToken.allDrawn) {
1227 allDrawn = true;
1228 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1229 }
1230 if (fromToken.firstWindowDrawn) {
1231 firstWindowDrawn = true;
1232 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001233 if (!fromToken.isHidden()) {
1234 setHidden(false);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001235 hiddenRequested = false;
1236 mHiddenSetFromTransferredStartingWindow = true;
1237 }
1238 setClientHidden(fromToken.mClientHidden);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001239
Jorim Jaggi980c9de2017-11-17 01:41:37 +01001240 transferAnimation(fromToken);
1241
1242 // When transferring an animation, we no longer need to apply an animation to the
1243 // the token we transfer the animation over. Thus, remove the animation from
1244 // pending opening apps.
1245 mService.mOpeningApps.remove(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001246
Peter Visontay3556a3b2017-11-01 17:23:17 +00001247 mService.updateFocusedWindowLocked(
1248 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
1249 getDisplayContent().setLayoutNeeded();
1250 mService.mWindowPlacerLocked.performSurfacePlacement();
1251 } finally {
1252 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001253 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001254 return true;
1255 } else if (fromToken.startingData != null) {
1256 // The previous app was getting ready to show a
1257 // starting window, but hasn't yet done so. Steal it!
1258 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1259 "Moving pending starting from " + fromToken + " to " + this);
1260 startingData = fromToken.startingData;
1261 fromToken.startingData = null;
1262 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001263 if (getController() != null) {
1264 getController().scheduleAddStartingWindow();
1265 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001266 return true;
1267 }
1268
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001269 // TODO: Transfer thumbnail
1270
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001271 return false;
1272 }
1273
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001274 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001275 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001276 }
1277
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001278 @Override
1279 void onAppTransitionDone() {
1280 sendingToBottom = false;
1281 }
1282
Wale Ogunwale51362492016-09-08 17:49:17 -07001283 /**
1284 * We override because this class doesn't want its children affecting its reported orientation
1285 * in anyway.
1286 */
1287 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001288 int getOrientation(int candidate) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001289 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1290 // Allow app to specify orientation regardless of its visibility state if the current
1291 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1292 // wants us to use the orientation of the app behind it.
1293 return mOrientation;
1294 }
1295
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001296 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1297 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1298 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001299 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Andrii Kulian0918d362018-05-23 17:01:37 -07001300 && (isVisible() || mService.mOpeningApps.contains(this))) {
Bryce Leea163b762017-01-24 11:05:01 -08001301 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001302 }
Bryce Leea163b762017-01-24 11:05:01 -08001303
1304 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001305 }
1306
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001307 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1308 int getOrientationIgnoreVisibility() {
1309 return mOrientation;
1310 }
1311
Craig Mautnerdbb79912012-03-01 18:59:14 -08001312 @Override
Winson Chunge55c0192017-08-24 14:50:48 -07001313 public void onConfigurationChanged(Configuration newParentConfig) {
1314 final int prevWinMode = getWindowingMode();
1315 super.onConfigurationChanged(newParentConfig);
1316 final int winMode = getWindowingMode();
1317
1318 if (prevWinMode == winMode) {
1319 return;
1320 }
1321
1322 if (prevWinMode != WINDOWING_MODE_UNDEFINED && winMode == WINDOWING_MODE_PINNED) {
1323 // Entering PiP from fullscreen, reset the snap fraction
1324 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
Winson Chung82267ce2018-04-06 16:38:26 -07001325 } else if (prevWinMode == WINDOWING_MODE_PINNED && winMode != WINDOWING_MODE_UNDEFINED
1326 && !isHidden()) {
Winson Chunge55c0192017-08-24 14:50:48 -07001327 // Leaving PiP to fullscreen, save the snap fraction based on the pre-animation bounds
1328 // for the next re-entry into PiP (assuming the activity is not hidden or destroyed)
1329 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
1330 if (pinnedStack != null) {
1331 mDisplayContent.mPinnedStackControllerLocked.saveReentrySnapFraction(this,
1332 pinnedStack.mPreAnimationBounds);
1333 }
1334 }
1335 }
1336
1337 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001338 void checkAppWindowsReadyToShow() {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001339 if (allDrawn == mLastAllDrawn) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001340 return;
1341 }
1342
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001343 mLastAllDrawn = allDrawn;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001344 if (!allDrawn) {
1345 return;
1346 }
1347
1348 // The token has now changed state to having all windows shown... what to do, what to do?
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001349 if (mFreezingScreen) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001350 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001351 stopFreezingScreen(false, true);
1352 if (DEBUG_ORIENTATION) Slog.i(TAG,
1353 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001354 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001355 // This will set mOrientationChangeComplete and cause a pass through layout.
1356 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001357 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001358 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001359 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001360
1361 // We can now show all of the drawn windows!
1362 if (!mService.mOpeningApps.contains(this)) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001363 showAllWindowsLocked();
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001364 }
1365 }
1366 }
1367
Matthew Ng5d23afa2017-06-21 16:16:24 -07001368 /**
Bryce Leed390deb2017-06-22 13:14:28 -07001369 * Returns whether the drawn window states of this {@link AppWindowToken} has considered every
1370 * child {@link WindowState}. A child is considered if it has been passed into
1371 * {@link #updateDrawnWindowStates(WindowState)} after being added. This is used to determine
1372 * whether states, such as {@code allDrawn}, can be set, which relies on state variables such as
1373 * {@code mNumInterestingWindows}, which depend on all {@link WindowState}s being considered.
1374 *
1375 * @return {@code true} If all children have been considered, {@code false}.
1376 */
1377 private boolean allDrawnStatesConsidered() {
Bryce Lee6311c4b2017-07-06 14:09:29 -07001378 for (int i = mChildren.size() - 1; i >= 0; --i) {
1379 final WindowState child = mChildren.get(i);
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001380 if (child.mightAffectAllDrawn() && !child.getDrawnStateEvaluated()) {
Bryce Leed390deb2017-06-22 13:14:28 -07001381 return false;
1382 }
1383 }
1384 return true;
1385 }
1386
1387 /**
Matthew Ng5d23afa2017-06-21 16:16:24 -07001388 * Determines if the token has finished drawing. This should only be called from
1389 * {@link DisplayContent#applySurfaceChangesTransaction}
1390 */
Matthew Ng498c71d2017-04-18 13:55:45 -07001391 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001392 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001393 // Number of drawn windows can be less when a window is being relaunched, wait for
Bryce Leed390deb2017-06-22 13:14:28 -07001394 // all windows to be launched and drawn for this token be considered all drawn.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001395 final int numInteresting = mNumInterestingWindows;
Bryce Leed390deb2017-06-22 13:14:28 -07001396
1397 // We must make sure that all present children have been considered (determined by
1398 // {@link #allDrawnStatesConsidered}) before evaluating whether everything has been
1399 // drawn.
1400 if (numInteresting > 0 && allDrawnStatesConsidered()
1401 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001402 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001403 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001404 allDrawn = true;
1405 // Force an additional layout pass where
1406 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001407 if (mDisplayContent != null) {
1408 mDisplayContent.setLayoutNeeded();
1409 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001410 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001411
Winson Chunge7ba6862017-05-24 12:13:33 -07001412 // Notify the pinned stack upon all windows drawn. If there was an animation in
1413 // progress then this signal will resume that animation.
Wale Ogunwale61911492017-10-11 08:50:50 -07001414 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
Winson Chunge7ba6862017-05-24 12:13:33 -07001415 if (pinnedStack != null) {
1416 pinnedStack.onAllWindowsDrawn();
Robert Carrecc06b32017-04-18 14:25:10 -07001417 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001418 }
1419 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001420 }
1421
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001422 /**
1423 * Updated this app token tracking states for interesting and drawn windows based on the window.
1424 *
1425 * @return Returns true if the input window is considered interesting and drawn while all the
1426 * windows in this app token where not considered drawn as of the last pass.
1427 */
1428 boolean updateDrawnWindowStates(WindowState w) {
Bryce Leed390deb2017-06-22 13:14:28 -07001429 w.setDrawnStateEvaluated(true /*evaluated*/);
1430
Jorim Jaggie4b0f282017-05-17 15:10:29 +02001431 if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001432 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001433 + " allDrawn=" + allDrawn + " freezingScreen=" + mFreezingScreen);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001434 }
1435
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001436 if (allDrawn && !mFreezingScreen) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001437 return false;
1438 }
1439
1440 if (mLastTransactionSequence != mService.mTransactionSequence) {
1441 mLastTransactionSequence = mService.mTransactionSequence;
Matthew Ng53e66b22018-01-12 17:13:13 -08001442 mNumDrawnWindows = 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001443 startingDisplayed = false;
Matthew Ng53e66b22018-01-12 17:13:13 -08001444
1445 // There is the main base application window, even if it is exiting, wait for it
1446 mNumInterestingWindows = findMainWindow(false /* includeStartingApp */) != null ? 1 : 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001447 }
1448
1449 final WindowStateAnimator winAnimator = w.mWinAnimator;
1450
1451 boolean isInterestingAndDrawn = false;
1452
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001453 if (!allDrawn && w.mightAffectAllDrawn()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001454 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1455 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001456 + ", isAnimationSet=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001457 if (!w.isDrawnLw()) {
1458 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1459 + " pv=" + w.mPolicyVisibility
1460 + " mDrawState=" + winAnimator.drawStateToString()
1461 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001462 + " a=" + isSelfAnimating());
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001463 }
1464 }
1465
1466 if (w != startingWindow) {
1467 if (w.isInteresting()) {
Matthew Ng53e66b22018-01-12 17:13:13 -08001468 // Add non-main window as interesting since the main app has already been added
1469 if (findMainWindow(false /* includeStartingApp */) != w) {
1470 mNumInterestingWindows++;
1471 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001472 if (w.isDrawnLw()) {
1473 mNumDrawnWindows++;
1474
1475 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1476 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001477 + " freezingScreen=" + mFreezingScreen
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001478 + " mAppFreezing=" + w.mAppFreezing);
1479
1480 isInterestingAndDrawn = true;
1481 }
1482 }
1483 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001484 if (getController() != null) {
1485 getController().reportStartingWindowDrawn();
1486 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001487 startingDisplayed = true;
1488 }
1489 }
1490
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001491 return isInterestingAndDrawn;
1492 }
1493
Adrian Roos23df3a32018-03-15 15:41:13 +01001494 void layoutLetterbox(WindowState winHint) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001495 final WindowState w = findMainWindow();
Adrian Roosf93b6d22018-03-21 13:48:26 +01001496 if (w == null || winHint != null && w != winHint) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001497 return;
1498 }
Jorim Jaggia32da382018-03-28 18:01:22 +02001499 final boolean surfaceReady = w.isDrawnLw() // Regular case
Adrian Roosf93b6d22018-03-21 13:48:26 +01001500 || w.mWinAnimator.mSurfaceDestroyDeferred // The preserved surface is still ready.
1501 || w.isDragResizeChanged(); // Waiting for relayoutWindow to call preserveSurface.
1502 final boolean needsLetterbox = w.isLetterboxedAppWindow() && fillsParent() && surfaceReady;
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001503 if (needsLetterbox) {
1504 if (mLetterbox == null) {
1505 mLetterbox = new Letterbox(() -> makeChildSurface(null));
1506 }
Adrian Roos23df3a32018-03-15 15:41:13 +01001507 mLetterbox.layout(getParent().getBounds(), w.mFrame);
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001508 } else if (mLetterbox != null) {
Adrian Roos23df3a32018-03-15 15:41:13 +01001509 mLetterbox.hide();
1510 }
1511 }
1512
1513 void updateLetterboxSurface(WindowState winHint) {
1514 final WindowState w = findMainWindow();
1515 if (w != winHint && winHint != null && w != null) {
1516 return;
1517 }
1518 layoutLetterbox(winHint);
1519 if (mLetterbox != null && mLetterbox.needsApplySurfaceChanges()) {
1520 mLetterbox.applySurfaceChanges(mPendingTransaction);
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001521 }
1522 }
1523
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001524 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001525 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001526 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1527 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1528 // TODO: Investigate if we need to continue to do this or if we can just process them
1529 // in-order.
1530 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001531 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001532 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001533 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001534 }
1535
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001536 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1537 boolean traverseTopToBottom) {
1538 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001539 }
1540
1541 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001542 AppWindowToken asAppWindowToken() {
1543 // I am an app window token!
1544 return this;
1545 }
1546
1547 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001548 boolean fillsParent() {
1549 return mFillsParent;
1550 }
1551
1552 void setFillsParent(boolean fillsParent) {
1553 mFillsParent = fillsParent;
1554 }
1555
Jorim Jaggife762342016-10-13 14:33:27 +02001556 boolean containsDismissKeyguardWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001557 // Window state is transient during relaunch. We are not guaranteed to be frozen during the
1558 // entirety of the relaunch.
1559 if (isRelaunching()) {
1560 return mLastContainsDismissKeyguardWindow;
1561 }
1562
Jorim Jaggife762342016-10-13 14:33:27 +02001563 for (int i = mChildren.size() - 1; i >= 0; i--) {
1564 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1565 return true;
1566 }
1567 }
1568 return false;
1569 }
1570
1571 boolean containsShowWhenLockedWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001572 // When we are relaunching, it is possible for us to be unfrozen before our previous
1573 // windows have been added back. Using the cached value ensures that our previous
1574 // showWhenLocked preference is honored until relaunching is complete.
1575 if (isRelaunching()) {
1576 return mLastContainsShowWhenLockedWindow;
1577 }
1578
Jorim Jaggife762342016-10-13 14:33:27 +02001579 for (int i = mChildren.size() - 1; i >= 0; i--) {
1580 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1581 return true;
1582 }
1583 }
Bryce Lee081554b2017-05-25 07:52:12 -07001584
Jorim Jaggife762342016-10-13 14:33:27 +02001585 return false;
1586 }
1587
1588 void checkKeyguardFlagsChanged() {
1589 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1590 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1591 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1592 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1593 mService.notifyKeyguardFlagsChanged(null /* callback */);
1594 }
1595 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1596 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1597 }
1598
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001599 WindowState getImeTargetBelowWindow(WindowState w) {
1600 final int index = mChildren.indexOf(w);
1601 if (index > 0) {
1602 final WindowState target = mChildren.get(index - 1);
1603 if (target.canBeImeTarget()) {
1604 return target;
1605 }
1606 }
1607 return null;
1608 }
1609
Winson Chungbe9be7f2017-06-28 10:55:22 -07001610 int getLowestAnimLayer() {
1611 for (int i = 0; i < mChildren.size(); i++) {
1612 final WindowState w = mChildren.get(i);
1613 if (w.mRemoved) {
1614 continue;
1615 }
1616 return w.mWinAnimator.mAnimLayer;
1617 }
1618 return Integer.MAX_VALUE;
1619 }
1620
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001621 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1622 WindowState candidate = null;
1623 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1624 final WindowState w = mChildren.get(i);
1625 if (w.mRemoved) {
1626 continue;
1627 }
1628 if (candidate == null || w.mWinAnimator.mAnimLayer >
1629 candidate.mWinAnimator.mAnimLayer) {
1630 candidate = w;
1631 }
1632 }
1633 return candidate;
1634 }
1635
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001636 /**
1637 * See {@link Activity#setDisablePreviewScreenshots}.
1638 */
1639 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001640 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001641 }
1642
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001643 /**
chaviwd3bf08d2017-08-01 17:24:59 -07001644 * Sets whether the current launch can turn the screen on. See {@link #canTurnScreenOn()}
1645 */
1646 void setCanTurnScreenOn(boolean canTurnScreenOn) {
1647 mCanTurnScreenOn = canTurnScreenOn;
1648 }
1649
1650 /**
1651 * Indicates whether the current launch can turn the screen on. This is to prevent multiple
1652 * relayouts from turning the screen back on. The screen should only turn on at most
1653 * once per activity resume.
1654 *
1655 * @return true if the screen can be turned on.
1656 */
1657 boolean canTurnScreenOn() {
1658 return mCanTurnScreenOn;
1659 }
1660
1661 /**
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001662 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1663 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1664 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1665 *
1666 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1667 * screenshot.
1668 */
1669 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001670 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001671 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001672 }
1673
Jorim Jaggibe418292018-03-26 16:14:12 +02001674 SurfaceControl getAppAnimationLayer() {
Jorim Jaggi391790622018-04-18 15:30:44 +02001675 return getAppAnimationLayer(isActivityTypeHome() ? ANIMATION_LAYER_HOME
1676 : needsZBoost() ? ANIMATION_LAYER_BOOSTED
1677 : ANIMATION_LAYER_STANDARD);
Jorim Jaggibe418292018-03-26 16:14:12 +02001678 }
1679
chaviw23ee71c2017-12-18 11:29:41 -08001680 @Override
Jorim Jaggi596a1992017-12-29 14:48:02 +01001681 public SurfaceControl getAnimationLeashParent() {
Robert Carrb9506032018-02-13 13:54:00 -08001682 // All normal app transitions take place in an animation layer which is below the pinned
1683 // stack but may be above the parent stacks of the given animating apps.
1684 // For transitions in the pinned stack (menu activity) we just let them occur as a child
1685 // of the pinned stack.
1686 if (!inPinnedWindowingMode()) {
1687 return getAppAnimationLayer();
1688 } else {
1689 return getStack().getSurfaceControl();
1690 }
chaviw23ee71c2017-12-18 11:29:41 -08001691 }
1692
Jorim Jaggic6976f02018-04-18 16:31:07 +02001693 private boolean shouldAnimate(int transit) {
1694 final boolean isSplitScreenPrimary =
1695 getWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
1696 final boolean allowSplitScreenPrimaryAnimation = transit != TRANSIT_WALLPAPER_OPEN;
1697
1698 // We animate always if it's not split screen primary, and only some special cases in split
1699 // screen primary because it causes issues with stack clipping when we run an un-minimize
1700 // animation at the same time.
1701 return !isSplitScreenPrimary || allowSplitScreenPrimaryAnimation;
1702 }
1703
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001704 boolean applyAnimationLocked(WindowManager.LayoutParams lp, int transit, boolean enter,
1705 boolean isVoiceInteraction) {
1706
Jorim Jaggic6976f02018-04-18 16:31:07 +02001707 if (mService.mDisableTransitionAnimation || !shouldAnimate(transit)) {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001708 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
Jorim Jaggic6976f02018-04-18 16:31:07 +02001709 Slog.v(TAG_WM, "applyAnimation: transition animation is disabled or skipped."
1710 + " atoken=" + this);
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001711 }
1712 cancelAnimation();
1713 return false;
1714 }
1715
1716 // Only apply an animation if the display isn't frozen. If it is frozen, there is no reason
1717 // to animate and it can cause strange artifacts when we unfreeze the display if some
1718 // different animation is running.
1719 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "AWT#applyAnimationLocked");
1720 if (okToAnimate()) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001721 final AnimationAdapter adapter;
1722 final TaskStack stack = getStack();
1723 mTmpPoint.set(0, 0);
1724 mTmpRect.setEmpty();
1725 if (stack != null) {
1726 stack.getRelativePosition(mTmpPoint);
1727 stack.getBounds(mTmpRect);
1728 mTmpRect.offsetTo(0, 0);
1729 }
Jorim Jaggic4d29f22018-03-22 16:30:56 +01001730
1731 // Delaying animation start isn't compatible with remote animations at all.
1732 if (mService.mAppTransition.getRemoteAnimationController() != null
1733 && !mSurfaceAnimator.isAnimationStartDelayed()) {
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001734 adapter = mService.mAppTransition.getRemoteAnimationController()
1735 .createAnimationAdapter(this, mTmpPoint, mTmpRect);
1736 } else {
1737 final Animation a = loadAnimation(lp, transit, enter, isVoiceInteraction);
1738 if (a != null) {
1739 adapter = new LocalAnimationAdapter(
1740 new WindowAnimationSpec(a, mTmpPoint, mTmpRect,
1741 mService.mAppTransition.canSkipFirstFrame(),
Jorim Jaggiaa763cd2018-03-22 23:20:36 +01001742 mService.mAppTransition.getAppStackClipMode(),
1743 true /* isAppAnimation */),
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001744 mService.mSurfaceAnimationRunner);
1745 if (a.getZAdjustment() == Animation.ZORDER_TOP) {
1746 mNeedsZBoost = true;
1747 }
1748 mTransit = transit;
1749 mTransitFlags = mService.mAppTransition.getTransitFlags();
1750 } else {
1751 adapter = null;
chaviw23ee71c2017-12-18 11:29:41 -08001752 }
Jorim Jaggi33a701a2017-12-01 14:58:18 +01001753 }
1754 if (adapter != null) {
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001755 startAnimation(getPendingTransaction(), adapter, !isVisible());
Jorim Jaggi82c17862018-02-21 17:50:18 +01001756 if (adapter.getShowWallpaper()) {
1757 mDisplayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
1758 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001759 }
1760 } else {
1761 cancelAnimation();
1762 }
1763 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
1764
1765 return isReallyAnimating();
1766 }
1767
1768 private Animation loadAnimation(WindowManager.LayoutParams lp, int transit, boolean enter,
1769 boolean isVoiceInteraction) {
1770 final DisplayContent displayContent = getTask().getDisplayContent();
1771 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
1772 final int width = displayInfo.appWidth;
1773 final int height = displayInfo.appHeight;
1774 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG_WM,
1775 "applyAnimation: atoken=" + this);
1776
1777 // Determine the visible rect to calculate the thumbnail clip
1778 final WindowState win = findMainWindow();
1779 final Rect frame = new Rect(0, 0, width, height);
1780 final Rect displayFrame = new Rect(0, 0,
1781 displayInfo.logicalWidth, displayInfo.logicalHeight);
1782 final Rect insets = new Rect();
1783 final Rect stableInsets = new Rect();
1784 Rect surfaceInsets = null;
1785 final boolean freeform = win != null && win.inFreeformWindowingMode();
1786 if (win != null) {
1787 // Containing frame will usually cover the whole screen, including dialog windows.
1788 // For freeform workspace windows it will not cover the whole screen and it also
1789 // won't exactly match the final freeform window frame (e.g. when overlapping with
1790 // the status bar). In that case we need to use the final frame.
1791 if (freeform) {
1792 frame.set(win.mFrame);
Adrian Roos4d18a2e2017-12-19 19:08:05 +01001793 } else if (win.isLetterboxedAppWindow()) {
1794 frame.set(getTask().getBounds());
Winson Chungc1674272018-02-21 10:15:17 -08001795 } else if (win.isDockedResizing()) {
1796 // If we are animating while docked resizing, then use the stack bounds as the
1797 // animation target (which will be different than the task bounds)
1798 frame.set(getTask().getParent().getBounds());
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001799 } else {
1800 frame.set(win.mContainingFrame);
1801 }
1802 surfaceInsets = win.getAttrs().surfaceInsets;
Adrian Roos20e07892018-02-23 19:12:01 +01001803 // XXX(b/72757033): These are insets relative to the window frame, but we're really
1804 // interested in the insets relative to the frame we chose in the if-blocks above.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001805 insets.set(win.mContentInsets);
1806 stableInsets.set(win.mStableInsets);
1807 }
1808
1809 if (mLaunchTaskBehind) {
1810 // Differentiate the two animations. This one which is briefly on the screen
1811 // gets the !enter animation, and the other activity which remains on the
1812 // screen gets the enter animation. Both appear in the mOpeningApps set.
1813 enter = false;
1814 }
1815 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG_WM, "Loading animation for app transition."
1816 + " transit=" + AppTransition.appTransitionToString(transit) + " enter=" + enter
1817 + " frame=" + frame + " insets=" + insets + " surfaceInsets=" + surfaceInsets);
1818 final Configuration displayConfig = displayContent.getConfiguration();
1819 final Animation a = mService.mAppTransition.loadAnimation(lp, transit, enter,
1820 displayConfig.uiMode, displayConfig.orientation, frame, displayFrame, insets,
1821 surfaceInsets, stableInsets, isVoiceInteraction, freeform, getTask().mTaskId);
1822 if (a != null) {
1823 if (DEBUG_ANIM) logWithStack(TAG, "Loaded animation " + a + " for " + this);
1824 final int containingWidth = frame.width();
1825 final int containingHeight = frame.height();
1826 a.initialize(containingWidth, containingHeight, width, height);
1827 a.scaleCurrentDuration(mService.getTransitionAnimationScaleLocked());
1828 }
1829 return a;
1830 }
1831
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001832 @Override
Jorim Jaggi6de61012018-03-19 14:53:23 +01001833 public boolean shouldDeferAnimationFinish(Runnable endDeferFinishCallback) {
1834 return mAnimatingAppWindowTokenRegistry != null
1835 && mAnimatingAppWindowTokenRegistry.notifyAboutToFinish(
1836 this, endDeferFinishCallback);
1837 }
1838
1839 @Override
1840 public void onAnimationLeashDestroyed(Transaction t) {
1841 super.onAnimationLeashDestroyed(t);
1842 if (mAnimatingAppWindowTokenRegistry != null) {
1843 mAnimatingAppWindowTokenRegistry.notifyFinished(this);
1844 }
1845 }
1846
1847 @Override
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001848 protected void setLayer(Transaction t, int layer) {
1849 if (!mSurfaceAnimator.hasLeash()) {
1850 t.setLayer(mSurfaceControl, layer);
1851 }
1852 }
1853
1854 @Override
1855 protected void setRelativeLayer(Transaction t, SurfaceControl relativeTo, int layer) {
1856 if (!mSurfaceAnimator.hasLeash()) {
1857 t.setRelativeLayer(mSurfaceControl, relativeTo, layer);
1858 }
1859 }
1860
1861 @Override
1862 protected void reparentSurfaceControl(Transaction t, SurfaceControl newParent) {
1863 if (!mSurfaceAnimator.hasLeash()) {
1864 t.reparent(mSurfaceControl, newParent.getHandle());
1865 }
1866 }
1867
1868 @Override
1869 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001870 // The leash is parented to the animation layer. We need to preserve the z-order by using
1871 // the prefix order index, but we boost if necessary.
Robert Carrb9506032018-02-13 13:54:00 -08001872 int layer = 0;
1873 if (!inPinnedWindowingMode()) {
1874 layer = getPrefixOrderIndex();
1875 } else {
1876 // Pinned stacks have animations take place within themselves rather than an animation
1877 // layer so we need to preserve the order relative to the stack (e.g. the order of our
1878 // task/parent).
1879 layer = getParent().getPrefixOrderIndex();
1880 }
1881
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001882 if (mNeedsZBoost) {
1883 layer += Z_BOOST_BASE;
1884 }
1885 leash.setLayer(layer);
Robert Carr2f8aa392018-01-31 14:46:51 -08001886
1887 final DisplayContent dc = getDisplayContent();
Jorim Jaggibe418292018-03-26 16:14:12 +02001888 dc.assignStackOrdering();
Jorim Jaggi6de61012018-03-19 14:53:23 +01001889 if (mAnimatingAppWindowTokenRegistry != null) {
1890 mAnimatingAppWindowTokenRegistry.notifyStarting(this);
1891 }
Jorim Jaggi619c9f72017-12-19 18:04:29 +01001892 }
1893
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001894 /**
1895 * This must be called while inside a transaction.
1896 */
1897 void showAllWindowsLocked() {
1898 forAllWindows(windowState -> {
1899 if (DEBUG_VISIBILITY) Slog.v(TAG, "performing show on: " + windowState);
1900 windowState.performShowLocked();
1901 }, false /* traverseTopToBottom */);
Jorim Jaggia5e10572017-11-15 14:36:26 +01001902 }
1903
1904 @Override
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001905 protected void onAnimationFinished() {
1906 super.onAnimationFinished();
1907
1908 mTransit = TRANSIT_UNSET;
1909 mTransitFlags = 0;
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001910 mNeedsZBoost = false;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001911
1912 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM | FINISH_LAYOUT_REDO_WALLPAPER,
1913 "AppWindowToken");
1914
Jorim Jaggi988f6682017-11-17 17:46:43 +01001915 clearThumbnail();
Jorim Jaggi752cd822018-03-29 16:29:18 +02001916 setClientHidden(isHidden() && hiddenRequested);
Jorim Jaggi988f6682017-11-17 17:46:43 +01001917
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001918 if (mService.mInputMethodTarget != null && mService.mInputMethodTarget.mAppToken == this) {
1919 getDisplayContent().computeImeTarget(true /* updateImeTarget */);
1920 }
1921
1922 if (DEBUG_ANIM) Slog.v(TAG, "Animation done in " + this
1923 + ": reportedVisible=" + reportedVisible
1924 + " okToDisplay=" + okToDisplay()
1925 + " okToAnimate=" + okToAnimate()
1926 + " startingDisplayed=" + startingDisplayed);
1927
1928 // WindowState.onExitAnimationDone might modify the children list, so make a copy and then
1929 // traverse the copy.
1930 final ArrayList<WindowState> children = new ArrayList<>(mChildren);
1931 children.forEach(WindowState::onExitAnimationDone);
1932
1933 mService.mAppTransition.notifyAppTransitionFinishedLocked(token);
1934 scheduleAnimation();
1935 }
1936
1937 @Override
1938 boolean isAppAnimating() {
1939 return isSelfAnimating();
1940 }
1941
1942 @Override
1943 boolean isSelfAnimating() {
1944 // If we are about to start a transition, we also need to be considered animating.
1945 return isWaitingForTransitionStart() || isReallyAnimating();
1946 }
1947
1948 /**
1949 * @return True if and only if we are actually running an animation. Note that
1950 * {@link #isSelfAnimating} also returns true if we are waiting for an animation to
1951 * start.
1952 */
1953 private boolean isReallyAnimating() {
1954 return super.isSelfAnimating();
1955 }
1956
Jorim Jaggi988f6682017-11-17 17:46:43 +01001957 @Override
1958 void cancelAnimation() {
1959 super.cancelAnimation();
1960 clearThumbnail();
1961 }
1962
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001963 boolean isWaitingForTransitionStart() {
1964 return mService.mAppTransition.isTransitionSet()
1965 && (mService.mOpeningApps.contains(this) || mService.mClosingApps.contains(this));
1966 }
1967
1968 public int getTransit() {
1969 return mTransit;
1970 }
1971
1972 int getTransitFlags() {
1973 return mTransitFlags;
1974 }
1975
Jorim Jaggi988f6682017-11-17 17:46:43 +01001976 void attachThumbnailAnimation() {
1977 if (!isReallyAnimating()) {
1978 return;
1979 }
1980 final int taskId = getTask().mTaskId;
1981 final GraphicBuffer thumbnailHeader =
1982 mService.mAppTransition.getAppTransitionThumbnailHeader(taskId);
1983 if (thumbnailHeader == null) {
1984 if (DEBUG_APP_TRANSITIONS) Slog.d(TAG, "No thumbnail header bitmap for: " + taskId);
1985 return;
1986 }
1987 clearThumbnail();
1988 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnailHeader);
1989 mThumbnail.startAnimation(getPendingTransaction(), loadThumbnailAnimation(thumbnailHeader));
1990 }
1991
Tony Mak64b8d562017-12-28 17:44:02 +00001992 /**
1993 * Attaches a surface with a thumbnail for the
1994 * {@link android.app.ActivityOptions#ANIM_OPEN_CROSS_PROFILE_APPS} animation.
1995 */
1996 void attachCrossProfileAppsThumbnailAnimation() {
1997 if (!isReallyAnimating()) {
1998 return;
1999 }
2000 clearThumbnail();
2001
2002 final WindowState win = findMainWindow();
2003 if (win == null) {
2004 return;
2005 }
2006 final Rect frame = win.mFrame;
2007 final int thumbnailDrawableRes = getTask().mUserId == mService.mCurrentUserId
2008 ? R.drawable.ic_account_circle
Tony Makda4af232018-04-27 11:01:10 +01002009 : R.drawable.ic_corp_badge;
Tony Mak64b8d562017-12-28 17:44:02 +00002010 final GraphicBuffer thumbnail =
2011 mService.mAppTransition
2012 .createCrossProfileAppsThumbnail(thumbnailDrawableRes, frame);
2013 if (thumbnail == null) {
2014 return;
2015 }
2016 mThumbnail = new AppWindowThumbnail(getPendingTransaction(), this, thumbnail);
2017 final Animation animation =
2018 mService.mAppTransition.createCrossProfileAppsThumbnailAnimationLocked(win.mFrame);
2019 mThumbnail.startAnimation(getPendingTransaction(), animation, new Point(frame.left,
2020 frame.top));
2021 }
2022
Jorim Jaggi988f6682017-11-17 17:46:43 +01002023 private Animation loadThumbnailAnimation(GraphicBuffer thumbnailHeader) {
2024 final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
2025
2026 // If this is a multi-window scenario, we use the windows frame as
2027 // destination of the thumbnail header animation. If this is a full screen
2028 // window scenario, we use the whole display as the target.
2029 WindowState win = findMainWindow();
2030 Rect appRect = win != null ? win.getContentFrameLw() :
2031 new Rect(0, 0, displayInfo.appWidth, displayInfo.appHeight);
2032 Rect insets = win != null ? win.mContentInsets : null;
2033 final Configuration displayConfig = mDisplayContent.getConfiguration();
2034 return mService.mAppTransition.createThumbnailAspectScaleAnimationLocked(
2035 appRect, insets, thumbnailHeader, getTask().mTaskId, displayConfig.uiMode,
2036 displayConfig.orientation);
2037 }
2038
2039 private void clearThumbnail() {
2040 if (mThumbnail == null) {
2041 return;
2042 }
2043 mThumbnail.destroy();
2044 mThumbnail = null;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002045 }
2046
Jorim Jaggif84e2f62018-01-16 14:17:59 +01002047 void registerRemoteAnimations(RemoteAnimationDefinition definition) {
2048 mRemoteAnimationDefinition = definition;
2049 }
2050
2051 RemoteAnimationDefinition getRemoteAnimationDefinition() {
2052 return mRemoteAnimationDefinition;
2053 }
2054
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002055 @Override
2056 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
2057 super.dump(pw, prefix, dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002058 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08002059 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002060 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08002061 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07002062 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
2063 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07002064 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
2065 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
2066 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07002067 if (paused) {
2068 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002069 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08002070 if (mAppStopped) {
2071 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
2072 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07002073 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002074 || allDrawn || mLastAllDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07002075 pw.print(prefix); pw.print("mNumInterestingWindows=");
2076 pw.print(mNumInterestingWindows);
2077 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002078 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07002079 pw.print(" allDrawn="); pw.print(allDrawn);
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002080 pw.print(" lastAllDrawn="); pw.print(mLastAllDrawn);
Craig Mautner6fbda632012-07-03 09:26:39 -07002081 pw.println(")");
2082 }
2083 if (inPendingTransaction) {
2084 pw.print(prefix); pw.print("inPendingTransaction=");
2085 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002086 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08002087 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002088 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
2089 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08002090 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08002091 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002092 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002093 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07002094 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002095 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08002096 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002097 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07002098 pw.print(" startingMoved="); pw.print(startingMoved);
2099 pw.println(" mHiddenSetFromTransferredStartingWindow="
2100 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002101 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01002102 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08002103 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002104 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08002105 }
2106 if (mPendingRelaunchCount != 0) {
2107 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01002108 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07002109 if (getController() != null) {
2110 pw.print(prefix); pw.print("controller="); pw.println(getController());
2111 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07002112 if (mRemovingFromDisplay) {
2113 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
2114 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002115 }
2116
2117 @Override
2118 void setHidden(boolean hidden) {
2119 super.setHidden(hidden);
Winson Chunge55c0192017-08-24 14:50:48 -07002120
2121 if (hidden) {
2122 // Once the app window is hidden, reset the last saved PiP snap fraction
2123 mDisplayContent.mPinnedStackControllerLocked.resetReentrySnapFraction(this);
2124 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002125 scheduleAnimation();
2126 }
2127
2128 @Override
2129 void prepareSurfaces() {
2130 // isSelfAnimating also returns true when we are about to start a transition, so we need
2131 // to check super here.
2132 final boolean reallyAnimating = super.isSelfAnimating();
2133 final boolean show = !isHidden() || reallyAnimating;
2134 if (show && !mLastSurfaceShowing) {
2135 mPendingTransaction.show(mSurfaceControl);
2136 } else if (!show && mLastSurfaceShowing) {
2137 mPendingTransaction.hide(mSurfaceControl);
Jorim Jaggi4d1835d2017-08-31 17:28:27 +02002138 }
Jorim Jaggi988f6682017-11-17 17:46:43 +01002139 if (mThumbnail != null) {
2140 mThumbnail.setShowing(mPendingTransaction, show);
2141 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002142 mLastSurfaceShowing = show;
2143 super.prepareSurfaces();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002144 }
2145
Jorim Jaggi77d0f36c2018-03-16 17:49:49 +01002146 /**
2147 * @return Whether our {@link #getSurfaceControl} is currently showing.
2148 */
2149 boolean isSurfaceShowing() {
2150 return mLastSurfaceShowing;
2151 }
2152
Jorim Jaggib0fc8172017-11-23 17:04:08 +00002153 boolean isFreezingScreen() {
2154 return mFreezingScreen;
2155 }
2156
2157 @Override
2158 boolean needsZBoost() {
2159 return mNeedsZBoost || super.needsZBoost();
2160 }
2161
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07002162 @CallSuper
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002163 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02002164 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07002165 final long token = proto.start(fieldId);
2166 writeNameToProto(proto, NAME);
Adrian Roos4921ccf2017-09-28 16:54:06 +02002167 super.writeToProto(proto, WINDOW_TOKEN, trim);
Vishnu Nair04ab4392018-01-10 11:00:06 -08002168 proto.write(LAST_SURFACE_SHOWING, mLastSurfaceShowing);
2169 proto.write(IS_WAITING_FOR_TRANSITION_START, isWaitingForTransitionStart());
2170 proto.write(IS_REALLY_ANIMATING, isReallyAnimating());
2171 if (mThumbnail != null){
2172 mThumbnail.writeToProto(proto, THUMBNAIL);
2173 }
2174 proto.write(FILLS_PARENT, mFillsParent);
2175 proto.write(APP_STOPPED, mAppStopped);
2176 proto.write(HIDDEN_REQUESTED, hiddenRequested);
2177 proto.write(CLIENT_HIDDEN, mClientHidden);
2178 proto.write(DEFER_HIDING_CLIENT, mDeferHidingClient);
2179 proto.write(REPORTED_DRAWN, reportedDrawn);
2180 proto.write(REPORTED_VISIBLE, reportedVisible);
2181 proto.write(NUM_INTERESTING_WINDOWS, mNumInterestingWindows);
2182 proto.write(NUM_DRAWN_WINDOWS, mNumDrawnWindows);
2183 proto.write(ALL_DRAWN, allDrawn);
2184 proto.write(LAST_ALL_DRAWN, mLastAllDrawn);
2185 proto.write(REMOVED, removed);
2186 if (startingWindow != null){
2187 startingWindow.writeIdentifierToProto(proto, STARTING_WINDOW);
2188 }
2189 proto.write(STARTING_DISPLAYED, startingDisplayed);
2190 proto.write(STARTING_MOVED, startingMoved);
2191 proto.write(HIDDEN_SET_FROM_TRANSFERRED_STARTING_WINDOW,
2192 mHiddenSetFromTransferredStartingWindow);
2193 for (Rect bounds : mFrozenBounds) {
2194 bounds.writeToProto(proto, FROZEN_BOUNDS);
2195 }
Steven Timotiusaf03df62017-07-18 16:56:43 -07002196 proto.end(token);
2197 }
2198
2199 void writeNameToProto(ProtoOutputStream proto, long fieldId) {
2200 if (appToken == null) {
2201 return;
2202 }
2203 try {
2204 proto.write(fieldId, appToken.getName());
2205 } catch (RemoteException e) {
2206 // This shouldn't happen, but in this case fall back to outputting nothing
2207 Slog.e(TAG, e.toString());
2208 }
2209 }
2210
2211 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002212 public String toString() {
2213 if (stringName == null) {
2214 StringBuilder sb = new StringBuilder();
2215 sb.append("AppWindowToken{");
2216 sb.append(Integer.toHexString(System.identityHashCode(this)));
2217 sb.append(" token="); sb.append(token); sb.append('}');
2218 stringName = sb.toString();
2219 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07002220 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002221 }
Adrian Roos20e07892018-02-23 19:12:01 +01002222
2223 Rect getLetterboxInsets() {
2224 if (mLetterbox != null) {
2225 return mLetterbox.getInsets();
2226 } else {
2227 return new Rect();
2228 }
2229 }
Adrian Roos23df3a32018-03-15 15:41:13 +01002230
2231 /**
2232 * @eturn true if there is a letterbox and any part of that letterbox overlaps with
2233 * the given {@code rect}.
2234 */
2235 boolean isLetterboxOverlappingWith(Rect rect) {
2236 return mLetterbox != null && mLetterbox.isOverlappingWith(rect);
2237 }
Jeff Browne9bdb312012-04-05 15:30:10 -07002238}