blob: 5fedd5a25c4bed80f9d4cb11f8d113184586d7bf [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 com.android.server.input.InputWindowHandle;
20
21import android.app.ActivityManager;
22import android.app.AppOpsManager;
23import android.content.Context;
24import android.content.res.Configuration;
25import android.graphics.Matrix;
26import android.graphics.PixelFormat;
27import android.graphics.Point;
28import android.graphics.Rect;
29import android.graphics.Region;
30import android.os.IBinder;
31import android.os.PowerManager;
32import android.os.RemoteCallbackList;
33import android.os.RemoteException;
34import android.os.SystemClock;
35import android.os.Trace;
36import android.os.UserHandle;
37import android.os.WorkSource;
38import android.util.DisplayMetrics;
39import android.util.Slog;
40import android.util.TimeUtils;
41import android.view.Display;
42import android.view.DisplayInfo;
43import android.view.Gravity;
44import android.view.IApplicationToken;
45import android.view.IWindow;
46import android.view.IWindowFocusObserver;
47import android.view.IWindowId;
48import android.view.InputChannel;
49import android.view.InputEvent;
50import android.view.InputEventReceiver;
51import android.view.View;
52import android.view.ViewTreeObserver;
53import android.view.WindowManager;
54import android.view.WindowManagerPolicy;
55
56import java.io.PrintWriter;
57import java.util.ArrayList;
58
Wale Ogunwaled045c822015-12-02 09:14:28 -080059import static android.app.ActivityManager.StackId;
Wale Ogunwalecad05a02015-09-25 10:41:44 -070060import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080061import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
62import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
63import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
64import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080065import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080066import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070067import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080068import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080069import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
70import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080071import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070072import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080073import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080074import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
Robert Carr31e28482015-12-02 16:53:18 -080075import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080076import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Wale Ogunwale8216eb22015-12-18 10:42:42 -080077import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080078import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Robert Carra1eb4392015-12-10 12:43:51 -080079import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080080import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
81import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080082import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080083import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070084import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080085import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
86import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
87import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080088import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
89import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
90import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
91import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
92import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
93import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
94import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
95import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
96import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
97import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
98import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
99import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800100
Craig Mautner59c00972012-07-30 12:10:24 -0700101class WindowList extends ArrayList<WindowState> {
102}
103
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800104/**
105 * A window in the window manager.
106 */
Craig Mautnere32c3072012-03-12 15:25:35 -0700107final class WindowState implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800108 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800109
Skuhne81c524a2015-08-12 13:34:14 -0700110 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700111 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
112 // use hard-coded min sizes for now.
113 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
114 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700115
116 // The thickness of a window resize handle outside the window bounds on the free form workspace
117 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700118 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700119
Jorim Jaggidcf467c2015-11-05 13:59:32 +0100120 static final int DRAG_RESIZE_MODE_FREEFORM = 0;
121 static final int DRAG_RESIZE_MODE_DOCKED_DIVIDER = 1;
122
Robert Carr7098dbd2016-02-01 12:31:01 -0800123 static final boolean DEBUG_DISABLE_SAVING_SURFACES = false;
124
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800125 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700126 final WindowManagerPolicy mPolicy;
127 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800128 final Session mSession;
129 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800130 final int mAppOp;
131 // UserId and appId of the owner. Don't display windows of non-current user.
132 final int mOwnerUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800133 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800134 WindowToken mToken;
135 WindowToken mRootToken;
136 AppWindowToken mAppToken;
137 AppWindowToken mTargetAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700138
139 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
140 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800141 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
142 final DeathRecipient mDeathRecipient;
143 final WindowState mAttachedWindow;
Craig Mautner7b1aa772012-11-30 16:14:45 -0800144 final WindowList mChildWindows = new WindowList();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800145 final int mBaseLayer;
146 final int mSubLayer;
147 final boolean mLayoutAttached;
148 final boolean mIsImWindow;
149 final boolean mIsWallpaper;
150 final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700151 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700152 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800153 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700154 int mSystemUiVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800155 boolean mPolicyVisibility = true;
156 boolean mPolicyVisibilityAfterAnim = true;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -0800157 boolean mAppOpVisibility = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800158 boolean mAppFreezing;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800159 boolean mAttachedHidden; // is our parent window hidden?
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800160 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Chong Zhang0275e392015-09-17 10:41:44 -0700161 boolean mDragResizing;
Jorim Jaggidcf467c2015-11-05 13:59:32 +0100162 int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700163
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800164 RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
165
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700166 /**
167 * The window size that was requested by the application. These are in
168 * the application's coordinate space (without compatibility scale applied).
169 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800170 int mRequestedWidth;
171 int mRequestedHeight;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700172 int mLastRequestedWidth;
173 int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700174
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800175 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800176 boolean mHaveFrame;
177 boolean mObscured;
178 boolean mTurnOnScreen;
179
180 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700181
Wale Ogunwale60454db2015-01-23 16:05:07 -0800182 private Configuration mConfiguration = Configuration.EMPTY;
183 private Configuration mOverrideConfig = Configuration.EMPTY;
Craig Mautnere8552142012-11-07 13:55:47 -0800184 // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned.
185 // Used only on {@link #TYPE_KEYGUARD}.
186 private boolean mConfigHasChanged;
Craig Mautnera2c77052012-03-26 12:14:43 -0700187
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700188 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700189 * Actual position of the surface shown on-screen (may be modified by animation). These are
190 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700191 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700192 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800193
194 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700195 * Insets that determine the actually visible area. These are in the application's
196 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800197 */
198 final Rect mVisibleInsets = new Rect();
199 final Rect mLastVisibleInsets = new Rect();
200 boolean mVisibleInsetsChanged;
201
202 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700203 * Insets that are covered by system windows (such as the status bar) and
204 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700205 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800206 */
207 final Rect mContentInsets = new Rect();
208 final Rect mLastContentInsets = new Rect();
209 boolean mContentInsetsChanged;
210
211 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800212 * Insets that determine the area covered by the display overscan region. These are in the
213 * application's coordinate space (without compatibility scale applied).
214 */
215 final Rect mOverscanInsets = new Rect();
216 final Rect mLastOverscanInsets = new Rect();
217 boolean mOverscanInsetsChanged;
218
219 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700220 * Insets that determine the area covered by the stable system windows. These are in the
221 * application's coordinate space (without compatibility scale applied).
222 */
223 final Rect mStableInsets = new Rect();
224 final Rect mLastStableInsets = new Rect();
225 boolean mStableInsetsChanged;
226
227 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700228 * Outsets determine the area outside of the surface where we want to pretend that it's possible
229 * to draw anyway.
230 */
231 final Rect mOutsets = new Rect();
232 final Rect mLastOutsets = new Rect();
233 boolean mOutsetsChanged = false;
234
235 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800236 * Set to true if we are waiting for this window to receive its
237 * given internal insets before laying out other windows based on it.
238 */
239 boolean mGivenInsetsPending;
240
241 /**
242 * These are the content insets that were given during layout for
243 * this window, to be applied to windows behind it.
244 */
245 final Rect mGivenContentInsets = new Rect();
246
247 /**
248 * These are the visible insets that were given during layout for
249 * this window, to be applied to windows behind it.
250 */
251 final Rect mGivenVisibleInsets = new Rect();
252
253 /**
254 * This is the given touchable area relative to the window frame, or null if none.
255 */
256 final Region mGivenTouchableRegion = new Region();
257
258 /**
259 * Flag indicating whether the touchable region should be adjusted by
260 * the visible insets; if false the area outside the visible insets is
261 * NOT touchable, so we must use those to adjust the frame during hit
262 * tests.
263 */
264 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
265
266 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400267 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700268 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800269 float mHScale=1, mVScale=1;
270 float mLastHScale=1, mLastVScale=1;
271 final Matrix mTmpMatrix = new Matrix();
272
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700273 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800274 final Rect mFrame = new Rect();
275 final Rect mLastFrame = new Rect();
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700276 // Frame that is scaled to the application's coordinate space when in
277 // screen size compatibility mode.
278 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800279
280 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700281
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800282 final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700283
Wale Ogunwale94596652015-02-06 19:27:34 -0800284 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
285 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700286 final Rect mDisplayFrame = new Rect();
287
288 // The region of the display frame that the display type supports displaying content on. This
289 // is mostly a special case for TV where some displays don’t have the entire display usable.
290 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
291 // window display contents to extend into the overscan region.
292 final Rect mOverscanFrame = new Rect();
293
294 // The display frame minus the stable insets. This value is always constant regardless of if
295 // the status bar or navigation bar is visible.
Adrian Roosfa104232014-06-20 16:10:14 -0700296 final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800297
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700298 // The area not occupied by the status and navigation bars. So, if both status and navigation
299 // bars are visible, the decor frame is equal to the stable frame.
300 final Rect mDecorFrame = new Rect();
301
302 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
303 // minus the area occupied by the IME if the IME is present.
304 final Rect mContentFrame = new Rect();
305
306 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
307 // displays hint text.
308 final Rect mVisibleFrame = new Rect();
309
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700310 // Frame that includes dead area outside of the surface but where we want to pretend that it's
311 // possible to draw.
312 final Rect mOutsetFrame = new Rect();
313
Jorim Jaggidc249c42015-12-15 14:57:31 -0800314 /**
315 * Usually empty. Set to the task's tempInsetFrame. See
316 *{@link android.app.IActivityManager#resizeDockedStack}.
317 */
318 final Rect mInsetFrame = new Rect();
319
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800320 boolean mContentChanged;
321
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800322 // If a window showing a wallpaper: the requested offset for the
323 // wallpaper; if a wallpaper window: the currently applied offset.
324 float mWallpaperX = -1;
325 float mWallpaperY = -1;
326
327 // If a window showing a wallpaper: what fraction of the offset
328 // range corresponds to a full virtual screen.
329 float mWallpaperXStep = -1;
330 float mWallpaperYStep = -1;
331
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700332 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
333 // to its window; if a wallpaper window: not used.
334 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
335 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
336
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800337 // Wallpaper windows: pixels offset based on above variables.
338 int mXOffset;
339 int mYOffset;
340
Craig Mautner2268e7e2012-12-13 15:40:00 -0800341 /**
342 * This is set after IWindowSession.relayout() has been called at
343 * least once for the window. It allows us to detect the situation
344 * where we don't yet have a surface, but should have one soon, so
345 * we can give the window focus before waiting for the relayout.
346 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800347 boolean mRelayoutCalled;
348
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800349 /**
350 * If the application has called relayout() with changes that can
351 * impact its window's size, we need to perform a layout pass on it
352 * even if it is not currently visible for layout. This is set
353 * when in that case until the layout is done.
354 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800355 boolean mLayoutNeeded;
356
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800357 /** Currently running an exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800358 boolean mExiting;
359
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800360 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800361 boolean mDestroying;
362
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800363 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800364 boolean mRemoveOnExit;
365
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800366 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800367 * Whether the app died while it was visible, if true we might need
368 * to continue to show it until it's restarted.
369 */
370 boolean mAppDied;
371
372 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800373 * Set when the orientation is changing and this window has not yet
374 * been updated for the new orientation.
375 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800376 boolean mOrientationChanging;
377
Dianne Hackborna57c6952013-03-29 14:46:40 -0700378 /**
379 * How long we last kept the screen frozen.
380 */
381 int mLastFreezeDuration;
382
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800383 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800384 boolean mRemoved;
385
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800386 /**
387 * Temp for keeping track of windows that have been removed when
388 * rebuilding window list.
389 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800390 boolean mRebuilding;
391
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800392 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700393 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800394 InputChannel mInputChannel;
Chong Zhang112eb8c2015-11-02 11:17:00 -0800395 InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800396
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800397 // Used to improve performance of toString()
398 String mStringNameCache;
399 CharSequence mLastTitle;
Dianne Hackborn529e7442012-11-01 14:22:28 -0700400 boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800401
Craig Mautnera2c77052012-03-26 12:14:43 -0700402 final WindowStateAnimator mWinAnimator;
403
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700404 boolean mHasSurface = false;
405
Craig Mautner19ab8282014-05-07 10:35:34 -0700406 boolean mNotOnAppsDisplay = false;
Craig Mautner59c00972012-07-30 12:10:24 -0700407 DisplayContent mDisplayContent;
Craig Mautner6881a102012-07-27 13:04:51 -0700408
Craig Mautner88400d32012-09-30 12:35:45 -0700409 /** When true this window can be displayed on screens owther than mOwnerUid's */
410 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700411
Robert Carr13f7be9e2015-12-02 18:39:45 -0800412 // Whether the window has a saved surface from last pause, which can be
413 // used to start an entering animation earlier.
414 public boolean mSurfaceSaved = false;
415
Robert Carra1eb4392015-12-10 12:43:51 -0800416 // This window will be replaced due to relaunch. This allows window manager
417 // to differentiate between simple removal of a window and replacement. In the latter case it
418 // will preserve the old window until the new one is drawn.
419 boolean mWillReplaceWindow = false;
420 // If true, the replaced window was already requested to be removed.
421 boolean mReplacingRemoveRequested = false;
422 // Whether the replacement of the window should trigger app transition animation.
423 boolean mAnimateReplacingWindow = false;
424 // If not null, the window that will be used to replace the old one. This is being set when
425 // the window is added and unset when this window reports its first draw.
426 WindowState mReplacingWindow = null;
427
Chong Zhangbd0d9372015-12-28 15:18:29 -0800428 // Whether this window is being moved via the resize API
429 boolean mMovedByResize;
Jeff Brownc2932a12014-11-20 18:04:05 -0800430 /**
431 * Wake lock for drawing.
432 * Even though it's slightly more expensive to do so, we will use a separate wake lock
433 * for each app that is requesting to draw while dozing so that we can accurately track
434 * who is preventing the system from suspending.
435 * This lock is only acquired on first use.
436 */
437 PowerManager.WakeLock mDrawLock;
438
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700439 final private Rect mTmpRect = new Rect();
440
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800441 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800442 WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a,
Craig Mautner59c00972012-07-30 12:10:24 -0700443 int viewVisibility, final DisplayContent displayContent) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800444 mService = service;
445 mSession = s;
446 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800447 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800448 mToken = token;
Craig Mautnera2d7b112012-08-21 15:12:20 -0700449 mOwnerUid = s.mUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800450 mWindowId = new IWindowId.Stub() {
451 @Override
452 public void registerFocusObserver(IWindowFocusObserver observer) {
453 WindowState.this.registerFocusObserver(observer);
454 }
455 @Override
456 public void unregisterFocusObserver(IWindowFocusObserver observer) {
457 WindowState.this.unregisterFocusObserver(observer);
458 }
459 @Override
460 public boolean isFocused() {
461 return WindowState.this.isFocused();
462 }
463 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800464 mAttrs.copyFrom(a);
465 mViewVisibility = viewVisibility;
Craig Mautner59c00972012-07-30 12:10:24 -0700466 mDisplayContent = displayContent;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700467 mPolicy = mService.mPolicy;
468 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800469 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700470 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700471 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800472 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700473 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700474 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800475 try {
476 c.asBinder().linkToDeath(deathRecipient, 0);
477 } catch (RemoteException e) {
478 mDeathRecipient = null;
479 mAttachedWindow = null;
480 mLayoutAttached = false;
481 mIsImWindow = false;
482 mIsWallpaper = false;
483 mIsFloatingLayer = false;
484 mBaseLayer = 0;
485 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700486 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700487 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800488 return;
489 }
490 mDeathRecipient = deathRecipient;
491
492 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
493 mAttrs.type <= LAST_SUB_WINDOW)) {
494 // The multiplier here is to reserve space for multiple
495 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700496 mBaseLayer = mPolicy.windowTypeToLayerLw(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800497 attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
498 + WindowManagerService.TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700499 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800500 mAttachedWindow = attachedWindow;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800501 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
takeda.masayuki18735092012-12-12 11:06:24 +0900502
tiger_huange2a98a72014-11-13 19:46:28 +0800503 final WindowList childWindows = mAttachedWindow.mChildWindows;
504 final int numChildWindows = childWindows.size();
505 if (numChildWindows == 0) {
506 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900507 } else {
tiger_huange2a98a72014-11-13 19:46:28 +0800508 boolean added = false;
509 for (int i = 0; i < numChildWindows; i++) {
510 final int childSubLayer = childWindows.get(i).mSubLayer;
511 if (mSubLayer < childSubLayer
512 || (mSubLayer == childSubLayer && childSubLayer < 0)) {
513 // We insert the child window into the list ordered by the sub-layer. For
514 // same sub-layers, the negative one should go below others; the positive
515 // one should go above others.
516 childWindows.add(i, this);
517 added = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900518 break;
takeda.masayuki18735092012-12-12 11:06:24 +0900519 }
520 }
tiger_huange2a98a72014-11-13 19:46:28 +0800521 if (!added) {
522 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900523 }
524 }
525
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800526 mLayoutAttached = mAttrs.type !=
527 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
528 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
529 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
530 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
531 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
532 } else {
533 // The multiplier here is to reserve space for multiple
534 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700535 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800536 * WindowManagerService.TYPE_LAYER_MULTIPLIER
537 + WindowManagerService.TYPE_LAYER_OFFSET;
538 mSubLayer = 0;
539 mAttachedWindow = null;
540 mLayoutAttached = false;
541 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
542 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
543 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
544 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
545 }
546
547 WindowState appWin = this;
Robert Carr51a1b872015-12-08 14:03:13 -0800548 while (appWin.isChildWindow()) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700549 appWin = appWin.mAttachedWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800550 }
551 WindowToken appToken = appWin.mToken;
552 while (appToken.appWindowToken == null) {
553 WindowToken parent = mService.mTokenMap.get(appToken.token);
554 if (parent == null || appToken == parent) {
555 break;
556 }
557 appToken = parent;
558 }
559 mRootToken = appToken;
560 mAppToken = appToken.appWindowToken;
Craig Mautner19ab8282014-05-07 10:35:34 -0700561 if (mAppToken != null) {
562 final DisplayContent appDisplay = getDisplayContent();
563 mNotOnAppsDisplay = displayContent != appDisplay;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700564
565 if (mAppToken.showForAllUsers) {
566 // Windows for apps that can show for all users should also show when the
567 // device is locked.
568 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
569 }
Craig Mautner19ab8282014-05-07 10:35:34 -0700570 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800571
Craig Mautner322e4032012-07-13 13:35:20 -0700572 mWinAnimator = new WindowStateAnimator(this);
573 mWinAnimator.mAlpha = a.alpha;
574
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800575 mRequestedWidth = 0;
576 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700577 mLastRequestedWidth = 0;
578 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800579 mXOffset = 0;
580 mYOffset = 0;
581 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800582 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700583 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
584 displayContent.getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800585 }
586
587 void attach() {
588 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700589 TAG, "Attaching " + this + " token=" + mToken
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800590 + ", list=" + mToken.windows);
591 mSession.windowAddedLocked();
592 }
593
Craig Mautnera2c77052012-03-26 12:14:43 -0700594 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800595 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800596 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800597 }
598
599 @Override
600 public String getOwningPackage() {
601 return mAttrs.packageName;
602 }
603
604 @Override
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700605 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf, Rect sf,
606 Rect osf) {
Robert Carra1eb4392015-12-10 12:43:51 -0800607 if (mWillReplaceWindow && (mExiting || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700608 // This window is being replaced and either already got information that it's being
609 // removed or we are still waiting for some information. Because of this we don't
610 // want to apply any more changes to it, so it remains in this state until new window
611 // appears.
612 return;
613 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800614 mHaveFrame = true;
615
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700616 final Task task = getTask();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800617 final boolean fullscreenTask = task == null || task.isFullscreen();
Chong Zhang09b21ef2015-09-14 10:20:21 -0700618 final boolean freeformWorkspace = task != null && task.inFreeformWorkspace();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800619
Wale Ogunwale8216eb22015-12-18 10:42:42 -0800620 if (fullscreenTask || (isChildWindow()
621 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0)) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800622 // We use the parent frame as the containing frame for fullscreen and child windows
623 mContainingFrame.set(pf);
624 mDisplayFrame.set(df);
Jorim Jaggidc249c42015-12-15 14:57:31 -0800625 mInsetFrame.setEmpty();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800626 } else {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700627 task.getBounds(mContainingFrame);
Jorim Jaggidc249c42015-12-15 14:57:31 -0800628 task.getTempInsetBounds(mInsetFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100629 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
630
631 // If the bounds are frozen, we still want to translate the window freely and only
632 // freeze the size.
633 Rect frozen = mAppToken.mFrozenBounds.peek();
634 mContainingFrame.right = mContainingFrame.left + frozen.width();
635 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
636 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800637 final WindowState imeWin = mService.mInputMethodWindow;
638 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this
639 && mContainingFrame.bottom > cf.bottom) {
640 // IME is up and obscuring this window. Adjust the window position so it is visible.
641 mContainingFrame.top -= mContainingFrame.bottom - cf.bottom;
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700642 }
Skuhne81c524a2015-08-12 13:34:14 -0700643
Skuhnef932e562015-08-20 12:07:30 -0700644 if (freeformWorkspace) {
Skuhne81c524a2015-08-12 13:34:14 -0700645 // In free form mode we have only to set the rectangle if it wasn't set already. No
646 // need to intersect it with the (visible) "content frame" since it is allowed to
647 // be outside the visible desktop.
648 if (mContainingFrame.isEmpty()) {
649 mContainingFrame.set(cf);
650 }
Doris Liu06d582d2015-06-01 13:18:43 -0700651 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800652 mDisplayFrame.set(mContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700653 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800654
Craig Mautner967212c2013-04-13 21:10:58 -0700655 final int pw = mContainingFrame.width();
656 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800657
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800658 if (!mParentFrame.equals(pf)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800659 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800660 // + " to " + pf);
661 mParentFrame.set(pf);
662 mContentChanged = true;
663 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700664 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
665 mLastRequestedWidth = mRequestedWidth;
666 mLastRequestedHeight = mRequestedHeight;
667 mContentChanged = true;
668 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800669
Craig Mautnereda67292013-04-28 13:50:14 -0700670 mOverscanFrame.set(of);
671 mContentFrame.set(cf);
672 mVisibleFrame.set(vf);
John Spurlock46646232013-09-30 22:32:42 -0400673 mDecorFrame.set(dcf);
Adrian Roosfa104232014-06-20 16:10:14 -0700674 mStableFrame.set(sf);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700675 final boolean hasOutsets = osf != null;
676 if (hasOutsets) {
677 mOutsetFrame.set(osf);
678 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800679
Craig Mautnereda67292013-04-28 13:50:14 -0700680 final int fw = mFrame.width();
681 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800682
Robert Carr31e28482015-12-02 16:53:18 -0800683 applyGravityAndUpdateFrame();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800684
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700685 // Calculate the outsets before the content frame gets shrinked to the window frame.
686 if (hasOutsets) {
687 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
688 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
689 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
690 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
691 } else {
692 mOutsets.set(0, 0, 0, 0);
693 }
694
Jorim Jaggidc249c42015-12-15 14:57:31 -0800695 // Denotes the actual frame used to calculate the insets. When resizing in docked mode,
696 // we'd like to freeze the layout, so we also need to freeze the insets temporarily. By the
697 // notion of a task having a different inset frame, we can achieve that while still moving
698 // the task around.
699 final Rect frame = !mInsetFrame.isEmpty() ? mInsetFrame : mFrame;
700
Craig Mautnera248eee2013-05-07 11:41:27 -0700701 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800702 // final window frame.
Skuhnef932e562015-08-20 12:07:30 -0700703 if (freeformWorkspace && !mFrame.isEmpty()) {
Skuhne81c524a2015-08-12 13:34:14 -0700704 // Keep the frame out of the blocked system area, limit it in size to the content area
705 // and make sure that there is always a minimum visible so that the user can drag it
706 // into a usable area..
707 final int height = Math.min(mFrame.height(), mContentFrame.height());
708 final int width = Math.min(mContentFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700709 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700710 final int minVisibleHeight = WindowManagerService.dipToPixel(
711 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics);
712 final int minVisibleWidth = WindowManagerService.dipToPixel(
713 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics);
Skuhne81c524a2015-08-12 13:34:14 -0700714 final int top = Math.max(mContentFrame.top,
715 Math.min(mFrame.top, mContentFrame.bottom - minVisibleHeight));
716 final int left = Math.max(mContentFrame.left + minVisibleWidth - width,
717 Math.min(mFrame.left, mContentFrame.right - minVisibleWidth));
718 mFrame.set(left, top, left + width, top + height);
719 mContentFrame.set(mFrame);
720 mVisibleFrame.set(mContentFrame);
721 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700722 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800723 if (isVisibleLw() || mWinAnimator.isAnimating()) {
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800724 // We don't adjust the dock divider frame for reasons other than performance. The
725 // real reason is that if it gets adjusted before it is shown for the first time,
726 // it would get size (0, 0). This causes a problem when we finally show the dock
727 // divider and try to draw to it. We do set the surface size at that moment to
728 // the correct size, but it's too late for the Surface Flinger to make it
729 // available for view rendering and as a result the renderer receives size 1, 1.
730 // This way we just keep the divider at the original size and Surface Flinger
731 // will return the correct value to the renderer.
732 mDisplayContent.getDockedDividerController().positionDockedStackedDivider(mFrame);
733 mContentFrame.set(mFrame);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800734 if (!mFrame.equals(mLastFrame)) {
735 mMovedByResize = true;
736 }
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800737 }
Skuhne81c524a2015-08-12 13:34:14 -0700738 } else {
Jorim Jaggidc249c42015-12-15 14:57:31 -0800739 mContentFrame.set(Math.max(mContentFrame.left, frame.left),
740 Math.max(mContentFrame.top, frame.top),
741 Math.min(mContentFrame.right, frame.right),
742 Math.min(mContentFrame.bottom, frame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800743
Jorim Jaggidc249c42015-12-15 14:57:31 -0800744 mVisibleFrame.set(Math.max(mVisibleFrame.left, frame.left),
745 Math.max(mVisibleFrame.top, frame.top),
746 Math.min(mVisibleFrame.right, frame.right),
747 Math.min(mVisibleFrame.bottom, frame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800748
Jorim Jaggidc249c42015-12-15 14:57:31 -0800749 mStableFrame.set(Math.max(mStableFrame.left, frame.left),
750 Math.max(mStableFrame.top, frame.top),
751 Math.min(mStableFrame.right, frame.right),
752 Math.min(mStableFrame.bottom, frame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700753 }
Adrian Roosfa104232014-06-20 16:10:14 -0700754
Jorim Jaggidc249c42015-12-15 14:57:31 -0800755 mOverscanInsets.set(Math.max(mOverscanFrame.left - frame.left, 0),
756 Math.max(mOverscanFrame.top - frame.top, 0),
757 Math.max(frame.right - mOverscanFrame.right, 0),
758 Math.max(frame.bottom - mOverscanFrame.bottom, 0));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800759
Craig Mautnereda67292013-04-28 13:50:14 -0700760
Craig Mautnereda67292013-04-28 13:50:14 -0700761
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100762 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
763
764 // For the docked divider, we calculate the stable insets like a full-screen window
765 // so it can use it to calculate the snap positions.
766 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
767 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
768 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
769 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800770
771 // The divider doesn't care about insets in any case, so set it to empty so we don't
772 // trigger a relayout when moving it.
773 mContentInsets.setEmpty();
774 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100775 } else {
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800776 mContentInsets.set(mContentFrame.left - frame.left,
777 mContentFrame.top - frame.top,
778 frame.right - mContentFrame.right,
779 frame.bottom - mContentFrame.bottom);
780
781 mVisibleInsets.set(mVisibleFrame.left - frame.left,
782 mVisibleFrame.top - frame.top,
783 frame.right - mVisibleFrame.right,
784 frame.bottom - mVisibleFrame.bottom);
785
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100786 mStableInsets.set(Math.max(mStableFrame.left - frame.left, 0),
787 Math.max(mStableFrame.top - frame.top, 0),
788 Math.max(frame.right - mStableFrame.right, 0),
789 Math.max(frame.bottom - mStableFrame.bottom, 0));
790 }
Adrian Roosfa104232014-06-20 16:10:14 -0700791
Jorim Jaggidc249c42015-12-15 14:57:31 -0800792 if (!mInsetFrame.isEmpty()) {
793 mContentFrame.set(mFrame);
794 mContentFrame.top += mContentInsets.top;
795 mContentFrame.bottom += mContentInsets.bottom;
796 mContentFrame.left += mContentInsets.left;
797 mContentFrame.right += mContentInsets.right;
798 mVisibleFrame.set(mFrame);
799 mVisibleFrame.top += mVisibleInsets.top;
800 mVisibleFrame.bottom += mVisibleInsets.bottom;
801 mVisibleFrame.left += mVisibleInsets.left;
802 mVisibleFrame.right += mVisibleInsets.right;
803 mStableFrame.set(mFrame);
804 mStableFrame.top += mStableInsets.top;
805 mStableFrame.bottom += mStableInsets.bottom;
806 mStableFrame.left += mStableInsets.left;
807 mStableFrame.right += mStableInsets.right;
808 }
Craig Mautnereda67292013-04-28 13:50:14 -0700809 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400810 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700811 // If there is a size compatibility scale being applied to the
812 // window, we need to apply this to its insets so that they are
813 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700814 mOverscanInsets.scale(mInvGlobalScale);
815 mContentInsets.scale(mInvGlobalScale);
816 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700817 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700818 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700819
820 // Also the scaled frame that we report to the app needs to be
821 // adjusted to be in its coordinate space.
822 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400823 }
824
Craig Mautnereda67292013-04-28 13:50:14 -0700825 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800826 final DisplayContent displayContent = getDisplayContent();
827 if (displayContent != null) {
828 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700829 mService.mWallpaperControllerLocked.updateWallpaperOffset(
830 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800831 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800832 }
833
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700834 if (DEBUG_LAYOUT || WindowManagerService.localLOGV) Slog.v(TAG,
835 "Resolving (mRequestedWidth="
836 + mRequestedWidth + ", mRequestedheight="
837 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
838 + "): frame=" + mFrame.toShortString()
839 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -0700840 + " vi=" + mVisibleInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700841 + " vi=" + mStableInsets.toShortString()
842 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800843 }
844
Craig Mautnera2c77052012-03-26 12:14:43 -0700845 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800846 public Rect getFrameLw() {
847 return mFrame;
848 }
849
Craig Mautnera2c77052012-03-26 12:14:43 -0700850 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700851 public Point getShownPositionLw() {
852 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800853 }
854
Craig Mautnera2c77052012-03-26 12:14:43 -0700855 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800856 public Rect getDisplayFrameLw() {
857 return mDisplayFrame;
858 }
859
Craig Mautnera2c77052012-03-26 12:14:43 -0700860 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800861 public Rect getOverscanFrameLw() {
862 return mOverscanFrame;
863 }
864
865 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800866 public Rect getContentFrameLw() {
867 return mContentFrame;
868 }
869
Craig Mautnera2c77052012-03-26 12:14:43 -0700870 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800871 public Rect getVisibleFrameLw() {
872 return mVisibleFrame;
873 }
874
Craig Mautnera2c77052012-03-26 12:14:43 -0700875 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800876 public boolean getGivenInsetsPendingLw() {
877 return mGivenInsetsPending;
878 }
879
Craig Mautnera2c77052012-03-26 12:14:43 -0700880 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800881 public Rect getGivenContentInsetsLw() {
882 return mGivenContentInsets;
883 }
884
Craig Mautnera2c77052012-03-26 12:14:43 -0700885 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800886 public Rect getGivenVisibleInsetsLw() {
887 return mGivenVisibleInsets;
888 }
889
Craig Mautnera2c77052012-03-26 12:14:43 -0700890 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800891 public WindowManager.LayoutParams getAttrs() {
892 return mAttrs;
893 }
894
Craig Mautner812d2ca2012-09-27 15:35:34 -0700895 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800896 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
897 int index = -1;
898 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -0700899 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800900 while (true) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -0700901 if (ws.mAttrs.needsMenuKey != WindowManager.LayoutParams.NEEDS_MENU_UNSET) {
902 return ws.mAttrs.needsMenuKey == WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800903 }
904 // If we reached the bottom of the range of windows we are considering,
905 // assume no menu is needed.
906 if (ws == bottom) {
907 return false;
908 }
909 // The current window hasn't specified whether menu key is needed;
910 // look behind it.
911 // First, we may need to determine the starting position.
912 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -0700913 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800914 }
915 index--;
916 if (index < 0) {
917 return false;
918 }
Craig Mautner59c00972012-07-30 12:10:24 -0700919 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800920 }
921 }
922
Craig Mautner19d59bc2012-09-04 11:15:56 -0700923 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700924 public int getSystemUiVisibility() {
925 return mSystemUiVisibility;
926 }
927
Craig Mautner19d59bc2012-09-04 11:15:56 -0700928 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800929 public int getSurfaceLayer() {
930 return mLayer;
931 }
932
Craig Mautner812d2ca2012-09-27 15:35:34 -0700933 @Override
Selim Cinekd6623612015-05-22 18:56:22 -0700934 public int getBaseType() {
935 WindowState win = this;
Robert Carr51a1b872015-12-08 14:03:13 -0800936 while (win.isChildWindow()) {
Selim Cinekd6623612015-05-22 18:56:22 -0700937 win = win.mAttachedWindow;
938 }
939 return win.mAttrs.type;
940 }
941
942 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800943 public IApplicationToken getAppToken() {
944 return mAppToken != null ? mAppToken.appToken : null;
945 }
Craig Mautner19d59bc2012-09-04 11:15:56 -0700946
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700947 @Override
948 public boolean isVoiceInteraction() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700949 return mAppToken != null && mAppToken.voiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700950 }
951
Craig Mautner4c5eb222013-11-18 12:59:05 -0800952 boolean setInsetsChanged() {
953 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
954 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
955 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -0700956 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700957 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
958 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
959 || mOutsetsChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -0800960 }
961
Craig Mautnerdf88d732014-01-27 09:21:32 -0800962 public DisplayContent getDisplayContent() {
Chad Jonesf391ebc2014-06-12 17:45:05 -0700963 if (mAppToken == null || mNotOnAppsDisplay) {
Craig Mautnerbe634952014-06-12 13:39:24 -0700964 return mDisplayContent;
965 }
966 final TaskStack stack = getStack();
967 return stack == null ? mDisplayContent : stack.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -0800968 }
969
Chong Zhang09b21ef2015-09-14 10:20:21 -0700970 public DisplayInfo getDisplayInfo() {
971 final DisplayContent displayContent = getDisplayContent();
972 return displayContent != null ? displayContent.getDisplayInfo() : null;
973 }
974
Craig Mautner19d59bc2012-09-04 11:15:56 -0700975 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800976 final DisplayContent displayContent = getDisplayContent();
977 if (displayContent == null) {
978 return -1;
979 }
980 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -0700981 }
982
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700983 Task getTask() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700984 return mAppToken != null ? mAppToken.mTask : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700985 }
986
987 TaskStack getStack() {
988 Task task = getTask();
989 if (task != null) {
990 if (task.mStack != null) {
991 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -0700992 }
Craig Mautnerd9a22882013-03-16 15:00:36 -0700993 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700994 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
995 // associate them with some stack to enable dimming.
996 return mAttrs.type >= WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
997 && mDisplayContent != null ? mDisplayContent.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -0700998 }
999
Skuhnef932e562015-08-20 12:07:30 -07001000 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001001 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001002 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001003 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001004 void getVisibleBounds(Rect bounds) {
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001005 boolean intersectWithStackBounds = mAppToken != null && mAppToken.mCropWindowsToStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001006 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001007 mTmpRect.setEmpty();
1008 if (intersectWithStackBounds) {
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001009 final TaskStack stack = getStack();
1010 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001011 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001012 } else {
1013 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001014 }
1015 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001016
Chong Zhang9184ec62015-09-24 12:32:21 -07001017 bounds.set(mVisibleFrame);
1018 if (intersectWithStackBounds) {
1019 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001020 }
1021
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001022 if (bounds.isEmpty()) {
1023 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001024 if (intersectWithStackBounds) {
1025 bounds.intersect(mTmpRect);
1026 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001027 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001028 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001029 }
1030
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001031 public long getInputDispatchingTimeoutNanos() {
1032 return mAppToken != null
1033 ? mAppToken.inputDispatchingTimeoutNanos
1034 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1035 }
1036
Craig Mautnere8552142012-11-07 13:55:47 -08001037 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001038 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001039 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001040 }
1041
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001042 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1043 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1044 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1045 if (dtdx < -.000001f || dtdx > .000001f) return false;
1046 if (dsdy < -.000001f || dsdy > .000001f) return false;
1047 return true;
1048 }
1049
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001050 void prelayout() {
1051 if (mEnforceSizeCompat) {
1052 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001053 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001054 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001055 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001056 }
1057 }
1058
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001059 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001060 * Does the minimal check for visibility. Callers generally want to use one of the public
1061 * methods as they perform additional checks on the app token.
1062 * TODO: See if there are other places we can use this check below instead of duplicating...
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001063 */
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001064 private boolean isVisibleUnchecked() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001065 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001066 && !mExiting && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001067 }
1068
1069 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001070 * Is this window visible? It is not visible if there is no surface, or we are in the process
1071 * of running an exit animation that will remove the surface, or its app token has been hidden.
1072 */
1073 @Override
1074 public boolean isVisibleLw() {
1075 return (mAppToken == null || !mAppToken.hiddenRequested) && isVisibleUnchecked();
1076 }
1077
1078 /**
1079 * Like {@link #isVisibleLw}, but also counts a window that is currently "hidden" behind the
1080 * keyguard as visible. This allows us to apply things like window flags that impact the
1081 * keyguard. XXX I am starting to think we need to have ANOTHER visibility flag for this
1082 * "hidden behind keyguard" state rather than overloading mPolicyVisibility. Ungh.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001083 */
Craig Mautner88400d32012-09-30 12:35:45 -07001084 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001085 public boolean isVisibleOrBehindKeyguardLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001086 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001087 return false;
1088 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001089 final AppWindowToken atoken = mAppToken;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001090 final boolean animating = atoken != null && atoken.mAppAnimator.animation != null;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001091 return mHasSurface && !mDestroying && !mExiting
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001092 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001093 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001094 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001095 }
1096
1097 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001098 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1099 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001100 */
1101 public boolean isWinVisibleLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001102 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.mAppAnimator.animating)
1103 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001104 }
1105
1106 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001107 * The same as isVisible(), but follows the current hidden state of the associated app token,
1108 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001109 */
1110 boolean isVisibleNow() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001111 return (!mRootToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
1112 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001113 }
1114
1115 /**
1116 * Can this window possibly be a drag/drop target? The test here is
1117 * a combination of the above "visible now" with the check that the
1118 * Input Manager uses when discarding windows from input consideration.
1119 */
1120 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001121 return isVisibleNow() && !mRemoved
1122 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001123 }
1124
1125 /**
1126 * Same as isVisible(), but we also count it as visible between the
1127 * call to IWindowSession.add() and the first relayout().
1128 */
1129 boolean isVisibleOrAdding() {
1130 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001131 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001132 && mPolicyVisibility && !mAttachedHidden
1133 && (atoken == null || !atoken.hiddenRequested)
1134 && !mExiting && !mDestroying;
1135 }
1136
1137 /**
1138 * Is this window currently on-screen? It is on-screen either if it
1139 * is visible or it is currently running an animation before no longer
1140 * being visible.
1141 */
1142 boolean isOnScreen() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001143 return mPolicyVisibility && isOnScreenIgnoringKeyguard();
1144 }
1145
1146 /**
1147 * Like isOnScreen(), but ignores any force hiding of the window due
1148 * to the keyguard.
1149 */
1150 boolean isOnScreenIgnoringKeyguard() {
1151 if (!mHasSurface || mDestroying) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001152 return false;
1153 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001154 final AppWindowToken atoken = mAppToken;
1155 if (atoken != null) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001156 return ((!mAttachedHidden && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001157 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001158 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001159 return !mAttachedHidden || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001160 }
1161
1162 /**
1163 * Like isOnScreen(), but we don't return true if the window is part
1164 * of a transition that has not yet been started.
1165 */
1166 boolean isReadyForDisplay() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001167 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001168 return false;
1169 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001170 return mHasSurface && mPolicyVisibility && !mDestroying
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001171 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001172 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001173 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001174 }
1175
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001176 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001177 * Like isReadyForDisplay(), but ignores any force hiding of the window due
1178 * to the keyguard.
1179 */
1180 boolean isReadyForDisplayIgnoringKeyguard() {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001181 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001182 return false;
1183 }
1184 final AppWindowToken atoken = mAppToken;
1185 if (atoken == null && !mPolicyVisibility) {
1186 // If this is not an app window, and the policy has asked to force
1187 // hide, then we really do want to hide.
1188 return false;
1189 }
1190 return mHasSurface && !mDestroying
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001191 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE && !mRootToken.hidden)
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001192 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -07001193 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
1194 && !mWinAnimator.isDummyAnimation()));
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001195 }
1196
1197 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001198 * Like isOnScreen, but returns false if the surface hasn't yet
1199 * been drawn.
1200 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001201 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001202 public boolean isDisplayedLw() {
1203 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001204 return isDrawnLw() && mPolicyVisibility
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001205 && ((!mAttachedHidden &&
1206 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001207 || mWinAnimator.mAnimating
1208 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001209 }
1210
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001211 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001212 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001213 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001214 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001215 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001216 return mWinAnimator.mAnimation != null
1217 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001218 }
1219
Craig Mautner812d2ca2012-09-27 15:35:34 -07001220 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001221 public boolean isGoneForLayoutLw() {
1222 final AppWindowToken atoken = mAppToken;
1223 return mViewVisibility == View.GONE
1224 || !mRelayoutCalled
1225 || (atoken == null && mRootToken.hidden)
Craig Mautner812d2ca2012-09-27 15:35:34 -07001226 || (atoken != null && (atoken.hiddenRequested || atoken.hidden))
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001227 || mAttachedHidden
Craig Mautner0e415c62013-04-29 16:10:58 -07001228 || (mExiting && !isAnimatingLw())
1229 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001230 }
1231
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001232 /**
1233 * Returns true if the window has a surface that it has drawn a
1234 * complete UI in to.
1235 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001236 public boolean isDrawFinishedLw() {
1237 return mHasSurface && !mDestroying &&
1238 (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING
1239 || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1240 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
1241 }
1242
1243 /**
1244 * Returns true if the window has a surface that it has drawn a
1245 * complete UI in to.
1246 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001247 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001248 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001249 return mHasSurface && !mDestroying &&
Craig Mautner749a7bb2012-04-02 13:49:53 -07001250 (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1251 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001252 }
1253
1254 /**
1255 * Return true if the window is opaque and fully drawn. This indicates
1256 * it may obscure windows behind it.
1257 */
1258 boolean isOpaqueDrawn() {
1259 return (mAttrs.format == PixelFormat.OPAQUE
1260 || mAttrs.type == TYPE_WALLPAPER)
Craig Mautnera2c77052012-03-26 12:14:43 -07001261 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001262 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001263 }
1264
1265 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001266 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001267 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1268 */
Craig Mautner4557c082015-04-27 13:07:40 -07001269 boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001270 return mHasSurface && (mContentChanged || mMovedByResize)
1271 && !mExiting && !mWinAnimator.mLastHidden && mService.okToDisplay()
1272 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Craig Mautner4557c082015-04-27 13:07:40 -07001273 && (mAttachedWindow == null || !mAttachedWindow.hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001274 }
1275
Chong Zhang0abb20f2015-11-19 14:17:31 -08001276 boolean isObscuringFullscreen(final DisplayInfo displayInfo) {
1277 Task task = getTask();
1278 if (task != null && task.mStack != null && !task.mStack.isFullscreen()) {
1279 return false;
1280 }
1281 if (!isOpaqueDrawn() || !isFrameFullscreen(displayInfo)) {
1282 return false;
1283 }
1284 return true;
1285 }
1286
1287 boolean isFrameFullscreen(final DisplayInfo displayInfo) {
1288 return mFrame.left <= 0 && mFrame.top <= 0
1289 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001290 }
1291
Craig Mautner812d2ca2012-09-27 15:35:34 -07001292 boolean isConfigChanged() {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001293 final Task task = getTask();
Wale Ogunwale60454db2015-01-23 16:05:07 -08001294 final Configuration overrideConfig =
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001295 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001296 final Configuration serviceConfig = mService.mCurConfiguration;
1297 boolean configChanged =
1298 (mConfiguration != serviceConfig && mConfiguration.diff(serviceConfig) != 0)
1299 || (mOverrideConfig != overrideConfig && !mOverrideConfig.equals(overrideConfig));
Craig Mautnere8552142012-11-07 13:55:47 -08001300
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001301 if ((mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Craig Mautnere8552142012-11-07 13:55:47 -08001302 // Retain configuration changed status until resetConfiguration called.
1303 mConfigHasChanged |= configChanged;
1304 configChanged = mConfigHasChanged;
1305 }
1306
1307 return configChanged;
Craig Mautner812d2ca2012-09-27 15:35:34 -07001308 }
1309
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001310 void removeLocked() {
1311 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001312
Robert Carr51a1b872015-12-08 14:03:13 -08001313 if (isChildWindow()) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001314 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001315 mAttachedWindow.mChildWindows.remove(this);
1316 }
Craig Mautner96868332012-12-04 14:29:11 -08001317 mWinAnimator.destroyDeferredSurfaceLocked();
1318 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001319 mSession.windowRemovedLocked();
1320 try {
1321 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1322 } catch (RuntimeException e) {
1323 // Ignore if it has already been removed (usually because
1324 // we are doing this as part of processing a death note.)
1325 }
1326 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001327
Wale Ogunwale60454db2015-01-23 16:05:07 -08001328 private void setConfiguration(
1329 final Configuration newConfig, final Configuration newOverrideConfig) {
Craig Mautnere8552142012-11-07 13:55:47 -08001330 mConfiguration = newConfig;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001331 mOverrideConfig = newOverrideConfig;
Craig Mautnere8552142012-11-07 13:55:47 -08001332 mConfigHasChanged = false;
1333 }
1334
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001335 void setHasSurface(boolean hasSurface) {
1336 mHasSurface = hasSurface;
1337 }
1338
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001339 int getAnimLayerAdjustment() {
1340 if (mTargetAppToken != null) {
1341 return mTargetAppToken.mAppAnimator.animLayerAdjustment;
1342 } else if (mAppToken != null) {
1343 return mAppToken.mAppAnimator.animLayerAdjustment;
1344 } else {
1345 // Nothing is animating, so there is no animation adjustment.
1346 return 0;
1347 }
1348 }
1349
1350 void scheduleAnimationIfDimming() {
1351 if (mDisplayContent == null) {
1352 return;
1353 }
1354 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1355 if (dimLayerUser != null && mDisplayContent.mDimLayerController.isDimming(
1356 dimLayerUser, mWinAnimator)) {
1357 // Force an animation pass just to update the mDimLayer layer.
1358 mService.scheduleAnimationLocked();
1359 }
1360 }
1361
Chong Zhangacf11402015-11-04 16:23:10 -08001362 private final class DeadWindowEventReceiver extends InputEventReceiver {
1363 DeadWindowEventReceiver(InputChannel inputChannel) {
1364 super(inputChannel, mService.mH.getLooper());
1365 }
1366 @Override
1367 public void onInputEvent(InputEvent event) {
1368 finishInputEvent(event, true);
1369 }
1370 }
1371 /**
1372 * Dummy event receiver for windows that died visible.
1373 */
1374 private DeadWindowEventReceiver mDeadWindowEventReceiver;
1375
Chong Zhang112eb8c2015-11-02 11:17:00 -08001376 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001377 if (mInputChannel != null) {
1378 throw new IllegalStateException("Window already has an input channel.");
1379 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001380 String name = makeInputChannelName();
1381 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1382 mInputChannel = inputChannels[0];
1383 mClientChannel = inputChannels[1];
1384 mInputWindowHandle.inputChannel = inputChannels[0];
1385 if (outInputChannel != null) {
1386 mClientChannel.transferTo(outInputChannel);
1387 mClientChannel.dispose();
1388 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08001389 } else {
1390 // If the window died visible, we setup a dummy input channel, so that taps
1391 // can still detected by input monitor channel, and we can relaunch the app.
1392 // Create dummy event receiver that simply reports all events as handled.
1393 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08001394 }
1395 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001396 }
1397
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001398 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08001399 if (mDeadWindowEventReceiver != null) {
1400 mDeadWindowEventReceiver.dispose();
1401 mDeadWindowEventReceiver = null;
1402 }
1403
1404 // unregister server channel first otherwise it complains about broken channel
1405 if (mInputChannel != null) {
1406 mService.mInputManager.unregisterInputChannel(mInputChannel);
1407 mInputChannel.dispose();
1408 mInputChannel = null;
1409 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001410 if (mClientChannel != null) {
1411 mClientChannel.dispose();
1412 mClientChannel = null;
1413 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001414 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001415 }
1416
Chong Zhang112eb8c2015-11-02 11:17:00 -08001417 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08001418 // When the app is terminated (eg. from Recents), the task might have already been
1419 // removed with the window pending removal. Don't apply dim in such cases, as there
1420 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
1421 final AppWindowToken token = mAppToken;
1422 if (token != null && token.removed) {
1423 return;
1424 }
1425
Chong Zhang112eb8c2015-11-02 11:17:00 -08001426 if (!mExiting && mAppDied) {
1427 // If app died visible, apply a dim over the window to indicate that it's inactive
1428 mDisplayContent.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
1429 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
1430 && mDisplayContent != null && !mExiting && isDisplayedLw()) {
1431 mDisplayContent.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001432 }
1433 }
1434
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001435 DimLayer.DimLayerUser getDimLayerUser() {
1436 Task task = getTask();
1437 if (task != null) {
1438 return task;
1439 }
1440 return getStack();
1441 }
1442
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001443 void maybeRemoveReplacedWindow() {
Robert Carra1eb4392015-12-10 12:43:51 -08001444 if (mAppToken == null) {
1445 return;
1446 }
1447 for (int i = mAppToken.allAppWindows.size() - 1; i >= 0; i--) {
1448 final WindowState win = mAppToken.allAppWindows.get(i);
1449 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + win);
1450 if (win.mWillReplaceWindow && win.mReplacingWindow == this) {
1451 win.mWillReplaceWindow = false;
1452 win.mAnimateReplacingWindow = false;
1453 win.mReplacingRemoveRequested = false;
1454 win.mReplacingWindow = null;
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001455 if (win.mExiting) {
1456 mService.removeWindowInnerLocked(win);
1457 }
1458 }
1459 }
1460 }
1461
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07001462 void setDisplayLayoutNeeded() {
1463 if (mDisplayContent != null) {
1464 mDisplayContent.layoutNeeded = true;
1465 }
1466 }
1467
Filip Gruszczynski955b2fc2015-10-15 14:46:07 -07001468 boolean inDockedWorkspace() {
Chong Zhang2a88fc32016-01-11 17:14:24 -08001469 final Task task = getTask();
Chong Zhangb15758a2015-11-17 12:12:03 -08001470 return task != null && task.inDockedWorkspace();
1471 }
1472
1473 boolean isDockedInEffect() {
Chong Zhang2a88fc32016-01-11 17:14:24 -08001474 final Task task = getTask();
Chong Zhangb15758a2015-11-17 12:12:03 -08001475 return task != null && task.isDockedInEffect();
Filip Gruszczynski955b2fc2015-10-15 14:46:07 -07001476 }
1477
Chong Zhang2a88fc32016-01-11 17:14:24 -08001478 void applyScrollIfNeeded() {
1479 final Task task = getTask();
Chong Zhangf66db432016-01-13 10:39:51 -08001480 if (task != null) {
1481 task.applyScrollToWindowIfNeeded(this);
Chong Zhang2a88fc32016-01-11 17:14:24 -08001482 }
1483 }
1484
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001485 int getTouchableRegion(Region region, int flags) {
1486 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001487 if (modal && mAppToken != null) {
1488 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001489 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001490 // If this is a modal window we need to dismiss it if it's not full screen and the
1491 // touch happens outside of the frame that displays the content. This means we
1492 // need to intercept touches outside of that window. The dim layer user
1493 // associated with the window (task or stack) will give us the good bounds, as
1494 // they would be used to display the dim layer.
1495 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1496 if (dimLayerUser != null) {
1497 dimLayerUser.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001498 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001499 getVisibleBounds(mTmpRect);
1500 }
1501 if (inFreeformWorkspace()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001502 // For freeform windows we the touch region to include the whole surface for the
1503 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001504 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
1505 final int delta = WindowManagerService.dipToPixel(
1506 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
1507 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001508 }
1509 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001510 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001511 } else {
1512 // Not modal or full screen modal
1513 getTouchableRegion(region);
1514 }
1515 return flags;
1516 }
1517
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001518 void checkPolicyVisibilityChange() {
1519 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
1520 if (DEBUG_VISIBILITY) {
1521 Slog.v(TAG, "Policy visibility changing after anim in " +
1522 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
1523 }
1524 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001525 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001526 if (!mPolicyVisibility) {
1527 if (mService.mCurrentFocus == this) {
1528 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
1529 "setAnimationLocked: setting mFocusMayChange true");
1530 mService.mFocusMayChange = true;
1531 }
1532 // Window is no longer visible -- make sure if we were waiting
1533 // for it to be displayed before enabling the display, that
1534 // we allow the display to be enabled now.
1535 mService.enableScreenIfNeededLocked();
1536 }
1537 }
1538 }
1539
1540 void setRequestedSize(int requestedWidth, int requestedHeight) {
1541 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
1542 mLayoutNeeded = true;
1543 mRequestedWidth = requestedWidth;
1544 mRequestedHeight = requestedHeight;
1545 }
1546 }
1547
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001548 void prepareWindowToDisplayDuringRelayout(Configuration outConfig) {
1549 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
1550 == SOFT_INPUT_ADJUST_RESIZE) {
1551 mLayoutNeeded = true;
1552 }
1553 if (isDrawnLw() && mService.okToDisplay()) {
1554 mWinAnimator.applyEnterAnimationLocked();
1555 }
1556 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
1557 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
1558 mTurnOnScreen = true;
1559 }
1560 if (isConfigChanged()) {
1561 if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + this + " visible with new config: "
1562 + mService.mCurConfiguration);
1563 outConfig.setTo(mService.mCurConfiguration);
1564 }
1565 }
1566
1567 void adjustStartingWindowFlags() {
1568 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
1569 && mAppToken.startingWindow != null) {
1570 // Special handling of starting window over the base
1571 // window of the app: propagate lock screen flags to it,
1572 // to provide the correct semantics while starting.
1573 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
1574 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
1575 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
1576 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
1577 }
1578 }
1579
1580 void setWindowScale(int requestedWidth, int requestedHeight) {
1581 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
1582
1583 if (scaledWindow) {
1584 // requested{Width|Height} Surface's physical size
1585 // attrs.{width|height} Size on screen
1586 // TODO: We don't check if attrs != null here. Is it implicitly checked?
1587 mHScale = (mAttrs.width != requestedWidth) ?
1588 (mAttrs.width / (float)requestedWidth) : 1.0f;
1589 mVScale = (mAttrs.height != requestedHeight) ?
1590 (mAttrs.height / (float)requestedHeight) : 1.0f;
1591 } else {
1592 mHScale = mVScale = 1;
1593 }
1594 }
1595
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001596 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08001597 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001598 public void binderDied() {
1599 try {
1600 synchronized(mService.mWindowMap) {
1601 WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07001602 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001603 if (win != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001604 if (win.mAppToken != null && !win.mAppToken.clientHidden) {
1605 win.mAppToken.appDied = true;
1606 }
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001607 mService.removeWindowLocked(win);
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001608 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08001609 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001610 mService.removeWindowLocked(WindowState.this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001611 }
1612 }
1613 } catch (IllegalArgumentException ex) {
1614 // This will happen if the window has already been
1615 // removed.
1616 }
1617 }
1618 }
1619
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08001620 /**
1621 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
1622 * because we want to preserve its location on screen to be re-activated later when the user
1623 * interacts with it.
1624 */
1625 boolean shouldKeepVisibleDeadAppWindow() {
1626 if (!isWinVisibleLw() || mAppToken == null || !mAppToken.appDied) {
1627 // Not a visible app window or the app isn't dead.
1628 return false;
1629 }
1630
1631 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1632 // We don't keep starting windows since they were added by the window manager before
1633 // the app even launched.
1634 return false;
1635 }
1636
1637 final TaskStack stack = getStack();
1638 return stack != null && StackId.keepVisibleDeadAppWindowOnScreen(stack.mStackId);
1639 }
1640
Wale Ogunwaled045c822015-12-02 09:14:28 -08001641 /** @return true if this window desires key events. */
1642 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08001643 return isVisibleOrAdding()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001644 && (mViewVisibility == View.VISIBLE)
Wale Ogunwaled045c822015-12-02 09:14:28 -08001645 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Wale Ogunwale6cae7652015-12-26 07:36:26 -08001646 && (mAppToken == null || mAppToken.windowsAreFocusable());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001647 }
1648
Craig Mautner749a7bb2012-04-02 13:49:53 -07001649 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001650 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001651 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001652 }
1653
Craig Mautner749a7bb2012-04-02 13:49:53 -07001654 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001655 public boolean showLw(boolean doAnimation) {
1656 return showLw(doAnimation, true);
1657 }
1658
1659 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07001660 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001661 return false;
1662 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001663 if (!mAppOpVisibility) {
1664 // Being hidden due to app op request.
1665 return false;
1666 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001667 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001668 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001669 return false;
1670 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001671 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001672 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001673 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07001674 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07001675 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001676 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07001677 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001678 // Check for the case where we are currently visible and
1679 // not animating; we do not want to do animation at such a
1680 // point to become visible when we already are.
1681 doAnimation = false;
1682 }
1683 }
1684 mPolicyVisibility = true;
1685 mPolicyVisibilityAfterAnim = true;
1686 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001687 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001688 }
1689 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001690 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001691 }
1692 return true;
1693 }
1694
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001695 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001696 public boolean hideLw(boolean doAnimation) {
1697 return hideLw(doAnimation, true);
1698 }
1699
1700 boolean hideLw(boolean doAnimation, boolean requestAnim) {
1701 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07001702 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001703 doAnimation = false;
1704 }
1705 }
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001706 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
1707 : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001708 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001709 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001710 return false;
1711 }
1712 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001713 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07001714 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001715 doAnimation = false;
1716 }
1717 }
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001718 if (doAnimation) {
1719 mPolicyVisibilityAfterAnim = false;
1720 } else {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001721 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001722 mPolicyVisibilityAfterAnim = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001723 mPolicyVisibility = false;
1724 // Window is no longer visible -- make sure if we were waiting
1725 // for it to be displayed before enabling the display, that
1726 // we allow the display to be enabled now.
1727 mService.enableScreenIfNeededLocked();
1728 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001729 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07001730 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001731 mService.mFocusMayChange = true;
1732 }
1733 }
1734 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001735 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001736 }
1737 return true;
1738 }
1739
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001740 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001741 if (mAppOpVisibility != state) {
1742 mAppOpVisibility = state;
1743 if (state) {
1744 // If the policy visibility had last been to hide, then this
1745 // will incorrectly show at this point since we lost that
1746 // information. Not a big deal -- for the windows that have app
1747 // ops modifies they should only be hidden by policy due to the
1748 // lock screen, and the user won't be changing this if locked.
1749 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001750 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001751 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001752 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001753 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001754 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001755 }
1756
Jeff Brownc2932a12014-11-20 18:04:05 -08001757 public void pokeDrawLockLw(long timeout) {
1758 if (isVisibleOrAdding()) {
1759 if (mDrawLock == null) {
1760 // We want the tag name to be somewhat stable so that it is easier to correlate
1761 // in wake lock statistics. So in particular, we don't want to include the
1762 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001763 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08001764 mDrawLock = mService.mPowerManager.newWakeLock(
1765 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
1766 mDrawLock.setReferenceCounted(false);
1767 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
1768 }
1769 // Each call to acquire resets the timeout.
1770 if (DEBUG_POWER) {
1771 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
1772 + mAttrs.packageName);
1773 }
1774 mDrawLock.acquire(timeout);
1775 } else if (DEBUG_POWER) {
1776 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
1777 + "owned by " + mAttrs.packageName);
1778 }
1779 }
1780
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001781 @Override
1782 public boolean isAlive() {
1783 return mClient.asBinder().isBinderAlive();
1784 }
1785
Craig Mautnera987d432012-10-11 14:07:58 -07001786 boolean isClosing() {
1787 return mExiting || (mService.mClosingApps.contains(mAppToken));
1788 }
1789
Chong Zhangbef461f2015-10-27 11:38:24 -07001790 boolean isAnimatingWithSavedSurface() {
1791 return mAppToken != null && mAppToken.mAnimatingWithSavedSurface;
1792 }
1793
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001794 private boolean shouldSaveSurface() {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001795 if (ActivityManager.isLowRamDeviceStatic()) {
1796 // Don't save surfaces on Svelte devices.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001797 return false;
1798 }
1799
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001800 Task task = getTask();
1801 if (task == null || task.inHomeStack()) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001802 // Don't save surfaces for home stack apps. These usually resume and draw
1803 // first frame very fast. Saving surfaces are mostly a waste of memory.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001804 return false;
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001805 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001806
1807 final AppWindowToken taskTop = task.getTopVisibleAppToken();
1808 if (taskTop != null && taskTop != mAppToken) {
1809 // Don't save if the window is not the topmost window.
1810 return false;
1811 }
1812
Robert Carr7098dbd2016-02-01 12:31:01 -08001813 if (DEBUG_DISABLE_SAVING_SURFACES) {
1814 return false;
1815 }
1816
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001817 return mAppToken.shouldSaveSurface();
1818 }
1819
1820 void destroyOrSaveSurface() {
1821 mSurfaceSaved = shouldSaveSurface();
1822 if (mSurfaceSaved) {
1823 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1824 Slog.v(TAG, "Saving surface: " + this);
1825 }
1826
1827 mWinAnimator.hide("saved surface");
1828 mWinAnimator.mDrawState = WindowStateAnimator.NO_SURFACE;
1829 setHasSurface(false);
1830 } else {
Robert Carr13f7be9e2015-12-02 18:39:45 -08001831 mWinAnimator.destroySurfaceLocked();
1832 }
Robert Carr13f7be9e2015-12-02 18:39:45 -08001833 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001834
Robert Carr13f7be9e2015-12-02 18:39:45 -08001835 public void destroySavedSurface() {
Robert Carr13f7be9e2015-12-02 18:39:45 -08001836 if (mSurfaceSaved) {
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001837 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1838 Slog.v(TAG, "Destroying saved surface: " + this);
1839 }
Robert Carr13f7be9e2015-12-02 18:39:45 -08001840 mWinAnimator.destroySurfaceLocked();
1841 }
1842 }
1843
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001844 public void restoreSavedSurface() {
1845 mSurfaceSaved = false;
1846 setHasSurface(true);
1847 mWinAnimator.mDrawState = WindowStateAnimator.READY_TO_SHOW;
1848 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1849 Slog.v(TAG, "Restoring saved surface: " + this);
1850 }
1851 }
1852
Robert Carr13f7be9e2015-12-02 18:39:45 -08001853 public boolean hasSavedSurface() {
1854 return mSurfaceSaved;
1855 }
1856
Craig Mautner69b08182012-09-05 13:07:13 -07001857 @Override
1858 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001859 final DisplayContent displayContent = getDisplayContent();
1860 if (displayContent == null) {
1861 // Only a window that was on a non-default display can be detached from it.
1862 return false;
1863 }
Winson Chung47a3e652014-05-21 16:03:42 -07001864 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07001865 }
1866
Adrian Rooscd3884d2015-02-18 17:25:23 +01001867 @Override
1868 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001869 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1870 return dimLayerUser != null && mDisplayContent != null &&
Chong Zhang112eb8c2015-11-02 11:17:00 -08001871 mDisplayContent.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01001872 }
1873
Craig Mautner88400d32012-09-30 12:35:45 -07001874 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
1875 mShowToOwnerOnly = showToOwnerOnly;
1876 }
1877
Craig Mautner5962b122012-10-05 14:45:52 -07001878 boolean isHiddenFromUserLocked() {
Craig Mautner341220f2012-10-16 15:20:09 -07001879 // Attached windows are evaluated based on the window that they are attached to.
1880 WindowState win = this;
Robert Carr51a1b872015-12-08 14:03:13 -08001881 while (win.isChildWindow()) {
Craig Mautner341220f2012-10-16 15:20:09 -07001882 win = win.mAttachedWindow;
1883 }
1884 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -07001885 && win.mAppToken != null && win.mAppToken.showForAllUsers) {
Craig Mautner341220f2012-10-16 15:20:09 -07001886 // Save some cycles by not calling getDisplayInfo unless it is an application
1887 // window intended for all users.
Craig Mautnerdf88d732014-01-27 09:21:32 -08001888 final DisplayContent displayContent = win.getDisplayContent();
1889 if (displayContent == null) {
1890 return true;
1891 }
1892 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Craig Mautner341220f2012-10-16 15:20:09 -07001893 if (win.mFrame.left <= 0 && win.mFrame.top <= 0
1894 && win.mFrame.right >= displayInfo.appWidth
1895 && win.mFrame.bottom >= displayInfo.appHeight) {
Craig Mautner5962b122012-10-05 14:45:52 -07001896 // Is a fullscreen window, like the clock alarm. Show to everyone.
1897 return false;
1898 }
1899 }
1900
Craig Mautner341220f2012-10-16 15:20:09 -07001901 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01001902 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001903 }
1904
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001905 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
1906 outRegion.set(
1907 frame.left + inset.left, frame.top + inset.top,
1908 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001909 }
1910
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001911 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001912 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001913 switch (mTouchableInsets) {
1914 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001915 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001916 outRegion.set(frame);
1917 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001918 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001919 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001920 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001921 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001922 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001923 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001924 case TOUCHABLE_INSETS_REGION: {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001925 final Region givenTouchableRegion = mGivenTouchableRegion;
1926 outRegion.set(givenTouchableRegion);
1927 outRegion.translate(frame.left, frame.top);
1928 break;
1929 }
1930 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001931 cropRegionToStackBoundsIfNeeded(outRegion);
1932 }
1933
1934 void cropRegionToStackBoundsIfNeeded(Region region) {
1935 if (mAppToken == null || !mAppToken.mCropWindowsToStack) {
1936 return;
1937 }
1938
1939 final TaskStack stack = getStack();
1940 if (stack == null) {
1941 return;
1942 }
1943
1944 stack.getDimBounds(mTmpRect);
1945 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001946 }
1947
Craig Mautner59c00972012-07-30 12:10:24 -07001948 WindowList getWindowList() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001949 final DisplayContent displayContent = getDisplayContent();
1950 return displayContent == null ? null : displayContent.getWindowList();
Craig Mautner59c00972012-07-30 12:10:24 -07001951 }
1952
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001953 /**
1954 * Report a focus change. Must be called with no locks held, and consistently
1955 * from the same serialized thread (such as dispatched from a handler).
1956 */
1957 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
1958 try {
1959 mClient.windowFocusChanged(focused, inTouchMode);
1960 } catch (RemoteException e) {
1961 }
1962 if (mFocusCallbacks != null) {
1963 final int N = mFocusCallbacks.beginBroadcast();
1964 for (int i=0; i<N; i++) {
1965 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
1966 try {
1967 if (focused) {
1968 obs.focusGained(mWindowId.asBinder());
1969 } else {
1970 obs.focusLost(mWindowId.asBinder());
1971 }
1972 } catch (RemoteException e) {
1973 }
1974 }
1975 mFocusCallbacks.finishBroadcast();
1976 }
1977 }
1978
Craig Mautnerdf88d732014-01-27 09:21:32 -08001979 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001980 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08001981 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001982 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
1983 + ": " + mCompatFrame);
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001984 final boolean configChanged = isConfigChanged();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001985 final Task task = getTask();
Wale Ogunwale60454db2015-01-23 16:05:07 -08001986 final Configuration overrideConfig =
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001987 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001988 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) && configChanged) {
1989 Slog.i(TAG, "Sending new config to window " + this + ": "
Robert Carre6a83512015-11-03 16:09:21 -08001990 + " / config="
Wale Ogunwale60454db2015-01-23 16:05:07 -08001991 + mService.mCurConfiguration + " overrideConfig=" + overrideConfig);
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001992 }
Wale Ogunwale60454db2015-01-23 16:05:07 -08001993 setConfiguration(mService.mCurConfiguration, overrideConfig);
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001994 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING)
1995 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
1996
Craig Mautnerdf88d732014-01-27 09:21:32 -08001997 final Rect frame = mFrame;
1998 final Rect overscanInsets = mLastOverscanInsets;
1999 final Rect contentInsets = mLastContentInsets;
2000 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07002001 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002002 final Rect outsets = mLastOutsets;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002003 final boolean reportDraw = mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING;
2004 final Configuration newConfig = configChanged ? mConfiguration : null;
Chet Haase8eb48d22014-09-24 07:31:29 -07002005 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
2006 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002007 // To prevent deadlock simulate one-way call if win.mClient is a local object.
2008 mService.mH.post(new Runnable() {
2009 @Override
2010 public void run() {
2011 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002012 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
2013 stableInsets, outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002014 } catch (RemoteException e) {
2015 // Not a remote call, RemoteException won't be raised.
2016 }
2017 }
2018 });
2019 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002020 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002021 outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002022 }
Svetoslav4604abc2014-06-10 18:59:30 -07002023
2024 //TODO (multidisplay): Accessibility supported only for the default display.
2025 if (mService.mAccessibilityController != null
2026 && getDisplayId() == Display.DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07002027 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07002028 }
2029
Craig Mautnerdf88d732014-01-27 09:21:32 -08002030 mOverscanInsetsChanged = false;
2031 mContentInsetsChanged = false;
2032 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07002033 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002034 mOutsetsChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08002035 mWinAnimator.mSurfaceResized = false;
2036 } catch (RemoteException e) {
2037 mOrientationChanging = false;
2038 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2039 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08002040 // We are assuming the hosting process is dead or in a zombie state.
2041 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
2042 + ", removing this window.");
2043 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002044 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002045 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002046 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002047 }
2048
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002049 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08002050 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
2051 // start even if we haven't received the relayout window, so that the client requests
2052 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
2053 // until the window to small size, otherwise the multithread renderer will shift last
2054 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
2055 // isDragResizing() or isDragResizeChanged() is true.
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002056 DisplayInfo displayInfo = getDisplayInfo();
2057 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Chong Zhangd153c4f2015-11-06 20:26:40 -08002058 boolean resizing = isDragResizing() || isDragResizeChanged();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002059 return (inFreeformWorkspace() || !resizing) ? frame : mTmpRect;
2060 }
2061
2062 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
2063 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
2064 Configuration newConfig) throws RemoteException {
Jorim Jaggidc249c42015-12-15 14:57:31 -08002065 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Jorim Jaggia4a58ef2016-01-27 02:10:08 -08002066 reportDraw, newConfig, getBackdropFrame(frame),
2067 isDragResizeChanged() /* forceRelayout */);
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002068 }
2069
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002070 public void registerFocusObserver(IWindowFocusObserver observer) {
2071 synchronized(mService.mWindowMap) {
2072 if (mFocusCallbacks == null) {
2073 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
2074 }
2075 mFocusCallbacks.register(observer);
2076 }
2077 }
2078
2079 public void unregisterFocusObserver(IWindowFocusObserver observer) {
2080 synchronized(mService.mWindowMap) {
2081 if (mFocusCallbacks != null) {
2082 mFocusCallbacks.unregister(observer);
2083 }
2084 }
2085 }
2086
2087 public boolean isFocused() {
2088 synchronized(mService.mWindowMap) {
2089 return mService.mCurrentFocus == this;
2090 }
2091 }
2092
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07002093 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07002094 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07002095 return task != null && task.inFreeformWorkspace();
2096 }
2097
Chong Zhang3005e752015-09-18 18:46:28 -07002098 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002099 return mDragResizing != computeDragResizing();
2100 }
2101
Jorim Jaggidcf467c2015-11-05 13:59:32 +01002102 int getResizeMode() {
2103 return mResizeMode;
2104 }
2105
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002106 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07002107 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002108 if (task == null) {
2109 return false;
2110 }
2111 if (task.isDragResizing()) {
2112 return true;
2113 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01002114
2115 // If the bounds are currently frozen, it means that the layout size that the app sees
2116 // and the bounds we clip this window to might be different. In order to avoid holes, we
2117 // simulate that we are still resizing so the app fills the hole with the resizing
2118 // background.
2119 return (mDisplayContent.mDividerControllerLocked.isResizing()
2120 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002121 !task.inFreeformWorkspace() && !task.isFullscreen();
Chong Zhang3005e752015-09-18 18:46:28 -07002122 }
2123
2124 void setDragResizing() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002125 mDragResizing = computeDragResizing();
Jorim Jaggidcf467c2015-11-05 13:59:32 +01002126 mResizeMode = mDragResizing && mDisplayContent.mDividerControllerLocked.isResizing()
2127 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
2128 : DRAG_RESIZE_MODE_FREEFORM;
Chong Zhang3005e752015-09-18 18:46:28 -07002129 }
2130
2131 boolean isDragResizing() {
2132 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07002133 }
2134
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002135 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08002136 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002137 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08002138 if (stack != null) {
2139 pw.print(" stackId="); pw.print(stack.mStackId);
2140 }
Craig Mautner59c00972012-07-30 12:10:24 -07002141 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002142 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07002143 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08002144 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
2145 pw.print(" package="); pw.print(mAttrs.packageName);
2146 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002147 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002148 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
2149 pw.print(" h="); pw.print(mRequestedHeight);
2150 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07002151 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
2152 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
2153 pw.print(" h="); pw.println(mLastRequestedHeight);
2154 }
Robert Carr51a1b872015-12-08 14:03:13 -08002155 if (isChildWindow() || mLayoutAttached) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002156 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
2157 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
2158 }
2159 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
2160 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
2161 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
2162 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
2163 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
2164 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002165 if (dumpAll) {
2166 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
2167 pw.print(" mSubLayer="); pw.print(mSubLayer);
2168 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautner59431632012-04-04 11:56:44 -07002169 pw.print((mTargetAppToken != null ?
2170 mTargetAppToken.mAppAnimator.animLayerAdjustment
2171 : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002172 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
2173 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08002174 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002175 if (dumpAll) {
2176 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
2177 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
2178 if (mAppToken != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08002179 pw.print(prefix); pw.print("mAppToken="); pw.print(mAppToken);
2180 pw.print(" mAppDied=");pw.println(mAppDied);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002181 }
2182 if (mTargetAppToken != null) {
2183 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
2184 }
2185 pw.print(prefix); pw.print("mViewVisibility=0x");
2186 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002187 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
2188 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07002189 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
2190 pw.print(" mSystemUiVisibility=0x");
2191 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002192 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002193 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
2194 || mAttachedHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002195 pw.print(prefix); pw.print("mPolicyVisibility=");
2196 pw.print(mPolicyVisibility);
2197 pw.print(" mPolicyVisibilityAfterAnim=");
2198 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002199 pw.print(" mAppOpVisibility=");
2200 pw.print(mAppOpVisibility);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002201 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
2202 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08002203 if (!mRelayoutCalled || mLayoutNeeded) {
2204 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
2205 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002206 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002207 if (mXOffset != 0 || mYOffset != 0) {
2208 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
2209 pw.print(" y="); pw.println(mYOffset);
2210 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002211 if (dumpAll) {
2212 pw.print(prefix); pw.print("mGivenContentInsets=");
2213 mGivenContentInsets.printShortString(pw);
2214 pw.print(" mGivenVisibleInsets=");
2215 mGivenVisibleInsets.printShortString(pw);
2216 pw.println();
2217 if (mTouchableInsets != 0 || mGivenInsetsPending) {
2218 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
2219 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07002220 Region region = new Region();
2221 getTouchableRegion(region);
2222 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002223 }
2224 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Wale Ogunwale7c726682015-02-06 17:34:28 -08002225 if (mOverrideConfig != Configuration.EMPTY) {
2226 pw.print(prefix); pw.print("mOverrideConfig="); pw.println(mOverrideConfig);
2227 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002228 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07002229 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07002230 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Craig Mautner178af592012-09-17 10:37:29 -07002231 pw.print(" isReadyForDisplay()="); pw.println(isReadyForDisplay());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002232 if (dumpAll) {
2233 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
2234 pw.print(" last="); mLastFrame.printShortString(pw);
2235 pw.println();
2236 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002237 if (mEnforceSizeCompat) {
2238 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002239 pw.println();
2240 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002241 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002242 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002243 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002244 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002245 pw.println();
2246 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
2247 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002248 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002249 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002250 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002251 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04002252 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
2253 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002254 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
2255 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002256 pw.print(prefix); pw.print("Cur insets: overscan=");
2257 mOverscanInsets.printShortString(pw);
2258 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002259 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002260 pw.print(" stable="); mStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002261 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002262 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002263 pw.print(prefix); pw.print("Lst insets: overscan=");
2264 mLastOverscanInsets.printShortString(pw);
2265 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002266 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002267 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002268 pw.print(" physical="); mLastOutsets.printShortString(pw);
2269 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002270 pw.println();
2271 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07002272 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
2273 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002274 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
2275 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
2276 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
2277 pw.print(" mDestroying="); pw.print(mDestroying);
2278 pw.print(" mRemoved="); pw.println(mRemoved);
2279 }
2280 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
2281 pw.print(prefix); pw.print("mOrientationChanging=");
2282 pw.print(mOrientationChanging);
2283 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
2284 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
2285 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07002286 if (mLastFreezeDuration != 0) {
2287 pw.print(prefix); pw.print("mLastFreezeDuration=");
2288 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
2289 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002290 if (mHScale != 1 || mVScale != 1) {
2291 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
2292 pw.print(" mVScale="); pw.println(mVScale);
2293 }
2294 if (mWallpaperX != -1 || mWallpaperY != -1) {
2295 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
2296 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
2297 }
2298 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
2299 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
2300 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
2301 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07002302 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
2303 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
2304 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
2305 pw.print(mWallpaperDisplayOffsetX);
2306 pw.print(" mWallpaperDisplayOffsetY=");
2307 pw.println(mWallpaperDisplayOffsetY);
2308 }
Jeff Brownc2932a12014-11-20 18:04:05 -08002309 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07002310 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08002311 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002312 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002313
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002314 String makeInputChannelName() {
2315 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002316 + " " + getWindowTag();
2317 }
2318
Robert Carra1eb4392015-12-10 12:43:51 -08002319 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002320 CharSequence tag = mAttrs.getTitle();
2321 if (tag == null || tag.length() <= 0) {
2322 tag = mAttrs.packageName;
2323 }
2324 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002325 }
2326
2327 @Override
2328 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002329 final CharSequence title = getWindowTag();
Dianne Hackbornc2293022013-02-06 23:14:49 -08002330 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mExiting) {
2331 mLastTitle = title;
Dianne Hackborn529e7442012-11-01 14:22:28 -07002332 mWasExiting = mExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002333 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -07002334 + " u" + UserHandle.getUserId(mSession.mUid)
Craig Mautnera987d432012-10-11 14:07:58 -07002335 + " " + mLastTitle + (mExiting ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002336 }
2337 return mStringNameCache;
2338 }
Robert Carr58f29132015-10-29 14:19:05 -07002339
2340 void transformFromScreenToSurfaceSpace(Rect rect) {
2341 if (mHScale >= 0) {
Chong Zhang84389572016-01-13 10:33:27 -08002342 rect.left = (int) (rect.left / mHScale);
2343 rect.right = (int) (rect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07002344 }
2345 if (mVScale >= 0) {
Chong Zhang84389572016-01-13 10:33:27 -08002346 rect.top = (int) (rect.top / mVScale);
2347 rect.bottom = (int) (rect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07002348 }
2349 }
Robert Carr31e28482015-12-02 16:53:18 -08002350
2351 void applyGravityAndUpdateFrame() {
2352 final int pw = mContainingFrame.width();
2353 final int ph = mContainingFrame.height();
2354 final Task task = getTask();
2355 final boolean nonFullscreenTask = task != null && !task.isFullscreen();
2356
2357 float x, y;
2358 int w,h;
2359
2360 if ((mAttrs.flags & FLAG_SCALED) != 0) {
2361 if (mAttrs.width < 0) {
2362 w = pw;
2363 } else if (mEnforceSizeCompat) {
2364 w = (int)(mAttrs.width * mGlobalScale + .5f);
2365 } else {
2366 w = mAttrs.width;
2367 }
2368 if (mAttrs.height < 0) {
2369 h = ph;
2370 } else if (mEnforceSizeCompat) {
2371 h = (int)(mAttrs.height * mGlobalScale + .5f);
2372 } else {
2373 h = mAttrs.height;
2374 }
2375 } else {
2376 if (mAttrs.width == MATCH_PARENT) {
2377 w = pw;
2378 } else if (mEnforceSizeCompat) {
2379 w = (int)(mRequestedWidth * mGlobalScale + .5f);
2380 } else {
2381 w = mRequestedWidth;
2382 }
2383 if (mAttrs.height == MATCH_PARENT) {
2384 h = ph;
2385 } else if (mEnforceSizeCompat) {
2386 h = (int)(mRequestedHeight * mGlobalScale + .5f);
2387 } else {
2388 h = mRequestedHeight;
2389 }
2390 }
2391
2392 if (mEnforceSizeCompat) {
2393 x = mAttrs.x * mGlobalScale;
2394 y = mAttrs.y * mGlobalScale;
2395 } else {
2396 x = mAttrs.x;
2397 y = mAttrs.y;
2398 }
2399
2400 if (nonFullscreenTask) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08002401 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08002402 // required by {@link Gravity#apply} call.
2403 w = Math.min(w, pw);
2404 h = Math.min(h, ph);
2405 }
2406
2407 // Set mFrame
2408 Gravity.apply(mAttrs.gravity, w, h, mContainingFrame,
2409 (int) (x + mAttrs.horizontalMargin * pw),
2410 (int) (y + mAttrs.verticalMargin * ph), mFrame);
2411
2412 // Now make sure the window fits in the overall display frame.
2413 Gravity.applyDisplay(mAttrs.gravity, mDisplayFrame, mFrame);
2414 }
Robert Carr51a1b872015-12-08 14:03:13 -08002415
2416 boolean isChildWindow() {
2417 return mAttachedWindow != null;
2418 }
Robert Carra1eb4392015-12-10 12:43:51 -08002419
2420 void setReplacing(boolean animate) {
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08002421 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
2422 || mAttrs.type == TYPE_APPLICATION_STARTING) {
2423 // We don't set replacing on starting windows since they are added by window manager and
2424 // not the client so won't be replaced by the client.
2425 return;
Robert Carra1eb4392015-12-10 12:43:51 -08002426 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08002427
2428 mWillReplaceWindow = true;
2429 mReplacingWindow = null;
2430 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08002431 }
Chong Zhangf596cd52016-01-05 13:42:44 -08002432
2433 void resetReplacing() {
2434 mWillReplaceWindow = false;
2435 mReplacingWindow = null;
2436 mAnimateReplacingWindow = false;
2437 }
satokcef37fb2011-10-24 21:49:38 +09002438}