blob: 4e38e3d0ecf7117f7cbf25138d7ed35a84c1a88d [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;
Winson Chunge7ba6862017-05-24 12:13:33 -070020import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Wale Ogunwale72919d22016-12-08 18:58:50 -080021import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
22import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070023import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
Wale Ogunwale51362492016-09-08 17:49:17 -070024import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070025import static android.view.Display.DEFAULT_DISPLAY;
Jorim Jaggife762342016-10-13 14:33:27 +020026import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020027import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Jorim Jaggife762342016-10-13 14:33:27 +020028import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070029import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080030import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070031import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070032import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
33import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070034import static com.android.server.wm.AppTransition.TRANSIT_UNSET;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080035import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080036import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
37import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070038import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070039import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
40import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080041import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020042import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070043import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080044import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
45import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
46import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
47import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070048import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070049import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070050import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070051import static com.android.server.wm.WindowManagerService.logWithStack;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080052
Filip Gruszczynskia590c992015-11-25 16:45:26 -080053import android.annotation.NonNull;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020054import android.app.Activity;
Winson Chunge7ba6862017-05-24 12:13:33 -070055import android.app.ActivityManager;
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;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070061import android.os.SystemClock;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080062import android.util.Slog;
63import android.view.IApplicationToken;
Robert Carr6914f082017-03-20 19:04:30 -070064import android.view.SurfaceControl;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080065import android.view.WindowManager;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080066import android.view.WindowManagerPolicy.StartingSurface;
67
68import com.android.internal.util.ToBooleanFunction;
69import com.android.server.input.InputApplicationHandle;
70import com.android.server.wm.WindowManagerService.H;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080071
72import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010073import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080074import java.util.ArrayList;
75
Bryce Lee39791592017-04-26 09:29:12 -070076import static android.os.Build.VERSION_CODES.O;
77
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080078class AppTokenList extends ArrayList<AppWindowToken> {
79}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080080
81/**
82 * Version of WindowToken that is specifically for a particular application (or
83 * really activity) that is displaying windows.
84 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070085class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080086 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
87
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080088 // Non-null only for application tokens.
89 final IApplicationToken appToken;
90
Filip Gruszczynskia590c992015-11-25 16:45:26 -080091 @NonNull final AppWindowAnimator mAppAnimator;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070092
Wale Ogunwale72919d22016-12-08 18:58:50 -080093 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -070094
Wale Ogunwale51362492016-09-08 17:49:17 -070095 /** @see WindowContainer#fillsParent() */
96 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -080097 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -080098 boolean mShowForAllUsers;
99 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -0700100
Bryce Lee6d410262017-02-28 15:30:17 -0800101 // Flag set while reparenting to prevent actions normally triggered by an individual parent
102 // change.
103 private boolean mReparenting;
104
Wale Ogunwalee287e192017-04-21 09:30:12 -0700105 // True if we are current in the process of removing this app token from the display
106 private boolean mRemovingFromDisplay = false;
107
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800108 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -0800109 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800110
111 // These are used for determining when all windows associated with
112 // an activity have been drawn, so they can be made visible together
113 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700114 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700115 private long mLastTransactionSequence = Long.MIN_VALUE;
116 private int mNumInterestingWindows;
117 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800118 boolean inPendingTransaction;
119 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -0800120 // Set to true when this app creates a surface while in the middle of an animation. In that
121 // case do not clear allDrawn until the animation completes.
122 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800123
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700124 /**
125 * These are to track the app's real drawing status if there were no saved surfaces.
126 * @see #updateDrawnWindowStates
127 */
Chong Zhang8e4bda92016-05-04 15:08:18 -0700128 boolean allDrawnExcludingSaved;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700129 private int mNumInterestingWindowsExcludingSaved;
130 private int mNumDrawnWindowsExcludingSaved;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700131
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800132 // Is this window's surface needed? This is almost like hidden, except
133 // it will sometimes be true a little earlier: when the token has
134 // been shown, but is still waiting for its app transition to execute
135 // before making its windows shown.
136 boolean hiddenRequested;
137
138 // Have we told the window clients to hide themselves?
Wale Ogunwale89973222017-04-23 18:39:45 -0700139 private boolean mClientHidden;
140
141 // If true we will defer setting mClientHidden to true and reporting to the client that it is
142 // hidden.
143 boolean mDeferHidingClient;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800144
145 // Last visibility state we reported to the app token.
146 boolean reportedVisible;
147
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700148 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700149 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700150
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800151 // Set to true when the token has been removed from the window mgr.
152 boolean removed;
153
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800154 // Information about an application starting window if displayed.
155 StartingData startingData;
156 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800157 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800158 boolean startingDisplayed;
159 boolean startingMoved;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700160 // True if the hidden state of this token was forced to false due to a transferred starting
161 // window.
162 private boolean mHiddenSetFromTransferredStartingWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800163 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700164 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
165 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800166
167 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700168 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800169
Wale Ogunwale571771c2016-08-26 13:18:50 -0700170 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800171 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800172
Craig Mautnerbb742462014-07-07 15:28:55 -0700173 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700174 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700175
Wale Ogunwale72919d22016-12-08 18:58:50 -0800176 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800177
Robert Carre12aece2016-02-02 22:43:27 -0800178 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700179 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700180 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800181
Jorim Jaggife762342016-10-13 14:33:27 +0200182 private boolean mLastContainsShowWhenLockedWindow;
183 private boolean mLastContainsDismissKeyguardWindow;
184
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700185 // The bounds of this activity. Mainly used for aspect-ratio compatibility.
186 // TODO(b/36505427): Every level on WindowContainer now has bounds information, which directly
187 // affects the configuration. We should probably move this into that class.
188 private final Rect mBounds = new Rect();
189
Jorim Jaggi0429f352015-12-22 16:29:16 +0100190 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700191 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100192
Wale Ogunwale6c459212017-05-17 08:56:03 -0700193 private boolean mDisablePreviewScreenshots;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100194
Robert Carred3e83b2017-04-21 13:26:55 -0700195 Task mLastParent;
196
Wale Ogunwale72919d22016-12-08 18:58:50 -0800197 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
198 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
199 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800200 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700201 AppWindowContainerController controller, Configuration overrideConfig, Rect bounds) {
202 this(service, token, voiceInteraction, dc, fullscreen, overrideConfig, bounds);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800203 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800204 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800205 mShowForAllUsers = showForAllUsers;
206 mTargetSdk = targetSdk;
207 mOrientation = orientation;
208 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
209 mLaunchTaskBehind = launchTaskBehind;
210 mAlwaysFocusable = alwaysFocusable;
211 mRotationAnimationHint = rotationAnimationHint;
212
213 // Application tokens start out hidden.
214 hidden = true;
215 hiddenRequested = true;
216 }
217
218 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700219 DisplayContent dc, boolean fillsParent, Configuration overrideConfig, Rect bounds) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800220 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
221 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700222 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800223 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800224 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800225 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700226 mAppAnimator = new AppWindowAnimator(this, service);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700227 if (overrideConfig != null) {
228 onOverrideConfigurationChanged(overrideConfig);
229 }
230 if (bounds != null) {
231 mBounds.set(bounds);
232 }
233 }
234
235 void onOverrideConfigurationChanged(Configuration overrideConfiguration, Rect bounds) {
236 onOverrideConfigurationChanged(overrideConfiguration);
237 if (mBounds.equals(bounds)) {
238 return;
239 }
240 // TODO(b/36505427): If bounds is in WC, then we can automatically call onResize() when set.
241 mBounds.set(bounds);
242 onResize();
243 }
244
245 void getBounds(Rect outBounds) {
246 outBounds.set(mBounds);
247 }
248
249 boolean hasBounds() {
250 return !mBounds.isEmpty();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800251 }
252
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800253 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
254 firstWindowDrawn = true;
255
256 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700257 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800258
Jorim Jaggi02886a82016-12-06 09:10:06 -0800259 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800260 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
261 + win.mToken + ": first real window is shown, no animation");
262 // If this initial window is animating, stop it -- we will do an animation to reveal
263 // it from behind the starting window, so there is no need for it to also be doing its
264 // own stuff.
265 winAnimator.clearAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800266 if (getController() != null) {
267 getController().removeStartingWindow();
268 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800269 }
270 updateReportedVisibilityLocked();
271 }
272
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800273 void updateReportedVisibilityLocked() {
274 if (appToken == null) {
275 return;
276 }
277
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700278 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700279 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800280
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700281 mReportedVisibilityResults.reset();
282
283 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700284 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700285 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800286 }
287
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700288 int numInteresting = mReportedVisibilityResults.numInteresting;
289 int numVisible = mReportedVisibilityResults.numVisible;
290 int numDrawn = mReportedVisibilityResults.numDrawn;
291 boolean nowGone = mReportedVisibilityResults.nowGone;
292
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700293 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800294 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700295 if (!nowGone) {
296 // If the app is not yet gone, then it can only become visible/drawn.
297 if (!nowDrawn) {
298 nowDrawn = reportedDrawn;
299 }
300 if (!nowVisible) {
301 nowVisible = reportedVisible;
302 }
303 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800304 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800305 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800306 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700307 if (nowDrawn != reportedDrawn) {
308 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800309 if (controller != null) {
310 controller.reportWindowsDrawn();
311 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700312 }
313 reportedDrawn = nowDrawn;
314 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800315 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700316 if (DEBUG_VISIBILITY) Slog.v(TAG,
317 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800318 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800319 if (controller != null) {
320 if (nowVisible) {
321 controller.reportWindowsVisible();
322 } else {
323 controller.reportWindowsGone();
324 }
325 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800326 }
327 }
328
Wale Ogunwale89973222017-04-23 18:39:45 -0700329 boolean isClientHidden() {
330 return mClientHidden;
331 }
332
333 void setClientHidden(boolean hideClient) {
334 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
335 return;
336 }
337 mClientHidden = hideClient;
338 sendAppVisibilityToClients();
339 }
340
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700341 boolean setVisibility(WindowManager.LayoutParams lp,
342 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
343
344 boolean delayed = false;
345 inPendingTransaction = false;
346
Wale Ogunwale89973222017-04-23 18:39:45 -0700347 setClientHidden(!visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700348
349 // Allow for state changes and animation to be applied if:
350 // * token is transitioning visibility state
351 // * or the token was marked as hidden and is exiting before we had a chance to play the
352 // transition animation
353 // * or this is an opening app and windows are being replaced.
354 boolean visibilityChanged = false;
355 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700356 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700357 boolean changed = false;
358 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
359 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
360
361 boolean runningAppAnimation = false;
362
363 if (transit != AppTransition.TRANSIT_UNSET) {
364 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
365 mAppAnimator.setNullAnimation();
366 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700367 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700368 delayed = runningAppAnimation = true;
369 }
370 final WindowState window = findMainWindow();
371 //TODO (multidisplay): Magnification is supported only for the default display.
372 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700373 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700374 accessibilityController.onAppWindowTransitionLocked(window, transit);
375 }
376 changed = true;
377 }
378
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700379 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700380 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700381 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700382 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700383 }
384
385 hidden = hiddenRequested = !visible;
386 visibilityChanged = true;
387 if (!visible) {
388 stopFreezingScreen(true, true);
389 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700390 // If we are being set visible, and the starting window is not yet displayed,
391 // then make sure it doesn't get displayed.
392 if (startingWindow != null && !startingWindow.isDrawnLw()) {
393 startingWindow.mPolicyVisibility = false;
394 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700395 }
396 }
397
398 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
399 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
400
401 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700402 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700403 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700404 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700405 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700406 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700407 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700408 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700409 }
410 }
411
412 if (mAppAnimator.animation != null) {
413 delayed = true;
414 }
415
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700416 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700417 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700418 delayed = true;
419 }
420 }
421
422 if (visibilityChanged) {
423 if (visible && !delayed) {
424 // The token was made immediately visible, there will be no entrance animation.
425 // We need to inform the client the enter animation was finished.
426 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700427 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700428 }
Robert Carre7cc44d2017-03-20 19:04:30 -0700429 // If we are hidden but there is no delay needed we immediately
430 // apply the Surface transaction so that the ActivityManager
431 // can have some guarantee on the Surface state
432 // following setting the visibility.
Robert Carr6914f082017-03-20 19:04:30 -0700433 if (hidden && !delayed) {
434 SurfaceControl.openTransaction();
435 for (int i = mChildren.size() - 1; i >= 0; i--) {
436 mChildren.get(i).mWinAnimator.hide("immediately hidden");
437 }
438 SurfaceControl.closeTransaction();
439 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700440
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700441 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700442 // The token is not closing nor opening, so even if there is an animation set, that
443 // doesn't mean that it goes through the normal app transition cycle so we have
444 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700445 // TODO(multi-display): notify docked divider on all displays where visibility was
446 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700447 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700448 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100449 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700450 }
451 }
452
453 return delayed;
454 }
455
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800456 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700457 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700458 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800459 while (j > 0) {
460 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700461 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700462 final int type = win.mAttrs.type;
463 // No need to loop through child window as base application and starting types can't be
464 // child windows.
465 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700466 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900467 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700468 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800469 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700470 candidate = win;
471 } else {
472 return win;
473 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800474 }
475 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700476 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800477 }
478
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800479 boolean windowsAreFocusable() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800480 return StackId.canReceiveKeys(getTask().mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800481 }
482
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800483 AppWindowContainerController getController() {
484 final WindowContainerController controller = super.getController();
485 return controller != null ? (AppWindowContainerController) controller : null;
486 }
487
Wale Ogunwale571771c2016-08-26 13:18:50 -0700488 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700489 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700490 // If the app token isn't hidden then it is considered visible and there is no need to check
491 // its children windows to see if they are visible.
492 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700493 }
494
495 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700496 void removeImmediately() {
497 onRemovedFromDisplay();
498 super.removeImmediately();
499 }
500
501 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700502 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800503 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800504 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800505 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800506 }
507
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700508 @Override
509 boolean checkCompleteDeferredRemoval() {
510 if (mIsExiting) {
511 removeIfPossible();
512 }
513 return super.checkCompleteDeferredRemoval();
514 }
515
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700516 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700517 if (mRemovingFromDisplay) {
518 return;
519 }
520 mRemovingFromDisplay = true;
521
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700522 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
523
Wale Ogunwale72919d22016-12-08 18:58:50 -0800524 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700525
526 mService.mOpeningApps.remove(this);
Jorim Jaggi1b4b23e2016-11-15 16:30:12 -0800527 mService.mUnknownAppVisibilityController.appRemoved(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100528 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700529 waitingToShow = false;
530 if (mService.mClosingApps.contains(this)) {
531 delayed = true;
532 } else if (mService.mAppTransition.isTransitionSet()) {
533 mService.mClosingApps.add(this);
534 delayed = true;
535 }
536
537 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
538 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
539
540 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
541 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
542
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800543 if (startingData != null && getController() != null) {
544 getController().removeStartingWindow();
545 }
546
Winson Chung87e5d552017-04-05 11:49:38 -0700547 // If this window was animating, then we need to ensure that the app transition notifies
548 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
549 // add to that list now
550 if (mAppAnimator.animating) {
551 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
552 }
553
Wale Ogunwalee287e192017-04-21 09:30:12 -0700554 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700555 if (delayed && !isEmpty()) {
556 // set the token aside because it has an active animation to be finished
557 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
558 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700559 if (stack != null) {
560 stack.mExitingAppTokens.add(this);
561 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700562 mIsExiting = true;
563 } else {
564 // Make sure there is no animation running on this token, so any windows associated
565 // with it will be removed as soon as their animations are complete
566 mAppAnimator.clearAnimation();
567 mAppAnimator.animating = false;
Wale Ogunwale3106ae012017-05-16 08:56:37 -0700568 if (stack != null) {
569 stack.mExitingAppTokens.remove(this);
570 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700571 removeIfPossible();
572 }
573
574 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700575 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800576
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700577 if (mService.mFocusedApp == this) {
578 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
579 mService.mFocusedApp = null;
580 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
581 mService.mInputMonitor.setFocusedAppLw(null);
582 }
583
584 if (!delayed) {
585 updateReportedVisibilityLocked();
586 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700587
588 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700589 }
590
Chong Zhange05bcb12016-07-26 17:47:29 -0700591 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700592 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700593 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700594 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700595 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700596 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700597 if (wallpaperMightChange) {
598 requestUpdateWallpaperIfNeeded();
599 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700600 }
601
Robert Carre12aece2016-02-02 22:43:27 -0800602 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700603 destroySurfaces(false /*cleanupOnResume*/);
604 }
605
606 /**
607 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
608 * the client has finished with them.
609 *
610 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
611 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
612 * others so that they are ready to be reused. If set to false (common case), destroy all
613 * surfaces that's eligible, if the app is already stopped.
614 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700615 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700616 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700617 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700618 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700619 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800620 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700621 if (destroyedSomething) {
622 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700623 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800624 }
625 }
626
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800627 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700628 * Notify that the app is now resumed, and it was not stopped before, perform a clean
629 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800630 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700631 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700632 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700633 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700634 mAppStopped = false;
635 if (!wasStopped) {
636 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800637 }
Robert Carre12aece2016-02-02 22:43:27 -0800638 }
639
Chong Zhangbef461f2015-10-27 11:38:24 -0700640 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700641 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
642 * keeping alive in case they were still being used.
643 */
644 void notifyAppStopped() {
645 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
646 mAppStopped = true;
647 destroySurfaces();
648 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800649 if (getController() != null) {
650 getController().removeStartingWindow();
651 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700652 }
653
654 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700655 * Checks whether we should save surfaces for this app.
656 *
657 * @return true if the surfaces should be saved, false otherwise.
658 */
659 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800660 // We want to save surface if the app's windows are "allDrawn".
661 // (If we started entering animation early with saved surfaces, allDrawn
662 // should have been restored to true. So we'll save again in that case
663 // even if app didn't actually finish drawing.)
664 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800665 }
666
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700667 private boolean canRestoreSurfaces() {
668 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700669 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700670 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800671 return true;
672 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700673 }
674 return false;
675 }
676
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700677 private void clearWasVisibleBeforeClientHidden() {
678 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700679 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700680 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700681 }
682 }
683
Chong Zhang8e4bda92016-05-04 15:08:18 -0700684 /**
685 * Whether the app has some window that is invisible in layout, but
686 * animating with saved surface.
687 */
688 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700689 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700690 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700691 if (w.isAnimatingInvisibleWithSavedSurface()) {
692 return true;
693 }
694 }
695 return false;
696 }
697
698 /**
699 * Hide all window surfaces that's still invisible in layout but animating
700 * with a saved surface, and mark them destroying.
701 */
702 void stopUsingSavedSurfaceLocked() {
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.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700706 }
707 destroySurfaces();
708 }
709
Chong Zhangf58631a2016-05-24 16:02:10 -0700710 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700711 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700712 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700713 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700714 }
715 }
716
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700717 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700718 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700719 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700720 return;
721 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700722
723 // Check if all interesting windows are drawn and we can mark allDrawn=true.
724 int interestingNotDrawn = -1;
725
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700726 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700727 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700728 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700729 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800730
Chong Zhang92147042016-05-09 12:47:11 -0700731 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700732 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700733 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700734 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700735 }
736 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700737 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800738
739 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700740 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
741 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700742 }
743
744 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700745 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700746 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800747 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700748 }
Chong Zhang92147042016-05-09 12:47:11 -0700749 }
750
751 void clearAllDrawn() {
752 allDrawn = false;
753 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700754 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700755 }
756
Bryce Lee6d410262017-02-28 15:30:17 -0800757 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800758 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800759 }
760
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800761 TaskStack getStack() {
762 final Task task = getTask();
763 if (task != null) {
764 return task.mStack;
765 } else {
766 return null;
767 }
768 }
769
Bryce Lee6d410262017-02-28 15:30:17 -0800770 @Override
771 void onParentSet() {
772 super.onParentSet();
773
Robert Carred3e83b2017-04-21 13:26:55 -0700774 final Task task = getTask();
775
Bryce Lee6d410262017-02-28 15:30:17 -0800776 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
777 // access visual elements like the {@link DisplayContent}. We must remove any associations
778 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800779 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800780 if (task == null) {
781 // It is possible we have been marked as a closing app earlier. We must remove ourselves
782 // from this list so we do not participate in any future animations.
783 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700784 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800785 task.mStack.mExitingAppTokens.remove(this);
786 }
Bryce Lee6d410262017-02-28 15:30:17 -0800787 }
Robert Carred3e83b2017-04-21 13:26:55 -0700788 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800789 }
790
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700791 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700792 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700793 if (startingWindow == win) {
794 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800795 if (getController() != null) {
796 getController().removeStartingWindow();
797 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700798 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700799 // If this is the last window and we had requested a starting transition window,
800 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800801 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700802 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700803 if (mHiddenSetFromTransferredStartingWindow) {
804 // We set the hidden state to false for the token from a transferred starting window.
805 // We now reset it back to true since the starting window was the last window in the
806 // token.
807 hidden = true;
808 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100809 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700810 // If this is the last window except for a starting transition window,
811 // we need to get rid of the starting transition.
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200812 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Last window, removing starting window "
813 + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800814 if (getController() != null) {
815 getController().removeStartingWindow();
816 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700817 }
818 }
819
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700820 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700821 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700822 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800823 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700824 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700825 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800826 // Set mDestroying, we don't want any animation or delayed removal here.
827 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700828 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700829 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800830 }
831 }
832 }
833
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700834 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700835 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700836 // No need to loop through child windows as the answer should be the same as that of the
837 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700838 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700839 return true;
840 }
841 }
842 return false;
843 }
844
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700845 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700846 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
847 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800848
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700849 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700850 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700851 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800852 }
853 if (animate) {
854 // Set-up dummy animation so we can start treating windows associated with this
855 // token like they are in transition before the new app window is ready for us to
856 // run the real transition animation.
857 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700858 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800859 mAppAnimator.setDummyAnimation();
860 }
861 }
862
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700863 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700864 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800865 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700866 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700867 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700868 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800869 }
870 }
871
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700872 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700873 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
874 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800875
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700876 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700877 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700878 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800879 }
880 }
881
Chong Zhang4d7369a2016-04-25 16:09:14 -0700882 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700883 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700884 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700885 w.requestUpdateWallpaperIfNeeded();
886 }
887 }
888
Chong Zhangd78ddb42016-03-02 17:01:14 -0800889 boolean isRelaunching() {
890 return mPendingRelaunchCount > 0;
891 }
892
893 void startRelaunching() {
894 if (canFreezeBounds()) {
895 freezeBounds();
896 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800897
898 // In the process of tearing down before relaunching, the app will
899 // try and clean up it's child surfaces. We need to prevent this from
900 // happening, so we sever the children, transfering their ownership
901 // from the client it-self to the parent surface (owned by us).
902 for (int i = mChildren.size() - 1; i >= 0; i--) {
903 final WindowState w = mChildren.get(i);
904 w.mWinAnimator.detachChildren();
905 }
906
Chong Zhangd78ddb42016-03-02 17:01:14 -0800907 mPendingRelaunchCount++;
908 }
909
910 void finishRelaunching() {
911 if (canFreezeBounds()) {
912 unfreezeBounds();
913 }
914 if (mPendingRelaunchCount > 0) {
915 mPendingRelaunchCount--;
916 }
Matthew Ng498c71d2017-04-18 13:55:45 -0700917 updateAllDrawn();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800918 }
919
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700920 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700921 if (mPendingRelaunchCount == 0) {
922 return;
923 }
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700924 if (canFreezeBounds()) {
925 unfreezeBounds();
926 }
927 mPendingRelaunchCount = 0;
928 }
929
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700930 /**
931 * Returns true if the new child window we are adding to this token is considered greater than
932 * the existing child window in this token in terms of z-order.
933 */
934 @Override
935 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
936 WindowState existingWindow) {
937 final int type1 = newWindow.mAttrs.type;
938 final int type2 = existingWindow.mAttrs.type;
939
940 // Base application windows should be z-ordered BELOW all other windows in the app token.
941 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
942 return false;
943 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
944 return true;
945 }
946
947 // Starting windows should be z-ordered ABOVE all other windows in the app token.
948 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
949 return true;
950 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
951 return false;
952 }
953
954 // Otherwise the new window is greater than the existing window.
955 return true;
956 }
957
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700958 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800959 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700960 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700961
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700962 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700963 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700964 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700965 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
966 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700967
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700968 // if we got a replacement window, reset the timeout to give drawing more time
969 if (gotReplacementWindow) {
970 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800971 }
Jorim Jaggife762342016-10-13 14:33:27 +0200972 checkKeyguardFlagsChanged();
973 }
974
975 @Override
976 void removeChild(WindowState child) {
977 super.removeChild(child);
978 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800979 }
980
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700981 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700982 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700983 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700984 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800985 return true;
986 }
987 }
988 return false;
989 }
990
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700991 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700992 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700993 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800994 }
995 }
996
Winson Chung30480042017-01-26 10:55:34 -0800997 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800998 final Task currentTask = getTask();
999 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -08001000 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001001 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001002 }
Bryce Lee6d410262017-02-28 15:30:17 -08001003
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001004 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -08001005 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001006 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -08001007 + " belongs to a different stack than " + task);
1008 }
1009
Winson Chung30480042017-01-26 10:55:34 -08001010 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001011 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001012 final DisplayContent prevDisplayContent = getDisplayContent();
1013
Bryce Lee6d410262017-02-28 15:30:17 -08001014 mReparenting = true;
1015
Winson Chung30480042017-01-26 10:55:34 -08001016 getParent().removeChild(this);
1017 task.addChild(this, position);
1018
Bryce Lee6d410262017-02-28 15:30:17 -08001019 mReparenting = false;
1020
Winson Chung30480042017-01-26 10:55:34 -08001021 // Relayout display(s).
1022 final DisplayContent displayContent = task.getDisplayContent();
1023 displayContent.setLayoutNeeded();
1024 if (prevDisplayContent != displayContent) {
1025 onDisplayChanged(displayContent);
1026 prevDisplayContent.setLayoutNeeded();
1027 }
1028 }
1029
Chong Zhangd78ddb42016-03-02 17:01:14 -08001030 private boolean canFreezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001031 final Task task = getTask();
1032
Chong Zhangd78ddb42016-03-02 17:01:14 -08001033 // For freeform windows, we can't freeze the bounds at the moment because this would make
1034 // the resizing unresponsive.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001035 return task != null && !task.inFreeformWorkspace();
Chong Zhangd78ddb42016-03-02 17:01:14 -08001036 }
1037
Jorim Jaggi0429f352015-12-22 16:29:16 +01001038 /**
1039 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
1040 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
1041 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
1042 * with a queue.
1043 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001044 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001045 final Task task = getTask();
1046 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001047
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001048 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001049 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001050 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001051 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001052 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001053 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001054 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001055 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001056 }
1057
1058 /**
1059 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
1060 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001061 private void unfreezeBounds() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001062 if (!mFrozenBounds.isEmpty()) {
1063 mFrozenBounds.remove();
1064 }
1065 if (!mFrozenMergedConfig.isEmpty()) {
1066 mFrozenMergedConfig.remove();
1067 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001068 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001069 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001070 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001071 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001072 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001073 }
1074
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001075 void setAppLayoutChanges(int changes, String reason) {
1076 if (!mChildren.isEmpty()) {
1077 final DisplayContent dc = getDisplayContent();
1078 dc.pendingLayoutChanges |= changes;
1079 if (DEBUG_LAYOUT_REPEATS) {
1080 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001081 }
1082 }
1083 }
1084
1085 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001086 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001087 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001088 if (win.removeReplacedWindowIfNeeded(replacement)) {
1089 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001090 }
1091 }
1092 }
1093
1094 void startFreezingScreen() {
1095 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001096 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
1097 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001098 if (!hiddenRequested) {
1099 if (!mAppAnimator.freezingScreen) {
1100 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001101 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001102 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001103 mService.mAppsFreezingScreen++;
1104 if (mService.mAppsFreezingScreen == 1) {
1105 mService.startFreezingDisplayLocked(false, 0, 0);
1106 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1107 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001108 }
1109 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001110 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001111 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001112 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001113 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001114 }
1115 }
1116 }
1117
1118 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
1119 if (!mAppAnimator.freezingScreen) {
1120 return;
1121 }
1122 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001123 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001124 boolean unfrozeWindows = false;
1125 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001126 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001127 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001128 }
1129 if (force || unfrozeWindows) {
1130 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
1131 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001132 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001133 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001134 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
1135 mService.mAppsFreezingScreen--;
1136 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001137 }
1138 if (unfreezeSurfaceNow) {
1139 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001140 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001141 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001142 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001143 }
1144 }
1145
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001146 @Override
1147 public void onAppFreezeTimeout() {
1148 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1149 stopFreezingScreen(true, true);
1150 }
1151
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001152 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001153 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001154 if (fromToken == null) {
1155 return false;
1156 }
1157
1158 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001159 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001160 // In this case, the starting icon has already been displayed, so start
1161 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001162 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001163
1164 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1165 + " from " + fromToken + " to " + this);
1166
1167 final long origId = Binder.clearCallingIdentity();
1168
1169 // Transfer the starting window over to the new token.
1170 startingData = fromToken.startingData;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001171 startingSurface = fromToken.startingSurface;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001172 startingDisplayed = fromToken.startingDisplayed;
1173 fromToken.startingDisplayed = false;
1174 startingWindow = tStartingWindow;
1175 reportedVisible = fromToken.reportedVisible;
1176 fromToken.startingData = null;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001177 fromToken.startingSurface = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001178 fromToken.startingWindow = null;
1179 fromToken.startingMoved = true;
1180 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001181 tStartingWindow.mAppToken = this;
1182
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001183 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001184 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001185 fromToken.removeChild(tStartingWindow);
1186 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale6c459212017-05-17 08:56:03 -07001187 fromToken.mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001188 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001189
1190 // Propagate other interesting state between the tokens. If the old token is displayed,
1191 // we should immediately force the new one to be displayed. If it is animating, we need
1192 // to move that animation to the new one.
1193 if (fromToken.allDrawn) {
1194 allDrawn = true;
1195 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1196 }
1197 if (fromToken.firstWindowDrawn) {
1198 firstWindowDrawn = true;
1199 }
1200 if (!fromToken.hidden) {
1201 hidden = false;
1202 hiddenRequested = false;
Wale Ogunwale6c459212017-05-17 08:56:03 -07001203 mHiddenSetFromTransferredStartingWindow = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001204 }
Wale Ogunwale89973222017-04-23 18:39:45 -07001205 setClientHidden(fromToken.mClientHidden);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001206 fromToken.mAppAnimator.transferCurrentAnimation(
1207 mAppAnimator, tStartingWindow.mWinAnimator);
1208
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001209 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001210 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001211 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001212 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001213 Binder.restoreCallingIdentity(origId);
1214 return true;
1215 } else if (fromToken.startingData != null) {
1216 // The previous app was getting ready to show a
1217 // starting window, but hasn't yet done so. Steal it!
1218 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1219 "Moving pending starting from " + fromToken + " to " + this);
1220 startingData = fromToken.startingData;
1221 fromToken.startingData = null;
1222 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001223 if (getController() != null) {
1224 getController().scheduleAddStartingWindow();
1225 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001226 return true;
1227 }
1228
1229 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1230 final AppWindowAnimator wAppAnimator = mAppAnimator;
1231 if (tAppAnimator.thumbnail != null) {
1232 // The old token is animating with a thumbnail, transfer that to the new token.
1233 if (wAppAnimator.thumbnail != null) {
1234 wAppAnimator.thumbnail.destroy();
1235 }
1236 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1237 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1238 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1239 tAppAnimator.thumbnail = null;
1240 }
1241 return false;
1242 }
1243
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001244 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001245 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001246 }
1247
1248 void setAllAppWinAnimators() {
1249 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1250 allAppWinAnimators.clear();
1251
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001252 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001253 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001254 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001255 }
1256 }
1257
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001258 @Override
1259 void onAppTransitionDone() {
1260 sendingToBottom = false;
1261 }
1262
Wale Ogunwale51362492016-09-08 17:49:17 -07001263 /**
1264 * We override because this class doesn't want its children affecting its reported orientation
1265 * in anyway.
1266 */
1267 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001268 int getOrientation(int candidate) {
Bryce Leed1ac18c2017-05-11 07:59:41 -07001269 // We do not allow non-fullscreen apps to influence orientation beyond O. While we do
Bryce Lee39791592017-04-26 09:29:12 -07001270 // throw an exception in {@link Activity#onCreate} and
1271 // {@link Activity#setRequestedOrientation}, we also ignore the orientation here so that
1272 // other calculations aren't affected.
Bryce Leed1ac18c2017-05-11 07:59:41 -07001273 if (!fillsParent() && mTargetSdk > O) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001274 // Can't specify orientation if app doesn't fill parent.
1275 return SCREEN_ORIENTATION_UNSET;
1276 }
1277
1278 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1279 // Allow app to specify orientation regardless of its visibility state if the current
1280 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1281 // wants us to use the orientation of the app behind it.
1282 return mOrientation;
1283 }
1284
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001285 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1286 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1287 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001288 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001289 && (isVisible() || mService.mOpeningApps.contains(this))) {
Bryce Leea163b762017-01-24 11:05:01 -08001290 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001291 }
Bryce Leea163b762017-01-24 11:05:01 -08001292
1293 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001294 }
1295
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001296 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1297 int getOrientationIgnoreVisibility() {
1298 return mOrientation;
1299 }
1300
Craig Mautnerdbb79912012-03-01 18:59:14 -08001301 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001302 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001303 if (allDrawn == mAppAnimator.allDrawn) {
1304 return;
1305 }
1306
1307 mAppAnimator.allDrawn = allDrawn;
1308 if (!allDrawn) {
1309 return;
1310 }
1311
1312 // The token has now changed state to having all windows shown... what to do, what to do?
1313 if (mAppAnimator.freezingScreen) {
1314 mAppAnimator.showAllWindowsLocked();
1315 stopFreezingScreen(false, true);
1316 if (DEBUG_ORIENTATION) Slog.i(TAG,
1317 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001318 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001319 // This will set mOrientationChangeComplete and cause a pass through layout.
1320 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001321 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001322 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001323 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001324
1325 // We can now show all of the drawn windows!
1326 if (!mService.mOpeningApps.contains(this)) {
1327 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1328 }
1329 }
1330 }
1331
Matthew Ng498c71d2017-04-18 13:55:45 -07001332 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001333 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001334 // Number of drawn windows can be less when a window is being relaunched, wait for
1335 // all windows to be launched and drawn for this token be considered all drawn
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001336 final int numInteresting = mNumInterestingWindows;
Matthew Ng498c71d2017-04-18 13:55:45 -07001337 if (numInteresting > 0 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001338 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001339 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001340 allDrawn = true;
1341 // Force an additional layout pass where
1342 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001343 if (mDisplayContent != null) {
1344 mDisplayContent.setLayoutNeeded();
1345 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001346 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001347
Winson Chunge7ba6862017-05-24 12:13:33 -07001348 // Notify the pinned stack upon all windows drawn. If there was an animation in
1349 // progress then this signal will resume that animation.
1350 final TaskStack pinnedStack = mDisplayContent.getStackById(PINNED_STACK_ID);
1351 if (pinnedStack != null) {
1352 pinnedStack.onAllWindowsDrawn();
Robert Carrecc06b32017-04-18 14:25:10 -07001353 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001354 }
1355 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001356
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001357 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001358 int numInteresting = mNumInterestingWindowsExcludingSaved;
1359 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001360 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1361 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001362 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001363 allDrawnExcludingSaved = true;
Matthew Ng498c71d2017-04-18 13:55:45 -07001364 if (mDisplayContent != null) {
1365 mDisplayContent.setLayoutNeeded();
1366 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001367 if (isAnimatingInvisibleWithSavedSurface()
1368 && !mService.mFinishedEarlyAnim.contains(this)) {
1369 mService.mFinishedEarlyAnim.add(this);
1370 }
1371 }
1372 }
1373 }
1374
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001375 /**
1376 * Updated this app token tracking states for interesting and drawn windows based on the window.
1377 *
1378 * @return Returns true if the input window is considered interesting and drawn while all the
1379 * windows in this app token where not considered drawn as of the last pass.
1380 */
1381 boolean updateDrawnWindowStates(WindowState w) {
Jorim Jaggie4b0f282017-05-17 15:10:29 +02001382 if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001383 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1384 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1385 }
1386
1387 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1388 return false;
1389 }
1390
1391 if (mLastTransactionSequence != mService.mTransactionSequence) {
1392 mLastTransactionSequence = mService.mTransactionSequence;
1393 mNumInterestingWindows = mNumDrawnWindows = 0;
1394 mNumInterestingWindowsExcludingSaved = 0;
1395 mNumDrawnWindowsExcludingSaved = 0;
1396 startingDisplayed = false;
1397 }
1398
1399 final WindowStateAnimator winAnimator = w.mWinAnimator;
1400
1401 boolean isInterestingAndDrawn = false;
1402
1403 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1404 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1405 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1406 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1407 if (!w.isDrawnLw()) {
1408 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1409 + " pv=" + w.mPolicyVisibility
1410 + " mDrawState=" + winAnimator.drawStateToString()
1411 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1412 + " a=" + winAnimator.mAnimating);
1413 }
1414 }
1415
1416 if (w != startingWindow) {
1417 if (w.isInteresting()) {
1418 mNumInterestingWindows++;
1419 if (w.isDrawnLw()) {
1420 mNumDrawnWindows++;
1421
1422 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1423 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1424 + " freezingScreen=" + mAppAnimator.freezingScreen
1425 + " mAppFreezing=" + w.mAppFreezing);
1426
1427 isInterestingAndDrawn = true;
1428 }
1429 }
1430 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001431 if (getController() != null) {
1432 getController().reportStartingWindowDrawn();
1433 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001434 startingDisplayed = true;
1435 }
1436 }
1437
1438 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1439 if (w != startingWindow && w.isInteresting()) {
1440 mNumInterestingWindowsExcludingSaved++;
1441 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1442 mNumDrawnWindowsExcludingSaved++;
1443
1444 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1445 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1446 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1447 + " freezingScreen=" + mAppAnimator.freezingScreen
1448 + " mAppFreezing=" + w.mAppFreezing);
1449
1450 isInterestingAndDrawn = true;
1451 }
1452 }
1453 }
1454
1455 return isInterestingAndDrawn;
1456 }
1457
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001458 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001459 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001460 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001461 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001462 mAppAnimator.animating = true;
1463 mService.mAnimator.setAnimating(true);
1464 mService.mAnimator.mAppWindowAnimating = true;
1465 } else if (mAppAnimator.wasAnimating) {
1466 // stopped animating, do one more pass through the layout
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001467 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1468 DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001469 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1470 }
1471 }
1472
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001473 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001474 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001475 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1476 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1477 // TODO: Investigate if we need to continue to do this or if we can just process them
1478 // in-order.
1479 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001480 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001481 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001482 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001483 }
1484
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001485 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1486 boolean traverseTopToBottom) {
1487 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001488 }
1489
1490 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001491 AppWindowToken asAppWindowToken() {
1492 // I am an app window token!
1493 return this;
1494 }
1495
1496 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001497 boolean fillsParent() {
1498 return mFillsParent;
1499 }
1500
1501 void setFillsParent(boolean fillsParent) {
1502 mFillsParent = fillsParent;
1503 }
1504
Jorim Jaggife762342016-10-13 14:33:27 +02001505 boolean containsDismissKeyguardWindow() {
1506 for (int i = mChildren.size() - 1; i >= 0; i--) {
1507 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1508 return true;
1509 }
1510 }
1511 return false;
1512 }
1513
1514 boolean containsShowWhenLockedWindow() {
1515 for (int i = mChildren.size() - 1; i >= 0; i--) {
1516 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1517 return true;
1518 }
1519 }
1520 return false;
1521 }
1522
1523 void checkKeyguardFlagsChanged() {
1524 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1525 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1526 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1527 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1528 mService.notifyKeyguardFlagsChanged(null /* callback */);
1529 }
1530 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1531 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1532 }
1533
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001534 WindowState getImeTargetBelowWindow(WindowState w) {
1535 final int index = mChildren.indexOf(w);
1536 if (index > 0) {
1537 final WindowState target = mChildren.get(index - 1);
1538 if (target.canBeImeTarget()) {
1539 return target;
1540 }
1541 }
1542 return null;
1543 }
1544
1545 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1546 WindowState candidate = null;
1547 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1548 final WindowState w = mChildren.get(i);
1549 if (w.mRemoved) {
1550 continue;
1551 }
1552 if (candidate == null || w.mWinAnimator.mAnimLayer >
1553 candidate.mWinAnimator.mAnimLayer) {
1554 candidate = w;
1555 }
1556 }
1557 return candidate;
1558 }
1559
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001560 /**
1561 * See {@link Activity#setDisablePreviewScreenshots}.
1562 */
1563 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001564 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001565 }
1566
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001567 /**
1568 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1569 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1570 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1571 *
1572 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1573 * screenshot.
1574 */
1575 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001576 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001577 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001578 }
1579
Wale Ogunwale51362492016-09-08 17:49:17 -07001580 @Override
Robert Carrdee1b3f2017-02-27 11:33:33 -08001581 int getAnimLayerAdjustment() {
1582 return mAppAnimator.animLayerAdjustment;
1583 }
1584
1585 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001586 void dump(PrintWriter pw, String prefix) {
1587 super.dump(pw, prefix);
1588 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001589 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001590 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001591 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001592 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1593 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07001594 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
1595 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
1596 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001597 if (paused) {
1598 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001599 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001600 if (mAppStopped) {
1601 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1602 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001603 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001604 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001605 pw.print(prefix); pw.print("mNumInterestingWindows=");
1606 pw.print(mNumInterestingWindows);
1607 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001608 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001609 pw.print(" allDrawn="); pw.print(allDrawn);
1610 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1611 pw.println(")");
1612 }
1613 if (inPendingTransaction) {
1614 pw.print(prefix); pw.print("inPendingTransaction=");
1615 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001616 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001617 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001618 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1619 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001620 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001621 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001622 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001623 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07001624 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001625 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001626 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001627 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07001628 pw.print(" startingMoved="); pw.print(startingMoved);
1629 pw.println(" mHiddenSetFromTransferredStartingWindow="
1630 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001631 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001632 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001633 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001634 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001635 }
1636 if (mPendingRelaunchCount != 0) {
1637 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001638 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07001639 if (getController() != null) {
1640 pw.print(prefix); pw.print("controller="); pw.println(getController());
1641 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07001642 if (mRemovingFromDisplay) {
1643 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
1644 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001645 }
1646
1647 @Override
1648 public String toString() {
1649 if (stringName == null) {
1650 StringBuilder sb = new StringBuilder();
1651 sb.append("AppWindowToken{");
1652 sb.append(Integer.toHexString(System.identityHashCode(this)));
1653 sb.append(" token="); sb.append(token); sb.append('}');
1654 stringName = sb.toString();
1655 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001656 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001657 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001658}