blob: 96582fc100586c251eb7ce2ed60c0b2cdc7f4b83 [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
Jorim Jaggi02886a82016-12-06 09:10:06 -080019import static android.app.ActivityManager.ENABLE_TASK_SNAPSHOTS;
20import static android.app.ActivityManager.StackId;
Winson Chungd73e94b2017-05-31 16:25:30 -070021import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
Jorim Jaggi02886a82016-12-06 09:10:06 -080022import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
Winson Chungd73e94b2017-05-31 16:25:30 -070023import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Jorim Jaggi02886a82016-12-06 09:10:06 -080024import static android.app.ActivityManager.isLowRamDeviceStatic;
25import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
26import static android.view.Display.DEFAULT_DISPLAY;
27import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
28import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
29import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
30import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
31import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
32import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW;
33import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
34import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
35import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
36import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
37import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
38import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
39import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
40import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
41import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
42import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
43import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
44import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Robert Carrc91d1c32017-02-15 19:37:46 -080045import static android.view.WindowManager.LayoutParams.FORMAT_CHANGED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080046import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
47import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
48import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
49import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
50import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
51import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
52import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
53import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
54import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Robert Carraf422a82017-04-10 18:34:33 -070055import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080056import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
57import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
58import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
59import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
60import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
61import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
62import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Robert Carrc91d1c32017-02-15 19:37:46 -080063import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED;
64import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM;
65import static android.view.WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME;
66import static android.view.WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080067import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
68import static android.view.WindowManagerPolicy.TRANSIT_ENTER;
69import static android.view.WindowManagerPolicy.TRANSIT_EXIT;
70import static android.view.WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
71import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
72import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
73import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
74import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
75import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
76import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
77import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
78import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
79import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Jorim Jaggi02886a82016-12-06 09:10:06 -080080import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
81import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
82import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
83import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
84import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020085import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Jorim Jaggi02886a82016-12-06 09:10:06 -080086import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SURFACE_TRACE;
87import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080088import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
89import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
90import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
91import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
92import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
93import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
94import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
95import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
96import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
97import static com.android.server.wm.WindowManagerService.localLOGV;
98import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING;
99import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
100import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN;
101import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
102
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800103import android.app.AppOpsManager;
104import android.content.Context;
105import android.content.res.Configuration;
106import android.graphics.Matrix;
107import android.graphics.PixelFormat;
108import android.graphics.Point;
109import android.graphics.Rect;
110import android.graphics.Region;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700111import android.os.Binder;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700112import android.os.Debug;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800113import android.os.IBinder;
114import android.os.PowerManager;
115import android.os.RemoteCallbackList;
116import android.os.RemoteException;
117import android.os.SystemClock;
118import android.os.Trace;
119import android.os.UserHandle;
120import android.os.WorkSource;
Andrii Kulian44607962017-03-16 11:06:24 -0700121import android.util.MergedConfiguration;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800122import android.util.DisplayMetrics;
123import android.util.Slog;
124import android.util.TimeUtils;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800125import android.view.DisplayInfo;
126import android.view.Gravity;
127import android.view.IApplicationToken;
128import android.view.IWindow;
129import android.view.IWindowFocusObserver;
130import android.view.IWindowId;
131import android.view.InputChannel;
132import android.view.InputEvent;
133import android.view.InputEventReceiver;
134import android.view.View;
135import android.view.ViewTreeObserver;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700136import android.view.WindowInfo;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800137import android.view.WindowManager;
138import android.view.WindowManagerPolicy;
139
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800140import com.android.internal.util.ToBooleanFunction;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800141import com.android.server.input.InputWindowHandle;
142
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800143import java.io.PrintWriter;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200144import java.lang.ref.WeakReference;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800145import java.util.ArrayList;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700146import java.util.Comparator;
147import java.util.LinkedList;
Wale Ogunwaled1880962016-11-08 10:31:59 -0800148import java.util.function.Predicate;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800149
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700150/** A window in the window manager. */
151class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800152 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800153
Skuhne81c524a2015-08-12 13:34:14 -0700154 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700155 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
156 // use hard-coded min sizes for now.
157 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
158 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700159
160 // The thickness of a window resize handle outside the window bounds on the free form workspace
161 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700162 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700163
Jorim Jaggi02886a82016-12-06 09:10:06 -0800164 private static final boolean DEBUG_DISABLE_SAVING_SURFACES = false ||
165 ENABLE_TASK_SNAPSHOTS;
Robert Carr7098dbd2016-02-01 12:31:01 -0800166
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800167 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700168 final WindowManagerPolicy mPolicy;
169 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800170 final Session mSession;
171 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800172 final int mAppOp;
173 // UserId and appId of the owner. Don't display windows of non-current user.
174 final int mOwnerUid;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800175 /** The owner has {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} */
176 final boolean mOwnerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200177 final WindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800178 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700179 // The same object as mToken if this is an app window and null for non-app windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800180 AppWindowToken mAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700181
182 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
183 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800184 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
185 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700186 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800187 final int mBaseLayer;
188 final int mSubLayer;
189 final boolean mLayoutAttached;
190 final boolean mIsImWindow;
191 final boolean mIsWallpaper;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700192 private final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700193 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700194 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800195 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700196 int mSystemUiVisibility;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700197 /**
198 * The visibility of the window based on policy like {@link WindowManagerPolicy}.
199 * Normally set by calling {@link #showLw} and {@link #hideLw}.
200 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800201 boolean mPolicyVisibility = true;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700202 /**
203 * What {@link #mPolicyVisibility} should be set to after a transition animation.
204 * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and
205 * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit
206 * animation is done.
207 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800208 boolean mPolicyVisibilityAfterAnim = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700209 private boolean mAppOpVisibility = true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700210 boolean mPermanentlyHidden; // the window should never be shown again
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800211 boolean mAppFreezing;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700212 boolean mHidden; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800213 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700214 private boolean mDragResizing;
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200215 private boolean mDragResizingChangeReported = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700216 private int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700217
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700218 private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800219
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700220 /**
221 * The window size that was requested by the application. These are in
222 * the application's coordinate space (without compatibility scale applied).
223 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800224 int mRequestedWidth;
225 int mRequestedHeight;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700226 private int mLastRequestedWidth;
227 private int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700228
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800229 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800230 boolean mHaveFrame;
231 boolean mObscured;
232 boolean mTurnOnScreen;
233
234 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700235
Andrii Kulian9d91ca62016-09-29 22:28:09 -0700236 /**
237 * Used to store last reported to client configuration and check if we have newer available.
238 * We'll send configuration to client only if it is different from the last applied one and
239 * client won't perform unnecessary updates.
240 */
241 private final Configuration mLastReportedConfiguration = new Configuration();
Craig Mautnera2c77052012-03-26 12:14:43 -0700242
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700243 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700244 * Actual position of the surface shown on-screen (may be modified by animation). These are
245 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700246 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700247 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800248
249 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700250 * Insets that determine the actually visible area. These are in the application's
251 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800252 */
253 final Rect mVisibleInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700254 private final Rect mLastVisibleInsets = new Rect();
255 private boolean mVisibleInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800256
257 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700258 * Insets that are covered by system windows (such as the status bar) and
259 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700260 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800261 */
262 final Rect mContentInsets = new Rect();
263 final Rect mLastContentInsets = new Rect();
Robert Carr18f622f2017-05-08 11:20:43 -0700264
265 /**
266 * The last content insets returned to the client in relayout. We use
267 * these in the bounds animation to ensure we only observe inset changes
268 * at the same time that a client resizes it's surface so that we may use
269 * the geometryAppliesWithResize synchronization mechanism to keep
270 * the contents in place.
271 */
272 final Rect mLastRelayoutContentInsets = new Rect();
273
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700274 private boolean mContentInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800275
276 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800277 * Insets that determine the area covered by the display overscan region. These are in the
278 * application's coordinate space (without compatibility scale applied).
279 */
280 final Rect mOverscanInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700281 private final Rect mLastOverscanInsets = new Rect();
282 private boolean mOverscanInsetsChanged;
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800283
284 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700285 * Insets that determine the area covered by the stable system windows. These are in the
286 * application's coordinate space (without compatibility scale applied).
287 */
288 final Rect mStableInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700289 private final Rect mLastStableInsets = new Rect();
290 private boolean mStableInsetsChanged;
Adrian Roosfa104232014-06-20 16:10:14 -0700291
292 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700293 * Outsets determine the area outside of the surface where we want to pretend that it's possible
294 * to draw anyway.
295 */
296 final Rect mOutsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700297 private final Rect mLastOutsets = new Rect();
298 private boolean mOutsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700299
300 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800301 * Set to true if we are waiting for this window to receive its
302 * given internal insets before laying out other windows based on it.
303 */
304 boolean mGivenInsetsPending;
305
306 /**
307 * These are the content insets that were given during layout for
308 * this window, to be applied to windows behind it.
309 */
310 final Rect mGivenContentInsets = new Rect();
311
312 /**
313 * These are the visible insets that were given during layout for
314 * this window, to be applied to windows behind it.
315 */
316 final Rect mGivenVisibleInsets = new Rect();
317
318 /**
319 * This is the given touchable area relative to the window frame, or null if none.
320 */
321 final Region mGivenTouchableRegion = new Region();
322
323 /**
324 * Flag indicating whether the touchable region should be adjusted by
325 * the visible insets; if false the area outside the visible insets is
326 * NOT touchable, so we must use those to adjust the frame during hit
327 * tests.
328 */
329 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
330
331 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400332 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700333 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800334 float mHScale=1, mVScale=1;
335 float mLastHScale=1, mLastVScale=1;
336 final Matrix mTmpMatrix = new Matrix();
337
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700338 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800339 final Rect mFrame = new Rect();
340 final Rect mLastFrame = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700341 private boolean mFrameSizeChanged = false;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700342 // Frame that is scaled to the application's coordinate space when in
343 // screen size compatibility mode.
344 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800345
346 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700347
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700348 private final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700349
Wale Ogunwale94596652015-02-06 19:27:34 -0800350 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
351 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700352 final Rect mDisplayFrame = new Rect();
353
354 // The region of the display frame that the display type supports displaying content on. This
355 // is mostly a special case for TV where some displays don’t have the entire display usable.
356 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
357 // window display contents to extend into the overscan region.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700358 private final Rect mOverscanFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700359
360 // The display frame minus the stable insets. This value is always constant regardless of if
361 // the status bar or navigation bar is visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700362 private final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800363
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700364 // The area not occupied by the status and navigation bars. So, if both status and navigation
365 // bars are visible, the decor frame is equal to the stable frame.
366 final Rect mDecorFrame = new Rect();
367
368 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
369 // minus the area occupied by the IME if the IME is present.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700370 private final Rect mContentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700371
372 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
373 // displays hint text.
374 final Rect mVisibleFrame = new Rect();
375
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700376 // Frame that includes dead area outside of the surface but where we want to pretend that it's
377 // possible to draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700378 private final Rect mOutsetFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700379
Jorim Jaggidc249c42015-12-15 14:57:31 -0800380 /**
381 * Usually empty. Set to the task's tempInsetFrame. See
382 *{@link android.app.IActivityManager#resizeDockedStack}.
383 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700384 private final Rect mInsetFrame = new Rect();
Jorim Jaggidc249c42015-12-15 14:57:31 -0800385
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800386 boolean mContentChanged;
387
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800388 // If a window showing a wallpaper: the requested offset for the
389 // wallpaper; if a wallpaper window: the currently applied offset.
390 float mWallpaperX = -1;
391 float mWallpaperY = -1;
392
393 // If a window showing a wallpaper: what fraction of the offset
394 // range corresponds to a full virtual screen.
395 float mWallpaperXStep = -1;
396 float mWallpaperYStep = -1;
397
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700398 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
399 // to its window; if a wallpaper window: not used.
400 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
401 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
402
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800403 // Wallpaper windows: pixels offset based on above variables.
404 int mXOffset;
405 int mYOffset;
406
Craig Mautner2268e7e2012-12-13 15:40:00 -0800407 /**
408 * This is set after IWindowSession.relayout() has been called at
409 * least once for the window. It allows us to detect the situation
410 * where we don't yet have a surface, but should have one soon, so
411 * we can give the window focus before waiting for the relayout.
412 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800413 boolean mRelayoutCalled;
414
Robert Carrfed10072016-05-26 11:48:49 -0700415 boolean mInRelayout;
416
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800417 /**
418 * If the application has called relayout() with changes that can
419 * impact its window's size, we need to perform a layout pass on it
420 * even if it is not currently visible for layout. This is set
421 * when in that case until the layout is done.
422 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800423 boolean mLayoutNeeded;
424
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800425 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800426 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800427
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800428 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800429 boolean mDestroying;
430
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800431 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800432 boolean mRemoveOnExit;
433
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800434 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800435 * Whether the app died while it was visible, if true we might need
436 * to continue to show it until it's restarted.
437 */
438 boolean mAppDied;
439
440 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800441 * Set when the orientation is changing and this window has not yet
442 * been updated for the new orientation.
443 */
Bryce Lee8c3cf382017-07-06 19:47:10 -0700444 private boolean mOrientationChanging;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800445
Dianne Hackborna57c6952013-03-29 14:46:40 -0700446 /**
Robert Carr9c1c3a02017-08-08 12:59:01 -0700447 * Sometimes in addition to the mOrientationChanging
448 * flag we report that the orientation is changing
449 * due to a mismatch in current and reported configuration.
450 *
451 * In the case of timeout we still need to make sure we
452 * leave the orientation changing state though, so we
453 * use this as a special time out escape hatch.
454 */
455 private boolean mOrientationChangeTimedOut;
456
457 /**
Robert Carr237028a2016-07-26 10:39:45 -0700458 * The orientation during the last visible call to relayout. If our
459 * current orientation is different, the window can't be ready
460 * to be shown.
461 */
462 int mLastVisibleLayoutRotation = -1;
463
464 /**
Andrii Kulianb2e37802017-01-11 00:36:44 -0800465 * Set when we need to report the orientation change to client to trigger a relayout.
466 */
467 boolean mReportOrientationChanged;
468
469 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700470 * How long we last kept the screen frozen.
471 */
472 int mLastFreezeDuration;
473
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800474 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800475 boolean mRemoved;
476
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800477 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800478 * It is save to remove the window and destroy the surface because the client requested removal
479 * or some other higher level component said so (e.g. activity manager).
480 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800481 */
Svetoslav Ganov200adfb2016-10-18 13:29:27 -0700482 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800483
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800484 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700485 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800486 InputChannel mInputChannel;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700487 private InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800488
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800489 // Used to improve performance of toString()
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700490 private String mStringNameCache;
491 private CharSequence mLastTitle;
492 private boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800493
Craig Mautnera2c77052012-03-26 12:14:43 -0700494 final WindowStateAnimator mWinAnimator;
495
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700496 boolean mHasSurface = false;
497
Craig Mautner88400d32012-09-30 12:35:45 -0700498 /** When true this window can be displayed on screens owther than mOwnerUid's */
499 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700500
Robert Carr13f7be9e2015-12-02 18:39:45 -0800501 // Whether the window has a saved surface from last pause, which can be
502 // used to start an entering animation earlier.
Chong Zhang92147042016-05-09 12:47:11 -0700503 private boolean mSurfaceSaved = false;
504
Chong Zhang8e4bda92016-05-04 15:08:18 -0700505 // Whether we're performing an entering animation with a saved surface. This flag is
506 // true during the time we're showing a window with a previously saved surface. It's
507 // cleared when surface is destroyed, saved, or re-drawn by the app.
Chong Zhang92147042016-05-09 12:47:11 -0700508 private boolean mAnimatingWithSavedSurface;
509
510 // Whether the window was visible when we set the app to invisible last time. WM uses
511 // this as a hint to restore the surface (if available) for early animation next time
512 // the app is brought visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700513 private boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800514
Robert Carra1eb4392015-12-10 12:43:51 -0800515 // This window will be replaced due to relaunch. This allows window manager
516 // to differentiate between simple removal of a window and replacement. In the latter case it
517 // will preserve the old window until the new one is drawn.
518 boolean mWillReplaceWindow = false;
519 // If true, the replaced window was already requested to be removed.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700520 private boolean mReplacingRemoveRequested = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800521 // Whether the replacement of the window should trigger app transition animation.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700522 private boolean mAnimateReplacingWindow = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800523 // If not null, the window that will be used to replace the old one. This is being set when
524 // the window is added and unset when this window reports its first draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700525 private WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700526 // For the new window in the replacement transition, if we have
527 // requested to replace without animation, then we should
528 // make sure we also don't apply an enter animation for
529 // the new window.
530 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800531 // Whether this window is being moved via the resize API
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700532 private boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800533
Jeff Brownc2932a12014-11-20 18:04:05 -0800534 /**
535 * Wake lock for drawing.
536 * Even though it's slightly more expensive to do so, we will use a separate wake lock
537 * for each app that is requesting to draw while dozing so that we can accurately track
538 * who is preventing the system from suspending.
539 * This lock is only acquired on first use.
540 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700541 private PowerManager.WakeLock mDrawLock;
Jeff Brownc2932a12014-11-20 18:04:05 -0800542
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700543 final private Rect mTmpRect = new Rect();
544
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800545 /**
546 * Whether the window was resized by us while it was gone for layout.
547 */
548 boolean mResizedWhileGone = false;
549
Andrii Kulianeb1d3222016-05-16 15:17:55 -0700550 /** @see #isResizedWhileNotDragResizing(). */
551 private boolean mResizedWhileNotDragResizing;
552
553 /** @see #isResizedWhileNotDragResizingReported(). */
554 private boolean mResizedWhileNotDragResizingReported;
Jorim Jaggif3df0aa2016-04-06 15:56:33 -0700555
Robert Carr6da3cc02016-06-16 15:17:07 -0700556 /**
557 * During seamless rotation we have two phases, first the old window contents
558 * are rotated to look as if they didn't move in the new coordinate system. Then we
559 * have to freeze updates to this layer (to preserve the transformation) until
560 * the resize actually occurs. This is true from when the transformation is set
561 * and false until the transaction to resize is sent.
562 */
563 boolean mSeamlesslyRotated = false;
564
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700565 private static final Region sEmptyRegion = new Region();
566
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700567 /**
Robert Carrc91d1c32017-02-15 19:37:46 -0800568 * Surface insets from the previous call to relayout(), used to track
569 * if we are changing the Surface insets.
570 */
571 final Rect mLastSurfaceInsets = new Rect();
572
573 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700574 * A flag set by the {@link WindowState} parent to indicate that the parent has examined this
575 * {@link WindowState} in its overall drawing context. This book-keeping allows the parent to
576 * make sure all children have been considered.
577 */
578 private boolean mDrawnStateEvaluated;
579
580 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700581 * Compares two window sub-layers and returns -1 if the first is lesser than the second in terms
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700582 * of z-order and 1 otherwise.
583 */
Griff Hazen51d00d82016-11-22 15:39:24 -0800584 private static final Comparator<WindowState> sWindowSubLayerComparator =
585 new Comparator<WindowState>() {
586 @Override
587 public int compare(WindowState w1, WindowState w2) {
588 final int layer1 = w1.mSubLayer;
589 final int layer2 = w2.mSubLayer;
590 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
591 // We insert the child window into the list ordered by
592 // the sub-layer. For same sub-layers, the negative one
593 // should go below others; the positive one should go
594 // above others.
595 return -1;
596 }
597 return 1;
598 };
599 };
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700600
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800601 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700602 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800603 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800604 mService = service;
605 mSession = s;
606 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800607 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800608 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700609 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700610 mOwnerUid = ownerId;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800611 mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200612 mWindowId = new WindowId(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800613 mAttrs.copyFrom(a);
614 mViewVisibility = viewVisibility;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700615 mPolicy = mService.mPolicy;
616 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800617 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700618 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700619 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700620 if (localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700621 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700622 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800623 try {
624 c.asBinder().linkToDeath(deathRecipient, 0);
625 } catch (RemoteException e) {
626 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700627 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800628 mLayoutAttached = false;
629 mIsImWindow = false;
630 mIsWallpaper = false;
631 mIsFloatingLayer = false;
632 mBaseLayer = 0;
633 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700634 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700635 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800636 return;
637 }
638 mDeathRecipient = deathRecipient;
639
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700640 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800641 // The multiplier here is to reserve space for multiple
642 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800643 mBaseLayer = mPolicy.getWindowLayerLw(parentWindow)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700644 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800645 mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700646 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900647
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700648 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow);
649 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900650
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800651 mLayoutAttached = mAttrs.type !=
652 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700653 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
654 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
655 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800656 } else {
657 // The multiplier here is to reserve space for multiple
658 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800659 mBaseLayer = mPolicy.getWindowLayerLw(this)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700660 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800661 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700662 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800663 mLayoutAttached = false;
664 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
665 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
666 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800667 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700668 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800669
Wale Ogunwale72919d22016-12-08 18:58:50 -0800670 if (mAppToken != null && mAppToken.mShowForAllUsers) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700671 // Windows for apps that can show for all users should also show when the device is
672 // locked.
673 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
Craig Mautner19ab8282014-05-07 10:35:34 -0700674 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800675
Craig Mautner322e4032012-07-13 13:35:20 -0700676 mWinAnimator = new WindowStateAnimator(this);
677 mWinAnimator.mAlpha = a.alpha;
678
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800679 mRequestedWidth = 0;
680 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700681 mLastRequestedWidth = 0;
682 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800683 mXOffset = 0;
684 mYOffset = 0;
685 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800686 mInputWindowHandle = new InputWindowHandle(
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800687 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this, c,
688 getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800689 }
690
691 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700692 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800693 mSession.windowAddedLocked(mAttrs.packageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800694 }
695
Bryce Leed390deb2017-06-22 13:14:28 -0700696 /**
697 * Returns whether this {@link WindowState} has been considered for drawing by its parent.
698 */
Bryce Lee6311c4b2017-07-06 14:09:29 -0700699 boolean getDrawnStateEvaluated() {
Bryce Leed390deb2017-06-22 13:14:28 -0700700 return mDrawnStateEvaluated;
701 }
702
703 /**
704 * Sets whether this {@link WindowState} has been considered for drawing by its parent. Should
705 * be cleared when detached from parent.
706 */
707 void setDrawnStateEvaluated(boolean evaluated) {
708 mDrawnStateEvaluated = evaluated;
709 }
710
711 @Override
712 void onParentSet() {
713 super.onParentSet();
714 setDrawnStateEvaluated(false /*evaluated*/);
715 }
716
Craig Mautnera2c77052012-03-26 12:14:43 -0700717 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800718 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800719 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800720 }
721
722 @Override
723 public String getOwningPackage() {
724 return mAttrs.packageName;
725 }
726
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800727 @Override
728 public boolean canAddInternalSystemWindow() {
729 return mOwnerCanAddInternalSystemWindow;
730 }
731
Jorim Jaggif5834272016-04-04 20:25:41 -0700732 /**
733 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
734 * from {@param frame}. In other words, it applies the insets that would result if
735 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700736 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
737 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700738 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700739 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
740 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
741 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
742 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
743 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700744 frame.inset(left, top, right, bottom);
745 }
746
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800747 @Override
Robert Carr43521762016-10-28 13:15:04 -0700748 public void computeFrameLw(Rect parentFrame, Rect displayFrame, Rect overscanFrame,
749 Rect contentFrame, Rect visibleFrame, Rect decorFrame, Rect stableFrame,
750 Rect outsetFrame) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800751 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700752 // This window is being replaced and either already got information that it's being
753 // removed or we are still waiting for some information. Because of this we don't
754 // want to apply any more changes to it, so it remains in this state until new window
755 // appears.
756 return;
757 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800758 mHaveFrame = true;
759
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700760 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700761 final boolean inFullscreenContainer = inFullscreenContainer();
Robert Carre6275582016-02-29 15:45:45 -0800762 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700763 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800764
Chong Zhangae35fef2016-03-16 15:56:55 -0700765 // If the task has temp inset bounds set, we have to make sure all its windows uses
766 // the temp inset frame. Otherwise different display frames get applied to the main
767 // window and the child window, making them misaligned.
Andrii Kulianc24f3732017-08-08 19:35:17 -0700768 if (inFullscreenContainer || isLetterboxedAppWindow()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700769 mInsetFrame.setEmpty();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700770 } else if (task != null && isInMultiWindowMode()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700771 task.getTempInsetBounds(mInsetFrame);
772 }
773
Jorim Jaggif5834272016-04-04 20:25:41 -0700774 // Denotes the actual frame used to calculate the insets and to perform the layout. When
775 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
776 // insets temporarily. By the notion of a task having a different layout frame, we can
777 // achieve that while still moving the task around.
778 final Rect layoutContainingFrame;
779 final Rect layoutDisplayFrame;
780
781 // The offset from the layout containing frame to the actual containing frame.
782 final int layoutXDiff;
783 final int layoutYDiff;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700784 if (inFullscreenContainer || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800785 // We use the parent frame as the containing frame for fullscreen and child windows
Robert Carr43521762016-10-28 13:15:04 -0700786 mContainingFrame.set(parentFrame);
787 mDisplayFrame.set(displayFrame);
788 layoutDisplayFrame = displayFrame;
789 layoutContainingFrame = parentFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700790 layoutXDiff = 0;
791 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800792 } else {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700793 getContainerBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100794 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
795
796 // If the bounds are frozen, we still want to translate the window freely and only
797 // freeze the size.
798 Rect frozen = mAppToken.mFrozenBounds.peek();
799 mContainingFrame.right = mContainingFrame.left + frozen.width();
800 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
801 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800802 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700803 // IME is up and obscuring this window. Adjust the window position so it is visible.
804 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this) {
Winson Chungd73e94b2017-05-31 16:25:30 -0700805 final int stackId = getStackId();
806 if (stackId == FREEFORM_WORKSPACE_STACK_ID
807 && mContainingFrame.bottom > contentFrame.bottom) {
808 // In freeform we want to move the top up directly.
809 // TODO: Investigate why this is contentFrame not parentFrame.
810 mContainingFrame.top -= mContainingFrame.bottom - contentFrame.bottom;
811 } else if (stackId != PINNED_STACK_ID
812 && mContainingFrame.bottom > parentFrame.bottom) {
813 // But in docked we want to behave like fullscreen and behave as if the task
814 // were given smaller bounds for the purposes of layout. Skip adjustments for
815 // the pinned stack, they are handled separately in the PinnedStackController.
816 mContainingFrame.bottom = parentFrame.bottom;
817 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700818 }
Skuhne81c524a2015-08-12 13:34:14 -0700819
Robert Carre6275582016-02-29 15:45:45 -0800820 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700821 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
822 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800823 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700824 if (mContainingFrame.isEmpty()) {
Robert Carr43521762016-10-28 13:15:04 -0700825 mContainingFrame.set(contentFrame);
Skuhne81c524a2015-08-12 13:34:14 -0700826 }
Doris Liu06d582d2015-06-01 13:18:43 -0700827 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800828 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700829 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
830 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
831 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700832 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
Robert Carr43521762016-10-28 13:15:04 -0700833 subtractInsets(mDisplayFrame, layoutContainingFrame, displayFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700834 if (!layoutInParentFrame()) {
Robert Carr43521762016-10-28 13:15:04 -0700835 subtractInsets(mContainingFrame, layoutContainingFrame, parentFrame, mTmpRect);
836 subtractInsets(mInsetFrame, layoutContainingFrame, parentFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700837 }
Robert Carr43521762016-10-28 13:15:04 -0700838 layoutDisplayFrame = displayFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700839 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700840 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800841
Craig Mautner967212c2013-04-13 21:10:58 -0700842 final int pw = mContainingFrame.width();
843 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800844
Robert Carr43521762016-10-28 13:15:04 -0700845 if (!mParentFrame.equals(parentFrame)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800846 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Robert Carr43521762016-10-28 13:15:04 -0700847 // + " to " + parentFrame);
848 mParentFrame.set(parentFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800849 mContentChanged = true;
850 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700851 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
852 mLastRequestedWidth = mRequestedWidth;
853 mLastRequestedHeight = mRequestedHeight;
854 mContentChanged = true;
855 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800856
Robert Carr43521762016-10-28 13:15:04 -0700857 mOverscanFrame.set(overscanFrame);
858 mContentFrame.set(contentFrame);
859 mVisibleFrame.set(visibleFrame);
860 mDecorFrame.set(decorFrame);
861 mStableFrame.set(stableFrame);
862 final boolean hasOutsets = outsetFrame != null;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700863 if (hasOutsets) {
Robert Carr43521762016-10-28 13:15:04 -0700864 mOutsetFrame.set(outsetFrame);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700865 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800866
Craig Mautnereda67292013-04-28 13:50:14 -0700867 final int fw = mFrame.width();
868 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800869
Jorim Jaggif5834272016-04-04 20:25:41 -0700870 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
871
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700872 // Calculate the outsets before the content frame gets shrinked to the window frame.
873 if (hasOutsets) {
874 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
875 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
876 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
877 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
878 } else {
879 mOutsets.set(0, 0, 0, 0);
880 }
881
Craig Mautnera248eee2013-05-07 11:41:27 -0700882 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800883 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -0800884 if (windowsAreFloating && !mFrame.isEmpty()) {
Robert Carre65a1c42017-02-28 16:52:59 -0800885 // For pinned workspace the frame isn't limited in any particular
886 // way since SystemUI controls the bounds. For freeform however
887 // we want to keep things inside the content frame.
888 final Rect limitFrame = task.inPinnedWorkspace() ? mFrame : mContentFrame;
Skuhne81c524a2015-08-12 13:34:14 -0700889 // Keep the frame out of the blocked system area, limit it in size to the content area
890 // and make sure that there is always a minimum visible so that the user can drag it
891 // into a usable area..
Robert Carre65a1c42017-02-28 16:52:59 -0800892 final int height = Math.min(mFrame.height(), limitFrame.height());
893 final int width = Math.min(limitFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700894 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +0900895 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
896 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
897 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
898 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Robert Carre65a1c42017-02-28 16:52:59 -0800899 final int top = Math.max(limitFrame.top,
900 Math.min(mFrame.top, limitFrame.bottom - minVisibleHeight));
901 final int left = Math.max(limitFrame.left + minVisibleWidth - width,
902 Math.min(mFrame.left, limitFrame.right - minVisibleWidth));
Skuhne81c524a2015-08-12 13:34:14 -0700903 mFrame.set(left, top, left + width, top + height);
904 mContentFrame.set(mFrame);
905 mVisibleFrame.set(mContentFrame);
906 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700907 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700908 dc.getDockedDividerController().positionDockedStackedDivider(mFrame);
Jorim Jaggi192086e2016-03-11 17:17:03 +0100909 mContentFrame.set(mFrame);
910 if (!mFrame.equals(mLastFrame)) {
911 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800912 }
Skuhne81c524a2015-08-12 13:34:14 -0700913 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -0700914 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
915 Math.max(mContentFrame.top, mFrame.top),
916 Math.min(mContentFrame.right, mFrame.right),
917 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800918
Jorim Jaggi656f6502016-04-11 21:08:17 -0700919 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
920 Math.max(mVisibleFrame.top, mFrame.top),
921 Math.min(mVisibleFrame.right, mFrame.right),
922 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800923
Jorim Jaggi656f6502016-04-11 21:08:17 -0700924 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
925 Math.max(mStableFrame.top, mFrame.top),
926 Math.min(mStableFrame.right, mFrame.right),
927 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700928 }
Adrian Roosfa104232014-06-20 16:10:14 -0700929
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700930 if (inFullscreenContainer && !windowsAreFloating) {
Jorim Jaggi899327f2016-02-25 20:44:18 -0500931 // Windows that are not fullscreen can be positioned outside of the display frame,
932 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -0700933 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
934 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
935 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
936 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800937 }
Craig Mautnereda67292013-04-28 13:50:14 -0700938
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100939 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100940 // For the docked divider, we calculate the stable insets like a full-screen window
941 // so it can use it to calculate the snap positions.
942 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
943 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
944 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
945 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800946
947 // The divider doesn't care about insets in any case, so set it to empty so we don't
948 // trigger a relayout when moving it.
949 mContentInsets.setEmpty();
950 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100951 } else {
Andrii Kuliand9003372016-04-04 17:46:59 -0700952 getDisplayContent().getLogicalDisplayRect(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700953 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
954 // non-fullscreen mode.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700955 boolean overrideRightInset = !windowsAreFloating && !inFullscreenContainer
956 && mFrame.right > mTmpRect.right;
957 boolean overrideBottomInset = !windowsAreFloating && !inFullscreenContainer
958 && mFrame.bottom > mTmpRect.bottom;
Jorim Jaggi656f6502016-04-11 21:08:17 -0700959 mContentInsets.set(mContentFrame.left - mFrame.left,
960 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700961 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700962 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700963 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700964 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800965
Jorim Jaggi656f6502016-04-11 21:08:17 -0700966 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
967 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700968 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700969 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700970 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700971 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800972
Jorim Jaggi656f6502016-04-11 21:08:17 -0700973 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
974 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700975 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700976 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700977 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700978 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100979 }
Adrian Roosfa104232014-06-20 16:10:14 -0700980
Jorim Jaggi656f6502016-04-11 21:08:17 -0700981 // Offset the actual frame by the amount layout frame is off.
982 mFrame.offset(-layoutXDiff, -layoutYDiff);
983 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -0700984 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
985 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
986 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
987
Craig Mautnereda67292013-04-28 13:50:14 -0700988 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400989 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700990 // If there is a size compatibility scale being applied to the
991 // window, we need to apply this to its insets so that they are
992 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700993 mOverscanInsets.scale(mInvGlobalScale);
994 mContentInsets.scale(mInvGlobalScale);
995 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700996 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700997 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700998
999 // Also the scaled frame that we report to the app needs to be
1000 // adjusted to be in its coordinate space.
1001 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001002 }
1003
Craig Mautnereda67292013-04-28 13:50:14 -07001004 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001005 final DisplayContent displayContent = getDisplayContent();
1006 if (displayContent != null) {
1007 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwale0303c572016-10-20 10:16:29 -07001008 getDisplayContent().mWallpaperController.updateWallpaperOffset(
Wale Ogunwalee8069dc2015-08-18 09:52:01 -07001009 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001010 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001011 }
1012
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001013 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001014 "Resolving (mRequestedWidth="
1015 + mRequestedWidth + ", mRequestedheight="
1016 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
1017 + "): frame=" + mFrame.toShortString()
1018 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07001019 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -07001020 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001021 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001022 }
1023
Craig Mautnera2c77052012-03-26 12:14:43 -07001024 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001025 public Rect getFrameLw() {
1026 return mFrame;
1027 }
1028
Craig Mautnera2c77052012-03-26 12:14:43 -07001029 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001030 public Point getShownPositionLw() {
1031 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001032 }
1033
Craig Mautnera2c77052012-03-26 12:14:43 -07001034 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001035 public Rect getDisplayFrameLw() {
1036 return mDisplayFrame;
1037 }
1038
Craig Mautnera2c77052012-03-26 12:14:43 -07001039 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001040 public Rect getOverscanFrameLw() {
1041 return mOverscanFrame;
1042 }
1043
1044 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001045 public Rect getContentFrameLw() {
1046 return mContentFrame;
1047 }
1048
Craig Mautnera2c77052012-03-26 12:14:43 -07001049 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001050 public Rect getVisibleFrameLw() {
1051 return mVisibleFrame;
1052 }
1053
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001054 Rect getStableFrameLw() {
1055 return mStableFrame;
1056 }
1057
Craig Mautnera2c77052012-03-26 12:14:43 -07001058 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001059 public boolean getGivenInsetsPendingLw() {
1060 return mGivenInsetsPending;
1061 }
1062
Craig Mautnera2c77052012-03-26 12:14:43 -07001063 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001064 public Rect getGivenContentInsetsLw() {
1065 return mGivenContentInsets;
1066 }
1067
Craig Mautnera2c77052012-03-26 12:14:43 -07001068 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001069 public Rect getGivenVisibleInsetsLw() {
1070 return mGivenVisibleInsets;
1071 }
1072
Craig Mautnera2c77052012-03-26 12:14:43 -07001073 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001074 public WindowManager.LayoutParams getAttrs() {
1075 return mAttrs;
1076 }
1077
Craig Mautner812d2ca2012-09-27 15:35:34 -07001078 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001079 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001080 return getDisplayContent().getNeedsMenu(this, bottom);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001081 }
1082
Craig Mautner19d59bc2012-09-04 11:15:56 -07001083 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001084 public int getSystemUiVisibility() {
1085 return mSystemUiVisibility;
1086 }
1087
Craig Mautner19d59bc2012-09-04 11:15:56 -07001088 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001089 public int getSurfaceLayer() {
1090 return mLayer;
1091 }
1092
Craig Mautner812d2ca2012-09-27 15:35:34 -07001093 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001094 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001095 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001096 }
1097
1098 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001099 public IApplicationToken getAppToken() {
1100 return mAppToken != null ? mAppToken.appToken : null;
1101 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001102
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001103 @Override
1104 public boolean isVoiceInteraction() {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001105 return mAppToken != null && mAppToken.mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001106 }
1107
Robert Carr31aa98b2016-07-20 15:29:03 -07001108 boolean setReportResizeHints() {
Craig Mautner4c5eb222013-11-18 12:59:05 -08001109 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1110 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1111 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001112 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001113 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
Robert Carr31aa98b2016-07-20 15:29:03 -07001114 mFrameSizeChanged |= (mLastFrame.width() != mFrame.width()) ||
1115 (mLastFrame.height() != mFrame.height());
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001116 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
Robert Carr31aa98b2016-07-20 15:29:03 -07001117 || mOutsetsChanged || mFrameSizeChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001118 }
1119
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001120 /**
1121 * Adds the window to the resizing list if any of the parameters we use to track the window
1122 * dimensions or insets have changed.
1123 */
1124 void updateResizingWindowIfNeeded() {
1125 final WindowStateAnimator winAnimator = mWinAnimator;
1126 if (!mHasSurface || mService.mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
1127 return;
1128 }
1129
1130 final Task task = getTask();
1131 // In the case of stack bound animations, the window frames will update (unlike other
1132 // animations which just modify various transformation properties). We don't want to
1133 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1134 // the frame may not correspond to the surface size or the onscreen area at various
1135 // phases in the animation, and the client will become sad and confused.
Winson Chung40a5f932017-04-13 16:39:36 -07001136 if (task != null && task.mStack.isAnimatingBounds()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001137 return;
1138 }
1139
1140 setReportResizeHints();
1141 boolean configChanged = isConfigChanged();
1142 if (DEBUG_CONFIGURATION && configChanged) {
1143 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1144 }
1145
1146 final boolean dragResizingChanged = isDragResizeChanged()
1147 && !isDragResizingChangeReported();
1148
1149 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
1150 + " dragResizingChanged=" + dragResizingChanged + " last=" + mLastFrame
1151 + " frame=" + mFrame);
1152
1153 // We update mLastFrame always rather than in the conditional with the last inset
1154 // variables, because mFrameSizeChanged only tracks the width and height changing.
1155 mLastFrame.set(mFrame);
1156
1157 if (mContentInsetsChanged
1158 || mVisibleInsetsChanged
1159 || winAnimator.mSurfaceResized
1160 || mOutsetsChanged
1161 || mFrameSizeChanged
1162 || configChanged
1163 || dragResizingChanged
Andrii Kulianb2e37802017-01-11 00:36:44 -08001164 || !isResizedWhileNotDragResizingReported()
1165 || mReportOrientationChanged) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001166 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1167 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
1168 + " contentInsetsChanged=" + mContentInsetsChanged
1169 + " " + mContentInsets.toShortString()
1170 + " visibleInsetsChanged=" + mVisibleInsetsChanged
1171 + " " + mVisibleInsets.toShortString()
1172 + " stableInsetsChanged=" + mStableInsetsChanged
1173 + " " + mStableInsets.toShortString()
1174 + " outsetsChanged=" + mOutsetsChanged
1175 + " " + mOutsets.toShortString()
1176 + " surfaceResized=" + winAnimator.mSurfaceResized
1177 + " configChanged=" + configChanged
1178 + " dragResizingChanged=" + dragResizingChanged
1179 + " resizedWhileNotDragResizingReported="
Andrii Kulianb2e37802017-01-11 00:36:44 -08001180 + isResizedWhileNotDragResizingReported()
1181 + " reportOrientationChanged=" + mReportOrientationChanged);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001182 }
1183
1184 // If it's a dead window left on screen, and the configuration changed, there is nothing
1185 // we can do about it. Remove the window now.
1186 if (mAppToken != null && mAppDied) {
1187 mAppToken.removeDeadWindows();
1188 return;
1189 }
1190
Jorim Jaggidc9385a2017-05-13 02:00:31 +02001191 updateLastInsetValues();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001192 mService.makeWindowFreezingScreenIfNeededLocked(this);
1193
1194 // If the orientation is changing, or we're starting or ending a drag resizing action,
1195 // then we need to hold off on unfreezing the display until this window has been
1196 // redrawn; to do that, we need to go through the process of getting informed by the
1197 // application when it has finished drawing.
Bryce Lee8c3cf382017-07-06 19:47:10 -07001198 if (getOrientationChanging() || dragResizingChanged
1199 || isResizedWhileNotDragResizing()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001200 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
1201 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1202 + ", mDrawState=DRAW_PENDING in " + this
1203 + ", surfaceController " + winAnimator.mSurfaceController);
1204 }
1205 winAnimator.mDrawState = DRAW_PENDING;
1206 if (mAppToken != null) {
1207 mAppToken.clearAllDrawn();
1208 }
1209 }
1210 if (!mService.mResizingWindows.contains(this)) {
1211 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
1212 mService.mResizingWindows.add(this);
1213 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07001214 } else if (getOrientationChanging()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001215 if (isDrawnLw()) {
1216 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1217 + this + ", surfaceController " + winAnimator.mSurfaceController);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001218 setOrientationChanging(false);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001219 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1220 - mService.mDisplayFreezeTime);
1221 }
1222 }
1223 }
1224
Bryce Lee8c3cf382017-07-06 19:47:10 -07001225 boolean getOrientationChanging() {
1226 // In addition to the local state flag, we must also consider the difference in the last
1227 // reported configuration vs. the current state. If the client code has not been informed of
1228 // the change, logic dependent on having finished processing the orientation, such as
1229 // unfreezing, could be improperly triggered.
1230 // TODO(b/62846907): Checking against {@link mLastReportedConfiguration} could be flaky as
1231 // this is not necessarily what the client has processed yet. Find a
1232 // better indicator consistent with the client.
Robert Carr926643f2017-08-02 12:01:12 -07001233 return (mOrientationChanging || (isVisible()
1234 && getConfiguration().orientation != mLastReportedConfiguration.orientation))
Robert Carr9c1c3a02017-08-08 12:59:01 -07001235 && !mSeamlesslyRotated
1236 && !mOrientationChangeTimedOut;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001237 }
1238
1239 void setOrientationChanging(boolean changing) {
1240 mOrientationChanging = changing;
Robert Carr9c1c3a02017-08-08 12:59:01 -07001241 mOrientationChangeTimedOut = false;
1242 }
1243
1244 void orientationChangeTimedOut() {
1245 mOrientationChangeTimedOut = true;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001246 }
1247
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001248 DisplayContent getDisplayContent() {
1249 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001250 }
1251
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001252 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001253 final DisplayContent displayContent = getDisplayContent();
1254 return displayContent != null ? displayContent.getDisplayInfo() : null;
1255 }
1256
Jorim Jaggife762342016-10-13 14:33:27 +02001257 @Override
1258 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001259 final DisplayContent displayContent = getDisplayContent();
1260 if (displayContent == null) {
1261 return -1;
1262 }
1263 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001264 }
1265
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001266 Task getTask() {
Bryce Lee6d410262017-02-28 15:30:17 -08001267 return mAppToken != null ? mAppToken.getTask() : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001268 }
1269
1270 TaskStack getStack() {
1271 Task task = getTask();
1272 if (task != null) {
1273 if (task.mStack != null) {
1274 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001275 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001276 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001277 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1278 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001279 final DisplayContent dc = getDisplayContent();
1280 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001281 }
1282
Skuhnef932e562015-08-20 12:07:30 -07001283 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001284 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001285 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001286 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001287 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001288 final Task task = getTask();
1289 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001290 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001291 mTmpRect.setEmpty();
1292 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001293 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001294 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001295 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001296 } else {
1297 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001298 }
1299 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001300
Chong Zhang9184ec62015-09-24 12:32:21 -07001301 bounds.set(mVisibleFrame);
1302 if (intersectWithStackBounds) {
1303 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001304 }
1305
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001306 if (bounds.isEmpty()) {
1307 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001308 if (intersectWithStackBounds) {
1309 bounds.intersect(mTmpRect);
1310 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001311 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001312 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001313 }
1314
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001315 public long getInputDispatchingTimeoutNanos() {
1316 return mAppToken != null
Wale Ogunwale72919d22016-12-08 18:58:50 -08001317 ? mAppToken.mInputDispatchingTimeoutNanos
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001318 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1319 }
1320
Craig Mautnere8552142012-11-07 13:55:47 -08001321 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001322 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001323 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001324 }
1325
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001326 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1327 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1328 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1329 if (dtdx < -.000001f || dtdx > .000001f) return false;
1330 if (dsdy < -.000001f || dsdy > .000001f) return false;
1331 return true;
1332 }
1333
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001334 void prelayout() {
1335 if (mEnforceSizeCompat) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001336 mGlobalScale = getDisplayContent().mCompatibleScreenScale;
1337 mInvGlobalScale = 1 / mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001338 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001339 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001340 }
1341 }
1342
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001343 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001344 boolean hasContentToDisplay() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001345 // If we're animating with a saved surface, we're already visible.
1346 // Return true so that the alpha doesn't get cleared.
1347 if (!mAppFreezing && isDrawnLw()
1348 && (mViewVisibility == View.VISIBLE || isAnimatingWithSavedSurface()
1349 || (mWinAnimator.isAnimationSet() && !mService.mAppTransition.isTransitionSet()))) {
1350 return true;
1351 }
1352
Wale Ogunwale44f21802016-09-02 12:49:48 -07001353 return super.hasContentToDisplay();
1354 }
1355
1356 @Override
1357 boolean isVisible() {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001358 return wouldBeVisibleIfPolicyIgnored() && mPolicyVisibility;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001359 }
1360
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001361 /**
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001362 * @return True if the window would be visible if we'd ignore policy visibility, false
1363 * otherwise.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001364 */
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001365 boolean wouldBeVisibleIfPolicyIgnored() {
Jorim Jaggi43530c92017-05-18 01:53:56 +02001366 return mHasSurface && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001367 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001368 }
1369
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001370 @Override
1371 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001372 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001373 }
1374
1375 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001376 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1377 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001378 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001379 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1380 boolean isWinVisibleLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001381 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.mAppAnimator.animating)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001382 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001383 }
1384
1385 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001386 * The same as isVisible(), but follows the current hidden state of the associated app token,
1387 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001388 */
1389 boolean isVisibleNow() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001390 return (!mToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001391 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001392 }
1393
1394 /**
1395 * Can this window possibly be a drag/drop target? The test here is
1396 * a combination of the above "visible now" with the check that the
1397 * Input Manager uses when discarding windows from input consideration.
1398 */
1399 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001400 return isVisibleNow() && !mRemoved
1401 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001402 }
1403
1404 /**
1405 * Same as isVisible(), but we also count it as visible between the
1406 * call to IWindowSession.add() and the first relayout().
1407 */
1408 boolean isVisibleOrAdding() {
1409 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001410 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001411 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001412 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001413 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001414 }
1415
1416 /**
1417 * Is this window currently on-screen? It is on-screen either if it
1418 * is visible or it is currently running an animation before no longer
1419 * being visible.
1420 */
1421 boolean isOnScreen() {
Jorim Jaggiaf221d12016-11-15 14:59:57 -08001422 if (!mHasSurface || mDestroying || !mPolicyVisibility) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001423 return false;
1424 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001425 final AppWindowToken atoken = mAppToken;
1426 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001427 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001428 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001429 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07001430 return !isParentWindowHidden() || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001431 }
1432
1433 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001434 * Whether this window's drawn state might affect the drawn states of the app token.
1435 *
1436 * @param visibleOnly Whether we should consider only the windows that's currently
1437 * visible in layout. If true, windows that has not relayout to VISIBLE
1438 * would always return false.
1439 *
1440 * @return true if the window should be considered while evaluating allDrawn flags.
1441 */
1442 boolean mightAffectAllDrawn(boolean visibleOnly) {
Wale Ogunwale89973222017-04-23 18:39:45 -07001443 final boolean isViewVisible = (mAppToken == null || !mAppToken.isClientHidden())
Chong Zhange292eb32016-05-21 09:23:55 -07001444 && (mViewVisibility == View.VISIBLE) && !mWindowRemovalAllowed;
Jorim Jaggib0d27342016-11-01 16:10:42 -07001445 return (isOnScreen() && (!visibleOnly || isViewVisible)
Chong Zhangfea963e2016-08-15 17:14:16 -07001446 || mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1447 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION)
Chong Zhang8e4bda92016-05-04 15:08:18 -07001448 && !mAnimatingExit && !mDestroying;
1449 }
1450
1451 /**
1452 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1453 * it must be drawn before allDrawn can become true.
1454 */
1455 boolean isInteresting() {
1456 return mAppToken != null && !mAppDied
1457 && (!mAppToken.mAppAnimator.freezingScreen || !mAppFreezing);
1458 }
1459
1460 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001461 * Like isOnScreen(), but we don't return true if the window is part
1462 * of a transition that has not yet been started.
1463 */
1464 boolean isReadyForDisplay() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001465 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001466 return false;
1467 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001468 return mHasSurface && mPolicyVisibility && !mDestroying
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001469 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001470 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001471 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001472 }
1473
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001474 // TODO: Another visibility method that was added late in the release to minimize risk.
1475 @Override
1476 public boolean canAffectSystemUiFlags() {
1477 final boolean shown = mWinAnimator.getShown();
Jorim Jaggic0c93242017-08-04 16:05:02 +02001478
1479 // We only consider the app to be exiting when the animation has started. After the app
1480 // transition is executed the windows are marked exiting before the new windows have been
1481 // shown. Thus, wait considering a window to be exiting after the animation has actually
1482 // started.
1483 final boolean appAnimationStarting = mAppToken != null
1484 && mAppToken.mAppAnimator.isAnimationStarting();
1485 final boolean exitingSelf = mAnimatingExit && (!mWinAnimator.isAnimationStarting()
1486 && !appAnimationStarting);
1487 final boolean appExiting = mAppToken != null && mAppToken.hidden && !appAnimationStarting;
1488
1489 final boolean exiting = exitingSelf || mDestroying || appExiting;
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001490 final boolean translucent = mAttrs.alpha == 0.0f;
1491 return shown && !exiting && !translucent;
1492 }
1493
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001494 /**
1495 * Like isOnScreen, but returns false if the surface hasn't yet
1496 * been drawn.
1497 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001498 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001499 public boolean isDisplayedLw() {
1500 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001501 return isDrawnLw() && mPolicyVisibility
Wale Ogunwale9d147902016-07-16 11:58:55 -07001502 && ((!isParentWindowHidden() &&
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001503 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001504 || mWinAnimator.mAnimating
1505 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001506 }
1507
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001508 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001509 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001510 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001511 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001512 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001513 return mWinAnimator.mAnimation != null
1514 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001515 }
1516
Craig Mautner812d2ca2012-09-27 15:35:34 -07001517 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001518 public boolean isGoneForLayoutLw() {
1519 final AppWindowToken atoken = mAppToken;
1520 return mViewVisibility == View.GONE
1521 || !mRelayoutCalled
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001522 || (atoken == null && mToken.hidden)
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001523 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001524 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001525 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001526 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001527 }
1528
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001529 /**
1530 * Returns true if the window has a surface that it has drawn a
1531 * complete UI in to.
1532 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001533 public boolean isDrawFinishedLw() {
1534 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001535 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1536 || mWinAnimator.mDrawState == READY_TO_SHOW
1537 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001538 }
1539
1540 /**
1541 * Returns true if the window has a surface that it has drawn a
1542 * complete UI in to.
1543 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001544 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001545 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001546 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001547 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001548 }
1549
1550 /**
1551 * Return true if the window is opaque and fully drawn. This indicates
1552 * it may obscure windows behind it.
1553 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001554 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001555 // When there is keyguard, wallpaper could be placed over the secure app
1556 // window but invisible. We need to check wallpaper visibility explicitly
1557 // to determine if it's occluding apps.
1558 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1559 || (mIsWallpaper && mWallpaperVisible))
Craig Mautnera2c77052012-03-26 12:14:43 -07001560 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001561 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001562 }
1563
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001564 @Override
1565 void onMovedByResize() {
1566 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001567 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001568 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001569 }
1570
1571 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1572 boolean changed = false;
1573
1574 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001575 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001576 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1577 }
1578
1579 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1580 // Starting window that's exiting will be removed when the animation finishes.
1581 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1582 // to actually remove it.
1583 if (!visible && isVisibleNow() && mAppToken.mAppAnimator.isAnimating()) {
1584 mAnimatingExit = true;
1585 mRemoveOnExit = true;
1586 mWindowRemovalAllowed = true;
1587 }
1588 return changed;
1589 }
1590
Robert Carrd5c7dd62017-03-08 10:39:30 -08001591 // Next up we will notify the client that it's visibility has changed.
1592 // We need to prevent it from destroying child surfaces until
1593 // the animation has finished.
1594 if (!visible && isVisibleNow()) {
1595 mWinAnimator.detachChildren();
1596 }
1597
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001598 if (visible != isVisibleNow()) {
1599 if (!runningAppAnimation) {
1600 final AccessibilityController accessibilityController =
1601 mService.mAccessibilityController;
1602 final int winTransit = visible ? TRANSIT_ENTER : TRANSIT_EXIT;
1603 mWinAnimator.applyAnimationLocked(winTransit, visible);
1604 //TODO (multidisplay): Magnification is supported only for the default
1605 if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
1606 accessibilityController.onWindowTransitionLocked(this, winTransit);
1607 }
1608 }
1609 changed = true;
1610 setDisplayLayoutNeeded();
1611 }
1612
1613 return changed;
1614 }
1615
1616 boolean onSetAppExiting() {
1617 final DisplayContent displayContent = getDisplayContent();
1618 boolean changed = false;
1619
1620 if (isVisibleNow()) {
1621 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
1622 //TODO (multidisplay): Magnification is supported only for the default
1623 if (mService.mAccessibilityController != null && isDefaultDisplay()) {
1624 mService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
1625 }
1626 changed = true;
1627 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001628 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001629 }
1630 }
1631
1632 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001633 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001634 changed |= c.onSetAppExiting();
1635 }
1636
1637 return changed;
1638 }
1639
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001640 @Override
1641 void onResize() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001642 // Some windows won't go through the resizing process, if they don't have a surface, so
1643 // destroy all saved surfaces here.
1644 destroySavedSurface();
1645
1646 final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
1647 if (mHasSurface && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001648 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001649 resizingWindows.add(this);
1650
1651 // If we are not drag resizing, force recreating of a new surface so updating
1652 // the content and positioning that surface will be in sync.
1653 //
1654 // As we use this flag as a hint to freeze surface boundary updates, we'd like to only
1655 // apply this to TYPE_BASE_APPLICATION, windows of TYPE_APPLICATION like dialogs, could
1656 // appear to not be drag resizing while they resize, but we'd still like to manipulate
1657 // their frame to update crop, etc...
1658 //
1659 // Anyway we don't need to synchronize position and content updates for these
1660 // windows since they aren't at the base layer and could be moved around anyway.
1661 if (!computeDragResizing() && mAttrs.type == TYPE_BASE_APPLICATION &&
Robert Carr8f0a3ad2017-02-15 19:30:28 -08001662 !mWinAnimator.isForceScaled() && !isGoneForLayoutLw() &&
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001663 !getTask().inPinnedWorkspace()) {
1664 setResizedWhileNotDragResizing(true);
1665 }
1666 }
1667 if (isGoneForLayoutLw()) {
1668 mResizedWhileGone = true;
1669 }
1670
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001671 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001672 }
1673
1674 void onUnfreezeBounds() {
1675 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001676 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001677 c.onUnfreezeBounds();
1678 }
1679
1680 if (!mHasSurface) {
1681 return;
1682 }
1683
1684 mLayoutNeeded = true;
1685 setDisplayLayoutNeeded();
1686 if (!mService.mResizingWindows.contains(this)) {
1687 mService.mResizingWindows.add(this);
1688 }
1689 }
1690
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001691 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001692 * If the window has moved due to its containing content frame changing, then notify the
1693 * listeners and optionally animate it. Simply checking a change of position is not enough,
1694 * because being move due to dock divider is not a trigger for animation.
1695 */
1696 void handleWindowMovedIfNeeded() {
1697 if (!hasMoved()) {
1698 return;
1699 }
1700
1701 // Frame has moved, containing content frame has also moved, and we're not currently
1702 // animating... let's do something.
1703 final int left = mFrame.left;
1704 final int top = mFrame.top;
1705 final Task task = getTask();
1706 final boolean adjustedForMinimizedDockOrIme = task != null
1707 && (task.mStack.isAdjustedForMinimizedDockedStack()
1708 || task.mStack.isAdjustedForIme());
Adrian Roose94c15c2017-05-09 13:17:54 -07001709 if (mService.okToAnimate()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001710 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1711 && !isDragResizing() && !adjustedForMinimizedDockOrIme
1712 && (task == null || getTask().mStack.hasMovementAnimations())
1713 && !mWinAnimator.mLastHidden) {
1714 mWinAnimator.setMoveAnimation(left, top);
1715 }
1716
1717 //TODO (multidisplay): Accessibility supported only for the default display.
1718 if (mService.mAccessibilityController != null
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001719 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001720 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
1721 }
1722
1723 try {
1724 mClient.moved(left, top);
1725 } catch (RemoteException e) {
1726 }
1727 mMovedByResize = false;
1728 }
1729
1730 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001731 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001732 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1733 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001734 private boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001735 return mHasSurface && (mContentChanged || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001736 && !mAnimatingExit
Chong Zhangbd0d9372015-12-28 15:18:29 -08001737 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001738 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001739 }
1740
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001741 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001742 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001743 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001744 return false;
1745 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001746 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001747 }
1748
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001749 boolean fillsDisplay() {
1750 final DisplayInfo displayInfo = getDisplayInfo();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001751 return mFrame.left <= 0 && mFrame.top <= 0
1752 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001753 }
1754
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001755 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001756 boolean isConfigChanged() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001757 return !mLastReportedConfiguration.equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001758 }
1759
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001760 void onWindowReplacementTimeout() {
1761 if (mWillReplaceWindow) {
1762 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001763 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001764 // delays removal on certain conditions, which will leave the stale window in the
1765 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1766 //
1767 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001768 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001769 } else {
1770 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001771 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001772 c.onWindowReplacementTimeout();
1773 }
1774 }
1775 }
1776
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001777 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001778 void forceWindowsScaleableInTransaction(boolean force) {
1779 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1780 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1781 }
1782
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001783 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001784 }
1785
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001786 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001787 void removeImmediately() {
1788 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001789
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001790 if (mRemoved) {
1791 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001792 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1793 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001794 return;
1795 }
1796
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001797 mRemoved = true;
1798
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001799 mWillReplaceWindow = false;
1800 if (mReplacementWindow != null) {
1801 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1802 }
1803
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001804 final DisplayContent dc = getDisplayContent();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001805 if (mService.mInputMethodTarget == this) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001806 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001807 }
1808
1809 final int type = mAttrs.type;
1810 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001811 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001812 }
1813 mPolicy.removeWindowLw(this);
1814
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001815 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001816
Craig Mautner96868332012-12-04 14:29:11 -08001817 mWinAnimator.destroyDeferredSurfaceLocked();
1818 mWinAnimator.destroySurfaceLocked();
Wale Ogunwale943002b2017-02-15 19:34:01 -08001819 mSession.windowRemovedLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001820 try {
1821 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1822 } catch (RuntimeException e) {
1823 // Ignore if it has already been removed (usually because
1824 // we are doing this as part of processing a death note.)
1825 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001826
1827 mService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001828 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001829
Wale Ogunwale571771c2016-08-26 13:18:50 -07001830 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001831 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001832 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001833 removeIfPossible(false /*keepVisibleDeadWindow*/);
1834 }
1835
Wale Ogunwale571771c2016-08-26 13:18:50 -07001836 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001837 mWindowRemovalAllowed = true;
1838 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1839 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1840
1841 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1842 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1843 "Starting window removed " + this);
1844
1845 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && this == mService.mCurrentFocus)
1846 Slog.v(TAG_WM, "Remove " + this + " client="
1847 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1848 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1849 + Debug.getCallers(5));
1850
1851 final long origId = Binder.clearCallingIdentity();
1852
1853 disposeInputChannel();
1854
1855 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1856 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1857 + " mAnimatingExit=" + mAnimatingExit
1858 + " mRemoveOnExit=" + mRemoveOnExit
1859 + " mHasSurface=" + mHasSurface
1860 + " surfaceShowing=" + mWinAnimator.getShown()
1861 + " isAnimationSet=" + mWinAnimator.isAnimationSet()
1862 + " app-animation="
1863 + (mAppToken != null ? mAppToken.mAppAnimator.animation : null)
1864 + " mWillReplaceWindow=" + mWillReplaceWindow
1865 + " inPendingTransaction="
1866 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
1867 + " mDisplayFrozen=" + mService.mDisplayFrozen
1868 + " callers=" + Debug.getCallers(6));
1869
1870 // Visibility of the removed window. Will be used later to update orientation later on.
1871 boolean wasVisible = false;
1872
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001873 final int displayId = getDisplayId();
1874
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001875 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1876 // window until the animation is done. If the display is frozen, just remove immediately,
1877 // since the animation wouldn't be seen.
Adrian Roose94c15c2017-05-09 13:17:54 -07001878 if (mHasSurface && mService.okToAnimate()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001879 if (mWillReplaceWindow) {
1880 // This window is going to be replaced. We need to keep it around until the new one
1881 // gets added, then we will get rid of this one.
1882 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1883 "Preserving " + this + " until the new one is " + "added");
1884 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1885 // been removed. We probably need another flag to indicate that window removal
1886 // should be deffered vs. overloading the flag that says we are playing an exit
1887 // animation.
1888 mAnimatingExit = true;
1889 mReplacingRemoveRequested = true;
1890 Binder.restoreCallingIdentity(origId);
1891 return;
1892 }
1893
1894 if (isAnimatingWithSavedSurface() && !mAppToken.allDrawnExcludingSaved) {
1895 // We started enter animation early with a saved surface, now the app asks to remove
1896 // this window. If we remove it now and the app is not yet drawn, we'll show a
1897 // flicker. Delay the removal now until it's really drawn.
1898 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
1899 "removeWindowLocked: delay removal of " + this + " due to early animation");
1900 // Do not set mAnimatingExit to true here, it will cause the surface to be hidden
1901 // immediately after the enter animation is done. If the app is not yet drawn then
1902 // it will show up as a flicker.
1903 setupWindowForRemoveOnExit();
1904 Binder.restoreCallingIdentity(origId);
1905 return;
1906 }
1907 // If we are not currently running the exit animation, we need to see about starting one
1908 wasVisible = isWinVisibleLw();
1909
1910 if (keepVisibleDeadWindow) {
1911 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1912 "Not removing " + this + " because app died while it's visible");
1913
1914 mAppDied = true;
1915 setDisplayLayoutNeeded();
1916 mService.mWindowPlacerLocked.performSurfacePlacement();
1917
1918 // Set up a replacement input channel since the app is now dead.
1919 // We need to catch tapping on the dead window to restart the app.
1920 openInputChannel(null);
1921 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
1922
1923 Binder.restoreCallingIdentity(origId);
1924 return;
1925 }
1926
1927 if (wasVisible) {
1928 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
1929
1930 // Try starting an animation.
1931 if (mWinAnimator.applyAnimationLocked(transit, false)) {
1932 mAnimatingExit = true;
1933 }
1934 //TODO (multidisplay): Magnification is supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001935 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001936 mService.mAccessibilityController.onWindowTransitionLocked(this, transit);
1937 }
1938 }
1939 final boolean isAnimating =
1940 mWinAnimator.isAnimationSet() && !mWinAnimator.isDummyAnimation();
1941 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001942 && mAppToken.isLastWindow(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001943 // We delay the removal of a window if it has a showing surface that can be used to run
1944 // exit animation and it is marked as exiting.
1945 // Also, If isn't the an animating starting window that is the last window in the app.
1946 // We allow the removal of the non-animating starting window now as there is no
1947 // additional window or animation that will trigger its removal.
1948 if (mWinAnimator.getShown() && mAnimatingExit
1949 && (!lastWindowIsStartingWindow || isAnimating)) {
1950 // The exit animation is running or should run... wait for it!
1951 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1952 "Not removing " + this + " due to exit animation ");
1953 setupWindowForRemoveOnExit();
1954 if (mAppToken != null) {
1955 mAppToken.updateReportedVisibilityLocked();
1956 }
1957 Binder.restoreCallingIdentity(origId);
1958 return;
1959 }
1960 }
1961
Wale Ogunwale571771c2016-08-26 13:18:50 -07001962 removeImmediately();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001963 // Removing a visible window will effect the computed orientation
1964 // So just update orientation if needed.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001965 if (wasVisible && mService.updateOrientationFromAppTokensLocked(false, displayId)) {
1966 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001967 }
1968 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
1969 Binder.restoreCallingIdentity(origId);
1970 }
1971
1972 private void setupWindowForRemoveOnExit() {
1973 mRemoveOnExit = true;
1974 setDisplayLayoutNeeded();
1975 // Request a focus update as this window's input channel is already gone. Otherwise
1976 // we could have no focused window in input manager.
1977 final boolean focusChanged = mService.updateFocusedWindowLocked(
1978 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
1979 mService.mWindowPlacerLocked.performSurfacePlacement();
1980 if (focusChanged) {
1981 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
1982 }
1983 }
1984
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001985 void setHasSurface(boolean hasSurface) {
1986 mHasSurface = hasSurface;
1987 }
1988
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001989 int getAnimLayerAdjustment() {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -08001990 if (mIsImWindow && mService.mInputMethodTarget != null) {
Wale Ogunwale455fac52016-07-21 07:24:49 -07001991 final AppWindowToken appToken = mService.mInputMethodTarget.mAppToken;
1992 if (appToken != null) {
Robert Carrdee1b3f2017-02-27 11:33:33 -08001993 return appToken.getAnimLayerAdjustment();
Wale Ogunwale455fac52016-07-21 07:24:49 -07001994 }
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001995 }
Wale Ogunwale455fac52016-07-21 07:24:49 -07001996
Robert Carrdee1b3f2017-02-27 11:33:33 -08001997 return mToken.getAnimLayerAdjustment();
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001998 }
1999
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002000 int getSpecialWindowAnimLayerAdjustment() {
2001 int specialAdjustment = 0;
2002 if (mIsImWindow) {
2003 specialAdjustment = getDisplayContent().mInputMethodAnimLayerAdjustment;
2004 } else if (mIsWallpaper) {
Wale Ogunwale0303c572016-10-20 10:16:29 -07002005 specialAdjustment = getDisplayContent().mWallpaperController.getAnimLayerAdjustment();
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002006 }
2007
2008 return mLayer + specialAdjustment;
2009 }
2010
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002011 boolean canBeImeTarget() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002012 if (mIsImWindow) {
2013 // IME windows can't be IME targets. IME targets are required to be below the IME
2014 // windows and that wouldn't be possible if the IME window is its own target...silly.
2015 return false;
2016 }
2017
Winson Chung3d0a74a2017-07-12 12:37:19 -07002018 final boolean windowsAreFocusable = mAppToken == null || mAppToken.windowsAreFocusable();
Winson Chungb1549342017-07-11 09:59:56 -07002019 if (!windowsAreFocusable) {
2020 // This window can't be an IME target if the app's windows should not be focusable.
2021 return false;
2022 }
2023
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002024 final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002025 final int type = mAttrs.type;
2026
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002027 // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are set or
2028 // both are cleared...and not a starting window.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002029 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
2030 && type != TYPE_APPLICATION_STARTING) {
2031 return false;
2032 }
2033
2034 if (DEBUG_INPUT_METHOD) {
2035 Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding());
2036 if (!isVisibleOrAdding()) {
2037 Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController
2038 + " relayoutCalled=" + mRelayoutCalled
2039 + " viewVis=" + mViewVisibility
2040 + " policyVis=" + mPolicyVisibility
2041 + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim
2042 + " parentHidden=" + isParentWindowHidden()
2043 + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
2044 if (mAppToken != null) {
2045 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + mAppToken.hiddenRequested);
2046 }
2047 }
2048 }
2049 return isVisibleOrAdding();
2050 }
2051
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002052 void scheduleAnimationIfDimming() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002053 final DisplayContent dc = getDisplayContent();
2054 if (dc == null) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002055 return;
2056 }
Jorim Jaggi1f833082017-08-04 18:06:56 +02002057
2058 // If layout is currently deferred, we want to hold of with updating the layers.
2059 if (mService.mWindowPlacerLocked.isLayoutDeferred()) {
2060 return;
2061 }
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002062 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002063 if (dimLayerUser != null && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator)) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002064 // Force an animation pass just to update the mDimLayer layer.
2065 mService.scheduleAnimationLocked();
2066 }
2067 }
2068
Chong Zhangacf11402015-11-04 16:23:10 -08002069 private final class DeadWindowEventReceiver extends InputEventReceiver {
2070 DeadWindowEventReceiver(InputChannel inputChannel) {
2071 super(inputChannel, mService.mH.getLooper());
2072 }
2073 @Override
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -07002074 public void onInputEvent(InputEvent event, int displayId) {
Chong Zhangacf11402015-11-04 16:23:10 -08002075 finishInputEvent(event, true);
2076 }
2077 }
2078 /**
2079 * Dummy event receiver for windows that died visible.
2080 */
2081 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2082
Chong Zhang112eb8c2015-11-02 11:17:00 -08002083 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002084 if (mInputChannel != null) {
2085 throw new IllegalStateException("Window already has an input channel.");
2086 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002087 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002088 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2089 mInputChannel = inputChannels[0];
2090 mClientChannel = inputChannels[1];
2091 mInputWindowHandle.inputChannel = inputChannels[0];
2092 if (outInputChannel != null) {
2093 mClientChannel.transferTo(outInputChannel);
2094 mClientChannel.dispose();
2095 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002096 } else {
2097 // If the window died visible, we setup a dummy input channel, so that taps
2098 // can still detected by input monitor channel, and we can relaunch the app.
2099 // Create dummy event receiver that simply reports all events as handled.
2100 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002101 }
2102 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002103 }
2104
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002105 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002106 if (mDeadWindowEventReceiver != null) {
2107 mDeadWindowEventReceiver.dispose();
2108 mDeadWindowEventReceiver = null;
2109 }
2110
2111 // unregister server channel first otherwise it complains about broken channel
2112 if (mInputChannel != null) {
2113 mService.mInputManager.unregisterInputChannel(mInputChannel);
2114 mInputChannel.dispose();
2115 mInputChannel = null;
2116 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002117 if (mClientChannel != null) {
2118 mClientChannel.dispose();
2119 mClientChannel = null;
2120 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07002121 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002122 }
2123
Chong Zhang112eb8c2015-11-02 11:17:00 -08002124 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08002125 // When the app is terminated (eg. from Recents), the task might have already been
2126 // removed with the window pending removal. Don't apply dim in such cases, as there
2127 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
2128 final AppWindowToken token = mAppToken;
2129 if (token != null && token.removed) {
2130 return;
2131 }
2132
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002133 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002134 if (!mAnimatingExit && mAppDied) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08002135 // If app died visible, apply a dim over the window to indicate that it's inactive
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002136 dc.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002137 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02002138 && dc != null && !mAnimatingExit && isVisible()) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002139 dc.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07002140 }
2141 }
2142
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002143 private DimLayer.DimLayerUser getDimLayerUser() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002144 Task task = getTask();
2145 if (task != null) {
2146 return task;
2147 }
2148 return getStack();
2149 }
2150
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002151 /** Returns true if the replacement window was removed. */
2152 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2153 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2154 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2155 removeReplacedWindow();
2156 return true;
2157 }
2158
2159 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002160 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002161 if (c.removeReplacedWindowIfNeeded(replacement)) {
2162 return true;
2163 }
2164 }
2165 return false;
2166 }
2167
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002168 private void removeReplacedWindow() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002169 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
2170 if (isDimming()) {
2171 transferDimToReplacement();
Robert Carra1eb4392015-12-10 12:43:51 -08002172 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002173 mWillReplaceWindow = false;
2174 mAnimateReplacingWindow = false;
2175 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002176 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002177 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002178 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002179 }
2180 }
2181
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002182 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2183 boolean replacementSet = false;
2184
2185 if (mWillReplaceWindow && mReplacementWindow == null
2186 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2187
2188 mReplacementWindow = replacementCandidate;
2189 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2190 replacementSet = true;
2191 }
2192
2193 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002194 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002195 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2196 }
2197
2198 return replacementSet;
2199 }
2200
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002201 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002202 final DisplayContent dc = getDisplayContent();
2203 if (dc != null) {
2204 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002205 }
2206 }
2207
Robert Carrfed10072016-05-26 11:48:49 -07002208 // TODO: Strange usage of word workspace here and above.
2209 boolean inPinnedWorkspace() {
2210 final Task task = getTask();
2211 return task != null && task.inPinnedWorkspace();
2212 }
2213
Chong Zhang5117e272016-05-03 12:47:34 -07002214 void applyAdjustForImeIfNeeded() {
2215 final Task task = getTask();
2216 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2217 task.mStack.applyAdjustForImeIfNeeded(task);
2218 }
2219 }
2220
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002221 @Override
2222 void switchUser() {
2223 super.switchUser();
2224 if (isHiddenFromUserLocked()) {
2225 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2226 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
2227 hideLw(false);
2228 }
2229 }
2230
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002231 int getTouchableRegion(Region region, int flags) {
2232 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002233 if (modal && mAppToken != null) {
2234 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002235 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002236 // If this is a modal window we need to dismiss it if it's not full screen and the
2237 // touch happens outside of the frame that displays the content. This means we
2238 // need to intercept touches outside of that window. The dim layer user
2239 // associated with the window (task or stack) will give us the good bounds, as
2240 // they would be used to display the dim layer.
2241 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
2242 if (dimLayerUser != null) {
2243 dimLayerUser.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002244 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002245 getVisibleBounds(mTmpRect);
2246 }
2247 if (inFreeformWorkspace()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002248 // For freeform windows we the touch region to include the whole surface for the
2249 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002250 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2251 final int delta = WindowManagerService.dipToPixel(
2252 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2253 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002254 }
2255 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002256 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002257 } else {
2258 // Not modal or full screen modal
2259 getTouchableRegion(region);
2260 }
2261 return flags;
2262 }
2263
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002264 void checkPolicyVisibilityChange() {
2265 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2266 if (DEBUG_VISIBILITY) {
2267 Slog.v(TAG, "Policy visibility changing after anim in " +
2268 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2269 }
2270 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08002271 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002272 if (!mPolicyVisibility) {
2273 if (mService.mCurrentFocus == this) {
2274 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2275 "setAnimationLocked: setting mFocusMayChange true");
2276 mService.mFocusMayChange = true;
2277 }
2278 // Window is no longer visible -- make sure if we were waiting
2279 // for it to be displayed before enabling the display, that
2280 // we allow the display to be enabled now.
2281 mService.enableScreenIfNeededLocked();
2282 }
2283 }
2284 }
2285
2286 void setRequestedSize(int requestedWidth, int requestedHeight) {
2287 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2288 mLayoutNeeded = true;
2289 mRequestedWidth = requestedWidth;
2290 mRequestedHeight = requestedHeight;
2291 }
2292 }
2293
Bryce Leef858b572017-06-29 14:03:33 -07002294 void prepareWindowToDisplayDuringRelayout(boolean wasVisible) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002295 // We need to turn on screen regardless of visibility.
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002296 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
2297 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
2298 mTurnOnScreen = true;
2299 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002300
2301 // If we were already visible, skip rest of preparation.
2302 if (wasVisible) {
2303 if (DEBUG_VISIBILITY) Slog.v(TAG,
2304 "Already visible and does not turn on screen, skip preparing: " + this);
2305 return;
2306 }
2307
2308 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2309 == SOFT_INPUT_ADJUST_RESIZE) {
2310 mLayoutNeeded = true;
2311 }
2312
Adrian Roose94c15c2017-05-09 13:17:54 -07002313 if (isDrawnLw() && mService.okToAnimate()) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002314 mWinAnimator.applyEnterAnimationLocked();
2315 }
Bryce Leef858b572017-06-29 14:03:33 -07002316 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002317
Bryce Leef858b572017-06-29 14:03:33 -07002318 void getMergedConfiguration(MergedConfiguration outConfiguration) {
2319 final Configuration globalConfig = mService.mRoot.getConfiguration();
2320 final Configuration overrideConfig = getMergedOverrideConfiguration();
2321 outConfiguration.setConfiguration(globalConfig, overrideConfig);
2322 }
2323
2324 void setReportedConfiguration(MergedConfiguration config) {
2325 mLastReportedConfiguration.setTo(config.getMergedConfiguration());
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002326 }
2327
2328 void adjustStartingWindowFlags() {
2329 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2330 && mAppToken.startingWindow != null) {
2331 // Special handling of starting window over the base
2332 // window of the app: propagate lock screen flags to it,
2333 // to provide the correct semantics while starting.
2334 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2335 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2336 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2337 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2338 }
2339 }
2340
2341 void setWindowScale(int requestedWidth, int requestedHeight) {
2342 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2343
2344 if (scaledWindow) {
2345 // requested{Width|Height} Surface's physical size
2346 // attrs.{width|height} Size on screen
2347 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2348 mHScale = (mAttrs.width != requestedWidth) ?
2349 (mAttrs.width / (float)requestedWidth) : 1.0f;
2350 mVScale = (mAttrs.height != requestedHeight) ?
2351 (mAttrs.height / (float)requestedHeight) : 1.0f;
2352 } else {
2353 mHScale = mVScale = 1;
2354 }
2355 }
2356
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002357 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002358 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002359 public void binderDied() {
2360 try {
2361 synchronized(mService.mWindowMap) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002362 final WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002363 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002364 if (win != null) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002365 final DisplayContent dc = getDisplayContent();
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002366 if (win.mAppToken != null && win.mAppToken.findMainWindow() == win) {
2367 mService.mTaskSnapshotController.onAppDied(win.mAppToken);
2368 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002369 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002370 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2371 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002372 // just in case they have the divider at an unstable position. Better
2373 // also reset drag resizing state, because the owner can't do it
2374 // anymore.
Wale Ogunwale1666e312016-12-16 11:27:18 -08002375 final TaskStack stack = dc.getDockedStackIgnoringVisibility();
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002376 if (stack != null) {
2377 stack.resetDockedStackToMiddle();
2378 }
Jorim Jaggidcb68142016-02-09 21:51:30 -08002379 mService.setDockedStackResizing(false);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002380 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002381 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002382 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002383 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002384 }
2385 }
2386 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002387 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002388 }
2389 }
2390 }
2391
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002392 /**
2393 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2394 * because we want to preserve its location on screen to be re-activated later when the user
2395 * interacts with it.
2396 */
2397 boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwale89973222017-04-23 18:39:45 -07002398 if (!isWinVisibleLw() || mAppToken == null || mAppToken.isClientHidden()) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002399 // Not a visible app window or the app isn't dead.
2400 return false;
2401 }
2402
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002403 if (mAttrs.token != mClient.asBinder()) {
2404 // The window was add by a client using another client's app token. We don't want to
2405 // keep the dead window around for this case since this is meant for 'real' apps.
2406 return false;
2407 }
2408
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002409 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2410 // We don't keep starting windows since they were added by the window manager before
2411 // the app even launched.
2412 return false;
2413 }
2414
2415 final TaskStack stack = getStack();
2416 return stack != null && StackId.keepVisibleDeadAppWindowOnScreen(stack.mStackId);
2417 }
2418
Wale Ogunwaled045c822015-12-02 09:14:28 -08002419 /** @return true if this window desires key events. */
2420 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002421 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002422 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002423 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002424 && (mAppToken == null || mAppToken.windowsAreFocusable())
Matthew Nge15352e2016-12-20 15:36:29 -08002425 && !canReceiveTouchInput();
2426 }
2427
2428 /** @return true if this window desires touch events. */
2429 boolean canReceiveTouchInput() {
Bryce Lee6d410262017-02-28 15:30:17 -08002430 return mAppToken != null && mAppToken.getTask() != null
2431 && mAppToken.getTask().mStack.shouldIgnoreInput();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002432 }
2433
Craig Mautner749a7bb2012-04-02 13:49:53 -07002434 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002435 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002436 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002437 }
2438
Craig Mautner749a7bb2012-04-02 13:49:53 -07002439 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002440 public boolean showLw(boolean doAnimation) {
2441 return showLw(doAnimation, true);
2442 }
2443
2444 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002445 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002446 return false;
2447 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002448 if (!mAppOpVisibility) {
2449 // Being hidden due to app op request.
2450 return false;
2451 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002452 if (mPermanentlyHidden) {
2453 // Permanently hidden until the app exists as apps aren't prepared
2454 // to handle their windows being removed from under them.
2455 return false;
2456 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002457 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002458 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002459 return false;
2460 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002461 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002462 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002463 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07002464 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Adrian Roose94c15c2017-05-09 13:17:54 -07002465 if (!mService.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002466 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07002467 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002468 // Check for the case where we are currently visible and
2469 // not animating; we do not want to do animation at such a
2470 // point to become visible when we already are.
2471 doAnimation = false;
2472 }
2473 }
2474 mPolicyVisibility = true;
2475 mPolicyVisibilityAfterAnim = true;
2476 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002477 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002478 }
2479 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002480 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002481 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002482 if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) {
2483 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2484 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002485 return true;
2486 }
2487
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002488 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002489 public boolean hideLw(boolean doAnimation) {
2490 return hideLw(doAnimation, true);
2491 }
2492
2493 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2494 if (doAnimation) {
Adrian Roose94c15c2017-05-09 13:17:54 -07002495 if (!mService.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002496 doAnimation = false;
2497 }
2498 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002499 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002500 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002501 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002502 return false;
2503 }
2504 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002505 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07002506 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002507 doAnimation = false;
2508 }
2509 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002510 mPolicyVisibilityAfterAnim = false;
2511 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002512 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002513 mPolicyVisibility = false;
2514 // Window is no longer visible -- make sure if we were waiting
2515 // for it to be displayed before enabling the display, that
2516 // we allow the display to be enabled now.
2517 mService.enableScreenIfNeededLocked();
2518 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002519 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002520 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002521 mService.mFocusMayChange = true;
2522 }
2523 }
2524 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002525 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002526 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002527 if (mService.mCurrentFocus == this) {
2528 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2529 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002530 return true;
2531 }
2532
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002533 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002534 if (mAppOpVisibility != state) {
2535 mAppOpVisibility = state;
2536 if (state) {
2537 // If the policy visibility had last been to hide, then this
2538 // will incorrectly show at this point since we lost that
2539 // information. Not a big deal -- for the windows that have app
2540 // ops modifies they should only be hidden by policy due to the
2541 // lock screen, and the user won't be changing this if locked.
2542 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002543 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002544 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002545 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002546 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002547 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002548 }
2549
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002550 public void hidePermanentlyLw() {
2551 if (!mPermanentlyHidden) {
2552 mPermanentlyHidden = true;
2553 hideLw(true, true);
2554 }
2555 }
2556
Jeff Brownc2932a12014-11-20 18:04:05 -08002557 public void pokeDrawLockLw(long timeout) {
2558 if (isVisibleOrAdding()) {
2559 if (mDrawLock == null) {
2560 // We want the tag name to be somewhat stable so that it is easier to correlate
2561 // in wake lock statistics. So in particular, we don't want to include the
2562 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002563 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08002564 mDrawLock = mService.mPowerManager.newWakeLock(
2565 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
2566 mDrawLock.setReferenceCounted(false);
2567 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2568 }
2569 // Each call to acquire resets the timeout.
2570 if (DEBUG_POWER) {
2571 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2572 + mAttrs.packageName);
2573 }
2574 mDrawLock.acquire(timeout);
2575 } else if (DEBUG_POWER) {
2576 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2577 + "owned by " + mAttrs.packageName);
2578 }
2579 }
2580
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002581 @Override
2582 public boolean isAlive() {
2583 return mClient.asBinder().isBinderAlive();
2584 }
2585
Craig Mautnera987d432012-10-11 14:07:58 -07002586 boolean isClosing() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002587 return mAnimatingExit || (mService.mClosingApps.contains(mAppToken));
Craig Mautnera987d432012-10-11 14:07:58 -07002588 }
2589
Chong Zhangbef461f2015-10-27 11:38:24 -07002590 boolean isAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002591 return mAnimatingWithSavedSurface;
2592 }
2593
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002594 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002595 boolean isAnimating() {
2596 if (mWinAnimator.isAnimationSet() || mAnimatingExit) {
2597 return true;
2598 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002599 return super.isAnimating();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002600 }
2601
Chong Zhang8e4bda92016-05-04 15:08:18 -07002602 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002603 if (mAnimatingWithSavedSurface
2604 && (mViewVisibility != View.VISIBLE || mWindowRemovalAllowed)) {
2605 return true;
2606 }
2607 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002608 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002609 if (c.isAnimatingInvisibleWithSavedSurface()) {
2610 return true;
2611 }
2612 }
2613 return false;
2614 }
2615
2616 void stopUsingSavedSurface() {
2617 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002618 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002619 c.stopUsingSavedSurface();
2620 }
2621
2622 if (!isAnimatingInvisibleWithSavedSurface()) {
2623 return;
2624 }
2625
2626 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG, "stopUsingSavedSurface: " + this);
2627 clearAnimatingWithSavedSurface();
2628 mDestroying = true;
2629 mWinAnimator.hide("stopUsingSavedSurface");
Wale Ogunwale0303c572016-10-20 10:16:29 -07002630 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002631 }
2632
2633 void markSavedSurfaceExiting() {
2634 if (isAnimatingInvisibleWithSavedSurface()) {
2635 mAnimatingExit = true;
2636 mWinAnimator.mAnimating = true;
2637 }
2638 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002639 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002640 c.markSavedSurfaceExiting();
2641 }
2642 }
2643
2644 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2645 animators.add(mWinAnimator);
2646
2647 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002648 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002649 c.addWinAnimatorToList(animators);
2650 }
2651 }
2652
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002653 void sendAppVisibilityToClients() {
2654 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002655
Wale Ogunwale89973222017-04-23 18:39:45 -07002656 final boolean clientHidden = mAppToken.isClientHidden();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002657 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2658 // Don't hide the starting window.
2659 return;
2660 }
2661
Wale Ogunwale89973222017-04-23 18:39:45 -07002662 if (clientHidden) {
2663 // Once we are notifying the client that it's visibility has changed, we need to prevent
2664 // it from destroying child surfaces until the animation has finished. We do this by
2665 // detaching any surface control the client added from the client.
2666 for (int i = mChildren.size() - 1; i >= 0; --i) {
2667 final WindowState c = mChildren.get(i);
2668 c.mWinAnimator.detachChildren();
2669 }
2670
2671 mWinAnimator.detachChildren();
2672 }
2673
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002674 try {
2675 if (DEBUG_VISIBILITY) Slog.v(TAG,
2676 "Setting visibility of " + this + ": " + (!clientHidden));
2677 mClient.dispatchAppVisibility(!clientHidden);
2678 } catch (RemoteException e) {
2679 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002680 }
2681
Chong Zhang92147042016-05-09 12:47:11 -07002682 public void setVisibleBeforeClientHidden() {
2683 mWasVisibleBeforeClientHidden |=
2684 (mViewVisibility == View.VISIBLE || mAnimatingWithSavedSurface);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002685
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002686 super.setVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -07002687 }
2688
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002689 public void clearWasVisibleBeforeClientHidden() {
Chong Zhang92147042016-05-09 12:47:11 -07002690 mWasVisibleBeforeClientHidden = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002691 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002692 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002693 c.clearWasVisibleBeforeClientHidden();
2694 }
Chong Zhang92147042016-05-09 12:47:11 -07002695 }
2696
2697 public boolean wasVisibleBeforeClientHidden() {
2698 return mWasVisibleBeforeClientHidden;
Chong Zhangbef461f2015-10-27 11:38:24 -07002699 }
2700
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002701 void onStartFreezingScreen() {
2702 mAppFreezing = true;
2703 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002704 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002705 c.onStartFreezingScreen();
2706 }
2707 }
2708
2709 boolean onStopFreezingScreen() {
2710 boolean unfrozeWindows = false;
2711 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002712 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002713 unfrozeWindows |= c.onStopFreezingScreen();
2714 }
2715
2716 if (!mAppFreezing) {
2717 return unfrozeWindows;
2718 }
2719
Wale Ogunwale953171d2016-09-30 09:17:30 -07002720 mAppFreezing = false;
2721
Bryce Lee8c3cf382017-07-06 19:47:10 -07002722 if (mHasSurface && !getOrientationChanging()
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002723 && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
2724 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
Bryce Lee8c3cf382017-07-06 19:47:10 -07002725 setOrientationChanging(true);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002726 mService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002727 }
2728 mLastFreezeDuration = 0;
2729 setDisplayLayoutNeeded();
2730 return true;
2731 }
2732
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002733 private boolean shouldSaveSurface() {
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002734 if (mWinAnimator.mSurfaceController == null) {
2735 // Don't bother if the surface controller is gone for any reason.
2736 return false;
2737 }
2738
Chong Zhang92147042016-05-09 12:47:11 -07002739 if (!mWasVisibleBeforeClientHidden) {
2740 return false;
2741 }
2742
Wale Ogunwale945d1972016-03-23 13:16:41 -07002743 if ((mAttrs.flags & FLAG_SECURE) != 0) {
2744 // We don't save secure surfaces since their content shouldn't be shown while the app
2745 // isn't on screen and content might leak through during the transition animation with
2746 // saved surface.
2747 return false;
2748 }
2749
Jorim Jaggi02886a82016-12-06 09:10:06 -08002750 if (isLowRamDeviceStatic()) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002751 // Don't save surfaces on Svelte devices.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002752 return false;
2753 }
2754
Jorim Jaggiab7ad382016-10-26 18:22:04 -07002755 final Task task = getTask();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002756 final AppWindowToken taskTop = task.getTopVisibleAppToken();
2757 if (taskTop != null && taskTop != mAppToken) {
2758 // Don't save if the window is not the topmost window.
2759 return false;
2760 }
2761
Jorim Jaggi8fa45222016-02-19 19:54:39 -08002762 if (mResizedWhileGone) {
2763 // Somebody resized our window while we were gone for layout, which means that the
2764 // client got an old size, so we have an outdated surface here.
2765 return false;
2766 }
2767
Robert Carr7098dbd2016-02-01 12:31:01 -08002768 if (DEBUG_DISABLE_SAVING_SURFACES) {
2769 return false;
2770 }
2771
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002772 return mAppToken.shouldSaveSurface();
2773 }
2774
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002775 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2776 boolean destroyedSomething = false;
2777 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002778 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002779 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2780 }
2781
Robert Carrdb2f6e62017-03-01 20:17:58 -08002782 if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) {
2783 return destroyedSomething;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002784 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08002785
2786 if (appStopped || mWindowRemovalAllowed) {
2787 mWinAnimator.destroyPreservedSurfaceLocked();
2788 }
2789
2790 if (mDestroying) {
2791 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2792 + " destroySurfaces: appStopped=" + appStopped
2793 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2794 + " win.mRemoveOnExit=" + mRemoveOnExit);
2795 if (!cleanupOnResume || mRemoveOnExit) {
Robert Carr89a28ab2017-04-24 15:33:11 -07002796 destroyOrSaveSurfaceUnchecked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08002797 }
2798 if (mRemoveOnExit) {
2799 removeImmediately();
2800 }
2801 if (cleanupOnResume) {
2802 requestUpdateWallpaperIfNeeded();
2803 }
2804 mDestroying = false;
2805 destroyedSomething = true;
2806 }
2807
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002808 return destroyedSomething;
2809 }
Chris Craik3131bde2016-05-06 13:39:08 -07002810
Robert Carr89a28ab2017-04-24 15:33:11 -07002811 // Destroy or save the application surface without checking
2812 // various indicators of whether the client has released the surface.
2813 // This is in general unsafe, and most callers should use {@link #destroySurface}
2814 void destroyOrSaveSurfaceUnchecked() {
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002815 mSurfaceSaved = shouldSaveSurface();
2816 if (mSurfaceSaved) {
2817 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2818 Slog.v(TAG, "Saving surface: " + this);
2819 }
Chris Craik3131bde2016-05-06 13:39:08 -07002820 // Previous user of the surface may have set a transparent region signaling a portion
2821 // doesn't need to be composited, so reset to default empty state.
2822 mSession.setTransparentRegion(mClient, sEmptyRegion);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002823
2824 mWinAnimator.hide("saved surface");
2825 mWinAnimator.mDrawState = WindowStateAnimator.NO_SURFACE;
2826 setHasSurface(false);
Chong Zhang47e36a32016-02-29 16:44:33 -08002827 // The client should have disconnected at this point, but if it doesn't,
2828 // we need to make sure it's disconnected. Otherwise when we reuse the surface
2829 // the client can't reconnect to the buffer queue, and rendering will fail.
2830 if (mWinAnimator.mSurfaceController != null) {
2831 mWinAnimator.mSurfaceController.disconnectInTransaction();
2832 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002833 mAnimatingWithSavedSurface = false;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002834 } else {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002835 mWinAnimator.destroySurfaceLocked();
2836 }
Chong Zhang92147042016-05-09 12:47:11 -07002837 // Clear animating flags now, since the surface is now gone. (Note this is true even
2838 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2839 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002840 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002841
Chong Zhang92147042016-05-09 12:47:11 -07002842 void destroySavedSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002843 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002844 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002845 c.destroySavedSurface();
2846 }
2847
Robert Carr13f7be9e2015-12-02 18:39:45 -08002848 if (mSurfaceSaved) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002849 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, "Destroying saved surface: " + this);
Robert Carr13f7be9e2015-12-02 18:39:45 -08002850 mWinAnimator.destroySurfaceLocked();
Robert Carr237028a2016-07-26 10:39:45 -07002851 mSurfaceSaved = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002852 }
Chong Zhang92147042016-05-09 12:47:11 -07002853 mWasVisibleBeforeClientHidden = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002854 }
2855
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002856 /** Returns -1 if there are no interesting windows or number of interesting windows not drawn.*/
2857 int restoreSavedSurfaceForInterestingWindow() {
2858 int interestingNotDrawn = -1;
2859 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002860 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002861 final int childInterestingNotDrawn = c.restoreSavedSurfaceForInterestingWindow();
2862 if (childInterestingNotDrawn != -1) {
2863 if (interestingNotDrawn == -1) {
2864 interestingNotDrawn = childInterestingNotDrawn;
2865 } else {
2866 interestingNotDrawn += childInterestingNotDrawn;
2867 }
2868 }
Chong Zhang4113ffa2016-02-18 12:39:13 -08002869 }
Robert Carr237028a2016-07-26 10:39:45 -07002870
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002871 if (mAttrs.type == TYPE_APPLICATION_STARTING
2872 || mAppDied || !wasVisibleBeforeClientHidden()
2873 || (mAppToken.mAppAnimator.freezingScreen && mAppFreezing)) {
2874 // Window isn't interesting...
2875 return interestingNotDrawn;
2876 }
2877
2878 restoreSavedSurface();
2879
2880 if (!isDrawnLw()) {
2881 if (interestingNotDrawn == -1) {
2882 interestingNotDrawn = 1;
2883 } else {
2884 interestingNotDrawn++;
2885 }
2886 }
2887 return interestingNotDrawn;
2888 }
2889
2890 /** Returns true if the saved surface was restored. */
2891 boolean restoreSavedSurface() {
2892 if (!mSurfaceSaved) {
2893 return false;
2894 }
2895
2896 // Sometimes we save surfaces due to layout invisible directly after rotation occurs.
2897 // However this means the surface was never laid out in the new orientation.
2898 // We can only restore to the last rotation we were laid out as visible in.
Andrii Kulian8ee72852017-03-10 10:36:45 -08002899 if (mLastVisibleLayoutRotation != getDisplayContent().getRotation()) {
Robert Carr237028a2016-07-26 10:39:45 -07002900 destroySavedSurface();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002901 return false;
Robert Carr237028a2016-07-26 10:39:45 -07002902 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002903 mSurfaceSaved = false;
Robert Carr237028a2016-07-26 10:39:45 -07002904
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002905 if (mWinAnimator.mSurfaceController != null) {
2906 setHasSurface(true);
Wale Ogunwale9d147902016-07-16 11:58:55 -07002907 mWinAnimator.mDrawState = READY_TO_SHOW;
Chong Zhang92147042016-05-09 12:47:11 -07002908 mAnimatingWithSavedSurface = true;
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002909
Chong Zhang6e9872b2016-08-17 10:19:05 -07002910 requestUpdateWallpaperIfNeeded();
2911
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002912 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2913 Slog.v(TAG, "Restoring saved surface: " + this);
2914 }
2915 } else {
2916 // mSurfaceController shouldn't be null if mSurfaceSaved was still true at
2917 // this point. Even if we destroyed the saved surface because of rotation
2918 // or resize, mSurfaceSaved flag should have been cleared. So this is a wtf.
2919 Slog.wtf(TAG, "Failed to restore saved surface: surface gone! " + this);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002920 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002921
2922 return true;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002923 }
2924
Chong Zhang92147042016-05-09 12:47:11 -07002925 boolean canRestoreSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002926 if (mWasVisibleBeforeClientHidden && mSurfaceSaved) {
2927 return true;
2928 }
2929
2930 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002931 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002932 if (c.canRestoreSurface()) {
2933 return true;
2934 }
2935 }
2936
2937 return false;
Chong Zhang92147042016-05-09 12:47:11 -07002938 }
2939
2940 boolean hasSavedSurface() {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002941 return mSurfaceSaved;
2942 }
2943
Chong Zhang92147042016-05-09 12:47:11 -07002944 void clearHasSavedSurface() {
2945 mSurfaceSaved = false;
2946 mAnimatingWithSavedSurface = false;
Chong Zhangf58631a2016-05-24 16:02:10 -07002947 if (mWasVisibleBeforeClientHidden) {
2948 mAppToken.destroySavedSurfaces();
2949 }
Chong Zhang92147042016-05-09 12:47:11 -07002950 }
2951
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002952 boolean clearAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002953 if (mAnimatingWithSavedSurface) {
2954 // App has drawn something to its windows, we're no longer animating with
2955 // the saved surfaces.
2956 if (DEBUG_ANIM) Slog.d(TAG,
2957 "clearAnimatingWithSavedSurface(): win=" + this);
2958 mAnimatingWithSavedSurface = false;
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002959 return true;
Chong Zhang92147042016-05-09 12:47:11 -07002960 }
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002961 return false;
Chong Zhang92147042016-05-09 12:47:11 -07002962 }
2963
Craig Mautner69b08182012-09-05 13:07:13 -07002964 @Override
2965 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002966 final DisplayContent displayContent = getDisplayContent();
2967 if (displayContent == null) {
2968 // Only a window that was on a non-default display can be detached from it.
2969 return false;
2970 }
Winson Chung47a3e652014-05-21 16:03:42 -07002971 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002972 }
2973
Adrian Rooscd3884d2015-02-18 17:25:23 +01002974 @Override
2975 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002976 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002977 final DisplayContent dc = getDisplayContent();
2978 return dimLayerUser != null && dc != null
2979 && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01002980 }
2981
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002982 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07002983 mShowToOwnerOnly = showToOwnerOnly;
2984 }
2985
Wale Ogunwaleea92d972016-12-08 07:33:13 -08002986 private boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002987 // Child windows are evaluated based on their parent window.
2988 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002989 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale72919d22016-12-08 18:58:50 -08002990 && win.mAppToken != null && win.mAppToken.mShowForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002991
2992 // All window frames that are fullscreen extend above status bar, but some don't extend
2993 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2994 // bottom right.
2995 if (win.mFrame.left <= win.mDisplayFrame.left
2996 && win.mFrame.top <= win.mDisplayFrame.top
2997 && win.mFrame.right >= win.mStableFrame.right
2998 && win.mFrame.bottom >= win.mStableFrame.bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002999 // Is a fullscreen window, like the clock alarm. Show to everyone.
3000 return false;
3001 }
3002 }
3003
Craig Mautner341220f2012-10-16 15:20:09 -07003004 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01003005 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07003006 }
3007
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003008 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
3009 outRegion.set(
3010 frame.left + inset.left, frame.top + inset.top,
3011 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04003012 }
3013
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003014 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003015 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003016 switch (mTouchableInsets) {
3017 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003018 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003019 outRegion.set(frame);
3020 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003021 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003022 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003023 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003024 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003025 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003026 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003027 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003028 outRegion.set(mGivenTouchableRegion);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003029 outRegion.translate(frame.left, frame.top);
3030 break;
3031 }
3032 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003033 cropRegionToStackBoundsIfNeeded(outRegion);
3034 }
3035
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003036 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08003037 final Task task = getTask();
3038 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003039 return;
3040 }
3041
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08003042 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003043 if (stack == null) {
3044 return;
3045 }
3046
3047 stack.getDimBounds(mTmpRect);
3048 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003049 }
3050
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003051 /**
3052 * Report a focus change. Must be called with no locks held, and consistently
3053 * from the same serialized thread (such as dispatched from a handler).
3054 */
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07003055 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003056 try {
3057 mClient.windowFocusChanged(focused, inTouchMode);
3058 } catch (RemoteException e) {
3059 }
3060 if (mFocusCallbacks != null) {
3061 final int N = mFocusCallbacks.beginBroadcast();
3062 for (int i=0; i<N; i++) {
3063 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
3064 try {
3065 if (focused) {
3066 obs.focusGained(mWindowId.asBinder());
3067 } else {
3068 obs.focusLost(mWindowId.asBinder());
3069 }
3070 } catch (RemoteException e) {
3071 }
3072 }
3073 mFocusCallbacks.finishBroadcast();
3074 }
3075 }
3076
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003077 @Override
3078 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003079 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003080 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003081 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003082
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003083 return super.getConfiguration();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003084 }
3085
Craig Mautnerdf88d732014-01-27 09:21:32 -08003086 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003087 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08003088 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003089 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
3090 + ": " + mCompatFrame);
Bryce Leef858b572017-06-29 14:03:33 -07003091 final MergedConfiguration mergedConfiguration =
3092 new MergedConfiguration(mService.mRoot.getConfiguration(),
3093 getMergedOverrideConfiguration());
3094
3095 setReportedConfiguration(mergedConfiguration);
3096
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003097 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003098 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
3099
Craig Mautnerdf88d732014-01-27 09:21:32 -08003100 final Rect frame = mFrame;
3101 final Rect overscanInsets = mLastOverscanInsets;
3102 final Rect contentInsets = mLastContentInsets;
3103 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07003104 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003105 final Rect outsets = mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003106 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003107 final boolean reportOrientation = mReportOrientationChanged;
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003108 final int displayId = getDisplayId();
Chet Haase8eb48d22014-09-24 07:31:29 -07003109 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
3110 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08003111 // To prevent deadlock simulate one-way call if win.mClient is a local object.
3112 mService.mH.post(new Runnable() {
3113 @Override
3114 public void run() {
3115 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003116 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003117 stableInsets, outsets, reportDraw, mergedConfiguration,
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003118 reportOrientation, displayId);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003119 } catch (RemoteException e) {
3120 // Not a remote call, RemoteException won't be raised.
3121 }
3122 }
3123 });
3124 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003125 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003126 outsets, reportDraw, mergedConfiguration, reportOrientation, displayId);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003127 }
Svetoslav4604abc2014-06-10 18:59:30 -07003128
3129 //TODO (multidisplay): Accessibility supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07003130 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07003131 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07003132 }
3133
Craig Mautnerdf88d732014-01-27 09:21:32 -08003134 mOverscanInsetsChanged = false;
3135 mContentInsetsChanged = false;
3136 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07003137 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003138 mOutsetsChanged = false;
Robert Carr31aa98b2016-07-20 15:29:03 -07003139 mFrameSizeChanged = false;
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003140 mResizedWhileNotDragResizingReported = true;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003141 mWinAnimator.mSurfaceResized = false;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003142 mReportOrientationChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003143 } catch (RemoteException e) {
Bryce Lee8c3cf382017-07-06 19:47:10 -07003144 setOrientationChanging(false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003145 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
3146 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08003147 // We are assuming the hosting process is dead or in a zombie state.
3148 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
3149 + ", removing this window.");
3150 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07003151 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003152 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003153 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003154 }
3155
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003156 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08003157 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
3158 // start even if we haven't received the relayout window, so that the client requests
3159 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
3160 // until the window to small size, otherwise the multithread renderer will shift last
3161 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
3162 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003163 boolean resizing = isDragResizing() || isDragResizeChanged();
3164 if (StackId.useWindowFrameForBackdrop(getStackId()) || !resizing) {
3165 return frame;
3166 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07003167 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003168 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003169 return mTmpRect;
3170 }
3171
Jorim Jaggi86905582016-02-09 21:36:09 -08003172 @Override
3173 public int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003174 final TaskStack stack = getStack();
3175 if (stack == null) {
3176 return INVALID_STACK_ID;
3177 }
3178 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003179 }
3180
3181 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
3182 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
Andrii Kulian44607962017-03-16 11:06:24 -07003183 MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId)
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003184 throws RemoteException {
Andrii Kulianb2e37802017-01-11 00:36:44 -08003185 final boolean forceRelayout = isDragResizeChanged() || mResizedWhileNotDragResizing
3186 || reportOrientation;
Chong Zhangedaf3052016-04-22 15:04:31 -07003187
Jorim Jaggidc249c42015-12-15 14:57:31 -08003188 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003189 reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout,
3190 mPolicy.isNavBarForcedShownLw(this), displayId);
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003191 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003192 }
3193
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003194 public void registerFocusObserver(IWindowFocusObserver observer) {
3195 synchronized(mService.mWindowMap) {
3196 if (mFocusCallbacks == null) {
3197 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
3198 }
3199 mFocusCallbacks.register(observer);
3200 }
3201 }
3202
3203 public void unregisterFocusObserver(IWindowFocusObserver observer) {
3204 synchronized(mService.mWindowMap) {
3205 if (mFocusCallbacks != null) {
3206 mFocusCallbacks.unregister(observer);
3207 }
3208 }
3209 }
3210
3211 public boolean isFocused() {
3212 synchronized(mService.mWindowMap) {
3213 return mService.mCurrentFocus == this;
3214 }
3215 }
3216
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07003217 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003218 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07003219 return task != null && task.inFreeformWorkspace();
3220 }
3221
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003222 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07003223 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003224 final Task task = getTask();
3225 return task != null && !task.isFullscreen();
3226 }
3227
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003228 /** Is this window in a container that takes up the entire screen space? */
3229 private boolean inFullscreenContainer() {
3230 if (mAppToken == null) {
3231 return true;
3232 }
3233 if (mAppToken.hasBounds()) {
3234 return false;
3235 }
3236 return !isInMultiWindowMode();
3237 }
3238
Andrii Kulian283acd22017-08-03 04:03:51 -07003239 /** @return true when the window is in fullscreen task, but has non-fullscreen bounds set. */
3240 boolean isLetterboxedAppWindow() {
3241 final Task task = getTask();
3242 final boolean taskIsFullscreen = task != null && task.isFullscreen();
3243 final boolean appWindowIsFullscreen = mAppToken != null && !mAppToken.hasBounds();
3244
3245 return taskIsFullscreen && !appWindowIsFullscreen;
3246 }
3247
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003248 /** Returns the appropriate bounds to use for computing frames. */
3249 private void getContainerBounds(Rect outBounds) {
3250 if (isInMultiWindowMode()) {
3251 getTask().getBounds(outBounds);
3252 } else if (mAppToken != null){
3253 mAppToken.getBounds(outBounds);
3254 } else {
3255 outBounds.setEmpty();
3256 }
3257 }
3258
Chong Zhang3005e752015-09-18 18:46:28 -07003259 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003260 return mDragResizing != computeDragResizing();
3261 }
3262
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003263 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003264 void setWaitingForDrawnIfResizingChanged() {
3265 if (isDragResizeChanged()) {
3266 mService.mWaitingForDrawn.add(this);
3267 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003268 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003269 }
3270
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003271 /**
3272 * @return Whether we reported a drag resize change to the application or not already.
3273 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003274 private boolean isDragResizingChangeReported() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003275 return mDragResizingChangeReported;
3276 }
3277
3278 /**
3279 * Resets the state whether we reported a drag resize change to the app.
3280 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003281 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003282 void resetDragResizingChangeReported() {
3283 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003284 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003285 }
3286
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003287 /**
3288 * Set whether we got resized but drag resizing flag was false.
3289 * @see #isResizedWhileNotDragResizing().
3290 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003291 private void setResizedWhileNotDragResizing(boolean resizedWhileNotDragResizing) {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003292 mResizedWhileNotDragResizing = resizedWhileNotDragResizing;
3293 mResizedWhileNotDragResizingReported = !resizedWhileNotDragResizing;
3294 }
3295
3296 /**
3297 * Indicates whether we got resized but drag resizing flag was false. In this case, we also
3298 * need to recreate the surface and defer surface bound updates in order to make sure the
3299 * buffer contents and the positioning/size stay in sync.
3300 */
3301 boolean isResizedWhileNotDragResizing() {
3302 return mResizedWhileNotDragResizing;
3303 }
3304
3305 /**
3306 * @return Whether we reported "resize while not drag resizing" to the application.
3307 * @see #isResizedWhileNotDragResizing()
3308 */
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003309 private boolean isResizedWhileNotDragResizingReported() {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003310 return mResizedWhileNotDragResizingReported;
3311 }
3312
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003313 int getResizeMode() {
3314 return mResizeMode;
3315 }
3316
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003317 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003318 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003319 if (task == null) {
3320 return false;
3321 }
Winson Chung2af04b32017-01-24 16:21:13 -08003322 if (!StackId.isStackAffectedByDragResizing(getStackId())) {
3323 return false;
3324 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003325 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003326 // Floating windows never enter drag resize mode.
3327 return false;
3328 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003329 if (task.isDragResizing()) {
3330 return true;
3331 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003332
3333 // If the bounds are currently frozen, it means that the layout size that the app sees
3334 // and the bounds we clip this window to might be different. In order to avoid holes, we
3335 // simulate that we are still resizing so the app fills the hole with the resizing
3336 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003337 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003338 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Jorim Jaggi899327f2016-02-25 20:44:18 -05003339 !task.inFreeformWorkspace() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003340
Chong Zhang3005e752015-09-18 18:46:28 -07003341 }
3342
3343 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003344 final boolean resizing = computeDragResizing();
3345 if (resizing == mDragResizing) {
3346 return;
3347 }
3348 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003349 final Task task = getTask();
3350 if (task != null && task.isDragResizing()) {
3351 mResizeMode = task.getDragResizeMode();
3352 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003353 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003354 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3355 : DRAG_RESIZE_MODE_FREEFORM;
3356 }
Chong Zhang3005e752015-09-18 18:46:28 -07003357 }
3358
3359 boolean isDragResizing() {
3360 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003361 }
3362
Robert Carr2487ce72016-04-07 15:18:45 -07003363 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003364 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3365 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003366 }
3367
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003368 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003369 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003370 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003371 if (stack != null) {
3372 pw.print(" stackId="); pw.print(stack.mStackId);
3373 }
Craig Mautner59c00972012-07-30 12:10:24 -07003374 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003375 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07003376 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08003377 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
3378 pw.print(" package="); pw.print(mAttrs.packageName);
3379 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003380 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003381 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
3382 pw.print(" h="); pw.print(mRequestedHeight);
3383 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003384 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
3385 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
3386 pw.print(" h="); pw.println(mLastRequestedHeight);
3387 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003388 if (mIsChildWindow || mLayoutAttached) {
3389 pw.print(prefix); pw.print("mParentWindow="); pw.print(getParentWindow());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003390 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
3391 }
3392 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
3393 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
3394 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
3395 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
3396 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
3397 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003398 if (dumpAll) {
3399 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3400 pw.print(" mSubLayer="); pw.print(mSubLayer);
3401 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Wale Ogunwale455fac52016-07-21 07:24:49 -07003402 pw.print(getAnimLayerAdjustment());
Craig Mautnerc2f9be02012-03-27 17:32:29 -07003403 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
3404 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003405 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003406 if (dumpAll) {
3407 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003408 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003409 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
3410 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08003411 pw.print(isAnimatingWithSavedSurface());
Bryce Lee6311c4b2017-07-06 14:09:29 -07003412 pw.print(" mAppDied=");pw.print(mAppDied);
3413 pw.print(prefix); pw.print("drawnStateEvaluated=");
3414 pw.print(getDrawnStateEvaluated());
3415 pw.print(prefix); pw.print("mightAffectAllDrawn=");
3416 pw.println(mightAffectAllDrawn(false /*visibleOnly*/));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003417 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003418 pw.print(prefix); pw.print("mViewVisibility=0x");
3419 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003420 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
3421 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07003422 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
3423 pw.print(" mSystemUiVisibility=0x");
3424 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003425 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003426 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
Svetoslav Ganov71c51022016-09-02 17:54:37 -07003427 || isParentWindowHidden()|| mPermanentlyHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003428 pw.print(prefix); pw.print("mPolicyVisibility=");
3429 pw.print(mPolicyVisibility);
3430 pw.print(" mPolicyVisibilityAfterAnim=");
3431 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003432 pw.print(" mAppOpVisibility=");
3433 pw.print(mAppOpVisibility);
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003434 pw.print(" parentHidden="); pw.print(isParentWindowHidden());
Svetoslav Ganovaa076532016-08-01 19:16:43 -07003435 pw.print(" mPermanentlyHidden="); pw.println(mPermanentlyHidden);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003436 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003437 if (!mRelayoutCalled || mLayoutNeeded) {
3438 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
3439 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003440 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003441 if (mXOffset != 0 || mYOffset != 0) {
3442 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
3443 pw.print(" y="); pw.println(mYOffset);
3444 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003445 if (dumpAll) {
3446 pw.print(prefix); pw.print("mGivenContentInsets=");
3447 mGivenContentInsets.printShortString(pw);
3448 pw.print(" mGivenVisibleInsets=");
3449 mGivenVisibleInsets.printShortString(pw);
3450 pw.println();
3451 if (mTouchableInsets != 0 || mGivenInsetsPending) {
3452 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
3453 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003454 Region region = new Region();
3455 getTouchableRegion(region);
3456 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003457 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003458 pw.print(prefix); pw.print("mFullConfiguration="); pw.println(getConfiguration());
3459 pw.print(prefix); pw.print("mLastReportedConfiguration=");
3460 pw.println(mLastReportedConfiguration);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003461 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07003462 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07003463 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Chong Zhanga8975bd2016-01-28 17:13:47 -08003464 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08003465 pw.print(" hasSavedSurface()="); pw.print(hasSavedSurface());
3466 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003467 if (dumpAll) {
3468 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
3469 pw.print(" last="); mLastFrame.printShortString(pw);
3470 pw.println();
3471 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003472 if (mEnforceSizeCompat) {
3473 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003474 pw.println();
3475 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003476 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003477 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003478 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003479 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003480 pw.println();
3481 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
3482 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003483 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003484 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003485 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003486 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04003487 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
3488 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003489 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
3490 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003491 pw.print(prefix); pw.print("Cur insets: overscan=");
3492 mOverscanInsets.printShortString(pw);
3493 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003494 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003495 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003496 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003497 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003498 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003499 pw.print(prefix); pw.print("Lst insets: overscan=");
3500 mLastOverscanInsets.printShortString(pw);
3501 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003502 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003503 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003504 pw.print(" physical="); mLastOutsets.printShortString(pw);
3505 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003506 pw.println();
3507 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07003508 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
3509 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003510 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
3511 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003512 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
3513 pw.print(" mDestroying="); pw.print(mDestroying);
3514 pw.print(" mRemoved="); pw.println(mRemoved);
3515 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07003516 if (getOrientationChanging() || mAppFreezing || mTurnOnScreen
Andrii Kulianb2e37802017-01-11 00:36:44 -08003517 || mReportOrientationChanged) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003518 pw.print(prefix); pw.print("mOrientationChanging=");
3519 pw.print(mOrientationChanging);
Bryce Lee8c3cf382017-07-06 19:47:10 -07003520 pw.print(" configOrientationChanging=");
3521 pw.print(mLastReportedConfiguration.orientation
3522 != getConfiguration().orientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003523 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003524 pw.print(" mTurnOnScreen="); pw.print(mTurnOnScreen);
Andrii Kulianb2e37802017-01-11 00:36:44 -08003525 pw.print(" mReportOrientationChanged="); pw.println(mReportOrientationChanged);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003526 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003527 if (mLastFreezeDuration != 0) {
3528 pw.print(prefix); pw.print("mLastFreezeDuration=");
3529 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
3530 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003531 if (mHScale != 1 || mVScale != 1) {
3532 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
3533 pw.print(" mVScale="); pw.println(mVScale);
3534 }
3535 if (mWallpaperX != -1 || mWallpaperY != -1) {
3536 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
3537 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
3538 }
3539 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
3540 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
3541 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
3542 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003543 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3544 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
3545 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
3546 pw.print(mWallpaperDisplayOffsetX);
3547 pw.print(" mWallpaperDisplayOffsetY=");
3548 pw.println(mWallpaperDisplayOffsetY);
3549 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003550 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07003551 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003552 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003553 if (isDragResizing()) {
3554 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
3555 }
3556 if (computeDragResizing()) {
3557 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
3558 }
Bryce Lee6311c4b2017-07-06 14:09:29 -07003559 pw.print(prefix); pw.println("isOnScreen=" + isOnScreen());
3560 pw.print(prefix); pw.println("isVisible=" + isVisible());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003561 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003562
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003563 @Override
3564 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003565 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003566 + " " + getWindowTag();
3567 }
3568
Robert Carra1eb4392015-12-10 12:43:51 -08003569 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003570 CharSequence tag = mAttrs.getTitle();
3571 if (tag == null || tag.length() <= 0) {
3572 tag = mAttrs.packageName;
3573 }
3574 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003575 }
3576
3577 @Override
3578 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003579 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003580 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003581 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003582 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003583 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003584 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003585 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003586 }
3587 return mStringNameCache;
3588 }
Robert Carr58f29132015-10-29 14:19:05 -07003589
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003590 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003591 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003592 clipRect.left = (int) (clipRect.left / mHScale);
3593 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003594 }
3595 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003596 clipRect.top = (int) (clipRect.top / mVScale);
3597 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003598 }
3599 }
Robert Carr31e28482015-12-02 16:53:18 -08003600
Jorim Jaggif5834272016-04-04 20:25:41 -07003601 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
3602 final int pw = containingFrame.width();
3603 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003604 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003605 final boolean inNonFullscreenContainer = !inFullscreenContainer();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003606 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3607
3608 // We need to fit it to the display if either
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003609 // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen
3610 // for the taskless windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003611 // b) If it's a secondary app window, we also need to fit it to the display unless
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003612 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on
3613 // screen, but SurfaceViews want to be always at a specific location so we don't fit it to
3614 // the display.
3615 final boolean fitToDisplay = (task == null || !inNonFullscreenContainer)
Robert Carr6f44db12016-07-21 14:54:43 -07003616 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003617 float x, y;
3618 int w,h;
3619
3620 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3621 if (mAttrs.width < 0) {
3622 w = pw;
3623 } else if (mEnforceSizeCompat) {
3624 w = (int)(mAttrs.width * mGlobalScale + .5f);
3625 } else {
3626 w = mAttrs.width;
3627 }
3628 if (mAttrs.height < 0) {
3629 h = ph;
3630 } else if (mEnforceSizeCompat) {
3631 h = (int)(mAttrs.height * mGlobalScale + .5f);
3632 } else {
3633 h = mAttrs.height;
3634 }
3635 } else {
3636 if (mAttrs.width == MATCH_PARENT) {
3637 w = pw;
3638 } else if (mEnforceSizeCompat) {
3639 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3640 } else {
3641 w = mRequestedWidth;
3642 }
3643 if (mAttrs.height == MATCH_PARENT) {
3644 h = ph;
3645 } else if (mEnforceSizeCompat) {
3646 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3647 } else {
3648 h = mRequestedHeight;
3649 }
3650 }
3651
3652 if (mEnforceSizeCompat) {
3653 x = mAttrs.x * mGlobalScale;
3654 y = mAttrs.y * mGlobalScale;
3655 } else {
3656 x = mAttrs.x;
3657 y = mAttrs.y;
3658 }
3659
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003660 if (inNonFullscreenContainer && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003661 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003662 // required by {@link Gravity#apply} call.
3663 w = Math.min(w, pw);
3664 h = Math.min(h, ph);
3665 }
3666
3667 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003668 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003669 (int) (x + mAttrs.horizontalMargin * pw),
3670 (int) (y + mAttrs.verticalMargin * ph), mFrame);
3671
3672 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003673 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003674 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003675 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003676
3677 // We need to make sure we update the CompatFrame as it is used for
3678 // cropping decisions, etc, on systems where we lack a decor layer.
3679 mCompatFrame.set(mFrame);
3680 if (mEnforceSizeCompat) {
3681 // See comparable block in computeFrameLw.
3682 mCompatFrame.scale(mInvGlobalScale);
3683 }
Robert Carr31e28482015-12-02 16:53:18 -08003684 }
Robert Carr51a1b872015-12-08 14:03:13 -08003685
3686 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003687 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003688 }
3689
Robert Carrf3b72c72016-03-21 18:16:39 -07003690 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003691 return mIsChildWindow
3692 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003693 }
3694
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003695 /** Returns the parent window if this is a child of another window, else null. */
3696 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003697 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3698 // WindowContainer that isn't a WindowState.
3699 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003700 }
3701
3702 /** Returns the topmost parent window if this is a child of another window, else this. */
3703 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003704 WindowState current = this;
3705 WindowState topParent = current;
3706 while (current != null && current.mIsChildWindow) {
3707 current = current.getParentWindow();
3708 // Parent window can be null if the child is detached from it's parent already, but
3709 // someone still has a reference to access it. So, we return the top parent value we
3710 // already have instead of null.
3711 if (current != null) {
3712 topParent = current;
3713 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003714 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003715 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003716 }
3717
Wale Ogunwale9d147902016-07-16 11:58:55 -07003718 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003719 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003720 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003721 }
3722
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003723 void setWillReplaceWindow(boolean animate) {
3724 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003725 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003726 c.setWillReplaceWindow(animate);
3727 }
3728
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003729 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3730 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3731 // We don't set replacing on starting windows since they are added by window manager and
3732 // not the client so won't be replaced by the client.
3733 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003734 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003735
3736 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003737 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003738 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003739 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003740
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003741 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003742 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003743 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003744 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003745
3746 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003747 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003748 c.clearWillReplaceWindow();
3749 }
3750 }
3751
3752 boolean waitingForReplacement() {
3753 if (mWillReplaceWindow) {
3754 return true;
3755 }
3756
3757 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003758 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003759 if (c.waitingForReplacement()) {
3760 return true;
3761 }
3762 }
3763 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003764 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003765
Chong Zhang4d7369a2016-04-25 16:09:14 -07003766 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003767 final DisplayContent dc = getDisplayContent();
3768 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3769 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3770 dc.setLayoutNeeded();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003771 mService.mWindowPlacerLocked.requestTraversal();
3772 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003773
3774 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003775 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003776 c.requestUpdateWallpaperIfNeeded();
3777 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003778 }
3779
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003780 float translateToWindowX(float x) {
3781 float winX = x - mFrame.left;
3782 if (mEnforceSizeCompat) {
3783 winX *= mGlobalScale;
3784 }
3785 return winX;
3786 }
3787
3788 float translateToWindowY(float y) {
3789 float winY = y - mFrame.top;
3790 if (mEnforceSizeCompat) {
3791 winY *= mGlobalScale;
3792 }
3793 return winY;
3794 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003795
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003796 private void transferDimToReplacement() {
Robert Carr9fe459d2016-04-07 23:32:28 -07003797 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003798 final DisplayContent dc = getDisplayContent();
3799 if (dimLayerUser != null && dc != null) {
3800 dc.mDimLayerController.applyDim(dimLayerUser,
3801 mReplacementWindow.mWinAnimator, (mAttrs.flags & FLAG_DIM_BEHIND) != 0);
Robert Carr9fe459d2016-04-07 23:32:28 -07003802 }
3803 }
3804
Robert Carrd1a010f2016-04-07 22:36:22 -07003805 // During activity relaunch due to resize, we sometimes use window replacement
3806 // for only child windows (as the main window is handled by window preservation)
3807 // and the big surface.
3808 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003809 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3810 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3811 // we also want to replace them at such phases, as they won't be covered by window
3812 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003813 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003814 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003815 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003816 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003817
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003818 void setWillReplaceChildWindows() {
3819 if (shouldBeReplacedWithChildren()) {
3820 setWillReplaceWindow(false /* animate */);
3821 }
3822 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003823 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003824 c.setWillReplaceChildWindows();
3825 }
3826 }
3827
3828 WindowState getReplacingWindow() {
3829 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3830 return this;
3831 }
3832 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003833 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003834 final WindowState replacing = c.getReplacingWindow();
3835 if (replacing != null) {
3836 return replacing;
3837 }
3838 }
3839 return null;
3840 }
3841
Jorim Jaggife762342016-10-13 14:33:27 +02003842 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07003843 public int getRotationAnimationHint() {
3844 if (mAppToken != null) {
3845 return mAppToken.mRotationAnimationHint;
3846 } else {
3847 return -1;
3848 }
3849 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003850
Jorim Jaggife762342016-10-13 14:33:27 +02003851 @Override
3852 public boolean isInputMethodWindow() {
3853 return mIsImWindow;
3854 }
3855
Wale Ogunwale9d147902016-07-16 11:58:55 -07003856 // This must be called while inside a transaction.
3857 boolean performShowLocked() {
3858 if (isHiddenFromUserLocked()) {
3859 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3860 hideLw(false);
3861 return false;
3862 }
3863
3864 logPerformShow("performShow on ");
3865
Jorim Jaggia50da602016-12-29 11:51:42 +01003866 final int drawState = mWinAnimator.mDrawState;
3867 if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW)
3868 && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3869 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3870 }
3871
Jorim Jaggib0d27342016-11-01 16:10:42 -07003872 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003873 return false;
3874 }
3875
3876 logPerformShow("Showing ");
3877
3878 mService.enableScreenIfNeededLocked();
3879 mWinAnimator.applyEnterAnimationLocked();
3880
3881 // Force the show in the next prepareSurfaceLocked() call.
3882 mWinAnimator.mLastAlpha = -1;
3883 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) Slog.v(TAG,
3884 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3885 mWinAnimator.mDrawState = HAS_DRAWN;
3886 mService.scheduleAnimationLocked();
3887
3888 if (mHidden) {
3889 mHidden = false;
3890 final DisplayContent displayContent = getDisplayContent();
3891
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003892 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003893 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003894 if (c.mWinAnimator.mSurfaceController != null) {
3895 c.performShowLocked();
3896 // It hadn't been shown, which means layout not performed on it, so now we
3897 // want to make sure to do a layout. If called from within the transaction
3898 // loop, this will cause it to restart with a new layout.
3899 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003900 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003901 }
3902 }
3903 }
3904 }
3905
Wale Ogunwale9d147902016-07-16 11:58:55 -07003906 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003907 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003908 }
3909
3910 return true;
3911 }
3912
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003913 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003914 if (DEBUG_VISIBILITY
Jorim Jaggie4b0f282017-05-17 15:10:29 +02003915 || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003916 Slog.v(TAG, prefix + this
3917 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07003918 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003919 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3920 + " during animation: policyVis=" + mPolicyVisibility
3921 + " parentHidden=" + isParentWindowHidden()
3922 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003923 + (mAppToken != null && mAppToken.hiddenRequested)
3924 + " tok.hidden=" + (mAppToken != null && mAppToken.hidden)
Wale Ogunwale9d147902016-07-16 11:58:55 -07003925 + " animating=" + mWinAnimator.mAnimating
3926 + " tok animating="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003927 + (mWinAnimator.mAppAnimator != null && mWinAnimator.mAppAnimator.animating)
Wale Ogunwale9d147902016-07-16 11:58:55 -07003928 + " Callers=" + Debug.getCallers(4));
3929 }
3930 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003931
3932 WindowInfo getWindowInfo() {
3933 WindowInfo windowInfo = WindowInfo.obtain();
3934 windowInfo.type = mAttrs.type;
3935 windowInfo.layer = mLayer;
3936 windowInfo.token = mClient.asBinder();
3937 windowInfo.title = mAttrs.accessibilityTitle;
3938 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3939 windowInfo.focused = isFocused();
Phil Weaverf00cd142017-03-03 13:44:00 -08003940 Task task = getTask();
3941 windowInfo.inPictureInPicture = (task != null) && task.inPinnedWorkspace();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003942
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003943 if (mIsChildWindow) {
3944 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003945 }
3946
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003947 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003948 if (childCount > 0) {
3949 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003950 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003951 }
3952 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003953 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003954 windowInfo.childTokens.add(child.mClient.asBinder());
3955 }
3956 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003957 return windowInfo;
3958 }
3959
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003960 int getHighestAnimLayer() {
3961 int highest = mWinAnimator.mAnimLayer;
3962 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003963 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003964 final int childLayer = c.getHighestAnimLayer();
3965 if (childLayer > highest) {
3966 highest = childLayer;
3967 }
3968 }
3969 return highest;
3970 }
3971
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003972 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003973 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003974 if (mChildren.isEmpty()) {
3975 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003976 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003977 }
3978
3979 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003980 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003981 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003982 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003983 }
3984 }
3985
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003986 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003987 // We want to consume the negative sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003988 // below the parent, then this window (the parent), and then the positive sublayer children
3989 // because they need to appear above the parent.
3990 int i = 0;
3991 final int count = mChildren.size();
3992 WindowState child = mChildren.get(i);
3993
3994 while (i < count && child.mSubLayer < 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003995 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003996 return true;
3997 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003998 i++;
3999 if (i >= count) {
4000 break;
4001 }
4002 child = mChildren.get(i);
4003 }
4004
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004005 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004006 return true;
4007 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004008
4009 while (i < count) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004010 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004011 return true;
4012 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004013 i++;
4014 if (i >= count) {
4015 break;
4016 }
4017 child = mChildren.get(i);
4018 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004019
4020 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004021 }
4022
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004023 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004024 // We want to consume the positive sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004025 // above the parent, then this window (the parent), and then the negative sublayer children
4026 // because they need to appear above the parent.
4027 int i = mChildren.size() - 1;
4028 WindowState child = mChildren.get(i);
4029
4030 while (i >= 0 && child.mSubLayer >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004031 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004032 return true;
4033 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004034 --i;
4035 if (i < 0) {
4036 break;
4037 }
4038 child = mChildren.get(i);
4039 }
4040
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004041 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004042 return true;
4043 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004044
4045 while (i >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004046 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004047 return true;
4048 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004049 --i;
4050 if (i < 0) {
4051 break;
4052 }
4053 child = mChildren.get(i);
4054 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004055
4056 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004057 }
4058
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004059 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
4060 boolean traverseTopToBottom) {
4061 if (traverseTopToBottom) {
4062 if (mService.mInputMethodTarget == this) {
4063 // This window is the current IME target, so we need to process the IME windows
4064 // directly above it.
4065 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
4066 return true;
4067 }
4068 }
4069 if (callback.apply(this)) {
4070 return true;
4071 }
4072 } else {
4073 if (callback.apply(this)) {
4074 return true;
4075 }
4076 if (mService.mInputMethodTarget == this) {
4077 // This window is the current IME target, so we need to process the IME windows
4078 // directly above it.
4079 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
4080 return true;
4081 }
4082 }
4083 }
4084
4085 return false;
4086 }
4087
Wale Ogunwaled1880962016-11-08 10:31:59 -08004088 WindowState getWindow(Predicate<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004089 if (mChildren.isEmpty()) {
4090 return callback.test(this) ? this : null;
4091 }
4092
4093 // We want to consume the positive sublayer children first because they need to appear
4094 // above the parent, then this window (the parent), and then the negative sublayer children
4095 // because they need to appear above the parent.
4096 int i = mChildren.size() - 1;
4097 WindowState child = mChildren.get(i);
4098
4099 while (i >= 0 && child.mSubLayer >= 0) {
4100 if (callback.test(child)) {
4101 return child;
4102 }
4103 --i;
4104 if (i < 0) {
4105 break;
4106 }
4107 child = mChildren.get(i);
4108 }
4109
Wale Ogunwaled1880962016-11-08 10:31:59 -08004110 if (callback.test(this)) {
4111 return this;
4112 }
Wale Ogunwale34247952017-02-19 11:57:53 -08004113
4114 while (i >= 0) {
4115 if (callback.test(child)) {
4116 return child;
4117 }
4118 --i;
4119 if (i < 0) {
4120 break;
4121 }
4122 child = mChildren.get(i);
4123 }
4124
4125 return null;
Wale Ogunwaled1880962016-11-08 10:31:59 -08004126 }
4127
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004128 boolean isWindowAnimationSet() {
4129 if (mWinAnimator.isWindowAnimationSet()) {
4130 return true;
4131 }
4132 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004133 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004134 if (c.isWindowAnimationSet()) {
4135 return true;
4136 }
4137 }
4138 return false;
4139 }
4140
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004141 void onExitAnimationDone() {
4142 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
4143 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
4144 + " windowAnimating=" + mWinAnimator.isWindowAnimationSet());
4145
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004146 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004147 // Copying to a different list as multiple children can be removed.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004148 // TODO: Not sure if we really need to copy this into a different list.
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004149 final LinkedList<WindowState> childWindows = new LinkedList(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004150 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004151 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004152 }
4153 }
4154
4155 if (mWinAnimator.mEnteringAnimation) {
4156 mWinAnimator.mEnteringAnimation = false;
4157 mService.requestTraversal();
4158 // System windows don't have an activity and an app token as a result, but need a way
4159 // to be informed about their entrance animation end.
4160 if (mAppToken == null) {
4161 try {
4162 mClient.dispatchWindowShown();
4163 } catch (RemoteException e) {
4164 }
4165 }
4166 }
4167
4168 if (!mWinAnimator.isWindowAnimationSet()) {
4169 //TODO (multidisplay): Accessibility is supported only for the default display.
4170 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
4171 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
4172 }
4173 }
4174
4175 if (!mAnimatingExit) {
4176 return;
4177 }
4178
4179 if (mWinAnimator.isWindowAnimationSet()) {
4180 return;
4181 }
4182
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07004183 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004184 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
4185
4186 mDestroying = true;
4187
4188 final boolean hasSurface = mWinAnimator.hasSurface();
4189 if (hasSurface) {
4190 mWinAnimator.hide("onExitAnimationDone");
4191 }
4192
4193 // If we have an app token, we ask it to destroy the surface for us, so that it can take
4194 // care to ensure the activity has actually stopped and the surface is not still in use.
4195 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
4196 // transaction.
4197 if (mAppToken != null) {
4198 mAppToken.destroySurfaces();
4199 } else {
4200 if (hasSurface) {
4201 mService.mDestroySurface.add(this);
4202 }
4203 if (mRemoveOnExit) {
4204 mService.mPendingRemove.add(this);
4205 mRemoveOnExit = false;
4206 }
4207 }
4208 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07004209 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004210 }
Dan Willemsen117197f2016-07-30 13:02:59 -07004211
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004212 boolean clearAnimatingFlags() {
4213 boolean didSomething = false;
4214 // We don't want to clear it out for windows that get replaced, because the
4215 // animation depends on the flag to remove the replaced window.
4216 //
4217 // We also don't clear the mAnimatingExit flag for windows which have the
4218 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4219 // by the client. We should let animation proceed and not clear this flag or
4220 // they won't eventually be removed by WindowStateAnimator#finishExit.
4221 if (!mWillReplaceWindow && !mRemoveOnExit) {
4222 // Clear mAnimating flag together with mAnimatingExit. When animation
4223 // changes from exiting to entering, we need to clear this flag until the
4224 // new animation gets applied, so that isAnimationStarting() becomes true
4225 // until then.
4226 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4227 // placement for this window during this period, one or more frame will
4228 // show up with wrong position or scale.
4229 if (mAnimatingExit) {
4230 mAnimatingExit = false;
4231 didSomething = true;
4232 }
4233 if (mWinAnimator.mAnimating) {
4234 mWinAnimator.mAnimating = false;
4235 didSomething = true;
4236 }
4237 if (mDestroying) {
4238 mDestroying = false;
4239 mService.mDestroySurface.remove(this);
4240 didSomething = true;
4241 }
4242 }
4243
4244 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004245 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004246 }
4247
4248 return didSomething;
4249 }
4250
Winson4b4ba902016-07-27 19:45:52 -07004251 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004252 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004253 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004254
4255 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004256 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004257 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004258 c.hideWallpaperWindow(wasDeferred, reason);
4259 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004260 if (!mWinAnimator.mLastHidden || wasDeferred) {
4261 mWinAnimator.hide(reason);
4262 dispatchWallpaperVisibility(false);
4263 final DisplayContent displayContent = getDisplayContent();
4264 if (displayContent != null) {
4265 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
4266 }
4267 }
4268 }
4269
4270 /**
4271 * Check wallpaper window for visibility change and notify window if so.
4272 * @param visible Current visibility.
4273 */
4274 void dispatchWallpaperVisibility(final boolean visible) {
4275 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07004276 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004277
4278 // Only send notification if the visibility actually changed and we are not trying to hide
4279 // the wallpaper when we are deferring hiding of the wallpaper.
4280 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4281 mWallpaperVisible = visible;
4282 try {
4283 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4284 "Updating vis of wallpaper " + this
4285 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4286 mClient.dispatchAppVisibility(visible);
4287 } catch (RemoteException e) {
4288 }
4289 }
4290 }
4291
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004292 boolean hasVisibleNotDrawnWallpaper() {
4293 if (mWallpaperVisible && !isDrawnLw()) {
4294 return true;
4295 }
4296 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004297 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004298 if (c.hasVisibleNotDrawnWallpaper()) {
4299 return true;
4300 }
4301 }
4302 return false;
4303 }
4304
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004305 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4306 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004307 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004308 c.updateReportedVisibility(results);
4309 }
4310
4311 if (mAppFreezing || mViewVisibility != View.VISIBLE
4312 || mAttrs.type == TYPE_APPLICATION_STARTING
4313 || mDestroying) {
4314 return;
4315 }
4316 if (DEBUG_VISIBILITY) {
4317 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
4318 + ", isAnimationSet=" + mWinAnimator.isAnimationSet());
4319 if (!isDrawnLw()) {
4320 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4321 + " pv=" + mPolicyVisibility
4322 + " mDrawState=" + mWinAnimator.mDrawState
4323 + " ph=" + isParentWindowHidden()
4324 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
4325 + " a=" + mWinAnimator.mAnimating);
4326 }
4327 }
4328
4329 results.numInteresting++;
4330 if (isDrawnLw()) {
4331 results.numDrawn++;
4332 if (!mWinAnimator.isAnimationSet()) {
4333 results.numVisible++;
4334 }
4335 results.nowGone = false;
4336 } else if (mWinAnimator.isAnimationSet()) {
4337 results.nowGone = false;
4338 }
4339 }
4340
Robert Carrfbbde852016-10-18 11:02:28 -07004341 /**
4342 * Calculate the window crop according to system decor policy. In general this is
4343 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4344 * special cases. This rectangle is in screen space.
4345 */
4346 void calculatePolicyCrop(Rect policyCrop) {
4347 final DisplayContent displayContent = getDisplayContent();
4348 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
4349
4350 if (!isDefaultDisplay()) {
4351 // On a different display there is no system decor. Crop the window
4352 // by the screen boundaries.
4353 // TODO(multi-display)
4354 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4355 policyCrop.intersect(-mCompatFrame.left, -mCompatFrame.top,
4356 displayInfo.logicalWidth - mCompatFrame.left,
4357 displayInfo.logicalHeight - mCompatFrame.top);
4358 } else if (mLayer >= mService.mSystemDecorLayer) {
4359 // Above the decor layer is easy, just use the entire window
4360 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4361 } else if (mDecorFrame.isEmpty()) {
4362 // Windows without policy decor aren't cropped.
4363 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4364 } else {
4365 // Crop to the system decor specified by policy.
4366 calculateSystemDecorRect(policyCrop);
4367 }
4368 }
4369
4370 /**
4371 * The system decor rect is the region of the window which is not covered
4372 * by system decorations.
4373 */
4374 private void calculateSystemDecorRect(Rect systemDecorRect) {
4375 final Rect decorRect = mDecorFrame;
4376 final int width = mFrame.width();
4377 final int height = mFrame.height();
4378
4379 // Compute the offset of the window in relation to the decor rect.
4380 final int left = mXOffset + mFrame.left;
4381 final int top = mYOffset + mFrame.top;
4382
4383 // Initialize the decor rect to the entire frame.
4384 if (isDockedResizing()) {
4385 // If we are resizing with the divider, the task bounds might be smaller than the
4386 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4387 // want in this case in order to avoid holes.
4388 //
4389 // We take care to not shrink the width, for surfaces which are larger than
4390 // the display region. Of course this area will not eventually be visible
4391 // but if we truncate the width now, we will calculate incorrectly
4392 // when adjusting to the stack bounds.
4393 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4394 systemDecorRect.set(0, 0,
4395 Math.max(width, displayInfo.logicalWidth),
4396 Math.max(height, displayInfo.logicalHeight));
4397 } else {
4398 systemDecorRect.set(0, 0, width, height);
4399 }
4400
4401 // If a freeform window is animating from a position where it would be cutoff, it would be
4402 // cutoff during the animation. We don't want that, so for the duration of the animation
4403 // we ignore the decor cropping and depend on layering to position windows correctly.
4404 final boolean cropToDecor = !(inFreeformWorkspace() && isAnimatingLw());
4405 if (cropToDecor) {
4406 // Intersect with the decor rect, offsetted by window position.
4407 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
4408 decorRect.right - left, decorRect.bottom - top);
4409 }
4410
4411 // If size compatibility is being applied to the window, the
4412 // surface is scaled relative to the screen. Also apply this
4413 // scaling to the crop rect. We aren't using the standard rect
4414 // scale function because we want to round things to make the crop
4415 // always round to a larger rect to ensure we don't crop too
4416 // much and hide part of the window that should be seen.
4417 if (mEnforceSizeCompat && mInvGlobalScale != 1.0f) {
4418 final float scale = mInvGlobalScale;
4419 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
4420 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
4421 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
4422 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
4423 }
4424
4425 }
4426
4427 /**
4428 * Expand the given rectangle by this windows surface insets. This
4429 * takes you from the 'window size' to the 'surface size'.
4430 * The surface insets are positive in each direction, so we inset by
4431 * the inverse.
4432 */
4433 void expandForSurfaceInsets(Rect r) {
4434 r.inset(-mAttrs.surfaceInsets.left,
4435 -mAttrs.surfaceInsets.top,
4436 -mAttrs.surfaceInsets.right,
4437 -mAttrs.surfaceInsets.bottom);
4438 }
4439
Robert Carrc91d1c32017-02-15 19:37:46 -08004440 boolean surfaceInsetsChanging() {
4441 return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets);
4442 }
4443
Bryce Leef858b572017-06-29 14:03:33 -07004444 int relayoutVisibleWindow(int result, int attrChanges, int oldVisibility) {
Robert Carrecc06b32017-04-18 14:25:10 -07004445 final boolean wasVisible = isVisibleLw();
4446
4447 result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004448 if (mAnimatingExit) {
4449 Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit="
4450 + mRemoveOnExit + ", mDestroying=" + mDestroying);
4451
4452 mWinAnimator.cancelExitAnimationForNextAnimationLocked();
4453 mAnimatingExit = false;
4454 }
4455 if (mDestroying) {
4456 mDestroying = false;
4457 mService.mDestroySurface.remove(this);
4458 }
4459 if (oldVisibility == View.GONE) {
4460 mWinAnimator.mEnterAnimationPending = true;
4461 }
4462
Andrii Kulian8ee72852017-03-10 10:36:45 -08004463 mLastVisibleLayoutRotation = getDisplayContent().getRotation();
Robert Carrc91d1c32017-02-15 19:37:46 -08004464
4465 mWinAnimator.mEnteringAnimation = true;
Bryce Leeae73ba42017-05-05 09:58:25 -07004466
Bryce Leef858b572017-06-29 14:03:33 -07004467 prepareWindowToDisplayDuringRelayout(wasVisible);
Bryce Leeae73ba42017-05-05 09:58:25 -07004468
Robert Carrc91d1c32017-02-15 19:37:46 -08004469 if ((attrChanges & FORMAT_CHANGED) != 0) {
4470 // If the format can't be changed in place, preserve the old surface until the app draws
4471 // on the new one. This prevents blinking when we change elevation of freeform and
4472 // pinned windows.
4473 if (!mWinAnimator.tryChangeFormatInPlaceLocked()) {
4474 mWinAnimator.preserveSurfaceLocked();
4475 result |= RELAYOUT_RES_SURFACE_CHANGED
4476 | RELAYOUT_RES_FIRST_TIME;
4477 }
4478 }
4479
4480 // When we change the Surface size, in scenarios which may require changing
4481 // the surface position in sync with the resize, we use a preserved surface
4482 // so we can freeze it while waiting for the client to report draw on the newly
Winson Chung8bca9e42017-04-16 15:59:43 -07004483 // sized surface. Don't preserve surfaces if the insets change while animating the pinned
4484 // stack since it can lead to issues if a new surface is created while calculating the
4485 // scale for the animation using the source hint rect
4486 // (see WindowStateAnimator#setSurfaceBoundariesLocked()).
Robert Carrc91d1c32017-02-15 19:37:46 -08004487 if (isDragResizeChanged() || isResizedWhileNotDragResizing()
Winson Chung8bca9e42017-04-16 15:59:43 -07004488 || (surfaceInsetsChanging() && !inPinnedWorkspace())) {
Robert Carrc91d1c32017-02-15 19:37:46 -08004489 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
4490
4491 setDragResizing();
4492 setResizedWhileNotDragResizing(false);
4493 // We can only change top level windows to the full-screen surface when
4494 // resizing (as we only have one full-screen surface). So there is no need
4495 // to preserve and destroy windows which are attached to another, they
4496 // will keep their surface and its size may change over time.
4497 if (mHasSurface && !isChildWindow()) {
4498 mWinAnimator.preserveSurfaceLocked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08004499 result |= RELAYOUT_RES_SURFACE_CHANGED |
4500 RELAYOUT_RES_FIRST_TIME;
Robert Carrc91d1c32017-02-15 19:37:46 -08004501 }
4502 }
4503 final boolean freeformResizing = isDragResizing()
4504 && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
4505 final boolean dockedResizing = isDragResizing()
4506 && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
4507 result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0;
4508 result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0;
4509 if (isAnimatingWithSavedSurface()) {
4510 // If we're animating with a saved surface now, request client to report draw.
4511 // We still need to know when the real thing is drawn.
4512 result |= RELAYOUT_RES_FIRST_TIME;
4513 }
4514 return result;
4515 }
4516
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004517 /**
4518 * @return True if this window has been laid out at least once; false otherwise.
4519 */
4520 boolean isLaidOut() {
4521 return mLayoutSeq != -1;
4522 }
4523
4524 /**
4525 * Updates the last inset values to the current ones.
4526 */
4527 void updateLastInsetValues() {
4528 mLastOverscanInsets.set(mOverscanInsets);
4529 mLastContentInsets.set(mContentInsets);
4530 mLastVisibleInsets.set(mVisibleInsets);
4531 mLastStableInsets.set(mStableInsets);
4532 mLastOutsets.set(mOutsets);
4533 }
4534
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004535 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4536 // access to its windows children. Need to investigate re-writing
4537 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4538 static final class UpdateReportedVisibilityResults {
4539 int numInteresting;
4540 int numVisible;
4541 int numDrawn;
4542 boolean nowGone = true;
4543
4544 void reset() {
4545 numInteresting = 0;
4546 numVisible = 0;
4547 numDrawn = 0;
4548 nowGone = true;
4549 }
4550 }
Robert Carraf422a82017-04-10 18:34:33 -07004551
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004552 private static final class WindowId extends IWindowId.Stub {
4553 private final WeakReference<WindowState> mOuter;
4554
4555 private WindowId(WindowState outer) {
4556
4557 // Use a weak reference for the outer class. This is important to prevent the following
4558 // leak: Since we send this class to the client process, binder will keep it alive as
4559 // long as the client keeps it alive. Now, if the window is removed, we need to clear
4560 // out our reference so even though this class is kept alive we don't leak WindowState,
4561 // which can keep a whole lot of classes alive.
4562 mOuter = new WeakReference<>(outer);
4563 }
4564
4565 @Override
4566 public void registerFocusObserver(IWindowFocusObserver observer) {
4567 final WindowState outer = mOuter.get();
4568 if (outer != null) {
4569 outer.registerFocusObserver(observer);
4570 }
4571 }
4572 @Override
4573 public void unregisterFocusObserver(IWindowFocusObserver observer) {
4574 final WindowState outer = mOuter.get();
4575 if (outer != null) {
4576 outer.unregisterFocusObserver(observer);
4577 }
4578 }
4579 @Override
4580 public boolean isFocused() {
4581 final WindowState outer = mOuter.get();
4582 return outer != null && outer.isFocused();
4583 }
4584 }
4585
Robert Carraf422a82017-04-10 18:34:33 -07004586 boolean usesRelativeZOrdering() {
4587 if (!isChildWindow()) {
4588 return false;
4589 } else if (mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) {
4590 return true;
4591 } else {
4592 return false;
4593 }
4594 }
satokcef37fb2011-10-24 21:49:38 +09004595}