blob: 627f8cee3fd16e10c59ec1f0cd54196a4293ff7d [file] [log] [blame]
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Wale Ogunwale72919d22016-12-08 18:58:50 -080019import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
20import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070021import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
Wale Ogunwale51362492016-09-08 17:49:17 -070022import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070023import static android.view.Display.DEFAULT_DISPLAY;
Jorim Jaggife762342016-10-13 14:33:27 +020024import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020025import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Jorim Jaggife762342016-10-13 14:33:27 +020026import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070027import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080028import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070029import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Adrian Roose99bc052017-11-20 17:55:31 +010030import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
31import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070032import static com.android.server.wm.AppTransition.TRANSIT_UNSET;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080033import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080034import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
35import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070036import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070037import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
38import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080039import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020040import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070041import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080042import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
43import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
44import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
45import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070046import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070047import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070048import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070049import static com.android.server.wm.WindowManagerService.logWithStack;
Steven Timotiusaf03df62017-07-18 16:56:43 -070050import static com.android.server.wm.proto.AppWindowTokenProto.NAME;
51import static com.android.server.wm.proto.AppWindowTokenProto.WINDOW_TOKEN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080052
Wale Ogunwale0d5609b2017-09-13 05:55:07 -070053import android.annotation.CallSuper;
Filip Gruszczynskia590c992015-11-25 16:45:26 -080054import android.annotation.NonNull;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020055import android.app.Activity;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070056import android.content.res.Configuration;
Jorim Jaggi0429f352015-12-22 16:29:16 +010057import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070058import android.os.Binder;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080059import android.os.Debug;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070060import android.os.IBinder;
Steven Timotiusaf03df62017-07-18 16:56:43 -070061import android.os.RemoteException;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070062import android.os.SystemClock;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080063import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -070064import android.util.proto.ProtoOutputStream;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080065import android.view.IApplicationToken;
Robert Carr6914f082017-03-20 19:04:30 -070066import android.view.SurfaceControl;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080067import android.view.WindowManager;
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +020068import android.view.WindowManager.LayoutParams;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080069
70import com.android.internal.util.ToBooleanFunction;
71import com.android.server.input.InputApplicationHandle;
Adrian Roose99bc052017-11-20 17:55:31 +010072import com.android.server.policy.WindowManagerPolicy.StartingSurface;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080073import com.android.server.wm.WindowManagerService.H;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080074
75import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010076import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080077import java.util.ArrayList;
78
79class AppTokenList extends ArrayList<AppWindowToken> {
80}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080081
82/**
83 * Version of WindowToken that is specifically for a particular application (or
84 * really activity) that is displaying windows.
85 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070086class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080087 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
88
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080089 // Non-null only for application tokens.
90 final IApplicationToken appToken;
91
Filip Gruszczynskia590c992015-11-25 16:45:26 -080092 @NonNull final AppWindowAnimator mAppAnimator;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070093
Wale Ogunwale72919d22016-12-08 18:58:50 -080094 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -070095
Wale Ogunwale51362492016-09-08 17:49:17 -070096 /** @see WindowContainer#fillsParent() */
97 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -080098 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -080099 boolean mShowForAllUsers;
100 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -0700101
Bryce Lee6d410262017-02-28 15:30:17 -0800102 // Flag set while reparenting to prevent actions normally triggered by an individual parent
103 // change.
104 private boolean mReparenting;
105
Wale Ogunwalee287e192017-04-21 09:30:12 -0700106 // True if we are current in the process of removing this app token from the display
107 private boolean mRemovingFromDisplay = false;
108
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800109 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -0800110 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800111
112 // These are used for determining when all windows associated with
113 // an activity have been drawn, so they can be made visible together
114 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700115 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700116 private long mLastTransactionSequence = Long.MIN_VALUE;
117 private int mNumInterestingWindows;
118 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800119 boolean inPendingTransaction;
120 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -0800121 // Set to true when this app creates a surface while in the middle of an animation. In that
122 // case do not clear allDrawn until the animation completes.
123 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800124
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800125 // Is this window's surface needed? This is almost like hidden, except
126 // it will sometimes be true a little earlier: when the token has
127 // been shown, but is still waiting for its app transition to execute
128 // before making its windows shown.
129 boolean hiddenRequested;
130
131 // Have we told the window clients to hide themselves?
Wale Ogunwale89973222017-04-23 18:39:45 -0700132 private boolean mClientHidden;
133
134 // If true we will defer setting mClientHidden to true and reporting to the client that it is
135 // hidden.
136 boolean mDeferHidingClient;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800137
138 // Last visibility state we reported to the app token.
139 boolean reportedVisible;
140
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700141 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700142 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700143
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800144 // Set to true when the token has been removed from the window mgr.
145 boolean removed;
146
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800147 // Information about an application starting window if displayed.
148 StartingData startingData;
149 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800150 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800151 boolean startingDisplayed;
152 boolean startingMoved;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700153 // True if the hidden state of this token was forced to false due to a transferred starting
154 // window.
155 private boolean mHiddenSetFromTransferredStartingWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800156 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700157 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
158 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800159
160 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700161 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800162
Wale Ogunwale571771c2016-08-26 13:18:50 -0700163 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800164 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800165
Craig Mautnerbb742462014-07-07 15:28:55 -0700166 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700167 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700168
Wale Ogunwale72919d22016-12-08 18:58:50 -0800169 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800170
Robert Carre12aece2016-02-02 22:43:27 -0800171 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700172 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700173 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800174
Jorim Jaggife762342016-10-13 14:33:27 +0200175 private boolean mLastContainsShowWhenLockedWindow;
176 private boolean mLastContainsDismissKeyguardWindow;
177
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700178 // The bounds of this activity. Mainly used for aspect-ratio compatibility.
179 // TODO(b/36505427): Every level on WindowContainer now has bounds information, which directly
180 // affects the configuration. We should probably move this into that class.
181 private final Rect mBounds = new Rect();
182
Jorim Jaggi0429f352015-12-22 16:29:16 +0100183 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700184 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100185
Wale Ogunwale6c459212017-05-17 08:56:03 -0700186 private boolean mDisablePreviewScreenshots;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100187
Wale Ogunwale034a8ec2017-09-02 17:14:40 -0700188 private Task mLastParent;
Robert Carred3e83b2017-04-21 13:26:55 -0700189
chaviwd3bf08d2017-08-01 17:24:59 -0700190 /**
191 * See {@link #canTurnScreenOn()}
192 */
193 private boolean mCanTurnScreenOn = true;
194
Wale Ogunwale72919d22016-12-08 18:58:50 -0800195 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
196 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
197 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800198 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Wale Ogunwale034a8ec2017-09-02 17:14:40 -0700199 AppWindowContainerController controller, Rect bounds) {
200 this(service, token, voiceInteraction, dc, fullscreen, bounds);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800201 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800202 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800203 mShowForAllUsers = showForAllUsers;
204 mTargetSdk = targetSdk;
205 mOrientation = orientation;
206 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
207 mLaunchTaskBehind = launchTaskBehind;
208 mAlwaysFocusable = alwaysFocusable;
209 mRotationAnimationHint = rotationAnimationHint;
210
211 // Application tokens start out hidden.
212 hidden = true;
213 hiddenRequested = true;
214 }
215
216 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Wale Ogunwale034a8ec2017-09-02 17:14:40 -0700217 DisplayContent dc, boolean fillsParent, Rect bounds) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800218 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
219 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700220 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800221 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800222 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800223 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700224 mAppAnimator = new AppWindowAnimator(this, service);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700225 if (bounds != null) {
226 mBounds.set(bounds);
227 }
228 }
229
230 void onOverrideConfigurationChanged(Configuration overrideConfiguration, Rect bounds) {
231 onOverrideConfigurationChanged(overrideConfiguration);
232 if (mBounds.equals(bounds)) {
233 return;
234 }
235 // TODO(b/36505427): If bounds is in WC, then we can automatically call onResize() when set.
236 mBounds.set(bounds);
237 onResize();
238 }
239
240 void getBounds(Rect outBounds) {
241 outBounds.set(mBounds);
242 }
243
244 boolean hasBounds() {
245 return !mBounds.isEmpty();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800246 }
247
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800248 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
249 firstWindowDrawn = true;
250
251 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700252 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800253
Jorim Jaggi02886a82016-12-06 09:10:06 -0800254 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800255 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
256 + win.mToken + ": first real window is shown, no animation");
257 // If this initial window is animating, stop it -- we will do an animation to reveal
258 // it from behind the starting window, so there is no need for it to also be doing its
259 // own stuff.
260 winAnimator.clearAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800261 if (getController() != null) {
262 getController().removeStartingWindow();
263 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800264 }
265 updateReportedVisibilityLocked();
266 }
267
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800268 void updateReportedVisibilityLocked() {
269 if (appToken == null) {
270 return;
271 }
272
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700273 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700274 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800275
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700276 mReportedVisibilityResults.reset();
277
278 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700279 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700280 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800281 }
282
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700283 int numInteresting = mReportedVisibilityResults.numInteresting;
284 int numVisible = mReportedVisibilityResults.numVisible;
285 int numDrawn = mReportedVisibilityResults.numDrawn;
286 boolean nowGone = mReportedVisibilityResults.nowGone;
287
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700288 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Jorim Jaggi6dfd9ba2017-08-03 15:00:01 +0200289 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting && !hidden;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700290 if (!nowGone) {
291 // If the app is not yet gone, then it can only become visible/drawn.
292 if (!nowDrawn) {
293 nowDrawn = reportedDrawn;
294 }
295 if (!nowVisible) {
296 nowVisible = reportedVisible;
297 }
298 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800299 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800300 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800301 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700302 if (nowDrawn != reportedDrawn) {
303 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800304 if (controller != null) {
305 controller.reportWindowsDrawn();
306 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700307 }
308 reportedDrawn = nowDrawn;
309 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800310 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700311 if (DEBUG_VISIBILITY) Slog.v(TAG,
312 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800313 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800314 if (controller != null) {
315 if (nowVisible) {
316 controller.reportWindowsVisible();
317 } else {
318 controller.reportWindowsGone();
319 }
320 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800321 }
322 }
323
Wale Ogunwale89973222017-04-23 18:39:45 -0700324 boolean isClientHidden() {
325 return mClientHidden;
326 }
327
328 void setClientHidden(boolean hideClient) {
329 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
330 return;
331 }
332 mClientHidden = hideClient;
333 sendAppVisibilityToClients();
334 }
335
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700336 boolean setVisibility(WindowManager.LayoutParams lp,
337 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
338
339 boolean delayed = false;
340 inPendingTransaction = false;
Wale Ogunwale9e4721f2017-05-23 19:37:30 -0700341 // Reset the state of mHiddenSetFromTransferredStartingWindow since visibility is actually
342 // been set by the app now.
343 mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale89973222017-04-23 18:39:45 -0700344 setClientHidden(!visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700345
346 // Allow for state changes and animation to be applied if:
347 // * token is transitioning visibility state
348 // * or the token was marked as hidden and is exiting before we had a chance to play the
349 // transition animation
350 // * or this is an opening app and windows are being replaced.
351 boolean visibilityChanged = false;
352 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700353 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700354 boolean changed = false;
355 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
356 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
357
358 boolean runningAppAnimation = false;
359
Jorim Jaggi4d1835d2017-08-31 17:28:27 +0200360 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
361 mAppAnimator.setNullAnimation();
362 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700363 if (transit != AppTransition.TRANSIT_UNSET) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700364 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700365 delayed = runningAppAnimation = true;
366 }
367 final WindowState window = findMainWindow();
368 //TODO (multidisplay): Magnification is supported only for the default display.
369 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700370 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700371 accessibilityController.onAppWindowTransitionLocked(window, transit);
372 }
373 changed = true;
374 }
375
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700376 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700377 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700378 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700379 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700380 }
381
382 hidden = hiddenRequested = !visible;
383 visibilityChanged = true;
384 if (!visible) {
385 stopFreezingScreen(true, true);
386 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700387 // If we are being set visible, and the starting window is not yet displayed,
388 // then make sure it doesn't get displayed.
389 if (startingWindow != null && !startingWindow.isDrawnLw()) {
390 startingWindow.mPolicyVisibility = false;
391 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700392 }
Jorim Jaggi38d44ec2017-06-14 16:04:59 -0700393
394 // We are becoming visible, so better freeze the screen with the windows that are
395 // getting visible so we also wait for them.
396 forAllWindows(mService::makeWindowFreezingScreenIfNeededLocked, true);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700397 }
398
399 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
400 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
401
402 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700403 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700404 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700405 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700406 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700407 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700408 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700409 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700410 }
411 }
412
413 if (mAppAnimator.animation != null) {
414 delayed = true;
415 }
416
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700417 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700418 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700419 delayed = true;
420 }
421 }
422
423 if (visibilityChanged) {
424 if (visible && !delayed) {
425 // The token was made immediately visible, there will be no entrance animation.
426 // We need to inform the client the enter animation was finished.
427 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700428 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700429 }
Robert Carr61b81112017-07-17 18:08:15 -0700430
Robert Carre7cc44d2017-03-20 19:04:30 -0700431 // If we are hidden but there is no delay needed we immediately
432 // apply the Surface transaction so that the ActivityManager
Robert Carr61b81112017-07-17 18:08:15 -0700433 // can have some guarantee on the Surface state following
434 // setting the visibility. This captures cases like dismissing
435 // the docked or pinned stack where there is no app transition.
436 //
437 // In the case of a "Null" animation, there will be
438 // no animation but there will still be a transition set.
439 // We still need to delay hiding the surface such that it
440 // can be synchronized with showing the next surface in the transition.
441 if (hidden && !delayed && !mService.mAppTransition.isTransitionSet()) {
Robert Carr6914f082017-03-20 19:04:30 -0700442 SurfaceControl.openTransaction();
443 for (int i = mChildren.size() - 1; i >= 0; i--) {
444 mChildren.get(i).mWinAnimator.hide("immediately hidden");
445 }
446 SurfaceControl.closeTransaction();
447 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700448
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700449 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700450 // The token is not closing nor opening, so even if there is an animation set, that
451 // doesn't mean that it goes through the normal app transition cycle so we have
452 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700453 // TODO(multi-display): notify docked divider on all displays where visibility was
454 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700455 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700456 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100457 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700458 }
459 }
460
461 return delayed;
462 }
463
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +0200464 /**
465 * @return The to top most child window for which {@link LayoutParams#isFullscreen()} returns
466 * true.
467 */
468 WindowState getTopFullscreenWindow() {
469 for (int i = mChildren.size() - 1; i >= 0; i--) {
470 final WindowState win = mChildren.get(i);
471 if (win != null && win.mAttrs.isFullscreen()) {
472 return win;
473 }
474 }
475 return null;
476 }
477
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800478 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700479 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700480 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800481 while (j > 0) {
482 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700483 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700484 final int type = win.mAttrs.type;
485 // No need to loop through child window as base application and starting types can't be
486 // child windows.
487 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700488 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900489 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700490 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800491 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700492 candidate = win;
493 } else {
494 return win;
495 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800496 }
497 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700498 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800499 }
500
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800501 boolean windowsAreFocusable() {
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700502 return getWindowConfiguration().canReceiveKeys() || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800503 }
504
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800505 AppWindowContainerController getController() {
506 final WindowContainerController controller = super.getController();
507 return controller != null ? (AppWindowContainerController) controller : null;
508 }
509
Wale Ogunwale571771c2016-08-26 13:18:50 -0700510 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700511 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700512 // If the app token isn't hidden then it is considered visible and there is no need to check
513 // its children windows to see if they are visible.
514 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700515 }
516
517 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700518 void removeImmediately() {
519 onRemovedFromDisplay();
520 super.removeImmediately();
521 }
522
523 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700524 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800525 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800526 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800527 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800528 }
529
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700530 @Override
531 boolean checkCompleteDeferredRemoval() {
532 if (mIsExiting) {
533 removeIfPossible();
534 }
535 return super.checkCompleteDeferredRemoval();
536 }
537
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700538 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700539 if (mRemovingFromDisplay) {
540 return;
541 }
542 mRemovingFromDisplay = true;
543
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700544 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
545
Wale Ogunwale72919d22016-12-08 18:58:50 -0800546 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700547
548 mService.mOpeningApps.remove(this);
Jorim Jaggi45ca0542017-05-30 16:16:01 -0700549 mService.mUnknownAppVisibilityController.appRemovedOrHidden(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100550 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700551 waitingToShow = false;
552 if (mService.mClosingApps.contains(this)) {
553 delayed = true;
554 } else if (mService.mAppTransition.isTransitionSet()) {
555 mService.mClosingApps.add(this);
556 delayed = true;
557 }
558
559 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
560 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
561
562 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
563 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
564
Jorim Jaggi19be6052017-08-03 18:33:43 +0200565 if (startingData != null && getController() != null) {
566 getController().removeStartingWindow();
567 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800568
Winson Chung87e5d552017-04-05 11:49:38 -0700569 // If this window was animating, then we need to ensure that the app transition notifies
570 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
571 // add to that list now
572 if (mAppAnimator.animating) {
573 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
574 }
575
Wale Ogunwalee287e192017-04-21 09:30:12 -0700576 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700577 if (delayed && !isEmpty()) {
578 // set the token aside because it has an active animation to be finished
579 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
580 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700581 if (stack != null) {
582 stack.mExitingAppTokens.add(this);
583 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700584 mIsExiting = true;
585 } else {
586 // Make sure there is no animation running on this token, so any windows associated
587 // with it will be removed as soon as their animations are complete
588 mAppAnimator.clearAnimation();
589 mAppAnimator.animating = false;
Wale Ogunwale3106ae012017-05-16 08:56:37 -0700590 if (stack != null) {
591 stack.mExitingAppTokens.remove(this);
592 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700593 removeIfPossible();
594 }
595
596 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700597 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800598
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700599 if (mService.mFocusedApp == this) {
600 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
601 mService.mFocusedApp = null;
602 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
603 mService.mInputMonitor.setFocusedAppLw(null);
604 }
605
606 if (!delayed) {
607 updateReportedVisibilityLocked();
608 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700609
610 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700611 }
612
Chong Zhange05bcb12016-07-26 17:47:29 -0700613 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700614 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700615 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700616 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700617 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700618 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700619 if (wallpaperMightChange) {
620 requestUpdateWallpaperIfNeeded();
621 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700622 }
623
Robert Carre12aece2016-02-02 22:43:27 -0800624 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700625 destroySurfaces(false /*cleanupOnResume*/);
626 }
627
628 /**
629 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
630 * the client has finished with them.
631 *
632 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
633 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
634 * others so that they are ready to be reused. If set to false (common case), destroy all
635 * surfaces that's eligible, if the app is already stopped.
636 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700637 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700638 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700639 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700640 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700641 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800642 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700643 if (destroyedSomething) {
644 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700645 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800646 }
647 }
648
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800649 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700650 * Notify that the app is now resumed, and it was not stopped before, perform a clean
651 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800652 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700653 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700654 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700655 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700656 mAppStopped = false;
chaviwd3bf08d2017-08-01 17:24:59 -0700657 // Allow the window to turn the screen on once the app is resumed again.
658 setCanTurnScreenOn(true);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700659 if (!wasStopped) {
660 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800661 }
Robert Carre12aece2016-02-02 22:43:27 -0800662 }
663
Chong Zhangbef461f2015-10-27 11:38:24 -0700664 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700665 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
666 * keeping alive in case they were still being used.
667 */
668 void notifyAppStopped() {
669 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
670 mAppStopped = true;
671 destroySurfaces();
672 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800673 if (getController() != null) {
674 getController().removeStartingWindow();
675 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700676 }
677
Chong Zhang92147042016-05-09 12:47:11 -0700678 void clearAllDrawn() {
679 allDrawn = false;
680 deferClearAllDrawn = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700681 }
682
Bryce Lee6d410262017-02-28 15:30:17 -0800683 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800684 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800685 }
686
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800687 TaskStack getStack() {
688 final Task task = getTask();
689 if (task != null) {
690 return task.mStack;
691 } else {
692 return null;
693 }
694 }
695
Bryce Lee6d410262017-02-28 15:30:17 -0800696 @Override
697 void onParentSet() {
698 super.onParentSet();
699
Robert Carred3e83b2017-04-21 13:26:55 -0700700 final Task task = getTask();
701
Bryce Lee6d410262017-02-28 15:30:17 -0800702 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
703 // access visual elements like the {@link DisplayContent}. We must remove any associations
704 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800705 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800706 if (task == null) {
707 // It is possible we have been marked as a closing app earlier. We must remove ourselves
708 // from this list so we do not participate in any future animations.
709 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700710 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800711 task.mStack.mExitingAppTokens.remove(this);
712 }
Bryce Lee6d410262017-02-28 15:30:17 -0800713 }
Robert Carred3e83b2017-04-21 13:26:55 -0700714 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800715 }
716
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700717 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700718 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700719 if (startingWindow == win) {
720 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800721 if (getController() != null) {
722 getController().removeStartingWindow();
723 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700724 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700725 // If this is the last window and we had requested a starting transition window,
726 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800727 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700728 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700729 if (mHiddenSetFromTransferredStartingWindow) {
730 // We set the hidden state to false for the token from a transferred starting window.
731 // We now reset it back to true since the starting window was the last window in the
732 // token.
733 hidden = true;
734 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100735 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700736 // If this is the last window except for a starting transition window,
737 // we need to get rid of the starting transition.
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200738 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Last window, removing starting window "
739 + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800740 if (getController() != null) {
741 getController().removeStartingWindow();
742 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700743 }
744 }
745
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700746 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700747 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700748 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800749 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700750 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700751 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800752 // Set mDestroying, we don't want any animation or delayed removal here.
753 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700754 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700755 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800756 }
757 }
758 }
759
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700760 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700761 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700762 // No need to loop through child windows as the answer should be the same as that of the
763 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700764 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700765 return true;
766 }
767 }
768 return false;
769 }
770
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700771 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700772 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
773 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800774
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700775 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700776 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700777 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800778 }
779 if (animate) {
780 // Set-up dummy animation so we can start treating windows associated with this
781 // token like they are in transition before the new app window is ready for us to
782 // run the real transition animation.
783 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700784 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800785 mAppAnimator.setDummyAnimation();
786 }
787 }
788
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700789 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700790 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800791 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700792 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700793 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700794 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800795 }
796 }
797
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700798 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700799 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
800 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800801
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700802 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700803 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700804 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800805 }
806 }
807
Chong Zhang4d7369a2016-04-25 16:09:14 -0700808 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700809 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700810 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700811 w.requestUpdateWallpaperIfNeeded();
812 }
813 }
814
Chong Zhangd78ddb42016-03-02 17:01:14 -0800815 boolean isRelaunching() {
816 return mPendingRelaunchCount > 0;
817 }
818
Robert Carr68375192017-06-13 12:41:53 -0700819 boolean shouldFreezeBounds() {
820 final Task task = getTask();
821
822 // For freeform windows, we can't freeze the bounds at the moment because this would make
823 // the resizing unresponsive.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700824 if (task == null || task.inFreeformWindowingMode()) {
Robert Carr68375192017-06-13 12:41:53 -0700825 return false;
826 }
827
828 // We freeze the bounds while drag resizing to deal with the time between
829 // the divider/drag handle being released, and the handling it's new
830 // configuration. If we are relaunched outside of the drag resizing state,
831 // we need to be careful not to do this.
832 return getTask().isDragResizing();
833 }
834
Chong Zhangd78ddb42016-03-02 17:01:14 -0800835 void startRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700836 if (shouldFreezeBounds()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -0800837 freezeBounds();
838 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800839
840 // In the process of tearing down before relaunching, the app will
841 // try and clean up it's child surfaces. We need to prevent this from
842 // happening, so we sever the children, transfering their ownership
843 // from the client it-self to the parent surface (owned by us).
844 for (int i = mChildren.size() - 1; i >= 0; i--) {
845 final WindowState w = mChildren.get(i);
846 w.mWinAnimator.detachChildren();
847 }
848
Chong Zhangd78ddb42016-03-02 17:01:14 -0800849 mPendingRelaunchCount++;
850 }
851
852 void finishRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700853 unfreezeBounds();
854
Chong Zhangd78ddb42016-03-02 17:01:14 -0800855 if (mPendingRelaunchCount > 0) {
856 mPendingRelaunchCount--;
Bryce Lee081554b2017-05-25 07:52:12 -0700857 } else {
858 // Update keyguard flags upon finishing relaunch.
859 checkKeyguardFlagsChanged();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800860 }
861 }
862
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700863 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700864 if (mPendingRelaunchCount == 0) {
865 return;
866 }
Robert Carr68375192017-06-13 12:41:53 -0700867 unfreezeBounds();
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700868 mPendingRelaunchCount = 0;
869 }
870
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700871 /**
872 * Returns true if the new child window we are adding to this token is considered greater than
873 * the existing child window in this token in terms of z-order.
874 */
875 @Override
876 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
877 WindowState existingWindow) {
878 final int type1 = newWindow.mAttrs.type;
879 final int type2 = existingWindow.mAttrs.type;
880
881 // Base application windows should be z-ordered BELOW all other windows in the app token.
882 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
883 return false;
884 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
885 return true;
886 }
887
888 // Starting windows should be z-ordered ABOVE all other windows in the app token.
889 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
890 return true;
891 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
892 return false;
893 }
894
895 // Otherwise the new window is greater than the existing window.
896 return true;
897 }
898
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700899 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800900 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700901 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700902
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700903 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700904 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700905 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700906 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
907 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700908
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700909 // if we got a replacement window, reset the timeout to give drawing more time
910 if (gotReplacementWindow) {
911 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800912 }
Jorim Jaggife762342016-10-13 14:33:27 +0200913 checkKeyguardFlagsChanged();
914 }
915
916 @Override
917 void removeChild(WindowState child) {
918 super.removeChild(child);
919 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800920 }
921
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700922 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700923 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700924 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700925 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800926 return true;
927 }
928 }
929 return false;
930 }
931
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700932 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700933 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700934 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800935 }
936 }
937
Winson Chung30480042017-01-26 10:55:34 -0800938 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800939 final Task currentTask = getTask();
940 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -0800941 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800942 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800943 }
Bryce Lee6d410262017-02-28 15:30:17 -0800944
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800945 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -0800946 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800947 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -0800948 + " belongs to a different stack than " + task);
949 }
950
Winson Chung30480042017-01-26 10:55:34 -0800951 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800952 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800953 final DisplayContent prevDisplayContent = getDisplayContent();
954
Bryce Lee6d410262017-02-28 15:30:17 -0800955 mReparenting = true;
956
Winson Chung30480042017-01-26 10:55:34 -0800957 getParent().removeChild(this);
958 task.addChild(this, position);
959
Bryce Lee6d410262017-02-28 15:30:17 -0800960 mReparenting = false;
961
Winson Chung30480042017-01-26 10:55:34 -0800962 // Relayout display(s).
963 final DisplayContent displayContent = task.getDisplayContent();
964 displayContent.setLayoutNeeded();
965 if (prevDisplayContent != displayContent) {
966 onDisplayChanged(displayContent);
967 prevDisplayContent.setLayoutNeeded();
968 }
969 }
970
Jorim Jaggi0429f352015-12-22 16:29:16 +0100971 /**
972 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
973 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
974 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
975 * with a queue.
976 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800977 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800978 final Task task = getTask();
979 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700980
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800981 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700982 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800983 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700984 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800985 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700986 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700987 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800988 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100989 }
990
991 /**
992 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
993 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800994 private void unfreezeBounds() {
Robert Carr68375192017-06-13 12:41:53 -0700995 if (mFrozenBounds.isEmpty()) {
996 return;
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700997 }
Robert Carr68375192017-06-13 12:41:53 -0700998 mFrozenBounds.remove();
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700999 if (!mFrozenMergedConfig.isEmpty()) {
1000 mFrozenMergedConfig.remove();
1001 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001002 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001003 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001004 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001005 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001006 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001007 }
1008
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001009 void setAppLayoutChanges(int changes, String reason) {
1010 if (!mChildren.isEmpty()) {
1011 final DisplayContent dc = getDisplayContent();
1012 dc.pendingLayoutChanges |= changes;
1013 if (DEBUG_LAYOUT_REPEATS) {
1014 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001015 }
1016 }
1017 }
1018
1019 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001020 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001021 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001022 if (win.removeReplacedWindowIfNeeded(replacement)) {
1023 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001024 }
1025 }
1026 }
1027
1028 void startFreezingScreen() {
1029 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001030 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
1031 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001032 if (!hiddenRequested) {
1033 if (!mAppAnimator.freezingScreen) {
1034 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001035 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001036 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001037 mService.mAppsFreezingScreen++;
1038 if (mService.mAppsFreezingScreen == 1) {
Bryce Lee8f853582017-06-05 17:25:59 -07001039 mService.startFreezingDisplayLocked(false, 0, 0, getDisplayContent());
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001040 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1041 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001042 }
1043 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001044 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001045 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001046 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001047 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001048 }
1049 }
1050 }
1051
1052 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
1053 if (!mAppAnimator.freezingScreen) {
1054 return;
1055 }
1056 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001057 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001058 boolean unfrozeWindows = false;
1059 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001060 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001061 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001062 }
1063 if (force || unfrozeWindows) {
1064 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
1065 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001066 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001067 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001068 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
1069 mService.mAppsFreezingScreen--;
1070 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001071 }
1072 if (unfreezeSurfaceNow) {
1073 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001074 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001075 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001076 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001077 }
1078 }
1079
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001080 @Override
1081 public void onAppFreezeTimeout() {
1082 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1083 stopFreezingScreen(true, true);
1084 }
1085
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001086 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001087 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001088 if (fromToken == null) {
1089 return false;
1090 }
1091
1092 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001093 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001094 // In this case, the starting icon has already been displayed, so start
1095 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001096 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001097
1098 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1099 + " from " + fromToken + " to " + this);
1100
1101 final long origId = Binder.clearCallingIdentity();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001102 try {
1103 // Transfer the starting window over to the new token.
1104 startingData = fromToken.startingData;
1105 startingSurface = fromToken.startingSurface;
1106 startingDisplayed = fromToken.startingDisplayed;
1107 fromToken.startingDisplayed = false;
1108 startingWindow = tStartingWindow;
1109 reportedVisible = fromToken.reportedVisible;
1110 fromToken.startingData = null;
1111 fromToken.startingSurface = null;
1112 fromToken.startingWindow = null;
1113 fromToken.startingMoved = true;
1114 tStartingWindow.mToken = this;
1115 tStartingWindow.mAppToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001116
Peter Visontay3556a3b2017-11-01 17:23:17 +00001117 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1118 "Removing starting " + tStartingWindow + " from " + fromToken);
1119 fromToken.removeChild(tStartingWindow);
1120 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
1121 fromToken.mHiddenSetFromTransferredStartingWindow = false;
1122 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001123
Peter Visontay3556a3b2017-11-01 17:23:17 +00001124 // Propagate other interesting state between the tokens. If the old token is displayed,
1125 // we should immediately force the new one to be displayed. If it is animating, we need
1126 // to move that animation to the new one.
1127 if (fromToken.allDrawn) {
1128 allDrawn = true;
1129 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1130 }
1131 if (fromToken.firstWindowDrawn) {
1132 firstWindowDrawn = true;
1133 }
1134 if (!fromToken.hidden) {
1135 hidden = false;
1136 hiddenRequested = false;
1137 mHiddenSetFromTransferredStartingWindow = true;
1138 }
1139 setClientHidden(fromToken.mClientHidden);
1140 fromToken.mAppAnimator.transferCurrentAnimation(
1141 mAppAnimator, tStartingWindow.mWinAnimator);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001142
Peter Visontay3556a3b2017-11-01 17:23:17 +00001143 mService.updateFocusedWindowLocked(
1144 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
1145 getDisplayContent().setLayoutNeeded();
1146 mService.mWindowPlacerLocked.performSurfacePlacement();
1147 } finally {
1148 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001149 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001150 return true;
1151 } else if (fromToken.startingData != null) {
1152 // The previous app was getting ready to show a
1153 // starting window, but hasn't yet done so. Steal it!
1154 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1155 "Moving pending starting from " + fromToken + " to " + this);
1156 startingData = fromToken.startingData;
1157 fromToken.startingData = null;
1158 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001159 if (getController() != null) {
1160 getController().scheduleAddStartingWindow();
1161 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001162 return true;
1163 }
1164
1165 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1166 final AppWindowAnimator wAppAnimator = mAppAnimator;
1167 if (tAppAnimator.thumbnail != null) {
1168 // The old token is animating with a thumbnail, transfer that to the new token.
1169 if (wAppAnimator.thumbnail != null) {
1170 wAppAnimator.thumbnail.destroy();
1171 }
1172 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001173 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1174 tAppAnimator.thumbnail = null;
1175 }
1176 return false;
1177 }
1178
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001179 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001180 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001181 }
1182
1183 void setAllAppWinAnimators() {
1184 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1185 allAppWinAnimators.clear();
1186
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001187 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001188 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001189 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001190 }
1191 }
1192
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001193 @Override
1194 void onAppTransitionDone() {
1195 sendingToBottom = false;
1196 }
1197
Wale Ogunwale51362492016-09-08 17:49:17 -07001198 /**
1199 * We override because this class doesn't want its children affecting its reported orientation
1200 * in anyway.
1201 */
1202 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001203 int getOrientation(int candidate) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001204 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1205 // Allow app to specify orientation regardless of its visibility state if the current
1206 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1207 // wants us to use the orientation of the app behind it.
1208 return mOrientation;
1209 }
1210
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001211 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1212 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1213 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001214 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee00d586d2017-07-28 20:48:43 -07001215 && (isVisible() || mService.mOpeningApps.contains(this) || isOnTop())) {
Bryce Leea163b762017-01-24 11:05:01 -08001216 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001217 }
Bryce Leea163b762017-01-24 11:05:01 -08001218
1219 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001220 }
1221
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001222 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1223 int getOrientationIgnoreVisibility() {
1224 return mOrientation;
1225 }
1226
Craig Mautnerdbb79912012-03-01 18:59:14 -08001227 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001228 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001229 if (allDrawn == mAppAnimator.allDrawn) {
1230 return;
1231 }
1232
1233 mAppAnimator.allDrawn = allDrawn;
1234 if (!allDrawn) {
1235 return;
1236 }
1237
1238 // The token has now changed state to having all windows shown... what to do, what to do?
1239 if (mAppAnimator.freezingScreen) {
1240 mAppAnimator.showAllWindowsLocked();
1241 stopFreezingScreen(false, true);
1242 if (DEBUG_ORIENTATION) Slog.i(TAG,
1243 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001244 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001245 // This will set mOrientationChangeComplete and cause a pass through layout.
1246 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001247 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001248 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001249 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001250
1251 // We can now show all of the drawn windows!
1252 if (!mService.mOpeningApps.contains(this)) {
1253 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1254 }
1255 }
1256 }
1257
Matthew Ng5d23afa2017-06-21 16:16:24 -07001258 /**
Bryce Leed390deb2017-06-22 13:14:28 -07001259 * Returns whether the drawn window states of this {@link AppWindowToken} has considered every
1260 * child {@link WindowState}. A child is considered if it has been passed into
1261 * {@link #updateDrawnWindowStates(WindowState)} after being added. This is used to determine
1262 * whether states, such as {@code allDrawn}, can be set, which relies on state variables such as
1263 * {@code mNumInterestingWindows}, which depend on all {@link WindowState}s being considered.
1264 *
1265 * @return {@code true} If all children have been considered, {@code false}.
1266 */
1267 private boolean allDrawnStatesConsidered() {
Bryce Lee6311c4b2017-07-06 14:09:29 -07001268 for (int i = mChildren.size() - 1; i >= 0; --i) {
1269 final WindowState child = mChildren.get(i);
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001270 if (child.mightAffectAllDrawn() && !child.getDrawnStateEvaluated()) {
Bryce Leed390deb2017-06-22 13:14:28 -07001271 return false;
1272 }
1273 }
1274 return true;
1275 }
1276
1277 /**
Matthew Ng5d23afa2017-06-21 16:16:24 -07001278 * Determines if the token has finished drawing. This should only be called from
1279 * {@link DisplayContent#applySurfaceChangesTransaction}
1280 */
Matthew Ng498c71d2017-04-18 13:55:45 -07001281 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001282 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001283 // Number of drawn windows can be less when a window is being relaunched, wait for
Bryce Leed390deb2017-06-22 13:14:28 -07001284 // all windows to be launched and drawn for this token be considered all drawn.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001285 final int numInteresting = mNumInterestingWindows;
Bryce Leed390deb2017-06-22 13:14:28 -07001286
1287 // We must make sure that all present children have been considered (determined by
1288 // {@link #allDrawnStatesConsidered}) before evaluating whether everything has been
1289 // drawn.
1290 if (numInteresting > 0 && allDrawnStatesConsidered()
1291 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001292 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001293 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001294 allDrawn = true;
1295 // Force an additional layout pass where
1296 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001297 if (mDisplayContent != null) {
1298 mDisplayContent.setLayoutNeeded();
1299 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001300 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001301
Winson Chunge7ba6862017-05-24 12:13:33 -07001302 // Notify the pinned stack upon all windows drawn. If there was an animation in
1303 // progress then this signal will resume that animation.
Wale Ogunwale61911492017-10-11 08:50:50 -07001304 final TaskStack pinnedStack = mDisplayContent.getPinnedStack();
Winson Chunge7ba6862017-05-24 12:13:33 -07001305 if (pinnedStack != null) {
1306 pinnedStack.onAllWindowsDrawn();
Robert Carrecc06b32017-04-18 14:25:10 -07001307 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001308 }
1309 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001310 }
1311
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001312 /**
1313 * Updated this app token tracking states for interesting and drawn windows based on the window.
1314 *
1315 * @return Returns true if the input window is considered interesting and drawn while all the
1316 * windows in this app token where not considered drawn as of the last pass.
1317 */
1318 boolean updateDrawnWindowStates(WindowState w) {
Bryce Leed390deb2017-06-22 13:14:28 -07001319 w.setDrawnStateEvaluated(true /*evaluated*/);
1320
Jorim Jaggie4b0f282017-05-17 15:10:29 +02001321 if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001322 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1323 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1324 }
1325
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001326 if (allDrawn && !mAppAnimator.freezingScreen) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001327 return false;
1328 }
1329
1330 if (mLastTransactionSequence != mService.mTransactionSequence) {
1331 mLastTransactionSequence = mService.mTransactionSequence;
1332 mNumInterestingWindows = mNumDrawnWindows = 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001333 startingDisplayed = false;
1334 }
1335
1336 final WindowStateAnimator winAnimator = w.mWinAnimator;
1337
1338 boolean isInterestingAndDrawn = false;
1339
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001340 if (!allDrawn && w.mightAffectAllDrawn()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001341 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1342 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1343 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1344 if (!w.isDrawnLw()) {
1345 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1346 + " pv=" + w.mPolicyVisibility
1347 + " mDrawState=" + winAnimator.drawStateToString()
1348 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1349 + " a=" + winAnimator.mAnimating);
1350 }
1351 }
1352
1353 if (w != startingWindow) {
1354 if (w.isInteresting()) {
1355 mNumInterestingWindows++;
1356 if (w.isDrawnLw()) {
1357 mNumDrawnWindows++;
1358
1359 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1360 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1361 + " freezingScreen=" + mAppAnimator.freezingScreen
1362 + " mAppFreezing=" + w.mAppFreezing);
1363
1364 isInterestingAndDrawn = true;
1365 }
1366 }
1367 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001368 if (getController() != null) {
1369 getController().reportStartingWindowDrawn();
1370 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001371 startingDisplayed = true;
1372 }
1373 }
1374
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001375 return isInterestingAndDrawn;
1376 }
1377
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001378 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001379 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001380 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001381 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001382 mAppAnimator.animating = true;
1383 mService.mAnimator.setAnimating(true);
1384 mService.mAnimator.mAppWindowAnimating = true;
1385 } else if (mAppAnimator.wasAnimating) {
1386 // stopped animating, do one more pass through the layout
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001387 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1388 DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001389 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1390 }
1391 }
1392
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001393 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001394 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001395 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1396 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1397 // TODO: Investigate if we need to continue to do this or if we can just process them
1398 // in-order.
1399 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001400 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001401 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001402 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001403 }
1404
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001405 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1406 boolean traverseTopToBottom) {
1407 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001408 }
1409
1410 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001411 AppWindowToken asAppWindowToken() {
1412 // I am an app window token!
1413 return this;
1414 }
1415
1416 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001417 boolean fillsParent() {
1418 return mFillsParent;
1419 }
1420
1421 void setFillsParent(boolean fillsParent) {
1422 mFillsParent = fillsParent;
1423 }
1424
Jorim Jaggife762342016-10-13 14:33:27 +02001425 boolean containsDismissKeyguardWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001426 // Window state is transient during relaunch. We are not guaranteed to be frozen during the
1427 // entirety of the relaunch.
1428 if (isRelaunching()) {
1429 return mLastContainsDismissKeyguardWindow;
1430 }
1431
Jorim Jaggife762342016-10-13 14:33:27 +02001432 for (int i = mChildren.size() - 1; i >= 0; i--) {
1433 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1434 return true;
1435 }
1436 }
1437 return false;
1438 }
1439
1440 boolean containsShowWhenLockedWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001441 // When we are relaunching, it is possible for us to be unfrozen before our previous
1442 // windows have been added back. Using the cached value ensures that our previous
1443 // showWhenLocked preference is honored until relaunching is complete.
1444 if (isRelaunching()) {
1445 return mLastContainsShowWhenLockedWindow;
1446 }
1447
Jorim Jaggife762342016-10-13 14:33:27 +02001448 for (int i = mChildren.size() - 1; i >= 0; i--) {
1449 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1450 return true;
1451 }
1452 }
Bryce Lee081554b2017-05-25 07:52:12 -07001453
Jorim Jaggife762342016-10-13 14:33:27 +02001454 return false;
1455 }
1456
1457 void checkKeyguardFlagsChanged() {
1458 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1459 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1460 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1461 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1462 mService.notifyKeyguardFlagsChanged(null /* callback */);
1463 }
1464 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1465 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1466 }
1467
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001468 WindowState getImeTargetBelowWindow(WindowState w) {
1469 final int index = mChildren.indexOf(w);
1470 if (index > 0) {
1471 final WindowState target = mChildren.get(index - 1);
1472 if (target.canBeImeTarget()) {
1473 return target;
1474 }
1475 }
1476 return null;
1477 }
1478
Winson Chungbe9be7f2017-06-28 10:55:22 -07001479 int getLowestAnimLayer() {
1480 for (int i = 0; i < mChildren.size(); i++) {
1481 final WindowState w = mChildren.get(i);
1482 if (w.mRemoved) {
1483 continue;
1484 }
1485 return w.mWinAnimator.mAnimLayer;
1486 }
1487 return Integer.MAX_VALUE;
1488 }
1489
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001490 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1491 WindowState candidate = null;
1492 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1493 final WindowState w = mChildren.get(i);
1494 if (w.mRemoved) {
1495 continue;
1496 }
1497 if (candidate == null || w.mWinAnimator.mAnimLayer >
1498 candidate.mWinAnimator.mAnimLayer) {
1499 candidate = w;
1500 }
1501 }
1502 return candidate;
1503 }
1504
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001505 /**
1506 * See {@link Activity#setDisablePreviewScreenshots}.
1507 */
1508 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001509 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001510 }
1511
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001512 /**
chaviwd3bf08d2017-08-01 17:24:59 -07001513 * Sets whether the current launch can turn the screen on. See {@link #canTurnScreenOn()}
1514 */
1515 void setCanTurnScreenOn(boolean canTurnScreenOn) {
1516 mCanTurnScreenOn = canTurnScreenOn;
1517 }
1518
1519 /**
1520 * Indicates whether the current launch can turn the screen on. This is to prevent multiple
1521 * relayouts from turning the screen back on. The screen should only turn on at most
1522 * once per activity resume.
1523 *
1524 * @return true if the screen can be turned on.
1525 */
1526 boolean canTurnScreenOn() {
1527 return mCanTurnScreenOn;
1528 }
1529
1530 /**
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001531 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1532 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1533 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1534 *
1535 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1536 * screenshot.
1537 */
1538 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001539 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001540 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001541 }
1542
Wale Ogunwale51362492016-09-08 17:49:17 -07001543 @Override
Robert Carrdee1b3f2017-02-27 11:33:33 -08001544 int getAnimLayerAdjustment() {
1545 return mAppAnimator.animLayerAdjustment;
1546 }
1547
1548 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001549 void dump(PrintWriter pw, String prefix) {
1550 super.dump(pw, prefix);
1551 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001552 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001553 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001554 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001555 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1556 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07001557 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
1558 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
1559 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001560 if (paused) {
1561 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001562 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001563 if (mAppStopped) {
1564 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1565 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001566 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001567 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001568 pw.print(prefix); pw.print("mNumInterestingWindows=");
1569 pw.print(mNumInterestingWindows);
1570 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001571 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001572 pw.print(" allDrawn="); pw.print(allDrawn);
1573 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1574 pw.println(")");
1575 }
1576 if (inPendingTransaction) {
1577 pw.print(prefix); pw.print("inPendingTransaction=");
1578 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001579 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001580 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001581 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1582 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001583 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001584 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001585 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001586 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07001587 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001588 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001589 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001590 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07001591 pw.print(" startingMoved="); pw.print(startingMoved);
1592 pw.println(" mHiddenSetFromTransferredStartingWindow="
1593 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001594 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001595 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001596 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001597 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001598 }
1599 if (mPendingRelaunchCount != 0) {
1600 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001601 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07001602 if (getController() != null) {
1603 pw.print(prefix); pw.print("controller="); pw.println(getController());
1604 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07001605 if (mRemovingFromDisplay) {
1606 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
1607 }
Jorim Jaggi4d1835d2017-08-31 17:28:27 +02001608 if (mAppAnimator.isAnimating()) {
1609 mAppAnimator.dump(pw, prefix + " ");
1610 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001611 }
1612
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001613 @CallSuper
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001614 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02001615 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07001616 final long token = proto.start(fieldId);
1617 writeNameToProto(proto, NAME);
Adrian Roos4921ccf2017-09-28 16:54:06 +02001618 super.writeToProto(proto, WINDOW_TOKEN, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07001619 proto.end(token);
1620 }
1621
1622 void writeNameToProto(ProtoOutputStream proto, long fieldId) {
1623 if (appToken == null) {
1624 return;
1625 }
1626 try {
1627 proto.write(fieldId, appToken.getName());
1628 } catch (RemoteException e) {
1629 // This shouldn't happen, but in this case fall back to outputting nothing
1630 Slog.e(TAG, e.toString());
1631 }
1632 }
1633
1634 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001635 public String toString() {
1636 if (stringName == null) {
1637 StringBuilder sb = new StringBuilder();
1638 sb.append("AppWindowToken{");
1639 sb.append(Integer.toHexString(System.identityHashCode(this)));
1640 sb.append(" token="); sb.append(token); sb.append('}');
1641 stringName = sb.toString();
1642 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001643 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001644 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001645}