blob: c968653b814f1f76a3808f615d343f60fccd5ddb [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 Carr237028a2016-07-26 10:39:45 -0700447 * The orientation during the last visible call to relayout. If our
448 * current orientation is different, the window can't be ready
449 * to be shown.
450 */
451 int mLastVisibleLayoutRotation = -1;
452
453 /**
Andrii Kulianb2e37802017-01-11 00:36:44 -0800454 * Set when we need to report the orientation change to client to trigger a relayout.
455 */
456 boolean mReportOrientationChanged;
457
458 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700459 * How long we last kept the screen frozen.
460 */
461 int mLastFreezeDuration;
462
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800463 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800464 boolean mRemoved;
465
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800466 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800467 * It is save to remove the window and destroy the surface because the client requested removal
468 * or some other higher level component said so (e.g. activity manager).
469 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800470 */
Svetoslav Ganov200adfb2016-10-18 13:29:27 -0700471 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800472
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800473 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700474 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800475 InputChannel mInputChannel;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700476 private InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800477
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800478 // Used to improve performance of toString()
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700479 private String mStringNameCache;
480 private CharSequence mLastTitle;
481 private boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800482
Craig Mautnera2c77052012-03-26 12:14:43 -0700483 final WindowStateAnimator mWinAnimator;
484
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700485 boolean mHasSurface = false;
486
Craig Mautner88400d32012-09-30 12:35:45 -0700487 /** When true this window can be displayed on screens owther than mOwnerUid's */
488 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700489
Robert Carr13f7be9e2015-12-02 18:39:45 -0800490 // Whether the window has a saved surface from last pause, which can be
491 // used to start an entering animation earlier.
Chong Zhang92147042016-05-09 12:47:11 -0700492 private boolean mSurfaceSaved = false;
493
Chong Zhang8e4bda92016-05-04 15:08:18 -0700494 // Whether we're performing an entering animation with a saved surface. This flag is
495 // true during the time we're showing a window with a previously saved surface. It's
496 // cleared when surface is destroyed, saved, or re-drawn by the app.
Chong Zhang92147042016-05-09 12:47:11 -0700497 private boolean mAnimatingWithSavedSurface;
498
499 // Whether the window was visible when we set the app to invisible last time. WM uses
500 // this as a hint to restore the surface (if available) for early animation next time
501 // the app is brought visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700502 private boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800503
Robert Carra1eb4392015-12-10 12:43:51 -0800504 // This window will be replaced due to relaunch. This allows window manager
505 // to differentiate between simple removal of a window and replacement. In the latter case it
506 // will preserve the old window until the new one is drawn.
507 boolean mWillReplaceWindow = false;
508 // If true, the replaced window was already requested to be removed.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700509 private boolean mReplacingRemoveRequested = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800510 // Whether the replacement of the window should trigger app transition animation.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700511 private boolean mAnimateReplacingWindow = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800512 // If not null, the window that will be used to replace the old one. This is being set when
513 // the window is added and unset when this window reports its first draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700514 private WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700515 // For the new window in the replacement transition, if we have
516 // requested to replace without animation, then we should
517 // make sure we also don't apply an enter animation for
518 // the new window.
519 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800520 // Whether this window is being moved via the resize API
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700521 private boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800522
Jeff Brownc2932a12014-11-20 18:04:05 -0800523 /**
524 * Wake lock for drawing.
525 * Even though it's slightly more expensive to do so, we will use a separate wake lock
526 * for each app that is requesting to draw while dozing so that we can accurately track
527 * who is preventing the system from suspending.
528 * This lock is only acquired on first use.
529 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700530 private PowerManager.WakeLock mDrawLock;
Jeff Brownc2932a12014-11-20 18:04:05 -0800531
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700532 final private Rect mTmpRect = new Rect();
533
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800534 /**
535 * Whether the window was resized by us while it was gone for layout.
536 */
537 boolean mResizedWhileGone = false;
538
Andrii Kulianeb1d3222016-05-16 15:17:55 -0700539 /** @see #isResizedWhileNotDragResizing(). */
540 private boolean mResizedWhileNotDragResizing;
541
542 /** @see #isResizedWhileNotDragResizingReported(). */
543 private boolean mResizedWhileNotDragResizingReported;
Jorim Jaggif3df0aa2016-04-06 15:56:33 -0700544
Robert Carr6da3cc02016-06-16 15:17:07 -0700545 /**
546 * During seamless rotation we have two phases, first the old window contents
547 * are rotated to look as if they didn't move in the new coordinate system. Then we
548 * have to freeze updates to this layer (to preserve the transformation) until
549 * the resize actually occurs. This is true from when the transformation is set
550 * and false until the transaction to resize is sent.
551 */
552 boolean mSeamlesslyRotated = false;
553
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700554 private static final Region sEmptyRegion = new Region();
555
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700556 /**
Robert Carrc91d1c32017-02-15 19:37:46 -0800557 * Surface insets from the previous call to relayout(), used to track
558 * if we are changing the Surface insets.
559 */
560 final Rect mLastSurfaceInsets = new Rect();
561
562 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700563 * A flag set by the {@link WindowState} parent to indicate that the parent has examined this
564 * {@link WindowState} in its overall drawing context. This book-keeping allows the parent to
565 * make sure all children have been considered.
566 */
567 private boolean mDrawnStateEvaluated;
568
569 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700570 * 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 -0700571 * of z-order and 1 otherwise.
572 */
Griff Hazen51d00d82016-11-22 15:39:24 -0800573 private static final Comparator<WindowState> sWindowSubLayerComparator =
574 new Comparator<WindowState>() {
575 @Override
576 public int compare(WindowState w1, WindowState w2) {
577 final int layer1 = w1.mSubLayer;
578 final int layer2 = w2.mSubLayer;
579 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
580 // We insert the child window into the list ordered by
581 // the sub-layer. For same sub-layers, the negative one
582 // should go below others; the positive one should go
583 // above others.
584 return -1;
585 }
586 return 1;
587 };
588 };
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700589
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800590 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700591 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800592 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800593 mService = service;
594 mSession = s;
595 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800596 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800597 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700598 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700599 mOwnerUid = ownerId;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800600 mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200601 mWindowId = new WindowId(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800602 mAttrs.copyFrom(a);
603 mViewVisibility = viewVisibility;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700604 mPolicy = mService.mPolicy;
605 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800606 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700607 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700608 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700609 if (localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700610 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700611 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800612 try {
613 c.asBinder().linkToDeath(deathRecipient, 0);
614 } catch (RemoteException e) {
615 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700616 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800617 mLayoutAttached = false;
618 mIsImWindow = false;
619 mIsWallpaper = false;
620 mIsFloatingLayer = false;
621 mBaseLayer = 0;
622 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700623 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700624 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800625 return;
626 }
627 mDeathRecipient = deathRecipient;
628
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700629 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800630 // The multiplier here is to reserve space for multiple
631 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800632 mBaseLayer = mPolicy.getWindowLayerLw(parentWindow)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700633 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800634 mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700635 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900636
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700637 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow);
638 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900639
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800640 mLayoutAttached = mAttrs.type !=
641 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700642 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
643 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
644 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800645 } else {
646 // The multiplier here is to reserve space for multiple
647 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800648 mBaseLayer = mPolicy.getWindowLayerLw(this)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700649 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800650 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700651 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800652 mLayoutAttached = false;
653 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
654 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
655 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800656 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700657 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800658
Wale Ogunwale72919d22016-12-08 18:58:50 -0800659 if (mAppToken != null && mAppToken.mShowForAllUsers) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700660 // Windows for apps that can show for all users should also show when the device is
661 // locked.
662 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
Craig Mautner19ab8282014-05-07 10:35:34 -0700663 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800664
Craig Mautner322e4032012-07-13 13:35:20 -0700665 mWinAnimator = new WindowStateAnimator(this);
666 mWinAnimator.mAlpha = a.alpha;
667
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800668 mRequestedWidth = 0;
669 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700670 mLastRequestedWidth = 0;
671 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800672 mXOffset = 0;
673 mYOffset = 0;
674 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800675 mInputWindowHandle = new InputWindowHandle(
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800676 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this, c,
677 getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800678 }
679
680 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700681 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800682 mSession.windowAddedLocked(mAttrs.packageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800683 }
684
Bryce Leed390deb2017-06-22 13:14:28 -0700685 /**
686 * Returns whether this {@link WindowState} has been considered for drawing by its parent.
687 */
Bryce Lee6311c4b2017-07-06 14:09:29 -0700688 boolean getDrawnStateEvaluated() {
Bryce Leed390deb2017-06-22 13:14:28 -0700689 return mDrawnStateEvaluated;
690 }
691
692 /**
693 * Sets whether this {@link WindowState} has been considered for drawing by its parent. Should
694 * be cleared when detached from parent.
695 */
696 void setDrawnStateEvaluated(boolean evaluated) {
697 mDrawnStateEvaluated = evaluated;
698 }
699
700 @Override
701 void onParentSet() {
702 super.onParentSet();
703 setDrawnStateEvaluated(false /*evaluated*/);
704 }
705
Craig Mautnera2c77052012-03-26 12:14:43 -0700706 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800707 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800708 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800709 }
710
711 @Override
712 public String getOwningPackage() {
713 return mAttrs.packageName;
714 }
715
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800716 @Override
717 public boolean canAddInternalSystemWindow() {
718 return mOwnerCanAddInternalSystemWindow;
719 }
720
Jorim Jaggif5834272016-04-04 20:25:41 -0700721 /**
722 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
723 * from {@param frame}. In other words, it applies the insets that would result if
724 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700725 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
726 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700727 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700728 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
729 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
730 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
731 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
732 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700733 frame.inset(left, top, right, bottom);
734 }
735
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800736 @Override
Robert Carr43521762016-10-28 13:15:04 -0700737 public void computeFrameLw(Rect parentFrame, Rect displayFrame, Rect overscanFrame,
738 Rect contentFrame, Rect visibleFrame, Rect decorFrame, Rect stableFrame,
739 Rect outsetFrame) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800740 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700741 // This window is being replaced and either already got information that it's being
742 // removed or we are still waiting for some information. Because of this we don't
743 // want to apply any more changes to it, so it remains in this state until new window
744 // appears.
745 return;
746 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800747 mHaveFrame = true;
748
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700749 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700750 final boolean inFullscreenContainer = inFullscreenContainer();
Robert Carre6275582016-02-29 15:45:45 -0800751 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700752 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800753
Chong Zhangae35fef2016-03-16 15:56:55 -0700754 // If the task has temp inset bounds set, we have to make sure all its windows uses
755 // the temp inset frame. Otherwise different display frames get applied to the main
756 // window and the child window, making them misaligned.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700757 if (inFullscreenContainer) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700758 mInsetFrame.setEmpty();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700759 } else if (task != null && isInMultiWindowMode()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700760 task.getTempInsetBounds(mInsetFrame);
761 }
762
Jorim Jaggif5834272016-04-04 20:25:41 -0700763 // Denotes the actual frame used to calculate the insets and to perform the layout. When
764 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
765 // insets temporarily. By the notion of a task having a different layout frame, we can
766 // achieve that while still moving the task around.
767 final Rect layoutContainingFrame;
768 final Rect layoutDisplayFrame;
769
770 // The offset from the layout containing frame to the actual containing frame.
771 final int layoutXDiff;
772 final int layoutYDiff;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700773 if (inFullscreenContainer || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800774 // We use the parent frame as the containing frame for fullscreen and child windows
Robert Carr43521762016-10-28 13:15:04 -0700775 mContainingFrame.set(parentFrame);
776 mDisplayFrame.set(displayFrame);
777 layoutDisplayFrame = displayFrame;
778 layoutContainingFrame = parentFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700779 layoutXDiff = 0;
780 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800781 } else {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700782 getContainerBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100783 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
784
785 // If the bounds are frozen, we still want to translate the window freely and only
786 // freeze the size.
787 Rect frozen = mAppToken.mFrozenBounds.peek();
788 mContainingFrame.right = mContainingFrame.left + frozen.width();
789 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
790 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800791 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700792 // IME is up and obscuring this window. Adjust the window position so it is visible.
793 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this) {
Winson Chungd73e94b2017-05-31 16:25:30 -0700794 final int stackId = getStackId();
795 if (stackId == FREEFORM_WORKSPACE_STACK_ID
796 && mContainingFrame.bottom > contentFrame.bottom) {
797 // In freeform we want to move the top up directly.
798 // TODO: Investigate why this is contentFrame not parentFrame.
799 mContainingFrame.top -= mContainingFrame.bottom - contentFrame.bottom;
800 } else if (stackId != PINNED_STACK_ID
801 && mContainingFrame.bottom > parentFrame.bottom) {
802 // But in docked we want to behave like fullscreen and behave as if the task
803 // were given smaller bounds for the purposes of layout. Skip adjustments for
804 // the pinned stack, they are handled separately in the PinnedStackController.
805 mContainingFrame.bottom = parentFrame.bottom;
806 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700807 }
Skuhne81c524a2015-08-12 13:34:14 -0700808
Robert Carre6275582016-02-29 15:45:45 -0800809 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700810 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
811 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800812 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700813 if (mContainingFrame.isEmpty()) {
Robert Carr43521762016-10-28 13:15:04 -0700814 mContainingFrame.set(contentFrame);
Skuhne81c524a2015-08-12 13:34:14 -0700815 }
Doris Liu06d582d2015-06-01 13:18:43 -0700816 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800817 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700818 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
819 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
820 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700821 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
Robert Carr43521762016-10-28 13:15:04 -0700822 subtractInsets(mDisplayFrame, layoutContainingFrame, displayFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700823 if (!layoutInParentFrame()) {
Robert Carr43521762016-10-28 13:15:04 -0700824 subtractInsets(mContainingFrame, layoutContainingFrame, parentFrame, mTmpRect);
825 subtractInsets(mInsetFrame, layoutContainingFrame, parentFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700826 }
Robert Carr43521762016-10-28 13:15:04 -0700827 layoutDisplayFrame = displayFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700828 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700829 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800830
Craig Mautner967212c2013-04-13 21:10:58 -0700831 final int pw = mContainingFrame.width();
832 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800833
Robert Carr43521762016-10-28 13:15:04 -0700834 if (!mParentFrame.equals(parentFrame)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800835 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Robert Carr43521762016-10-28 13:15:04 -0700836 // + " to " + parentFrame);
837 mParentFrame.set(parentFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800838 mContentChanged = true;
839 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700840 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
841 mLastRequestedWidth = mRequestedWidth;
842 mLastRequestedHeight = mRequestedHeight;
843 mContentChanged = true;
844 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800845
Robert Carr43521762016-10-28 13:15:04 -0700846 mOverscanFrame.set(overscanFrame);
847 mContentFrame.set(contentFrame);
848 mVisibleFrame.set(visibleFrame);
849 mDecorFrame.set(decorFrame);
850 mStableFrame.set(stableFrame);
851 final boolean hasOutsets = outsetFrame != null;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700852 if (hasOutsets) {
Robert Carr43521762016-10-28 13:15:04 -0700853 mOutsetFrame.set(outsetFrame);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700854 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800855
Craig Mautnereda67292013-04-28 13:50:14 -0700856 final int fw = mFrame.width();
857 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800858
Jorim Jaggif5834272016-04-04 20:25:41 -0700859 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
860
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700861 // Calculate the outsets before the content frame gets shrinked to the window frame.
862 if (hasOutsets) {
863 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
864 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
865 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
866 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
867 } else {
868 mOutsets.set(0, 0, 0, 0);
869 }
870
Craig Mautnera248eee2013-05-07 11:41:27 -0700871 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800872 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -0800873 if (windowsAreFloating && !mFrame.isEmpty()) {
Robert Carre65a1c42017-02-28 16:52:59 -0800874 // For pinned workspace the frame isn't limited in any particular
875 // way since SystemUI controls the bounds. For freeform however
876 // we want to keep things inside the content frame.
877 final Rect limitFrame = task.inPinnedWorkspace() ? mFrame : mContentFrame;
Skuhne81c524a2015-08-12 13:34:14 -0700878 // Keep the frame out of the blocked system area, limit it in size to the content area
879 // and make sure that there is always a minimum visible so that the user can drag it
880 // into a usable area..
Robert Carre65a1c42017-02-28 16:52:59 -0800881 final int height = Math.min(mFrame.height(), limitFrame.height());
882 final int width = Math.min(limitFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700883 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +0900884 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
885 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
886 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
887 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Robert Carre65a1c42017-02-28 16:52:59 -0800888 final int top = Math.max(limitFrame.top,
889 Math.min(mFrame.top, limitFrame.bottom - minVisibleHeight));
890 final int left = Math.max(limitFrame.left + minVisibleWidth - width,
891 Math.min(mFrame.left, limitFrame.right - minVisibleWidth));
Skuhne81c524a2015-08-12 13:34:14 -0700892 mFrame.set(left, top, left + width, top + height);
893 mContentFrame.set(mFrame);
894 mVisibleFrame.set(mContentFrame);
895 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700896 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700897 dc.getDockedDividerController().positionDockedStackedDivider(mFrame);
Jorim Jaggi192086e2016-03-11 17:17:03 +0100898 mContentFrame.set(mFrame);
899 if (!mFrame.equals(mLastFrame)) {
900 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800901 }
Skuhne81c524a2015-08-12 13:34:14 -0700902 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -0700903 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
904 Math.max(mContentFrame.top, mFrame.top),
905 Math.min(mContentFrame.right, mFrame.right),
906 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800907
Jorim Jaggi656f6502016-04-11 21:08:17 -0700908 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
909 Math.max(mVisibleFrame.top, mFrame.top),
910 Math.min(mVisibleFrame.right, mFrame.right),
911 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800912
Jorim Jaggi656f6502016-04-11 21:08:17 -0700913 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
914 Math.max(mStableFrame.top, mFrame.top),
915 Math.min(mStableFrame.right, mFrame.right),
916 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700917 }
Adrian Roosfa104232014-06-20 16:10:14 -0700918
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700919 if (inFullscreenContainer && !windowsAreFloating) {
Jorim Jaggi899327f2016-02-25 20:44:18 -0500920 // Windows that are not fullscreen can be positioned outside of the display frame,
921 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -0700922 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
923 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
924 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
925 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800926 }
Craig Mautnereda67292013-04-28 13:50:14 -0700927
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100928 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100929 // For the docked divider, we calculate the stable insets like a full-screen window
930 // so it can use it to calculate the snap positions.
931 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
932 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
933 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
934 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800935
936 // The divider doesn't care about insets in any case, so set it to empty so we don't
937 // trigger a relayout when moving it.
938 mContentInsets.setEmpty();
939 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100940 } else {
Andrii Kuliand9003372016-04-04 17:46:59 -0700941 getDisplayContent().getLogicalDisplayRect(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700942 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
943 // non-fullscreen mode.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700944 boolean overrideRightInset = !windowsAreFloating && !inFullscreenContainer
945 && mFrame.right > mTmpRect.right;
946 boolean overrideBottomInset = !windowsAreFloating && !inFullscreenContainer
947 && mFrame.bottom > mTmpRect.bottom;
Jorim Jaggi656f6502016-04-11 21:08:17 -0700948 mContentInsets.set(mContentFrame.left - mFrame.left,
949 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700950 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700951 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700952 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700953 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800954
Jorim Jaggi656f6502016-04-11 21:08:17 -0700955 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
956 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700957 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700958 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700959 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700960 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800961
Jorim Jaggi656f6502016-04-11 21:08:17 -0700962 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
963 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700964 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700965 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700966 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700967 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100968 }
Adrian Roosfa104232014-06-20 16:10:14 -0700969
Jorim Jaggi656f6502016-04-11 21:08:17 -0700970 // Offset the actual frame by the amount layout frame is off.
971 mFrame.offset(-layoutXDiff, -layoutYDiff);
972 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -0700973 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
974 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
975 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
976
Craig Mautnereda67292013-04-28 13:50:14 -0700977 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400978 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700979 // If there is a size compatibility scale being applied to the
980 // window, we need to apply this to its insets so that they are
981 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700982 mOverscanInsets.scale(mInvGlobalScale);
983 mContentInsets.scale(mInvGlobalScale);
984 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700985 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700986 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700987
988 // Also the scaled frame that we report to the app needs to be
989 // adjusted to be in its coordinate space.
990 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400991 }
992
Craig Mautnereda67292013-04-28 13:50:14 -0700993 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800994 final DisplayContent displayContent = getDisplayContent();
995 if (displayContent != null) {
996 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwale0303c572016-10-20 10:16:29 -0700997 getDisplayContent().mWallpaperController.updateWallpaperOffset(
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700998 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800999 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001000 }
1001
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001002 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001003 "Resolving (mRequestedWidth="
1004 + mRequestedWidth + ", mRequestedheight="
1005 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
1006 + "): frame=" + mFrame.toShortString()
1007 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07001008 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -07001009 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001010 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001011 }
1012
Craig Mautnera2c77052012-03-26 12:14:43 -07001013 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001014 public Rect getFrameLw() {
1015 return mFrame;
1016 }
1017
Craig Mautnera2c77052012-03-26 12:14:43 -07001018 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001019 public Point getShownPositionLw() {
1020 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001021 }
1022
Craig Mautnera2c77052012-03-26 12:14:43 -07001023 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001024 public Rect getDisplayFrameLw() {
1025 return mDisplayFrame;
1026 }
1027
Craig Mautnera2c77052012-03-26 12:14:43 -07001028 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001029 public Rect getOverscanFrameLw() {
1030 return mOverscanFrame;
1031 }
1032
1033 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001034 public Rect getContentFrameLw() {
1035 return mContentFrame;
1036 }
1037
Craig Mautnera2c77052012-03-26 12:14:43 -07001038 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001039 public Rect getVisibleFrameLw() {
1040 return mVisibleFrame;
1041 }
1042
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001043 Rect getStableFrameLw() {
1044 return mStableFrame;
1045 }
1046
Craig Mautnera2c77052012-03-26 12:14:43 -07001047 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001048 public boolean getGivenInsetsPendingLw() {
1049 return mGivenInsetsPending;
1050 }
1051
Craig Mautnera2c77052012-03-26 12:14:43 -07001052 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001053 public Rect getGivenContentInsetsLw() {
1054 return mGivenContentInsets;
1055 }
1056
Craig Mautnera2c77052012-03-26 12:14:43 -07001057 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001058 public Rect getGivenVisibleInsetsLw() {
1059 return mGivenVisibleInsets;
1060 }
1061
Craig Mautnera2c77052012-03-26 12:14:43 -07001062 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001063 public WindowManager.LayoutParams getAttrs() {
1064 return mAttrs;
1065 }
1066
Craig Mautner812d2ca2012-09-27 15:35:34 -07001067 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001068 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001069 return getDisplayContent().getNeedsMenu(this, bottom);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001070 }
1071
Craig Mautner19d59bc2012-09-04 11:15:56 -07001072 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001073 public int getSystemUiVisibility() {
1074 return mSystemUiVisibility;
1075 }
1076
Craig Mautner19d59bc2012-09-04 11:15:56 -07001077 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001078 public int getSurfaceLayer() {
1079 return mLayer;
1080 }
1081
Craig Mautner812d2ca2012-09-27 15:35:34 -07001082 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001083 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001084 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001085 }
1086
1087 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001088 public IApplicationToken getAppToken() {
1089 return mAppToken != null ? mAppToken.appToken : null;
1090 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001091
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001092 @Override
1093 public boolean isVoiceInteraction() {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001094 return mAppToken != null && mAppToken.mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001095 }
1096
Robert Carr31aa98b2016-07-20 15:29:03 -07001097 boolean setReportResizeHints() {
Craig Mautner4c5eb222013-11-18 12:59:05 -08001098 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1099 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1100 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001101 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001102 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
Robert Carr31aa98b2016-07-20 15:29:03 -07001103 mFrameSizeChanged |= (mLastFrame.width() != mFrame.width()) ||
1104 (mLastFrame.height() != mFrame.height());
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001105 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
Robert Carr31aa98b2016-07-20 15:29:03 -07001106 || mOutsetsChanged || mFrameSizeChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001107 }
1108
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001109 /**
1110 * Adds the window to the resizing list if any of the parameters we use to track the window
1111 * dimensions or insets have changed.
1112 */
1113 void updateResizingWindowIfNeeded() {
1114 final WindowStateAnimator winAnimator = mWinAnimator;
1115 if (!mHasSurface || mService.mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
1116 return;
1117 }
1118
1119 final Task task = getTask();
1120 // In the case of stack bound animations, the window frames will update (unlike other
1121 // animations which just modify various transformation properties). We don't want to
1122 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1123 // the frame may not correspond to the surface size or the onscreen area at various
1124 // phases in the animation, and the client will become sad and confused.
Winson Chung40a5f932017-04-13 16:39:36 -07001125 if (task != null && task.mStack.isAnimatingBounds()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001126 return;
1127 }
1128
1129 setReportResizeHints();
1130 boolean configChanged = isConfigChanged();
1131 if (DEBUG_CONFIGURATION && configChanged) {
1132 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1133 }
1134
1135 final boolean dragResizingChanged = isDragResizeChanged()
1136 && !isDragResizingChangeReported();
1137
1138 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
1139 + " dragResizingChanged=" + dragResizingChanged + " last=" + mLastFrame
1140 + " frame=" + mFrame);
1141
1142 // We update mLastFrame always rather than in the conditional with the last inset
1143 // variables, because mFrameSizeChanged only tracks the width and height changing.
1144 mLastFrame.set(mFrame);
1145
1146 if (mContentInsetsChanged
1147 || mVisibleInsetsChanged
1148 || winAnimator.mSurfaceResized
1149 || mOutsetsChanged
1150 || mFrameSizeChanged
1151 || configChanged
1152 || dragResizingChanged
Andrii Kulianb2e37802017-01-11 00:36:44 -08001153 || !isResizedWhileNotDragResizingReported()
1154 || mReportOrientationChanged) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001155 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1156 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
1157 + " contentInsetsChanged=" + mContentInsetsChanged
1158 + " " + mContentInsets.toShortString()
1159 + " visibleInsetsChanged=" + mVisibleInsetsChanged
1160 + " " + mVisibleInsets.toShortString()
1161 + " stableInsetsChanged=" + mStableInsetsChanged
1162 + " " + mStableInsets.toShortString()
1163 + " outsetsChanged=" + mOutsetsChanged
1164 + " " + mOutsets.toShortString()
1165 + " surfaceResized=" + winAnimator.mSurfaceResized
1166 + " configChanged=" + configChanged
1167 + " dragResizingChanged=" + dragResizingChanged
1168 + " resizedWhileNotDragResizingReported="
Andrii Kulianb2e37802017-01-11 00:36:44 -08001169 + isResizedWhileNotDragResizingReported()
1170 + " reportOrientationChanged=" + mReportOrientationChanged);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001171 }
1172
1173 // If it's a dead window left on screen, and the configuration changed, there is nothing
1174 // we can do about it. Remove the window now.
1175 if (mAppToken != null && mAppDied) {
1176 mAppToken.removeDeadWindows();
1177 return;
1178 }
1179
Jorim Jaggidc9385a2017-05-13 02:00:31 +02001180 updateLastInsetValues();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001181 mService.makeWindowFreezingScreenIfNeededLocked(this);
1182
1183 // If the orientation is changing, or we're starting or ending a drag resizing action,
1184 // then we need to hold off on unfreezing the display until this window has been
1185 // redrawn; to do that, we need to go through the process of getting informed by the
1186 // application when it has finished drawing.
Bryce Lee8c3cf382017-07-06 19:47:10 -07001187 if (getOrientationChanging() || dragResizingChanged
1188 || isResizedWhileNotDragResizing()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001189 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
1190 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1191 + ", mDrawState=DRAW_PENDING in " + this
1192 + ", surfaceController " + winAnimator.mSurfaceController);
1193 }
1194 winAnimator.mDrawState = DRAW_PENDING;
1195 if (mAppToken != null) {
1196 mAppToken.clearAllDrawn();
1197 }
1198 }
1199 if (!mService.mResizingWindows.contains(this)) {
1200 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
1201 mService.mResizingWindows.add(this);
1202 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07001203 } else if (getOrientationChanging()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001204 if (isDrawnLw()) {
1205 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1206 + this + ", surfaceController " + winAnimator.mSurfaceController);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001207 setOrientationChanging(false);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001208 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1209 - mService.mDisplayFreezeTime);
1210 }
1211 }
1212 }
1213
Bryce Lee8c3cf382017-07-06 19:47:10 -07001214 boolean getOrientationChanging() {
1215 // In addition to the local state flag, we must also consider the difference in the last
1216 // reported configuration vs. the current state. If the client code has not been informed of
1217 // the change, logic dependent on having finished processing the orientation, such as
1218 // unfreezing, could be improperly triggered.
1219 // TODO(b/62846907): Checking against {@link mLastReportedConfiguration} could be flaky as
1220 // this is not necessarily what the client has processed yet. Find a
1221 // better indicator consistent with the client.
Robert Carr926643f2017-08-02 12:01:12 -07001222 return (mOrientationChanging || (isVisible()
1223 && getConfiguration().orientation != mLastReportedConfiguration.orientation))
1224 && !mSeamlesslyRotated;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001225 }
1226
1227 void setOrientationChanging(boolean changing) {
1228 mOrientationChanging = changing;
1229 }
1230
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001231 DisplayContent getDisplayContent() {
1232 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001233 }
1234
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001235 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001236 final DisplayContent displayContent = getDisplayContent();
1237 return displayContent != null ? displayContent.getDisplayInfo() : null;
1238 }
1239
Jorim Jaggife762342016-10-13 14:33:27 +02001240 @Override
1241 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001242 final DisplayContent displayContent = getDisplayContent();
1243 if (displayContent == null) {
1244 return -1;
1245 }
1246 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001247 }
1248
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001249 Task getTask() {
Bryce Lee6d410262017-02-28 15:30:17 -08001250 return mAppToken != null ? mAppToken.getTask() : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001251 }
1252
1253 TaskStack getStack() {
1254 Task task = getTask();
1255 if (task != null) {
1256 if (task.mStack != null) {
1257 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001258 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001259 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001260 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1261 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001262 final DisplayContent dc = getDisplayContent();
1263 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001264 }
1265
Skuhnef932e562015-08-20 12:07:30 -07001266 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001267 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001268 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001269 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001270 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001271 final Task task = getTask();
1272 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001273 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001274 mTmpRect.setEmpty();
1275 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001276 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001277 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001278 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001279 } else {
1280 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001281 }
1282 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001283
Chong Zhang9184ec62015-09-24 12:32:21 -07001284 bounds.set(mVisibleFrame);
1285 if (intersectWithStackBounds) {
1286 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001287 }
1288
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001289 if (bounds.isEmpty()) {
1290 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001291 if (intersectWithStackBounds) {
1292 bounds.intersect(mTmpRect);
1293 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001294 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001295 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001296 }
1297
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001298 public long getInputDispatchingTimeoutNanos() {
1299 return mAppToken != null
Wale Ogunwale72919d22016-12-08 18:58:50 -08001300 ? mAppToken.mInputDispatchingTimeoutNanos
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001301 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1302 }
1303
Craig Mautnere8552142012-11-07 13:55:47 -08001304 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001305 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001306 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001307 }
1308
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001309 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1310 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1311 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1312 if (dtdx < -.000001f || dtdx > .000001f) return false;
1313 if (dsdy < -.000001f || dsdy > .000001f) return false;
1314 return true;
1315 }
1316
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001317 void prelayout() {
1318 if (mEnforceSizeCompat) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001319 mGlobalScale = getDisplayContent().mCompatibleScreenScale;
1320 mInvGlobalScale = 1 / mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001321 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001322 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001323 }
1324 }
1325
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001326 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001327 boolean hasContentToDisplay() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001328 // If we're animating with a saved surface, we're already visible.
1329 // Return true so that the alpha doesn't get cleared.
1330 if (!mAppFreezing && isDrawnLw()
1331 && (mViewVisibility == View.VISIBLE || isAnimatingWithSavedSurface()
1332 || (mWinAnimator.isAnimationSet() && !mService.mAppTransition.isTransitionSet()))) {
1333 return true;
1334 }
1335
Wale Ogunwale44f21802016-09-02 12:49:48 -07001336 return super.hasContentToDisplay();
1337 }
1338
1339 @Override
1340 boolean isVisible() {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001341 return wouldBeVisibleIfPolicyIgnored() && mPolicyVisibility;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001342 }
1343
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001344 /**
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001345 * @return True if the window would be visible if we'd ignore policy visibility, false
1346 * otherwise.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001347 */
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001348 boolean wouldBeVisibleIfPolicyIgnored() {
Jorim Jaggi43530c92017-05-18 01:53:56 +02001349 return mHasSurface && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001350 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001351 }
1352
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001353 @Override
1354 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001355 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001356 }
1357
1358 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001359 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1360 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001361 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001362 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1363 boolean isWinVisibleLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001364 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.mAppAnimator.animating)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001365 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001366 }
1367
1368 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001369 * The same as isVisible(), but follows the current hidden state of the associated app token,
1370 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001371 */
1372 boolean isVisibleNow() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001373 return (!mToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001374 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001375 }
1376
1377 /**
1378 * Can this window possibly be a drag/drop target? The test here is
1379 * a combination of the above "visible now" with the check that the
1380 * Input Manager uses when discarding windows from input consideration.
1381 */
1382 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001383 return isVisibleNow() && !mRemoved
1384 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001385 }
1386
1387 /**
1388 * Same as isVisible(), but we also count it as visible between the
1389 * call to IWindowSession.add() and the first relayout().
1390 */
1391 boolean isVisibleOrAdding() {
1392 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001393 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001394 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001395 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001396 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001397 }
1398
1399 /**
1400 * Is this window currently on-screen? It is on-screen either if it
1401 * is visible or it is currently running an animation before no longer
1402 * being visible.
1403 */
1404 boolean isOnScreen() {
Jorim Jaggiaf221d12016-11-15 14:59:57 -08001405 if (!mHasSurface || mDestroying || !mPolicyVisibility) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001406 return false;
1407 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001408 final AppWindowToken atoken = mAppToken;
1409 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001410 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001411 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001412 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07001413 return !isParentWindowHidden() || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001414 }
1415
1416 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001417 * Whether this window's drawn state might affect the drawn states of the app token.
1418 *
1419 * @param visibleOnly Whether we should consider only the windows that's currently
1420 * visible in layout. If true, windows that has not relayout to VISIBLE
1421 * would always return false.
1422 *
1423 * @return true if the window should be considered while evaluating allDrawn flags.
1424 */
1425 boolean mightAffectAllDrawn(boolean visibleOnly) {
Wale Ogunwale89973222017-04-23 18:39:45 -07001426 final boolean isViewVisible = (mAppToken == null || !mAppToken.isClientHidden())
Chong Zhange292eb32016-05-21 09:23:55 -07001427 && (mViewVisibility == View.VISIBLE) && !mWindowRemovalAllowed;
Jorim Jaggib0d27342016-11-01 16:10:42 -07001428 return (isOnScreen() && (!visibleOnly || isViewVisible)
Chong Zhangfea963e2016-08-15 17:14:16 -07001429 || mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1430 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION)
Chong Zhang8e4bda92016-05-04 15:08:18 -07001431 && !mAnimatingExit && !mDestroying;
1432 }
1433
1434 /**
1435 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1436 * it must be drawn before allDrawn can become true.
1437 */
1438 boolean isInteresting() {
1439 return mAppToken != null && !mAppDied
1440 && (!mAppToken.mAppAnimator.freezingScreen || !mAppFreezing);
1441 }
1442
1443 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001444 * Like isOnScreen(), but we don't return true if the window is part
1445 * of a transition that has not yet been started.
1446 */
1447 boolean isReadyForDisplay() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001448 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001449 return false;
1450 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001451 return mHasSurface && mPolicyVisibility && !mDestroying
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001452 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001453 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001454 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001455 }
1456
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001457 // TODO: Another visibility method that was added late in the release to minimize risk.
1458 @Override
1459 public boolean canAffectSystemUiFlags() {
1460 final boolean shown = mWinAnimator.getShown();
Jorim Jaggic0c93242017-08-04 16:05:02 +02001461
1462 // We only consider the app to be exiting when the animation has started. After the app
1463 // transition is executed the windows are marked exiting before the new windows have been
1464 // shown. Thus, wait considering a window to be exiting after the animation has actually
1465 // started.
1466 final boolean appAnimationStarting = mAppToken != null
1467 && mAppToken.mAppAnimator.isAnimationStarting();
1468 final boolean exitingSelf = mAnimatingExit && (!mWinAnimator.isAnimationStarting()
1469 && !appAnimationStarting);
1470 final boolean appExiting = mAppToken != null && mAppToken.hidden && !appAnimationStarting;
1471
1472 final boolean exiting = exitingSelf || mDestroying || appExiting;
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001473 final boolean translucent = mAttrs.alpha == 0.0f;
1474 return shown && !exiting && !translucent;
1475 }
1476
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001477 /**
1478 * Like isOnScreen, but returns false if the surface hasn't yet
1479 * been drawn.
1480 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001481 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001482 public boolean isDisplayedLw() {
1483 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001484 return isDrawnLw() && mPolicyVisibility
Wale Ogunwale9d147902016-07-16 11:58:55 -07001485 && ((!isParentWindowHidden() &&
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001486 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001487 || mWinAnimator.mAnimating
1488 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001489 }
1490
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001491 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001492 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001493 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001494 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001495 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001496 return mWinAnimator.mAnimation != null
1497 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001498 }
1499
Craig Mautner812d2ca2012-09-27 15:35:34 -07001500 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001501 public boolean isGoneForLayoutLw() {
1502 final AppWindowToken atoken = mAppToken;
1503 return mViewVisibility == View.GONE
1504 || !mRelayoutCalled
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001505 || (atoken == null && mToken.hidden)
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001506 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001507 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001508 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001509 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001510 }
1511
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001512 /**
1513 * Returns true if the window has a surface that it has drawn a
1514 * complete UI in to.
1515 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001516 public boolean isDrawFinishedLw() {
1517 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001518 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1519 || mWinAnimator.mDrawState == READY_TO_SHOW
1520 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001521 }
1522
1523 /**
1524 * Returns true if the window has a surface that it has drawn a
1525 * complete UI in to.
1526 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001527 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001528 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001529 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001530 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001531 }
1532
1533 /**
1534 * Return true if the window is opaque and fully drawn. This indicates
1535 * it may obscure windows behind it.
1536 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001537 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001538 // When there is keyguard, wallpaper could be placed over the secure app
1539 // window but invisible. We need to check wallpaper visibility explicitly
1540 // to determine if it's occluding apps.
1541 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1542 || (mIsWallpaper && mWallpaperVisible))
Craig Mautnera2c77052012-03-26 12:14:43 -07001543 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001544 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001545 }
1546
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001547 @Override
1548 void onMovedByResize() {
1549 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001550 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001551 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001552 }
1553
1554 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1555 boolean changed = false;
1556
1557 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001558 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001559 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1560 }
1561
1562 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1563 // Starting window that's exiting will be removed when the animation finishes.
1564 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1565 // to actually remove it.
1566 if (!visible && isVisibleNow() && mAppToken.mAppAnimator.isAnimating()) {
1567 mAnimatingExit = true;
1568 mRemoveOnExit = true;
1569 mWindowRemovalAllowed = true;
1570 }
1571 return changed;
1572 }
1573
Robert Carrd5c7dd62017-03-08 10:39:30 -08001574 // Next up we will notify the client that it's visibility has changed.
1575 // We need to prevent it from destroying child surfaces until
1576 // the animation has finished.
1577 if (!visible && isVisibleNow()) {
1578 mWinAnimator.detachChildren();
1579 }
1580
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001581 if (visible != isVisibleNow()) {
1582 if (!runningAppAnimation) {
1583 final AccessibilityController accessibilityController =
1584 mService.mAccessibilityController;
1585 final int winTransit = visible ? TRANSIT_ENTER : TRANSIT_EXIT;
1586 mWinAnimator.applyAnimationLocked(winTransit, visible);
1587 //TODO (multidisplay): Magnification is supported only for the default
1588 if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
1589 accessibilityController.onWindowTransitionLocked(this, winTransit);
1590 }
1591 }
1592 changed = true;
1593 setDisplayLayoutNeeded();
1594 }
1595
1596 return changed;
1597 }
1598
1599 boolean onSetAppExiting() {
1600 final DisplayContent displayContent = getDisplayContent();
1601 boolean changed = false;
1602
1603 if (isVisibleNow()) {
1604 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
1605 //TODO (multidisplay): Magnification is supported only for the default
1606 if (mService.mAccessibilityController != null && isDefaultDisplay()) {
1607 mService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
1608 }
1609 changed = true;
1610 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001611 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001612 }
1613 }
1614
1615 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001616 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001617 changed |= c.onSetAppExiting();
1618 }
1619
1620 return changed;
1621 }
1622
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001623 @Override
1624 void onResize() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001625 // Some windows won't go through the resizing process, if they don't have a surface, so
1626 // destroy all saved surfaces here.
1627 destroySavedSurface();
1628
1629 final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
1630 if (mHasSurface && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001631 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001632 resizingWindows.add(this);
1633
1634 // If we are not drag resizing, force recreating of a new surface so updating
1635 // the content and positioning that surface will be in sync.
1636 //
1637 // As we use this flag as a hint to freeze surface boundary updates, we'd like to only
1638 // apply this to TYPE_BASE_APPLICATION, windows of TYPE_APPLICATION like dialogs, could
1639 // appear to not be drag resizing while they resize, but we'd still like to manipulate
1640 // their frame to update crop, etc...
1641 //
1642 // Anyway we don't need to synchronize position and content updates for these
1643 // windows since they aren't at the base layer and could be moved around anyway.
1644 if (!computeDragResizing() && mAttrs.type == TYPE_BASE_APPLICATION &&
Robert Carr8f0a3ad2017-02-15 19:30:28 -08001645 !mWinAnimator.isForceScaled() && !isGoneForLayoutLw() &&
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001646 !getTask().inPinnedWorkspace()) {
1647 setResizedWhileNotDragResizing(true);
1648 }
1649 }
1650 if (isGoneForLayoutLw()) {
1651 mResizedWhileGone = true;
1652 }
1653
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001654 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001655 }
1656
1657 void onUnfreezeBounds() {
1658 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001659 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001660 c.onUnfreezeBounds();
1661 }
1662
1663 if (!mHasSurface) {
1664 return;
1665 }
1666
1667 mLayoutNeeded = true;
1668 setDisplayLayoutNeeded();
1669 if (!mService.mResizingWindows.contains(this)) {
1670 mService.mResizingWindows.add(this);
1671 }
1672 }
1673
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001674 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001675 * If the window has moved due to its containing content frame changing, then notify the
1676 * listeners and optionally animate it. Simply checking a change of position is not enough,
1677 * because being move due to dock divider is not a trigger for animation.
1678 */
1679 void handleWindowMovedIfNeeded() {
1680 if (!hasMoved()) {
1681 return;
1682 }
1683
1684 // Frame has moved, containing content frame has also moved, and we're not currently
1685 // animating... let's do something.
1686 final int left = mFrame.left;
1687 final int top = mFrame.top;
1688 final Task task = getTask();
1689 final boolean adjustedForMinimizedDockOrIme = task != null
1690 && (task.mStack.isAdjustedForMinimizedDockedStack()
1691 || task.mStack.isAdjustedForIme());
Adrian Roose94c15c2017-05-09 13:17:54 -07001692 if (mService.okToAnimate()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001693 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1694 && !isDragResizing() && !adjustedForMinimizedDockOrIme
1695 && (task == null || getTask().mStack.hasMovementAnimations())
1696 && !mWinAnimator.mLastHidden) {
1697 mWinAnimator.setMoveAnimation(left, top);
1698 }
1699
1700 //TODO (multidisplay): Accessibility supported only for the default display.
1701 if (mService.mAccessibilityController != null
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001702 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001703 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
1704 }
1705
1706 try {
1707 mClient.moved(left, top);
1708 } catch (RemoteException e) {
1709 }
1710 mMovedByResize = false;
1711 }
1712
1713 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001714 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001715 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1716 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001717 private boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001718 return mHasSurface && (mContentChanged || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001719 && !mAnimatingExit
Chong Zhangbd0d9372015-12-28 15:18:29 -08001720 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001721 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001722 }
1723
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001724 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001725 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001726 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001727 return false;
1728 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001729 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001730 }
1731
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001732 boolean fillsDisplay() {
1733 final DisplayInfo displayInfo = getDisplayInfo();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001734 return mFrame.left <= 0 && mFrame.top <= 0
1735 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001736 }
1737
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001738 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001739 boolean isConfigChanged() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001740 return !mLastReportedConfiguration.equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001741 }
1742
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001743 void onWindowReplacementTimeout() {
1744 if (mWillReplaceWindow) {
1745 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001746 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001747 // delays removal on certain conditions, which will leave the stale window in the
1748 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1749 //
1750 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001751 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001752 } else {
1753 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001754 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001755 c.onWindowReplacementTimeout();
1756 }
1757 }
1758 }
1759
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001760 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001761 void forceWindowsScaleableInTransaction(boolean force) {
1762 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1763 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1764 }
1765
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001766 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001767 }
1768
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001769 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001770 void removeImmediately() {
1771 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001772
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001773 if (mRemoved) {
1774 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001775 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1776 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001777 return;
1778 }
1779
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001780 mRemoved = true;
1781
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001782 mWillReplaceWindow = false;
1783 if (mReplacementWindow != null) {
1784 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1785 }
1786
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001787 final DisplayContent dc = getDisplayContent();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001788 if (mService.mInputMethodTarget == this) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001789 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001790 }
1791
1792 final int type = mAttrs.type;
1793 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001794 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001795 }
1796 mPolicy.removeWindowLw(this);
1797
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001798 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001799
Craig Mautner96868332012-12-04 14:29:11 -08001800 mWinAnimator.destroyDeferredSurfaceLocked();
1801 mWinAnimator.destroySurfaceLocked();
Wale Ogunwale943002b2017-02-15 19:34:01 -08001802 mSession.windowRemovedLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001803 try {
1804 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1805 } catch (RuntimeException e) {
1806 // Ignore if it has already been removed (usually because
1807 // we are doing this as part of processing a death note.)
1808 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001809
1810 mService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001811 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001812
Wale Ogunwale571771c2016-08-26 13:18:50 -07001813 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001814 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001815 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001816 removeIfPossible(false /*keepVisibleDeadWindow*/);
1817 }
1818
Wale Ogunwale571771c2016-08-26 13:18:50 -07001819 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001820 mWindowRemovalAllowed = true;
1821 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1822 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1823
1824 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1825 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1826 "Starting window removed " + this);
1827
1828 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && this == mService.mCurrentFocus)
1829 Slog.v(TAG_WM, "Remove " + this + " client="
1830 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1831 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1832 + Debug.getCallers(5));
1833
1834 final long origId = Binder.clearCallingIdentity();
1835
1836 disposeInputChannel();
1837
1838 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1839 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1840 + " mAnimatingExit=" + mAnimatingExit
1841 + " mRemoveOnExit=" + mRemoveOnExit
1842 + " mHasSurface=" + mHasSurface
1843 + " surfaceShowing=" + mWinAnimator.getShown()
1844 + " isAnimationSet=" + mWinAnimator.isAnimationSet()
1845 + " app-animation="
1846 + (mAppToken != null ? mAppToken.mAppAnimator.animation : null)
1847 + " mWillReplaceWindow=" + mWillReplaceWindow
1848 + " inPendingTransaction="
1849 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
1850 + " mDisplayFrozen=" + mService.mDisplayFrozen
1851 + " callers=" + Debug.getCallers(6));
1852
1853 // Visibility of the removed window. Will be used later to update orientation later on.
1854 boolean wasVisible = false;
1855
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001856 final int displayId = getDisplayId();
1857
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001858 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1859 // window until the animation is done. If the display is frozen, just remove immediately,
1860 // since the animation wouldn't be seen.
Adrian Roose94c15c2017-05-09 13:17:54 -07001861 if (mHasSurface && mService.okToAnimate()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001862 if (mWillReplaceWindow) {
1863 // This window is going to be replaced. We need to keep it around until the new one
1864 // gets added, then we will get rid of this one.
1865 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1866 "Preserving " + this + " until the new one is " + "added");
1867 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1868 // been removed. We probably need another flag to indicate that window removal
1869 // should be deffered vs. overloading the flag that says we are playing an exit
1870 // animation.
1871 mAnimatingExit = true;
1872 mReplacingRemoveRequested = true;
1873 Binder.restoreCallingIdentity(origId);
1874 return;
1875 }
1876
1877 if (isAnimatingWithSavedSurface() && !mAppToken.allDrawnExcludingSaved) {
1878 // We started enter animation early with a saved surface, now the app asks to remove
1879 // this window. If we remove it now and the app is not yet drawn, we'll show a
1880 // flicker. Delay the removal now until it's really drawn.
1881 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
1882 "removeWindowLocked: delay removal of " + this + " due to early animation");
1883 // Do not set mAnimatingExit to true here, it will cause the surface to be hidden
1884 // immediately after the enter animation is done. If the app is not yet drawn then
1885 // it will show up as a flicker.
1886 setupWindowForRemoveOnExit();
1887 Binder.restoreCallingIdentity(origId);
1888 return;
1889 }
1890 // If we are not currently running the exit animation, we need to see about starting one
1891 wasVisible = isWinVisibleLw();
1892
1893 if (keepVisibleDeadWindow) {
1894 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1895 "Not removing " + this + " because app died while it's visible");
1896
1897 mAppDied = true;
1898 setDisplayLayoutNeeded();
1899 mService.mWindowPlacerLocked.performSurfacePlacement();
1900
1901 // Set up a replacement input channel since the app is now dead.
1902 // We need to catch tapping on the dead window to restart the app.
1903 openInputChannel(null);
1904 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
1905
1906 Binder.restoreCallingIdentity(origId);
1907 return;
1908 }
1909
1910 if (wasVisible) {
1911 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
1912
1913 // Try starting an animation.
1914 if (mWinAnimator.applyAnimationLocked(transit, false)) {
1915 mAnimatingExit = true;
1916 }
1917 //TODO (multidisplay): Magnification is supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001918 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001919 mService.mAccessibilityController.onWindowTransitionLocked(this, transit);
1920 }
1921 }
1922 final boolean isAnimating =
1923 mWinAnimator.isAnimationSet() && !mWinAnimator.isDummyAnimation();
1924 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001925 && mAppToken.isLastWindow(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001926 // We delay the removal of a window if it has a showing surface that can be used to run
1927 // exit animation and it is marked as exiting.
1928 // Also, If isn't the an animating starting window that is the last window in the app.
1929 // We allow the removal of the non-animating starting window now as there is no
1930 // additional window or animation that will trigger its removal.
1931 if (mWinAnimator.getShown() && mAnimatingExit
1932 && (!lastWindowIsStartingWindow || isAnimating)) {
1933 // The exit animation is running or should run... wait for it!
1934 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1935 "Not removing " + this + " due to exit animation ");
1936 setupWindowForRemoveOnExit();
1937 if (mAppToken != null) {
1938 mAppToken.updateReportedVisibilityLocked();
1939 }
1940 Binder.restoreCallingIdentity(origId);
1941 return;
1942 }
1943 }
1944
Wale Ogunwale571771c2016-08-26 13:18:50 -07001945 removeImmediately();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001946 // Removing a visible window will effect the computed orientation
1947 // So just update orientation if needed.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001948 if (wasVisible && mService.updateOrientationFromAppTokensLocked(false, displayId)) {
1949 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001950 }
1951 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
1952 Binder.restoreCallingIdentity(origId);
1953 }
1954
1955 private void setupWindowForRemoveOnExit() {
1956 mRemoveOnExit = true;
1957 setDisplayLayoutNeeded();
1958 // Request a focus update as this window's input channel is already gone. Otherwise
1959 // we could have no focused window in input manager.
1960 final boolean focusChanged = mService.updateFocusedWindowLocked(
1961 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
1962 mService.mWindowPlacerLocked.performSurfacePlacement();
1963 if (focusChanged) {
1964 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
1965 }
1966 }
1967
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001968 void setHasSurface(boolean hasSurface) {
1969 mHasSurface = hasSurface;
1970 }
1971
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001972 int getAnimLayerAdjustment() {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -08001973 if (mIsImWindow && mService.mInputMethodTarget != null) {
Wale Ogunwale455fac52016-07-21 07:24:49 -07001974 final AppWindowToken appToken = mService.mInputMethodTarget.mAppToken;
1975 if (appToken != null) {
Robert Carrdee1b3f2017-02-27 11:33:33 -08001976 return appToken.getAnimLayerAdjustment();
Wale Ogunwale455fac52016-07-21 07:24:49 -07001977 }
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001978 }
Wale Ogunwale455fac52016-07-21 07:24:49 -07001979
Robert Carrdee1b3f2017-02-27 11:33:33 -08001980 return mToken.getAnimLayerAdjustment();
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001981 }
1982
Wale Ogunwalec69694a2016-10-18 13:51:15 -07001983 int getSpecialWindowAnimLayerAdjustment() {
1984 int specialAdjustment = 0;
1985 if (mIsImWindow) {
1986 specialAdjustment = getDisplayContent().mInputMethodAnimLayerAdjustment;
1987 } else if (mIsWallpaper) {
Wale Ogunwale0303c572016-10-20 10:16:29 -07001988 specialAdjustment = getDisplayContent().mWallpaperController.getAnimLayerAdjustment();
Wale Ogunwalec69694a2016-10-18 13:51:15 -07001989 }
1990
1991 return mLayer + specialAdjustment;
1992 }
1993
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001994 boolean canBeImeTarget() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08001995 if (mIsImWindow) {
1996 // IME windows can't be IME targets. IME targets are required to be below the IME
1997 // windows and that wouldn't be possible if the IME window is its own target...silly.
1998 return false;
1999 }
2000
Winson Chung3d0a74a2017-07-12 12:37:19 -07002001 final boolean windowsAreFocusable = mAppToken == null || mAppToken.windowsAreFocusable();
Winson Chungb1549342017-07-11 09:59:56 -07002002 if (!windowsAreFocusable) {
2003 // This window can't be an IME target if the app's windows should not be focusable.
2004 return false;
2005 }
2006
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002007 final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002008 final int type = mAttrs.type;
2009
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002010 // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are set or
2011 // both are cleared...and not a starting window.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002012 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
2013 && type != TYPE_APPLICATION_STARTING) {
2014 return false;
2015 }
2016
2017 if (DEBUG_INPUT_METHOD) {
2018 Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding());
2019 if (!isVisibleOrAdding()) {
2020 Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController
2021 + " relayoutCalled=" + mRelayoutCalled
2022 + " viewVis=" + mViewVisibility
2023 + " policyVis=" + mPolicyVisibility
2024 + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim
2025 + " parentHidden=" + isParentWindowHidden()
2026 + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
2027 if (mAppToken != null) {
2028 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + mAppToken.hiddenRequested);
2029 }
2030 }
2031 }
2032 return isVisibleOrAdding();
2033 }
2034
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002035 void scheduleAnimationIfDimming() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002036 final DisplayContent dc = getDisplayContent();
2037 if (dc == null) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002038 return;
2039 }
Jorim Jaggi1f833082017-08-04 18:06:56 +02002040
2041 // If layout is currently deferred, we want to hold of with updating the layers.
2042 if (mService.mWindowPlacerLocked.isLayoutDeferred()) {
2043 return;
2044 }
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002045 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002046 if (dimLayerUser != null && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator)) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002047 // Force an animation pass just to update the mDimLayer layer.
2048 mService.scheduleAnimationLocked();
2049 }
2050 }
2051
Chong Zhangacf11402015-11-04 16:23:10 -08002052 private final class DeadWindowEventReceiver extends InputEventReceiver {
2053 DeadWindowEventReceiver(InputChannel inputChannel) {
2054 super(inputChannel, mService.mH.getLooper());
2055 }
2056 @Override
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -07002057 public void onInputEvent(InputEvent event, int displayId) {
Chong Zhangacf11402015-11-04 16:23:10 -08002058 finishInputEvent(event, true);
2059 }
2060 }
2061 /**
2062 * Dummy event receiver for windows that died visible.
2063 */
2064 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2065
Chong Zhang112eb8c2015-11-02 11:17:00 -08002066 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002067 if (mInputChannel != null) {
2068 throw new IllegalStateException("Window already has an input channel.");
2069 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002070 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002071 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2072 mInputChannel = inputChannels[0];
2073 mClientChannel = inputChannels[1];
2074 mInputWindowHandle.inputChannel = inputChannels[0];
2075 if (outInputChannel != null) {
2076 mClientChannel.transferTo(outInputChannel);
2077 mClientChannel.dispose();
2078 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002079 } else {
2080 // If the window died visible, we setup a dummy input channel, so that taps
2081 // can still detected by input monitor channel, and we can relaunch the app.
2082 // Create dummy event receiver that simply reports all events as handled.
2083 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002084 }
2085 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002086 }
2087
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002088 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002089 if (mDeadWindowEventReceiver != null) {
2090 mDeadWindowEventReceiver.dispose();
2091 mDeadWindowEventReceiver = null;
2092 }
2093
2094 // unregister server channel first otherwise it complains about broken channel
2095 if (mInputChannel != null) {
2096 mService.mInputManager.unregisterInputChannel(mInputChannel);
2097 mInputChannel.dispose();
2098 mInputChannel = null;
2099 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002100 if (mClientChannel != null) {
2101 mClientChannel.dispose();
2102 mClientChannel = null;
2103 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07002104 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002105 }
2106
Chong Zhang112eb8c2015-11-02 11:17:00 -08002107 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08002108 // When the app is terminated (eg. from Recents), the task might have already been
2109 // removed with the window pending removal. Don't apply dim in such cases, as there
2110 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
2111 final AppWindowToken token = mAppToken;
2112 if (token != null && token.removed) {
2113 return;
2114 }
2115
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002116 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002117 if (!mAnimatingExit && mAppDied) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08002118 // If app died visible, apply a dim over the window to indicate that it's inactive
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002119 dc.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002120 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02002121 && dc != null && !mAnimatingExit && isVisible()) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002122 dc.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07002123 }
2124 }
2125
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002126 private DimLayer.DimLayerUser getDimLayerUser() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002127 Task task = getTask();
2128 if (task != null) {
2129 return task;
2130 }
2131 return getStack();
2132 }
2133
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002134 /** Returns true if the replacement window was removed. */
2135 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2136 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2137 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2138 removeReplacedWindow();
2139 return true;
2140 }
2141
2142 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002143 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002144 if (c.removeReplacedWindowIfNeeded(replacement)) {
2145 return true;
2146 }
2147 }
2148 return false;
2149 }
2150
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002151 private void removeReplacedWindow() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002152 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
2153 if (isDimming()) {
2154 transferDimToReplacement();
Robert Carra1eb4392015-12-10 12:43:51 -08002155 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002156 mWillReplaceWindow = false;
2157 mAnimateReplacingWindow = false;
2158 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002159 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002160 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002161 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002162 }
2163 }
2164
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002165 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2166 boolean replacementSet = false;
2167
2168 if (mWillReplaceWindow && mReplacementWindow == null
2169 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2170
2171 mReplacementWindow = replacementCandidate;
2172 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2173 replacementSet = true;
2174 }
2175
2176 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002177 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002178 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2179 }
2180
2181 return replacementSet;
2182 }
2183
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002184 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002185 final DisplayContent dc = getDisplayContent();
2186 if (dc != null) {
2187 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002188 }
2189 }
2190
Robert Carrfed10072016-05-26 11:48:49 -07002191 // TODO: Strange usage of word workspace here and above.
2192 boolean inPinnedWorkspace() {
2193 final Task task = getTask();
2194 return task != null && task.inPinnedWorkspace();
2195 }
2196
Chong Zhang5117e272016-05-03 12:47:34 -07002197 void applyAdjustForImeIfNeeded() {
2198 final Task task = getTask();
2199 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2200 task.mStack.applyAdjustForImeIfNeeded(task);
2201 }
2202 }
2203
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002204 @Override
2205 void switchUser() {
2206 super.switchUser();
2207 if (isHiddenFromUserLocked()) {
2208 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2209 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
2210 hideLw(false);
2211 }
2212 }
2213
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002214 int getTouchableRegion(Region region, int flags) {
2215 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002216 if (modal && mAppToken != null) {
2217 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002218 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002219 // If this is a modal window we need to dismiss it if it's not full screen and the
2220 // touch happens outside of the frame that displays the content. This means we
2221 // need to intercept touches outside of that window. The dim layer user
2222 // associated with the window (task or stack) will give us the good bounds, as
2223 // they would be used to display the dim layer.
2224 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
2225 if (dimLayerUser != null) {
2226 dimLayerUser.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002227 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002228 getVisibleBounds(mTmpRect);
2229 }
2230 if (inFreeformWorkspace()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002231 // For freeform windows we the touch region to include the whole surface for the
2232 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002233 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2234 final int delta = WindowManagerService.dipToPixel(
2235 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2236 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002237 }
2238 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002239 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002240 } else {
2241 // Not modal or full screen modal
2242 getTouchableRegion(region);
2243 }
2244 return flags;
2245 }
2246
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002247 void checkPolicyVisibilityChange() {
2248 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2249 if (DEBUG_VISIBILITY) {
2250 Slog.v(TAG, "Policy visibility changing after anim in " +
2251 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2252 }
2253 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08002254 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002255 if (!mPolicyVisibility) {
2256 if (mService.mCurrentFocus == this) {
2257 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2258 "setAnimationLocked: setting mFocusMayChange true");
2259 mService.mFocusMayChange = true;
2260 }
2261 // Window is no longer visible -- make sure if we were waiting
2262 // for it to be displayed before enabling the display, that
2263 // we allow the display to be enabled now.
2264 mService.enableScreenIfNeededLocked();
2265 }
2266 }
2267 }
2268
2269 void setRequestedSize(int requestedWidth, int requestedHeight) {
2270 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2271 mLayoutNeeded = true;
2272 mRequestedWidth = requestedWidth;
2273 mRequestedHeight = requestedHeight;
2274 }
2275 }
2276
Bryce Leef858b572017-06-29 14:03:33 -07002277 void prepareWindowToDisplayDuringRelayout(boolean wasVisible) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002278 // We need to turn on screen regardless of visibility.
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002279 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
2280 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
2281 mTurnOnScreen = true;
2282 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002283
2284 // If we were already visible, skip rest of preparation.
2285 if (wasVisible) {
2286 if (DEBUG_VISIBILITY) Slog.v(TAG,
2287 "Already visible and does not turn on screen, skip preparing: " + this);
2288 return;
2289 }
2290
2291 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2292 == SOFT_INPUT_ADJUST_RESIZE) {
2293 mLayoutNeeded = true;
2294 }
2295
Adrian Roose94c15c2017-05-09 13:17:54 -07002296 if (isDrawnLw() && mService.okToAnimate()) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002297 mWinAnimator.applyEnterAnimationLocked();
2298 }
Bryce Leef858b572017-06-29 14:03:33 -07002299 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002300
Bryce Leef858b572017-06-29 14:03:33 -07002301 void getMergedConfiguration(MergedConfiguration outConfiguration) {
2302 final Configuration globalConfig = mService.mRoot.getConfiguration();
2303 final Configuration overrideConfig = getMergedOverrideConfiguration();
2304 outConfiguration.setConfiguration(globalConfig, overrideConfig);
2305 }
2306
2307 void setReportedConfiguration(MergedConfiguration config) {
2308 mLastReportedConfiguration.setTo(config.getMergedConfiguration());
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002309 }
2310
2311 void adjustStartingWindowFlags() {
2312 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2313 && mAppToken.startingWindow != null) {
2314 // Special handling of starting window over the base
2315 // window of the app: propagate lock screen flags to it,
2316 // to provide the correct semantics while starting.
2317 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2318 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2319 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2320 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2321 }
2322 }
2323
2324 void setWindowScale(int requestedWidth, int requestedHeight) {
2325 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2326
2327 if (scaledWindow) {
2328 // requested{Width|Height} Surface's physical size
2329 // attrs.{width|height} Size on screen
2330 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2331 mHScale = (mAttrs.width != requestedWidth) ?
2332 (mAttrs.width / (float)requestedWidth) : 1.0f;
2333 mVScale = (mAttrs.height != requestedHeight) ?
2334 (mAttrs.height / (float)requestedHeight) : 1.0f;
2335 } else {
2336 mHScale = mVScale = 1;
2337 }
2338 }
2339
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002340 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002341 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002342 public void binderDied() {
2343 try {
2344 synchronized(mService.mWindowMap) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002345 final WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002346 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002347 if (win != null) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002348 final DisplayContent dc = getDisplayContent();
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002349 if (win.mAppToken != null && win.mAppToken.findMainWindow() == win) {
2350 mService.mTaskSnapshotController.onAppDied(win.mAppToken);
2351 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002352 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002353 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2354 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002355 // just in case they have the divider at an unstable position. Better
2356 // also reset drag resizing state, because the owner can't do it
2357 // anymore.
Wale Ogunwale1666e312016-12-16 11:27:18 -08002358 final TaskStack stack = dc.getDockedStackIgnoringVisibility();
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002359 if (stack != null) {
2360 stack.resetDockedStackToMiddle();
2361 }
Jorim Jaggidcb68142016-02-09 21:51:30 -08002362 mService.setDockedStackResizing(false);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002363 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002364 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002365 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002366 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002367 }
2368 }
2369 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002370 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002371 }
2372 }
2373 }
2374
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002375 /**
2376 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2377 * because we want to preserve its location on screen to be re-activated later when the user
2378 * interacts with it.
2379 */
2380 boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwale89973222017-04-23 18:39:45 -07002381 if (!isWinVisibleLw() || mAppToken == null || mAppToken.isClientHidden()) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002382 // Not a visible app window or the app isn't dead.
2383 return false;
2384 }
2385
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002386 if (mAttrs.token != mClient.asBinder()) {
2387 // The window was add by a client using another client's app token. We don't want to
2388 // keep the dead window around for this case since this is meant for 'real' apps.
2389 return false;
2390 }
2391
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002392 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2393 // We don't keep starting windows since they were added by the window manager before
2394 // the app even launched.
2395 return false;
2396 }
2397
2398 final TaskStack stack = getStack();
2399 return stack != null && StackId.keepVisibleDeadAppWindowOnScreen(stack.mStackId);
2400 }
2401
Wale Ogunwaled045c822015-12-02 09:14:28 -08002402 /** @return true if this window desires key events. */
2403 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002404 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002405 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002406 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002407 && (mAppToken == null || mAppToken.windowsAreFocusable())
Matthew Nge15352e2016-12-20 15:36:29 -08002408 && !canReceiveTouchInput();
2409 }
2410
2411 /** @return true if this window desires touch events. */
2412 boolean canReceiveTouchInput() {
Bryce Lee6d410262017-02-28 15:30:17 -08002413 return mAppToken != null && mAppToken.getTask() != null
2414 && mAppToken.getTask().mStack.shouldIgnoreInput();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002415 }
2416
Craig Mautner749a7bb2012-04-02 13:49:53 -07002417 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002418 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002419 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002420 }
2421
Craig Mautner749a7bb2012-04-02 13:49:53 -07002422 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002423 public boolean showLw(boolean doAnimation) {
2424 return showLw(doAnimation, true);
2425 }
2426
2427 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002428 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002429 return false;
2430 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002431 if (!mAppOpVisibility) {
2432 // Being hidden due to app op request.
2433 return false;
2434 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002435 if (mPermanentlyHidden) {
2436 // Permanently hidden until the app exists as apps aren't prepared
2437 // to handle their windows being removed from under them.
2438 return false;
2439 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002440 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002441 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002442 return false;
2443 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002444 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002445 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002446 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07002447 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Adrian Roose94c15c2017-05-09 13:17:54 -07002448 if (!mService.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002449 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07002450 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002451 // Check for the case where we are currently visible and
2452 // not animating; we do not want to do animation at such a
2453 // point to become visible when we already are.
2454 doAnimation = false;
2455 }
2456 }
2457 mPolicyVisibility = true;
2458 mPolicyVisibilityAfterAnim = true;
2459 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002460 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002461 }
2462 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002463 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002464 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002465 if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) {
2466 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2467 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002468 return true;
2469 }
2470
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002471 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002472 public boolean hideLw(boolean doAnimation) {
2473 return hideLw(doAnimation, true);
2474 }
2475
2476 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2477 if (doAnimation) {
Adrian Roose94c15c2017-05-09 13:17:54 -07002478 if (!mService.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002479 doAnimation = false;
2480 }
2481 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002482 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002483 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002484 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002485 return false;
2486 }
2487 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002488 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07002489 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002490 doAnimation = false;
2491 }
2492 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002493 mPolicyVisibilityAfterAnim = false;
2494 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002495 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002496 mPolicyVisibility = false;
2497 // Window is no longer visible -- make sure if we were waiting
2498 // for it to be displayed before enabling the display, that
2499 // we allow the display to be enabled now.
2500 mService.enableScreenIfNeededLocked();
2501 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002502 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002503 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002504 mService.mFocusMayChange = true;
2505 }
2506 }
2507 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002508 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002509 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002510 if (mService.mCurrentFocus == this) {
2511 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2512 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002513 return true;
2514 }
2515
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002516 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002517 if (mAppOpVisibility != state) {
2518 mAppOpVisibility = state;
2519 if (state) {
2520 // If the policy visibility had last been to hide, then this
2521 // will incorrectly show at this point since we lost that
2522 // information. Not a big deal -- for the windows that have app
2523 // ops modifies they should only be hidden by policy due to the
2524 // lock screen, and the user won't be changing this if locked.
2525 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002526 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002527 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002528 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002529 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002530 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002531 }
2532
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002533 public void hidePermanentlyLw() {
2534 if (!mPermanentlyHidden) {
2535 mPermanentlyHidden = true;
2536 hideLw(true, true);
2537 }
2538 }
2539
Jeff Brownc2932a12014-11-20 18:04:05 -08002540 public void pokeDrawLockLw(long timeout) {
2541 if (isVisibleOrAdding()) {
2542 if (mDrawLock == null) {
2543 // We want the tag name to be somewhat stable so that it is easier to correlate
2544 // in wake lock statistics. So in particular, we don't want to include the
2545 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002546 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08002547 mDrawLock = mService.mPowerManager.newWakeLock(
2548 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
2549 mDrawLock.setReferenceCounted(false);
2550 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2551 }
2552 // Each call to acquire resets the timeout.
2553 if (DEBUG_POWER) {
2554 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2555 + mAttrs.packageName);
2556 }
2557 mDrawLock.acquire(timeout);
2558 } else if (DEBUG_POWER) {
2559 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2560 + "owned by " + mAttrs.packageName);
2561 }
2562 }
2563
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002564 @Override
2565 public boolean isAlive() {
2566 return mClient.asBinder().isBinderAlive();
2567 }
2568
Craig Mautnera987d432012-10-11 14:07:58 -07002569 boolean isClosing() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002570 return mAnimatingExit || (mService.mClosingApps.contains(mAppToken));
Craig Mautnera987d432012-10-11 14:07:58 -07002571 }
2572
Chong Zhangbef461f2015-10-27 11:38:24 -07002573 boolean isAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002574 return mAnimatingWithSavedSurface;
2575 }
2576
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002577 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002578 boolean isAnimating() {
2579 if (mWinAnimator.isAnimationSet() || mAnimatingExit) {
2580 return true;
2581 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002582 return super.isAnimating();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002583 }
2584
Chong Zhang8e4bda92016-05-04 15:08:18 -07002585 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002586 if (mAnimatingWithSavedSurface
2587 && (mViewVisibility != View.VISIBLE || mWindowRemovalAllowed)) {
2588 return true;
2589 }
2590 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002591 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002592 if (c.isAnimatingInvisibleWithSavedSurface()) {
2593 return true;
2594 }
2595 }
2596 return false;
2597 }
2598
2599 void stopUsingSavedSurface() {
2600 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002601 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002602 c.stopUsingSavedSurface();
2603 }
2604
2605 if (!isAnimatingInvisibleWithSavedSurface()) {
2606 return;
2607 }
2608
2609 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG, "stopUsingSavedSurface: " + this);
2610 clearAnimatingWithSavedSurface();
2611 mDestroying = true;
2612 mWinAnimator.hide("stopUsingSavedSurface");
Wale Ogunwale0303c572016-10-20 10:16:29 -07002613 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002614 }
2615
2616 void markSavedSurfaceExiting() {
2617 if (isAnimatingInvisibleWithSavedSurface()) {
2618 mAnimatingExit = true;
2619 mWinAnimator.mAnimating = true;
2620 }
2621 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002622 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002623 c.markSavedSurfaceExiting();
2624 }
2625 }
2626
2627 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2628 animators.add(mWinAnimator);
2629
2630 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002631 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002632 c.addWinAnimatorToList(animators);
2633 }
2634 }
2635
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002636 void sendAppVisibilityToClients() {
2637 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002638
Wale Ogunwale89973222017-04-23 18:39:45 -07002639 final boolean clientHidden = mAppToken.isClientHidden();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002640 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2641 // Don't hide the starting window.
2642 return;
2643 }
2644
Wale Ogunwale89973222017-04-23 18:39:45 -07002645 if (clientHidden) {
2646 // Once we are notifying the client that it's visibility has changed, we need to prevent
2647 // it from destroying child surfaces until the animation has finished. We do this by
2648 // detaching any surface control the client added from the client.
2649 for (int i = mChildren.size() - 1; i >= 0; --i) {
2650 final WindowState c = mChildren.get(i);
2651 c.mWinAnimator.detachChildren();
2652 }
2653
2654 mWinAnimator.detachChildren();
2655 }
2656
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002657 try {
2658 if (DEBUG_VISIBILITY) Slog.v(TAG,
2659 "Setting visibility of " + this + ": " + (!clientHidden));
2660 mClient.dispatchAppVisibility(!clientHidden);
2661 } catch (RemoteException e) {
2662 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002663 }
2664
Chong Zhang92147042016-05-09 12:47:11 -07002665 public void setVisibleBeforeClientHidden() {
2666 mWasVisibleBeforeClientHidden |=
2667 (mViewVisibility == View.VISIBLE || mAnimatingWithSavedSurface);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002668
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002669 super.setVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -07002670 }
2671
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002672 public void clearWasVisibleBeforeClientHidden() {
Chong Zhang92147042016-05-09 12:47:11 -07002673 mWasVisibleBeforeClientHidden = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002674 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002675 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002676 c.clearWasVisibleBeforeClientHidden();
2677 }
Chong Zhang92147042016-05-09 12:47:11 -07002678 }
2679
2680 public boolean wasVisibleBeforeClientHidden() {
2681 return mWasVisibleBeforeClientHidden;
Chong Zhangbef461f2015-10-27 11:38:24 -07002682 }
2683
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002684 void onStartFreezingScreen() {
2685 mAppFreezing = true;
2686 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002687 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002688 c.onStartFreezingScreen();
2689 }
2690 }
2691
2692 boolean onStopFreezingScreen() {
2693 boolean unfrozeWindows = false;
2694 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002695 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002696 unfrozeWindows |= c.onStopFreezingScreen();
2697 }
2698
2699 if (!mAppFreezing) {
2700 return unfrozeWindows;
2701 }
2702
Wale Ogunwale953171d2016-09-30 09:17:30 -07002703 mAppFreezing = false;
2704
Bryce Lee8c3cf382017-07-06 19:47:10 -07002705 if (mHasSurface && !getOrientationChanging()
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002706 && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
2707 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
Bryce Lee8c3cf382017-07-06 19:47:10 -07002708 setOrientationChanging(true);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002709 mService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002710 }
2711 mLastFreezeDuration = 0;
2712 setDisplayLayoutNeeded();
2713 return true;
2714 }
2715
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002716 private boolean shouldSaveSurface() {
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002717 if (mWinAnimator.mSurfaceController == null) {
2718 // Don't bother if the surface controller is gone for any reason.
2719 return false;
2720 }
2721
Chong Zhang92147042016-05-09 12:47:11 -07002722 if (!mWasVisibleBeforeClientHidden) {
2723 return false;
2724 }
2725
Wale Ogunwale945d1972016-03-23 13:16:41 -07002726 if ((mAttrs.flags & FLAG_SECURE) != 0) {
2727 // We don't save secure surfaces since their content shouldn't be shown while the app
2728 // isn't on screen and content might leak through during the transition animation with
2729 // saved surface.
2730 return false;
2731 }
2732
Jorim Jaggi02886a82016-12-06 09:10:06 -08002733 if (isLowRamDeviceStatic()) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002734 // Don't save surfaces on Svelte devices.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002735 return false;
2736 }
2737
Jorim Jaggiab7ad382016-10-26 18:22:04 -07002738 final Task task = getTask();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002739 final AppWindowToken taskTop = task.getTopVisibleAppToken();
2740 if (taskTop != null && taskTop != mAppToken) {
2741 // Don't save if the window is not the topmost window.
2742 return false;
2743 }
2744
Jorim Jaggi8fa45222016-02-19 19:54:39 -08002745 if (mResizedWhileGone) {
2746 // Somebody resized our window while we were gone for layout, which means that the
2747 // client got an old size, so we have an outdated surface here.
2748 return false;
2749 }
2750
Robert Carr7098dbd2016-02-01 12:31:01 -08002751 if (DEBUG_DISABLE_SAVING_SURFACES) {
2752 return false;
2753 }
2754
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002755 return mAppToken.shouldSaveSurface();
2756 }
2757
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002758 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2759 boolean destroyedSomething = false;
2760 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002761 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002762 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2763 }
2764
Robert Carrdb2f6e62017-03-01 20:17:58 -08002765 if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) {
2766 return destroyedSomething;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002767 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08002768
2769 if (appStopped || mWindowRemovalAllowed) {
2770 mWinAnimator.destroyPreservedSurfaceLocked();
2771 }
2772
2773 if (mDestroying) {
2774 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2775 + " destroySurfaces: appStopped=" + appStopped
2776 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2777 + " win.mRemoveOnExit=" + mRemoveOnExit);
2778 if (!cleanupOnResume || mRemoveOnExit) {
Robert Carr89a28ab2017-04-24 15:33:11 -07002779 destroyOrSaveSurfaceUnchecked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08002780 }
2781 if (mRemoveOnExit) {
2782 removeImmediately();
2783 }
2784 if (cleanupOnResume) {
2785 requestUpdateWallpaperIfNeeded();
2786 }
2787 mDestroying = false;
2788 destroyedSomething = true;
2789 }
2790
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002791 return destroyedSomething;
2792 }
Chris Craik3131bde2016-05-06 13:39:08 -07002793
Robert Carr89a28ab2017-04-24 15:33:11 -07002794 // Destroy or save the application surface without checking
2795 // various indicators of whether the client has released the surface.
2796 // This is in general unsafe, and most callers should use {@link #destroySurface}
2797 void destroyOrSaveSurfaceUnchecked() {
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002798 mSurfaceSaved = shouldSaveSurface();
2799 if (mSurfaceSaved) {
2800 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2801 Slog.v(TAG, "Saving surface: " + this);
2802 }
Chris Craik3131bde2016-05-06 13:39:08 -07002803 // Previous user of the surface may have set a transparent region signaling a portion
2804 // doesn't need to be composited, so reset to default empty state.
2805 mSession.setTransparentRegion(mClient, sEmptyRegion);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002806
2807 mWinAnimator.hide("saved surface");
2808 mWinAnimator.mDrawState = WindowStateAnimator.NO_SURFACE;
2809 setHasSurface(false);
Chong Zhang47e36a32016-02-29 16:44:33 -08002810 // The client should have disconnected at this point, but if it doesn't,
2811 // we need to make sure it's disconnected. Otherwise when we reuse the surface
2812 // the client can't reconnect to the buffer queue, and rendering will fail.
2813 if (mWinAnimator.mSurfaceController != null) {
2814 mWinAnimator.mSurfaceController.disconnectInTransaction();
2815 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002816 mAnimatingWithSavedSurface = false;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002817 } else {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002818 mWinAnimator.destroySurfaceLocked();
2819 }
Chong Zhang92147042016-05-09 12:47:11 -07002820 // Clear animating flags now, since the surface is now gone. (Note this is true even
2821 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2822 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002823 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002824
Chong Zhang92147042016-05-09 12:47:11 -07002825 void destroySavedSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002826 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002827 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002828 c.destroySavedSurface();
2829 }
2830
Robert Carr13f7be9e2015-12-02 18:39:45 -08002831 if (mSurfaceSaved) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002832 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, "Destroying saved surface: " + this);
Robert Carr13f7be9e2015-12-02 18:39:45 -08002833 mWinAnimator.destroySurfaceLocked();
Robert Carr237028a2016-07-26 10:39:45 -07002834 mSurfaceSaved = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002835 }
Chong Zhang92147042016-05-09 12:47:11 -07002836 mWasVisibleBeforeClientHidden = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002837 }
2838
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002839 /** Returns -1 if there are no interesting windows or number of interesting windows not drawn.*/
2840 int restoreSavedSurfaceForInterestingWindow() {
2841 int interestingNotDrawn = -1;
2842 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002843 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002844 final int childInterestingNotDrawn = c.restoreSavedSurfaceForInterestingWindow();
2845 if (childInterestingNotDrawn != -1) {
2846 if (interestingNotDrawn == -1) {
2847 interestingNotDrawn = childInterestingNotDrawn;
2848 } else {
2849 interestingNotDrawn += childInterestingNotDrawn;
2850 }
2851 }
Chong Zhang4113ffa2016-02-18 12:39:13 -08002852 }
Robert Carr237028a2016-07-26 10:39:45 -07002853
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002854 if (mAttrs.type == TYPE_APPLICATION_STARTING
2855 || mAppDied || !wasVisibleBeforeClientHidden()
2856 || (mAppToken.mAppAnimator.freezingScreen && mAppFreezing)) {
2857 // Window isn't interesting...
2858 return interestingNotDrawn;
2859 }
2860
2861 restoreSavedSurface();
2862
2863 if (!isDrawnLw()) {
2864 if (interestingNotDrawn == -1) {
2865 interestingNotDrawn = 1;
2866 } else {
2867 interestingNotDrawn++;
2868 }
2869 }
2870 return interestingNotDrawn;
2871 }
2872
2873 /** Returns true if the saved surface was restored. */
2874 boolean restoreSavedSurface() {
2875 if (!mSurfaceSaved) {
2876 return false;
2877 }
2878
2879 // Sometimes we save surfaces due to layout invisible directly after rotation occurs.
2880 // However this means the surface was never laid out in the new orientation.
2881 // We can only restore to the last rotation we were laid out as visible in.
Andrii Kulian8ee72852017-03-10 10:36:45 -08002882 if (mLastVisibleLayoutRotation != getDisplayContent().getRotation()) {
Robert Carr237028a2016-07-26 10:39:45 -07002883 destroySavedSurface();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002884 return false;
Robert Carr237028a2016-07-26 10:39:45 -07002885 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002886 mSurfaceSaved = false;
Robert Carr237028a2016-07-26 10:39:45 -07002887
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002888 if (mWinAnimator.mSurfaceController != null) {
2889 setHasSurface(true);
Wale Ogunwale9d147902016-07-16 11:58:55 -07002890 mWinAnimator.mDrawState = READY_TO_SHOW;
Chong Zhang92147042016-05-09 12:47:11 -07002891 mAnimatingWithSavedSurface = true;
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002892
Chong Zhang6e9872b2016-08-17 10:19:05 -07002893 requestUpdateWallpaperIfNeeded();
2894
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002895 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2896 Slog.v(TAG, "Restoring saved surface: " + this);
2897 }
2898 } else {
2899 // mSurfaceController shouldn't be null if mSurfaceSaved was still true at
2900 // this point. Even if we destroyed the saved surface because of rotation
2901 // or resize, mSurfaceSaved flag should have been cleared. So this is a wtf.
2902 Slog.wtf(TAG, "Failed to restore saved surface: surface gone! " + this);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002903 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002904
2905 return true;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002906 }
2907
Chong Zhang92147042016-05-09 12:47:11 -07002908 boolean canRestoreSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002909 if (mWasVisibleBeforeClientHidden && mSurfaceSaved) {
2910 return true;
2911 }
2912
2913 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002914 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002915 if (c.canRestoreSurface()) {
2916 return true;
2917 }
2918 }
2919
2920 return false;
Chong Zhang92147042016-05-09 12:47:11 -07002921 }
2922
2923 boolean hasSavedSurface() {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002924 return mSurfaceSaved;
2925 }
2926
Chong Zhang92147042016-05-09 12:47:11 -07002927 void clearHasSavedSurface() {
2928 mSurfaceSaved = false;
2929 mAnimatingWithSavedSurface = false;
Chong Zhangf58631a2016-05-24 16:02:10 -07002930 if (mWasVisibleBeforeClientHidden) {
2931 mAppToken.destroySavedSurfaces();
2932 }
Chong Zhang92147042016-05-09 12:47:11 -07002933 }
2934
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002935 boolean clearAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002936 if (mAnimatingWithSavedSurface) {
2937 // App has drawn something to its windows, we're no longer animating with
2938 // the saved surfaces.
2939 if (DEBUG_ANIM) Slog.d(TAG,
2940 "clearAnimatingWithSavedSurface(): win=" + this);
2941 mAnimatingWithSavedSurface = false;
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002942 return true;
Chong Zhang92147042016-05-09 12:47:11 -07002943 }
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002944 return false;
Chong Zhang92147042016-05-09 12:47:11 -07002945 }
2946
Craig Mautner69b08182012-09-05 13:07:13 -07002947 @Override
2948 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002949 final DisplayContent displayContent = getDisplayContent();
2950 if (displayContent == null) {
2951 // Only a window that was on a non-default display can be detached from it.
2952 return false;
2953 }
Winson Chung47a3e652014-05-21 16:03:42 -07002954 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002955 }
2956
Adrian Rooscd3884d2015-02-18 17:25:23 +01002957 @Override
2958 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002959 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002960 final DisplayContent dc = getDisplayContent();
2961 return dimLayerUser != null && dc != null
2962 && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01002963 }
2964
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002965 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07002966 mShowToOwnerOnly = showToOwnerOnly;
2967 }
2968
Wale Ogunwaleea92d972016-12-08 07:33:13 -08002969 private boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002970 // Child windows are evaluated based on their parent window.
2971 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002972 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale72919d22016-12-08 18:58:50 -08002973 && win.mAppToken != null && win.mAppToken.mShowForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002974
2975 // All window frames that are fullscreen extend above status bar, but some don't extend
2976 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2977 // bottom right.
2978 if (win.mFrame.left <= win.mDisplayFrame.left
2979 && win.mFrame.top <= win.mDisplayFrame.top
2980 && win.mFrame.right >= win.mStableFrame.right
2981 && win.mFrame.bottom >= win.mStableFrame.bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002982 // Is a fullscreen window, like the clock alarm. Show to everyone.
2983 return false;
2984 }
2985 }
2986
Craig Mautner341220f2012-10-16 15:20:09 -07002987 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01002988 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002989 }
2990
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002991 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2992 outRegion.set(
2993 frame.left + inset.left, frame.top + inset.top,
2994 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002995 }
2996
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002997 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002998 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002999 switch (mTouchableInsets) {
3000 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003001 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003002 outRegion.set(frame);
3003 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003004 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003005 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003006 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003007 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003008 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003009 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003010 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003011 outRegion.set(mGivenTouchableRegion);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003012 outRegion.translate(frame.left, frame.top);
3013 break;
3014 }
3015 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003016 cropRegionToStackBoundsIfNeeded(outRegion);
3017 }
3018
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003019 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08003020 final Task task = getTask();
3021 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003022 return;
3023 }
3024
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08003025 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003026 if (stack == null) {
3027 return;
3028 }
3029
3030 stack.getDimBounds(mTmpRect);
3031 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003032 }
3033
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003034 /**
3035 * Report a focus change. Must be called with no locks held, and consistently
3036 * from the same serialized thread (such as dispatched from a handler).
3037 */
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07003038 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003039 try {
3040 mClient.windowFocusChanged(focused, inTouchMode);
3041 } catch (RemoteException e) {
3042 }
3043 if (mFocusCallbacks != null) {
3044 final int N = mFocusCallbacks.beginBroadcast();
3045 for (int i=0; i<N; i++) {
3046 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
3047 try {
3048 if (focused) {
3049 obs.focusGained(mWindowId.asBinder());
3050 } else {
3051 obs.focusLost(mWindowId.asBinder());
3052 }
3053 } catch (RemoteException e) {
3054 }
3055 }
3056 mFocusCallbacks.finishBroadcast();
3057 }
3058 }
3059
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003060 @Override
3061 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003062 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003063 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003064 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003065
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003066 return super.getConfiguration();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003067 }
3068
Craig Mautnerdf88d732014-01-27 09:21:32 -08003069 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003070 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08003071 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003072 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
3073 + ": " + mCompatFrame);
Bryce Leef858b572017-06-29 14:03:33 -07003074 final MergedConfiguration mergedConfiguration =
3075 new MergedConfiguration(mService.mRoot.getConfiguration(),
3076 getMergedOverrideConfiguration());
3077
3078 setReportedConfiguration(mergedConfiguration);
3079
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003080 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003081 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
3082
Craig Mautnerdf88d732014-01-27 09:21:32 -08003083 final Rect frame = mFrame;
3084 final Rect overscanInsets = mLastOverscanInsets;
3085 final Rect contentInsets = mLastContentInsets;
3086 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07003087 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003088 final Rect outsets = mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003089 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003090 final boolean reportOrientation = mReportOrientationChanged;
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003091 final int displayId = getDisplayId();
Chet Haase8eb48d22014-09-24 07:31:29 -07003092 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
3093 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08003094 // To prevent deadlock simulate one-way call if win.mClient is a local object.
3095 mService.mH.post(new Runnable() {
3096 @Override
3097 public void run() {
3098 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003099 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003100 stableInsets, outsets, reportDraw, mergedConfiguration,
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003101 reportOrientation, displayId);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003102 } catch (RemoteException e) {
3103 // Not a remote call, RemoteException won't be raised.
3104 }
3105 }
3106 });
3107 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003108 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003109 outsets, reportDraw, mergedConfiguration, reportOrientation, displayId);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003110 }
Svetoslav4604abc2014-06-10 18:59:30 -07003111
3112 //TODO (multidisplay): Accessibility supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07003113 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07003114 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07003115 }
3116
Craig Mautnerdf88d732014-01-27 09:21:32 -08003117 mOverscanInsetsChanged = false;
3118 mContentInsetsChanged = false;
3119 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07003120 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003121 mOutsetsChanged = false;
Robert Carr31aa98b2016-07-20 15:29:03 -07003122 mFrameSizeChanged = false;
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003123 mResizedWhileNotDragResizingReported = true;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003124 mWinAnimator.mSurfaceResized = false;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003125 mReportOrientationChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003126 } catch (RemoteException e) {
Bryce Lee8c3cf382017-07-06 19:47:10 -07003127 setOrientationChanging(false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003128 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
3129 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08003130 // We are assuming the hosting process is dead or in a zombie state.
3131 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
3132 + ", removing this window.");
3133 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07003134 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003135 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003136 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003137 }
3138
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003139 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08003140 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
3141 // start even if we haven't received the relayout window, so that the client requests
3142 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
3143 // until the window to small size, otherwise the multithread renderer will shift last
3144 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
3145 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003146 boolean resizing = isDragResizing() || isDragResizeChanged();
3147 if (StackId.useWindowFrameForBackdrop(getStackId()) || !resizing) {
3148 return frame;
3149 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07003150 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003151 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003152 return mTmpRect;
3153 }
3154
Jorim Jaggi86905582016-02-09 21:36:09 -08003155 @Override
3156 public int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003157 final TaskStack stack = getStack();
3158 if (stack == null) {
3159 return INVALID_STACK_ID;
3160 }
3161 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003162 }
3163
3164 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
3165 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
Andrii Kulian44607962017-03-16 11:06:24 -07003166 MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId)
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003167 throws RemoteException {
Andrii Kulianb2e37802017-01-11 00:36:44 -08003168 final boolean forceRelayout = isDragResizeChanged() || mResizedWhileNotDragResizing
3169 || reportOrientation;
Chong Zhangedaf3052016-04-22 15:04:31 -07003170
Jorim Jaggidc249c42015-12-15 14:57:31 -08003171 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003172 reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout,
3173 mPolicy.isNavBarForcedShownLw(this), displayId);
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003174 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003175 }
3176
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003177 public void registerFocusObserver(IWindowFocusObserver observer) {
3178 synchronized(mService.mWindowMap) {
3179 if (mFocusCallbacks == null) {
3180 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
3181 }
3182 mFocusCallbacks.register(observer);
3183 }
3184 }
3185
3186 public void unregisterFocusObserver(IWindowFocusObserver observer) {
3187 synchronized(mService.mWindowMap) {
3188 if (mFocusCallbacks != null) {
3189 mFocusCallbacks.unregister(observer);
3190 }
3191 }
3192 }
3193
3194 public boolean isFocused() {
3195 synchronized(mService.mWindowMap) {
3196 return mService.mCurrentFocus == this;
3197 }
3198 }
3199
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07003200 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003201 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07003202 return task != null && task.inFreeformWorkspace();
3203 }
3204
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003205 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07003206 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003207 final Task task = getTask();
3208 return task != null && !task.isFullscreen();
3209 }
3210
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003211 /** Is this window in a container that takes up the entire screen space? */
3212 private boolean inFullscreenContainer() {
3213 if (mAppToken == null) {
3214 return true;
3215 }
3216 if (mAppToken.hasBounds()) {
3217 return false;
3218 }
3219 return !isInMultiWindowMode();
3220 }
3221
3222 /** Returns the appropriate bounds to use for computing frames. */
3223 private void getContainerBounds(Rect outBounds) {
3224 if (isInMultiWindowMode()) {
3225 getTask().getBounds(outBounds);
3226 } else if (mAppToken != null){
3227 mAppToken.getBounds(outBounds);
3228 } else {
3229 outBounds.setEmpty();
3230 }
3231 }
3232
Chong Zhang3005e752015-09-18 18:46:28 -07003233 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003234 return mDragResizing != computeDragResizing();
3235 }
3236
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003237 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003238 void setWaitingForDrawnIfResizingChanged() {
3239 if (isDragResizeChanged()) {
3240 mService.mWaitingForDrawn.add(this);
3241 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003242 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003243 }
3244
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003245 /**
3246 * @return Whether we reported a drag resize change to the application or not already.
3247 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003248 private boolean isDragResizingChangeReported() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003249 return mDragResizingChangeReported;
3250 }
3251
3252 /**
3253 * Resets the state whether we reported a drag resize change to the app.
3254 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003255 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003256 void resetDragResizingChangeReported() {
3257 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003258 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003259 }
3260
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003261 /**
3262 * Set whether we got resized but drag resizing flag was false.
3263 * @see #isResizedWhileNotDragResizing().
3264 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003265 private void setResizedWhileNotDragResizing(boolean resizedWhileNotDragResizing) {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003266 mResizedWhileNotDragResizing = resizedWhileNotDragResizing;
3267 mResizedWhileNotDragResizingReported = !resizedWhileNotDragResizing;
3268 }
3269
3270 /**
3271 * Indicates whether we got resized but drag resizing flag was false. In this case, we also
3272 * need to recreate the surface and defer surface bound updates in order to make sure the
3273 * buffer contents and the positioning/size stay in sync.
3274 */
3275 boolean isResizedWhileNotDragResizing() {
3276 return mResizedWhileNotDragResizing;
3277 }
3278
3279 /**
3280 * @return Whether we reported "resize while not drag resizing" to the application.
3281 * @see #isResizedWhileNotDragResizing()
3282 */
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003283 private boolean isResizedWhileNotDragResizingReported() {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003284 return mResizedWhileNotDragResizingReported;
3285 }
3286
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003287 int getResizeMode() {
3288 return mResizeMode;
3289 }
3290
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003291 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003292 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003293 if (task == null) {
3294 return false;
3295 }
Winson Chung2af04b32017-01-24 16:21:13 -08003296 if (!StackId.isStackAffectedByDragResizing(getStackId())) {
3297 return false;
3298 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003299 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003300 // Floating windows never enter drag resize mode.
3301 return false;
3302 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003303 if (task.isDragResizing()) {
3304 return true;
3305 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003306
3307 // If the bounds are currently frozen, it means that the layout size that the app sees
3308 // and the bounds we clip this window to might be different. In order to avoid holes, we
3309 // simulate that we are still resizing so the app fills the hole with the resizing
3310 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003311 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003312 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Jorim Jaggi899327f2016-02-25 20:44:18 -05003313 !task.inFreeformWorkspace() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003314
Chong Zhang3005e752015-09-18 18:46:28 -07003315 }
3316
3317 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003318 final boolean resizing = computeDragResizing();
3319 if (resizing == mDragResizing) {
3320 return;
3321 }
3322 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003323 final Task task = getTask();
3324 if (task != null && task.isDragResizing()) {
3325 mResizeMode = task.getDragResizeMode();
3326 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003327 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003328 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3329 : DRAG_RESIZE_MODE_FREEFORM;
3330 }
Chong Zhang3005e752015-09-18 18:46:28 -07003331 }
3332
3333 boolean isDragResizing() {
3334 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003335 }
3336
Robert Carr2487ce72016-04-07 15:18:45 -07003337 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003338 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3339 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003340 }
3341
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003342 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003343 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003344 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003345 if (stack != null) {
3346 pw.print(" stackId="); pw.print(stack.mStackId);
3347 }
Craig Mautner59c00972012-07-30 12:10:24 -07003348 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003349 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07003350 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08003351 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
3352 pw.print(" package="); pw.print(mAttrs.packageName);
3353 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003354 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003355 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
3356 pw.print(" h="); pw.print(mRequestedHeight);
3357 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003358 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
3359 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
3360 pw.print(" h="); pw.println(mLastRequestedHeight);
3361 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003362 if (mIsChildWindow || mLayoutAttached) {
3363 pw.print(prefix); pw.print("mParentWindow="); pw.print(getParentWindow());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003364 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
3365 }
3366 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
3367 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
3368 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
3369 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
3370 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
3371 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003372 if (dumpAll) {
3373 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3374 pw.print(" mSubLayer="); pw.print(mSubLayer);
3375 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Wale Ogunwale455fac52016-07-21 07:24:49 -07003376 pw.print(getAnimLayerAdjustment());
Craig Mautnerc2f9be02012-03-27 17:32:29 -07003377 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
3378 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003379 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003380 if (dumpAll) {
3381 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003382 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003383 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
3384 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08003385 pw.print(isAnimatingWithSavedSurface());
Bryce Lee6311c4b2017-07-06 14:09:29 -07003386 pw.print(" mAppDied=");pw.print(mAppDied);
3387 pw.print(prefix); pw.print("drawnStateEvaluated=");
3388 pw.print(getDrawnStateEvaluated());
3389 pw.print(prefix); pw.print("mightAffectAllDrawn=");
3390 pw.println(mightAffectAllDrawn(false /*visibleOnly*/));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003391 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003392 pw.print(prefix); pw.print("mViewVisibility=0x");
3393 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003394 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
3395 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07003396 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
3397 pw.print(" mSystemUiVisibility=0x");
3398 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003399 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003400 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
Svetoslav Ganov71c51022016-09-02 17:54:37 -07003401 || isParentWindowHidden()|| mPermanentlyHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003402 pw.print(prefix); pw.print("mPolicyVisibility=");
3403 pw.print(mPolicyVisibility);
3404 pw.print(" mPolicyVisibilityAfterAnim=");
3405 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003406 pw.print(" mAppOpVisibility=");
3407 pw.print(mAppOpVisibility);
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003408 pw.print(" parentHidden="); pw.print(isParentWindowHidden());
Svetoslav Ganovaa076532016-08-01 19:16:43 -07003409 pw.print(" mPermanentlyHidden="); pw.println(mPermanentlyHidden);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003410 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003411 if (!mRelayoutCalled || mLayoutNeeded) {
3412 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
3413 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003414 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003415 if (mXOffset != 0 || mYOffset != 0) {
3416 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
3417 pw.print(" y="); pw.println(mYOffset);
3418 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003419 if (dumpAll) {
3420 pw.print(prefix); pw.print("mGivenContentInsets=");
3421 mGivenContentInsets.printShortString(pw);
3422 pw.print(" mGivenVisibleInsets=");
3423 mGivenVisibleInsets.printShortString(pw);
3424 pw.println();
3425 if (mTouchableInsets != 0 || mGivenInsetsPending) {
3426 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
3427 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003428 Region region = new Region();
3429 getTouchableRegion(region);
3430 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003431 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003432 pw.print(prefix); pw.print("mFullConfiguration="); pw.println(getConfiguration());
3433 pw.print(prefix); pw.print("mLastReportedConfiguration=");
3434 pw.println(mLastReportedConfiguration);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003435 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07003436 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07003437 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Chong Zhanga8975bd2016-01-28 17:13:47 -08003438 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08003439 pw.print(" hasSavedSurface()="); pw.print(hasSavedSurface());
3440 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003441 if (dumpAll) {
3442 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
3443 pw.print(" last="); mLastFrame.printShortString(pw);
3444 pw.println();
3445 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003446 if (mEnforceSizeCompat) {
3447 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003448 pw.println();
3449 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003450 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003451 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003452 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003453 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003454 pw.println();
3455 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
3456 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003457 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003458 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003459 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003460 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04003461 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
3462 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003463 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
3464 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003465 pw.print(prefix); pw.print("Cur insets: overscan=");
3466 mOverscanInsets.printShortString(pw);
3467 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003468 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003469 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003470 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003471 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003472 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003473 pw.print(prefix); pw.print("Lst insets: overscan=");
3474 mLastOverscanInsets.printShortString(pw);
3475 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003476 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003477 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003478 pw.print(" physical="); mLastOutsets.printShortString(pw);
3479 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003480 pw.println();
3481 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07003482 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
3483 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003484 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
3485 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003486 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
3487 pw.print(" mDestroying="); pw.print(mDestroying);
3488 pw.print(" mRemoved="); pw.println(mRemoved);
3489 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07003490 if (getOrientationChanging() || mAppFreezing || mTurnOnScreen
Andrii Kulianb2e37802017-01-11 00:36:44 -08003491 || mReportOrientationChanged) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003492 pw.print(prefix); pw.print("mOrientationChanging=");
3493 pw.print(mOrientationChanging);
Bryce Lee8c3cf382017-07-06 19:47:10 -07003494 pw.print(" configOrientationChanging=");
3495 pw.print(mLastReportedConfiguration.orientation
3496 != getConfiguration().orientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003497 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003498 pw.print(" mTurnOnScreen="); pw.print(mTurnOnScreen);
Andrii Kulianb2e37802017-01-11 00:36:44 -08003499 pw.print(" mReportOrientationChanged="); pw.println(mReportOrientationChanged);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003500 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003501 if (mLastFreezeDuration != 0) {
3502 pw.print(prefix); pw.print("mLastFreezeDuration=");
3503 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
3504 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003505 if (mHScale != 1 || mVScale != 1) {
3506 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
3507 pw.print(" mVScale="); pw.println(mVScale);
3508 }
3509 if (mWallpaperX != -1 || mWallpaperY != -1) {
3510 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
3511 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
3512 }
3513 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
3514 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
3515 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
3516 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003517 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3518 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
3519 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
3520 pw.print(mWallpaperDisplayOffsetX);
3521 pw.print(" mWallpaperDisplayOffsetY=");
3522 pw.println(mWallpaperDisplayOffsetY);
3523 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003524 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07003525 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003526 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003527 if (isDragResizing()) {
3528 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
3529 }
3530 if (computeDragResizing()) {
3531 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
3532 }
Bryce Lee6311c4b2017-07-06 14:09:29 -07003533 pw.print(prefix); pw.println("isOnScreen=" + isOnScreen());
3534 pw.print(prefix); pw.println("isVisible=" + isVisible());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003535 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003536
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003537 @Override
3538 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003539 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003540 + " " + getWindowTag();
3541 }
3542
Robert Carra1eb4392015-12-10 12:43:51 -08003543 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003544 CharSequence tag = mAttrs.getTitle();
3545 if (tag == null || tag.length() <= 0) {
3546 tag = mAttrs.packageName;
3547 }
3548 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003549 }
3550
3551 @Override
3552 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003553 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003554 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003555 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003556 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003557 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003558 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003559 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003560 }
3561 return mStringNameCache;
3562 }
Robert Carr58f29132015-10-29 14:19:05 -07003563
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003564 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003565 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003566 clipRect.left = (int) (clipRect.left / mHScale);
3567 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003568 }
3569 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003570 clipRect.top = (int) (clipRect.top / mVScale);
3571 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003572 }
3573 }
Robert Carr31e28482015-12-02 16:53:18 -08003574
Jorim Jaggif5834272016-04-04 20:25:41 -07003575 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
3576 final int pw = containingFrame.width();
3577 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003578 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003579 final boolean inNonFullscreenContainer = !inFullscreenContainer();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003580 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3581
3582 // We need to fit it to the display if either
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003583 // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen
3584 // for the taskless windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003585 // 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 -07003586 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on
3587 // screen, but SurfaceViews want to be always at a specific location so we don't fit it to
3588 // the display.
3589 final boolean fitToDisplay = (task == null || !inNonFullscreenContainer)
Robert Carr6f44db12016-07-21 14:54:43 -07003590 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003591 float x, y;
3592 int w,h;
3593
3594 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3595 if (mAttrs.width < 0) {
3596 w = pw;
3597 } else if (mEnforceSizeCompat) {
3598 w = (int)(mAttrs.width * mGlobalScale + .5f);
3599 } else {
3600 w = mAttrs.width;
3601 }
3602 if (mAttrs.height < 0) {
3603 h = ph;
3604 } else if (mEnforceSizeCompat) {
3605 h = (int)(mAttrs.height * mGlobalScale + .5f);
3606 } else {
3607 h = mAttrs.height;
3608 }
3609 } else {
3610 if (mAttrs.width == MATCH_PARENT) {
3611 w = pw;
3612 } else if (mEnforceSizeCompat) {
3613 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3614 } else {
3615 w = mRequestedWidth;
3616 }
3617 if (mAttrs.height == MATCH_PARENT) {
3618 h = ph;
3619 } else if (mEnforceSizeCompat) {
3620 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3621 } else {
3622 h = mRequestedHeight;
3623 }
3624 }
3625
3626 if (mEnforceSizeCompat) {
3627 x = mAttrs.x * mGlobalScale;
3628 y = mAttrs.y * mGlobalScale;
3629 } else {
3630 x = mAttrs.x;
3631 y = mAttrs.y;
3632 }
3633
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003634 if (inNonFullscreenContainer && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003635 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003636 // required by {@link Gravity#apply} call.
3637 w = Math.min(w, pw);
3638 h = Math.min(h, ph);
3639 }
3640
3641 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003642 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003643 (int) (x + mAttrs.horizontalMargin * pw),
3644 (int) (y + mAttrs.verticalMargin * ph), mFrame);
3645
3646 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003647 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003648 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003649 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003650
3651 // We need to make sure we update the CompatFrame as it is used for
3652 // cropping decisions, etc, on systems where we lack a decor layer.
3653 mCompatFrame.set(mFrame);
3654 if (mEnforceSizeCompat) {
3655 // See comparable block in computeFrameLw.
3656 mCompatFrame.scale(mInvGlobalScale);
3657 }
Robert Carr31e28482015-12-02 16:53:18 -08003658 }
Robert Carr51a1b872015-12-08 14:03:13 -08003659
3660 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003661 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003662 }
3663
Robert Carrf3b72c72016-03-21 18:16:39 -07003664 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003665 return mIsChildWindow
3666 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003667 }
3668
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003669 /** Returns the parent window if this is a child of another window, else null. */
3670 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003671 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3672 // WindowContainer that isn't a WindowState.
3673 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003674 }
3675
3676 /** Returns the topmost parent window if this is a child of another window, else this. */
3677 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003678 WindowState current = this;
3679 WindowState topParent = current;
3680 while (current != null && current.mIsChildWindow) {
3681 current = current.getParentWindow();
3682 // Parent window can be null if the child is detached from it's parent already, but
3683 // someone still has a reference to access it. So, we return the top parent value we
3684 // already have instead of null.
3685 if (current != null) {
3686 topParent = current;
3687 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003688 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003689 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003690 }
3691
Wale Ogunwale9d147902016-07-16 11:58:55 -07003692 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003693 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003694 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003695 }
3696
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003697 void setWillReplaceWindow(boolean animate) {
3698 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003699 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003700 c.setWillReplaceWindow(animate);
3701 }
3702
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003703 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3704 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3705 // We don't set replacing on starting windows since they are added by window manager and
3706 // not the client so won't be replaced by the client.
3707 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003708 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003709
3710 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003711 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003712 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003713 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003714
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003715 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003716 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003717 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003718 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003719
3720 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003721 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003722 c.clearWillReplaceWindow();
3723 }
3724 }
3725
3726 boolean waitingForReplacement() {
3727 if (mWillReplaceWindow) {
3728 return true;
3729 }
3730
3731 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003732 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003733 if (c.waitingForReplacement()) {
3734 return true;
3735 }
3736 }
3737 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003738 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003739
Chong Zhang4d7369a2016-04-25 16:09:14 -07003740 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003741 final DisplayContent dc = getDisplayContent();
3742 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3743 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3744 dc.setLayoutNeeded();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003745 mService.mWindowPlacerLocked.requestTraversal();
3746 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003747
3748 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003749 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003750 c.requestUpdateWallpaperIfNeeded();
3751 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003752 }
3753
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003754 float translateToWindowX(float x) {
3755 float winX = x - mFrame.left;
3756 if (mEnforceSizeCompat) {
3757 winX *= mGlobalScale;
3758 }
3759 return winX;
3760 }
3761
3762 float translateToWindowY(float y) {
3763 float winY = y - mFrame.top;
3764 if (mEnforceSizeCompat) {
3765 winY *= mGlobalScale;
3766 }
3767 return winY;
3768 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003769
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003770 private void transferDimToReplacement() {
Robert Carr9fe459d2016-04-07 23:32:28 -07003771 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003772 final DisplayContent dc = getDisplayContent();
3773 if (dimLayerUser != null && dc != null) {
3774 dc.mDimLayerController.applyDim(dimLayerUser,
3775 mReplacementWindow.mWinAnimator, (mAttrs.flags & FLAG_DIM_BEHIND) != 0);
Robert Carr9fe459d2016-04-07 23:32:28 -07003776 }
3777 }
3778
Robert Carrd1a010f2016-04-07 22:36:22 -07003779 // During activity relaunch due to resize, we sometimes use window replacement
3780 // for only child windows (as the main window is handled by window preservation)
3781 // and the big surface.
3782 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003783 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3784 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3785 // we also want to replace them at such phases, as they won't be covered by window
3786 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003787 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003788 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003789 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003790 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003791
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003792 void setWillReplaceChildWindows() {
3793 if (shouldBeReplacedWithChildren()) {
3794 setWillReplaceWindow(false /* animate */);
3795 }
3796 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003797 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003798 c.setWillReplaceChildWindows();
3799 }
3800 }
3801
3802 WindowState getReplacingWindow() {
3803 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3804 return this;
3805 }
3806 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003807 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003808 final WindowState replacing = c.getReplacingWindow();
3809 if (replacing != null) {
3810 return replacing;
3811 }
3812 }
3813 return null;
3814 }
3815
Jorim Jaggife762342016-10-13 14:33:27 +02003816 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07003817 public int getRotationAnimationHint() {
3818 if (mAppToken != null) {
3819 return mAppToken.mRotationAnimationHint;
3820 } else {
3821 return -1;
3822 }
3823 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003824
Jorim Jaggife762342016-10-13 14:33:27 +02003825 @Override
3826 public boolean isInputMethodWindow() {
3827 return mIsImWindow;
3828 }
3829
Wale Ogunwale9d147902016-07-16 11:58:55 -07003830 // This must be called while inside a transaction.
3831 boolean performShowLocked() {
3832 if (isHiddenFromUserLocked()) {
3833 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3834 hideLw(false);
3835 return false;
3836 }
3837
3838 logPerformShow("performShow on ");
3839
Jorim Jaggia50da602016-12-29 11:51:42 +01003840 final int drawState = mWinAnimator.mDrawState;
3841 if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW)
3842 && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3843 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3844 }
3845
Jorim Jaggib0d27342016-11-01 16:10:42 -07003846 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003847 return false;
3848 }
3849
3850 logPerformShow("Showing ");
3851
3852 mService.enableScreenIfNeededLocked();
3853 mWinAnimator.applyEnterAnimationLocked();
3854
3855 // Force the show in the next prepareSurfaceLocked() call.
3856 mWinAnimator.mLastAlpha = -1;
3857 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) Slog.v(TAG,
3858 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3859 mWinAnimator.mDrawState = HAS_DRAWN;
3860 mService.scheduleAnimationLocked();
3861
3862 if (mHidden) {
3863 mHidden = false;
3864 final DisplayContent displayContent = getDisplayContent();
3865
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003866 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003867 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003868 if (c.mWinAnimator.mSurfaceController != null) {
3869 c.performShowLocked();
3870 // It hadn't been shown, which means layout not performed on it, so now we
3871 // want to make sure to do a layout. If called from within the transaction
3872 // loop, this will cause it to restart with a new layout.
3873 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003874 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003875 }
3876 }
3877 }
3878 }
3879
Wale Ogunwale9d147902016-07-16 11:58:55 -07003880 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003881 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003882 }
3883
3884 return true;
3885 }
3886
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003887 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003888 if (DEBUG_VISIBILITY
Jorim Jaggie4b0f282017-05-17 15:10:29 +02003889 || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003890 Slog.v(TAG, prefix + this
3891 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07003892 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003893 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3894 + " during animation: policyVis=" + mPolicyVisibility
3895 + " parentHidden=" + isParentWindowHidden()
3896 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003897 + (mAppToken != null && mAppToken.hiddenRequested)
3898 + " tok.hidden=" + (mAppToken != null && mAppToken.hidden)
Wale Ogunwale9d147902016-07-16 11:58:55 -07003899 + " animating=" + mWinAnimator.mAnimating
3900 + " tok animating="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003901 + (mWinAnimator.mAppAnimator != null && mWinAnimator.mAppAnimator.animating)
Wale Ogunwale9d147902016-07-16 11:58:55 -07003902 + " Callers=" + Debug.getCallers(4));
3903 }
3904 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003905
3906 WindowInfo getWindowInfo() {
3907 WindowInfo windowInfo = WindowInfo.obtain();
3908 windowInfo.type = mAttrs.type;
3909 windowInfo.layer = mLayer;
3910 windowInfo.token = mClient.asBinder();
3911 windowInfo.title = mAttrs.accessibilityTitle;
3912 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3913 windowInfo.focused = isFocused();
Phil Weaverf00cd142017-03-03 13:44:00 -08003914 Task task = getTask();
3915 windowInfo.inPictureInPicture = (task != null) && task.inPinnedWorkspace();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003916
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003917 if (mIsChildWindow) {
3918 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003919 }
3920
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003921 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003922 if (childCount > 0) {
3923 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003924 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003925 }
3926 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003927 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003928 windowInfo.childTokens.add(child.mClient.asBinder());
3929 }
3930 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003931 return windowInfo;
3932 }
3933
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003934 int getHighestAnimLayer() {
3935 int highest = mWinAnimator.mAnimLayer;
3936 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003937 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003938 final int childLayer = c.getHighestAnimLayer();
3939 if (childLayer > highest) {
3940 highest = childLayer;
3941 }
3942 }
3943 return highest;
3944 }
3945
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003946 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003947 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003948 if (mChildren.isEmpty()) {
3949 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003950 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003951 }
3952
3953 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003954 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003955 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003956 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003957 }
3958 }
3959
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003960 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003961 // We want to consume the negative sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003962 // below the parent, then this window (the parent), and then the positive sublayer children
3963 // because they need to appear above the parent.
3964 int i = 0;
3965 final int count = mChildren.size();
3966 WindowState child = mChildren.get(i);
3967
3968 while (i < count && child.mSubLayer < 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003969 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003970 return true;
3971 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003972 i++;
3973 if (i >= count) {
3974 break;
3975 }
3976 child = mChildren.get(i);
3977 }
3978
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003979 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003980 return true;
3981 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003982
3983 while (i < count) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003984 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003985 return true;
3986 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003987 i++;
3988 if (i >= count) {
3989 break;
3990 }
3991 child = mChildren.get(i);
3992 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003993
3994 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003995 }
3996
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003997 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003998 // We want to consume the positive sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003999 // above the parent, then this window (the parent), and then the negative sublayer children
4000 // because they need to appear above the parent.
4001 int i = mChildren.size() - 1;
4002 WindowState child = mChildren.get(i);
4003
4004 while (i >= 0 && child.mSubLayer >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004005 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004006 return true;
4007 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004008 --i;
4009 if (i < 0) {
4010 break;
4011 }
4012 child = mChildren.get(i);
4013 }
4014
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004015 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004016 return true;
4017 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004018
4019 while (i >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004020 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004021 return true;
4022 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004023 --i;
4024 if (i < 0) {
4025 break;
4026 }
4027 child = mChildren.get(i);
4028 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004029
4030 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004031 }
4032
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004033 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
4034 boolean traverseTopToBottom) {
4035 if (traverseTopToBottom) {
4036 if (mService.mInputMethodTarget == this) {
4037 // This window is the current IME target, so we need to process the IME windows
4038 // directly above it.
4039 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
4040 return true;
4041 }
4042 }
4043 if (callback.apply(this)) {
4044 return true;
4045 }
4046 } else {
4047 if (callback.apply(this)) {
4048 return true;
4049 }
4050 if (mService.mInputMethodTarget == this) {
4051 // This window is the current IME target, so we need to process the IME windows
4052 // directly above it.
4053 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
4054 return true;
4055 }
4056 }
4057 }
4058
4059 return false;
4060 }
4061
Wale Ogunwaled1880962016-11-08 10:31:59 -08004062 WindowState getWindow(Predicate<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004063 if (mChildren.isEmpty()) {
4064 return callback.test(this) ? this : null;
4065 }
4066
4067 // We want to consume the positive sublayer children first because they need to appear
4068 // above the parent, then this window (the parent), and then the negative sublayer children
4069 // because they need to appear above the parent.
4070 int i = mChildren.size() - 1;
4071 WindowState child = mChildren.get(i);
4072
4073 while (i >= 0 && child.mSubLayer >= 0) {
4074 if (callback.test(child)) {
4075 return child;
4076 }
4077 --i;
4078 if (i < 0) {
4079 break;
4080 }
4081 child = mChildren.get(i);
4082 }
4083
Wale Ogunwaled1880962016-11-08 10:31:59 -08004084 if (callback.test(this)) {
4085 return this;
4086 }
Wale Ogunwale34247952017-02-19 11:57:53 -08004087
4088 while (i >= 0) {
4089 if (callback.test(child)) {
4090 return child;
4091 }
4092 --i;
4093 if (i < 0) {
4094 break;
4095 }
4096 child = mChildren.get(i);
4097 }
4098
4099 return null;
Wale Ogunwaled1880962016-11-08 10:31:59 -08004100 }
4101
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004102 boolean isWindowAnimationSet() {
4103 if (mWinAnimator.isWindowAnimationSet()) {
4104 return true;
4105 }
4106 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004107 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004108 if (c.isWindowAnimationSet()) {
4109 return true;
4110 }
4111 }
4112 return false;
4113 }
4114
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004115 void onExitAnimationDone() {
4116 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
4117 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
4118 + " windowAnimating=" + mWinAnimator.isWindowAnimationSet());
4119
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004120 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004121 // Copying to a different list as multiple children can be removed.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004122 // TODO: Not sure if we really need to copy this into a different list.
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004123 final LinkedList<WindowState> childWindows = new LinkedList(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004124 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004125 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004126 }
4127 }
4128
4129 if (mWinAnimator.mEnteringAnimation) {
4130 mWinAnimator.mEnteringAnimation = false;
4131 mService.requestTraversal();
4132 // System windows don't have an activity and an app token as a result, but need a way
4133 // to be informed about their entrance animation end.
4134 if (mAppToken == null) {
4135 try {
4136 mClient.dispatchWindowShown();
4137 } catch (RemoteException e) {
4138 }
4139 }
4140 }
4141
4142 if (!mWinAnimator.isWindowAnimationSet()) {
4143 //TODO (multidisplay): Accessibility is supported only for the default display.
4144 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
4145 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
4146 }
4147 }
4148
4149 if (!mAnimatingExit) {
4150 return;
4151 }
4152
4153 if (mWinAnimator.isWindowAnimationSet()) {
4154 return;
4155 }
4156
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07004157 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004158 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
4159
4160 mDestroying = true;
4161
4162 final boolean hasSurface = mWinAnimator.hasSurface();
4163 if (hasSurface) {
4164 mWinAnimator.hide("onExitAnimationDone");
4165 }
4166
4167 // If we have an app token, we ask it to destroy the surface for us, so that it can take
4168 // care to ensure the activity has actually stopped and the surface is not still in use.
4169 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
4170 // transaction.
4171 if (mAppToken != null) {
4172 mAppToken.destroySurfaces();
4173 } else {
4174 if (hasSurface) {
4175 mService.mDestroySurface.add(this);
4176 }
4177 if (mRemoveOnExit) {
4178 mService.mPendingRemove.add(this);
4179 mRemoveOnExit = false;
4180 }
4181 }
4182 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07004183 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004184 }
Dan Willemsen117197f2016-07-30 13:02:59 -07004185
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004186 boolean clearAnimatingFlags() {
4187 boolean didSomething = false;
4188 // We don't want to clear it out for windows that get replaced, because the
4189 // animation depends on the flag to remove the replaced window.
4190 //
4191 // We also don't clear the mAnimatingExit flag for windows which have the
4192 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4193 // by the client. We should let animation proceed and not clear this flag or
4194 // they won't eventually be removed by WindowStateAnimator#finishExit.
4195 if (!mWillReplaceWindow && !mRemoveOnExit) {
4196 // Clear mAnimating flag together with mAnimatingExit. When animation
4197 // changes from exiting to entering, we need to clear this flag until the
4198 // new animation gets applied, so that isAnimationStarting() becomes true
4199 // until then.
4200 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4201 // placement for this window during this period, one or more frame will
4202 // show up with wrong position or scale.
4203 if (mAnimatingExit) {
4204 mAnimatingExit = false;
4205 didSomething = true;
4206 }
4207 if (mWinAnimator.mAnimating) {
4208 mWinAnimator.mAnimating = false;
4209 didSomething = true;
4210 }
4211 if (mDestroying) {
4212 mDestroying = false;
4213 mService.mDestroySurface.remove(this);
4214 didSomething = true;
4215 }
4216 }
4217
4218 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004219 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004220 }
4221
4222 return didSomething;
4223 }
4224
Winson4b4ba902016-07-27 19:45:52 -07004225 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004226 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004227 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004228
4229 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004230 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004231 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004232 c.hideWallpaperWindow(wasDeferred, reason);
4233 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004234 if (!mWinAnimator.mLastHidden || wasDeferred) {
4235 mWinAnimator.hide(reason);
4236 dispatchWallpaperVisibility(false);
4237 final DisplayContent displayContent = getDisplayContent();
4238 if (displayContent != null) {
4239 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
4240 }
4241 }
4242 }
4243
4244 /**
4245 * Check wallpaper window for visibility change and notify window if so.
4246 * @param visible Current visibility.
4247 */
4248 void dispatchWallpaperVisibility(final boolean visible) {
4249 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07004250 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004251
4252 // Only send notification if the visibility actually changed and we are not trying to hide
4253 // the wallpaper when we are deferring hiding of the wallpaper.
4254 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4255 mWallpaperVisible = visible;
4256 try {
4257 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4258 "Updating vis of wallpaper " + this
4259 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4260 mClient.dispatchAppVisibility(visible);
4261 } catch (RemoteException e) {
4262 }
4263 }
4264 }
4265
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004266 boolean hasVisibleNotDrawnWallpaper() {
4267 if (mWallpaperVisible && !isDrawnLw()) {
4268 return true;
4269 }
4270 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004271 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004272 if (c.hasVisibleNotDrawnWallpaper()) {
4273 return true;
4274 }
4275 }
4276 return false;
4277 }
4278
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004279 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4280 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004281 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004282 c.updateReportedVisibility(results);
4283 }
4284
4285 if (mAppFreezing || mViewVisibility != View.VISIBLE
4286 || mAttrs.type == TYPE_APPLICATION_STARTING
4287 || mDestroying) {
4288 return;
4289 }
4290 if (DEBUG_VISIBILITY) {
4291 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
4292 + ", isAnimationSet=" + mWinAnimator.isAnimationSet());
4293 if (!isDrawnLw()) {
4294 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4295 + " pv=" + mPolicyVisibility
4296 + " mDrawState=" + mWinAnimator.mDrawState
4297 + " ph=" + isParentWindowHidden()
4298 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
4299 + " a=" + mWinAnimator.mAnimating);
4300 }
4301 }
4302
4303 results.numInteresting++;
4304 if (isDrawnLw()) {
4305 results.numDrawn++;
4306 if (!mWinAnimator.isAnimationSet()) {
4307 results.numVisible++;
4308 }
4309 results.nowGone = false;
4310 } else if (mWinAnimator.isAnimationSet()) {
4311 results.nowGone = false;
4312 }
4313 }
4314
Robert Carrfbbde852016-10-18 11:02:28 -07004315 /**
4316 * Calculate the window crop according to system decor policy. In general this is
4317 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4318 * special cases. This rectangle is in screen space.
4319 */
4320 void calculatePolicyCrop(Rect policyCrop) {
4321 final DisplayContent displayContent = getDisplayContent();
4322 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
4323
4324 if (!isDefaultDisplay()) {
4325 // On a different display there is no system decor. Crop the window
4326 // by the screen boundaries.
4327 // TODO(multi-display)
4328 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4329 policyCrop.intersect(-mCompatFrame.left, -mCompatFrame.top,
4330 displayInfo.logicalWidth - mCompatFrame.left,
4331 displayInfo.logicalHeight - mCompatFrame.top);
4332 } else if (mLayer >= mService.mSystemDecorLayer) {
4333 // Above the decor layer is easy, just use the entire window
4334 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4335 } else if (mDecorFrame.isEmpty()) {
4336 // Windows without policy decor aren't cropped.
4337 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4338 } else {
4339 // Crop to the system decor specified by policy.
4340 calculateSystemDecorRect(policyCrop);
4341 }
4342 }
4343
4344 /**
4345 * The system decor rect is the region of the window which is not covered
4346 * by system decorations.
4347 */
4348 private void calculateSystemDecorRect(Rect systemDecorRect) {
4349 final Rect decorRect = mDecorFrame;
4350 final int width = mFrame.width();
4351 final int height = mFrame.height();
4352
4353 // Compute the offset of the window in relation to the decor rect.
4354 final int left = mXOffset + mFrame.left;
4355 final int top = mYOffset + mFrame.top;
4356
4357 // Initialize the decor rect to the entire frame.
4358 if (isDockedResizing()) {
4359 // If we are resizing with the divider, the task bounds might be smaller than the
4360 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4361 // want in this case in order to avoid holes.
4362 //
4363 // We take care to not shrink the width, for surfaces which are larger than
4364 // the display region. Of course this area will not eventually be visible
4365 // but if we truncate the width now, we will calculate incorrectly
4366 // when adjusting to the stack bounds.
4367 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4368 systemDecorRect.set(0, 0,
4369 Math.max(width, displayInfo.logicalWidth),
4370 Math.max(height, displayInfo.logicalHeight));
4371 } else {
4372 systemDecorRect.set(0, 0, width, height);
4373 }
4374
4375 // If a freeform window is animating from a position where it would be cutoff, it would be
4376 // cutoff during the animation. We don't want that, so for the duration of the animation
4377 // we ignore the decor cropping and depend on layering to position windows correctly.
4378 final boolean cropToDecor = !(inFreeformWorkspace() && isAnimatingLw());
4379 if (cropToDecor) {
4380 // Intersect with the decor rect, offsetted by window position.
4381 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
4382 decorRect.right - left, decorRect.bottom - top);
4383 }
4384
4385 // If size compatibility is being applied to the window, the
4386 // surface is scaled relative to the screen. Also apply this
4387 // scaling to the crop rect. We aren't using the standard rect
4388 // scale function because we want to round things to make the crop
4389 // always round to a larger rect to ensure we don't crop too
4390 // much and hide part of the window that should be seen.
4391 if (mEnforceSizeCompat && mInvGlobalScale != 1.0f) {
4392 final float scale = mInvGlobalScale;
4393 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
4394 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
4395 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
4396 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
4397 }
4398
4399 }
4400
4401 /**
4402 * Expand the given rectangle by this windows surface insets. This
4403 * takes you from the 'window size' to the 'surface size'.
4404 * The surface insets are positive in each direction, so we inset by
4405 * the inverse.
4406 */
4407 void expandForSurfaceInsets(Rect r) {
4408 r.inset(-mAttrs.surfaceInsets.left,
4409 -mAttrs.surfaceInsets.top,
4410 -mAttrs.surfaceInsets.right,
4411 -mAttrs.surfaceInsets.bottom);
4412 }
4413
Robert Carrc91d1c32017-02-15 19:37:46 -08004414 boolean surfaceInsetsChanging() {
4415 return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets);
4416 }
4417
Bryce Leef858b572017-06-29 14:03:33 -07004418 int relayoutVisibleWindow(int result, int attrChanges, int oldVisibility) {
Robert Carrecc06b32017-04-18 14:25:10 -07004419 final boolean wasVisible = isVisibleLw();
4420
4421 result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004422 if (mAnimatingExit) {
4423 Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit="
4424 + mRemoveOnExit + ", mDestroying=" + mDestroying);
4425
4426 mWinAnimator.cancelExitAnimationForNextAnimationLocked();
4427 mAnimatingExit = false;
4428 }
4429 if (mDestroying) {
4430 mDestroying = false;
4431 mService.mDestroySurface.remove(this);
4432 }
4433 if (oldVisibility == View.GONE) {
4434 mWinAnimator.mEnterAnimationPending = true;
4435 }
4436
Andrii Kulian8ee72852017-03-10 10:36:45 -08004437 mLastVisibleLayoutRotation = getDisplayContent().getRotation();
Robert Carrc91d1c32017-02-15 19:37:46 -08004438
4439 mWinAnimator.mEnteringAnimation = true;
Bryce Leeae73ba42017-05-05 09:58:25 -07004440
Bryce Leef858b572017-06-29 14:03:33 -07004441 prepareWindowToDisplayDuringRelayout(wasVisible);
Bryce Leeae73ba42017-05-05 09:58:25 -07004442
Robert Carrc91d1c32017-02-15 19:37:46 -08004443 if ((attrChanges & FORMAT_CHANGED) != 0) {
4444 // If the format can't be changed in place, preserve the old surface until the app draws
4445 // on the new one. This prevents blinking when we change elevation of freeform and
4446 // pinned windows.
4447 if (!mWinAnimator.tryChangeFormatInPlaceLocked()) {
4448 mWinAnimator.preserveSurfaceLocked();
4449 result |= RELAYOUT_RES_SURFACE_CHANGED
4450 | RELAYOUT_RES_FIRST_TIME;
4451 }
4452 }
4453
4454 // When we change the Surface size, in scenarios which may require changing
4455 // the surface position in sync with the resize, we use a preserved surface
4456 // so we can freeze it while waiting for the client to report draw on the newly
Winson Chung8bca9e42017-04-16 15:59:43 -07004457 // sized surface. Don't preserve surfaces if the insets change while animating the pinned
4458 // stack since it can lead to issues if a new surface is created while calculating the
4459 // scale for the animation using the source hint rect
4460 // (see WindowStateAnimator#setSurfaceBoundariesLocked()).
Robert Carrc91d1c32017-02-15 19:37:46 -08004461 if (isDragResizeChanged() || isResizedWhileNotDragResizing()
Winson Chung8bca9e42017-04-16 15:59:43 -07004462 || (surfaceInsetsChanging() && !inPinnedWorkspace())) {
Robert Carrc91d1c32017-02-15 19:37:46 -08004463 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
4464
4465 setDragResizing();
4466 setResizedWhileNotDragResizing(false);
4467 // We can only change top level windows to the full-screen surface when
4468 // resizing (as we only have one full-screen surface). So there is no need
4469 // to preserve and destroy windows which are attached to another, they
4470 // will keep their surface and its size may change over time.
4471 if (mHasSurface && !isChildWindow()) {
4472 mWinAnimator.preserveSurfaceLocked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08004473 result |= RELAYOUT_RES_SURFACE_CHANGED |
4474 RELAYOUT_RES_FIRST_TIME;
Robert Carrc91d1c32017-02-15 19:37:46 -08004475 }
4476 }
4477 final boolean freeformResizing = isDragResizing()
4478 && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
4479 final boolean dockedResizing = isDragResizing()
4480 && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
4481 result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0;
4482 result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0;
4483 if (isAnimatingWithSavedSurface()) {
4484 // If we're animating with a saved surface now, request client to report draw.
4485 // We still need to know when the real thing is drawn.
4486 result |= RELAYOUT_RES_FIRST_TIME;
4487 }
4488 return result;
4489 }
4490
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004491 /**
4492 * @return True if this window has been laid out at least once; false otherwise.
4493 */
4494 boolean isLaidOut() {
4495 return mLayoutSeq != -1;
4496 }
4497
4498 /**
4499 * Updates the last inset values to the current ones.
4500 */
4501 void updateLastInsetValues() {
4502 mLastOverscanInsets.set(mOverscanInsets);
4503 mLastContentInsets.set(mContentInsets);
4504 mLastVisibleInsets.set(mVisibleInsets);
4505 mLastStableInsets.set(mStableInsets);
4506 mLastOutsets.set(mOutsets);
4507 }
4508
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004509 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4510 // access to its windows children. Need to investigate re-writing
4511 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4512 static final class UpdateReportedVisibilityResults {
4513 int numInteresting;
4514 int numVisible;
4515 int numDrawn;
4516 boolean nowGone = true;
4517
4518 void reset() {
4519 numInteresting = 0;
4520 numVisible = 0;
4521 numDrawn = 0;
4522 nowGone = true;
4523 }
4524 }
Robert Carraf422a82017-04-10 18:34:33 -07004525
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004526 private static final class WindowId extends IWindowId.Stub {
4527 private final WeakReference<WindowState> mOuter;
4528
4529 private WindowId(WindowState outer) {
4530
4531 // Use a weak reference for the outer class. This is important to prevent the following
4532 // leak: Since we send this class to the client process, binder will keep it alive as
4533 // long as the client keeps it alive. Now, if the window is removed, we need to clear
4534 // out our reference so even though this class is kept alive we don't leak WindowState,
4535 // which can keep a whole lot of classes alive.
4536 mOuter = new WeakReference<>(outer);
4537 }
4538
4539 @Override
4540 public void registerFocusObserver(IWindowFocusObserver observer) {
4541 final WindowState outer = mOuter.get();
4542 if (outer != null) {
4543 outer.registerFocusObserver(observer);
4544 }
4545 }
4546 @Override
4547 public void unregisterFocusObserver(IWindowFocusObserver observer) {
4548 final WindowState outer = mOuter.get();
4549 if (outer != null) {
4550 outer.unregisterFocusObserver(observer);
4551 }
4552 }
4553 @Override
4554 public boolean isFocused() {
4555 final WindowState outer = mOuter.get();
4556 return outer != null && outer.isFocused();
4557 }
4558 }
4559
Robert Carraf422a82017-04-10 18:34:33 -07004560 boolean usesRelativeZOrdering() {
4561 if (!isChildWindow()) {
4562 return false;
4563 } else if (mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) {
4564 return true;
4565 } else {
4566 return false;
4567 }
4568 }
satokcef37fb2011-10-24 21:49:38 +09004569}