blob: 1b463c7889de3816361c438155c284bd0f64dd0b [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 Ogunwaleb62139d2017-09-20 15:37:35 -070019import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
Wale Ogunwale72919d22016-12-08 18:58:50 -080020import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
21import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -070022import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
Wale Ogunwale51362492016-09-08 17:49:17 -070023import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
Bryce Lee0e7b7c92017-08-10 14:59:00 -070024import static android.os.Build.VERSION_CODES.O_MR1;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070025import static android.view.Display.DEFAULT_DISPLAY;
Jorim Jaggife762342016-10-13 14:33:27 +020026import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020027import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Jorim Jaggife762342016-10-13 14:33:27 +020028import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Wale Ogunwaled1c37912016-08-16 03:19:39 -070029import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080030import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070031import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070032import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
33import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070034import static com.android.server.wm.AppTransition.TRANSIT_UNSET;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080035import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080036import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
37import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070038import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070039import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
40import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
Wale Ogunwale9017ec02016-02-25 08:55:25 -080041import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020042import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070043import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TOKEN_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080044import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
45import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
46import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
47import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Chong Zhang92147042016-05-09 12:47:11 -070048import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070049import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070050import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070051import static com.android.server.wm.WindowManagerService.logWithStack;
Steven Timotiusaf03df62017-07-18 16:56:43 -070052import static com.android.server.wm.proto.AppWindowTokenProto.NAME;
53import static com.android.server.wm.proto.AppWindowTokenProto.WINDOW_TOKEN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080054
Wale Ogunwale0d5609b2017-09-13 05:55:07 -070055import android.annotation.CallSuper;
Filip Gruszczynskia590c992015-11-25 16:45:26 -080056import android.annotation.NonNull;
Jorim Jaggid635a4a2017-05-03 15:21:26 +020057import android.app.Activity;
Jorim Jaggi26c8c422016-05-09 19:57:25 -070058import android.content.res.Configuration;
Jorim Jaggi0429f352015-12-22 16:29:16 +010059import android.graphics.Rect;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070060import android.os.Binder;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080061import android.os.Debug;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070062import android.os.IBinder;
Steven Timotiusaf03df62017-07-18 16:56:43 -070063import android.os.RemoteException;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070064import android.os.SystemClock;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080065import android.util.Slog;
Steven Timotiusaf03df62017-07-18 16:56:43 -070066import android.util.proto.ProtoOutputStream;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080067import android.view.IApplicationToken;
Robert Carr6914f082017-03-20 19:04:30 -070068import android.view.SurfaceControl;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080069import android.view.WindowManager;
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +020070import android.view.WindowManager.LayoutParams;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -080071import android.view.WindowManagerPolicy.StartingSurface;
72
73import com.android.internal.util.ToBooleanFunction;
74import com.android.server.input.InputApplicationHandle;
75import com.android.server.wm.WindowManagerService.H;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080076
77import java.io.PrintWriter;
Jorim Jaggi0429f352015-12-22 16:29:16 +010078import java.util.ArrayDeque;
Craig Mautnerb1fd65c02013-02-05 13:34:57 -080079import java.util.ArrayList;
80
81class AppTokenList extends ArrayList<AppWindowToken> {
82}
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080083
84/**
85 * Version of WindowToken that is specifically for a particular application (or
86 * really activity) that is displaying windows.
87 */
Wale Ogunwale3f4433d2016-08-18 20:42:42 -070088class AppWindowToken extends WindowToken implements WindowManagerService.AppFreezeListener {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080089 private static final String TAG = TAG_WITH_CLASS_NAME ? "AppWindowToken" : TAG_WM;
90
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080091 // Non-null only for application tokens.
92 final IApplicationToken appToken;
93
Filip Gruszczynskia590c992015-11-25 16:45:26 -080094 @NonNull final AppWindowAnimator mAppAnimator;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -070095
Wale Ogunwale72919d22016-12-08 18:58:50 -080096 final boolean mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -070097
Wale Ogunwale51362492016-09-08 17:49:17 -070098 /** @see WindowContainer#fillsParent() */
99 private boolean mFillsParent;
Craig Mautner4c5eb222013-11-18 12:59:05 -0800100 boolean layoutConfigChanges;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800101 boolean mShowForAllUsers;
102 int mTargetSdk;
Craig Mautnera2c77052012-03-26 12:14:43 -0700103
Bryce Lee6d410262017-02-28 15:30:17 -0800104 // Flag set while reparenting to prevent actions normally triggered by an individual parent
105 // change.
106 private boolean mReparenting;
107
Wale Ogunwalee287e192017-04-21 09:30:12 -0700108 // True if we are current in the process of removing this app token from the display
109 private boolean mRemovingFromDisplay = false;
110
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800111 // The input dispatching timeout for this application token in nanoseconds.
Wale Ogunwale72919d22016-12-08 18:58:50 -0800112 long mInputDispatchingTimeoutNanos;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800113
114 // These are used for determining when all windows associated with
115 // an activity have been drawn, so they can be made visible together
116 // at the same time.
Craig Mautner764983d2012-03-22 11:37:36 -0700117 // initialize so that it doesn't match mTransactionSequence which is an int.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700118 private long mLastTransactionSequence = Long.MIN_VALUE;
119 private int mNumInterestingWindows;
120 private int mNumDrawnWindows;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800121 boolean inPendingTransaction;
122 boolean allDrawn;
Craig Mautner7636dfb2012-11-16 15:24:11 -0800123 // Set to true when this app creates a surface while in the middle of an animation. In that
124 // case do not clear allDrawn until the animation completes.
125 boolean deferClearAllDrawn;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800126
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800127 // Is this window's surface needed? This is almost like hidden, except
128 // it will sometimes be true a little earlier: when the token has
129 // been shown, but is still waiting for its app transition to execute
130 // before making its windows shown.
131 boolean hiddenRequested;
132
133 // Have we told the window clients to hide themselves?
Wale Ogunwale89973222017-04-23 18:39:45 -0700134 private boolean mClientHidden;
135
136 // If true we will defer setting mClientHidden to true and reporting to the client that it is
137 // hidden.
138 boolean mDeferHidingClient;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800139
140 // Last visibility state we reported to the app token.
141 boolean reportedVisible;
142
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700143 // Last drawn state we reported to the app token.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700144 private boolean reportedDrawn;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700145
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800146 // Set to true when the token has been removed from the window mgr.
147 boolean removed;
148
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800149 // Information about an application starting window if displayed.
150 StartingData startingData;
151 WindowState startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800152 StartingSurface startingSurface;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800153 boolean startingDisplayed;
154 boolean startingMoved;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700155 // True if the hidden state of this token was forced to false due to a transferred starting
156 // window.
157 private boolean mHiddenSetFromTransferredStartingWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800158 boolean firstWindowDrawn;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700159 private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
160 new WindowState.UpdateReportedVisibilityResults();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800161
162 // Input application handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700163 final InputApplicationHandle mInputApplicationHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800164
Wale Ogunwale571771c2016-08-26 13:18:50 -0700165 // TODO: Have a WindowContainer state for tracking exiting/deferred removal.
Craig Mautner799bc1d2015-01-14 10:33:48 -0800166 boolean mIsExiting;
Craig Mautner9ef471f2014-02-07 13:11:47 -0800167
Craig Mautnerbb742462014-07-07 15:28:55 -0700168 boolean mLaunchTaskBehind;
Craig Mautner8746a472014-07-24 15:12:54 -0700169 boolean mEnteringAnimation;
Craig Mautnerbb742462014-07-07 15:28:55 -0700170
Wale Ogunwale72919d22016-12-08 18:58:50 -0800171 private boolean mAlwaysFocusable;
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800172
Robert Carre12aece2016-02-02 22:43:27 -0800173 boolean mAppStopped;
Robert Carrfd10cd12016-06-29 16:41:50 -0700174 int mRotationAnimationHint;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700175 private int mPendingRelaunchCount;
Robert Carre12aece2016-02-02 22:43:27 -0800176
Jorim Jaggife762342016-10-13 14:33:27 +0200177 private boolean mLastContainsShowWhenLockedWindow;
178 private boolean mLastContainsDismissKeyguardWindow;
179
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700180 // The bounds of this activity. Mainly used for aspect-ratio compatibility.
181 // TODO(b/36505427): Every level on WindowContainer now has bounds information, which directly
182 // affects the configuration. We should probably move this into that class.
183 private final Rect mBounds = new Rect();
184
Jorim Jaggi0429f352015-12-22 16:29:16 +0100185 ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700186 ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100187
Wale Ogunwale6c459212017-05-17 08:56:03 -0700188 private boolean mDisablePreviewScreenshots;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +0100189
Wale Ogunwale034a8ec2017-09-02 17:14:40 -0700190 private Task mLastParent;
Robert Carred3e83b2017-04-21 13:26:55 -0700191
chaviwd3bf08d2017-08-01 17:24:59 -0700192 /**
193 * See {@link #canTurnScreenOn()}
194 */
195 private boolean mCanTurnScreenOn = true;
196
Wale Ogunwale72919d22016-12-08 18:58:50 -0800197 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
198 DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
199 boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800200 int configChanges, boolean launchTaskBehind, boolean alwaysFocusable,
Wale Ogunwale034a8ec2017-09-02 17:14:40 -0700201 AppWindowContainerController controller, Rect bounds) {
202 this(service, token, voiceInteraction, dc, fullscreen, bounds);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800203 setController(controller);
Wale Ogunwale72919d22016-12-08 18:58:50 -0800204 mInputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800205 mShowForAllUsers = showForAllUsers;
206 mTargetSdk = targetSdk;
207 mOrientation = orientation;
208 layoutConfigChanges = (configChanges & (CONFIG_SCREEN_SIZE | CONFIG_ORIENTATION)) != 0;
209 mLaunchTaskBehind = launchTaskBehind;
210 mAlwaysFocusable = alwaysFocusable;
211 mRotationAnimationHint = rotationAnimationHint;
212
213 // Application tokens start out hidden.
214 hidden = true;
215 hiddenRequested = true;
216 }
217
218 AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
Wale Ogunwale034a8ec2017-09-02 17:14:40 -0700219 DisplayContent dc, boolean fillsParent, Rect bounds) {
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800220 super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true, dc,
221 false /* ownerCanManageAppTokens */);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700222 appToken = token;
Wale Ogunwale72919d22016-12-08 18:58:50 -0800223 mVoiceInteraction = voiceInteraction;
Wale Ogunwale17f175c2017-02-07 16:54:10 -0800224 mFillsParent = fillsParent;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800225 mInputApplicationHandle = new InputApplicationHandle(this);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700226 mAppAnimator = new AppWindowAnimator(this, service);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700227 if (bounds != null) {
228 mBounds.set(bounds);
229 }
230 }
231
232 void onOverrideConfigurationChanged(Configuration overrideConfiguration, Rect bounds) {
233 onOverrideConfigurationChanged(overrideConfiguration);
234 if (mBounds.equals(bounds)) {
235 return;
236 }
237 // TODO(b/36505427): If bounds is in WC, then we can automatically call onResize() when set.
238 mBounds.set(bounds);
239 onResize();
240 }
241
242 void getBounds(Rect outBounds) {
243 outBounds.set(mBounds);
244 }
245
246 boolean hasBounds() {
247 return !mBounds.isEmpty();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800248 }
249
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800250 void onFirstWindowDrawn(WindowState win, WindowStateAnimator winAnimator) {
251 firstWindowDrawn = true;
252
253 // We now have a good window to show, remove dead placeholders
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700254 removeDeadWindows();
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800255
Jorim Jaggi02886a82016-12-06 09:10:06 -0800256 if (startingWindow != null) {
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800257 if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, "Finish starting "
258 + win.mToken + ": first real window is shown, no animation");
259 // If this initial window is animating, stop it -- we will do an animation to reveal
260 // it from behind the starting window, so there is no need for it to also be doing its
261 // own stuff.
262 winAnimator.clearAnimation();
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800263 if (getController() != null) {
264 getController().removeStartingWindow();
265 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -0800266 }
267 updateReportedVisibilityLocked();
268 }
269
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800270 void updateReportedVisibilityLocked() {
271 if (appToken == null) {
272 return;
273 }
274
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700275 if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this);
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700276 final int count = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800277
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700278 mReportedVisibilityResults.reset();
279
280 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700281 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700282 win.updateReportedVisibility(mReportedVisibilityResults);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800283 }
284
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700285 int numInteresting = mReportedVisibilityResults.numInteresting;
286 int numVisible = mReportedVisibilityResults.numVisible;
287 int numDrawn = mReportedVisibilityResults.numDrawn;
288 boolean nowGone = mReportedVisibilityResults.nowGone;
289
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700290 boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
Jorim Jaggi6dfd9ba2017-08-03 15:00:01 +0200291 boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting && !hidden;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700292 if (!nowGone) {
293 // If the app is not yet gone, then it can only become visible/drawn.
294 if (!nowDrawn) {
295 nowDrawn = reportedDrawn;
296 }
297 if (!nowVisible) {
298 nowVisible = reportedVisible;
299 }
300 }
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800301 if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800302 + numInteresting + " visible=" + numVisible);
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800303 final AppWindowContainerController controller = getController();
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700304 if (nowDrawn != reportedDrawn) {
305 if (nowDrawn) {
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800306 if (controller != null) {
307 controller.reportWindowsDrawn();
308 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700309 }
310 reportedDrawn = nowDrawn;
311 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800312 if (nowVisible != reportedVisible) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700313 if (DEBUG_VISIBILITY) Slog.v(TAG,
314 "Visibility changed in " + this + ": vis=" + nowVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800315 reportedVisible = nowVisible;
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800316 if (controller != null) {
317 if (nowVisible) {
318 controller.reportWindowsVisible();
319 } else {
320 controller.reportWindowsGone();
321 }
322 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800323 }
324 }
325
Wale Ogunwale89973222017-04-23 18:39:45 -0700326 boolean isClientHidden() {
327 return mClientHidden;
328 }
329
330 void setClientHidden(boolean hideClient) {
331 if (mClientHidden == hideClient || (hideClient && mDeferHidingClient)) {
332 return;
333 }
334 mClientHidden = hideClient;
335 sendAppVisibilityToClients();
336 }
337
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700338 boolean setVisibility(WindowManager.LayoutParams lp,
339 boolean visible, int transit, boolean performLayout, boolean isVoiceInteraction) {
340
341 boolean delayed = false;
342 inPendingTransaction = false;
Wale Ogunwale9e4721f2017-05-23 19:37:30 -0700343 // Reset the state of mHiddenSetFromTransferredStartingWindow since visibility is actually
344 // been set by the app now.
345 mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale89973222017-04-23 18:39:45 -0700346 setClientHidden(!visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700347
348 // Allow for state changes and animation to be applied if:
349 // * token is transitioning visibility state
350 // * or the token was marked as hidden and is exiting before we had a chance to play the
351 // transition animation
352 // * or this is an opening app and windows are being replaced.
353 boolean visibilityChanged = false;
354 if (hidden == visible || (hidden && mIsExiting) || (visible && waitingForReplacement())) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700355 final AccessibilityController accessibilityController = mService.mAccessibilityController;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700356 boolean changed = false;
357 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
358 "Changing app " + this + " hidden=" + hidden + " performLayout=" + performLayout);
359
360 boolean runningAppAnimation = false;
361
Jorim Jaggi4d1835d2017-08-31 17:28:27 +0200362 if (mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
363 mAppAnimator.setNullAnimation();
364 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700365 if (transit != AppTransition.TRANSIT_UNSET) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700366 if (mService.applyAnimationLocked(this, lp, transit, visible, isVoiceInteraction)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700367 delayed = runningAppAnimation = true;
368 }
369 final WindowState window = findMainWindow();
370 //TODO (multidisplay): Magnification is supported only for the default display.
371 if (window != null && accessibilityController != null
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700372 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700373 accessibilityController.onAppWindowTransitionLocked(window, transit);
374 }
375 changed = true;
376 }
377
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700378 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700379 for (int i = 0; i < windowsCount; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700380 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700381 changed |= win.onAppVisibilityChanged(visible, runningAppAnimation);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700382 }
383
384 hidden = hiddenRequested = !visible;
385 visibilityChanged = true;
386 if (!visible) {
387 stopFreezingScreen(true, true);
388 } else {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700389 // If we are being set visible, and the starting window is not yet displayed,
390 // then make sure it doesn't get displayed.
391 if (startingWindow != null && !startingWindow.isDrawnLw()) {
392 startingWindow.mPolicyVisibility = false;
393 startingWindow.mPolicyVisibilityAfterAnim = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700394 }
Jorim Jaggi38d44ec2017-06-14 16:04:59 -0700395
396 // We are becoming visible, so better freeze the screen with the windows that are
397 // getting visible so we also wait for them.
398 forAllWindows(mService::makeWindowFreezingScreenIfNeededLocked, true);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700399 }
400
401 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "setVisibility: " + this
402 + ": hidden=" + hidden + " hiddenRequested=" + hiddenRequested);
403
404 if (changed) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700405 mService.mInputMonitor.setUpdateInputWindowsNeededLw();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700406 if (performLayout) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700407 mService.updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700408 false /*updateInputWindows*/);
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700409 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700410 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700411 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700412 }
413 }
414
415 if (mAppAnimator.animation != null) {
416 delayed = true;
417 }
418
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700419 for (int i = mChildren.size() - 1; i >= 0 && !delayed; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700420 if ((mChildren.get(i)).isWindowAnimationSet()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700421 delayed = true;
422 }
423 }
424
425 if (visibilityChanged) {
426 if (visible && !delayed) {
427 // The token was made immediately visible, there will be no entrance animation.
428 // We need to inform the client the enter animation was finished.
429 mEnteringAnimation = true;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700430 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700431 }
Robert Carr61b81112017-07-17 18:08:15 -0700432
Robert Carre7cc44d2017-03-20 19:04:30 -0700433 // If we are hidden but there is no delay needed we immediately
434 // apply the Surface transaction so that the ActivityManager
Robert Carr61b81112017-07-17 18:08:15 -0700435 // can have some guarantee on the Surface state following
436 // setting the visibility. This captures cases like dismissing
437 // the docked or pinned stack where there is no app transition.
438 //
439 // In the case of a "Null" animation, there will be
440 // no animation but there will still be a transition set.
441 // We still need to delay hiding the surface such that it
442 // can be synchronized with showing the next surface in the transition.
443 if (hidden && !delayed && !mService.mAppTransition.isTransitionSet()) {
Robert Carr6914f082017-03-20 19:04:30 -0700444 SurfaceControl.openTransaction();
445 for (int i = mChildren.size() - 1; i >= 0; i--) {
446 mChildren.get(i).mWinAnimator.hide("immediately hidden");
447 }
448 SurfaceControl.closeTransaction();
449 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700450
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700451 if (!mService.mClosingApps.contains(this) && !mService.mOpeningApps.contains(this)) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700452 // The token is not closing nor opening, so even if there is an animation set, that
453 // doesn't mean that it goes through the normal app transition cycle so we have
454 // to inform the docked controller about visibility change.
Andrii Kulian1e32e022016-09-16 15:29:34 -0700455 // TODO(multi-display): notify docked divider on all displays where visibility was
456 // affected.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -0700457 mService.getDefaultDisplayContentLocked().getDockedDividerController()
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700458 .notifyAppVisibilityChanged();
Jorim Jaggi8b702ed2017-01-20 16:59:03 +0100459 mService.mTaskSnapshotController.notifyAppVisibilityChanged(this, visible);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700460 }
461 }
462
463 return delayed;
464 }
465
Jorim Jaggi87fdbcb2017-08-17 13:41:11 +0200466 /**
467 * @return The to top most child window for which {@link LayoutParams#isFullscreen()} returns
468 * true.
469 */
470 WindowState getTopFullscreenWindow() {
471 for (int i = mChildren.size() - 1; i >= 0; i--) {
472 final WindowState win = mChildren.get(i);
473 if (win != null && win.mAttrs.isFullscreen()) {
474 return win;
475 }
476 }
477 return null;
478 }
479
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800480 WindowState findMainWindow() {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700481 WindowState candidate = null;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700482 int j = mChildren.size();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800483 while (j > 0) {
484 j--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700485 final WindowState win = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700486 final int type = win.mAttrs.type;
487 // No need to loop through child window as base application and starting types can't be
488 // child windows.
489 if (type == TYPE_BASE_APPLICATION || type == TYPE_APPLICATION_STARTING) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700490 // In cases where there are multiple windows, we prefer the non-exiting window. This
Sungsoo Lim0d3d1f82015-12-02 14:47:59 +0900491 // happens for example when replacing windows during an activity relaunch. When
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700492 // constructing the animation, we want the new window, not the exiting one.
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800493 if (win.mAnimatingExit) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700494 candidate = win;
495 } else {
496 return win;
497 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800498 }
499 }
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700500 return candidate;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800501 }
502
Wale Ogunwale6cae7652015-12-26 07:36:26 -0800503 boolean windowsAreFocusable() {
Wale Ogunwale3382ab12017-07-27 08:55:03 -0700504 return getWindowConfiguration().canReceiveKeys() || mAlwaysFocusable;
Wale Ogunwaled045c822015-12-02 09:14:28 -0800505 }
506
Wale Ogunwale26c0dfe2016-12-14 14:42:30 -0800507 AppWindowContainerController getController() {
508 final WindowContainerController controller = super.getController();
509 return controller != null ? (AppWindowContainerController) controller : null;
510 }
511
Wale Ogunwale571771c2016-08-26 13:18:50 -0700512 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -0700513 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -0700514 // If the app token isn't hidden then it is considered visible and there is no need to check
515 // its children windows to see if they are visible.
516 return !hidden;
Wale Ogunwale44f21802016-09-02 12:49:48 -0700517 }
518
519 @Override
Wale Ogunwalee287e192017-04-21 09:30:12 -0700520 void removeImmediately() {
521 onRemovedFromDisplay();
522 super.removeImmediately();
523 }
524
525 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -0700526 void removeIfPossible() {
Craig Mautnere3119b72015-01-20 15:02:36 -0800527 mIsExiting = false;
Wale Ogunwale3d0bfd92016-12-05 11:38:02 -0800528 removeAllWindowsIfPossible();
Bryce Lee6d410262017-02-28 15:30:17 -0800529 removeImmediately();
Craig Mautnere3119b72015-01-20 15:02:36 -0800530 }
531
Wale Ogunwale3f4433d2016-08-18 20:42:42 -0700532 @Override
533 boolean checkCompleteDeferredRemoval() {
534 if (mIsExiting) {
535 removeIfPossible();
536 }
537 return super.checkCompleteDeferredRemoval();
538 }
539
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700540 void onRemovedFromDisplay() {
Wale Ogunwalee287e192017-04-21 09:30:12 -0700541 if (mRemovingFromDisplay) {
542 return;
543 }
544 mRemovingFromDisplay = true;
545
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700546 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + this);
547
Wale Ogunwale72919d22016-12-08 18:58:50 -0800548 boolean delayed = setVisibility(null, false, TRANSIT_UNSET, true, mVoiceInteraction);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700549
550 mService.mOpeningApps.remove(this);
Jorim Jaggi45ca0542017-05-30 16:16:01 -0700551 mService.mUnknownAppVisibilityController.appRemovedOrHidden(this);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +0100552 mService.mTaskSnapshotController.onAppRemoved(this);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700553 waitingToShow = false;
554 if (mService.mClosingApps.contains(this)) {
555 delayed = true;
556 } else if (mService.mAppTransition.isTransitionSet()) {
557 mService.mClosingApps.add(this);
558 delayed = true;
559 }
560
561 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + this + " delayed=" + delayed
562 + " animation=" + mAppAnimator.animation + " animating=" + mAppAnimator.animating);
563
564 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
565 + this + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
566
Jorim Jaggi19be6052017-08-03 18:33:43 +0200567 if (startingData != null && getController() != null) {
568 getController().removeStartingWindow();
569 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800570
Winson Chung87e5d552017-04-05 11:49:38 -0700571 // If this window was animating, then we need to ensure that the app transition notifies
572 // that animations have completed in WMS.handleAnimatingStoppedAndTransitionLocked(), so
573 // add to that list now
574 if (mAppAnimator.animating) {
575 mService.mNoAnimationNotifyOnTransitionFinished.add(token);
576 }
577
Wale Ogunwalee287e192017-04-21 09:30:12 -0700578 final TaskStack stack = getStack();
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700579 if (delayed && !isEmpty()) {
580 // set the token aside because it has an active animation to be finished
581 if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
582 "removeAppToken make exiting: " + this);
Wale Ogunwalee287e192017-04-21 09:30:12 -0700583 if (stack != null) {
584 stack.mExitingAppTokens.add(this);
585 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700586 mIsExiting = true;
587 } else {
588 // Make sure there is no animation running on this token, so any windows associated
589 // with it will be removed as soon as their animations are complete
590 mAppAnimator.clearAnimation();
591 mAppAnimator.animating = false;
Wale Ogunwale3106ae012017-05-16 08:56:37 -0700592 if (stack != null) {
593 stack.mExitingAppTokens.remove(this);
594 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700595 removeIfPossible();
596 }
597
598 removed = true;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700599 stopFreezingScreen(true, true);
Bryce Lee6d410262017-02-28 15:30:17 -0800600
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700601 if (mService.mFocusedApp == this) {
602 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + this);
603 mService.mFocusedApp = null;
604 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
605 mService.mInputMonitor.setFocusedAppLw(null);
606 }
607
608 if (!delayed) {
609 updateReportedVisibilityLocked();
610 }
Wale Ogunwalee287e192017-04-21 09:30:12 -0700611
612 mRemovingFromDisplay = false;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -0700613 }
614
Chong Zhange05bcb12016-07-26 17:47:29 -0700615 void clearAnimatingFlags() {
Chong Zhangb0d26702016-08-12 16:03:29 -0700616 boolean wallpaperMightChange = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700617 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700618 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700619 wallpaperMightChange |= win.clearAnimatingFlags();
Chong Zhange05bcb12016-07-26 17:47:29 -0700620 }
Chong Zhangb0d26702016-08-12 16:03:29 -0700621 if (wallpaperMightChange) {
622 requestUpdateWallpaperIfNeeded();
623 }
Chong Zhange05bcb12016-07-26 17:47:29 -0700624 }
625
Robert Carre12aece2016-02-02 22:43:27 -0800626 void destroySurfaces() {
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700627 destroySurfaces(false /*cleanupOnResume*/);
628 }
629
630 /**
631 * Destroy surfaces which have been marked as eligible by the animator, taking care to ensure
632 * the client has finished with them.
633 *
634 * @param cleanupOnResume whether this is done when app is resumed without fully stopped. If
635 * set to true, destroy only surfaces of removed windows, and clear relevant flags of the
636 * others so that they are ready to be reused. If set to false (common case), destroy all
637 * surfaces that's eligible, if the app is already stopped.
638 */
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700639 private void destroySurfaces(boolean cleanupOnResume) {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700640 boolean destroyedSomething = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700641 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700642 final WindowState win = mChildren.get(i);
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700643 destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
Robert Carre12aece2016-02-02 22:43:27 -0800644 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700645 if (destroyedSomething) {
646 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec69694a2016-10-18 13:51:15 -0700647 dc.assignWindowLayers(true /*setLayoutNeeded*/);
Robert Carre12aece2016-02-02 22:43:27 -0800648 }
649 }
650
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800651 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700652 * Notify that the app is now resumed, and it was not stopped before, perform a clean
653 * up of the surfaces
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800654 */
Jorim Jaggibae01b12017-04-11 16:29:10 -0700655 void notifyAppResumed(boolean wasStopped) {
Chong Zhangad24f962016-08-25 12:12:33 -0700656 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppResumed: wasStopped=" + wasStopped
Jorim Jaggibae01b12017-04-11 16:29:10 -0700657 + " " + this);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700658 mAppStopped = false;
chaviwd3bf08d2017-08-01 17:24:59 -0700659 // Allow the window to turn the screen on once the app is resumed again.
660 setCanTurnScreenOn(true);
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700661 if (!wasStopped) {
662 destroySurfaces(true /*cleanupOnResume*/);
Wale Ogunwale8d5a5422016-03-03 18:28:21 -0800663 }
Robert Carre12aece2016-02-02 22:43:27 -0800664 }
665
Chong Zhangbef461f2015-10-27 11:38:24 -0700666 /**
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700667 * Notify that the app has stopped, and it is okay to destroy any surfaces which were
668 * keeping alive in case they were still being used.
669 */
670 void notifyAppStopped() {
671 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "notifyAppStopped: " + this);
672 mAppStopped = true;
673 destroySurfaces();
674 // Remove any starting window that was added for this app if they are still around.
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800675 if (getController() != null) {
676 getController().removeStartingWindow();
677 }
Chong Zhang45e6d2d2016-07-20 18:33:56 -0700678 }
679
Chong Zhang92147042016-05-09 12:47:11 -0700680 void clearAllDrawn() {
681 allDrawn = false;
682 deferClearAllDrawn = false;
Chong Zhangbef461f2015-10-27 11:38:24 -0700683 }
684
Bryce Lee6d410262017-02-28 15:30:17 -0800685 Task getTask() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800686 return (Task) getParent();
Bryce Lee6d410262017-02-28 15:30:17 -0800687 }
688
Jorim Jaggi3878ca32017-02-02 17:13:05 -0800689 TaskStack getStack() {
690 final Task task = getTask();
691 if (task != null) {
692 return task.mStack;
693 } else {
694 return null;
695 }
696 }
697
Bryce Lee6d410262017-02-28 15:30:17 -0800698 @Override
699 void onParentSet() {
700 super.onParentSet();
701
Robert Carred3e83b2017-04-21 13:26:55 -0700702 final Task task = getTask();
703
Bryce Lee6d410262017-02-28 15:30:17 -0800704 // When the associated task is {@code null}, the {@link AppWindowToken} can no longer
705 // access visual elements like the {@link DisplayContent}. We must remove any associations
706 // such as animations.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800707 if (!mReparenting) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800708 if (task == null) {
709 // It is possible we have been marked as a closing app earlier. We must remove ourselves
710 // from this list so we do not participate in any future animations.
711 mService.mClosingApps.remove(this);
Robert Carred3e83b2017-04-21 13:26:55 -0700712 } else if (mLastParent != null && mLastParent.mStack != null) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800713 task.mStack.mExitingAppTokens.remove(this);
714 }
Bryce Lee6d410262017-02-28 15:30:17 -0800715 }
Robert Carred3e83b2017-04-21 13:26:55 -0700716 mLastParent = task;
Bryce Lee6d410262017-02-28 15:30:17 -0800717 }
718
Wale Ogunwalefa854eb2016-09-20 13:43:52 -0700719 void postWindowRemoveStartingWindowCleanup(WindowState win) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700720 // TODO: Something smells about the code below...Is there a better way?
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700721 if (startingWindow == win) {
722 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800723 if (getController() != null) {
724 getController().removeStartingWindow();
725 }
Wale Ogunwale6c459212017-05-17 08:56:03 -0700726 } else if (mChildren.size() == 0) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700727 // If this is the last window and we had requested a starting transition window,
728 // well there is no point now.
Jorim Jaggi02886a82016-12-06 09:10:06 -0800729 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingData");
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700730 startingData = null;
Wale Ogunwale6c459212017-05-17 08:56:03 -0700731 if (mHiddenSetFromTransferredStartingWindow) {
732 // We set the hidden state to false for the token from a transferred starting window.
733 // We now reset it back to true since the starting window was the last window in the
734 // token.
735 hidden = true;
736 }
Jorim Jaggi829b9cd2017-01-23 16:20:53 +0100737 } else if (mChildren.size() == 1 && startingSurface != null && !isRelaunching()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700738 // If this is the last window except for a starting transition window,
739 // we need to get rid of the starting transition.
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200740 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Last window, removing starting window "
741 + win);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -0800742 if (getController() != null) {
743 getController().removeStartingWindow();
744 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700745 }
746 }
747
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700748 void removeDeadWindows() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700749 for (int winNdx = mChildren.size() - 1; winNdx >= 0; --winNdx) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700750 WindowState win = mChildren.get(winNdx);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800751 if (win.mAppDied) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700752 if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700753 "removeDeadWindows: " + win);
Chong Zhang112eb8c2015-11-02 11:17:00 -0800754 // Set mDestroying, we don't want any animation or delayed removal here.
755 win.mDestroying = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700756 // Also removes child windows.
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700757 win.removeIfPossible();
Chong Zhang112eb8c2015-11-02 11:17:00 -0800758 }
759 }
760 }
761
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700762 boolean hasWindowsAlive() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700763 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700764 // No need to loop through child windows as the answer should be the same as that of the
765 // parent window.
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700766 if (!(mChildren.get(i)).mAppDied) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -0700767 return true;
768 }
769 }
770 return false;
771 }
772
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700773 void setWillReplaceWindows(boolean animate) {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700774 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
775 "Marking app token " + this + " with replacing windows.");
Robert Carra1eb4392015-12-10 12:43:51 -0800776
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700777 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700778 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700779 w.setWillReplaceWindow(animate);
Robert Carra1eb4392015-12-10 12:43:51 -0800780 }
781 if (animate) {
782 // Set-up dummy animation so we can start treating windows associated with this
783 // token like they are in transition before the new app window is ready for us to
784 // run the real transition animation.
785 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM,
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700786 "setWillReplaceWindow() Setting dummy animation on: " + this);
Robert Carra1eb4392015-12-10 12:43:51 -0800787 mAppAnimator.setDummyAnimation();
788 }
789 }
790
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700791 void setWillReplaceChildWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700792 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this
Robert Carr23fa16b2016-01-13 13:19:58 -0800793 + " with replacing child windows.");
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700794 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700795 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700796 w.setWillReplaceChildWindows();
Robert Carr23fa16b2016-01-13 13:19:58 -0800797 }
798 }
799
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700800 void clearWillReplaceWindows() {
Wale Ogunwale455fac52016-07-21 07:24:49 -0700801 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
802 "Resetting app token " + this + " of replacing window marks.");
Chong Zhangf596cd52016-01-05 13:42:44 -0800803
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700804 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700805 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700806 w.clearWillReplaceWindow();
Chong Zhangf596cd52016-01-05 13:42:44 -0800807 }
808 }
809
Chong Zhang4d7369a2016-04-25 16:09:14 -0700810 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700811 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700812 final WindowState w = mChildren.get(i);
Chong Zhang4d7369a2016-04-25 16:09:14 -0700813 w.requestUpdateWallpaperIfNeeded();
814 }
815 }
816
Chong Zhangd78ddb42016-03-02 17:01:14 -0800817 boolean isRelaunching() {
818 return mPendingRelaunchCount > 0;
819 }
820
Robert Carr68375192017-06-13 12:41:53 -0700821 boolean shouldFreezeBounds() {
822 final Task task = getTask();
823
824 // For freeform windows, we can't freeze the bounds at the moment because this would make
825 // the resizing unresponsive.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700826 if (task == null || task.inFreeformWindowingMode()) {
Robert Carr68375192017-06-13 12:41:53 -0700827 return false;
828 }
829
830 // We freeze the bounds while drag resizing to deal with the time between
831 // the divider/drag handle being released, and the handling it's new
832 // configuration. If we are relaunched outside of the drag resizing state,
833 // we need to be careful not to do this.
834 return getTask().isDragResizing();
835 }
836
Chong Zhangd78ddb42016-03-02 17:01:14 -0800837 void startRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700838 if (shouldFreezeBounds()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -0800839 freezeBounds();
840 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800841
842 // In the process of tearing down before relaunching, the app will
843 // try and clean up it's child surfaces. We need to prevent this from
844 // happening, so we sever the children, transfering their ownership
845 // from the client it-self to the parent surface (owned by us).
846 for (int i = mChildren.size() - 1; i >= 0; i--) {
847 final WindowState w = mChildren.get(i);
848 w.mWinAnimator.detachChildren();
849 }
850
Chong Zhangd78ddb42016-03-02 17:01:14 -0800851 mPendingRelaunchCount++;
852 }
853
854 void finishRelaunching() {
Robert Carr68375192017-06-13 12:41:53 -0700855 unfreezeBounds();
856
Chong Zhangd78ddb42016-03-02 17:01:14 -0800857 if (mPendingRelaunchCount > 0) {
858 mPendingRelaunchCount--;
Bryce Lee081554b2017-05-25 07:52:12 -0700859 } else {
860 // Update keyguard flags upon finishing relaunch.
861 checkKeyguardFlagsChanged();
Chong Zhangd78ddb42016-03-02 17:01:14 -0800862 }
863 }
864
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700865 void clearRelaunching() {
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700866 if (mPendingRelaunchCount == 0) {
867 return;
868 }
Robert Carr68375192017-06-13 12:41:53 -0700869 unfreezeBounds();
Wale Ogunwale8fd75422016-06-24 14:20:37 -0700870 mPendingRelaunchCount = 0;
871 }
872
Wale Ogunwale07bcab72016-10-14 15:30:09 -0700873 /**
874 * Returns true if the new child window we are adding to this token is considered greater than
875 * the existing child window in this token in terms of z-order.
876 */
877 @Override
878 protected boolean isFirstChildWindowGreaterThanSecond(WindowState newWindow,
879 WindowState existingWindow) {
880 final int type1 = newWindow.mAttrs.type;
881 final int type2 = existingWindow.mAttrs.type;
882
883 // Base application windows should be z-ordered BELOW all other windows in the app token.
884 if (type1 == TYPE_BASE_APPLICATION && type2 != TYPE_BASE_APPLICATION) {
885 return false;
886 } else if (type1 != TYPE_BASE_APPLICATION && type2 == TYPE_BASE_APPLICATION) {
887 return true;
888 }
889
890 // Starting windows should be z-ordered ABOVE all other windows in the app token.
891 if (type1 == TYPE_APPLICATION_STARTING && type2 != TYPE_APPLICATION_STARTING) {
892 return true;
893 } else if (type1 != TYPE_APPLICATION_STARTING && type2 == TYPE_APPLICATION_STARTING) {
894 return false;
895 }
896
897 // Otherwise the new window is greater than the existing window.
898 return true;
899 }
900
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700901 @Override
Robert Carra1eb4392015-12-10 12:43:51 -0800902 void addWindow(WindowState w) {
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700903 super.addWindow(w);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700904
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700905 boolean gotReplacementWindow = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700906 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700907 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700908 gotReplacementWindow |= candidate.setReplacementWindowIfNeeded(w);
909 }
Wale Ogunwale92fc3722016-08-05 12:19:08 -0700910
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700911 // if we got a replacement window, reset the timeout to give drawing more time
912 if (gotReplacementWindow) {
913 mService.scheduleWindowReplacementTimeouts(this);
Robert Carra1eb4392015-12-10 12:43:51 -0800914 }
Jorim Jaggife762342016-10-13 14:33:27 +0200915 checkKeyguardFlagsChanged();
916 }
917
918 @Override
919 void removeChild(WindowState child) {
920 super.removeChild(child);
921 checkKeyguardFlagsChanged();
Robert Carra1eb4392015-12-10 12:43:51 -0800922 }
923
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700924 private boolean waitingForReplacement() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700925 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700926 final WindowState candidate = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700927 if (candidate.waitingForReplacement()) {
Robert Carra1eb4392015-12-10 12:43:51 -0800928 return true;
929 }
930 }
931 return false;
932 }
933
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700934 void onWindowReplacementTimeout() {
Wale Ogunwaled1c37912016-08-16 03:19:39 -0700935 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700936 (mChildren.get(i)).onWindowReplacementTimeout();
Robert Carra1eb4392015-12-10 12:43:51 -0800937 }
938 }
939
Winson Chung30480042017-01-26 10:55:34 -0800940 void reparent(Task task, int position) {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800941 final Task currentTask = getTask();
942 if (task == currentTask) {
Winson Chung30480042017-01-26 10:55:34 -0800943 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800944 "window token=" + this + " already child of task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800945 }
Bryce Lee6d410262017-02-28 15:30:17 -0800946
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800947 if (currentTask.mStack != task.mStack) {
Bryce Lee6d410262017-02-28 15:30:17 -0800948 throw new IllegalArgumentException(
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800949 "window token=" + this + " current task=" + currentTask
Bryce Lee6d410262017-02-28 15:30:17 -0800950 + " belongs to a different stack than " + task);
951 }
952
Winson Chung30480042017-01-26 10:55:34 -0800953 if (DEBUG_ADD_REMOVE) Slog.i(TAG, "reParentWindowToken: removing window token=" + this
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800954 + " from task=" + currentTask);
Winson Chung30480042017-01-26 10:55:34 -0800955 final DisplayContent prevDisplayContent = getDisplayContent();
956
Bryce Lee6d410262017-02-28 15:30:17 -0800957 mReparenting = true;
958
Winson Chung30480042017-01-26 10:55:34 -0800959 getParent().removeChild(this);
960 task.addChild(this, position);
961
Bryce Lee6d410262017-02-28 15:30:17 -0800962 mReparenting = false;
963
Winson Chung30480042017-01-26 10:55:34 -0800964 // Relayout display(s).
965 final DisplayContent displayContent = task.getDisplayContent();
966 displayContent.setLayoutNeeded();
967 if (prevDisplayContent != displayContent) {
968 onDisplayChanged(displayContent);
969 prevDisplayContent.setLayoutNeeded();
970 }
971 }
972
Jorim Jaggi0429f352015-12-22 16:29:16 +0100973 /**
974 * Freezes the task bounds. The size of this task reported the app will be fixed to the bounds
975 * freezed by {@link Task#prepareFreezingBounds} until {@link #unfreezeBounds} gets called, even
976 * if they change in the meantime. If the bounds are already frozen, the bounds will be frozen
977 * with a queue.
978 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800979 private void freezeBounds() {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800980 final Task task = getTask();
981 mFrozenBounds.offer(new Rect(task.mPreparedFrozenBounds));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700982
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800983 if (task.mPreparedFrozenMergedConfig.equals(Configuration.EMPTY)) {
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700984 // We didn't call prepareFreezingBounds on the task, so use the current value.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800985 mFrozenMergedConfig.offer(new Configuration(task.getConfiguration()));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700986 } else {
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800987 mFrozenMergedConfig.offer(new Configuration(task.mPreparedFrozenMergedConfig));
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700988 }
Andrii Kulianb10330d2016-09-16 13:51:46 -0700989 // Calling unset() to make it equal to Configuration.EMPTY.
Bryce Lee7fbeb8a2017-03-02 08:42:30 -0800990 task.mPreparedFrozenMergedConfig.unset();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100991 }
992
993 /**
994 * Unfreezes the previously frozen bounds. See {@link #freezeBounds}.
995 */
Chong Zhangd78ddb42016-03-02 17:01:14 -0800996 private void unfreezeBounds() {
Robert Carr68375192017-06-13 12:41:53 -0700997 if (mFrozenBounds.isEmpty()) {
998 return;
Wale Ogunwale37dbafc2016-06-27 10:15:20 -0700999 }
Robert Carr68375192017-06-13 12:41:53 -07001000 mFrozenBounds.remove();
Wale Ogunwale37dbafc2016-06-27 10:15:20 -07001001 if (!mFrozenMergedConfig.isEmpty()) {
1002 mFrozenMergedConfig.remove();
1003 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001004 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001005 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001006 win.onUnfreezeBounds();
Jorim Jaggi4846ee32016-01-07 17:39:12 +01001007 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001008 mService.mWindowPlacerLocked.performSurfacePlacement();
Jorim Jaggi0429f352015-12-22 16:29:16 +01001009 }
1010
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001011 void setAppLayoutChanges(int changes, String reason) {
1012 if (!mChildren.isEmpty()) {
1013 final DisplayContent dc = getDisplayContent();
1014 dc.pendingLayoutChanges |= changes;
1015 if (DEBUG_LAYOUT_REPEATS) {
1016 mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001017 }
1018 }
1019 }
1020
1021 void removeReplacedWindowIfNeeded(WindowState replacement) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001022 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001023 final WindowState win = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001024 if (win.removeReplacedWindowIfNeeded(replacement)) {
1025 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001026 }
1027 }
1028 }
1029
1030 void startFreezingScreen() {
1031 if (DEBUG_ORIENTATION) logWithStack(TAG, "Set freezing of " + appToken + ": hidden="
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001032 + hidden + " freezing=" + mAppAnimator.freezingScreen + " hiddenRequested="
1033 + hiddenRequested);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001034 if (!hiddenRequested) {
1035 if (!mAppAnimator.freezingScreen) {
1036 mAppAnimator.freezingScreen = true;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001037 mService.registerAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001038 mAppAnimator.lastFreezeDuration = 0;
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001039 mService.mAppsFreezingScreen++;
1040 if (mService.mAppsFreezingScreen == 1) {
Bryce Lee8f853582017-06-05 17:25:59 -07001041 mService.startFreezingDisplayLocked(false, 0, 0, getDisplayContent());
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001042 mService.mH.removeMessages(H.APP_FREEZE_TIMEOUT);
1043 mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001044 }
1045 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001046 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001047 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001048 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001049 w.onStartFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001050 }
1051 }
1052 }
1053
1054 void stopFreezingScreen(boolean unfreezeSurfaceNow, boolean force) {
1055 if (!mAppAnimator.freezingScreen) {
1056 return;
1057 }
1058 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force);
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001059 final int count = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001060 boolean unfrozeWindows = false;
1061 for (int i = 0; i < count; i++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001062 final WindowState w = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001063 unfrozeWindows |= w.onStopFreezingScreen();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001064 }
1065 if (force || unfrozeWindows) {
1066 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "No longer freezing: " + this);
1067 mAppAnimator.freezingScreen = false;
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001068 mService.unregisterAppFreezeListener(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001069 mAppAnimator.lastFreezeDuration =
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001070 (int)(SystemClock.elapsedRealtime() - mService.mDisplayFreezeTime);
1071 mService.mAppsFreezingScreen--;
1072 mService.mLastFinishedFreezeSource = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001073 }
1074 if (unfreezeSurfaceNow) {
1075 if (unfrozeWindows) {
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001076 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001077 }
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001078 mService.stopFreezingDisplayLocked();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001079 }
1080 }
1081
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001082 @Override
1083 public void onAppFreezeTimeout() {
1084 Slog.w(TAG_WM, "Force clearing freeze: " + this);
1085 stopFreezingScreen(true, true);
1086 }
1087
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001088 boolean transferStartingWindow(IBinder transferFrom) {
Wale Ogunwale02319a62016-09-26 15:21:22 -07001089 final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001090 if (fromToken == null) {
1091 return false;
1092 }
1093
1094 final WindowState tStartingWindow = fromToken.startingWindow;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001095 if (tStartingWindow != null && fromToken.startingSurface != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001096 // In this case, the starting icon has already been displayed, so start
1097 // letting windows get shown immediately without any more transitions.
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001098 mService.mSkipAppTransitionAnimation = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001099
1100 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Moving existing starting " + tStartingWindow
1101 + " from " + fromToken + " to " + this);
1102
1103 final long origId = Binder.clearCallingIdentity();
1104
1105 // Transfer the starting window over to the new token.
1106 startingData = fromToken.startingData;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001107 startingSurface = fromToken.startingSurface;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001108 startingDisplayed = fromToken.startingDisplayed;
1109 fromToken.startingDisplayed = false;
1110 startingWindow = tStartingWindow;
1111 reportedVisible = fromToken.reportedVisible;
1112 fromToken.startingData = null;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001113 fromToken.startingSurface = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001114 fromToken.startingWindow = null;
1115 fromToken.startingMoved = true;
1116 tStartingWindow.mToken = this;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001117 tStartingWindow.mAppToken = this;
1118
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001119 if (DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001120 "Removing starting " + tStartingWindow + " from " + fromToken);
Wale Ogunwalefa854eb2016-09-20 13:43:52 -07001121 fromToken.removeChild(tStartingWindow);
1122 fromToken.postWindowRemoveStartingWindowCleanup(tStartingWindow);
Wale Ogunwale6c459212017-05-17 08:56:03 -07001123 fromToken.mHiddenSetFromTransferredStartingWindow = false;
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001124 addWindow(tStartingWindow);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001125
1126 // Propagate other interesting state between the tokens. If the old token is displayed,
1127 // we should immediately force the new one to be displayed. If it is animating, we need
1128 // to move that animation to the new one.
1129 if (fromToken.allDrawn) {
1130 allDrawn = true;
1131 deferClearAllDrawn = fromToken.deferClearAllDrawn;
1132 }
1133 if (fromToken.firstWindowDrawn) {
1134 firstWindowDrawn = true;
1135 }
1136 if (!fromToken.hidden) {
1137 hidden = false;
1138 hiddenRequested = false;
Wale Ogunwale6c459212017-05-17 08:56:03 -07001139 mHiddenSetFromTransferredStartingWindow = true;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001140 }
Wale Ogunwale89973222017-04-23 18:39:45 -07001141 setClientHidden(fromToken.mClientHidden);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001142 fromToken.mAppAnimator.transferCurrentAnimation(
1143 mAppAnimator, tStartingWindow.mWinAnimator);
1144
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001145 mService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001146 UPDATE_FOCUS_WILL_PLACE_SURFACES, true /*updateInputWindows*/);
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001147 getDisplayContent().setLayoutNeeded();
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001148 mService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001149 Binder.restoreCallingIdentity(origId);
1150 return true;
1151 } else if (fromToken.startingData != null) {
1152 // The previous app was getting ready to show a
1153 // starting window, but hasn't yet done so. Steal it!
1154 if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
1155 "Moving pending starting from " + fromToken + " to " + this);
1156 startingData = fromToken.startingData;
1157 fromToken.startingData = null;
1158 fromToken.startingMoved = true;
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001159 if (getController() != null) {
1160 getController().scheduleAddStartingWindow();
1161 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001162 return true;
1163 }
1164
1165 final AppWindowAnimator tAppAnimator = fromToken.mAppAnimator;
1166 final AppWindowAnimator wAppAnimator = mAppAnimator;
1167 if (tAppAnimator.thumbnail != null) {
1168 // The old token is animating with a thumbnail, transfer that to the new token.
1169 if (wAppAnimator.thumbnail != null) {
1170 wAppAnimator.thumbnail.destroy();
1171 }
1172 wAppAnimator.thumbnail = tAppAnimator.thumbnail;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001173 wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
1174 tAppAnimator.thumbnail = null;
1175 }
1176 return false;
1177 }
1178
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001179 boolean isLastWindow(WindowState win) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001180 return mChildren.size() == 1 && mChildren.get(0) == win;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001181 }
1182
1183 void setAllAppWinAnimators() {
1184 final ArrayList<WindowStateAnimator> allAppWinAnimators = mAppAnimator.mAllAppWinAnimators;
1185 allAppWinAnimators.clear();
1186
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001187 final int windowsCount = mChildren.size();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001188 for (int j = 0; j < windowsCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001189 (mChildren.get(j)).addWinAnimatorToList(allAppWinAnimators);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001190 }
1191 }
1192
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001193 @Override
1194 void onAppTransitionDone() {
1195 sendingToBottom = false;
1196 }
1197
Wale Ogunwale51362492016-09-08 17:49:17 -07001198 /**
1199 * We override because this class doesn't want its children affecting its reported orientation
1200 * in anyway.
1201 */
1202 @Override
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001203 int getOrientation(int candidate) {
Bryce Lee0e7b7c92017-08-10 14:59:00 -07001204 // We do not allow non-fullscreen apps to influence orientation starting in O-MR1. While we
1205 // do throw an exception in {@link Activity#onCreate} and
Bryce Lee39791592017-04-26 09:29:12 -07001206 // {@link Activity#setRequestedOrientation}, we also ignore the orientation here so that
1207 // other calculations aren't affected.
Bryce Lee0e7b7c92017-08-10 14:59:00 -07001208 if (!fillsParent() && mTargetSdk >= O_MR1) {
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001209 // Can't specify orientation if app doesn't fill parent.
1210 return SCREEN_ORIENTATION_UNSET;
1211 }
1212
1213 if (candidate == SCREEN_ORIENTATION_BEHIND) {
1214 // Allow app to specify orientation regardless of its visibility state if the current
1215 // candidate want us to use orientation behind. I.e. the visible app on-top of this one
1216 // wants us to use the orientation of the app behind it.
1217 return mOrientation;
1218 }
1219
Bryce Lee61fbcbc2017-03-10 14:14:03 -08001220 // The {@link AppWindowToken} should only specify an orientation when it is not closing or
1221 // going to the bottom. Allowing closing {@link AppWindowToken} to participate can lead to
1222 // an Activity in another task being started in the wrong orientation during the transition.
Wale Ogunwale5e5a68d2017-03-24 17:36:38 -07001223 if (!(sendingToBottom || mService.mClosingApps.contains(this))
Bryce Lee00d586d2017-07-28 20:48:43 -07001224 && (isVisible() || mService.mOpeningApps.contains(this) || isOnTop())) {
Bryce Leea163b762017-01-24 11:05:01 -08001225 return mOrientation;
Wale Ogunwale51362492016-09-08 17:49:17 -07001226 }
Bryce Leea163b762017-01-24 11:05:01 -08001227
1228 return SCREEN_ORIENTATION_UNSET;
Wale Ogunwale51362492016-09-08 17:49:17 -07001229 }
1230
Wale Ogunwaleb198b742016-12-01 08:44:09 -08001231 /** Returns the app's preferred orientation regardless of its currently visibility state. */
1232 int getOrientationIgnoreVisibility() {
1233 return mOrientation;
1234 }
1235
Craig Mautnerdbb79912012-03-01 18:59:14 -08001236 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001237 void checkAppWindowsReadyToShow() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001238 if (allDrawn == mAppAnimator.allDrawn) {
1239 return;
1240 }
1241
1242 mAppAnimator.allDrawn = allDrawn;
1243 if (!allDrawn) {
1244 return;
1245 }
1246
1247 // The token has now changed state to having all windows shown... what to do, what to do?
1248 if (mAppAnimator.freezingScreen) {
1249 mAppAnimator.showAllWindowsLocked();
1250 stopFreezingScreen(false, true);
1251 if (DEBUG_ORIENTATION) Slog.i(TAG,
1252 "Setting mOrientationChangeComplete=true because wtoken " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001253 + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001254 // This will set mOrientationChangeComplete and cause a pass through layout.
1255 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001256 "checkAppWindowsReadyToShow: freezingScreen");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001257 } else {
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001258 setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001259
1260 // We can now show all of the drawn windows!
1261 if (!mService.mOpeningApps.contains(this)) {
1262 mService.mAnimator.orAnimating(mAppAnimator.showAllWindowsLocked());
1263 }
1264 }
1265 }
1266
Matthew Ng5d23afa2017-06-21 16:16:24 -07001267 /**
Bryce Leed390deb2017-06-22 13:14:28 -07001268 * Returns whether the drawn window states of this {@link AppWindowToken} has considered every
1269 * child {@link WindowState}. A child is considered if it has been passed into
1270 * {@link #updateDrawnWindowStates(WindowState)} after being added. This is used to determine
1271 * whether states, such as {@code allDrawn}, can be set, which relies on state variables such as
1272 * {@code mNumInterestingWindows}, which depend on all {@link WindowState}s being considered.
1273 *
1274 * @return {@code true} If all children have been considered, {@code false}.
1275 */
1276 private boolean allDrawnStatesConsidered() {
Bryce Lee6311c4b2017-07-06 14:09:29 -07001277 for (int i = mChildren.size() - 1; i >= 0; --i) {
1278 final WindowState child = mChildren.get(i);
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001279 if (child.mightAffectAllDrawn() && !child.getDrawnStateEvaluated()) {
Bryce Leed390deb2017-06-22 13:14:28 -07001280 return false;
1281 }
1282 }
1283 return true;
1284 }
1285
1286 /**
Matthew Ng5d23afa2017-06-21 16:16:24 -07001287 * Determines if the token has finished drawing. This should only be called from
1288 * {@link DisplayContent#applySurfaceChangesTransaction}
1289 */
Matthew Ng498c71d2017-04-18 13:55:45 -07001290 void updateAllDrawn() {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001291 if (!allDrawn) {
Matthew Ng498c71d2017-04-18 13:55:45 -07001292 // Number of drawn windows can be less when a window is being relaunched, wait for
Bryce Leed390deb2017-06-22 13:14:28 -07001293 // all windows to be launched and drawn for this token be considered all drawn.
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001294 final int numInteresting = mNumInterestingWindows;
Bryce Leed390deb2017-06-22 13:14:28 -07001295
1296 // We must make sure that all present children have been considered (determined by
1297 // {@link #allDrawnStatesConsidered}) before evaluating whether everything has been
1298 // drawn.
1299 if (numInteresting > 0 && allDrawnStatesConsidered()
1300 && mNumDrawnWindows >= numInteresting && !isRelaunching()) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001301 if (DEBUG_VISIBILITY) Slog.v(TAG, "allDrawn: " + this
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001302 + " interesting=" + numInteresting + " drawn=" + mNumDrawnWindows);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001303 allDrawn = true;
1304 // Force an additional layout pass where
1305 // WindowStateAnimator#commitFinishDrawingLocked() will call performShowLocked().
Matthew Ng498c71d2017-04-18 13:55:45 -07001306 if (mDisplayContent != null) {
1307 mDisplayContent.setLayoutNeeded();
1308 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001309 mService.mH.obtainMessage(NOTIFY_ACTIVITY_DRAWN, token).sendToTarget();
Robert Carrecc06b32017-04-18 14:25:10 -07001310
Winson Chunge7ba6862017-05-24 12:13:33 -07001311 // Notify the pinned stack upon all windows drawn. If there was an animation in
1312 // progress then this signal will resume that animation.
Wale Ogunwaleb62139d2017-09-20 15:37:35 -07001313 final TaskStack pinnedStack =
1314 mDisplayContent.getStack(WINDOWING_MODE_PINNED);
Winson Chunge7ba6862017-05-24 12:13:33 -07001315 if (pinnedStack != null) {
1316 pinnedStack.onAllWindowsDrawn();
Robert Carrecc06b32017-04-18 14:25:10 -07001317 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001318 }
1319 }
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001320 }
1321
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001322 /**
1323 * Updated this app token tracking states for interesting and drawn windows based on the window.
1324 *
1325 * @return Returns true if the input window is considered interesting and drawn while all the
1326 * windows in this app token where not considered drawn as of the last pass.
1327 */
1328 boolean updateDrawnWindowStates(WindowState w) {
Bryce Leed390deb2017-06-22 13:14:28 -07001329 w.setDrawnStateEvaluated(true /*evaluated*/);
1330
Jorim Jaggie4b0f282017-05-17 15:10:29 +02001331 if (DEBUG_STARTING_WINDOW_VERBOSE && w == startingWindow) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001332 Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen=" + w.isOnScreen()
1333 + " allDrawn=" + allDrawn + " freezingScreen=" + mAppAnimator.freezingScreen);
1334 }
1335
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001336 if (allDrawn && !mAppAnimator.freezingScreen) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001337 return false;
1338 }
1339
1340 if (mLastTransactionSequence != mService.mTransactionSequence) {
1341 mLastTransactionSequence = mService.mTransactionSequence;
1342 mNumInterestingWindows = mNumDrawnWindows = 0;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001343 startingDisplayed = false;
1344 }
1345
1346 final WindowStateAnimator winAnimator = w.mWinAnimator;
1347
1348 boolean isInterestingAndDrawn = false;
1349
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001350 if (!allDrawn && w.mightAffectAllDrawn()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001351 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
1352 Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
1353 + ", isAnimationSet=" + winAnimator.isAnimationSet());
1354 if (!w.isDrawnLw()) {
1355 Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
1356 + " pv=" + w.mPolicyVisibility
1357 + " mDrawState=" + winAnimator.drawStateToString()
1358 + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
1359 + " a=" + winAnimator.mAnimating);
1360 }
1361 }
1362
1363 if (w != startingWindow) {
1364 if (w.isInteresting()) {
1365 mNumInterestingWindows++;
1366 if (w.isDrawnLw()) {
1367 mNumDrawnWindows++;
1368
1369 if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, "tokenMayBeDrawn: "
1370 + this + " w=" + w + " numInteresting=" + mNumInterestingWindows
1371 + " freezingScreen=" + mAppAnimator.freezingScreen
1372 + " mAppFreezing=" + w.mAppFreezing);
1373
1374 isInterestingAndDrawn = true;
1375 }
1376 }
1377 } else if (w.isDrawnLw()) {
Jorim Jaggi3878ca32017-02-02 17:13:05 -08001378 if (getController() != null) {
1379 getController().reportStartingWindowDrawn();
1380 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001381 startingDisplayed = true;
1382 }
1383 }
1384
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001385 return isInterestingAndDrawn;
1386 }
1387
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001388 @Override
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001389 void stepAppWindowsAnimation(long currentTime) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001390 mAppAnimator.wasAnimating = mAppAnimator.animating;
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07001391 if (mAppAnimator.stepAnimationLocked(currentTime)) {
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001392 mAppAnimator.animating = true;
1393 mService.mAnimator.setAnimating(true);
1394 mService.mAnimator.mAppWindowAnimating = true;
1395 } else if (mAppAnimator.wasAnimating) {
1396 // stopped animating, do one more pass through the layout
Wale Ogunwale1e129a42016-11-21 13:03:47 -08001397 setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
1398 DEBUG_LAYOUT_REPEATS ? "appToken " + this + " done" : null);
Wale Ogunwale3f4433d2016-08-18 20:42:42 -07001399 if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
1400 }
1401 }
1402
Wale Ogunwale9adfe572016-09-08 20:43:58 -07001403 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001404 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001405 // For legacy reasons we process the TaskStack.mExitingAppTokens first in DisplayContent
1406 // before the non-exiting app tokens. So, we skip the exiting app tokens here.
1407 // TODO: Investigate if we need to continue to do this or if we can just process them
1408 // in-order.
1409 if (mIsExiting && !waitingForReplacement()) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001410 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001411 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001412 return forAllWindowsUnchecked(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001413 }
1414
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08001415 boolean forAllWindowsUnchecked(ToBooleanFunction<WindowState> callback,
1416 boolean traverseTopToBottom) {
1417 return super.forAllWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07001418 }
1419
1420 @Override
Wale Ogunwale2049dbf2016-08-02 21:05:23 -07001421 AppWindowToken asAppWindowToken() {
1422 // I am an app window token!
1423 return this;
1424 }
1425
1426 @Override
Wale Ogunwale51362492016-09-08 17:49:17 -07001427 boolean fillsParent() {
1428 return mFillsParent;
1429 }
1430
1431 void setFillsParent(boolean fillsParent) {
1432 mFillsParent = fillsParent;
1433 }
1434
Jorim Jaggife762342016-10-13 14:33:27 +02001435 boolean containsDismissKeyguardWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001436 // Window state is transient during relaunch. We are not guaranteed to be frozen during the
1437 // entirety of the relaunch.
1438 if (isRelaunching()) {
1439 return mLastContainsDismissKeyguardWindow;
1440 }
1441
Jorim Jaggife762342016-10-13 14:33:27 +02001442 for (int i = mChildren.size() - 1; i >= 0; i--) {
1443 if ((mChildren.get(i).mAttrs.flags & FLAG_DISMISS_KEYGUARD) != 0) {
1444 return true;
1445 }
1446 }
1447 return false;
1448 }
1449
1450 boolean containsShowWhenLockedWindow() {
Bryce Lee081554b2017-05-25 07:52:12 -07001451 // When we are relaunching, it is possible for us to be unfrozen before our previous
1452 // windows have been added back. Using the cached value ensures that our previous
1453 // showWhenLocked preference is honored until relaunching is complete.
1454 if (isRelaunching()) {
1455 return mLastContainsShowWhenLockedWindow;
1456 }
1457
Jorim Jaggife762342016-10-13 14:33:27 +02001458 for (int i = mChildren.size() - 1; i >= 0; i--) {
1459 if ((mChildren.get(i).mAttrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
1460 return true;
1461 }
1462 }
Bryce Lee081554b2017-05-25 07:52:12 -07001463
Jorim Jaggife762342016-10-13 14:33:27 +02001464 return false;
1465 }
1466
1467 void checkKeyguardFlagsChanged() {
1468 final boolean containsDismissKeyguard = containsDismissKeyguardWindow();
1469 final boolean containsShowWhenLocked = containsShowWhenLockedWindow();
1470 if (containsDismissKeyguard != mLastContainsDismissKeyguardWindow
1471 || containsShowWhenLocked != mLastContainsShowWhenLockedWindow) {
1472 mService.notifyKeyguardFlagsChanged(null /* callback */);
1473 }
1474 mLastContainsDismissKeyguardWindow = containsDismissKeyguard;
1475 mLastContainsShowWhenLockedWindow = containsShowWhenLocked;
1476 }
1477
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001478 WindowState getImeTargetBelowWindow(WindowState w) {
1479 final int index = mChildren.indexOf(w);
1480 if (index > 0) {
1481 final WindowState target = mChildren.get(index - 1);
1482 if (target.canBeImeTarget()) {
1483 return target;
1484 }
1485 }
1486 return null;
1487 }
1488
Winson Chungbe9be7f2017-06-28 10:55:22 -07001489 int getLowestAnimLayer() {
1490 for (int i = 0; i < mChildren.size(); i++) {
1491 final WindowState w = mChildren.get(i);
1492 if (w.mRemoved) {
1493 continue;
1494 }
1495 return w.mWinAnimator.mAnimLayer;
1496 }
1497 return Integer.MAX_VALUE;
1498 }
1499
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001500 WindowState getHighestAnimLayerWindow(WindowState currentTarget) {
1501 WindowState candidate = null;
1502 for (int i = mChildren.indexOf(currentTarget); i >= 0; i--) {
1503 final WindowState w = mChildren.get(i);
1504 if (w.mRemoved) {
1505 continue;
1506 }
1507 if (candidate == null || w.mWinAnimator.mAnimLayer >
1508 candidate.mWinAnimator.mAnimLayer) {
1509 candidate = w;
1510 }
1511 }
1512 return candidate;
1513 }
1514
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001515 /**
1516 * See {@link Activity#setDisablePreviewScreenshots}.
1517 */
1518 void setDisablePreviewScreenshots(boolean disable) {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001519 mDisablePreviewScreenshots = disable;
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001520 }
1521
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001522 /**
chaviwd3bf08d2017-08-01 17:24:59 -07001523 * Sets whether the current launch can turn the screen on. See {@link #canTurnScreenOn()}
1524 */
1525 void setCanTurnScreenOn(boolean canTurnScreenOn) {
1526 mCanTurnScreenOn = canTurnScreenOn;
1527 }
1528
1529 /**
1530 * Indicates whether the current launch can turn the screen on. This is to prevent multiple
1531 * relayouts from turning the screen back on. The screen should only turn on at most
1532 * once per activity resume.
1533 *
1534 * @return true if the screen can be turned on.
1535 */
1536 boolean canTurnScreenOn() {
1537 return mCanTurnScreenOn;
1538 }
1539
1540 /**
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001541 * Retrieves whether we'd like to generate a snapshot that's based solely on the theme. This is
1542 * the case when preview screenshots are disabled {@link #setDisablePreviewScreenshots} or when
1543 * we can't take a snapshot for other reasons, for example, if we have a secure window.
1544 *
1545 * @return True if we need to generate an app theme snapshot, false if we'd like to take a real
1546 * screenshot.
1547 */
1548 boolean shouldUseAppThemeSnapshot() {
Wale Ogunwale6c459212017-05-17 08:56:03 -07001549 return mDisablePreviewScreenshots || forAllWindows(w -> (w.mAttrs.flags & FLAG_SECURE) != 0,
Jorim Jaggid635a4a2017-05-03 15:21:26 +02001550 true /* topToBottom */);
Jorim Jaggi0fe7ce962017-02-22 16:45:48 +01001551 }
1552
Wale Ogunwale51362492016-09-08 17:49:17 -07001553 @Override
Robert Carrdee1b3f2017-02-27 11:33:33 -08001554 int getAnimLayerAdjustment() {
1555 return mAppAnimator.animLayerAdjustment;
1556 }
1557
1558 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001559 void dump(PrintWriter pw, String prefix) {
1560 super.dump(pw, prefix);
1561 if (appToken != null) {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001562 pw.println(prefix + "app=true mVoiceInteraction=" + mVoiceInteraction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001563 }
Bryce Lee7fbeb8a2017-03-02 08:42:30 -08001564 pw.print(prefix); pw.print("task="); pw.println(getTask());
Wale Ogunwale51362492016-09-08 17:49:17 -07001565 pw.print(prefix); pw.print(" mFillsParent="); pw.print(mFillsParent);
1566 pw.print(" mOrientation="); pw.println(mOrientation);
Wale Ogunwale89973222017-04-23 18:39:45 -07001567 pw.println(prefix + "hiddenRequested=" + hiddenRequested + " mClientHidden=" + mClientHidden
1568 + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
1569 + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
Craig Mautner59431632012-04-04 11:56:44 -07001570 if (paused) {
1571 pw.print(prefix); pw.print("paused="); pw.println(paused);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001572 }
Wale Ogunwale9017ec02016-02-25 08:55:25 -08001573 if (mAppStopped) {
1574 pw.print(prefix); pw.print("mAppStopped="); pw.println(mAppStopped);
1575 }
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001576 if (mNumInterestingWindows != 0 || mNumDrawnWindows != 0
Craig Mautner6fbda632012-07-03 09:26:39 -07001577 || allDrawn || mAppAnimator.allDrawn) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001578 pw.print(prefix); pw.print("mNumInterestingWindows=");
1579 pw.print(mNumInterestingWindows);
1580 pw.print(" mNumDrawnWindows="); pw.print(mNumDrawnWindows);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001581 pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
Craig Mautner6fbda632012-07-03 09:26:39 -07001582 pw.print(" allDrawn="); pw.print(allDrawn);
1583 pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
1584 pw.println(")");
1585 }
1586 if (inPendingTransaction) {
1587 pw.print(prefix); pw.print("inPendingTransaction=");
1588 pw.println(inPendingTransaction);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001589 }
Craig Mautner799bc1d2015-01-14 10:33:48 -08001590 if (startingData != null || removed || firstWindowDrawn || mIsExiting) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001591 pw.print(prefix); pw.print("startingData="); pw.print(startingData);
1592 pw.print(" removed="); pw.print(removed);
Craig Mautner3d7ca312015-01-08 10:56:00 -08001593 pw.print(" firstWindowDrawn="); pw.print(firstWindowDrawn);
Craig Mautner799bc1d2015-01-14 10:33:48 -08001594 pw.print(" mIsExiting="); pw.println(mIsExiting);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001595 }
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001596 if (startingWindow != null || startingSurface != null
Wale Ogunwale6c459212017-05-17 08:56:03 -07001597 || startingDisplayed || startingMoved || mHiddenSetFromTransferredStartingWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001598 pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
Jorim Jaggiba41f4b2016-12-14 17:43:07 -08001599 pw.print(" startingSurface="); pw.print(startingSurface);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001600 pw.print(" startingDisplayed="); pw.print(startingDisplayed);
Wale Ogunwale6c459212017-05-17 08:56:03 -07001601 pw.print(" startingMoved="); pw.print(startingMoved);
1602 pw.println(" mHiddenSetFromTransferredStartingWindow="
1603 + mHiddenSetFromTransferredStartingWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001604 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01001605 if (!mFrozenBounds.isEmpty()) {
Chong Zhangd78ddb42016-03-02 17:01:14 -08001606 pw.print(prefix); pw.print("mFrozenBounds="); pw.println(mFrozenBounds);
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001607 pw.print(prefix); pw.print("mFrozenMergedConfig="); pw.println(mFrozenMergedConfig);
Chong Zhangd78ddb42016-03-02 17:01:14 -08001608 }
1609 if (mPendingRelaunchCount != 0) {
1610 pw.print(prefix); pw.print("mPendingRelaunchCount="); pw.println(mPendingRelaunchCount);
Jorim Jaggi0429f352015-12-22 16:29:16 +01001611 }
Wale Ogunwale9c64cb62017-04-12 13:39:59 -07001612 if (getController() != null) {
1613 pw.print(prefix); pw.print("controller="); pw.println(getController());
1614 }
Wale Ogunwalee287e192017-04-21 09:30:12 -07001615 if (mRemovingFromDisplay) {
1616 pw.println(prefix + "mRemovingFromDisplay=" + mRemovingFromDisplay);
1617 }
Jorim Jaggi4d1835d2017-08-31 17:28:27 +02001618 if (mAppAnimator.isAnimating()) {
1619 mAppAnimator.dump(pw, prefix + " ");
1620 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001621 }
1622
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001623 @CallSuper
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001624 @Override
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07001625 public void writeToProto(ProtoOutputStream proto, long fieldId) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07001626 final long token = proto.start(fieldId);
1627 writeNameToProto(proto, NAME);
1628 super.writeToProto(proto, WINDOW_TOKEN);
1629 proto.end(token);
1630 }
1631
1632 void writeNameToProto(ProtoOutputStream proto, long fieldId) {
1633 if (appToken == null) {
1634 return;
1635 }
1636 try {
1637 proto.write(fieldId, appToken.getName());
1638 } catch (RemoteException e) {
1639 // This shouldn't happen, but in this case fall back to outputting nothing
1640 Slog.e(TAG, e.toString());
1641 }
1642 }
1643
1644 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001645 public String toString() {
1646 if (stringName == null) {
1647 StringBuilder sb = new StringBuilder();
1648 sb.append("AppWindowToken{");
1649 sb.append(Integer.toHexString(System.identityHashCode(this)));
1650 sb.append(" token="); sb.append(token); sb.append('}');
1651 stringName = sb.toString();
1652 }
Wale Ogunwaleba51ca22016-09-23 06:06:54 -07001653 return stringName + ((mIsExiting) ? " mIsExiting=" : "");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001654 }
Jeff Browne9bdb312012-04-05 15:30:10 -07001655}