blob: 46049f593105dd26d615a2fa0513c3004c1b5808 [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;
Bryce Lee0e7b7c92017-08-10 14:59:00 -070025import static android.os.Build.VERSION_CODES.O_MR1;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070026import static android.view.Display.DEFAULT_DISPLAY;
Jorim Jaggife762342016-10-13 14:33:27 +020027import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020028import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Jorim Jaggife762342016-10-13 14:33:27 +020029import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070030import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080031import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070032import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070033import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
34import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070035import static com.android.server.wm.AppTransition.TRANSIT_UNSET;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080036import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080037import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
38import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070039import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070040import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
41import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080042import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020043import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070044import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080045import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
46import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
47import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
48import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070049import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070050import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070051import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070052import static com.android.server.wm.WindowManagerService.logWithStack;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080053
Filip Gruszczynskia590c992015-11-25 16:45:26 -080054import android.annotation.NonNull;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020055import android.app.Activity;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070056import android.content.res.Configuration;
Jorim Jaggi0429f352015-12-22 16:29:16 +010057import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070058import android.os.Binder;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080059import android.os.Debug;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070060import android.os.IBinder;
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
chaviwd3bf08d2017-08-01 17:24:59 -0700197 /**
198 * See {@link #canTurnScreenOn()}
199 */
200 private boolean mCanTurnScreenOn = true;
201
Wale Ogunwale72919d22016-12-08 18:58:50 -0800202 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
203 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
204 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800205 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700206 AppWindowContainerController controller, Configuration overrideConfig, Rect bounds) {
207 this(service, token, voiceInteraction, dc, fullscreen, overrideConfig, bounds);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800208 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800209 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800210 mShowForAllUsers = showForAllUsers;
211 mTargetSdk = targetSdk;
212 mOrientation = orientation;
213 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
214 mLaunchTaskBehind = launchTaskBehind;
215 mAlwaysFocusable = alwaysFocusable;
216 mRotationAnimationHint = rotationAnimationHint;
217
218 // Application tokens start out hidden.
219 hidden = true;
220 hiddenRequested = true;
221 }
222
223 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700224 DisplayContent dc, boolean fillsParent, Configuration overrideConfig, Rect bounds) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800225 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
226 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700227 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800228 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800229 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800230 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700231 mAppAnimator = new AppWindowAnimator(this, service);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700232 if (overrideConfig != null) {
233 onOverrideConfigurationChanged(overrideConfig);
234 }
235 if (bounds != null) {
236 mBounds.set(bounds);
237 }
238 }
239
240 void onOverrideConfigurationChanged(Configuration overrideConfiguration, Rect bounds) {
241 onOverrideConfigurationChanged(overrideConfiguration);
242 if (mBounds.equals(bounds)) {
243 return;
244 }
245 // TODO(b/36505427): If bounds is in WC, then we can automatically call onResize() when set.
246 mBounds.set(bounds);
247 onResize();
248 }
249
250 void getBounds(Rect outBounds) {
251 outBounds.set(mBounds);
252 }
253
254 boolean hasBounds() {
255 return !mBounds.isEmpty();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800256 }
257
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800258 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
259 firstWindowDrawn = true;
260
261 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700262 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800263
Jorim Jaggi02886a82016-12-06 09:10:06 -0800264 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800265 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
266 + win.mToken + ": first real window is shown, no animation");
267 // If this initial window is animating, stop it -- we will do an animation to reveal
268 // it from behind the starting window, so there is no need for it to also be doing its
269 // own stuff.
270 winAnimator.clearAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800271 if (getController() != null) {
272 getController().removeStartingWindow();
273 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800274 }
275 updateReportedVisibilityLocked();
276 }
277
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800278 void updateReportedVisibilityLocked() {
279 if (appToken == null) {
280 return;
281 }
282
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700283 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700284 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800285
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700286 mReportedVisibilityResults.reset();
287
288 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700289 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700290 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800291 }
292
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700293 int numInteresting = mReportedVisibilityResults.numInteresting;
294 int numVisible = mReportedVisibilityResults.numVisible;
295 int numDrawn = mReportedVisibilityResults.numDrawn;
296 boolean nowGone = mReportedVisibilityResults.nowGone;
297
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700298 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Jorim Jaggi6dfd9ba2017-08-03 15:00:01 +0200299 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting && !hidden;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700300 if (!nowGone) {
301 // If the app is not yet gone, then it can only become visible/drawn.
302 if (!nowDrawn) {
303 nowDrawn = reportedDrawn;
304 }
305 if (!nowVisible) {
306 nowVisible = reportedVisible;
307 }
308 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800309 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800310 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800311 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700312 if (nowDrawn != reportedDrawn) {
313 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800314 if (controller != null) {
315 controller.reportWindowsDrawn();
316 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700317 }
318 reportedDrawn = nowDrawn;
319 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800320 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700321 if (DEBUG_VISIBILITY) Slog.v(TAG,
322 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800323 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800324 if (controller != null) {
325 if (nowVisible) {
326 controller.reportWindowsVisible();
327 } else {
328 controller.reportWindowsGone();
329 }
330 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800331 }
332 }
333
Wale Ogunwale89973222017-04-23 18:39:45 -0700334 boolean isClientHidden() {
335 return mClientHidden;
336 }
337
338 void setClientHidden(boolean hideClient) {
339 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
340 return;
341 }
342 mClientHidden = hideClient;
343 sendAppVisibilityToClients();
344 }
345
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700346 boolean setVisibility(WindowManager.LayoutParams lp,
347 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
348
349 boolean delayed = false;
350 inPendingTransaction = false;
Wale Ogunwale9e4721f2017-05-23 19:37:30 -0700351 // Reset the state of mHiddenSetFromTransferredStartingWindow since visibility is actually
352 // been set by the app now.
353 mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale89973222017-04-23 18:39:45 -0700354 setClientHidden(!visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700355
356 // Allow for state changes and animation to be applied if:
357 // * token is transitioning visibility state
358 // * or the token was marked as hidden and is exiting before we had a chance to play the
359 // transition animation
360 // * or this is an opening app and windows are being replaced.
361 boolean visibilityChanged = false;
362 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700363 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700364 boolean changed = false;
365 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
366 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
367
368 boolean runningAppAnimation = false;
369
370 if (transit != AppTransition.TRANSIT_UNSET) {
371 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
372 mAppAnimator.setNullAnimation();
373 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700374 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700375 delayed = runningAppAnimation = true;
376 }
377 final WindowState window = findMainWindow();
378 //TODO (multidisplay): Magnification is supported only for the default display.
379 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700380 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700381 accessibilityController.onAppWindowTransitionLocked(window, transit);
382 }
383 changed = true;
384 }
385
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700386 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700387 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700388 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700389 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700390 }
391
392 hidden = hiddenRequested = !visible;
393 visibilityChanged = true;
394 if (!visible) {
395 stopFreezingScreen(true, true);
396 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700397 // If we are being set visible, and the starting window is not yet displayed,
398 // then make sure it doesn't get displayed.
399 if (startingWindow != null && !startingWindow.isDrawnLw()) {
400 startingWindow.mPolicyVisibility = false;
401 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700402 }
Jorim Jaggi38d44ec2017-06-14 16:04:59 -0700403
404 // We are becoming visible, so better freeze the screen with the windows that are
405 // getting visible so we also wait for them.
406 forAllWindows(mService::makeWindowFreezingScreenIfNeededLocked, true);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700407 }
408
409 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
410 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
411
412 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700413 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700414 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700415 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700416 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700417 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700418 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700419 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700420 }
421 }
422
423 if (mAppAnimator.animation != null) {
424 delayed = true;
425 }
426
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700427 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700428 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700429 delayed = true;
430 }
431 }
432
433 if (visibilityChanged) {
434 if (visible && !delayed) {
435 // The token was made immediately visible, there will be no entrance animation.
436 // We need to inform the client the enter animation was finished.
437 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700438 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700439 }
Robert Carr61b81112017-07-17 18:08:15 -0700440
Robert Carre7cc44d2017-03-20 19:04:30 -0700441 // If we are hidden but there is no delay needed we immediately
442 // apply the Surface transaction so that the ActivityManager
Robert Carr61b81112017-07-17 18:08:15 -0700443 // can have some guarantee on the Surface state following
444 // setting the visibility. This captures cases like dismissing
445 // the docked or pinned stack where there is no app transition.
446 //
447 // In the case of a "Null" animation, there will be
448 // no animation but there will still be a transition set.
449 // We still need to delay hiding the surface such that it
450 // can be synchronized with showing the next surface in the transition.
451 if (hidden && !delayed && !mService.mAppTransition.isTransitionSet()) {
Robert Carr6914f082017-03-20 19:04:30 -0700452 SurfaceControl.openTransaction();
453 for (int i = mChildren.size() - 1; i >= 0; i--) {
454 mChildren.get(i).mWinAnimator.hide("immediately hidden");
455 }
456 SurfaceControl.closeTransaction();
457 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700458
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700459 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700460 // The token is not closing nor opening, so even if there is an animation set, that
461 // doesn't mean that it goes through the normal app transition cycle so we have
462 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700463 // TODO(multi-display): notify docked divider on all displays where visibility was
464 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700465 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700466 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100467 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700468 }
469 }
470
471 return delayed;
472 }
473
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800474 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700475 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700476 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800477 while (j > 0) {
478 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700479 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700480 final int type = win.mAttrs.type;
481 // No need to loop through child window as base application and starting types can't be
482 // child windows.
483 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700484 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900485 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700486 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800487 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700488 candidate = win;
489 } else {
490 return win;
491 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800492 }
493 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700494 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800495 }
496
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800497 boolean windowsAreFocusable() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800498 return StackId.canReceiveKeys(getTask().mStack.mStackId) || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800499 }
500
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800501 AppWindowContainerController getController() {
502 final WindowContainerController controller = super.getController();
503 return controller != null ? (AppWindowContainerController) controller : null;
504 }
505
Wale Ogunwale571771c2016-08-26 13:18:50 -0700506 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700507 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700508 // If the app token isn't hidden then it is considered visible and there is no need to check
509 // its children windows to see if they are visible.
510 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700511 }
512
513 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700514 void removeImmediately() {
515 onRemovedFromDisplay();
516 super.removeImmediately();
517 }
518
519 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700520 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800521 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800522 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800523 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800524 }
525
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700526 @Override
527 boolean checkCompleteDeferredRemoval() {
528 if (mIsExiting) {
529 removeIfPossible();
530 }
531 return super.checkCompleteDeferredRemoval();
532 }
533
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700534 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700535 if (mRemovingFromDisplay) {
536 return;
537 }
538 mRemovingFromDisplay = true;
539
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700540 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
541
Wale Ogunwale72919d22016-12-08 18:58:50 -0800542 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700543
544 mService.mOpeningApps.remove(this);
Jorim Jaggi45ca0542017-05-30 16:16:01 -0700545 mService.mUnknownAppVisibilityController.appRemovedOrHidden(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100546 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700547 waitingToShow = false;
548 if (mService.mClosingApps.contains(this)) {
549 delayed = true;
550 } else if (mService.mAppTransition.isTransitionSet()) {
551 mService.mClosingApps.add(this);
552 delayed = true;
553 }
554
555 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
556 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
557
558 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
559 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
560
Jorim Jaggi19be6052017-08-03 18:33:43 +0200561 if (startingData != null && getController() != null) {
562 getController().removeStartingWindow();
563 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800564
Winson Chung87e5d552017-04-05 11:49:38 -0700565 // If this window was animating, then we need to ensure that the app transition notifies
566 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
567 // add to that list now
568 if (mAppAnimator.animating) {
569 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
570 }
571
Wale Ogunwalee287e192017-04-21 09:30:12 -0700572 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700573 if (delayed && !isEmpty()) {
574 // set the token aside because it has an active animation to be finished
575 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
576 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700577 if (stack != null) {
578 stack.mExitingAppTokens.add(this);
579 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700580 mIsExiting = true;
581 } else {
582 // Make sure there is no animation running on this token, so any windows associated
583 // with it will be removed as soon as their animations are complete
584 mAppAnimator.clearAnimation();
585 mAppAnimator.animating = false;
Wale Ogunwale3106ae012017-05-16 08:56:37 -0700586 if (stack != null) {
587 stack.mExitingAppTokens.remove(this);
588 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700589 removeIfPossible();
590 }
591
592 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700593 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800594
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700595 if (mService.mFocusedApp == this) {
596 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
597 mService.mFocusedApp = null;
598 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
599 mService.mInputMonitor.setFocusedAppLw(null);
600 }
601
602 if (!delayed) {
603 updateReportedVisibilityLocked();
604 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700605
606 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700607 }
608
Chong Zhange05bcb12016-07-26 17:47:29 -0700609 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700610 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700611 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700612 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700613 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700614 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700615 if (wallpaperMightChange) {
616 requestUpdateWallpaperIfNeeded();
617 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700618 }
619
Robert Carre12aece2016-02-02 22:43:27 -0800620 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700621 destroySurfaces(false /*cleanupOnResume*/);
622 }
623
624 /**
625 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
626 * the client has finished with them.
627 *
628 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
629 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
630 * others so that they are ready to be reused. If set to false (common case), destroy all
631 * surfaces that's eligible, if the app is already stopped.
632 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700633 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700634 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700635 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700636 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700637 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800638 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700639 if (destroyedSomething) {
640 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700641 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800642 }
643 }
644
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800645 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700646 * Notify that the app is now resumed, and it was not stopped before, perform a clean
647 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800648 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700649 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700650 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700651 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700652 mAppStopped = false;
chaviwd3bf08d2017-08-01 17:24:59 -0700653 // Allow the window to turn the screen on once the app is resumed again.
654 setCanTurnScreenOn(true);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700655 if (!wasStopped) {
656 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800657 }
Robert Carre12aece2016-02-02 22:43:27 -0800658 }
659
Chong Zhangbef461f2015-10-27 11:38:24 -0700660 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700661 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
662 * keeping alive in case they were still being used.
663 */
664 void notifyAppStopped() {
665 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
666 mAppStopped = true;
667 destroySurfaces();
668 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800669 if (getController() != null) {
670 getController().removeStartingWindow();
671 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700672 }
673
674 /**
Chong Zhangbef461f2015-10-27 11:38:24 -0700675 * Checks whether we should save surfaces for this app.
676 *
677 * @return true if the surfaces should be saved, false otherwise.
678 */
679 boolean shouldSaveSurface() {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800680 // We want to save surface if the app's windows are "allDrawn".
681 // (If we started entering animation early with saved surfaces, allDrawn
682 // should have been restored to true. So we'll save again in that case
683 // even if app didn't actually finish drawing.)
684 return allDrawn;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800685 }
686
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700687 private boolean canRestoreSurfaces() {
688 for (int i = mChildren.size() -1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700689 final WindowState w = mChildren.get(i);
Chong Zhang92147042016-05-09 12:47:11 -0700690 if (w.canRestoreSurface()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -0800691 return true;
692 }
Chong Zhangbef461f2015-10-27 11:38:24 -0700693 }
694 return false;
695 }
696
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700697 private void clearWasVisibleBeforeClientHidden() {
698 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700699 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700700 w.clearWasVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -0700701 }
702 }
703
Chong Zhang8e4bda92016-05-04 15:08:18 -0700704 /**
705 * Whether the app has some window that is invisible in layout, but
706 * animating with saved surface.
707 */
708 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700709 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700710 final WindowState w = mChildren.get(i);
Chong Zhang8e4bda92016-05-04 15:08:18 -0700711 if (w.isAnimatingInvisibleWithSavedSurface()) {
712 return true;
713 }
714 }
715 return false;
716 }
717
718 /**
719 * Hide all window surfaces that's still invisible in layout but animating
720 * with a saved surface, and mark them destroying.
721 */
722 void stopUsingSavedSurfaceLocked() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700723 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700724 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700725 w.stopUsingSavedSurface();
Chong Zhang8e4bda92016-05-04 15:08:18 -0700726 }
727 destroySurfaces();
728 }
729
Chong Zhangf58631a2016-05-24 16:02:10 -0700730 void markSavedSurfaceExiting() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700731 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700732 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700733 w.markSavedSurfaceExiting();
Chong Zhangf58631a2016-05-24 16:02:10 -0700734 }
735 }
736
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700737 void restoreSavedSurfaceForInterestingWindows() {
Chong Zhang92147042016-05-09 12:47:11 -0700738 if (!canRestoreSurfaces()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700739 clearWasVisibleBeforeClientHidden();
Chong Zhangbef461f2015-10-27 11:38:24 -0700740 return;
741 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700742
743 // Check if all interesting windows are drawn and we can mark allDrawn=true.
744 int interestingNotDrawn = -1;
745
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700746 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700747 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700748 interestingNotDrawn = w.restoreSavedSurfaceForInterestingWindow();
Chong Zhangbef461f2015-10-27 11:38:24 -0700749 }
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800750
Chong Zhang92147042016-05-09 12:47:11 -0700751 if (!allDrawn) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700752 allDrawn = (interestingNotDrawn == 0);
Chong Zhang92147042016-05-09 12:47:11 -0700753 if (allDrawn) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700754 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Chong Zhang92147042016-05-09 12:47:11 -0700755 }
756 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700757 clearWasVisibleBeforeClientHidden();
Chong Zhangbfc2f8f2016-01-29 15:50:34 -0800758
759 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700760 "restoreSavedSurfaceForInterestingWindows: " + this + " allDrawn=" + allDrawn
761 + " interestingNotDrawn=" + interestingNotDrawn);
Chong Zhangbef461f2015-10-27 11:38:24 -0700762 }
763
764 void destroySavedSurfaces() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700765 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700766 final WindowState win = mChildren.get(i);
Robert Carr13f7be9e2015-12-02 18:39:45 -0800767 win.destroySavedSurface();
Chong Zhangbef461f2015-10-27 11:38:24 -0700768 }
Chong Zhang92147042016-05-09 12:47:11 -0700769 }
770
771 void clearAllDrawn() {
772 allDrawn = false;
773 deferClearAllDrawn = false;
Chong Zhang8e4bda92016-05-04 15:08:18 -0700774 allDrawnExcludingSaved = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700775 }
776
Bryce Lee6d410262017-02-28 15:30:17 -0800777 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800778 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800779 }
780
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800781 TaskStack getStack() {
782 final Task task = getTask();
783 if (task != null) {
784 return task.mStack;
785 } else {
786 return null;
787 }
788 }
789
Bryce Lee6d410262017-02-28 15:30:17 -0800790 @Override
791 void onParentSet() {
792 super.onParentSet();
793
Robert Carred3e83b2017-04-21 13:26:55 -0700794 final Task task = getTask();
795
Bryce Lee6d410262017-02-28 15:30:17 -0800796 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
797 // access visual elements like the {@link DisplayContent}. We must remove any associations
798 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800799 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800800 if (task == null) {
801 // It is possible we have been marked as a closing app earlier. We must remove ourselves
802 // from this list so we do not participate in any future animations.
803 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700804 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800805 task.mStack.mExitingAppTokens.remove(this);
806 }
Bryce Lee6d410262017-02-28 15:30:17 -0800807 }
Robert Carred3e83b2017-04-21 13:26:55 -0700808 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800809 }
810
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700811 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700812 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700813 if (startingWindow == win) {
814 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800815 if (getController() != null) {
816 getController().removeStartingWindow();
817 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700818 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700819 // If this is the last window and we had requested a starting transition window,
820 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800821 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700822 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700823 if (mHiddenSetFromTransferredStartingWindow) {
824 // We set the hidden state to false for the token from a transferred starting window.
825 // We now reset it back to true since the starting window was the last window in the
826 // token.
827 hidden = true;
828 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100829 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700830 // If this is the last window except for a starting transition window,
831 // we need to get rid of the starting transition.
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200832 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Last window, removing starting window "
833 + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800834 if (getController() != null) {
835 getController().removeStartingWindow();
836 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700837 }
838 }
839
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700840 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700841 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700842 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800843 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700844 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700845 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800846 // Set mDestroying, we don't want any animation or delayed removal here.
847 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700848 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700849 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800850 }
851 }
852 }
853
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700854 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700855 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700856 // No need to loop through child windows as the answer should be the same as that of the
857 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700858 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700859 return true;
860 }
861 }
862 return false;
863 }
864
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700865 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700866 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
867 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800868
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700869 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700870 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700871 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800872 }
873 if (animate) {
874 // Set-up dummy animation so we can start treating windows associated with this
875 // token like they are in transition before the new app window is ready for us to
876 // run the real transition animation.
877 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700878 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800879 mAppAnimator.setDummyAnimation();
880 }
881 }
882
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700883 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700884 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800885 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700886 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700887 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700888 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800889 }
890 }
891
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700892 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700893 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
894 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800895
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700896 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700897 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700898 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800899 }
900 }
901
Chong Zhang4d7369a2016-04-25 16:09:14 -0700902 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700903 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700904 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700905 w.requestUpdateWallpaperIfNeeded();
906 }
907 }
908
Chong Zhangd78ddb42016-03-02 17:01:14 -0800909 boolean isRelaunching() {
910 return mPendingRelaunchCount > 0;
911 }
912
Robert Carr68375192017-06-13 12:41:53 -0700913 boolean shouldFreezeBounds() {
914 final Task task = getTask();
915
916 // For freeform windows, we can't freeze the bounds at the moment because this would make
917 // the resizing unresponsive.
918 if (task == null || task.inFreeformWorkspace()) {
919 return false;
920 }
921
922 // We freeze the bounds while drag resizing to deal with the time between
923 // the divider/drag handle being released, and the handling it's new
924 // configuration. If we are relaunched outside of the drag resizing state,
925 // we need to be careful not to do this.
926 return getTask().isDragResizing();
927 }
928
Chong Zhangd78ddb42016-03-02 17:01:14 -0800929 void startRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700930 if (shouldFreezeBounds()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -0800931 freezeBounds();
932 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800933
934 // In the process of tearing down before relaunching, the app will
935 // try and clean up it's child surfaces. We need to prevent this from
936 // happening, so we sever the children, transfering their ownership
937 // from the client it-self to the parent surface (owned by us).
938 for (int i = mChildren.size() - 1; i >= 0; i--) {
939 final WindowState w = mChildren.get(i);
940 w.mWinAnimator.detachChildren();
941 }
942
Chong Zhangd78ddb42016-03-02 17:01:14 -0800943 mPendingRelaunchCount++;
944 }
945
946 void finishRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700947 unfreezeBounds();
948
Chong Zhangd78ddb42016-03-02 17:01:14 -0800949 if (mPendingRelaunchCount > 0) {
950 mPendingRelaunchCount--;
Bryce Lee081554b2017-05-25 07:52:12 -0700951 } else {
952 // Update keyguard flags upon finishing relaunch.
953 checkKeyguardFlagsChanged();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800954 }
955 }
956
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700957 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700958 if (mPendingRelaunchCount == 0) {
959 return;
960 }
Robert Carr68375192017-06-13 12:41:53 -0700961 unfreezeBounds();
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700962 mPendingRelaunchCount = 0;
963 }
964
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700965 /**
966 * Returns true if the new child window we are adding to this token is considered greater than
967 * the existing child window in this token in terms of z-order.
968 */
969 @Override
970 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
971 WindowState existingWindow) {
972 final int type1 = newWindow.mAttrs.type;
973 final int type2 = existingWindow.mAttrs.type;
974
975 // Base application windows should be z-ordered BELOW all other windows in the app token.
976 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
977 return false;
978 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
979 return true;
980 }
981
982 // Starting windows should be z-ordered ABOVE all other windows in the app token.
983 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
984 return true;
985 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
986 return false;
987 }
988
989 // Otherwise the new window is greater than the existing window.
990 return true;
991 }
992
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700993 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800994 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700995 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700996
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700997 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700998 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700999 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001000 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
1001 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001002
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001003 // if we got a replacement window, reset the timeout to give drawing more time
1004 if (gotReplacementWindow) {
1005 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -08001006 }
Jorim Jaggife762342016-10-13 14:33:27 +02001007 checkKeyguardFlagsChanged();
1008 }
1009
1010 @Override
1011 void removeChild(WindowState child) {
1012 super.removeChild(child);
1013 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -08001014 }
1015
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001016 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001017 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001018 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001019 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -08001020 return true;
1021 }
1022 }
1023 return false;
1024 }
1025
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001026 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001027 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001028 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -08001029 }
1030 }
1031
Winson Chung30480042017-01-26 10:55:34 -08001032 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001033 final Task currentTask = getTask();
1034 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -08001035 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001036 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001037 }
Bryce Lee6d410262017-02-28 15:30:17 -08001038
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001039 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -08001040 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001041 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -08001042 + " belongs to a different stack than " + task);
1043 }
1044
Winson Chung30480042017-01-26 10:55:34 -08001045 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001046 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -08001047 final DisplayContent prevDisplayContent = getDisplayContent();
1048
Bryce Lee6d410262017-02-28 15:30:17 -08001049 mReparenting = true;
1050
Winson Chung30480042017-01-26 10:55:34 -08001051 getParent().removeChild(this);
1052 task.addChild(this, position);
1053
Bryce Lee6d410262017-02-28 15:30:17 -08001054 mReparenting = false;
1055
Winson Chung30480042017-01-26 10:55:34 -08001056 // Relayout display(s).
1057 final DisplayContent displayContent = task.getDisplayContent();
1058 displayContent.setLayoutNeeded();
1059 if (prevDisplayContent != displayContent) {
1060 onDisplayChanged(displayContent);
1061 prevDisplayContent.setLayoutNeeded();
1062 }
1063 }
1064
Jorim Jaggi0429f352015-12-22 16:29:16 +01001065 /**
1066 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
1067 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
1068 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
1069 * with a queue.
1070 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001071 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001072 final Task task = getTask();
1073 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001074
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001075 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001076 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001077 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001078 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001079 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001080 }
Andrii Kulianb10330d2016-09-16 13:51:46 -07001081 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001082 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001083 }
1084
1085 /**
1086 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
1087 */
Chong Zhangd78ddb42016-03-02 17:01:14 -08001088 private void unfreezeBounds() {
Robert Carr68375192017-06-13 12:41:53 -07001089 if (mFrozenBounds.isEmpty()) {
1090 return;
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001091 }
Robert Carr68375192017-06-13 12:41:53 -07001092 mFrozenBounds.remove();
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001093 if (!mFrozenMergedConfig.isEmpty()) {
1094 mFrozenMergedConfig.remove();
1095 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001096 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001097 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001098 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001099 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001100 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001101 }
1102
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001103 void setAppLayoutChanges(int changes, String reason) {
1104 if (!mChildren.isEmpty()) {
1105 final DisplayContent dc = getDisplayContent();
1106 dc.pendingLayoutChanges |= changes;
1107 if (DEBUG_LAYOUT_REPEATS) {
1108 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001109 }
1110 }
1111 }
1112
1113 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001114 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001115 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001116 if (win.removeReplacedWindowIfNeeded(replacement)) {
1117 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001118 }
1119 }
1120 }
1121
1122 void startFreezingScreen() {
1123 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001124 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
1125 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001126 if (!hiddenRequested) {
1127 if (!mAppAnimator.freezingScreen) {
1128 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001129 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001130 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001131 mService.mAppsFreezingScreen++;
1132 if (mService.mAppsFreezingScreen == 1) {
Bryce Lee8f853582017-06-05 17:25:59 -07001133 mService.startFreezingDisplayLocked(false, 0, 0, getDisplayContent());
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001134 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1135 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001136 }
1137 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001138 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001139 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001140 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001141 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001142 }
1143 }
1144 }
1145
1146 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
1147 if (!mAppAnimator.freezingScreen) {
1148 return;
1149 }
1150 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001151 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001152 boolean unfrozeWindows = false;
1153 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001154 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001155 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001156 }
1157 if (force || unfrozeWindows) {
1158 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
1159 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001160 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001161 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001162 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
1163 mService.mAppsFreezingScreen--;
1164 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001165 }
1166 if (unfreezeSurfaceNow) {
1167 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001168 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001169 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001170 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001171 }
1172 }
1173
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001174 @Override
1175 public void onAppFreezeTimeout() {
1176 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1177 stopFreezingScreen(true, true);
1178 }
1179
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001180 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001181 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001182 if (fromToken == null) {
1183 return false;
1184 }
1185
1186 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001187 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001188 // In this case, the starting icon has already been displayed, so start
1189 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001190 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001191
1192 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1193 + " from " + fromToken + " to " + this);
1194
1195 final long origId = Binder.clearCallingIdentity();
1196
1197 // Transfer the starting window over to the new token.
1198 startingData = fromToken.startingData;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001199 startingSurface = fromToken.startingSurface;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001200 startingDisplayed = fromToken.startingDisplayed;
1201 fromToken.startingDisplayed = false;
1202 startingWindow = tStartingWindow;
1203 reportedVisible = fromToken.reportedVisible;
1204 fromToken.startingData = null;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001205 fromToken.startingSurface = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001206 fromToken.startingWindow = null;
1207 fromToken.startingMoved = true;
1208 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001209 tStartingWindow.mAppToken = this;
1210
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001211 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001212 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001213 fromToken.removeChild(tStartingWindow);
1214 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale6c459212017-05-17 08:56:03 -07001215 fromToken.mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001216 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001217
1218 // Propagate other interesting state between the tokens. If the old token is displayed,
1219 // we should immediately force the new one to be displayed. If it is animating, we need
1220 // to move that animation to the new one.
1221 if (fromToken.allDrawn) {
1222 allDrawn = true;
1223 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1224 }
1225 if (fromToken.firstWindowDrawn) {
1226 firstWindowDrawn = true;
1227 }
1228 if (!fromToken.hidden) {
1229 hidden = false;
1230 hiddenRequested = false;
Wale Ogunwale6c459212017-05-17 08:56:03 -07001231 mHiddenSetFromTransferredStartingWindow = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001232 }
Wale Ogunwale89973222017-04-23 18:39:45 -07001233 setClientHidden(fromToken.mClientHidden);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001234 fromToken.mAppAnimator.transferCurrentAnimation(
1235 mAppAnimator, tStartingWindow.mWinAnimator);
1236
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001237 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001238 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001239 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001240 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001241 Binder.restoreCallingIdentity(origId);
1242 return true;
1243 } else if (fromToken.startingData != null) {
1244 // The previous app was getting ready to show a
1245 // starting window, but hasn't yet done so. Steal it!
1246 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1247 "Moving pending starting from " + fromToken + " to " + this);
1248 startingData = fromToken.startingData;
1249 fromToken.startingData = null;
1250 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001251 if (getController() != null) {
1252 getController().scheduleAddStartingWindow();
1253 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001254 return true;
1255 }
1256
1257 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1258 final AppWindowAnimator wAppAnimator = mAppAnimator;
1259 if (tAppAnimator.thumbnail != null) {
1260 // The old token is animating with a thumbnail, transfer that to the new token.
1261 if (wAppAnimator.thumbnail != null) {
1262 wAppAnimator.thumbnail.destroy();
1263 }
1264 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
1265 wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
1266 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1267 tAppAnimator.thumbnail = null;
1268 }
1269 return false;
1270 }
1271
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001272 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001273 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001274 }
1275
1276 void setAllAppWinAnimators() {
1277 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1278 allAppWinAnimators.clear();
1279
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001280 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001281 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001282 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001283 }
1284 }
1285
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001286 @Override
1287 void onAppTransitionDone() {
1288 sendingToBottom = false;
1289 }
1290
Wale Ogunwale51362492016-09-08 17:49:17 -07001291 /**
1292 * We override because this class doesn't want its children affecting its reported orientation
1293 * in anyway.
1294 */
1295 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001296 int getOrientation(int candidate) {
Bryce Lee0e7b7c92017-08-10 14:59:00 -07001297 // We do not allow non-fullscreen apps to influence orientation starting in O-MR1. While we
1298 // do throw an exception in {@link Activity#onCreate} and
Bryce Lee39791592017-04-26 09:29:12 -07001299 // {@link Activity#setRequestedOrientation}, we also ignore the orientation here so that
1300 // other calculations aren't affected.
Bryce Lee0e7b7c92017-08-10 14:59:00 -07001301 if (!fillsParent() && mTargetSdk >= O_MR1) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001302 // Can't specify orientation if app doesn't fill parent.
1303 return SCREEN_ORIENTATION_UNSET;
1304 }
1305
1306 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1307 // Allow app to specify orientation regardless of its visibility state if the current
1308 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1309 // wants us to use the orientation of the app behind it.
1310 return mOrientation;
1311 }
1312
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001313 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1314 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1315 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001316 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee00d586d2017-07-28 20:48:43 -07001317 && (isVisible() || mService.mOpeningApps.contains(this) || isOnTop())) {
Bryce Leea163b762017-01-24 11:05:01 -08001318 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001319 }
Bryce Leea163b762017-01-24 11:05:01 -08001320
1321 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001322 }
1323
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001324 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1325 int getOrientationIgnoreVisibility() {
1326 return mOrientation;
1327 }
1328
Craig Mautnerdbb79912012-03-01 18:59:14 -08001329 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001330 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001331 if (allDrawn == mAppAnimator.allDrawn) {
1332 return;
1333 }
1334
1335 mAppAnimator.allDrawn = allDrawn;
1336 if (!allDrawn) {
1337 return;
1338 }
1339
1340 // The token has now changed state to having all windows shown... what to do, what to do?
1341 if (mAppAnimator.freezingScreen) {
1342 mAppAnimator.showAllWindowsLocked();
1343 stopFreezingScreen(false, true);
1344 if (DEBUG_ORIENTATION) Slog.i(TAG,
1345 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001346 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001347 // This will set mOrientationChangeComplete and cause a pass through layout.
1348 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001349 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001350 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001351 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001352
1353 // We can now show all of the drawn windows!
1354 if (!mService.mOpeningApps.contains(this)) {
1355 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1356 }
1357 }
1358 }
1359
Matthew Ng5d23afa2017-06-21 16:16:24 -07001360 /**
Bryce Leed390deb2017-06-22 13:14:28 -07001361 * Returns whether the drawn window states of this {@link AppWindowToken} has considered every
1362 * child {@link WindowState}. A child is considered if it has been passed into
1363 * {@link #updateDrawnWindowStates(WindowState)} after being added. This is used to determine
1364 * whether states, such as {@code allDrawn}, can be set, which relies on state variables such as
1365 * {@code mNumInterestingWindows}, which depend on all {@link WindowState}s being considered.
1366 *
1367 * @return {@code true} If all children have been considered, {@code false}.
1368 */
1369 private boolean allDrawnStatesConsidered() {
Bryce Lee6311c4b2017-07-06 14:09:29 -07001370 for (int i = mChildren.size() - 1; i >= 0; --i) {
1371 final WindowState child = mChildren.get(i);
1372 if (child.mightAffectAllDrawn(false /*visibleOnly*/ )
1373 && !child.getDrawnStateEvaluated()) {
Bryce Leed390deb2017-06-22 13:14:28 -07001374 return false;
1375 }
1376 }
1377 return true;
1378 }
1379
1380 /**
Matthew Ng5d23afa2017-06-21 16:16:24 -07001381 * Determines if the token has finished drawing. This should only be called from
1382 * {@link DisplayContent#applySurfaceChangesTransaction}
1383 */
Matthew Ng498c71d2017-04-18 13:55:45 -07001384 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001385 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001386 // Number of drawn windows can be less when a window is being relaunched, wait for
Bryce Leed390deb2017-06-22 13:14:28 -07001387 // all windows to be launched and drawn for this token be considered all drawn.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001388 final int numInteresting = mNumInterestingWindows;
Bryce Leed390deb2017-06-22 13:14:28 -07001389
1390 // We must make sure that all present children have been considered (determined by
1391 // {@link #allDrawnStatesConsidered}) before evaluating whether everything has been
1392 // drawn.
1393 if (numInteresting > 0 && allDrawnStatesConsidered()
1394 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001395 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001396 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001397 allDrawn = true;
1398 // Force an additional layout pass where
1399 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001400 if (mDisplayContent != null) {
1401 mDisplayContent.setLayoutNeeded();
1402 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001403 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001404
Winson Chunge7ba6862017-05-24 12:13:33 -07001405 // Notify the pinned stack upon all windows drawn. If there was an animation in
1406 // progress then this signal will resume that animation.
1407 final TaskStack pinnedStack = mDisplayContent.getStackById(PINNED_STACK_ID);
1408 if (pinnedStack != null) {
1409 pinnedStack.onAllWindowsDrawn();
Robert Carrecc06b32017-04-18 14:25:10 -07001410 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001411 }
1412 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001413
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001414 if (!allDrawnExcludingSaved) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001415 int numInteresting = mNumInterestingWindowsExcludingSaved;
1416 if (numInteresting > 0 && mNumDrawnWindowsExcludingSaved >= numInteresting) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001417 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawnExcludingSaved: " + this
1418 + " interesting=" + numInteresting
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001419 + " drawn=" + mNumDrawnWindowsExcludingSaved);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001420 allDrawnExcludingSaved = true;
Matthew Ng498c71d2017-04-18 13:55:45 -07001421 if (mDisplayContent != null) {
1422 mDisplayContent.setLayoutNeeded();
1423 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001424 if (isAnimatingInvisibleWithSavedSurface()
1425 && !mService.mFinishedEarlyAnim.contains(this)) {
1426 mService.mFinishedEarlyAnim.add(this);
1427 }
1428 }
1429 }
1430 }
1431
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001432 /**
1433 * Updated this app token tracking states for interesting and drawn windows based on the window.
1434 *
1435 * @return Returns true if the input window is considered interesting and drawn while all the
1436 * windows in this app token where not considered drawn as of the last pass.
1437 */
1438 boolean updateDrawnWindowStates(WindowState w) {
Bryce Leed390deb2017-06-22 13:14:28 -07001439 w.setDrawnStateEvaluated(true /*evaluated*/);
1440
Jorim Jaggie4b0f282017-05-17 15:10:29 +02001441 if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001442 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1443 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1444 }
1445
1446 if (allDrawn && allDrawnExcludingSaved && !mAppAnimator.freezingScreen) {
1447 return false;
1448 }
1449
1450 if (mLastTransactionSequence != mService.mTransactionSequence) {
1451 mLastTransactionSequence = mService.mTransactionSequence;
1452 mNumInterestingWindows = mNumDrawnWindows = 0;
1453 mNumInterestingWindowsExcludingSaved = 0;
1454 mNumDrawnWindowsExcludingSaved = 0;
1455 startingDisplayed = false;
1456 }
1457
1458 final WindowStateAnimator winAnimator = w.mWinAnimator;
1459
1460 boolean isInterestingAndDrawn = false;
1461
1462 if (!allDrawn && w.mightAffectAllDrawn(false /* visibleOnly */)) {
1463 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1464 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1465 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1466 if (!w.isDrawnLw()) {
1467 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1468 + " pv=" + w.mPolicyVisibility
1469 + " mDrawState=" + winAnimator.drawStateToString()
1470 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1471 + " a=" + winAnimator.mAnimating);
1472 }
1473 }
1474
1475 if (w != startingWindow) {
1476 if (w.isInteresting()) {
1477 mNumInterestingWindows++;
1478 if (w.isDrawnLw()) {
1479 mNumDrawnWindows++;
1480
1481 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1482 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1483 + " freezingScreen=" + mAppAnimator.freezingScreen
1484 + " mAppFreezing=" + w.mAppFreezing);
1485
1486 isInterestingAndDrawn = true;
1487 }
1488 }
1489 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001490 if (getController() != null) {
1491 getController().reportStartingWindowDrawn();
1492 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001493 startingDisplayed = true;
1494 }
1495 }
1496
1497 if (!allDrawnExcludingSaved && w.mightAffectAllDrawn(true /* visibleOnly */)) {
1498 if (w != startingWindow && w.isInteresting()) {
1499 mNumInterestingWindowsExcludingSaved++;
1500 if (w.isDrawnLw() && !w.isAnimatingWithSavedSurface()) {
1501 mNumDrawnWindowsExcludingSaved++;
1502
1503 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
1504 "tokenMayBeDrawnExcludingSaved: " + this + " w=" + w
1505 + " numInteresting=" + mNumInterestingWindowsExcludingSaved
1506 + " freezingScreen=" + mAppAnimator.freezingScreen
1507 + " mAppFreezing=" + w.mAppFreezing);
1508
1509 isInterestingAndDrawn = true;
1510 }
1511 }
1512 }
1513
1514 return isInterestingAndDrawn;
1515 }
1516
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001517 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001518 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001519 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001520 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001521 mAppAnimator.animating = true;
1522 mService.mAnimator.setAnimating(true);
1523 mService.mAnimator.mAppWindowAnimating = true;
1524 } else if (mAppAnimator.wasAnimating) {
1525 // stopped animating, do one more pass through the layout
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001526 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1527 DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001528 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1529 }
1530 }
1531
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001532 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001533 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001534 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1535 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1536 // TODO: Investigate if we need to continue to do this or if we can just process them
1537 // in-order.
1538 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001539 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001540 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001541 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001542 }
1543
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001544 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1545 boolean traverseTopToBottom) {
1546 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001547 }
1548
1549 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001550 AppWindowToken asAppWindowToken() {
1551 // I am an app window token!
1552 return this;
1553 }
1554
1555 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001556 boolean fillsParent() {
1557 return mFillsParent;
1558 }
1559
1560 void setFillsParent(boolean fillsParent) {
1561 mFillsParent = fillsParent;
1562 }
1563
Jorim Jaggife762342016-10-13 14:33:27 +02001564 boolean containsDismissKeyguardWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001565 // Window state is transient during relaunch. We are not guaranteed to be frozen during the
1566 // entirety of the relaunch.
1567 if (isRelaunching()) {
1568 return mLastContainsDismissKeyguardWindow;
1569 }
1570
Jorim Jaggife762342016-10-13 14:33:27 +02001571 for (int i = mChildren.size() - 1; i >= 0; i--) {
1572 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1573 return true;
1574 }
1575 }
1576 return false;
1577 }
1578
1579 boolean containsShowWhenLockedWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001580 // When we are relaunching, it is possible for us to be unfrozen before our previous
1581 // windows have been added back. Using the cached value ensures that our previous
1582 // showWhenLocked preference is honored until relaunching is complete.
1583 if (isRelaunching()) {
1584 return mLastContainsShowWhenLockedWindow;
1585 }
1586
Jorim Jaggife762342016-10-13 14:33:27 +02001587 for (int i = mChildren.size() - 1; i >= 0; i--) {
1588 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1589 return true;
1590 }
1591 }
Bryce Lee081554b2017-05-25 07:52:12 -07001592
Jorim Jaggife762342016-10-13 14:33:27 +02001593 return false;
1594 }
1595
1596 void checkKeyguardFlagsChanged() {
1597 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1598 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1599 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1600 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1601 mService.notifyKeyguardFlagsChanged(null /* callback */);
1602 }
1603 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1604 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1605 }
1606
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001607 WindowState getImeTargetBelowWindow(WindowState w) {
1608 final int index = mChildren.indexOf(w);
1609 if (index > 0) {
1610 final WindowState target = mChildren.get(index - 1);
1611 if (target.canBeImeTarget()) {
1612 return target;
1613 }
1614 }
1615 return null;
1616 }
1617
Winson Chungbe9be7f2017-06-28 10:55:22 -07001618 int getLowestAnimLayer() {
1619 for (int i = 0; i < mChildren.size(); i++) {
1620 final WindowState w = mChildren.get(i);
1621 if (w.mRemoved) {
1622 continue;
1623 }
1624 return w.mWinAnimator.mAnimLayer;
1625 }
1626 return Integer.MAX_VALUE;
1627 }
1628
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001629 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1630 WindowState candidate = null;
1631 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1632 final WindowState w = mChildren.get(i);
1633 if (w.mRemoved) {
1634 continue;
1635 }
1636 if (candidate == null || w.mWinAnimator.mAnimLayer >
1637 candidate.mWinAnimator.mAnimLayer) {
1638 candidate = w;
1639 }
1640 }
1641 return candidate;
1642 }
1643
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001644 /**
1645 * See {@link Activity#setDisablePreviewScreenshots}.
1646 */
1647 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001648 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001649 }
1650
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001651 /**
chaviwd3bf08d2017-08-01 17:24:59 -07001652 * Sets whether the current launch can turn the screen on. See {@link #canTurnScreenOn()}
1653 */
1654 void setCanTurnScreenOn(boolean canTurnScreenOn) {
1655 mCanTurnScreenOn = canTurnScreenOn;
1656 }
1657
1658 /**
1659 * Indicates whether the current launch can turn the screen on. This is to prevent multiple
1660 * relayouts from turning the screen back on. The screen should only turn on at most
1661 * once per activity resume.
1662 *
1663 * @return true if the screen can be turned on.
1664 */
1665 boolean canTurnScreenOn() {
1666 return mCanTurnScreenOn;
1667 }
1668
1669 /**
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001670 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1671 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1672 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1673 *
1674 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1675 * screenshot.
1676 */
1677 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001678 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001679 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001680 }
1681
Wale Ogunwale51362492016-09-08 17:49:17 -07001682 @Override
Robert Carrdee1b3f2017-02-27 11:33:33 -08001683 int getAnimLayerAdjustment() {
1684 return mAppAnimator.animLayerAdjustment;
1685 }
1686
1687 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001688 void dump(PrintWriter pw, String prefix) {
1689 super.dump(pw, prefix);
1690 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001691 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001692 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001693 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001694 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1695 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07001696 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
1697 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
1698 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001699 if (paused) {
1700 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001701 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001702 if (mAppStopped) {
1703 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1704 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001705 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001706 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001707 pw.print(prefix); pw.print("mNumInterestingWindows=");
1708 pw.print(mNumInterestingWindows);
1709 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001710 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001711 pw.print(" allDrawn="); pw.print(allDrawn);
1712 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1713 pw.println(")");
1714 }
1715 if (inPendingTransaction) {
1716 pw.print(prefix); pw.print("inPendingTransaction=");
1717 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001718 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001719 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001720 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1721 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001722 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001723 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001724 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001725 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07001726 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001727 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001728 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001729 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07001730 pw.print(" startingMoved="); pw.print(startingMoved);
1731 pw.println(" mHiddenSetFromTransferredStartingWindow="
1732 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001733 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001734 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001735 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001736 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001737 }
1738 if (mPendingRelaunchCount != 0) {
1739 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001740 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07001741 if (getController() != null) {
1742 pw.print(prefix); pw.print("controller="); pw.println(getController());
1743 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07001744 if (mRemovingFromDisplay) {
1745 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
1746 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001747 }
1748
1749 @Override
1750 public String toString() {
1751 if (stringName == null) {
1752 StringBuilder sb = new StringBuilder();
1753 sb.append("AppWindowToken{");
1754 sb.append(Integer.toHexString(System.identityHashCode(this)));
1755 sb.append(" token="); sb.append(token); sb.append('}');
1756 stringName = sb.toString();
1757 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001758 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001759 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001760}