blob: 2c5b035741569b20e5a408d2742aa8ad60ea6fc4 [file] [log] [blame]
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Wale Ogunwale053c8e42015-11-16 14:27:21 -080019import android.app.ActivityManager;
20import android.app.AppOpsManager;
21import android.content.Context;
22import android.content.res.Configuration;
23import android.graphics.Matrix;
24import android.graphics.PixelFormat;
25import android.graphics.Point;
26import android.graphics.Rect;
27import android.graphics.Region;
28import android.os.IBinder;
29import android.os.PowerManager;
30import android.os.RemoteCallbackList;
31import android.os.RemoteException;
32import android.os.SystemClock;
33import android.os.Trace;
34import android.os.UserHandle;
35import android.os.WorkSource;
36import android.util.DisplayMetrics;
37import android.util.Slog;
38import android.util.TimeUtils;
39import android.view.Display;
40import android.view.DisplayInfo;
41import android.view.Gravity;
42import android.view.IApplicationToken;
43import android.view.IWindow;
44import android.view.IWindowFocusObserver;
45import android.view.IWindowId;
46import android.view.InputChannel;
47import android.view.InputEvent;
48import android.view.InputEventReceiver;
49import android.view.View;
50import android.view.ViewTreeObserver;
51import android.view.WindowManager;
52import android.view.WindowManagerPolicy;
53
Jorim Jaggi9511b0f2016-01-29 19:12:44 -080054import com.android.server.input.InputWindowHandle;
55
Wale Ogunwale053c8e42015-11-16 14:27:21 -080056import java.io.PrintWriter;
57import java.util.ArrayList;
58
Wale Ogunwaled045c822015-12-02 09:14:28 -080059import static android.app.ActivityManager.StackId;
Wale Ogunwalea9f9b372016-02-04 18:04:39 -080060import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
Filip Gruszczynski84fa3352016-01-25 16:28:49 -080061import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
Wale Ogunwalecad05a02015-09-25 10:41:44 -070062import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080063import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
64import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
65import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
66import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080067import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080068import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070069import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080070import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080071import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
72import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080073import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Wale Ogunwale945d1972016-03-23 13:16:41 -070074import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070075import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080076import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080077import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
Robert Carr31e28482015-12-02 16:53:18 -080078import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080079import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080080import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -080081import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
Robert Carra1eb4392015-12-10 12:43:51 -080082import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080083import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
84import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
Robert Carrd1a010f2016-04-07 22:36:22 -070085import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080086import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080087import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070088import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080089import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
90import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
91import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +010092import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
93import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080094import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
95import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
96import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
97import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
98import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
99import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
100import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
101import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
102import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
103import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
104import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
105import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800106
Craig Mautner59c00972012-07-30 12:10:24 -0700107class WindowList extends ArrayList<WindowState> {
Wale Ogunwale33fde7d2016-03-05 22:38:51 -0800108 WindowList() {}
109 WindowList(WindowList windowList) {
110 super(windowList);
111 }
Craig Mautner59c00972012-07-30 12:10:24 -0700112}
113
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800114/**
115 * A window in the window manager.
116 */
Craig Mautnere32c3072012-03-12 15:25:35 -0700117final class WindowState implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800118 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800119
Skuhne81c524a2015-08-12 13:34:14 -0700120 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700121 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
122 // use hard-coded min sizes for now.
123 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
124 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700125
126 // The thickness of a window resize handle outside the window bounds on the free form workspace
127 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700128 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700129
Robert Carr7098dbd2016-02-01 12:31:01 -0800130 static final boolean DEBUG_DISABLE_SAVING_SURFACES = false;
131
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800132 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700133 final WindowManagerPolicy mPolicy;
134 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800135 final Session mSession;
136 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800137 final int mAppOp;
138 // UserId and appId of the owner. Don't display windows of non-current user.
139 final int mOwnerUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800140 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800141 WindowToken mToken;
142 WindowToken mRootToken;
143 AppWindowToken mAppToken;
144 AppWindowToken mTargetAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700145
146 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
147 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800148 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
149 final DeathRecipient mDeathRecipient;
150 final WindowState mAttachedWindow;
Craig Mautner7b1aa772012-11-30 16:14:45 -0800151 final WindowList mChildWindows = new WindowList();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800152 final int mBaseLayer;
153 final int mSubLayer;
154 final boolean mLayoutAttached;
155 final boolean mIsImWindow;
156 final boolean mIsWallpaper;
157 final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700158 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700159 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800160 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700161 int mSystemUiVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800162 boolean mPolicyVisibility = true;
163 boolean mPolicyVisibilityAfterAnim = true;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -0800164 boolean mAppOpVisibility = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800165 boolean mAppFreezing;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800166 boolean mAttachedHidden; // is our parent window hidden?
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800167 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Chong Zhang0275e392015-09-17 10:41:44 -0700168 boolean mDragResizing;
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800169 boolean mDragResizingChangeReported;
Jorim Jaggidcf467c2015-11-05 13:59:32 +0100170 int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700171
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800172 RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
173
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700174 /**
175 * The window size that was requested by the application. These are in
176 * the application's coordinate space (without compatibility scale applied).
177 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800178 int mRequestedWidth;
179 int mRequestedHeight;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700180 int mLastRequestedWidth;
181 int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700182
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800183 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800184 boolean mHaveFrame;
185 boolean mObscured;
186 boolean mTurnOnScreen;
187
188 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700189
Wale Ogunwale60454db2015-01-23 16:05:07 -0800190 private Configuration mConfiguration = Configuration.EMPTY;
191 private Configuration mOverrideConfig = Configuration.EMPTY;
Robert Carrc24d8f92016-02-29 16:24:33 -0800192 // Represents the changes from our override configuration applied
193 // to the global configuration. This is the only form of configuration
194 // which is suitable for delivery to the client.
195 private Configuration mMergedConfiguration = new Configuration();
Craig Mautnere8552142012-11-07 13:55:47 -0800196 // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned.
197 // Used only on {@link #TYPE_KEYGUARD}.
198 private boolean mConfigHasChanged;
Craig Mautnera2c77052012-03-26 12:14:43 -0700199
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700200 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700201 * Actual position of the surface shown on-screen (may be modified by animation). These are
202 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700203 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700204 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800205
206 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700207 * Insets that determine the actually visible area. These are in the application's
208 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800209 */
210 final Rect mVisibleInsets = new Rect();
211 final Rect mLastVisibleInsets = new Rect();
212 boolean mVisibleInsetsChanged;
213
214 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700215 * Insets that are covered by system windows (such as the status bar) and
216 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700217 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800218 */
219 final Rect mContentInsets = new Rect();
220 final Rect mLastContentInsets = new Rect();
221 boolean mContentInsetsChanged;
222
223 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800224 * Insets that determine the area covered by the display overscan region. These are in the
225 * application's coordinate space (without compatibility scale applied).
226 */
227 final Rect mOverscanInsets = new Rect();
228 final Rect mLastOverscanInsets = new Rect();
229 boolean mOverscanInsetsChanged;
230
231 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700232 * Insets that determine the area covered by the stable system windows. These are in the
233 * application's coordinate space (without compatibility scale applied).
234 */
235 final Rect mStableInsets = new Rect();
236 final Rect mLastStableInsets = new Rect();
237 boolean mStableInsetsChanged;
238
239 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700240 * Outsets determine the area outside of the surface where we want to pretend that it's possible
241 * to draw anyway.
242 */
243 final Rect mOutsets = new Rect();
244 final Rect mLastOutsets = new Rect();
245 boolean mOutsetsChanged = false;
246
247 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800248 * Set to true if we are waiting for this window to receive its
249 * given internal insets before laying out other windows based on it.
250 */
251 boolean mGivenInsetsPending;
252
253 /**
254 * These are the content insets that were given during layout for
255 * this window, to be applied to windows behind it.
256 */
257 final Rect mGivenContentInsets = new Rect();
258
259 /**
260 * These are the visible insets that were given during layout for
261 * this window, to be applied to windows behind it.
262 */
263 final Rect mGivenVisibleInsets = new Rect();
264
265 /**
266 * This is the given touchable area relative to the window frame, or null if none.
267 */
268 final Region mGivenTouchableRegion = new Region();
269
270 /**
271 * Flag indicating whether the touchable region should be adjusted by
272 * the visible insets; if false the area outside the visible insets is
273 * NOT touchable, so we must use those to adjust the frame during hit
274 * tests.
275 */
276 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
277
278 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400279 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700280 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800281 float mHScale=1, mVScale=1;
282 float mLastHScale=1, mLastVScale=1;
283 final Matrix mTmpMatrix = new Matrix();
284
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700285 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800286 final Rect mFrame = new Rect();
287 final Rect mLastFrame = new Rect();
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700288 // Frame that is scaled to the application's coordinate space when in
289 // screen size compatibility mode.
290 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800291
292 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700293
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800294 final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700295
Wale Ogunwale94596652015-02-06 19:27:34 -0800296 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
297 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700298 final Rect mDisplayFrame = new Rect();
299
300 // The region of the display frame that the display type supports displaying content on. This
301 // is mostly a special case for TV where some displays don’t have the entire display usable.
302 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
303 // window display contents to extend into the overscan region.
304 final Rect mOverscanFrame = new Rect();
305
306 // The display frame minus the stable insets. This value is always constant regardless of if
307 // the status bar or navigation bar is visible.
Adrian Roosfa104232014-06-20 16:10:14 -0700308 final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800309
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700310 // The area not occupied by the status and navigation bars. So, if both status and navigation
311 // bars are visible, the decor frame is equal to the stable frame.
312 final Rect mDecorFrame = new Rect();
313
314 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
315 // minus the area occupied by the IME if the IME is present.
316 final Rect mContentFrame = new Rect();
317
318 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
319 // displays hint text.
320 final Rect mVisibleFrame = new Rect();
321
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700322 // Frame that includes dead area outside of the surface but where we want to pretend that it's
323 // possible to draw.
324 final Rect mOutsetFrame = new Rect();
325
Jorim Jaggidc249c42015-12-15 14:57:31 -0800326 /**
327 * Usually empty. Set to the task's tempInsetFrame. See
328 *{@link android.app.IActivityManager#resizeDockedStack}.
329 */
330 final Rect mInsetFrame = new Rect();
331
Jorim Jaggif5834272016-04-04 20:25:41 -0700332 private static final Rect sTmpRect = new Rect();
333
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800334 boolean mContentChanged;
335
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800336 // If a window showing a wallpaper: the requested offset for the
337 // wallpaper; if a wallpaper window: the currently applied offset.
338 float mWallpaperX = -1;
339 float mWallpaperY = -1;
340
341 // If a window showing a wallpaper: what fraction of the offset
342 // range corresponds to a full virtual screen.
343 float mWallpaperXStep = -1;
344 float mWallpaperYStep = -1;
345
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700346 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
347 // to its window; if a wallpaper window: not used.
348 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
349 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
350
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800351 // Wallpaper windows: pixels offset based on above variables.
352 int mXOffset;
353 int mYOffset;
354
Craig Mautner2268e7e2012-12-13 15:40:00 -0800355 /**
356 * This is set after IWindowSession.relayout() has been called at
357 * least once for the window. It allows us to detect the situation
358 * where we don't yet have a surface, but should have one soon, so
359 * we can give the window focus before waiting for the relayout.
360 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800361 boolean mRelayoutCalled;
362
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800363 /**
364 * If the application has called relayout() with changes that can
365 * impact its window's size, we need to perform a layout pass on it
366 * even if it is not currently visible for layout. This is set
367 * when in that case until the layout is done.
368 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800369 boolean mLayoutNeeded;
370
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800371 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800372 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800373
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800374 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800375 boolean mDestroying;
376
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800377 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800378 boolean mRemoveOnExit;
379
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800380 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800381 * Whether the app died while it was visible, if true we might need
382 * to continue to show it until it's restarted.
383 */
384 boolean mAppDied;
385
386 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800387 * Set when the orientation is changing and this window has not yet
388 * been updated for the new orientation.
389 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800390 boolean mOrientationChanging;
391
Dianne Hackborna57c6952013-03-29 14:46:40 -0700392 /**
393 * How long we last kept the screen frozen.
394 */
395 int mLastFreezeDuration;
396
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800397 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800398 boolean mRemoved;
399
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800400 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800401 * It is save to remove the window and destroy the surface because the client requested removal
402 * or some other higher level component said so (e.g. activity manager).
403 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800404 */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800405 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800406
407 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800408 * Temp for keeping track of windows that have been removed when
409 * rebuilding window list.
410 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800411 boolean mRebuilding;
412
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800413 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700414 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800415 InputChannel mInputChannel;
Chong Zhang112eb8c2015-11-02 11:17:00 -0800416 InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800417
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800418 // Used to improve performance of toString()
419 String mStringNameCache;
420 CharSequence mLastTitle;
Dianne Hackborn529e7442012-11-01 14:22:28 -0700421 boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800422
Craig Mautnera2c77052012-03-26 12:14:43 -0700423 final WindowStateAnimator mWinAnimator;
424
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700425 boolean mHasSurface = false;
426
Craig Mautner19ab8282014-05-07 10:35:34 -0700427 boolean mNotOnAppsDisplay = false;
Craig Mautner59c00972012-07-30 12:10:24 -0700428 DisplayContent mDisplayContent;
Craig Mautner6881a102012-07-27 13:04:51 -0700429
Craig Mautner88400d32012-09-30 12:35:45 -0700430 /** When true this window can be displayed on screens owther than mOwnerUid's */
431 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700432
Robert Carr13f7be9e2015-12-02 18:39:45 -0800433 // Whether the window has a saved surface from last pause, which can be
434 // used to start an entering animation earlier.
435 public boolean mSurfaceSaved = false;
436
Robert Carra1eb4392015-12-10 12:43:51 -0800437 // This window will be replaced due to relaunch. This allows window manager
438 // to differentiate between simple removal of a window and replacement. In the latter case it
439 // will preserve the old window until the new one is drawn.
440 boolean mWillReplaceWindow = false;
441 // If true, the replaced window was already requested to be removed.
442 boolean mReplacingRemoveRequested = false;
443 // Whether the replacement of the window should trigger app transition animation.
444 boolean mAnimateReplacingWindow = false;
445 // If not null, the window that will be used to replace the old one. This is being set when
446 // the window is added and unset when this window reports its first draw.
447 WindowState mReplacingWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700448 // For the new window in the replacement transition, if we have
449 // requested to replace without animation, then we should
450 // make sure we also don't apply an enter animation for
451 // the new window.
452 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800453 // Whether this window is being moved via the resize API
454 boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800455
Jeff Brownc2932a12014-11-20 18:04:05 -0800456 /**
457 * Wake lock for drawing.
458 * Even though it's slightly more expensive to do so, we will use a separate wake lock
459 * for each app that is requesting to draw while dozing so that we can accurately track
460 * who is preventing the system from suspending.
461 * This lock is only acquired on first use.
462 */
463 PowerManager.WakeLock mDrawLock;
464
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700465 final private Rect mTmpRect = new Rect();
466
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800467 /**
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800468 * See {@link #notifyMovedInStack}.
469 */
470 private boolean mJustMovedInStack;
471
472 /**
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800473 * Whether the window was resized by us while it was gone for layout.
474 */
475 boolean mResizedWhileGone = false;
476
Jorim Jaggif3df0aa2016-04-06 15:56:33 -0700477 /**
478 * Indicates whether we got resized but drag resizing flag was false. In this case, we also
479 * need to recreate the surface and defer surface bound updates in order to make sure the
480 * buffer contents and the positioning/size stay in sync.
481 */
482 boolean mResizedWhileNotDragResizing;
483
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800484 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800485 WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a,
Craig Mautner59c00972012-07-30 12:10:24 -0700486 int viewVisibility, final DisplayContent displayContent) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800487 mService = service;
488 mSession = s;
489 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800490 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800491 mToken = token;
Craig Mautnera2d7b112012-08-21 15:12:20 -0700492 mOwnerUid = s.mUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800493 mWindowId = new IWindowId.Stub() {
494 @Override
495 public void registerFocusObserver(IWindowFocusObserver observer) {
496 WindowState.this.registerFocusObserver(observer);
497 }
498 @Override
499 public void unregisterFocusObserver(IWindowFocusObserver observer) {
500 WindowState.this.unregisterFocusObserver(observer);
501 }
502 @Override
503 public boolean isFocused() {
504 return WindowState.this.isFocused();
505 }
506 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800507 mAttrs.copyFrom(a);
508 mViewVisibility = viewVisibility;
Craig Mautner59c00972012-07-30 12:10:24 -0700509 mDisplayContent = displayContent;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700510 mPolicy = mService.mPolicy;
511 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800512 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700513 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700514 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800515 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700516 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700517 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800518 try {
519 c.asBinder().linkToDeath(deathRecipient, 0);
520 } catch (RemoteException e) {
521 mDeathRecipient = null;
522 mAttachedWindow = null;
523 mLayoutAttached = false;
524 mIsImWindow = false;
525 mIsWallpaper = false;
526 mIsFloatingLayer = false;
527 mBaseLayer = 0;
528 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700529 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700530 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800531 return;
532 }
533 mDeathRecipient = deathRecipient;
534
535 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
536 mAttrs.type <= LAST_SUB_WINDOW)) {
537 // The multiplier here is to reserve space for multiple
538 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700539 mBaseLayer = mPolicy.windowTypeToLayerLw(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800540 attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
541 + WindowManagerService.TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700542 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800543 mAttachedWindow = attachedWindow;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800544 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
takeda.masayuki18735092012-12-12 11:06:24 +0900545
tiger_huange2a98a72014-11-13 19:46:28 +0800546 final WindowList childWindows = mAttachedWindow.mChildWindows;
547 final int numChildWindows = childWindows.size();
548 if (numChildWindows == 0) {
549 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900550 } else {
tiger_huange2a98a72014-11-13 19:46:28 +0800551 boolean added = false;
552 for (int i = 0; i < numChildWindows; i++) {
553 final int childSubLayer = childWindows.get(i).mSubLayer;
554 if (mSubLayer < childSubLayer
555 || (mSubLayer == childSubLayer && childSubLayer < 0)) {
556 // We insert the child window into the list ordered by the sub-layer. For
557 // same sub-layers, the negative one should go below others; the positive
558 // one should go above others.
559 childWindows.add(i, this);
560 added = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900561 break;
takeda.masayuki18735092012-12-12 11:06:24 +0900562 }
563 }
tiger_huange2a98a72014-11-13 19:46:28 +0800564 if (!added) {
565 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900566 }
567 }
568
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800569 mLayoutAttached = mAttrs.type !=
570 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
571 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
572 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
573 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
574 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
575 } else {
576 // The multiplier here is to reserve space for multiple
577 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700578 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800579 * WindowManagerService.TYPE_LAYER_MULTIPLIER
580 + WindowManagerService.TYPE_LAYER_OFFSET;
581 mSubLayer = 0;
582 mAttachedWindow = null;
583 mLayoutAttached = false;
584 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
585 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
586 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
587 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
588 }
589
590 WindowState appWin = this;
Robert Carr51a1b872015-12-08 14:03:13 -0800591 while (appWin.isChildWindow()) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700592 appWin = appWin.mAttachedWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800593 }
594 WindowToken appToken = appWin.mToken;
595 while (appToken.appWindowToken == null) {
596 WindowToken parent = mService.mTokenMap.get(appToken.token);
597 if (parent == null || appToken == parent) {
598 break;
599 }
600 appToken = parent;
601 }
602 mRootToken = appToken;
603 mAppToken = appToken.appWindowToken;
Craig Mautner19ab8282014-05-07 10:35:34 -0700604 if (mAppToken != null) {
605 final DisplayContent appDisplay = getDisplayContent();
606 mNotOnAppsDisplay = displayContent != appDisplay;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700607
608 if (mAppToken.showForAllUsers) {
609 // Windows for apps that can show for all users should also show when the
610 // device is locked.
611 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
612 }
Craig Mautner19ab8282014-05-07 10:35:34 -0700613 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800614
Craig Mautner322e4032012-07-13 13:35:20 -0700615 mWinAnimator = new WindowStateAnimator(this);
616 mWinAnimator.mAlpha = a.alpha;
617
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800618 mRequestedWidth = 0;
619 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700620 mLastRequestedWidth = 0;
621 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800622 mXOffset = 0;
623 mYOffset = 0;
624 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800625 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700626 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
627 displayContent.getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800628 }
629
630 void attach() {
631 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700632 TAG, "Attaching " + this + " token=" + mToken
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800633 + ", list=" + mToken.windows);
634 mSession.windowAddedLocked();
635 }
636
Craig Mautnera2c77052012-03-26 12:14:43 -0700637 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800638 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800639 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800640 }
641
642 @Override
643 public String getOwningPackage() {
644 return mAttrs.packageName;
645 }
646
Jorim Jaggif5834272016-04-04 20:25:41 -0700647 /**
648 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
649 * from {@param frame}. In other words, it applies the insets that would result if
650 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700651 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
652 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700653 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700654 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
655 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
656 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
657 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
658 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700659 frame.inset(left, top, right, bottom);
660 }
661
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800662 @Override
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700663 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf, Rect sf,
664 Rect osf) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800665 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700666 // This window is being replaced and either already got information that it's being
667 // removed or we are still waiting for some information. Because of this we don't
668 // want to apply any more changes to it, so it remains in this state until new window
669 // appears.
670 return;
671 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800672 mHaveFrame = true;
673
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700674 final Task task = getTask();
Andrii Kulian933076d2016-03-29 17:04:42 -0700675 final boolean fullscreenTask = !isInMultiWindowMode();
Robert Carre6275582016-02-29 15:45:45 -0800676 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800677
Chong Zhangae35fef2016-03-16 15:56:55 -0700678 // If the task has temp inset bounds set, we have to make sure all its windows uses
679 // the temp inset frame. Otherwise different display frames get applied to the main
680 // window and the child window, making them misaligned.
681 if (fullscreenTask) {
682 mInsetFrame.setEmpty();
683 } else {
684 task.getTempInsetBounds(mInsetFrame);
685 }
686
Jorim Jaggif5834272016-04-04 20:25:41 -0700687 // Denotes the actual frame used to calculate the insets and to perform the layout. When
688 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
689 // insets temporarily. By the notion of a task having a different layout frame, we can
690 // achieve that while still moving the task around.
691 final Rect layoutContainingFrame;
692 final Rect layoutDisplayFrame;
693
694 // The offset from the layout containing frame to the actual containing frame.
695 final int layoutXDiff;
696 final int layoutYDiff;
Andrii Kuliandaea3572016-04-08 13:20:51 -0700697 if (mInsetFrame.isEmpty() && (fullscreenTask || layoutInParentFrame())) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800698 // We use the parent frame as the containing frame for fullscreen and child windows
699 mContainingFrame.set(pf);
700 mDisplayFrame.set(df);
Jorim Jaggif5834272016-04-04 20:25:41 -0700701 layoutDisplayFrame = df;
702 layoutContainingFrame = pf;
703 layoutXDiff = 0;
704 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800705 } else {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700706 task.getBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100707 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
708
709 // If the bounds are frozen, we still want to translate the window freely and only
710 // freeze the size.
711 Rect frozen = mAppToken.mFrozenBounds.peek();
712 mContainingFrame.right = mContainingFrame.left + frozen.width();
713 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
714 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800715 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700716 // IME is up and obscuring this window. Adjust the window position so it is visible.
717 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this) {
718 if (windowsAreFloating && mContainingFrame.bottom > cf.bottom) {
719 // In freeform we want to move the top up directly.
720 // TODO: Investigate why this is cf not pf.
721 mContainingFrame.top -= mContainingFrame.bottom - cf.bottom;
722 } else if (mContainingFrame.bottom > pf.bottom) {
723 // But in docked we want to behave like fullscreen
724 // and behave as if the task were given smaller bounds
725 // for the purposes of layout.
726 mContainingFrame.bottom = pf.bottom;
727 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700728 }
Skuhne81c524a2015-08-12 13:34:14 -0700729
Robert Carre6275582016-02-29 15:45:45 -0800730 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700731 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
732 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800733 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700734 if (mContainingFrame.isEmpty()) {
735 mContainingFrame.set(cf);
736 }
Doris Liu06d582d2015-06-01 13:18:43 -0700737 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800738 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700739 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
740 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
741 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Andrii Kuliandaea3572016-04-08 13:20:51 -0700742 mTmpRect.set(0, 0, mDisplayContent.getDisplayInfo().logicalWidth,
743 mDisplayContent.getDisplayInfo().logicalHeight);
744 subtractInsets(mDisplayFrame, layoutContainingFrame, df, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700745 if (!layoutInParentFrame()) {
Andrii Kuliandaea3572016-04-08 13:20:51 -0700746 subtractInsets(mContainingFrame, layoutContainingFrame, pf, mTmpRect);
747 subtractInsets(mInsetFrame, layoutContainingFrame, pf, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700748 }
Jorim Jaggif5834272016-04-04 20:25:41 -0700749 layoutDisplayFrame = df;
750 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700751 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800752
Craig Mautner967212c2013-04-13 21:10:58 -0700753 final int pw = mContainingFrame.width();
754 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800755
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800756 if (!mParentFrame.equals(pf)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800757 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800758 // + " to " + pf);
759 mParentFrame.set(pf);
760 mContentChanged = true;
761 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700762 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
763 mLastRequestedWidth = mRequestedWidth;
764 mLastRequestedHeight = mRequestedHeight;
765 mContentChanged = true;
766 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800767
Craig Mautnereda67292013-04-28 13:50:14 -0700768 mOverscanFrame.set(of);
769 mContentFrame.set(cf);
770 mVisibleFrame.set(vf);
John Spurlock46646232013-09-30 22:32:42 -0400771 mDecorFrame.set(dcf);
Adrian Roosfa104232014-06-20 16:10:14 -0700772 mStableFrame.set(sf);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700773 final boolean hasOutsets = osf != null;
774 if (hasOutsets) {
775 mOutsetFrame.set(osf);
776 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800777
Craig Mautnereda67292013-04-28 13:50:14 -0700778 final int fw = mFrame.width();
779 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800780
Jorim Jaggif5834272016-04-04 20:25:41 -0700781 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
782
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700783 // Calculate the outsets before the content frame gets shrinked to the window frame.
784 if (hasOutsets) {
785 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
786 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
787 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
788 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
789 } else {
790 mOutsets.set(0, 0, 0, 0);
791 }
792
Craig Mautnera248eee2013-05-07 11:41:27 -0700793 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800794 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -0800795 if (windowsAreFloating && !mFrame.isEmpty()) {
Skuhne81c524a2015-08-12 13:34:14 -0700796 // Keep the frame out of the blocked system area, limit it in size to the content area
797 // and make sure that there is always a minimum visible so that the user can drag it
798 // into a usable area..
799 final int height = Math.min(mFrame.height(), mContentFrame.height());
800 final int width = Math.min(mContentFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700801 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700802 final int minVisibleHeight = WindowManagerService.dipToPixel(
803 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics);
804 final int minVisibleWidth = WindowManagerService.dipToPixel(
805 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics);
Skuhne81c524a2015-08-12 13:34:14 -0700806 final int top = Math.max(mContentFrame.top,
807 Math.min(mFrame.top, mContentFrame.bottom - minVisibleHeight));
808 final int left = Math.max(mContentFrame.left + minVisibleWidth - width,
809 Math.min(mFrame.left, mContentFrame.right - minVisibleWidth));
810 mFrame.set(left, top, left + width, top + height);
811 mContentFrame.set(mFrame);
812 mVisibleFrame.set(mContentFrame);
813 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700814 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi192086e2016-03-11 17:17:03 +0100815 mDisplayContent.getDockedDividerController().positionDockedStackedDivider(mFrame);
816 mContentFrame.set(mFrame);
817 if (!mFrame.equals(mLastFrame)) {
818 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800819 }
Skuhne81c524a2015-08-12 13:34:14 -0700820 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -0700821 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
822 Math.max(mContentFrame.top, mFrame.top),
823 Math.min(mContentFrame.right, mFrame.right),
824 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800825
Jorim Jaggi656f6502016-04-11 21:08:17 -0700826 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
827 Math.max(mVisibleFrame.top, mFrame.top),
828 Math.min(mVisibleFrame.right, mFrame.right),
829 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800830
Jorim Jaggi656f6502016-04-11 21:08:17 -0700831 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
832 Math.max(mStableFrame.top, mFrame.top),
833 Math.min(mStableFrame.right, mFrame.right),
834 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700835 }
Adrian Roosfa104232014-06-20 16:10:14 -0700836
Jorim Jaggi899327f2016-02-25 20:44:18 -0500837 if (fullscreenTask && !windowsAreFloating) {
838 // Windows that are not fullscreen can be positioned outside of the display frame,
839 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -0700840 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
841 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
842 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
843 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800844 }
Craig Mautnereda67292013-04-28 13:50:14 -0700845
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100846 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100847 // For the docked divider, we calculate the stable insets like a full-screen window
848 // so it can use it to calculate the snap positions.
849 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
850 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
851 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
852 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800853
854 // The divider doesn't care about insets in any case, so set it to empty so we don't
855 // trigger a relayout when moving it.
856 mContentInsets.setEmpty();
857 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100858 } else {
Andrii Kuliand9003372016-04-04 17:46:59 -0700859 getDisplayContent().getLogicalDisplayRect(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700860 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
861 // non-fullscreen mode.
Jorim Jaggi656f6502016-04-11 21:08:17 -0700862 boolean overrideRightInset = !fullscreenTask && mFrame.right > mTmpRect.right;
863 boolean overrideBottomInset = !fullscreenTask && mFrame.bottom > mTmpRect.bottom;
864 mContentInsets.set(mContentFrame.left - mFrame.left,
865 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700866 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700867 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700868 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700869 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800870
Jorim Jaggi656f6502016-04-11 21:08:17 -0700871 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
872 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700873 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700874 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700875 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700876 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800877
Jorim Jaggi656f6502016-04-11 21:08:17 -0700878 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
879 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700880 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700881 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700882 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700883 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100884 }
Adrian Roosfa104232014-06-20 16:10:14 -0700885
Jorim Jaggi656f6502016-04-11 21:08:17 -0700886 // Offset the actual frame by the amount layout frame is off.
887 mFrame.offset(-layoutXDiff, -layoutYDiff);
888 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -0700889 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
890 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
891 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
892
Craig Mautnereda67292013-04-28 13:50:14 -0700893 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400894 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700895 // If there is a size compatibility scale being applied to the
896 // window, we need to apply this to its insets so that they are
897 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700898 mOverscanInsets.scale(mInvGlobalScale);
899 mContentInsets.scale(mInvGlobalScale);
900 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700901 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700902 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700903
904 // Also the scaled frame that we report to the app needs to be
905 // adjusted to be in its coordinate space.
906 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400907 }
908
Craig Mautnereda67292013-04-28 13:50:14 -0700909 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800910 final DisplayContent displayContent = getDisplayContent();
911 if (displayContent != null) {
912 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700913 mService.mWallpaperControllerLocked.updateWallpaperOffset(
914 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800915 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800916 }
917
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700918 if (DEBUG_LAYOUT || WindowManagerService.localLOGV) Slog.v(TAG,
919 "Resolving (mRequestedWidth="
920 + mRequestedWidth + ", mRequestedheight="
921 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
922 + "): frame=" + mFrame.toShortString()
923 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -0700924 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700925 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700926 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800927 }
928
Craig Mautnera2c77052012-03-26 12:14:43 -0700929 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800930 public Rect getFrameLw() {
931 return mFrame;
932 }
933
Craig Mautnera2c77052012-03-26 12:14:43 -0700934 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700935 public Point getShownPositionLw() {
936 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800937 }
938
Craig Mautnera2c77052012-03-26 12:14:43 -0700939 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800940 public Rect getDisplayFrameLw() {
941 return mDisplayFrame;
942 }
943
Craig Mautnera2c77052012-03-26 12:14:43 -0700944 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800945 public Rect getOverscanFrameLw() {
946 return mOverscanFrame;
947 }
948
949 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800950 public Rect getContentFrameLw() {
951 return mContentFrame;
952 }
953
Craig Mautnera2c77052012-03-26 12:14:43 -0700954 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800955 public Rect getVisibleFrameLw() {
956 return mVisibleFrame;
957 }
958
Craig Mautnera2c77052012-03-26 12:14:43 -0700959 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800960 public boolean getGivenInsetsPendingLw() {
961 return mGivenInsetsPending;
962 }
963
Craig Mautnera2c77052012-03-26 12:14:43 -0700964 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800965 public Rect getGivenContentInsetsLw() {
966 return mGivenContentInsets;
967 }
968
Craig Mautnera2c77052012-03-26 12:14:43 -0700969 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800970 public Rect getGivenVisibleInsetsLw() {
971 return mGivenVisibleInsets;
972 }
973
Craig Mautnera2c77052012-03-26 12:14:43 -0700974 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800975 public WindowManager.LayoutParams getAttrs() {
976 return mAttrs;
977 }
978
Craig Mautner812d2ca2012-09-27 15:35:34 -0700979 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800980 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
981 int index = -1;
982 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -0700983 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800984 while (true) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -0700985 if (ws.mAttrs.needsMenuKey != WindowManager.LayoutParams.NEEDS_MENU_UNSET) {
986 return ws.mAttrs.needsMenuKey == WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800987 }
988 // If we reached the bottom of the range of windows we are considering,
989 // assume no menu is needed.
990 if (ws == bottom) {
991 return false;
992 }
993 // The current window hasn't specified whether menu key is needed;
994 // look behind it.
995 // First, we may need to determine the starting position.
996 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -0700997 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800998 }
999 index--;
1000 if (index < 0) {
1001 return false;
1002 }
Craig Mautner59c00972012-07-30 12:10:24 -07001003 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001004 }
1005 }
1006
Craig Mautner19d59bc2012-09-04 11:15:56 -07001007 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001008 public int getSystemUiVisibility() {
1009 return mSystemUiVisibility;
1010 }
1011
Craig Mautner19d59bc2012-09-04 11:15:56 -07001012 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001013 public int getSurfaceLayer() {
1014 return mLayer;
1015 }
1016
Craig Mautner812d2ca2012-09-27 15:35:34 -07001017 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001018 public int getBaseType() {
1019 WindowState win = this;
Robert Carr51a1b872015-12-08 14:03:13 -08001020 while (win.isChildWindow()) {
Selim Cinekd6623612015-05-22 18:56:22 -07001021 win = win.mAttachedWindow;
1022 }
1023 return win.mAttrs.type;
1024 }
1025
1026 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001027 public IApplicationToken getAppToken() {
1028 return mAppToken != null ? mAppToken.appToken : null;
1029 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001030
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001031 @Override
1032 public boolean isVoiceInteraction() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001033 return mAppToken != null && mAppToken.voiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001034 }
1035
Craig Mautner4c5eb222013-11-18 12:59:05 -08001036 boolean setInsetsChanged() {
1037 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1038 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1039 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001040 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001041 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
1042 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
1043 || mOutsetsChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001044 }
1045
Craig Mautnerdf88d732014-01-27 09:21:32 -08001046 public DisplayContent getDisplayContent() {
Chad Jonesf391ebc2014-06-12 17:45:05 -07001047 if (mAppToken == null || mNotOnAppsDisplay) {
Craig Mautnerbe634952014-06-12 13:39:24 -07001048 return mDisplayContent;
1049 }
1050 final TaskStack stack = getStack();
1051 return stack == null ? mDisplayContent : stack.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001052 }
1053
Chong Zhang09b21ef2015-09-14 10:20:21 -07001054 public DisplayInfo getDisplayInfo() {
1055 final DisplayContent displayContent = getDisplayContent();
1056 return displayContent != null ? displayContent.getDisplayInfo() : null;
1057 }
1058
Craig Mautner19d59bc2012-09-04 11:15:56 -07001059 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001060 final DisplayContent displayContent = getDisplayContent();
1061 if (displayContent == null) {
1062 return -1;
1063 }
1064 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001065 }
1066
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001067 Task getTask() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07001068 return mAppToken != null ? mAppToken.mTask : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001069 }
1070
1071 TaskStack getStack() {
1072 Task task = getTask();
1073 if (task != null) {
1074 if (task.mStack != null) {
1075 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001076 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001077 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001078 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1079 // associate them with some stack to enable dimming.
1080 return mAttrs.type >= WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1081 && mDisplayContent != null ? mDisplayContent.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001082 }
1083
Skuhnef932e562015-08-20 12:07:30 -07001084 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001085 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001086 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001087 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001088 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001089 final Task task = getTask();
1090 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001091 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001092 mTmpRect.setEmpty();
1093 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001094 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001095 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001096 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001097 } else {
1098 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001099 }
1100 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001101
Chong Zhang9184ec62015-09-24 12:32:21 -07001102 bounds.set(mVisibleFrame);
1103 if (intersectWithStackBounds) {
1104 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001105 }
1106
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001107 if (bounds.isEmpty()) {
1108 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001109 if (intersectWithStackBounds) {
1110 bounds.intersect(mTmpRect);
1111 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001112 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001113 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001114 }
1115
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001116 public long getInputDispatchingTimeoutNanos() {
1117 return mAppToken != null
1118 ? mAppToken.inputDispatchingTimeoutNanos
1119 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1120 }
1121
Craig Mautnere8552142012-11-07 13:55:47 -08001122 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001123 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001124 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001125 }
1126
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001127 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1128 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1129 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1130 if (dtdx < -.000001f || dtdx > .000001f) return false;
1131 if (dsdy < -.000001f || dsdy > .000001f) return false;
1132 return true;
1133 }
1134
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001135 void prelayout() {
1136 if (mEnforceSizeCompat) {
1137 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001138 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001139 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001140 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001141 }
1142 }
1143
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001144 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001145 * Does the minimal check for visibility. Callers generally want to use one of the public
1146 * methods as they perform additional checks on the app token.
1147 * TODO: See if there are other places we can use this check below instead of duplicating...
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001148 */
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001149 private boolean isVisibleUnchecked() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001150 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001151 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001152 }
1153
1154 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001155 * Is this window visible? It is not visible if there is no surface, or we are in the process
1156 * of running an exit animation that will remove the surface, or its app token has been hidden.
1157 */
1158 @Override
1159 public boolean isVisibleLw() {
1160 return (mAppToken == null || !mAppToken.hiddenRequested) && isVisibleUnchecked();
1161 }
1162
1163 /**
1164 * Like {@link #isVisibleLw}, but also counts a window that is currently "hidden" behind the
1165 * keyguard as visible. This allows us to apply things like window flags that impact the
1166 * keyguard. XXX I am starting to think we need to have ANOTHER visibility flag for this
1167 * "hidden behind keyguard" state rather than overloading mPolicyVisibility. Ungh.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001168 */
Craig Mautner88400d32012-09-30 12:35:45 -07001169 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001170 public boolean isVisibleOrBehindKeyguardLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001171 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001172 return false;
1173 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001174 final AppWindowToken atoken = mAppToken;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001175 final boolean animating = atoken != null && atoken.mAppAnimator.animation != null;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001176 return mHasSurface && !mDestroying && !mAnimatingExit
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001177 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001178 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001179 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001180 }
1181
1182 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001183 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1184 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001185 */
1186 public boolean isWinVisibleLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001187 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.mAppAnimator.animating)
1188 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001189 }
1190
1191 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001192 * The same as isVisible(), but follows the current hidden state of the associated app token,
1193 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001194 */
1195 boolean isVisibleNow() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001196 return (!mRootToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
1197 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001198 }
1199
1200 /**
1201 * Can this window possibly be a drag/drop target? The test here is
1202 * a combination of the above "visible now" with the check that the
1203 * Input Manager uses when discarding windows from input consideration.
1204 */
1205 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001206 return isVisibleNow() && !mRemoved
1207 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001208 }
1209
1210 /**
1211 * Same as isVisible(), but we also count it as visible between the
1212 * call to IWindowSession.add() and the first relayout().
1213 */
1214 boolean isVisibleOrAdding() {
1215 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001216 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001217 && mPolicyVisibility && !mAttachedHidden
1218 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001219 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001220 }
1221
1222 /**
1223 * Is this window currently on-screen? It is on-screen either if it
1224 * is visible or it is currently running an animation before no longer
1225 * being visible.
1226 */
1227 boolean isOnScreen() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001228 return mPolicyVisibility && isOnScreenIgnoringKeyguard();
1229 }
1230
1231 /**
1232 * Like isOnScreen(), but ignores any force hiding of the window due
1233 * to the keyguard.
1234 */
1235 boolean isOnScreenIgnoringKeyguard() {
1236 if (!mHasSurface || mDestroying) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001237 return false;
1238 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001239 final AppWindowToken atoken = mAppToken;
1240 if (atoken != null) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001241 return ((!mAttachedHidden && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001242 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001243 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001244 return !mAttachedHidden || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001245 }
1246
1247 /**
1248 * Like isOnScreen(), but we don't return true if the window is part
1249 * of a transition that has not yet been started.
1250 */
1251 boolean isReadyForDisplay() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001252 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001253 return false;
1254 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001255 return mHasSurface && mPolicyVisibility && !mDestroying
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001256 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001257 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001258 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001259 }
1260
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001261 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001262 * Like isReadyForDisplay(), but ignores any force hiding of the window due
1263 * to the keyguard.
1264 */
1265 boolean isReadyForDisplayIgnoringKeyguard() {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001266 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001267 return false;
1268 }
1269 final AppWindowToken atoken = mAppToken;
1270 if (atoken == null && !mPolicyVisibility) {
1271 // If this is not an app window, and the policy has asked to force
1272 // hide, then we really do want to hide.
1273 return false;
1274 }
1275 return mHasSurface && !mDestroying
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001276 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE && !mRootToken.hidden)
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001277 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -07001278 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
1279 && !mWinAnimator.isDummyAnimation()));
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001280 }
1281
1282 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001283 * Like isOnScreen, but returns false if the surface hasn't yet
1284 * been drawn.
1285 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001286 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001287 public boolean isDisplayedLw() {
1288 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001289 return isDrawnLw() && mPolicyVisibility
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001290 && ((!mAttachedHidden &&
1291 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001292 || mWinAnimator.mAnimating
1293 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001294 }
1295
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001296 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001297 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001298 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001299 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001300 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001301 return mWinAnimator.mAnimation != null
1302 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001303 }
1304
Craig Mautner812d2ca2012-09-27 15:35:34 -07001305 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001306 public boolean isGoneForLayoutLw() {
1307 final AppWindowToken atoken = mAppToken;
1308 return mViewVisibility == View.GONE
1309 || !mRelayoutCalled
1310 || (atoken == null && mRootToken.hidden)
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001311 || (atoken != null && atoken.hiddenRequested)
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001312 || mAttachedHidden
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001313 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001314 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001315 }
1316
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001317 /**
1318 * Returns true if the window has a surface that it has drawn a
1319 * complete UI in to.
1320 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001321 public boolean isDrawFinishedLw() {
1322 return mHasSurface && !mDestroying &&
1323 (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING
1324 || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1325 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
1326 }
1327
1328 /**
1329 * Returns true if the window has a surface that it has drawn a
1330 * complete UI in to.
1331 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001332 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001333 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001334 return mHasSurface && !mDestroying &&
Craig Mautner749a7bb2012-04-02 13:49:53 -07001335 (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1336 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001337 }
1338
1339 /**
1340 * Return true if the window is opaque and fully drawn. This indicates
1341 * it may obscure windows behind it.
1342 */
1343 boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001344 // When there is keyguard, wallpaper could be placed over the secure app
1345 // window but invisible. We need to check wallpaper visibility explicitly
1346 // to determine if it's occluding apps.
1347 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1348 || (mIsWallpaper && mWallpaperVisible))
Craig Mautnera2c77052012-03-26 12:14:43 -07001349 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001350 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001351 }
1352
1353 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001354 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001355 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1356 */
Craig Mautner4557c082015-04-27 13:07:40 -07001357 boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001358 return mHasSurface && (mContentChanged || mMovedByResize)
Jorim Jaggi192086e2016-03-11 17:17:03 +01001359 && !mAnimatingExit && mService.okToDisplay()
Chong Zhangbd0d9372015-12-28 15:18:29 -08001360 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Craig Mautner4557c082015-04-27 13:07:40 -07001361 && (mAttachedWindow == null || !mAttachedWindow.hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001362 }
1363
Chong Zhang0abb20f2015-11-19 14:17:31 -08001364 boolean isObscuringFullscreen(final DisplayInfo displayInfo) {
1365 Task task = getTask();
1366 if (task != null && task.mStack != null && !task.mStack.isFullscreen()) {
1367 return false;
1368 }
1369 if (!isOpaqueDrawn() || !isFrameFullscreen(displayInfo)) {
1370 return false;
1371 }
1372 return true;
1373 }
1374
1375 boolean isFrameFullscreen(final DisplayInfo displayInfo) {
1376 return mFrame.left <= 0 && mFrame.top <= 0
1377 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001378 }
1379
Craig Mautner812d2ca2012-09-27 15:35:34 -07001380 boolean isConfigChanged() {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001381 final Task task = getTask();
Wale Ogunwale60454db2015-01-23 16:05:07 -08001382 final Configuration overrideConfig =
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001383 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001384 final Configuration serviceConfig = mService.mCurConfiguration;
1385 boolean configChanged =
1386 (mConfiguration != serviceConfig && mConfiguration.diff(serviceConfig) != 0)
1387 || (mOverrideConfig != overrideConfig && !mOverrideConfig.equals(overrideConfig));
Craig Mautnere8552142012-11-07 13:55:47 -08001388
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001389 if ((mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Craig Mautnere8552142012-11-07 13:55:47 -08001390 // Retain configuration changed status until resetConfiguration called.
1391 mConfigHasChanged |= configChanged;
1392 configChanged = mConfigHasChanged;
1393 }
1394
1395 return configChanged;
Craig Mautner812d2ca2012-09-27 15:35:34 -07001396 }
1397
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07001398 boolean isAdjustedForMinimizedDock() {
1399 return mAppToken != null && mAppToken.mTask != null
1400 && mAppToken.mTask.mStack.isAdjustedForMinimizedDock();
1401 }
1402
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001403 void removeLocked() {
1404 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001405
Robert Carr51a1b872015-12-08 14:03:13 -08001406 if (isChildWindow()) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001407 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001408 mAttachedWindow.mChildWindows.remove(this);
1409 }
Craig Mautner96868332012-12-04 14:29:11 -08001410 mWinAnimator.destroyDeferredSurfaceLocked();
1411 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001412 mSession.windowRemovedLocked();
1413 try {
1414 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1415 } catch (RuntimeException e) {
1416 // Ignore if it has already been removed (usually because
1417 // we are doing this as part of processing a death note.)
1418 }
1419 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001420
Wale Ogunwale60454db2015-01-23 16:05:07 -08001421 private void setConfiguration(
1422 final Configuration newConfig, final Configuration newOverrideConfig) {
Craig Mautnere8552142012-11-07 13:55:47 -08001423 mConfiguration = newConfig;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001424 mOverrideConfig = newOverrideConfig;
Craig Mautnere8552142012-11-07 13:55:47 -08001425 mConfigHasChanged = false;
Robert Carrc24d8f92016-02-29 16:24:33 -08001426
1427 mMergedConfiguration.setTo(newConfig);
1428 if (newOverrideConfig != null && newOverrideConfig != Configuration.EMPTY) {
1429 mMergedConfiguration.updateFrom(newOverrideConfig);
1430 }
Craig Mautnere8552142012-11-07 13:55:47 -08001431 }
1432
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001433 void setHasSurface(boolean hasSurface) {
1434 mHasSurface = hasSurface;
1435 }
1436
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001437 int getAnimLayerAdjustment() {
1438 if (mTargetAppToken != null) {
1439 return mTargetAppToken.mAppAnimator.animLayerAdjustment;
1440 } else if (mAppToken != null) {
1441 return mAppToken.mAppAnimator.animLayerAdjustment;
1442 } else {
1443 // Nothing is animating, so there is no animation adjustment.
1444 return 0;
1445 }
1446 }
1447
1448 void scheduleAnimationIfDimming() {
1449 if (mDisplayContent == null) {
1450 return;
1451 }
1452 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1453 if (dimLayerUser != null && mDisplayContent.mDimLayerController.isDimming(
1454 dimLayerUser, mWinAnimator)) {
1455 // Force an animation pass just to update the mDimLayer layer.
1456 mService.scheduleAnimationLocked();
1457 }
1458 }
1459
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08001460 /**
1461 * Notifies this window that the corresponding task has just moved in the stack.
1462 * <p>
1463 * This is used to fix the following: If we moved in the stack, and if the last clip rect was
1464 * empty, meaning that our task was completely offscreen, we need to keep it invisible because
1465 * the actual app transition that updates the visibility is delayed by a few transactions.
1466 * Instead of messing around with the ordering and timing how transitions and transactions are
1467 * executed, we introduce this little hack which prevents this window of getting visible again
1468 * with the wrong bounds until the app transitions has started.
1469 * <p>
1470 * This method notifies the window about that we just moved in the stack so we can apply this
1471 * logic in {@link WindowStateAnimator#updateSurfaceWindowCrop}
1472 */
1473 void notifyMovedInStack() {
1474 mJustMovedInStack = true;
1475 }
1476
1477 /**
1478 * See {@link #notifyMovedInStack}.
1479 *
1480 * @return Whether we just got moved in the corresponding stack.
1481 */
1482 boolean hasJustMovedInStack() {
1483 return mJustMovedInStack;
1484 }
1485
1486 /**
1487 * Resets that we just moved in the corresponding stack. See {@link #notifyMovedInStack}.
1488 */
1489 void resetJustMovedInStack() {
1490 mJustMovedInStack = false;
1491 }
1492
Chong Zhangacf11402015-11-04 16:23:10 -08001493 private final class DeadWindowEventReceiver extends InputEventReceiver {
1494 DeadWindowEventReceiver(InputChannel inputChannel) {
1495 super(inputChannel, mService.mH.getLooper());
1496 }
1497 @Override
1498 public void onInputEvent(InputEvent event) {
1499 finishInputEvent(event, true);
1500 }
1501 }
1502 /**
1503 * Dummy event receiver for windows that died visible.
1504 */
1505 private DeadWindowEventReceiver mDeadWindowEventReceiver;
1506
Chong Zhang112eb8c2015-11-02 11:17:00 -08001507 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001508 if (mInputChannel != null) {
1509 throw new IllegalStateException("Window already has an input channel.");
1510 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001511 String name = makeInputChannelName();
1512 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1513 mInputChannel = inputChannels[0];
1514 mClientChannel = inputChannels[1];
1515 mInputWindowHandle.inputChannel = inputChannels[0];
1516 if (outInputChannel != null) {
1517 mClientChannel.transferTo(outInputChannel);
1518 mClientChannel.dispose();
1519 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08001520 } else {
1521 // If the window died visible, we setup a dummy input channel, so that taps
1522 // can still detected by input monitor channel, and we can relaunch the app.
1523 // Create dummy event receiver that simply reports all events as handled.
1524 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08001525 }
1526 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001527 }
1528
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001529 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08001530 if (mDeadWindowEventReceiver != null) {
1531 mDeadWindowEventReceiver.dispose();
1532 mDeadWindowEventReceiver = null;
1533 }
1534
1535 // unregister server channel first otherwise it complains about broken channel
1536 if (mInputChannel != null) {
1537 mService.mInputManager.unregisterInputChannel(mInputChannel);
1538 mInputChannel.dispose();
1539 mInputChannel = null;
1540 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001541 if (mClientChannel != null) {
1542 mClientChannel.dispose();
1543 mClientChannel = null;
1544 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001545 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001546 }
1547
Chong Zhang112eb8c2015-11-02 11:17:00 -08001548 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08001549 // When the app is terminated (eg. from Recents), the task might have already been
1550 // removed with the window pending removal. Don't apply dim in such cases, as there
1551 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
1552 final AppWindowToken token = mAppToken;
1553 if (token != null && token.removed) {
1554 return;
1555 }
1556
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001557 if (!mAnimatingExit && mAppDied) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001558 // If app died visible, apply a dim over the window to indicate that it's inactive
1559 mDisplayContent.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
1560 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
Robert Carr9fe459d2016-04-07 23:32:28 -07001561 && mDisplayContent != null && !mAnimatingExit && isVisibleUnchecked()) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001562 mDisplayContent.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001563 }
1564 }
1565
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001566 DimLayer.DimLayerUser getDimLayerUser() {
1567 Task task = getTask();
1568 if (task != null) {
1569 return task;
1570 }
1571 return getStack();
1572 }
1573
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001574 void maybeRemoveReplacedWindow() {
Robert Carra1eb4392015-12-10 12:43:51 -08001575 if (mAppToken == null) {
1576 return;
1577 }
1578 for (int i = mAppToken.allAppWindows.size() - 1; i >= 0; i--) {
1579 final WindowState win = mAppToken.allAppWindows.get(i);
Robert Carrdcdca582016-04-07 22:59:24 -07001580 if (win.mWillReplaceWindow && win.mReplacingWindow == this && hasDrawnLw()) {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08001581 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + win);
Robert Carr9fe459d2016-04-07 23:32:28 -07001582 if (win.isDimming()) {
1583 win.transferDimToReplacement();
1584 }
Robert Carra1eb4392015-12-10 12:43:51 -08001585 win.mWillReplaceWindow = false;
1586 win.mAnimateReplacingWindow = false;
1587 win.mReplacingRemoveRequested = false;
1588 win.mReplacingWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -07001589 mSkipEnterAnimationForSeamlessReplacement = false;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001590 if (win.mAnimatingExit) {
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001591 mService.removeWindowInnerLocked(win);
1592 }
1593 }
1594 }
1595 }
1596
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07001597 void setDisplayLayoutNeeded() {
1598 if (mDisplayContent != null) {
1599 mDisplayContent.layoutNeeded = true;
1600 }
1601 }
1602
Filip Gruszczynski955b2fc2015-10-15 14:46:07 -07001603 boolean inDockedWorkspace() {
Chong Zhang2a88fc32016-01-11 17:14:24 -08001604 final Task task = getTask();
Chong Zhangb15758a2015-11-17 12:12:03 -08001605 return task != null && task.inDockedWorkspace();
1606 }
1607
1608 boolean isDockedInEffect() {
Chong Zhang2a88fc32016-01-11 17:14:24 -08001609 final Task task = getTask();
Chong Zhangb15758a2015-11-17 12:12:03 -08001610 return task != null && task.isDockedInEffect();
Filip Gruszczynski955b2fc2015-10-15 14:46:07 -07001611 }
1612
Chong Zhang2a88fc32016-01-11 17:14:24 -08001613 void applyScrollIfNeeded() {
1614 final Task task = getTask();
Chong Zhangf66db432016-01-13 10:39:51 -08001615 if (task != null) {
1616 task.applyScrollToWindowIfNeeded(this);
Chong Zhang2a88fc32016-01-11 17:14:24 -08001617 }
1618 }
1619
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001620 int getTouchableRegion(Region region, int flags) {
1621 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001622 if (modal && mAppToken != null) {
1623 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001624 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001625 // If this is a modal window we need to dismiss it if it's not full screen and the
1626 // touch happens outside of the frame that displays the content. This means we
1627 // need to intercept touches outside of that window. The dim layer user
1628 // associated with the window (task or stack) will give us the good bounds, as
1629 // they would be used to display the dim layer.
1630 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1631 if (dimLayerUser != null) {
1632 dimLayerUser.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001633 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001634 getVisibleBounds(mTmpRect);
1635 }
1636 if (inFreeformWorkspace()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001637 // For freeform windows we the touch region to include the whole surface for the
1638 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001639 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
1640 final int delta = WindowManagerService.dipToPixel(
1641 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
1642 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001643 }
1644 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001645 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001646 } else {
1647 // Not modal or full screen modal
1648 getTouchableRegion(region);
1649 }
1650 return flags;
1651 }
1652
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001653 void checkPolicyVisibilityChange() {
1654 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
1655 if (DEBUG_VISIBILITY) {
1656 Slog.v(TAG, "Policy visibility changing after anim in " +
1657 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
1658 }
1659 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001660 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001661 if (!mPolicyVisibility) {
1662 if (mService.mCurrentFocus == this) {
1663 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
1664 "setAnimationLocked: setting mFocusMayChange true");
1665 mService.mFocusMayChange = true;
1666 }
1667 // Window is no longer visible -- make sure if we were waiting
1668 // for it to be displayed before enabling the display, that
1669 // we allow the display to be enabled now.
1670 mService.enableScreenIfNeededLocked();
1671 }
1672 }
1673 }
1674
1675 void setRequestedSize(int requestedWidth, int requestedHeight) {
1676 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
1677 mLayoutNeeded = true;
1678 mRequestedWidth = requestedWidth;
1679 mRequestedHeight = requestedHeight;
1680 }
1681 }
1682
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001683 void prepareWindowToDisplayDuringRelayout(Configuration outConfig) {
1684 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
1685 == SOFT_INPUT_ADJUST_RESIZE) {
1686 mLayoutNeeded = true;
1687 }
1688 if (isDrawnLw() && mService.okToDisplay()) {
1689 mWinAnimator.applyEnterAnimationLocked();
1690 }
1691 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
1692 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
1693 mTurnOnScreen = true;
1694 }
1695 if (isConfigChanged()) {
Robert Carrc24d8f92016-02-29 16:24:33 -08001696 final Configuration newConfig = updateConfiguration();
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001697 if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + this + " visible with new config: "
Robert Carrc24d8f92016-02-29 16:24:33 -08001698 + newConfig);
1699 outConfig.setTo(newConfig);
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001700 }
1701 }
1702
1703 void adjustStartingWindowFlags() {
1704 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
1705 && mAppToken.startingWindow != null) {
1706 // Special handling of starting window over the base
1707 // window of the app: propagate lock screen flags to it,
1708 // to provide the correct semantics while starting.
1709 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
1710 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
1711 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
1712 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
1713 }
1714 }
1715
1716 void setWindowScale(int requestedWidth, int requestedHeight) {
1717 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
1718
1719 if (scaledWindow) {
1720 // requested{Width|Height} Surface's physical size
1721 // attrs.{width|height} Size on screen
1722 // TODO: We don't check if attrs != null here. Is it implicitly checked?
1723 mHScale = (mAttrs.width != requestedWidth) ?
1724 (mAttrs.width / (float)requestedWidth) : 1.0f;
1725 mVScale = (mAttrs.height != requestedHeight) ?
1726 (mAttrs.height / (float)requestedHeight) : 1.0f;
1727 } else {
1728 mHScale = mVScale = 1;
1729 }
1730 }
1731
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001732 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08001733 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001734 public void binderDied() {
1735 try {
1736 synchronized(mService.mWindowMap) {
1737 WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07001738 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001739 if (win != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001740 if (win.mAppToken != null && !win.mAppToken.clientHidden) {
1741 win.mAppToken.appDied = true;
1742 }
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001743 mService.removeWindowLocked(win);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08001744 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
1745 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08001746 // just in case they have the divider at an unstable position. Better
1747 // also reset drag resizing state, because the owner can't do it
1748 // anymore.
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08001749 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
1750 if (stack != null) {
1751 stack.resetDockedStackToMiddle();
1752 }
Jorim Jaggidcb68142016-02-09 21:51:30 -08001753 mService.setDockedStackResizing(false);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08001754 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001755 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08001756 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001757 mService.removeWindowLocked(WindowState.this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001758 }
1759 }
1760 } catch (IllegalArgumentException ex) {
1761 // This will happen if the window has already been
1762 // removed.
1763 }
1764 }
1765 }
1766
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08001767 /**
1768 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
1769 * because we want to preserve its location on screen to be re-activated later when the user
1770 * interacts with it.
1771 */
1772 boolean shouldKeepVisibleDeadAppWindow() {
1773 if (!isWinVisibleLw() || mAppToken == null || !mAppToken.appDied) {
1774 // Not a visible app window or the app isn't dead.
1775 return false;
1776 }
1777
1778 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1779 // We don't keep starting windows since they were added by the window manager before
1780 // the app even launched.
1781 return false;
1782 }
1783
1784 final TaskStack stack = getStack();
1785 return stack != null && StackId.keepVisibleDeadAppWindowOnScreen(stack.mStackId);
1786 }
1787
Wale Ogunwaled045c822015-12-02 09:14:28 -08001788 /** @return true if this window desires key events. */
1789 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08001790 return isVisibleOrAdding()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001791 && (mViewVisibility == View.VISIBLE)
Wale Ogunwaled045c822015-12-02 09:14:28 -08001792 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07001793 && (mAppToken == null || mAppToken.windowsAreFocusable())
1794 && !isAdjustedForMinimizedDock();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001795 }
1796
Craig Mautner749a7bb2012-04-02 13:49:53 -07001797 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001798 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001799 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001800 }
1801
Craig Mautner749a7bb2012-04-02 13:49:53 -07001802 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001803 public boolean showLw(boolean doAnimation) {
1804 return showLw(doAnimation, true);
1805 }
1806
1807 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07001808 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001809 return false;
1810 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001811 if (!mAppOpVisibility) {
1812 // Being hidden due to app op request.
1813 return false;
1814 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001815 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001816 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001817 return false;
1818 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001819 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001820 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001821 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07001822 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07001823 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001824 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07001825 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001826 // Check for the case where we are currently visible and
1827 // not animating; we do not want to do animation at such a
1828 // point to become visible when we already are.
1829 doAnimation = false;
1830 }
1831 }
1832 mPolicyVisibility = true;
1833 mPolicyVisibilityAfterAnim = true;
1834 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001835 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001836 }
1837 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001838 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001839 }
1840 return true;
1841 }
1842
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001843 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001844 public boolean hideLw(boolean doAnimation) {
1845 return hideLw(doAnimation, true);
1846 }
1847
1848 boolean hideLw(boolean doAnimation, boolean requestAnim) {
1849 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07001850 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001851 doAnimation = false;
1852 }
1853 }
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001854 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
1855 : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001856 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001857 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001858 return false;
1859 }
1860 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001861 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07001862 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001863 doAnimation = false;
1864 }
1865 }
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001866 if (doAnimation) {
1867 mPolicyVisibilityAfterAnim = false;
1868 } else {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001869 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001870 mPolicyVisibilityAfterAnim = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001871 mPolicyVisibility = false;
1872 // Window is no longer visible -- make sure if we were waiting
1873 // for it to be displayed before enabling the display, that
1874 // we allow the display to be enabled now.
1875 mService.enableScreenIfNeededLocked();
1876 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001877 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07001878 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001879 mService.mFocusMayChange = true;
1880 }
1881 }
1882 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001883 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001884 }
1885 return true;
1886 }
1887
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001888 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001889 if (mAppOpVisibility != state) {
1890 mAppOpVisibility = state;
1891 if (state) {
1892 // If the policy visibility had last been to hide, then this
1893 // will incorrectly show at this point since we lost that
1894 // information. Not a big deal -- for the windows that have app
1895 // ops modifies they should only be hidden by policy due to the
1896 // lock screen, and the user won't be changing this if locked.
1897 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001898 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001899 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001900 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001901 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001902 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001903 }
1904
Jeff Brownc2932a12014-11-20 18:04:05 -08001905 public void pokeDrawLockLw(long timeout) {
1906 if (isVisibleOrAdding()) {
1907 if (mDrawLock == null) {
1908 // We want the tag name to be somewhat stable so that it is easier to correlate
1909 // in wake lock statistics. So in particular, we don't want to include the
1910 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001911 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08001912 mDrawLock = mService.mPowerManager.newWakeLock(
1913 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
1914 mDrawLock.setReferenceCounted(false);
1915 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
1916 }
1917 // Each call to acquire resets the timeout.
1918 if (DEBUG_POWER) {
1919 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
1920 + mAttrs.packageName);
1921 }
1922 mDrawLock.acquire(timeout);
1923 } else if (DEBUG_POWER) {
1924 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
1925 + "owned by " + mAttrs.packageName);
1926 }
1927 }
1928
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001929 @Override
1930 public boolean isAlive() {
1931 return mClient.asBinder().isBinderAlive();
1932 }
1933
Craig Mautnera987d432012-10-11 14:07:58 -07001934 boolean isClosing() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001935 return mAnimatingExit || (mService.mClosingApps.contains(mAppToken));
Craig Mautnera987d432012-10-11 14:07:58 -07001936 }
1937
Chong Zhangbef461f2015-10-27 11:38:24 -07001938 boolean isAnimatingWithSavedSurface() {
1939 return mAppToken != null && mAppToken.mAnimatingWithSavedSurface;
1940 }
1941
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001942 private boolean shouldSaveSurface() {
Chong Zhang6c71c0b2016-04-01 15:10:31 -07001943 if (mWinAnimator.mSurfaceController == null) {
1944 // Don't bother if the surface controller is gone for any reason.
1945 return false;
1946 }
1947
Wale Ogunwale945d1972016-03-23 13:16:41 -07001948 if ((mAttrs.flags & FLAG_SECURE) != 0) {
1949 // We don't save secure surfaces since their content shouldn't be shown while the app
1950 // isn't on screen and content might leak through during the transition animation with
1951 // saved surface.
1952 return false;
1953 }
1954
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001955 if (ActivityManager.isLowRamDeviceStatic()) {
1956 // Don't save surfaces on Svelte devices.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001957 return false;
1958 }
1959
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001960 Task task = getTask();
1961 if (task == null || task.inHomeStack()) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001962 // Don't save surfaces for home stack apps. These usually resume and draw
1963 // first frame very fast. Saving surfaces are mostly a waste of memory.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001964 return false;
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001965 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001966
1967 final AppWindowToken taskTop = task.getTopVisibleAppToken();
1968 if (taskTop != null && taskTop != mAppToken) {
1969 // Don't save if the window is not the topmost window.
1970 return false;
1971 }
1972
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001973 if (mResizedWhileGone) {
1974 // Somebody resized our window while we were gone for layout, which means that the
1975 // client got an old size, so we have an outdated surface here.
1976 return false;
1977 }
1978
Robert Carr7098dbd2016-02-01 12:31:01 -08001979 if (DEBUG_DISABLE_SAVING_SURFACES) {
1980 return false;
1981 }
1982
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001983 return mAppToken.shouldSaveSurface();
1984 }
1985
1986 void destroyOrSaveSurface() {
1987 mSurfaceSaved = shouldSaveSurface();
1988 if (mSurfaceSaved) {
1989 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1990 Slog.v(TAG, "Saving surface: " + this);
1991 }
1992
1993 mWinAnimator.hide("saved surface");
1994 mWinAnimator.mDrawState = WindowStateAnimator.NO_SURFACE;
1995 setHasSurface(false);
Chong Zhang47e36a32016-02-29 16:44:33 -08001996 // The client should have disconnected at this point, but if it doesn't,
1997 // we need to make sure it's disconnected. Otherwise when we reuse the surface
1998 // the client can't reconnect to the buffer queue, and rendering will fail.
1999 if (mWinAnimator.mSurfaceController != null) {
2000 mWinAnimator.mSurfaceController.disconnectInTransaction();
2001 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002002 } else {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002003 mWinAnimator.destroySurfaceLocked();
2004 }
Robert Carr13f7be9e2015-12-02 18:39:45 -08002005 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002006
Robert Carr13f7be9e2015-12-02 18:39:45 -08002007 public void destroySavedSurface() {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002008 if (mSurfaceSaved) {
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002009 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2010 Slog.v(TAG, "Destroying saved surface: " + this);
2011 }
Robert Carr13f7be9e2015-12-02 18:39:45 -08002012 mWinAnimator.destroySurfaceLocked();
2013 }
2014 }
2015
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002016 public void restoreSavedSurface() {
Chong Zhang4113ffa2016-02-18 12:39:13 -08002017 if (!mSurfaceSaved) {
2018 return;
2019 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002020 mSurfaceSaved = false;
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002021 if (mWinAnimator.mSurfaceController != null) {
2022 setHasSurface(true);
2023 mWinAnimator.mDrawState = WindowStateAnimator.READY_TO_SHOW;
2024
2025 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2026 Slog.v(TAG, "Restoring saved surface: " + this);
2027 }
2028 } else {
2029 // mSurfaceController shouldn't be null if mSurfaceSaved was still true at
2030 // this point. Even if we destroyed the saved surface because of rotation
2031 // or resize, mSurfaceSaved flag should have been cleared. So this is a wtf.
2032 Slog.wtf(TAG, "Failed to restore saved surface: surface gone! " + this);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002033 }
2034 }
2035
Robert Carr13f7be9e2015-12-02 18:39:45 -08002036 public boolean hasSavedSurface() {
2037 return mSurfaceSaved;
2038 }
2039
Craig Mautner69b08182012-09-05 13:07:13 -07002040 @Override
2041 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002042 final DisplayContent displayContent = getDisplayContent();
2043 if (displayContent == null) {
2044 // Only a window that was on a non-default display can be detached from it.
2045 return false;
2046 }
Winson Chung47a3e652014-05-21 16:03:42 -07002047 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002048 }
2049
Adrian Rooscd3884d2015-02-18 17:25:23 +01002050 @Override
2051 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002052 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
2053 return dimLayerUser != null && mDisplayContent != null &&
Chong Zhang112eb8c2015-11-02 11:17:00 -08002054 mDisplayContent.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01002055 }
2056
Craig Mautner88400d32012-09-30 12:35:45 -07002057 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
2058 mShowToOwnerOnly = showToOwnerOnly;
2059 }
2060
Craig Mautner5962b122012-10-05 14:45:52 -07002061 boolean isHiddenFromUserLocked() {
Craig Mautner341220f2012-10-16 15:20:09 -07002062 // Attached windows are evaluated based on the window that they are attached to.
2063 WindowState win = this;
Robert Carr51a1b872015-12-08 14:03:13 -08002064 while (win.isChildWindow()) {
Craig Mautner341220f2012-10-16 15:20:09 -07002065 win = win.mAttachedWindow;
2066 }
2067 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -07002068 && win.mAppToken != null && win.mAppToken.showForAllUsers) {
Craig Mautner341220f2012-10-16 15:20:09 -07002069 // Save some cycles by not calling getDisplayInfo unless it is an application
2070 // window intended for all users.
Craig Mautnerdf88d732014-01-27 09:21:32 -08002071 final DisplayContent displayContent = win.getDisplayContent();
2072 if (displayContent == null) {
2073 return true;
2074 }
2075 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Craig Mautner341220f2012-10-16 15:20:09 -07002076 if (win.mFrame.left <= 0 && win.mFrame.top <= 0
2077 && win.mFrame.right >= displayInfo.appWidth
2078 && win.mFrame.bottom >= displayInfo.appHeight) {
Craig Mautner5962b122012-10-05 14:45:52 -07002079 // Is a fullscreen window, like the clock alarm. Show to everyone.
2080 return false;
2081 }
2082 }
2083
Craig Mautner341220f2012-10-16 15:20:09 -07002084 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01002085 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002086 }
2087
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002088 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2089 outRegion.set(
2090 frame.left + inset.left, frame.top + inset.top,
2091 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002092 }
2093
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002094 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002095 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002096 switch (mTouchableInsets) {
2097 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002098 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002099 outRegion.set(frame);
2100 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002101 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002102 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002103 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002104 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002105 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002106 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002107 case TOUCHABLE_INSETS_REGION: {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002108 final Region givenTouchableRegion = mGivenTouchableRegion;
2109 outRegion.set(givenTouchableRegion);
2110 outRegion.translate(frame.left, frame.top);
2111 break;
2112 }
2113 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002114 cropRegionToStackBoundsIfNeeded(outRegion);
2115 }
2116
2117 void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002118 final Task task = getTask();
2119 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002120 return;
2121 }
2122
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002123 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002124 if (stack == null) {
2125 return;
2126 }
2127
2128 stack.getDimBounds(mTmpRect);
2129 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002130 }
2131
Craig Mautner59c00972012-07-30 12:10:24 -07002132 WindowList getWindowList() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002133 final DisplayContent displayContent = getDisplayContent();
2134 return displayContent == null ? null : displayContent.getWindowList();
Craig Mautner59c00972012-07-30 12:10:24 -07002135 }
2136
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002137 /**
2138 * Report a focus change. Must be called with no locks held, and consistently
2139 * from the same serialized thread (such as dispatched from a handler).
2140 */
2141 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
2142 try {
2143 mClient.windowFocusChanged(focused, inTouchMode);
2144 } catch (RemoteException e) {
2145 }
2146 if (mFocusCallbacks != null) {
2147 final int N = mFocusCallbacks.beginBroadcast();
2148 for (int i=0; i<N; i++) {
2149 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2150 try {
2151 if (focused) {
2152 obs.focusGained(mWindowId.asBinder());
2153 } else {
2154 obs.focusLost(mWindowId.asBinder());
2155 }
2156 } catch (RemoteException e) {
2157 }
2158 }
2159 mFocusCallbacks.finishBroadcast();
2160 }
2161 }
2162
Robert Carrc24d8f92016-02-29 16:24:33 -08002163 /**
2164 * Update our current configurations, based on task configuration.
2165 *
2166 * @return A configuration suitable for sending to the client.
2167 */
2168 private Configuration updateConfiguration() {
2169 final Task task = getTask();
2170 final Configuration overrideConfig =
2171 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
2172 final boolean configChanged = isConfigChanged();
2173 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) && configChanged) {
2174 Slog.i(TAG, "Sending new config to window " + this + ": " +
2175 " / config=" + mService.mCurConfiguration + " overrideConfig=" + overrideConfig);
2176 }
2177 setConfiguration(mService.mCurConfiguration, overrideConfig);
2178 return mMergedConfiguration;
2179 }
2180
Craig Mautnerdf88d732014-01-27 09:21:32 -08002181 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002182 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08002183 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002184 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
2185 + ": " + mCompatFrame);
Robert Carrc24d8f92016-02-29 16:24:33 -08002186 final Configuration newConfig = isConfigChanged() ? updateConfiguration() : null;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002187 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING)
2188 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
2189
Craig Mautnerdf88d732014-01-27 09:21:32 -08002190 final Rect frame = mFrame;
2191 final Rect overscanInsets = mLastOverscanInsets;
2192 final Rect contentInsets = mLastContentInsets;
2193 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07002194 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002195 final Rect outsets = mLastOutsets;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002196 final boolean reportDraw = mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING;
Chet Haase8eb48d22014-09-24 07:31:29 -07002197 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
2198 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002199 // To prevent deadlock simulate one-way call if win.mClient is a local object.
2200 mService.mH.post(new Runnable() {
2201 @Override
2202 public void run() {
2203 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002204 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
2205 stableInsets, outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002206 } catch (RemoteException e) {
2207 // Not a remote call, RemoteException won't be raised.
2208 }
2209 }
2210 });
2211 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002212 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002213 outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002214 }
Svetoslav4604abc2014-06-10 18:59:30 -07002215
2216 //TODO (multidisplay): Accessibility supported only for the default display.
2217 if (mService.mAccessibilityController != null
2218 && getDisplayId() == Display.DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07002219 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07002220 }
2221
Craig Mautnerdf88d732014-01-27 09:21:32 -08002222 mOverscanInsetsChanged = false;
2223 mContentInsetsChanged = false;
2224 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07002225 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002226 mOutsetsChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08002227 mWinAnimator.mSurfaceResized = false;
2228 } catch (RemoteException e) {
2229 mOrientationChanging = false;
2230 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2231 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08002232 // We are assuming the hosting process is dead or in a zombie state.
2233 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
2234 + ", removing this window.");
2235 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002236 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002237 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002238 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002239 }
2240
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002241 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08002242 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
2243 // start even if we haven't received the relayout window, so that the client requests
2244 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
2245 // until the window to small size, otherwise the multithread renderer will shift last
2246 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
2247 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002248 boolean resizing = isDragResizing() || isDragResizeChanged();
2249 if (StackId.useWindowFrameForBackdrop(getStackId()) || !resizing) {
2250 return frame;
2251 }
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002252 DisplayInfo displayInfo = getDisplayInfo();
2253 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002254 return mTmpRect;
2255 }
2256
Jorim Jaggi86905582016-02-09 21:36:09 -08002257 @Override
2258 public int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002259 final TaskStack stack = getStack();
2260 if (stack == null) {
2261 return INVALID_STACK_ID;
2262 }
2263 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002264 }
2265
2266 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
2267 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
2268 Configuration newConfig) throws RemoteException {
Chong Zhangedaf3052016-04-22 15:04:31 -07002269 final boolean forceRelayout = isDragResizeChanged() || mResizedWhileNotDragResizing;
2270
Jorim Jaggidc249c42015-12-15 14:57:31 -08002271 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Jorim Jaggia4a58ef2016-01-27 02:10:08 -08002272 reportDraw, newConfig, getBackdropFrame(frame),
Chong Zhangedaf3052016-04-22 15:04:31 -07002273 forceRelayout, mPolicy.isNavBarForcedShownLw(this));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002274 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002275 }
2276
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002277 public void registerFocusObserver(IWindowFocusObserver observer) {
2278 synchronized(mService.mWindowMap) {
2279 if (mFocusCallbacks == null) {
2280 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
2281 }
2282 mFocusCallbacks.register(observer);
2283 }
2284 }
2285
2286 public void unregisterFocusObserver(IWindowFocusObserver observer) {
2287 synchronized(mService.mWindowMap) {
2288 if (mFocusCallbacks != null) {
2289 mFocusCallbacks.unregister(observer);
2290 }
2291 }
2292 }
2293
2294 public boolean isFocused() {
2295 synchronized(mService.mWindowMap) {
2296 return mService.mCurrentFocus == this;
2297 }
2298 }
2299
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07002300 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07002301 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07002302 return task != null && task.inFreeformWorkspace();
2303 }
2304
Wale Ogunwale9185fb02016-03-11 18:06:14 -08002305 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07002306 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08002307 final Task task = getTask();
2308 return task != null && !task.isFullscreen();
2309 }
2310
Chong Zhang3005e752015-09-18 18:46:28 -07002311 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002312 return mDragResizing != computeDragResizing();
2313 }
2314
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002315 /**
2316 * @return Whether we reported a drag resize change to the application or not already.
2317 */
2318 boolean isDragResizingChangeReported() {
2319 return mDragResizingChangeReported;
2320 }
2321
2322 /**
2323 * Resets the state whether we reported a drag resize change to the app.
2324 */
2325 void resetDragResizingChangeReported() {
2326 mDragResizingChangeReported = false;
2327 }
2328
Jorim Jaggidcf467c2015-11-05 13:59:32 +01002329 int getResizeMode() {
2330 return mResizeMode;
2331 }
2332
Jorim Jaggi192086e2016-03-11 17:17:03 +01002333 boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07002334 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002335 if (task == null) {
2336 return false;
2337 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08002338 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
2339
2340 // Floating windows never enter drag resize mode.
2341 return false;
2342 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002343 if (task.isDragResizing()) {
2344 return true;
2345 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01002346
2347 // If the bounds are currently frozen, it means that the layout size that the app sees
2348 // and the bounds we clip this window to might be different. In order to avoid holes, we
2349 // simulate that we are still resizing so the app fills the hole with the resizing
2350 // background.
2351 return (mDisplayContent.mDividerControllerLocked.isResizing()
2352 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Jorim Jaggi899327f2016-02-25 20:44:18 -05002353 !task.inFreeformWorkspace() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08002354
Chong Zhang3005e752015-09-18 18:46:28 -07002355 }
2356
2357 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002358 final boolean resizing = computeDragResizing();
2359 if (resizing == mDragResizing) {
2360 return;
2361 }
2362 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01002363 final Task task = getTask();
2364 if (task != null && task.isDragResizing()) {
2365 mResizeMode = task.getDragResizeMode();
2366 } else {
2367 mResizeMode = mDragResizing && mDisplayContent.mDividerControllerLocked.isResizing()
2368 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
2369 : DRAG_RESIZE_MODE_FREEFORM;
2370 }
Chong Zhang3005e752015-09-18 18:46:28 -07002371 }
2372
2373 boolean isDragResizing() {
2374 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07002375 }
2376
Robert Carr2487ce72016-04-07 15:18:45 -07002377 boolean isDockedResizing() {
2378 return mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
2379 }
2380
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002381 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08002382 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002383 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08002384 if (stack != null) {
2385 pw.print(" stackId="); pw.print(stack.mStackId);
2386 }
Wale Ogunwale4c5aa5172016-04-19 11:29:05 -07002387 if (mNotOnAppsDisplay) {
2388 pw.print(" mNotOnAppsDisplay="); pw.print(mNotOnAppsDisplay);
2389 }
Craig Mautner59c00972012-07-30 12:10:24 -07002390 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002391 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07002392 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08002393 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
2394 pw.print(" package="); pw.print(mAttrs.packageName);
2395 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002396 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002397 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
2398 pw.print(" h="); pw.print(mRequestedHeight);
2399 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07002400 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
2401 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
2402 pw.print(" h="); pw.println(mLastRequestedHeight);
2403 }
Robert Carr51a1b872015-12-08 14:03:13 -08002404 if (isChildWindow() || mLayoutAttached) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002405 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
2406 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
2407 }
2408 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
2409 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
2410 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
2411 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
2412 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
2413 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002414 if (dumpAll) {
2415 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
2416 pw.print(" mSubLayer="); pw.print(mSubLayer);
2417 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautner59431632012-04-04 11:56:44 -07002418 pw.print((mTargetAppToken != null ?
2419 mTargetAppToken.mAppAnimator.animLayerAdjustment
2420 : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002421 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
2422 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08002423 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002424 if (dumpAll) {
2425 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
2426 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
2427 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07002428 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
2429 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08002430 pw.print(isAnimatingWithSavedSurface());
Chong Zhang112eb8c2015-11-02 11:17:00 -08002431 pw.print(" mAppDied=");pw.println(mAppDied);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002432 }
2433 if (mTargetAppToken != null) {
2434 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
2435 }
2436 pw.print(prefix); pw.print("mViewVisibility=0x");
2437 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002438 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
2439 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07002440 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
2441 pw.print(" mSystemUiVisibility=0x");
2442 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002443 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002444 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
2445 || mAttachedHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002446 pw.print(prefix); pw.print("mPolicyVisibility=");
2447 pw.print(mPolicyVisibility);
2448 pw.print(" mPolicyVisibilityAfterAnim=");
2449 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002450 pw.print(" mAppOpVisibility=");
2451 pw.print(mAppOpVisibility);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002452 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
2453 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08002454 if (!mRelayoutCalled || mLayoutNeeded) {
2455 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
2456 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002457 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002458 if (mXOffset != 0 || mYOffset != 0) {
2459 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
2460 pw.print(" y="); pw.println(mYOffset);
2461 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002462 if (dumpAll) {
2463 pw.print(prefix); pw.print("mGivenContentInsets=");
2464 mGivenContentInsets.printShortString(pw);
2465 pw.print(" mGivenVisibleInsets=");
2466 mGivenVisibleInsets.printShortString(pw);
2467 pw.println();
2468 if (mTouchableInsets != 0 || mGivenInsetsPending) {
2469 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
2470 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07002471 Region region = new Region();
2472 getTouchableRegion(region);
2473 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002474 }
2475 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Wale Ogunwale7c726682015-02-06 17:34:28 -08002476 if (mOverrideConfig != Configuration.EMPTY) {
2477 pw.print(prefix); pw.print("mOverrideConfig="); pw.println(mOverrideConfig);
2478 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002479 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07002480 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07002481 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Chong Zhanga8975bd2016-01-28 17:13:47 -08002482 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08002483 pw.print(" hasSavedSurface()="); pw.print(hasSavedSurface());
2484 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002485 if (dumpAll) {
2486 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
2487 pw.print(" last="); mLastFrame.printShortString(pw);
2488 pw.println();
2489 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002490 if (mEnforceSizeCompat) {
2491 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002492 pw.println();
2493 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002494 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002495 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002496 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002497 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002498 pw.println();
2499 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
2500 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002501 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002502 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002503 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002504 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04002505 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
2506 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002507 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
2508 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002509 pw.print(prefix); pw.print("Cur insets: overscan=");
2510 mOverscanInsets.printShortString(pw);
2511 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002512 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002513 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07002514 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002515 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002516 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002517 pw.print(prefix); pw.print("Lst insets: overscan=");
2518 mLastOverscanInsets.printShortString(pw);
2519 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002520 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002521 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002522 pw.print(" physical="); mLastOutsets.printShortString(pw);
2523 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002524 pw.println();
2525 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07002526 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
2527 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002528 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
2529 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002530 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
2531 pw.print(" mDestroying="); pw.print(mDestroying);
2532 pw.print(" mRemoved="); pw.println(mRemoved);
2533 }
2534 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
2535 pw.print(prefix); pw.print("mOrientationChanging=");
2536 pw.print(mOrientationChanging);
2537 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
2538 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
2539 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07002540 if (mLastFreezeDuration != 0) {
2541 pw.print(prefix); pw.print("mLastFreezeDuration=");
2542 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
2543 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002544 if (mHScale != 1 || mVScale != 1) {
2545 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
2546 pw.print(" mVScale="); pw.println(mVScale);
2547 }
2548 if (mWallpaperX != -1 || mWallpaperY != -1) {
2549 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
2550 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
2551 }
2552 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
2553 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
2554 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
2555 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07002556 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
2557 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
2558 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
2559 pw.print(mWallpaperDisplayOffsetX);
2560 pw.print(" mWallpaperDisplayOffsetY=");
2561 pw.println(mWallpaperDisplayOffsetY);
2562 }
Jeff Brownc2932a12014-11-20 18:04:05 -08002563 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07002564 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08002565 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08002566 if (isDragResizing()) {
2567 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
2568 }
2569 if (computeDragResizing()) {
2570 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
2571 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002572 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002573
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002574 String makeInputChannelName() {
2575 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002576 + " " + getWindowTag();
2577 }
2578
Robert Carra1eb4392015-12-10 12:43:51 -08002579 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002580 CharSequence tag = mAttrs.getTitle();
2581 if (tag == null || tag.length() <= 0) {
2582 tag = mAttrs.packageName;
2583 }
2584 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002585 }
2586
2587 @Override
2588 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002589 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002590 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08002591 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002592 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002593 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -07002594 + " u" + UserHandle.getUserId(mSession.mUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002595 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002596 }
2597 return mStringNameCache;
2598 }
Robert Carr58f29132015-10-29 14:19:05 -07002599
2600 void transformFromScreenToSurfaceSpace(Rect rect) {
2601 if (mHScale >= 0) {
Chong Zhang84389572016-01-13 10:33:27 -08002602 rect.left = (int) (rect.left / mHScale);
2603 rect.right = (int) (rect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07002604 }
2605 if (mVScale >= 0) {
Chong Zhang84389572016-01-13 10:33:27 -08002606 rect.top = (int) (rect.top / mVScale);
2607 rect.bottom = (int) (rect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07002608 }
2609 }
Robert Carr31e28482015-12-02 16:53:18 -08002610
Jorim Jaggif5834272016-04-04 20:25:41 -07002611 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
2612 final int pw = containingFrame.width();
2613 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08002614 final Task task = getTask();
Andrii Kulian933076d2016-03-29 17:04:42 -07002615 final boolean nonFullscreenTask = isInMultiWindowMode();
Jorim Jaggid450aa92016-04-15 22:52:00 -07002616 final boolean fitToDisplay = (task == null || !nonFullscreenTask) && !layoutInParentFrame();
Robert Carr31e28482015-12-02 16:53:18 -08002617 float x, y;
2618 int w,h;
2619
2620 if ((mAttrs.flags & FLAG_SCALED) != 0) {
2621 if (mAttrs.width < 0) {
2622 w = pw;
2623 } else if (mEnforceSizeCompat) {
2624 w = (int)(mAttrs.width * mGlobalScale + .5f);
2625 } else {
2626 w = mAttrs.width;
2627 }
2628 if (mAttrs.height < 0) {
2629 h = ph;
2630 } else if (mEnforceSizeCompat) {
2631 h = (int)(mAttrs.height * mGlobalScale + .5f);
2632 } else {
2633 h = mAttrs.height;
2634 }
2635 } else {
2636 if (mAttrs.width == MATCH_PARENT) {
2637 w = pw;
2638 } else if (mEnforceSizeCompat) {
2639 w = (int)(mRequestedWidth * mGlobalScale + .5f);
2640 } else {
2641 w = mRequestedWidth;
2642 }
2643 if (mAttrs.height == MATCH_PARENT) {
2644 h = ph;
2645 } else if (mEnforceSizeCompat) {
2646 h = (int)(mRequestedHeight * mGlobalScale + .5f);
2647 } else {
2648 h = mRequestedHeight;
2649 }
2650 }
2651
2652 if (mEnforceSizeCompat) {
2653 x = mAttrs.x * mGlobalScale;
2654 y = mAttrs.y * mGlobalScale;
2655 } else {
2656 x = mAttrs.x;
2657 y = mAttrs.y;
2658 }
2659
Robert Carr1d2bacb2016-03-30 14:29:35 -07002660 if (nonFullscreenTask && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08002661 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08002662 // required by {@link Gravity#apply} call.
2663 w = Math.min(w, pw);
2664 h = Math.min(h, ph);
2665 }
2666
2667 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07002668 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08002669 (int) (x + mAttrs.horizontalMargin * pw),
2670 (int) (y + mAttrs.verticalMargin * ph), mFrame);
2671
2672 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08002673 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07002674 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08002675 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08002676
2677 // We need to make sure we update the CompatFrame as it is used for
2678 // cropping decisions, etc, on systems where we lack a decor layer.
2679 mCompatFrame.set(mFrame);
2680 if (mEnforceSizeCompat) {
2681 // See comparable block in computeFrameLw.
2682 mCompatFrame.scale(mInvGlobalScale);
2683 }
Robert Carr31e28482015-12-02 16:53:18 -08002684 }
Robert Carr51a1b872015-12-08 14:03:13 -08002685
2686 boolean isChildWindow() {
2687 return mAttachedWindow != null;
2688 }
Robert Carra1eb4392015-12-10 12:43:51 -08002689
Robert Carrf3b72c72016-03-21 18:16:39 -07002690 boolean layoutInParentFrame() {
2691 return isChildWindow() && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
2692 }
2693
Robert Carra1eb4392015-12-10 12:43:51 -08002694 void setReplacing(boolean animate) {
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08002695 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
2696 || mAttrs.type == TYPE_APPLICATION_STARTING) {
2697 // We don't set replacing on starting windows since they are added by window manager and
2698 // not the client so won't be replaced by the client.
2699 return;
Robert Carra1eb4392015-12-10 12:43:51 -08002700 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08002701
2702 mWillReplaceWindow = true;
2703 mReplacingWindow = null;
2704 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08002705 }
Chong Zhangf596cd52016-01-05 13:42:44 -08002706
2707 void resetReplacing() {
2708 mWillReplaceWindow = false;
2709 mReplacingWindow = null;
2710 mAnimateReplacingWindow = false;
2711 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08002712
2713 float translateToWindowX(float x) {
2714 float winX = x - mFrame.left;
2715 if (mEnforceSizeCompat) {
2716 winX *= mGlobalScale;
2717 }
2718 return winX;
2719 }
2720
2721 float translateToWindowY(float y) {
2722 float winY = y - mFrame.top;
2723 if (mEnforceSizeCompat) {
2724 winY *= mGlobalScale;
2725 }
2726 return winY;
2727 }
Robert Carrd1a010f2016-04-07 22:36:22 -07002728
Robert Carr9fe459d2016-04-07 23:32:28 -07002729 void transferDimToReplacement() {
2730 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
2731 if (dimLayerUser != null && mDisplayContent != null) {
2732 mDisplayContent.mDimLayerController.applyDim(dimLayerUser,
2733 mReplacingWindow.mWinAnimator,
2734 (mAttrs.flags & FLAG_DIM_BEHIND) != 0 ? true : false);
2735 }
2736 }
2737
Robert Carrd1a010f2016-04-07 22:36:22 -07002738 // During activity relaunch due to resize, we sometimes use window replacement
2739 // for only child windows (as the main window is handled by window preservation)
2740 // and the big surface.
2741 //
2742 // Though windows of TYPE_APPLICATION (as opposed to TYPE_BASE_APPLICATION)
2743 // are not children in the sense of an attached window, we also want to replace
2744 // them at such phases, as they won't be covered by window preservation,
2745 // and in general we expect them to return following relaunch.
2746 boolean shouldBeReplacedWithChildren() {
2747 return isChildWindow() || mAttrs.type == TYPE_APPLICATION;
2748 }
satokcef37fb2011-10-24 21:49:38 +09002749}