blob: 96ea5e5a3d0c0bf0a341db976fc3a9aa4731b693 [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 Ogunwale6cae7652015-12-26 07:36:26 -080019import static android.app.ActivityManager.StackId;
Wale Ogunwale72919d22016-12-08 18:58:50 -080020import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
21import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070022import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
Wale Ogunwale51362492016-09-08 17:49:17 -070023import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070024import static android.view.Display.DEFAULT_DISPLAY;
Jorim Jaggife762342016-10-13 14:33:27 +020025import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020026import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Jorim Jaggife762342016-10-13 14:33:27 +020027import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070028import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080029import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070030import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070031import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
32import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070033import static com.android.server.wm.AppTransition.TRANSIT_UNSET;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080034import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080035import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
36import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070037import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070038import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
39import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080040import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
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;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080050
Filip Gruszczynskia590c992015-11-25 16:45:26 -080051import android.annotation.NonNull;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020052import android.app.Activity;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070053import android.content.res.Configuration;
Jorim Jaggi0429f352015-12-22 16:29:16 +010054import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070055import android.os.Binder;
Bryce Lee39791592017-04-26 09:29:12 -070056import android.os.Build;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080057import android.os.Debug;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070058import android.os.IBinder;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070059import android.os.SystemClock;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080060import android.util.Slog;
61import android.view.IApplicationToken;
Robert Carr6914f082017-03-20 19:04:30 -070062import android.view.SurfaceControl;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080063import android.view.WindowManager;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080064import android.view.WindowManagerPolicy.StartingSurface;
65
66import com.android.internal.util.ToBooleanFunction;
67import com.android.server.input.InputApplicationHandle;
68import com.android.server.wm.WindowManagerService.H;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080069
70import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010071import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080072import java.util.ArrayList;
73
Bryce Lee39791592017-04-26 09:29:12 -070074import static android.os.Build.VERSION_CODES.O;
75
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080076class AppTokenList extends ArrayList<AppWindowToken> {
77}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080078
79/**
80 * Version of WindowToken that is specifically for a particular application (or
81 * really activity) that is displaying windows.
82 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070083class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080084 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
85
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080086 // Non-null only for application tokens.
87 final IApplicationToken appToken;
88
Filip Gruszczynskia590c992015-11-25 16:45:26 -080089 @NonNull final AppWindowAnimator mAppAnimator;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070090
Wale Ogunwale72919d22016-12-08 18:58:50 -080091 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -070092
Wale Ogunwale51362492016-09-08 17:49:17 -070093 /** @see WindowContainer#fillsParent() */
94 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -080095 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -080096 boolean mShowForAllUsers;
97 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -070098
Bryce Lee6d410262017-02-28 15:30:17 -080099 // Flag set while reparenting to prevent actions normally triggered by an individual parent
100 // change.
101 private boolean mReparenting;
102
Wale Ogunwalee287e192017-04-21 09:30:12 -0700103 // True if we are current in the process of removing this app token from the display
104 private boolean mRemovingFromDisplay = false;
105
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800106 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -0800107 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800108
109 // These are used for determining when all windows associated with
110 // an activity have been drawn, so they can be made visible together
111 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700112 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700113 private long mLastTransactionSequence = Long.MIN_VALUE;
114 private int mNumInterestingWindows;
115 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800116 boolean inPendingTransaction;
117 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -0800118 // Set to true when this app creates a surface while in the middle of an animation. In that
119 // case do not clear allDrawn until the animation completes.
120 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800121
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700122 /**
123 * These are to track the app's real drawing status if there were no saved surfaces.
124 * @see #updateDrawnWindowStates
125 */
Chong Zhang8e4bda92016-05-04 15:08:18 -0700126 boolean allDrawnExcludingSaved;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700127 private int mNumInterestingWindowsExcludingSaved;
128 private int mNumDrawnWindowsExcludingSaved;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700129
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800130 // Is this window's surface needed? This is almost like hidden, except
131 // it will sometimes be true a little earlier: when the token has
132 // been shown, but is still waiting for its app transition to execute
133 // before making its windows shown.
134 boolean hiddenRequested;
135
136 // Have we told the window clients to hide themselves?
Wale Ogunwale89973222017-04-23 18:39:45 -0700137 private boolean mClientHidden;
138
139 // If true we will defer setting mClientHidden to true and reporting to the client that it is
140 // hidden.
141 boolean mDeferHidingClient;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800142
143 // Last visibility state we reported to the app token.
144 boolean reportedVisible;
145
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700146 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700147 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700148
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800149 // Set to true when the token has been removed from the window mgr.
150 boolean removed;
151
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800152 // Information about an application starting window if displayed.
153 StartingData startingData;
154 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800155 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800156 boolean startingDisplayed;
157 boolean startingMoved;
158 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700159 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
160 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800161
162 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700163 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800164
Wale Ogunwale571771c2016-08-26 13:18:50 -0700165 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800166 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800167
Craig Mautnerbb742462014-07-07 15:28:55 -0700168 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700169 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700170
Wale Ogunwale72919d22016-12-08 18:58:50 -0800171 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800172
Robert Carre12aece2016-02-02 22:43:27 -0800173 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700174 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700175 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800176
Jorim Jaggife762342016-10-13 14:33:27 +0200177 private boolean mLastContainsShowWhenLockedWindow;
178 private boolean mLastContainsDismissKeyguardWindow;
179
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700180 // The bounds of this activity. Mainly used for aspect-ratio compatibility.
181 // TODO(b/36505427): Every level on WindowContainer now has bounds information, which directly
182 // affects the configuration. We should probably move this into that class.
183 private final Rect mBounds = new Rect();
184
Jorim Jaggi0429f352015-12-22 16:29:16 +0100185 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700186 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100187
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100188 private boolean mDisbalePreviewScreenshots;
189
Robert Carred3e83b2017-04-21 13:26:55 -0700190 Task mLastParent;
191
Wale Ogunwale72919d22016-12-08 18:58:50 -0800192 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
193 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
194 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800195 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700196 AppWindowContainerController controller, Configuration overrideConfig, Rect bounds) {
197 this(service, token, voiceInteraction, dc, fullscreen, overrideConfig, bounds);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800198 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800199 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800200 mShowForAllUsers = showForAllUsers;
201 mTargetSdk = targetSdk;
202 mOrientation = orientation;
203 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
204 mLaunchTaskBehind = launchTaskBehind;
205 mAlwaysFocusable = alwaysFocusable;
206 mRotationAnimationHint = rotationAnimationHint;
207
208 // Application tokens start out hidden.
209 hidden = true;
210 hiddenRequested = true;
211 }
212
213 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700214 DisplayContent dc, boolean fillsParent, Configuration overrideConfig, Rect bounds) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800215 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
216 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700217 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800218 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800219 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800220 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700221 mAppAnimator = new AppWindowAnimator(this, service);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700222 if (overrideConfig != null) {
223 onOverrideConfigurationChanged(overrideConfig);
224 }
225 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;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800289 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
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;
341
Wale Ogunwale89973222017-04-23 18:39:45 -0700342 setClientHidden(!visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700343
344 // Allow for state changes and animation to be applied if:
345 // * token is transitioning visibility state
346 // * or the token was marked as hidden and is exiting before we had a chance to play the
347 // transition animation
348 // * or this is an opening app and windows are being replaced.
349 boolean visibilityChanged = false;
350 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700351 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700352 boolean changed = false;
353 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
354 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
355
356 boolean runningAppAnimation = false;
357
358 if (transit != AppTransition.TRANSIT_UNSET) {
359 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
360 mAppAnimator.setNullAnimation();
361 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700362 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700363 delayed = runningAppAnimation = true;
364 }
365 final WindowState window = findMainWindow();
366 //TODO (multidisplay): Magnification is supported only for the default display.
367 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700368 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700369 accessibilityController.onAppWindowTransitionLocked(window, transit);
370 }
371 changed = true;
372 }
373
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700374 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700375 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700376 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700377 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700378 }
379
380 hidden = hiddenRequested = !visible;
381 visibilityChanged = true;
382 if (!visible) {
383 stopFreezingScreen(true, true);
384 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700385 // If we are being set visible, and the starting window is not yet displayed,
386 // then make sure it doesn't get displayed.
387 if (startingWindow != null && !startingWindow.isDrawnLw()) {
388 startingWindow.mPolicyVisibility = false;
389 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700390 }
391 }
392
393 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
394 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
395
396 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700397 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700398 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700399 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700400 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700401 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700402 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700403 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700404 }
405 }
406
407 if (mAppAnimator.animation != null) {
408 delayed = true;
409 }
410
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700411 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700412 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700413 delayed = true;
414 }
415 }
416
417 if (visibilityChanged) {
418 if (visible && !delayed) {
419 // The token was made immediately visible, there will be no entrance animation.
420 // We need to inform the client the enter animation was finished.
421 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700422 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700423 }
Robert Carre7cc44d2017-03-20 19:04:30 -0700424 // If we are hidden but there is no delay needed we immediately
425 // apply the Surface transaction so that the ActivityManager
426 // can have some guarantee on the Surface state
427 // following setting the visibility.
Robert Carr6914f082017-03-20 19:04:30 -0700428 if (hidden && !delayed) {
429 SurfaceControl.openTransaction();
430 for (int i = mChildren.size() - 1; i >= 0; i--) {
431 mChildren.get(i).mWinAnimator.hide("immediately hidden");
432 }
433 SurfaceControl.closeTransaction();
434 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700435
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700436 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700437 // The token is not closing nor opening, so even if there is an animation set, that
438 // doesn't mean that it goes through the normal app transition cycle so we have
439 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700440 // TODO(multi-display): notify docked divider on all displays where visibility was
441 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700442 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700443 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100444 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700445 }
446 }
447
448 return delayed;
449 }
450
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800451 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700452 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700453 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800454 while (j > 0) {
455 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700456 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700457 final int type = win.mAttrs.type;
458 // No need to loop through child window as base application and starting types can't be
459 // child windows.
460 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700461 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900462 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700463 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800464 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700465 candidate = win;
466 } else {
467 return win;
468 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800469 }
470 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700471 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800472 }
473
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800474 boolean windowsAreFocusable() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800475 return StackId.canReceiveKeys(getTask().mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800476 }
477
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800478 AppWindowContainerController getController() {
479 final WindowContainerController controller = super.getController();
480 return controller != null ? (AppWindowContainerController) controller : null;
481 }
482
Wale Ogunwale571771c2016-08-26 13:18:50 -0700483 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700484 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700485 // If the app token isn't hidden then it is considered visible and there is no need to check
486 // its children windows to see if they are visible.
487 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700488 }
489
490 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700491 void removeImmediately() {
492 onRemovedFromDisplay();
493 super.removeImmediately();
494 }
495
496 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700497 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800498 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800499 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800500 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800501 }
502
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700503 @Override
504 boolean checkCompleteDeferredRemoval() {
505 if (mIsExiting) {
506 removeIfPossible();
507 }
508 return super.checkCompleteDeferredRemoval();
509 }
510
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700511 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700512 if (mRemovingFromDisplay) {
513 return;
514 }
515 mRemovingFromDisplay = true;
516
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700517 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
518
Wale Ogunwale72919d22016-12-08 18:58:50 -0800519 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700520
521 mService.mOpeningApps.remove(this);
Jorim Jaggi1b4b23e2016-11-15 16:30:12 -0800522 mService.mUnknownAppVisibilityController.appRemoved(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100523 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700524 waitingToShow = false;
525 if (mService.mClosingApps.contains(this)) {
526 delayed = true;
527 } else if (mService.mAppTransition.isTransitionSet()) {
528 mService.mClosingApps.add(this);
529 delayed = true;
530 }
531
532 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
533 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
534
535 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
536 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
537
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800538 if (startingData != null && getController() != null) {
539 getController().removeStartingWindow();
540 }
541
Winson Chung87e5d552017-04-05 11:49:38 -0700542 // If this window was animating, then we need to ensure that the app transition notifies
543 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
544 // add to that list now
545 if (mAppAnimator.animating) {
546 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
547 }
548
Wale Ogunwalee287e192017-04-21 09:30:12 -0700549 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700550 if (delayed && !isEmpty()) {
551 // set the token aside because it has an active animation to be finished
552 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
553 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700554 if (stack != null) {
555 stack.mExitingAppTokens.add(this);
556 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700557 mIsExiting = true;
558 } else {
559 // Make sure there is no animation running on this token, so any windows associated
560 // with it will be removed as soon as their animations are complete
561 mAppAnimator.clearAnimation();
562 mAppAnimator.animating = false;
563 removeIfPossible();
564 }
565
566 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700567 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800568
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700569 if (mService.mFocusedApp == this) {
570 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
571 mService.mFocusedApp = null;
572 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
573 mService.mInputMonitor.setFocusedAppLw(null);
574 }
575
576 if (!delayed) {
577 updateReportedVisibilityLocked();
578 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700579
580 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700581 }
582
Chong Zhange05bcb12016-07-26 17:47:29 -0700583 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700584 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700585 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700586 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700587 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700588 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700589 if (wallpaperMightChange) {
590 requestUpdateWallpaperIfNeeded();
591 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700592 }
593
Robert Carre12aece2016-02-02 22:43:27 -0800594 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700595 destroySurfaces(false /*cleanupOnResume*/);
596 }
597
598 /**
599 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
600 * the client has finished with them.
601 *
602 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
603 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
604 * others so that they are ready to be reused. If set to false (common case), destroy all
605 * surfaces that's eligible, if the app is already stopped.
606 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700607 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700608 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700609 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700610 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700611 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800612 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700613 if (destroyedSomething) {
614 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700615 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800616 }
617 }
618
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800619 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700620 * Notify that the app is now resumed, and it was not stopped before, perform a clean
621 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800622 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700623 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700624 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700625 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700626 mAppStopped = false;
627 if (!wasStopped) {
628 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800629 }
Robert Carre12aece2016-02-02 22:43:27 -0800630 }
631
Chong Zhangbef461f2015-10-27 11:38:24 -0700632 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700633 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
634 * keeping alive in case they were still being used.
635 */
636 void notifyAppStopped() {
637 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
638 mAppStopped = true;
639 destroySurfaces();
640 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800641 if (getController() != null) {
642 getController().removeStartingWindow();
643 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700644 }
645
646 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700647 * Checks whether we should save surfaces for this app.
648 *
649 * @return true if the surfaces should be saved, false otherwise.
650 */
651 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800652 // We want to save surface if the app's windows are "allDrawn".
653 // (If we started entering animation early with saved surfaces, allDrawn
654 // should have been restored to true. So we'll save again in that case
655 // even if app didn't actually finish drawing.)
656 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800657 }
658
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700659 private boolean canRestoreSurfaces() {
660 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700661 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700662 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800663 return true;
664 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700665 }
666 return false;
667 }
668
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700669 private void clearWasVisibleBeforeClientHidden() {
670 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700671 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700672 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700673 }
674 }
675
Chong Zhang8e4bda92016-05-04 15:08:18 -0700676 /**
677 * Whether the app has some window that is invisible in layout, but
678 * animating with saved surface.
679 */
680 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700681 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700682 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700683 if (w.isAnimatingInvisibleWithSavedSurface()) {
684 return true;
685 }
686 }
687 return false;
688 }
689
690 /**
691 * Hide all window surfaces that's still invisible in layout but animating
692 * with a saved surface, and mark them destroying.
693 */
694 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700695 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700696 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700697 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700698 }
699 destroySurfaces();
700 }
701
Chong Zhangf58631a2016-05-24 16:02:10 -0700702 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700703 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700704 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700705 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700706 }
707 }
708
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700709 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700710 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700711 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700712 return;
713 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700714
715 // Check if all interesting windows are drawn and we can mark allDrawn=true.
716 int interestingNotDrawn = -1;
717
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700718 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700719 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700720 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700721 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800722
Chong Zhang92147042016-05-09 12:47:11 -0700723 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700724 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700725 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700726 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700727 }
728 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700729 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800730
731 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700732 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
733 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700734 }
735
736 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700737 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700738 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800739 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700740 }
Chong Zhang92147042016-05-09 12:47:11 -0700741 }
742
743 void clearAllDrawn() {
744 allDrawn = false;
745 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700746 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700747 }
748
Bryce Lee6d410262017-02-28 15:30:17 -0800749 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800750 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800751 }
752
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800753 TaskStack getStack() {
754 final Task task = getTask();
755 if (task != null) {
756 return task.mStack;
757 } else {
758 return null;
759 }
760 }
761
Bryce Lee6d410262017-02-28 15:30:17 -0800762 @Override
763 void onParentSet() {
764 super.onParentSet();
765
Robert Carred3e83b2017-04-21 13:26:55 -0700766 final Task task = getTask();
767
Bryce Lee6d410262017-02-28 15:30:17 -0800768 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
769 // access visual elements like the {@link DisplayContent}. We must remove any associations
770 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800771 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800772 if (task == null) {
773 // It is possible we have been marked as a closing app earlier. We must remove ourselves
774 // from this list so we do not participate in any future animations.
775 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700776 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800777 task.mStack.mExitingAppTokens.remove(this);
778 }
Bryce Lee6d410262017-02-28 15:30:17 -0800779 }
Robert Carred3e83b2017-04-21 13:26:55 -0700780 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800781 }
782
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700783 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700784 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700785 if (startingWindow == win) {
786 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800787 if (getController() != null) {
788 getController().removeStartingWindow();
789 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700790 } else if (mChildren.size() == 0 && startingData != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700791 // If this is the last window and we had requested a starting transition window,
792 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800793 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700794 startingData = null;
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100795 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700796 // If this is the last window except for a starting transition window,
797 // we need to get rid of the starting transition.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800798 if (getController() != null) {
799 getController().removeStartingWindow();
800 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700801 }
802 }
803
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700804 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700805 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700806 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800807 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700808 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700809 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800810 // Set mDestroying, we don't want any animation or delayed removal here.
811 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700812 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700813 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800814 }
815 }
816 }
817
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700818 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700819 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700820 // No need to loop through child windows as the answer should be the same as that of the
821 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700822 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700823 return true;
824 }
825 }
826 return false;
827 }
828
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700829 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700830 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
831 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800832
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700833 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700834 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700835 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800836 }
837 if (animate) {
838 // Set-up dummy animation so we can start treating windows associated with this
839 // token like they are in transition before the new app window is ready for us to
840 // run the real transition animation.
841 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700842 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800843 mAppAnimator.setDummyAnimation();
844 }
845 }
846
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700847 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700848 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800849 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700850 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700851 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700852 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800853 }
854 }
855
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700856 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700857 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
858 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800859
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700860 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700861 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700862 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800863 }
864 }
865
Chong Zhang4d7369a2016-04-25 16:09:14 -0700866 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700867 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700868 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700869 w.requestUpdateWallpaperIfNeeded();
870 }
871 }
872
Chong Zhangd78ddb42016-03-02 17:01:14 -0800873 boolean isRelaunching() {
874 return mPendingRelaunchCount > 0;
875 }
876
877 void startRelaunching() {
878 if (canFreezeBounds()) {
879 freezeBounds();
880 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800881
882 // In the process of tearing down before relaunching, the app will
883 // try and clean up it's child surfaces. We need to prevent this from
884 // happening, so we sever the children, transfering their ownership
885 // from the client it-self to the parent surface (owned by us).
886 for (int i = mChildren.size() - 1; i >= 0; i--) {
887 final WindowState w = mChildren.get(i);
888 w.mWinAnimator.detachChildren();
889 }
890
Chong Zhangd78ddb42016-03-02 17:01:14 -0800891 mPendingRelaunchCount++;
892 }
893
894 void finishRelaunching() {
895 if (canFreezeBounds()) {
896 unfreezeBounds();
897 }
898 if (mPendingRelaunchCount > 0) {
899 mPendingRelaunchCount--;
900 }
Matthew Ng498c71d2017-04-18 13:55:45 -0700901 updateAllDrawn();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800902 }
903
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700904 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700905 if (mPendingRelaunchCount == 0) {
906 return;
907 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700908 if (canFreezeBounds()) {
909 unfreezeBounds();
910 }
911 mPendingRelaunchCount = 0;
912 }
913
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700914 /**
915 * Returns true if the new child window we are adding to this token is considered greater than
916 * the existing child window in this token in terms of z-order.
917 */
918 @Override
919 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
920 WindowState existingWindow) {
921 final int type1 = newWindow.mAttrs.type;
922 final int type2 = existingWindow.mAttrs.type;
923
924 // Base application windows should be z-ordered BELOW all other windows in the app token.
925 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
926 return false;
927 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
928 return true;
929 }
930
931 // Starting windows should be z-ordered ABOVE all other windows in the app token.
932 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
933 return true;
934 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
935 return false;
936 }
937
938 // Otherwise the new window is greater than the existing window.
939 return true;
940 }
941
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700942 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800943 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700944 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700945
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700946 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700947 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700948 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700949 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
950 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700951
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700952 // if we got a replacement window, reset the timeout to give drawing more time
953 if (gotReplacementWindow) {
954 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800955 }
Jorim Jaggife762342016-10-13 14:33:27 +0200956 checkKeyguardFlagsChanged();
957 }
958
959 @Override
960 void removeChild(WindowState child) {
961 super.removeChild(child);
962 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800963 }
964
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700965 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700966 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700967 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700968 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800969 return true;
970 }
971 }
972 return false;
973 }
974
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700975 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700976 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700977 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800978 }
979 }
980
Winson Chung30480042017-01-26 10:55:34 -0800981 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800982 final Task currentTask = getTask();
983 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -0800984 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800985 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800986 }
Bryce Lee6d410262017-02-28 15:30:17 -0800987
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800988 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -0800989 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800990 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -0800991 + " belongs to a different stack than " + task);
992 }
993
Winson Chung30480042017-01-26 10:55:34 -0800994 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800995 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800996 final DisplayContent prevDisplayContent = getDisplayContent();
997
Bryce Lee6d410262017-02-28 15:30:17 -0800998 mReparenting = true;
999
Winson Chung30480042017-01-26 10:55:34 -08001000 getParent().removeChild(this);
1001 task.addChild(this, position);
1002
Bryce Lee6d410262017-02-28 15:30:17 -08001003 mReparenting = false;
1004
Winson Chung30480042017-01-26 10:55:34 -08001005 // Relayout display(s).
1006 final DisplayContent displayContent = task.getDisplayContent();
1007 displayContent.setLayoutNeeded();
1008 if (prevDisplayContent != displayContent) {
1009 onDisplayChanged(displayContent);
1010 prevDisplayContent.setLayoutNeeded();
1011 }
1012 }
1013
Chong Zhangd78ddb42016-03-02 17:01:14 -08001014 private boolean canFreezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001015 final Task task = getTask();
1016
Chong Zhangd78ddb42016-03-02 17:01:14 -08001017 // For freeform windows, we can't freeze the bounds at the moment because this would make
1018 // the resizing unresponsive.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001019 return task != null && !task.inFreeformWorkspace();
Chong Zhangd78ddb42016-03-02 17:01:14 -08001020 }
1021
Jorim Jaggi0429f352015-12-22 16:29:16 +01001022 /**
1023 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
1024 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
1025 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
1026 * with a queue.
1027 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001028 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001029 final Task task = getTask();
1030 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001031
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001032 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001033 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001034 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001035 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001036 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001037 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001038 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001039 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001040 }
1041
1042 /**
1043 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
1044 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001045 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001046 if (!mFrozenBounds.isEmpty()) {
1047 mFrozenBounds.remove();
1048 }
1049 if (!mFrozenMergedConfig.isEmpty()) {
1050 mFrozenMergedConfig.remove();
1051 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001052 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001053 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001054 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001055 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001056 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001057 }
1058
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001059 void setAppLayoutChanges(int changes, String reason) {
1060 if (!mChildren.isEmpty()) {
1061 final DisplayContent dc = getDisplayContent();
1062 dc.pendingLayoutChanges |= changes;
1063 if (DEBUG_LAYOUT_REPEATS) {
1064 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001065 }
1066 }
1067 }
1068
1069 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001070 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001071 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001072 if (win.removeReplacedWindowIfNeeded(replacement)) {
1073 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001074 }
1075 }
1076 }
1077
1078 void startFreezingScreen() {
1079 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001080 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
1081 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001082 if (!hiddenRequested) {
1083 if (!mAppAnimator.freezingScreen) {
1084 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001085 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001086 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001087 mService.mAppsFreezingScreen++;
1088 if (mService.mAppsFreezingScreen == 1) {
1089 mService.startFreezingDisplayLocked(false, 0, 0);
1090 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1091 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001092 }
1093 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001094 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001095 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001096 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001097 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001098 }
1099 }
1100 }
1101
1102 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
1103 if (!mAppAnimator.freezingScreen) {
1104 return;
1105 }
1106 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001107 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001108 boolean unfrozeWindows = false;
1109 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001110 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001111 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001112 }
1113 if (force || unfrozeWindows) {
1114 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
1115 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001116 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001117 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001118 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
1119 mService.mAppsFreezingScreen--;
1120 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001121 }
1122 if (unfreezeSurfaceNow) {
1123 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001124 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001125 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001126 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001127 }
1128 }
1129
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001130 @Override
1131 public void onAppFreezeTimeout() {
1132 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1133 stopFreezingScreen(true, true);
1134 }
1135
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001136 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001137 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001138 if (fromToken == null) {
1139 return false;
1140 }
1141
1142 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001143 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001144 // In this case, the starting icon has already been displayed, so start
1145 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001146 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001147
1148 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1149 + " from " + fromToken + " to " + this);
1150
1151 final long origId = Binder.clearCallingIdentity();
1152
1153 // Transfer the starting window over to the new token.
1154 startingData = fromToken.startingData;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001155 startingSurface = fromToken.startingSurface;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001156 startingDisplayed = fromToken.startingDisplayed;
1157 fromToken.startingDisplayed = false;
1158 startingWindow = tStartingWindow;
1159 reportedVisible = fromToken.reportedVisible;
1160 fromToken.startingData = null;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001161 fromToken.startingSurface = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001162 fromToken.startingWindow = null;
1163 fromToken.startingMoved = true;
1164 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001165 tStartingWindow.mAppToken = this;
1166
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001167 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001168 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001169 fromToken.removeChild(tStartingWindow);
1170 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001171 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001172
1173 // Propagate other interesting state between the tokens. If the old token is displayed,
1174 // we should immediately force the new one to be displayed. If it is animating, we need
1175 // to move that animation to the new one.
1176 if (fromToken.allDrawn) {
1177 allDrawn = true;
1178 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1179 }
1180 if (fromToken.firstWindowDrawn) {
1181 firstWindowDrawn = true;
1182 }
1183 if (!fromToken.hidden) {
1184 hidden = false;
1185 hiddenRequested = false;
1186 }
Wale Ogunwale89973222017-04-23 18:39:45 -07001187 setClientHidden(fromToken.mClientHidden);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001188 fromToken.mAppAnimator.transferCurrentAnimation(
1189 mAppAnimator, tStartingWindow.mWinAnimator);
1190
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001191 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001192 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001193 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001194 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001195 Binder.restoreCallingIdentity(origId);
1196 return true;
1197 } else if (fromToken.startingData != null) {
1198 // The previous app was getting ready to show a
1199 // starting window, but hasn't yet done so. Steal it!
1200 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1201 "Moving pending starting from " + fromToken + " to " + this);
1202 startingData = fromToken.startingData;
1203 fromToken.startingData = null;
1204 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001205 if (getController() != null) {
1206 getController().scheduleAddStartingWindow();
1207 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001208 return true;
1209 }
1210
1211 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1212 final AppWindowAnimator wAppAnimator = mAppAnimator;
1213 if (tAppAnimator.thumbnail != null) {
1214 // The old token is animating with a thumbnail, transfer that to the new token.
1215 if (wAppAnimator.thumbnail != null) {
1216 wAppAnimator.thumbnail.destroy();
1217 }
1218 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1219 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1220 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1221 tAppAnimator.thumbnail = null;
1222 }
1223 return false;
1224 }
1225
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001226 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001227 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001228 }
1229
1230 void setAllAppWinAnimators() {
1231 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1232 allAppWinAnimators.clear();
1233
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001234 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001235 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001236 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001237 }
1238 }
1239
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001240 @Override
1241 void onAppTransitionDone() {
1242 sendingToBottom = false;
1243 }
1244
Wale Ogunwale51362492016-09-08 17:49:17 -07001245 /**
1246 * We override because this class doesn't want its children affecting its reported orientation
1247 * in anyway.
1248 */
1249 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001250 int getOrientation(int candidate) {
Bryce Leed1ac18c2017-05-11 07:59:41 -07001251 // We do not allow non-fullscreen apps to influence orientation beyond O. While we do
Bryce Lee39791592017-04-26 09:29:12 -07001252 // throw an exception in {@link Activity#onCreate} and
1253 // {@link Activity#setRequestedOrientation}, we also ignore the orientation here so that
1254 // other calculations aren't affected.
Bryce Leed1ac18c2017-05-11 07:59:41 -07001255 if (!fillsParent() && mTargetSdk > O) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001256 // Can't specify orientation if app doesn't fill parent.
1257 return SCREEN_ORIENTATION_UNSET;
1258 }
1259
1260 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1261 // Allow app to specify orientation regardless of its visibility state if the current
1262 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1263 // wants us to use the orientation of the app behind it.
1264 return mOrientation;
1265 }
1266
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001267 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1268 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1269 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001270 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001271 && (isVisible() || mService.mOpeningApps.contains(this))) {
Bryce Leea163b762017-01-24 11:05:01 -08001272 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001273 }
Bryce Leea163b762017-01-24 11:05:01 -08001274
1275 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001276 }
1277
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001278 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1279 int getOrientationIgnoreVisibility() {
1280 return mOrientation;
1281 }
1282
Craig Mautnerdbb79912012-03-01 18:59:14 -08001283 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001284 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001285 if (allDrawn == mAppAnimator.allDrawn) {
1286 return;
1287 }
1288
1289 mAppAnimator.allDrawn = allDrawn;
1290 if (!allDrawn) {
1291 return;
1292 }
1293
1294 // The token has now changed state to having all windows shown... what to do, what to do?
1295 if (mAppAnimator.freezingScreen) {
1296 mAppAnimator.showAllWindowsLocked();
1297 stopFreezingScreen(false, true);
1298 if (DEBUG_ORIENTATION) Slog.i(TAG,
1299 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001300 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001301 // This will set mOrientationChangeComplete and cause a pass through layout.
1302 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001303 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001304 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001305 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001306
1307 // We can now show all of the drawn windows!
1308 if (!mService.mOpeningApps.contains(this)) {
1309 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1310 }
1311 }
1312 }
1313
Matthew Ng498c71d2017-04-18 13:55:45 -07001314 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001315 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001316 // Number of drawn windows can be less when a window is being relaunched, wait for
1317 // all windows to be launched and drawn for this token be considered all drawn
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001318 final int numInteresting = mNumInterestingWindows;
Matthew Ng498c71d2017-04-18 13:55:45 -07001319 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001320 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001321 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001322 allDrawn = true;
1323 // Force an additional layout pass where
1324 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001325 if (mDisplayContent != null) {
1326 mDisplayContent.setLayoutNeeded();
1327 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001328 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001329
1330 final TaskStack s = getStack();
1331 if (s != null) {
1332 s.onAllWindowsDrawn();
1333 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001334 }
1335 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001336
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001337 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001338 int numInteresting = mNumInterestingWindowsExcludingSaved;
1339 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001340 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1341 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001342 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001343 allDrawnExcludingSaved = true;
Matthew Ng498c71d2017-04-18 13:55:45 -07001344 if (mDisplayContent != null) {
1345 mDisplayContent.setLayoutNeeded();
1346 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001347 if (isAnimatingInvisibleWithSavedSurface()
1348 && !mService.mFinishedEarlyAnim.contains(this)) {
1349 mService.mFinishedEarlyAnim.add(this);
1350 }
1351 }
1352 }
1353 }
1354
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001355 /**
1356 * Updated this app token tracking states for interesting and drawn windows based on the window.
1357 *
1358 * @return Returns true if the input window is considered interesting and drawn while all the
1359 * windows in this app token where not considered drawn as of the last pass.
1360 */
1361 boolean updateDrawnWindowStates(WindowState w) {
1362 if (DEBUG_STARTING_WINDOW && w == startingWindow) {
1363 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1364 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1365 }
1366
1367 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1368 return false;
1369 }
1370
1371 if (mLastTransactionSequence != mService.mTransactionSequence) {
1372 mLastTransactionSequence = mService.mTransactionSequence;
1373 mNumInterestingWindows = mNumDrawnWindows = 0;
1374 mNumInterestingWindowsExcludingSaved = 0;
1375 mNumDrawnWindowsExcludingSaved = 0;
1376 startingDisplayed = false;
1377 }
1378
1379 final WindowStateAnimator winAnimator = w.mWinAnimator;
1380
1381 boolean isInterestingAndDrawn = false;
1382
1383 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1384 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1385 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1386 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1387 if (!w.isDrawnLw()) {
1388 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1389 + " pv=" + w.mPolicyVisibility
1390 + " mDrawState=" + winAnimator.drawStateToString()
1391 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1392 + " a=" + winAnimator.mAnimating);
1393 }
1394 }
1395
1396 if (w != startingWindow) {
1397 if (w.isInteresting()) {
1398 mNumInterestingWindows++;
1399 if (w.isDrawnLw()) {
1400 mNumDrawnWindows++;
1401
1402 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1403 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1404 + " freezingScreen=" + mAppAnimator.freezingScreen
1405 + " mAppFreezing=" + w.mAppFreezing);
1406
1407 isInterestingAndDrawn = true;
1408 }
1409 }
1410 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001411 if (getController() != null) {
1412 getController().reportStartingWindowDrawn();
1413 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001414 startingDisplayed = true;
1415 }
1416 }
1417
1418 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1419 if (w != startingWindow && w.isInteresting()) {
1420 mNumInterestingWindowsExcludingSaved++;
1421 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1422 mNumDrawnWindowsExcludingSaved++;
1423
1424 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1425 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1426 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1427 + " freezingScreen=" + mAppAnimator.freezingScreen
1428 + " mAppFreezing=" + w.mAppFreezing);
1429
1430 isInterestingAndDrawn = true;
1431 }
1432 }
1433 }
1434
1435 return isInterestingAndDrawn;
1436 }
1437
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001438 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001439 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001440 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001441 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001442 mAppAnimator.animating = true;
1443 mService.mAnimator.setAnimating(true);
1444 mService.mAnimator.mAppWindowAnimating = true;
1445 } else if (mAppAnimator.wasAnimating) {
1446 // stopped animating, do one more pass through the layout
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001447 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1448 DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001449 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1450 }
1451 }
1452
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001453 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001454 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001455 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1456 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1457 // TODO: Investigate if we need to continue to do this or if we can just process them
1458 // in-order.
1459 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001460 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001461 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001462 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001463 }
1464
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001465 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1466 boolean traverseTopToBottom) {
1467 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001468 }
1469
1470 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001471 AppWindowToken asAppWindowToken() {
1472 // I am an app window token!
1473 return this;
1474 }
1475
1476 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001477 boolean fillsParent() {
1478 return mFillsParent;
1479 }
1480
1481 void setFillsParent(boolean fillsParent) {
1482 mFillsParent = fillsParent;
1483 }
1484
Jorim Jaggife762342016-10-13 14:33:27 +02001485 boolean containsDismissKeyguardWindow() {
1486 for (int i = mChildren.size() - 1; i >= 0; i--) {
1487 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1488 return true;
1489 }
1490 }
1491 return false;
1492 }
1493
1494 boolean containsShowWhenLockedWindow() {
1495 for (int i = mChildren.size() - 1; i >= 0; i--) {
1496 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1497 return true;
1498 }
1499 }
1500 return false;
1501 }
1502
1503 void checkKeyguardFlagsChanged() {
1504 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1505 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1506 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1507 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1508 mService.notifyKeyguardFlagsChanged(null /* callback */);
1509 }
1510 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1511 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1512 }
1513
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001514 WindowState getImeTargetBelowWindow(WindowState w) {
1515 final int index = mChildren.indexOf(w);
1516 if (index > 0) {
1517 final WindowState target = mChildren.get(index - 1);
1518 if (target.canBeImeTarget()) {
1519 return target;
1520 }
1521 }
1522 return null;
1523 }
1524
1525 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1526 WindowState candidate = null;
1527 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1528 final WindowState w = mChildren.get(i);
1529 if (w.mRemoved) {
1530 continue;
1531 }
1532 if (candidate == null || w.mWinAnimator.mAnimLayer >
1533 candidate.mWinAnimator.mAnimLayer) {
1534 candidate = w;
1535 }
1536 }
1537 return candidate;
1538 }
1539
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001540 /**
1541 * See {@link Activity#setDisablePreviewScreenshots}.
1542 */
1543 void setDisablePreviewScreenshots(boolean disable) {
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001544 mDisbalePreviewScreenshots = disable;
1545 }
1546
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001547 /**
1548 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1549 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1550 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1551 *
1552 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1553 * screenshot.
1554 */
1555 boolean shouldUseAppThemeSnapshot() {
1556 return mDisbalePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
1557 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001558 }
1559
Wale Ogunwale51362492016-09-08 17:49:17 -07001560 @Override
Robert Carrdee1b3f2017-02-27 11:33:33 -08001561 int getAnimLayerAdjustment() {
1562 return mAppAnimator.animLayerAdjustment;
1563 }
1564
1565 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001566 void dump(PrintWriter pw, String prefix) {
1567 super.dump(pw, prefix);
1568 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001569 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001570 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001571 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001572 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1573 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07001574 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
1575 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
1576 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001577 if (paused) {
1578 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001579 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001580 if (mAppStopped) {
1581 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1582 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001583 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001584 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001585 pw.print(prefix); pw.print("mNumInterestingWindows=");
1586 pw.print(mNumInterestingWindows);
1587 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001588 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001589 pw.print(" allDrawn="); pw.print(allDrawn);
1590 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1591 pw.println(")");
1592 }
1593 if (inPendingTransaction) {
1594 pw.print(prefix); pw.print("inPendingTransaction=");
1595 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001596 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001597 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001598 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1599 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001600 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001601 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001602 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001603 if (startingWindow != null || startingSurface != null
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001604 || startingDisplayed || startingMoved) {
1605 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001606 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001607 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001608 pw.print(" startingMoved="); pw.println(startingMoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001609 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001610 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001611 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001612 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001613 }
1614 if (mPendingRelaunchCount != 0) {
1615 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001616 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07001617 if (getController() != null) {
1618 pw.print(prefix); pw.print("controller="); pw.println(getController());
1619 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07001620 if (mRemovingFromDisplay) {
1621 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
1622 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001623 }
1624
1625 @Override
1626 public String toString() {
1627 if (stringName == null) {
1628 StringBuilder sb = new StringBuilder();
1629 sb.append("AppWindowToken{");
1630 sb.append(Integer.toHexString(System.identityHashCode(this)));
1631 sb.append(" token="); sb.append(token); sb.append('}');
1632 stringName = sb.toString();
1633 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001634 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001635 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001636}