blob: 2b845006400684f75eafb1f71ee7f6c3dcf596bb [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 Ogunwalecad05a02015-09-25 10:41:44 -070019import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080020import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080021import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070022import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080023import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
24import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070025import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080026import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080027import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
28import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080029import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080030import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
31import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080032import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080033import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070034import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080035import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
36import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
37import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Filip Gruszczynskib6e66622015-10-25 16:05:27 -070038import static com.android.server.wm.WindowManagerService.DEBUG_ADD_REMOVE;
Chong Zhangbef461f2015-10-27 11:38:24 -070039import static com.android.server.wm.WindowManagerService.DEBUG_ANIM;
40import static com.android.server.wm.WindowManagerService.DEBUG_APP_TRANSITIONS;
Craig Mautnerd1c2c542014-02-06 10:31:41 -080041import static com.android.server.wm.WindowManagerService.DEBUG_CONFIGURATION;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -080042import static com.android.server.wm.WindowManagerService.DEBUG_FOCUS_LIGHT;
Craig Mautnerb3b36ba2013-05-20 13:21:10 -070043import static com.android.server.wm.WindowManagerService.DEBUG_LAYOUT;
Craig Mautnerd1c2c542014-02-06 10:31:41 -080044import static com.android.server.wm.WindowManagerService.DEBUG_ORIENTATION;
Jeff Brownc2932a12014-11-20 18:04:05 -080045import static com.android.server.wm.WindowManagerService.DEBUG_POWER;
Craig Mautnerd1c2c542014-02-06 10:31:41 -080046import static com.android.server.wm.WindowManagerService.DEBUG_RESIZE;
47import static com.android.server.wm.WindowManagerService.DEBUG_VISIBILITY;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080048
Chong Zhangdb20b5f2015-10-23 14:01:43 -070049import android.app.ActivityManager;
Dianne Hackbornc2293022013-02-06 23:14:49 -080050import android.app.AppOpsManager;
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -070051import android.graphics.Point;
Jeff Brownc2932a12014-11-20 18:04:05 -080052import android.os.PowerManager;
Dianne Hackborne3f23a32013-03-01 13:25:35 -080053import android.os.RemoteCallbackList;
Craig Mautnerdf88d732014-01-27 09:21:32 -080054import android.os.SystemClock;
Wale Ogunwalecad05a02015-09-25 10:41:44 -070055import android.os.Trace;
Jeff Brownc2932a12014-11-20 18:04:05 -080056import android.os.WorkSource;
Skuhne81c524a2015-08-12 13:34:14 -070057import android.util.DisplayMetrics;
Dianne Hackborna57c6952013-03-29 14:46:40 -070058import android.util.TimeUtils;
Svetoslav4604abc2014-06-10 18:59:30 -070059import android.view.Display;
Dianne Hackborne3f23a32013-03-01 13:25:35 -080060import android.view.IWindowFocusObserver;
61import android.view.IWindowId;
Jeff Brownc2932a12014-11-20 18:04:05 -080062
Jeff Brown4532e612012-04-05 14:27:12 -070063import com.android.server.input.InputWindowHandle;
64
Craig Mautnere7ae2502012-03-26 17:11:19 -070065import android.content.Context;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080066import android.content.res.Configuration;
67import android.graphics.Matrix;
68import android.graphics.PixelFormat;
69import android.graphics.Rect;
70import android.graphics.Region;
71import android.os.IBinder;
72import android.os.RemoteException;
Craig Mautner9dc52bc2012-08-06 14:15:42 -070073import android.os.UserHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080074import android.util.Slog;
Craig Mautner59c00972012-07-30 12:10:24 -070075import android.view.DisplayInfo;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080076import android.view.Gravity;
77import android.view.IApplicationToken;
78import android.view.IWindow;
79import android.view.InputChannel;
Chong Zhangacf11402015-11-04 16:23:10 -080080import android.view.InputEvent;
81import android.view.InputEventReceiver;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080082import android.view.View;
83import android.view.ViewTreeObserver;
84import android.view.WindowManager;
85import android.view.WindowManagerPolicy;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080086
87import java.io.PrintWriter;
88import java.util.ArrayList;
89
Craig Mautner59c00972012-07-30 12:10:24 -070090class WindowList extends ArrayList<WindowState> {
91}
92
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080093/**
94 * A window in the window manager.
95 */
Craig Mautnere32c3072012-03-12 15:25:35 -070096final class WindowState implements WindowManagerPolicy.WindowState {
Craig Mautnerd87946b2012-03-29 18:00:19 -070097 static final String TAG = "WindowState";
Craig Mautner164d4bb2012-11-26 13:51:23 -080098
Skuhne81c524a2015-08-12 13:34:14 -070099 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700100 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
101 // use hard-coded min sizes for now.
102 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
103 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700104
105 // The thickness of a window resize handle outside the window bounds on the free form workspace
106 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700107 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700108
109 static final boolean BOUNDS_FOR_TOUCH = true;
Skuhne81c524a2015-08-12 13:34:14 -0700110
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800111 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700112 final WindowManagerPolicy mPolicy;
113 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800114 final Session mSession;
115 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800116 final int mAppOp;
117 // UserId and appId of the owner. Don't display windows of non-current user.
118 final int mOwnerUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800119 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800120 WindowToken mToken;
121 WindowToken mRootToken;
122 AppWindowToken mAppToken;
123 AppWindowToken mTargetAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700124
125 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
126 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800127 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
128 final DeathRecipient mDeathRecipient;
129 final WindowState mAttachedWindow;
Craig Mautner7b1aa772012-11-30 16:14:45 -0800130 final WindowList mChildWindows = new WindowList();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800131 final int mBaseLayer;
132 final int mSubLayer;
133 final boolean mLayoutAttached;
134 final boolean mIsImWindow;
135 final boolean mIsWallpaper;
136 final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700137 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700138 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800139 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700140 int mSystemUiVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800141 boolean mPolicyVisibility = true;
142 boolean mPolicyVisibilityAfterAnim = true;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -0800143 boolean mAppOpVisibility = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800144 boolean mAppFreezing;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800145 boolean mAttachedHidden; // is our parent window hidden?
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800146 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Chong Zhang0275e392015-09-17 10:41:44 -0700147 boolean mDragResizing;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700148
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800149 RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
150
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700151 /**
152 * The window size that was requested by the application. These are in
153 * the application's coordinate space (without compatibility scale applied).
154 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800155 int mRequestedWidth;
156 int mRequestedHeight;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700157 int mLastRequestedWidth;
158 int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700159
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800160 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800161 boolean mHaveFrame;
162 boolean mObscured;
163 boolean mTurnOnScreen;
164
165 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700166
Wale Ogunwale60454db2015-01-23 16:05:07 -0800167 private Configuration mConfiguration = Configuration.EMPTY;
168 private Configuration mOverrideConfig = Configuration.EMPTY;
Craig Mautnere8552142012-11-07 13:55:47 -0800169 // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned.
170 // Used only on {@link #TYPE_KEYGUARD}.
171 private boolean mConfigHasChanged;
Craig Mautnera2c77052012-03-26 12:14:43 -0700172
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700173 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700174 * Actual position of the surface shown on-screen (may be modified by animation). These are
175 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700176 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700177 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800178
179 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700180 * Insets that determine the actually visible area. These are in the application's
181 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800182 */
183 final Rect mVisibleInsets = new Rect();
184 final Rect mLastVisibleInsets = new Rect();
185 boolean mVisibleInsetsChanged;
186
187 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700188 * Insets that are covered by system windows (such as the status bar) and
189 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700190 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800191 */
192 final Rect mContentInsets = new Rect();
193 final Rect mLastContentInsets = new Rect();
194 boolean mContentInsetsChanged;
195
196 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800197 * Insets that determine the area covered by the display overscan region. These are in the
198 * application's coordinate space (without compatibility scale applied).
199 */
200 final Rect mOverscanInsets = new Rect();
201 final Rect mLastOverscanInsets = new Rect();
202 boolean mOverscanInsetsChanged;
203
204 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700205 * Insets that determine the area covered by the stable system windows. These are in the
206 * application's coordinate space (without compatibility scale applied).
207 */
208 final Rect mStableInsets = new Rect();
209 final Rect mLastStableInsets = new Rect();
210 boolean mStableInsetsChanged;
211
212 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700213 * Outsets determine the area outside of the surface where we want to pretend that it's possible
214 * to draw anyway.
215 */
216 final Rect mOutsets = new Rect();
217 final Rect mLastOutsets = new Rect();
218 boolean mOutsetsChanged = false;
219
220 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800221 * Set to true if we are waiting for this window to receive its
222 * given internal insets before laying out other windows based on it.
223 */
224 boolean mGivenInsetsPending;
225
226 /**
227 * These are the content insets that were given during layout for
228 * this window, to be applied to windows behind it.
229 */
230 final Rect mGivenContentInsets = new Rect();
231
232 /**
233 * These are the visible insets that were given during layout for
234 * this window, to be applied to windows behind it.
235 */
236 final Rect mGivenVisibleInsets = new Rect();
237
238 /**
239 * This is the given touchable area relative to the window frame, or null if none.
240 */
241 final Region mGivenTouchableRegion = new Region();
242
243 /**
244 * Flag indicating whether the touchable region should be adjusted by
245 * the visible insets; if false the area outside the visible insets is
246 * NOT touchable, so we must use those to adjust the frame during hit
247 * tests.
248 */
249 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
250
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700251 /**
252 * This is rectangle of the window's surface that is not covered by
253 * system decorations.
254 */
255 final Rect mSystemDecorRect = new Rect();
256 final Rect mLastSystemDecorRect = new Rect();
257
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800258 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400259 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700260 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800261 float mHScale=1, mVScale=1;
262 float mLastHScale=1, mLastVScale=1;
263 final Matrix mTmpMatrix = new Matrix();
264
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700265 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800266 final Rect mFrame = new Rect();
267 final Rect mLastFrame = new Rect();
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700268 // Frame that is scaled to the application's coordinate space when in
269 // screen size compatibility mode.
270 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800271
272 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700273
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800274 final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700275
Wale Ogunwale94596652015-02-06 19:27:34 -0800276 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
277 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700278 final Rect mDisplayFrame = new Rect();
279
280 // The region of the display frame that the display type supports displaying content on. This
281 // is mostly a special case for TV where some displays don’t have the entire display usable.
282 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
283 // window display contents to extend into the overscan region.
284 final Rect mOverscanFrame = new Rect();
285
286 // The display frame minus the stable insets. This value is always constant regardless of if
287 // the status bar or navigation bar is visible.
Adrian Roosfa104232014-06-20 16:10:14 -0700288 final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800289
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700290 // The area not occupied by the status and navigation bars. So, if both status and navigation
291 // bars are visible, the decor frame is equal to the stable frame.
292 final Rect mDecorFrame = new Rect();
293
294 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
295 // minus the area occupied by the IME if the IME is present.
296 final Rect mContentFrame = new Rect();
297
298 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
299 // displays hint text.
300 final Rect mVisibleFrame = new Rect();
301
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700302 // Frame that includes dead area outside of the surface but where we want to pretend that it's
303 // possible to draw.
304 final Rect mOutsetFrame = new Rect();
305
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800306 boolean mContentChanged;
307
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800308 // If a window showing a wallpaper: the requested offset for the
309 // wallpaper; if a wallpaper window: the currently applied offset.
310 float mWallpaperX = -1;
311 float mWallpaperY = -1;
312
313 // If a window showing a wallpaper: what fraction of the offset
314 // range corresponds to a full virtual screen.
315 float mWallpaperXStep = -1;
316 float mWallpaperYStep = -1;
317
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700318 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
319 // to its window; if a wallpaper window: not used.
320 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
321 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
322
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800323 // Wallpaper windows: pixels offset based on above variables.
324 int mXOffset;
325 int mYOffset;
326
Craig Mautner2268e7e2012-12-13 15:40:00 -0800327 /**
328 * This is set after IWindowSession.relayout() has been called at
329 * least once for the window. It allows us to detect the situation
330 * where we don't yet have a surface, but should have one soon, so
331 * we can give the window focus before waiting for the relayout.
332 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800333 boolean mRelayoutCalled;
334
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800335 /**
336 * If the application has called relayout() with changes that can
337 * impact its window's size, we need to perform a layout pass on it
338 * even if it is not currently visible for layout. This is set
339 * when in that case until the layout is done.
340 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800341 boolean mLayoutNeeded;
342
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800343 /** Currently running an exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800344 boolean mExiting;
345
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800346 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800347 boolean mDestroying;
348
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800349 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800350 boolean mRemoveOnExit;
351
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800352 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800353 * Whether the app died while it was visible, if true we might need
354 * to continue to show it until it's restarted.
355 */
356 boolean mAppDied;
357
358 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800359 * Set when the orientation is changing and this window has not yet
360 * been updated for the new orientation.
361 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800362 boolean mOrientationChanging;
363
Dianne Hackborna57c6952013-03-29 14:46:40 -0700364 /**
365 * How long we last kept the screen frozen.
366 */
367 int mLastFreezeDuration;
368
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800369 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800370 boolean mRemoved;
371
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800372 /**
373 * Temp for keeping track of windows that have been removed when
374 * rebuilding window list.
375 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800376 boolean mRebuilding;
377
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800378 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700379 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800380 InputChannel mInputChannel;
Chong Zhang112eb8c2015-11-02 11:17:00 -0800381 InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800382
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800383 // Used to improve performance of toString()
384 String mStringNameCache;
385 CharSequence mLastTitle;
Dianne Hackborn529e7442012-11-01 14:22:28 -0700386 boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800387
Craig Mautnera2c77052012-03-26 12:14:43 -0700388 final WindowStateAnimator mWinAnimator;
389
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700390 boolean mHasSurface = false;
391
Craig Mautner19ab8282014-05-07 10:35:34 -0700392 boolean mNotOnAppsDisplay = false;
Craig Mautner59c00972012-07-30 12:10:24 -0700393 DisplayContent mDisplayContent;
Craig Mautner6881a102012-07-27 13:04:51 -0700394
Craig Mautner88400d32012-09-30 12:35:45 -0700395 /** When true this window can be displayed on screens owther than mOwnerUid's */
396 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700397
Jeff Brownc2932a12014-11-20 18:04:05 -0800398 /**
399 * Wake lock for drawing.
400 * Even though it's slightly more expensive to do so, we will use a separate wake lock
401 * for each app that is requesting to draw while dozing so that we can accurately track
402 * who is preventing the system from suspending.
403 * This lock is only acquired on first use.
404 */
405 PowerManager.WakeLock mDrawLock;
406
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700407 final private Rect mTmpRect = new Rect();
408
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800409 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800410 WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a,
Craig Mautner59c00972012-07-30 12:10:24 -0700411 int viewVisibility, final DisplayContent displayContent) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800412 mService = service;
413 mSession = s;
414 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800415 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800416 mToken = token;
Craig Mautnera2d7b112012-08-21 15:12:20 -0700417 mOwnerUid = s.mUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800418 mWindowId = new IWindowId.Stub() {
419 @Override
420 public void registerFocusObserver(IWindowFocusObserver observer) {
421 WindowState.this.registerFocusObserver(observer);
422 }
423 @Override
424 public void unregisterFocusObserver(IWindowFocusObserver observer) {
425 WindowState.this.unregisterFocusObserver(observer);
426 }
427 @Override
428 public boolean isFocused() {
429 return WindowState.this.isFocused();
430 }
431 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800432 mAttrs.copyFrom(a);
433 mViewVisibility = viewVisibility;
Craig Mautner59c00972012-07-30 12:10:24 -0700434 mDisplayContent = displayContent;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700435 mPolicy = mService.mPolicy;
436 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800437 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700438 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700439 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800440 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700441 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700442 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800443 try {
444 c.asBinder().linkToDeath(deathRecipient, 0);
445 } catch (RemoteException e) {
446 mDeathRecipient = null;
447 mAttachedWindow = null;
448 mLayoutAttached = false;
449 mIsImWindow = false;
450 mIsWallpaper = false;
451 mIsFloatingLayer = false;
452 mBaseLayer = 0;
453 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700454 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700455 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800456 return;
457 }
458 mDeathRecipient = deathRecipient;
459
460 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
461 mAttrs.type <= LAST_SUB_WINDOW)) {
462 // The multiplier here is to reserve space for multiple
463 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700464 mBaseLayer = mPolicy.windowTypeToLayerLw(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800465 attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
466 + WindowManagerService.TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700467 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800468 mAttachedWindow = attachedWindow;
Filip Gruszczynskib6e66622015-10-25 16:05:27 -0700469 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to "
470 + mAttachedWindow);
takeda.masayuki18735092012-12-12 11:06:24 +0900471
tiger_huange2a98a72014-11-13 19:46:28 +0800472 final WindowList childWindows = mAttachedWindow.mChildWindows;
473 final int numChildWindows = childWindows.size();
474 if (numChildWindows == 0) {
475 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900476 } else {
tiger_huange2a98a72014-11-13 19:46:28 +0800477 boolean added = false;
478 for (int i = 0; i < numChildWindows; i++) {
479 final int childSubLayer = childWindows.get(i).mSubLayer;
480 if (mSubLayer < childSubLayer
481 || (mSubLayer == childSubLayer && childSubLayer < 0)) {
482 // We insert the child window into the list ordered by the sub-layer. For
483 // same sub-layers, the negative one should go below others; the positive
484 // one should go above others.
485 childWindows.add(i, this);
486 added = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900487 break;
takeda.masayuki18735092012-12-12 11:06:24 +0900488 }
489 }
tiger_huange2a98a72014-11-13 19:46:28 +0800490 if (!added) {
491 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900492 }
493 }
494
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800495 mLayoutAttached = mAttrs.type !=
496 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
497 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
498 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
499 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
500 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
501 } else {
502 // The multiplier here is to reserve space for multiple
503 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700504 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800505 * WindowManagerService.TYPE_LAYER_MULTIPLIER
506 + WindowManagerService.TYPE_LAYER_OFFSET;
507 mSubLayer = 0;
508 mAttachedWindow = null;
509 mLayoutAttached = false;
510 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
511 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
512 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
513 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
514 }
515
516 WindowState appWin = this;
517 while (appWin.mAttachedWindow != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700518 appWin = appWin.mAttachedWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800519 }
520 WindowToken appToken = appWin.mToken;
521 while (appToken.appWindowToken == null) {
522 WindowToken parent = mService.mTokenMap.get(appToken.token);
523 if (parent == null || appToken == parent) {
524 break;
525 }
526 appToken = parent;
527 }
528 mRootToken = appToken;
529 mAppToken = appToken.appWindowToken;
Craig Mautner19ab8282014-05-07 10:35:34 -0700530 if (mAppToken != null) {
531 final DisplayContent appDisplay = getDisplayContent();
532 mNotOnAppsDisplay = displayContent != appDisplay;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700533
534 if (mAppToken.showForAllUsers) {
535 // Windows for apps that can show for all users should also show when the
536 // device is locked.
537 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
538 }
Craig Mautner19ab8282014-05-07 10:35:34 -0700539 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800540
Craig Mautner322e4032012-07-13 13:35:20 -0700541 mWinAnimator = new WindowStateAnimator(this);
542 mWinAnimator.mAlpha = a.alpha;
543
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800544 mRequestedWidth = 0;
545 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700546 mLastRequestedWidth = 0;
547 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800548 mXOffset = 0;
549 mYOffset = 0;
550 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800551 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700552 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
553 displayContent.getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800554 }
555
556 void attach() {
557 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700558 TAG, "Attaching " + this + " token=" + mToken
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800559 + ", list=" + mToken.windows);
560 mSession.windowAddedLocked();
561 }
562
Craig Mautnera2c77052012-03-26 12:14:43 -0700563 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800564 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800565 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800566 }
567
568 @Override
569 public String getOwningPackage() {
570 return mAttrs.packageName;
571 }
572
573 @Override
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700574 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf, Rect sf,
575 Rect osf) {
Filip Gruszczynskib6e66622015-10-25 16:05:27 -0700576 if (mAppToken != null && mAppToken.mWillReplaceWindow
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700577 && (mExiting || !mAppToken.mReplacingRemoveRequested)) {
578 // This window is being replaced and either already got information that it's being
579 // removed or we are still waiting for some information. Because of this we don't
580 // want to apply any more changes to it, so it remains in this state until new window
581 // appears.
582 return;
583 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800584 mHaveFrame = true;
585
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700586 final Task task = getTask();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700587 final boolean nonFullscreenTask = task != null && !task.isFullscreen();
Chong Zhang09b21ef2015-09-14 10:20:21 -0700588 final boolean freeformWorkspace = task != null && task.inFreeformWorkspace();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700589 if (nonFullscreenTask) {
590 task.getBounds(mContainingFrame);
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800591 final WindowState imeWin = mService.mInputMethodWindow;
592 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this
593 && mContainingFrame.bottom > cf.bottom) {
594 // IME is up and obscuring this window. Adjust the window position so it is visible.
595 mContainingFrame.top -= mContainingFrame.bottom - cf.bottom;
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700596 }
Skuhne81c524a2015-08-12 13:34:14 -0700597
Skuhnef932e562015-08-20 12:07:30 -0700598 if (freeformWorkspace) {
Skuhne81c524a2015-08-12 13:34:14 -0700599 // In free form mode we have only to set the rectangle if it wasn't set already. No
600 // need to intersect it with the (visible) "content frame" since it is allowed to
601 // be outside the visible desktop.
602 if (mContainingFrame.isEmpty()) {
603 mContainingFrame.set(cf);
604 }
Doris Liu06d582d2015-06-01 13:18:43 -0700605 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800606 mDisplayFrame.set(mContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700607 } else {
608 mContainingFrame.set(pf);
Wale Ogunwale94596652015-02-06 19:27:34 -0800609 mDisplayFrame.set(df);
Craig Mautner967212c2013-04-13 21:10:58 -0700610 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800611
Craig Mautner967212c2013-04-13 21:10:58 -0700612 final int pw = mContainingFrame.width();
613 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800614
615 int w,h;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -0800616 if ((mAttrs.flags & FLAG_SCALED) != 0) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700617 if (mAttrs.width < 0) {
618 w = pw;
619 } else if (mEnforceSizeCompat) {
620 w = (int)(mAttrs.width * mGlobalScale + .5f);
621 } else {
622 w = mAttrs.width;
623 }
624 if (mAttrs.height < 0) {
625 h = ph;
626 } else if (mEnforceSizeCompat) {
627 h = (int)(mAttrs.height * mGlobalScale + .5f);
628 } else {
629 h = mAttrs.height;
630 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800631 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700632 if (mAttrs.width == WindowManager.LayoutParams.MATCH_PARENT) {
633 w = pw;
634 } else if (mEnforceSizeCompat) {
635 w = (int)(mRequestedWidth * mGlobalScale + .5f);
636 } else {
637 w = mRequestedWidth;
638 }
639 if (mAttrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
640 h = ph;
641 } else if (mEnforceSizeCompat) {
642 h = (int)(mRequestedHeight * mGlobalScale + .5f);
643 } else {
644 h = mRequestedHeight;
645 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800646 }
647
648 if (!mParentFrame.equals(pf)) {
649 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
650 // + " to " + pf);
651 mParentFrame.set(pf);
652 mContentChanged = true;
653 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700654 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
655 mLastRequestedWidth = mRequestedWidth;
656 mLastRequestedHeight = mRequestedHeight;
657 mContentChanged = true;
658 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800659
Craig Mautnereda67292013-04-28 13:50:14 -0700660 mOverscanFrame.set(of);
661 mContentFrame.set(cf);
662 mVisibleFrame.set(vf);
John Spurlock46646232013-09-30 22:32:42 -0400663 mDecorFrame.set(dcf);
Adrian Roosfa104232014-06-20 16:10:14 -0700664 mStableFrame.set(sf);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700665 final boolean hasOutsets = osf != null;
666 if (hasOutsets) {
667 mOutsetFrame.set(osf);
668 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800669
Craig Mautnereda67292013-04-28 13:50:14 -0700670 final int fw = mFrame.width();
671 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800672
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700673 float x, y;
674 if (mEnforceSizeCompat) {
675 x = mAttrs.x * mGlobalScale;
676 y = mAttrs.y * mGlobalScale;
677 } else {
678 x = mAttrs.x;
679 y = mAttrs.y;
680 }
681
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700682 if (nonFullscreenTask) {
Wale Ogunwaleb171abb2015-04-22 12:47:17 -0700683 // Make sure window fits in containing frame since it is in a non-fullscreen stack as
684 // required by {@link Gravity#apply} call.
685 w = Math.min(w, pw);
686 h = Math.min(h, ph);
687 }
688
Craig Mautner967212c2013-04-13 21:10:58 -0700689 Gravity.apply(mAttrs.gravity, w, h, mContainingFrame,
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700690 (int) (x + mAttrs.horizontalMargin * pw),
Craig Mautnereda67292013-04-28 13:50:14 -0700691 (int) (y + mAttrs.verticalMargin * ph), mFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800692
Wale Ogunwale94596652015-02-06 19:27:34 -0800693 // Now make sure the window fits in the overall display frame.
694 Gravity.applyDisplay(mAttrs.gravity, mDisplayFrame, mFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800695
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700696 // Calculate the outsets before the content frame gets shrinked to the window frame.
697 if (hasOutsets) {
698 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
699 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
700 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
701 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
702 } else {
703 mOutsets.set(0, 0, 0, 0);
704 }
705
Craig Mautnera248eee2013-05-07 11:41:27 -0700706 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800707 // final window frame.
Skuhnef932e562015-08-20 12:07:30 -0700708 if (freeformWorkspace && !mFrame.isEmpty()) {
Skuhne81c524a2015-08-12 13:34:14 -0700709 // Keep the frame out of the blocked system area, limit it in size to the content area
710 // and make sure that there is always a minimum visible so that the user can drag it
711 // into a usable area..
712 final int height = Math.min(mFrame.height(), mContentFrame.height());
713 final int width = Math.min(mContentFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700714 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700715 final int minVisibleHeight = WindowManagerService.dipToPixel(
716 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics);
717 final int minVisibleWidth = WindowManagerService.dipToPixel(
718 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics);
Skuhne81c524a2015-08-12 13:34:14 -0700719 final int top = Math.max(mContentFrame.top,
720 Math.min(mFrame.top, mContentFrame.bottom - minVisibleHeight));
721 final int left = Math.max(mContentFrame.left + minVisibleWidth - width,
722 Math.min(mFrame.left, mContentFrame.right - minVisibleWidth));
723 mFrame.set(left, top, left + width, top + height);
724 mContentFrame.set(mFrame);
725 mVisibleFrame.set(mContentFrame);
726 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700727 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
728 mDisplayContent.mDividerControllerLocked.positionDockedStackedDivider(mFrame);
Filip Gruszczynskia6a72d92015-10-07 11:27:52 -0700729 mContentFrame.set(mFrame);
Skuhne81c524a2015-08-12 13:34:14 -0700730 } else {
731 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
732 Math.max(mContentFrame.top, mFrame.top),
733 Math.min(mContentFrame.right, mFrame.right),
734 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800735
Skuhne81c524a2015-08-12 13:34:14 -0700736 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
737 Math.max(mVisibleFrame.top, mFrame.top),
738 Math.min(mVisibleFrame.right, mFrame.right),
739 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800740
Skuhne81c524a2015-08-12 13:34:14 -0700741 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
742 Math.max(mStableFrame.top, mFrame.top),
743 Math.min(mStableFrame.right, mFrame.right),
744 Math.min(mStableFrame.bottom, mFrame.bottom));
745 }
Adrian Roosfa104232014-06-20 16:10:14 -0700746
Craig Mautnerc36c8e62013-05-10 13:33:31 -0700747 mOverscanInsets.set(Math.max(mOverscanFrame.left - mFrame.left, 0),
748 Math.max(mOverscanFrame.top - mFrame.top, 0),
Adrian Roos3236f3a2014-12-09 15:06:40 +0000749 Math.max(mFrame.right - mOverscanFrame.right, 0),
750 Math.max(mFrame.bottom - mOverscanFrame.bottom, 0));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800751
Craig Mautnereda67292013-04-28 13:50:14 -0700752 mContentInsets.set(mContentFrame.left - mFrame.left,
753 mContentFrame.top - mFrame.top,
754 mFrame.right - mContentFrame.right,
755 mFrame.bottom - mContentFrame.bottom);
756
757 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
758 mVisibleFrame.top - mFrame.top,
759 mFrame.right - mVisibleFrame.right,
760 mFrame.bottom - mVisibleFrame.bottom);
761
Adrian Roosfa104232014-06-20 16:10:14 -0700762 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
763 Math.max(mStableFrame.top - mFrame.top, 0),
764 Math.max(mFrame.right - mStableFrame.right, 0),
765 Math.max(mFrame.bottom - mStableFrame.bottom, 0));
766
Craig Mautnereda67292013-04-28 13:50:14 -0700767 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400768 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700769 // If there is a size compatibility scale being applied to the
770 // window, we need to apply this to its insets so that they are
771 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700772 mOverscanInsets.scale(mInvGlobalScale);
773 mContentInsets.scale(mInvGlobalScale);
774 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700775 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700776 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700777
778 // Also the scaled frame that we report to the app needs to be
779 // adjusted to be in its coordinate space.
780 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400781 }
782
Craig Mautnereda67292013-04-28 13:50:14 -0700783 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800784 final DisplayContent displayContent = getDisplayContent();
785 if (displayContent != null) {
786 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700787 mService.mWallpaperControllerLocked.updateWallpaperOffset(
788 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800789 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800790 }
791
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700792 if (DEBUG_LAYOUT || WindowManagerService.localLOGV) Slog.v(TAG,
793 "Resolving (mRequestedWidth="
794 + mRequestedWidth + ", mRequestedheight="
795 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
796 + "): frame=" + mFrame.toShortString()
797 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -0700798 + " vi=" + mVisibleInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700799 + " vi=" + mStableInsets.toShortString()
800 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800801 }
802
Craig Mautnera2c77052012-03-26 12:14:43 -0700803 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800804 public Rect getFrameLw() {
805 return mFrame;
806 }
807
Craig Mautnera2c77052012-03-26 12:14:43 -0700808 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700809 public Point getShownPositionLw() {
810 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800811 }
812
Craig Mautnera2c77052012-03-26 12:14:43 -0700813 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800814 public Rect getDisplayFrameLw() {
815 return mDisplayFrame;
816 }
817
Craig Mautnera2c77052012-03-26 12:14:43 -0700818 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800819 public Rect getOverscanFrameLw() {
820 return mOverscanFrame;
821 }
822
823 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800824 public Rect getContentFrameLw() {
825 return mContentFrame;
826 }
827
Craig Mautnera2c77052012-03-26 12:14:43 -0700828 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800829 public Rect getVisibleFrameLw() {
830 return mVisibleFrame;
831 }
832
Craig Mautnera2c77052012-03-26 12:14:43 -0700833 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800834 public boolean getGivenInsetsPendingLw() {
835 return mGivenInsetsPending;
836 }
837
Craig Mautnera2c77052012-03-26 12:14:43 -0700838 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800839 public Rect getGivenContentInsetsLw() {
840 return mGivenContentInsets;
841 }
842
Craig Mautnera2c77052012-03-26 12:14:43 -0700843 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800844 public Rect getGivenVisibleInsetsLw() {
845 return mGivenVisibleInsets;
846 }
847
Craig Mautnera2c77052012-03-26 12:14:43 -0700848 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800849 public WindowManager.LayoutParams getAttrs() {
850 return mAttrs;
851 }
852
Craig Mautner812d2ca2012-09-27 15:35:34 -0700853 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800854 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
855 int index = -1;
856 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -0700857 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800858 while (true) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -0700859 if (ws.mAttrs.needsMenuKey != WindowManager.LayoutParams.NEEDS_MENU_UNSET) {
860 return ws.mAttrs.needsMenuKey == WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800861 }
862 // If we reached the bottom of the range of windows we are considering,
863 // assume no menu is needed.
864 if (ws == bottom) {
865 return false;
866 }
867 // The current window hasn't specified whether menu key is needed;
868 // look behind it.
869 // First, we may need to determine the starting position.
870 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -0700871 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800872 }
873 index--;
874 if (index < 0) {
875 return false;
876 }
Craig Mautner59c00972012-07-30 12:10:24 -0700877 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800878 }
879 }
880
Craig Mautner19d59bc2012-09-04 11:15:56 -0700881 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700882 public int getSystemUiVisibility() {
883 return mSystemUiVisibility;
884 }
885
Craig Mautner19d59bc2012-09-04 11:15:56 -0700886 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800887 public int getSurfaceLayer() {
888 return mLayer;
889 }
890
Craig Mautner812d2ca2012-09-27 15:35:34 -0700891 @Override
Selim Cinekd6623612015-05-22 18:56:22 -0700892 public int getBaseType() {
893 WindowState win = this;
894 while (win.mAttachedWindow != null) {
895 win = win.mAttachedWindow;
896 }
897 return win.mAttrs.type;
898 }
899
900 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800901 public IApplicationToken getAppToken() {
902 return mAppToken != null ? mAppToken.appToken : null;
903 }
Craig Mautner19d59bc2012-09-04 11:15:56 -0700904
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700905 @Override
906 public boolean isVoiceInteraction() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700907 return mAppToken != null && mAppToken.voiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700908 }
909
Craig Mautner4c5eb222013-11-18 12:59:05 -0800910 boolean setInsetsChanged() {
911 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
912 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
913 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -0700914 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700915 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
916 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
917 || mOutsetsChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -0800918 }
919
Craig Mautnerdf88d732014-01-27 09:21:32 -0800920 public DisplayContent getDisplayContent() {
Chad Jonesf391ebc2014-06-12 17:45:05 -0700921 if (mAppToken == null || mNotOnAppsDisplay) {
Craig Mautnerbe634952014-06-12 13:39:24 -0700922 return mDisplayContent;
923 }
924 final TaskStack stack = getStack();
925 return stack == null ? mDisplayContent : stack.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -0800926 }
927
Chong Zhang09b21ef2015-09-14 10:20:21 -0700928 public DisplayInfo getDisplayInfo() {
929 final DisplayContent displayContent = getDisplayContent();
930 return displayContent != null ? displayContent.getDisplayInfo() : null;
931 }
932
Craig Mautner19d59bc2012-09-04 11:15:56 -0700933 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800934 final DisplayContent displayContent = getDisplayContent();
935 if (displayContent == null) {
936 return -1;
937 }
938 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -0700939 }
940
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700941 Task getTask() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700942 return mAppToken != null ? mAppToken.mTask : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700943 }
944
945 TaskStack getStack() {
946 Task task = getTask();
947 if (task != null) {
948 if (task.mStack != null) {
949 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -0700950 }
Craig Mautnerd9a22882013-03-16 15:00:36 -0700951 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700952 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
953 // associate them with some stack to enable dimming.
954 return mAttrs.type >= WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
955 && mDisplayContent != null ? mDisplayContent.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -0700956 }
957
Skuhnef932e562015-08-20 12:07:30 -0700958 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700959 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -0700960 * @param bounds The rect which gets the bounds.
961 * @param forTouch Pass in BOUNDS_FOR_TOUCH to get touch related bounds, otherwise visible
962 * bounds will be returned.
963 */
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700964 void getVisibleBounds(Rect bounds, boolean forTouch) {
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700965 boolean intersectWithStackBounds = mAppToken != null && mAppToken.mCropWindowsToStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700966 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700967 mTmpRect.setEmpty();
968 if (intersectWithStackBounds) {
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700969 final TaskStack stack = getStack();
970 if (stack != null) {
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700971 stack.getBounds(mTmpRect);
972 } else {
973 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700974 }
975 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700976
Chong Zhang9184ec62015-09-24 12:32:21 -0700977 bounds.set(mVisibleFrame);
978 if (intersectWithStackBounds) {
979 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700980 }
981
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700982 if (bounds.isEmpty()) {
983 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700984 if (intersectWithStackBounds) {
985 bounds.intersect(mTmpRect);
986 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800987 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700988 }
Chong Zhang9184ec62015-09-24 12:32:21 -0700989 if (forTouch && inFreeformWorkspace()) {
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700990 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700991 final int delta = WindowManagerService.dipToPixel(
992 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700993 bounds.inset(-delta, -delta);
994 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700995 }
996
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800997 public long getInputDispatchingTimeoutNanos() {
998 return mAppToken != null
999 ? mAppToken.inputDispatchingTimeoutNanos
1000 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1001 }
1002
Craig Mautnere8552142012-11-07 13:55:47 -08001003 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001004 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001005 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001006 }
1007
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001008 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1009 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1010 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1011 if (dtdx < -.000001f || dtdx > .000001f) return false;
1012 if (dsdy < -.000001f || dsdy > .000001f) return false;
1013 return true;
1014 }
1015
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001016 void prelayout() {
1017 if (mEnforceSizeCompat) {
1018 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001019 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001020 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001021 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001022 }
1023 }
1024
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001025 /**
1026 * Is this window visible? It is not visible if there is no
1027 * surface, or we are in the process of running an exit animation
1028 * that will remove the surface, or its app token has been hidden.
1029 */
Craig Mautner88400d32012-09-30 12:35:45 -07001030 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001031 public boolean isVisibleLw() {
1032 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001033 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001034 && (atoken == null || !atoken.hiddenRequested)
1035 && !mExiting && !mDestroying;
1036 }
1037
1038 /**
1039 * Like {@link #isVisibleLw}, but also counts a window that is currently
1040 * "hidden" behind the keyguard as visible. This allows us to apply
1041 * things like window flags that impact the keyguard.
1042 * XXX I am starting to think we need to have ANOTHER visibility flag
1043 * for this "hidden behind keyguard" state rather than overloading
1044 * mPolicyVisibility. Ungh.
1045 */
Craig Mautner88400d32012-09-30 12:35:45 -07001046 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001047 public boolean isVisibleOrBehindKeyguardLw() {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001048 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -08001049 mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001050 return false;
1051 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001052 final AppWindowToken atoken = mAppToken;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001053 final boolean animating = atoken != null && atoken.mAppAnimator.animation != null;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001054 return mHasSurface && !mDestroying && !mExiting
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001055 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001056 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
1057 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001058 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001059 }
1060
1061 /**
1062 * Is this window visible, ignoring its app token? It is not visible
1063 * if there is no surface, or we are in the process of running an exit animation
1064 * that will remove the surface.
1065 */
1066 public boolean isWinVisibleLw() {
1067 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001068 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautner59431632012-04-04 11:56:44 -07001069 && (atoken == null || !atoken.hiddenRequested || atoken.mAppAnimator.animating)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001070 && !mExiting && !mDestroying;
1071 }
1072
1073 /**
1074 * The same as isVisible(), but follows the current hidden state of
1075 * the associated app token, not the pending requested hidden state.
1076 */
1077 boolean isVisibleNow() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001078 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07001079 && (!mRootToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
1080 && !mExiting && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001081 }
1082
1083 /**
1084 * Can this window possibly be a drag/drop target? The test here is
1085 * a combination of the above "visible now" with the check that the
1086 * Input Manager uses when discarding windows from input consideration.
1087 */
1088 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001089 return isVisibleNow() && !mRemoved
1090 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001091 }
1092
1093 /**
1094 * Same as isVisible(), but we also count it as visible between the
1095 * call to IWindowSession.add() and the first relayout().
1096 */
1097 boolean isVisibleOrAdding() {
1098 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001099 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001100 && mPolicyVisibility && !mAttachedHidden
1101 && (atoken == null || !atoken.hiddenRequested)
1102 && !mExiting && !mDestroying;
1103 }
1104
1105 /**
1106 * Is this window currently on-screen? It is on-screen either if it
1107 * is visible or it is currently running an animation before no longer
1108 * being visible.
1109 */
1110 boolean isOnScreen() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001111 return mPolicyVisibility && isOnScreenIgnoringKeyguard();
1112 }
1113
1114 /**
1115 * Like isOnScreen(), but ignores any force hiding of the window due
1116 * to the keyguard.
1117 */
1118 boolean isOnScreenIgnoringKeyguard() {
1119 if (!mHasSurface || mDestroying) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001120 return false;
1121 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001122 final AppWindowToken atoken = mAppToken;
1123 if (atoken != null) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001124 return ((!mAttachedHidden && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001125 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001126 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001127 return !mAttachedHidden || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001128 }
1129
1130 /**
1131 * Like isOnScreen(), but we don't return true if the window is part
1132 * of a transition that has not yet been started.
1133 */
1134 boolean isReadyForDisplay() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001135 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001136 return false;
1137 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001138 return mHasSurface && mPolicyVisibility && !mDestroying
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001139 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
1140 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001141 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001142 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001143 }
1144
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001145 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001146 * Like isReadyForDisplay(), but ignores any force hiding of the window due
1147 * to the keyguard.
1148 */
1149 boolean isReadyForDisplayIgnoringKeyguard() {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001150 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001151 return false;
1152 }
1153 final AppWindowToken atoken = mAppToken;
1154 if (atoken == null && !mPolicyVisibility) {
1155 // If this is not an app window, and the policy has asked to force
1156 // hide, then we really do want to hide.
1157 return false;
1158 }
1159 return mHasSurface && !mDestroying
1160 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
1161 && !mRootToken.hidden)
1162 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -07001163 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
1164 && !mWinAnimator.isDummyAnimation()));
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001165 }
1166
1167 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001168 * Like isOnScreen, but returns false if the surface hasn't yet
1169 * been drawn.
1170 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001171 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001172 public boolean isDisplayedLw() {
1173 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001174 return isDrawnLw() && mPolicyVisibility
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001175 && ((!mAttachedHidden &&
1176 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001177 || mWinAnimator.mAnimating
1178 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001179 }
1180
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001181 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001182 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001183 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001184 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001185 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001186 return mWinAnimator.mAnimation != null
1187 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001188 }
1189
Craig Mautner812d2ca2012-09-27 15:35:34 -07001190 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001191 public boolean isGoneForLayoutLw() {
1192 final AppWindowToken atoken = mAppToken;
1193 return mViewVisibility == View.GONE
1194 || !mRelayoutCalled
1195 || (atoken == null && mRootToken.hidden)
Craig Mautner812d2ca2012-09-27 15:35:34 -07001196 || (atoken != null && (atoken.hiddenRequested || atoken.hidden))
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001197 || mAttachedHidden
Craig Mautner0e415c62013-04-29 16:10:58 -07001198 || (mExiting && !isAnimatingLw())
1199 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001200 }
1201
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001202 /**
1203 * Returns true if the window has a surface that it has drawn a
1204 * complete UI in to.
1205 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001206 public boolean isDrawFinishedLw() {
1207 return mHasSurface && !mDestroying &&
1208 (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING
1209 || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1210 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
1211 }
1212
1213 /**
1214 * Returns true if the window has a surface that it has drawn a
1215 * complete UI in to.
1216 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001217 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001218 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001219 return mHasSurface && !mDestroying &&
Craig Mautner749a7bb2012-04-02 13:49:53 -07001220 (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1221 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001222 }
1223
1224 /**
1225 * Return true if the window is opaque and fully drawn. This indicates
1226 * it may obscure windows behind it.
1227 */
1228 boolean isOpaqueDrawn() {
1229 return (mAttrs.format == PixelFormat.OPAQUE
1230 || mAttrs.type == TYPE_WALLPAPER)
Craig Mautnera2c77052012-03-26 12:14:43 -07001231 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001232 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001233 }
1234
1235 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001236 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001237 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1238 */
Craig Mautner4557c082015-04-27 13:07:40 -07001239 boolean hasMoved() {
1240 return mHasSurface && mContentChanged && !mExiting && !mWinAnimator.mLastHidden
1241 && mService.okToDisplay() && (mFrame.top != mLastFrame.top
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001242 || mFrame.left != mLastFrame.left)
Craig Mautner4557c082015-04-27 13:07:40 -07001243 && (mAttachedWindow == null || !mAttachedWindow.hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001244 }
1245
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001246 boolean isFullscreen(int screenWidth, int screenHeight) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001247 return mFrame.left <= 0 && mFrame.top <= 0 &&
1248 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001249 }
1250
Craig Mautner812d2ca2012-09-27 15:35:34 -07001251 boolean isConfigChanged() {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001252 final Task task = getTask();
Wale Ogunwale60454db2015-01-23 16:05:07 -08001253 final Configuration overrideConfig =
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001254 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001255 final Configuration serviceConfig = mService.mCurConfiguration;
1256 boolean configChanged =
1257 (mConfiguration != serviceConfig && mConfiguration.diff(serviceConfig) != 0)
1258 || (mOverrideConfig != overrideConfig && !mOverrideConfig.equals(overrideConfig));
Craig Mautnere8552142012-11-07 13:55:47 -08001259
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001260 if ((mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Craig Mautnere8552142012-11-07 13:55:47 -08001261 // Retain configuration changed status until resetConfiguration called.
1262 mConfigHasChanged |= configChanged;
1263 configChanged = mConfigHasChanged;
1264 }
1265
1266 return configChanged;
Craig Mautner812d2ca2012-09-27 15:35:34 -07001267 }
1268
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001269 void removeLocked() {
1270 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001271
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001272 if (mAttachedWindow != null) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001273 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001274 mAttachedWindow.mChildWindows.remove(this);
1275 }
Craig Mautner96868332012-12-04 14:29:11 -08001276 mWinAnimator.destroyDeferredSurfaceLocked();
1277 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001278 mSession.windowRemovedLocked();
1279 try {
1280 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1281 } catch (RuntimeException e) {
1282 // Ignore if it has already been removed (usually because
1283 // we are doing this as part of processing a death note.)
1284 }
1285 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001286
Wale Ogunwale60454db2015-01-23 16:05:07 -08001287 private void setConfiguration(
1288 final Configuration newConfig, final Configuration newOverrideConfig) {
Craig Mautnere8552142012-11-07 13:55:47 -08001289 mConfiguration = newConfig;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001290 mOverrideConfig = newOverrideConfig;
Craig Mautnere8552142012-11-07 13:55:47 -08001291 mConfigHasChanged = false;
1292 }
1293
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001294 void setHasSurface(boolean hasSurface) {
1295 mHasSurface = hasSurface;
1296 }
1297
Chong Zhangacf11402015-11-04 16:23:10 -08001298 private final class DeadWindowEventReceiver extends InputEventReceiver {
1299 DeadWindowEventReceiver(InputChannel inputChannel) {
1300 super(inputChannel, mService.mH.getLooper());
1301 }
1302 @Override
1303 public void onInputEvent(InputEvent event) {
1304 finishInputEvent(event, true);
1305 }
1306 }
1307 /**
1308 * Dummy event receiver for windows that died visible.
1309 */
1310 private DeadWindowEventReceiver mDeadWindowEventReceiver;
1311
Chong Zhang112eb8c2015-11-02 11:17:00 -08001312 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001313 if (mInputChannel != null) {
1314 throw new IllegalStateException("Window already has an input channel.");
1315 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001316 String name = makeInputChannelName();
1317 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1318 mInputChannel = inputChannels[0];
1319 mClientChannel = inputChannels[1];
1320 mInputWindowHandle.inputChannel = inputChannels[0];
1321 if (outInputChannel != null) {
1322 mClientChannel.transferTo(outInputChannel);
1323 mClientChannel.dispose();
1324 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08001325 } else {
1326 // If the window died visible, we setup a dummy input channel, so that taps
1327 // can still detected by input monitor channel, and we can relaunch the app.
1328 // Create dummy event receiver that simply reports all events as handled.
1329 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08001330 }
1331 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001332 }
1333
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001334 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08001335 if (mDeadWindowEventReceiver != null) {
1336 mDeadWindowEventReceiver.dispose();
1337 mDeadWindowEventReceiver = null;
1338 }
1339
1340 // unregister server channel first otherwise it complains about broken channel
1341 if (mInputChannel != null) {
1342 mService.mInputManager.unregisterInputChannel(mInputChannel);
1343 mInputChannel.dispose();
1344 mInputChannel = null;
1345 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001346 if (mClientChannel != null) {
1347 mClientChannel.dispose();
1348 mClientChannel = null;
1349 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001350 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001351 }
1352
Chong Zhang112eb8c2015-11-02 11:17:00 -08001353 void applyDimLayerIfNeeded() {
1354 if (!mExiting && mAppDied) {
1355 // If app died visible, apply a dim over the window to indicate that it's inactive
1356 mDisplayContent.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
1357 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
1358 && mDisplayContent != null && !mExiting && isDisplayedLw()) {
1359 mDisplayContent.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001360 }
1361 }
1362
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001363 DimLayer.DimLayerUser getDimLayerUser() {
1364 Task task = getTask();
1365 if (task != null) {
1366 return task;
1367 }
1368 return getStack();
1369 }
1370
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001371 void maybeRemoveReplacedWindow() {
1372 AppWindowToken token = mAppToken;
Filip Gruszczynskib6e66622015-10-25 16:05:27 -07001373 if (token != null && token.mWillReplaceWindow && token.mReplacingWindow == this) {
1374 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replacing window: " + this);
1375 token.mWillReplaceWindow = false;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001376 token.mAnimateReplacingWindow = false;
1377 token.mReplacingRemoveRequested = false;
Filip Gruszczynskib6e66622015-10-25 16:05:27 -07001378 token.mReplacingWindow = null;
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001379 for (int i = token.allAppWindows.size() - 1; i >= 0; i--) {
1380 WindowState win = token.allAppWindows.get(i);
1381 if (win.mExiting) {
1382 mService.removeWindowInnerLocked(win);
1383 }
1384 }
1385 }
1386 }
1387
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07001388 void setDisplayLayoutNeeded() {
1389 if (mDisplayContent != null) {
1390 mDisplayContent.layoutNeeded = true;
1391 }
1392 }
1393
Filip Gruszczynski955b2fc2015-10-15 14:46:07 -07001394 boolean inDockedWorkspace() {
1395 return mAppToken != null && mAppToken.mTask != null && mAppToken.mTask.inDockedWorkspace();
1396 }
1397
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001398 int getTouchableRegion(Region region, int flags, InputMonitor inputMonitor) {
1399 final boolean modal = (flags & (WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
1400 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) == 0;
1401 if (modal && mAppToken != null) {
1402 // Limit the outer touch to the activity stack region.
1403 flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
1404 if (!inFreeformWorkspace()) {
1405 // If this is a modal window we need to dismiss it if it's not full screen and the
1406 // touch happens outside of the frame that displays the content. This means we
1407 // need to intercept touches outside of that window. The dim layer user
1408 // associated with the window (task or stack) will give us the good bounds, as
1409 // they would be used to display the dim layer.
1410 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1411 if (dimLayerUser != null) {
1412 dimLayerUser.getBounds(mTmpRect);
1413 } else {
1414 getVisibleBounds(mTmpRect, BOUNDS_FOR_TOUCH);
1415 }
1416 } else {
1417 // For freeform windows we the touch region to include the whole surface for the
1418 // shadows.
1419 getVisibleBounds(mTmpRect, BOUNDS_FOR_TOUCH);
1420 }
1421 region.set(mTmpRect);
1422 } else {
1423 // Not modal or full screen modal
1424 getTouchableRegion(region);
1425 }
1426 return flags;
1427 }
1428
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001429 void checkPolicyVisibilityChange() {
1430 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
1431 if (DEBUG_VISIBILITY) {
1432 Slog.v(TAG, "Policy visibility changing after anim in " +
1433 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
1434 }
1435 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001436 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001437 if (!mPolicyVisibility) {
1438 if (mService.mCurrentFocus == this) {
1439 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
1440 "setAnimationLocked: setting mFocusMayChange true");
1441 mService.mFocusMayChange = true;
1442 }
1443 // Window is no longer visible -- make sure if we were waiting
1444 // for it to be displayed before enabling the display, that
1445 // we allow the display to be enabled now.
1446 mService.enableScreenIfNeededLocked();
1447 }
1448 }
1449 }
1450
1451 void setRequestedSize(int requestedWidth, int requestedHeight) {
1452 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
1453 mLayoutNeeded = true;
1454 mRequestedWidth = requestedWidth;
1455 mRequestedHeight = requestedHeight;
1456 }
1457 }
1458
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001459 void prepareWindowToDisplayDuringRelayout(Configuration outConfig) {
1460 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
1461 == SOFT_INPUT_ADJUST_RESIZE) {
1462 mLayoutNeeded = true;
1463 }
1464 if (isDrawnLw() && mService.okToDisplay()) {
1465 mWinAnimator.applyEnterAnimationLocked();
1466 }
1467 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
1468 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
1469 mTurnOnScreen = true;
1470 }
1471 if (isConfigChanged()) {
1472 if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + this + " visible with new config: "
1473 + mService.mCurConfiguration);
1474 outConfig.setTo(mService.mCurConfiguration);
1475 }
1476 }
1477
1478 void adjustStartingWindowFlags() {
1479 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
1480 && mAppToken.startingWindow != null) {
1481 // Special handling of starting window over the base
1482 // window of the app: propagate lock screen flags to it,
1483 // to provide the correct semantics while starting.
1484 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
1485 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
1486 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
1487 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
1488 }
1489 }
1490
1491 void setWindowScale(int requestedWidth, int requestedHeight) {
1492 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
1493
1494 if (scaledWindow) {
1495 // requested{Width|Height} Surface's physical size
1496 // attrs.{width|height} Size on screen
1497 // TODO: We don't check if attrs != null here. Is it implicitly checked?
1498 mHScale = (mAttrs.width != requestedWidth) ?
1499 (mAttrs.width / (float)requestedWidth) : 1.0f;
1500 mVScale = (mAttrs.height != requestedHeight) ?
1501 (mAttrs.height / (float)requestedHeight) : 1.0f;
1502 } else {
1503 mHScale = mVScale = 1;
1504 }
1505 }
1506
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001507 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08001508 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001509 public void binderDied() {
1510 try {
1511 synchronized(mService.mWindowMap) {
1512 WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07001513 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001514 if (win != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001515 if (win.mAppToken != null && !win.mAppToken.clientHidden) {
1516 win.mAppToken.appDied = true;
1517 }
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001518 mService.removeWindowLocked(win);
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001519 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08001520 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001521 mService.removeWindowLocked(WindowState.this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001522 }
1523 }
1524 } catch (IllegalArgumentException ex) {
1525 // This will happen if the window has already been
1526 // removed.
1527 }
1528 }
1529 }
1530
Craig Mautner58106812012-12-28 12:27:40 -08001531 /**
1532 * @return true if this window desires key events.
Craig Mautneref25d7a2012-05-15 23:01:47 -07001533 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001534 public final boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08001535 return isVisibleOrAdding()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001536 && (mViewVisibility == View.VISIBLE)
1537 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
1538 }
1539
Craig Mautner749a7bb2012-04-02 13:49:53 -07001540 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001541 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001542 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001543 }
1544
Craig Mautner749a7bb2012-04-02 13:49:53 -07001545 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001546 public boolean showLw(boolean doAnimation) {
1547 return showLw(doAnimation, true);
1548 }
1549
1550 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07001551 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001552 return false;
1553 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001554 if (!mAppOpVisibility) {
1555 // Being hidden due to app op request.
1556 return false;
1557 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001558 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001559 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001560 return false;
1561 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001562 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001563 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001564 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07001565 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07001566 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001567 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07001568 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001569 // Check for the case where we are currently visible and
1570 // not animating; we do not want to do animation at such a
1571 // point to become visible when we already are.
1572 doAnimation = false;
1573 }
1574 }
1575 mPolicyVisibility = true;
1576 mPolicyVisibilityAfterAnim = true;
1577 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001578 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001579 }
1580 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001581 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001582 }
1583 return true;
1584 }
1585
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001586 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001587 public boolean hideLw(boolean doAnimation) {
1588 return hideLw(doAnimation, true);
1589 }
1590
1591 boolean hideLw(boolean doAnimation, boolean requestAnim) {
1592 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07001593 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001594 doAnimation = false;
1595 }
1596 }
1597 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
1598 : mPolicyVisibility;
1599 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001600 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001601 return false;
1602 }
1603 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001604 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07001605 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001606 doAnimation = false;
1607 }
1608 }
1609 if (doAnimation) {
1610 mPolicyVisibilityAfterAnim = false;
1611 } else {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001612 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001613 mPolicyVisibilityAfterAnim = false;
1614 mPolicyVisibility = false;
1615 // Window is no longer visible -- make sure if we were waiting
1616 // for it to be displayed before enabling the display, that
1617 // we allow the display to be enabled now.
1618 mService.enableScreenIfNeededLocked();
1619 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001620 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07001621 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001622 mService.mFocusMayChange = true;
1623 }
1624 }
1625 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001626 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001627 }
1628 return true;
1629 }
1630
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001631 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001632 if (mAppOpVisibility != state) {
1633 mAppOpVisibility = state;
1634 if (state) {
1635 // If the policy visibility had last been to hide, then this
1636 // will incorrectly show at this point since we lost that
1637 // information. Not a big deal -- for the windows that have app
1638 // ops modifies they should only be hidden by policy due to the
1639 // lock screen, and the user won't be changing this if locked.
1640 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001641 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001642 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001643 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001644 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001645 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001646 }
1647
Jeff Brownc2932a12014-11-20 18:04:05 -08001648 public void pokeDrawLockLw(long timeout) {
1649 if (isVisibleOrAdding()) {
1650 if (mDrawLock == null) {
1651 // We want the tag name to be somewhat stable so that it is easier to correlate
1652 // in wake lock statistics. So in particular, we don't want to include the
1653 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001654 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08001655 mDrawLock = mService.mPowerManager.newWakeLock(
1656 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
1657 mDrawLock.setReferenceCounted(false);
1658 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
1659 }
1660 // Each call to acquire resets the timeout.
1661 if (DEBUG_POWER) {
1662 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
1663 + mAttrs.packageName);
1664 }
1665 mDrawLock.acquire(timeout);
1666 } else if (DEBUG_POWER) {
1667 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
1668 + "owned by " + mAttrs.packageName);
1669 }
1670 }
1671
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001672 @Override
1673 public boolean isAlive() {
1674 return mClient.asBinder().isBinderAlive();
1675 }
1676
Craig Mautnera987d432012-10-11 14:07:58 -07001677 boolean isClosing() {
1678 return mExiting || (mService.mClosingApps.contains(mAppToken));
1679 }
1680
Chong Zhangbef461f2015-10-27 11:38:24 -07001681 boolean isAnimatingWithSavedSurface() {
1682 return mAppToken != null && mAppToken.mAnimatingWithSavedSurface;
1683 }
1684
1685 boolean shouldSaveSurface() {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001686 if (ActivityManager.isLowRamDeviceStatic()) {
1687 // Don't save surfaces on Svelte devices.
1688 return false;
1689 }
1690
1691 Task task = getTask();
Chong Zhangbef461f2015-10-27 11:38:24 -07001692 if (task == null || task.inHomeStack()
1693 || task.getTopAppWindowToken() != mAppToken) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001694 // Don't save surfaces for home stack apps. These usually resume and draw
1695 // first frame very fast. Saving surfaces are mostly a waste of memory.
Chong Zhangbef461f2015-10-27 11:38:24 -07001696 // Don't save if the window is not the topmost window.
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001697 return false;
1698 }
1699
Chong Zhangbef461f2015-10-27 11:38:24 -07001700 return mAppToken.shouldSaveSurface();
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001701 }
1702
Craig Mautner69b08182012-09-05 13:07:13 -07001703 @Override
1704 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001705 final DisplayContent displayContent = getDisplayContent();
1706 if (displayContent == null) {
1707 // Only a window that was on a non-default display can be detached from it.
1708 return false;
1709 }
Winson Chung47a3e652014-05-21 16:03:42 -07001710 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07001711 }
1712
Adrian Rooscd3884d2015-02-18 17:25:23 +01001713 @Override
1714 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001715 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1716 return dimLayerUser != null && mDisplayContent != null &&
Chong Zhang112eb8c2015-11-02 11:17:00 -08001717 mDisplayContent.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01001718 }
1719
Craig Mautner88400d32012-09-30 12:35:45 -07001720 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
1721 mShowToOwnerOnly = showToOwnerOnly;
1722 }
1723
Craig Mautner5962b122012-10-05 14:45:52 -07001724 boolean isHiddenFromUserLocked() {
Craig Mautner341220f2012-10-16 15:20:09 -07001725 // Attached windows are evaluated based on the window that they are attached to.
1726 WindowState win = this;
1727 while (win.mAttachedWindow != null) {
1728 win = win.mAttachedWindow;
1729 }
1730 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -07001731 && win.mAppToken != null && win.mAppToken.showForAllUsers) {
Craig Mautner341220f2012-10-16 15:20:09 -07001732 // Save some cycles by not calling getDisplayInfo unless it is an application
1733 // window intended for all users.
Craig Mautnerdf88d732014-01-27 09:21:32 -08001734 final DisplayContent displayContent = win.getDisplayContent();
1735 if (displayContent == null) {
1736 return true;
1737 }
1738 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Craig Mautner341220f2012-10-16 15:20:09 -07001739 if (win.mFrame.left <= 0 && win.mFrame.top <= 0
1740 && win.mFrame.right >= displayInfo.appWidth
1741 && win.mFrame.bottom >= displayInfo.appHeight) {
Craig Mautner5962b122012-10-05 14:45:52 -07001742 // Is a fullscreen window, like the clock alarm. Show to everyone.
1743 return false;
1744 }
1745 }
1746
Craig Mautner341220f2012-10-16 15:20:09 -07001747 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01001748 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001749 }
1750
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001751 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
1752 outRegion.set(
1753 frame.left + inset.left, frame.top + inset.top,
1754 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001755 }
1756
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001757 public void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001758 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001759 switch (mTouchableInsets) {
1760 default:
1761 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
1762 outRegion.set(frame);
1763 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001764 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001765 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001766 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001767 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001768 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001769 break;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001770 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
1771 final Region givenTouchableRegion = mGivenTouchableRegion;
1772 outRegion.set(givenTouchableRegion);
1773 outRegion.translate(frame.left, frame.top);
1774 break;
1775 }
1776 }
1777 }
1778
Craig Mautner59c00972012-07-30 12:10:24 -07001779 WindowList getWindowList() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001780 final DisplayContent displayContent = getDisplayContent();
1781 return displayContent == null ? null : displayContent.getWindowList();
Craig Mautner59c00972012-07-30 12:10:24 -07001782 }
1783
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001784 /**
1785 * Report a focus change. Must be called with no locks held, and consistently
1786 * from the same serialized thread (such as dispatched from a handler).
1787 */
1788 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
1789 try {
1790 mClient.windowFocusChanged(focused, inTouchMode);
1791 } catch (RemoteException e) {
1792 }
1793 if (mFocusCallbacks != null) {
1794 final int N = mFocusCallbacks.beginBroadcast();
1795 for (int i=0; i<N; i++) {
1796 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
1797 try {
1798 if (focused) {
1799 obs.focusGained(mWindowId.asBinder());
1800 } else {
1801 obs.focusLost(mWindowId.asBinder());
1802 }
1803 } catch (RemoteException e) {
1804 }
1805 }
1806 mFocusCallbacks.finishBroadcast();
1807 }
1808 }
1809
Craig Mautnerdf88d732014-01-27 09:21:32 -08001810 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001811 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08001812 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001813 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
1814 + ": " + mCompatFrame);
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001815 final boolean configChanged = isConfigChanged();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001816 final Task task = getTask();
Wale Ogunwale60454db2015-01-23 16:05:07 -08001817 final Configuration overrideConfig =
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001818 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001819 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) && configChanged) {
1820 Slog.i(TAG, "Sending new config to window " + this + ": "
Robert Carre6a83512015-11-03 16:09:21 -08001821 + " / config="
Wale Ogunwale60454db2015-01-23 16:05:07 -08001822 + mService.mCurConfiguration + " overrideConfig=" + overrideConfig);
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001823 }
Wale Ogunwale60454db2015-01-23 16:05:07 -08001824 setConfiguration(mService.mCurConfiguration, overrideConfig);
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001825 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING)
1826 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
1827
Craig Mautnerdf88d732014-01-27 09:21:32 -08001828 final Rect frame = mFrame;
1829 final Rect overscanInsets = mLastOverscanInsets;
1830 final Rect contentInsets = mLastContentInsets;
1831 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07001832 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001833 final Rect outsets = mLastOutsets;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001834 final boolean reportDraw = mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING;
1835 final Configuration newConfig = configChanged ? mConfiguration : null;
Chet Haase8eb48d22014-09-24 07:31:29 -07001836 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1837 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001838 // To prevent deadlock simulate one-way call if win.mClient is a local object.
1839 mService.mH.post(new Runnable() {
1840 @Override
1841 public void run() {
1842 try {
1843 mClient.resized(frame, overscanInsets, contentInsets,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001844 visibleInsets, stableInsets, outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001845 } catch (RemoteException e) {
1846 // Not a remote call, RemoteException won't be raised.
1847 }
1848 }
1849 });
1850 } else {
Adrian Roosfa104232014-06-20 16:10:14 -07001851 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001852 outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001853 }
Svetoslav4604abc2014-06-10 18:59:30 -07001854
1855 //TODO (multidisplay): Accessibility supported only for the default display.
1856 if (mService.mAccessibilityController != null
1857 && getDisplayId() == Display.DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07001858 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07001859 }
1860
Craig Mautnerdf88d732014-01-27 09:21:32 -08001861 mOverscanInsetsChanged = false;
1862 mContentInsetsChanged = false;
1863 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07001864 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001865 mOutsetsChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001866 mWinAnimator.mSurfaceResized = false;
1867 } catch (RemoteException e) {
1868 mOrientationChanging = false;
1869 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1870 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08001871 // We are assuming the hosting process is dead or in a zombie state.
1872 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
1873 + ", removing this window.");
1874 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001875 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001876 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001877 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001878 }
1879
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001880 public void registerFocusObserver(IWindowFocusObserver observer) {
1881 synchronized(mService.mWindowMap) {
1882 if (mFocusCallbacks == null) {
1883 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
1884 }
1885 mFocusCallbacks.register(observer);
1886 }
1887 }
1888
1889 public void unregisterFocusObserver(IWindowFocusObserver observer) {
1890 synchronized(mService.mWindowMap) {
1891 if (mFocusCallbacks != null) {
1892 mFocusCallbacks.unregister(observer);
1893 }
1894 }
1895 }
1896
1897 public boolean isFocused() {
1898 synchronized(mService.mWindowMap) {
1899 return mService.mCurrentFocus == this;
1900 }
1901 }
1902
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07001903 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07001904 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07001905 return task != null && task.inFreeformWorkspace();
1906 }
1907
Chong Zhang3005e752015-09-18 18:46:28 -07001908 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07001909 return mDragResizing != computeDragResizing();
1910 }
1911
1912 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07001913 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07001914 if (task == null) {
1915 return false;
1916 }
1917 if (task.isDragResizing()) {
1918 return true;
1919 }
1920 return mDisplayContent.mDividerControllerLocked.isResizing() &&
1921 !task.inFreeformWorkspace() && !task.isFullscreen();
Chong Zhang3005e752015-09-18 18:46:28 -07001922 }
1923
1924 void setDragResizing() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07001925 mDragResizing = computeDragResizing();
Chong Zhang3005e752015-09-18 18:46:28 -07001926 }
1927
1928 boolean isDragResizing() {
1929 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07001930 }
1931
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001932 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08001933 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001934 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08001935 if (stack != null) {
1936 pw.print(" stackId="); pw.print(stack.mStackId);
1937 }
Craig Mautner59c00972012-07-30 12:10:24 -07001938 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001939 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07001940 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08001941 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
1942 pw.print(" package="); pw.print(mAttrs.packageName);
1943 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001944 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001945 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
1946 pw.print(" h="); pw.print(mRequestedHeight);
1947 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07001948 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
1949 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
1950 pw.print(" h="); pw.println(mLastRequestedHeight);
1951 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001952 if (mAttachedWindow != null || mLayoutAttached) {
1953 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
1954 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
1955 }
1956 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
1957 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
1958 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
1959 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
1960 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
1961 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001962 if (dumpAll) {
1963 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
1964 pw.print(" mSubLayer="); pw.print(mSubLayer);
1965 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautner59431632012-04-04 11:56:44 -07001966 pw.print((mTargetAppToken != null ?
1967 mTargetAppToken.mAppAnimator.animLayerAdjustment
1968 : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001969 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
1970 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08001971 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001972 if (dumpAll) {
1973 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
1974 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
1975 if (mAppToken != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001976 pw.print(prefix); pw.print("mAppToken="); pw.print(mAppToken);
1977 pw.print(" mAppDied=");pw.println(mAppDied);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001978 }
1979 if (mTargetAppToken != null) {
1980 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
1981 }
1982 pw.print(prefix); pw.print("mViewVisibility=0x");
1983 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001984 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
1985 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001986 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
1987 pw.print(" mSystemUiVisibility=0x");
1988 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001989 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001990 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
1991 || mAttachedHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001992 pw.print(prefix); pw.print("mPolicyVisibility=");
1993 pw.print(mPolicyVisibility);
1994 pw.print(" mPolicyVisibilityAfterAnim=");
1995 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001996 pw.print(" mAppOpVisibility=");
1997 pw.print(mAppOpVisibility);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001998 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
1999 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08002000 if (!mRelayoutCalled || mLayoutNeeded) {
2001 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
2002 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002003 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002004 if (mXOffset != 0 || mYOffset != 0) {
2005 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
2006 pw.print(" y="); pw.println(mYOffset);
2007 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002008 if (dumpAll) {
2009 pw.print(prefix); pw.print("mGivenContentInsets=");
2010 mGivenContentInsets.printShortString(pw);
2011 pw.print(" mGivenVisibleInsets=");
2012 mGivenVisibleInsets.printShortString(pw);
2013 pw.println();
2014 if (mTouchableInsets != 0 || mGivenInsetsPending) {
2015 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
2016 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07002017 Region region = new Region();
2018 getTouchableRegion(region);
2019 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002020 }
2021 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Wale Ogunwale7c726682015-02-06 17:34:28 -08002022 if (mOverrideConfig != Configuration.EMPTY) {
2023 pw.print(prefix); pw.print("mOverrideConfig="); pw.println(mOverrideConfig);
2024 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002025 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07002026 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07002027 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Craig Mautner178af592012-09-17 10:37:29 -07002028 pw.print(" isReadyForDisplay()="); pw.println(isReadyForDisplay());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002029 if (dumpAll) {
2030 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
2031 pw.print(" last="); mLastFrame.printShortString(pw);
2032 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002033 pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw);
2034 pw.print(" last="); mLastSystemDecorRect.printShortString(pw);
Craig Mautner80b1f642015-04-22 10:59:09 -07002035 if (mWinAnimator.mHasClipRect) {
2036 pw.print(" mLastClipRect=");
2037 mWinAnimator.mLastClipRect.printShortString(pw);
2038 }
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002039 pw.println();
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002040 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002041 if (mEnforceSizeCompat) {
2042 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002043 pw.println();
2044 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002045 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002046 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002047 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002048 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002049 pw.println();
2050 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
2051 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002052 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002053 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002054 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002055 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04002056 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
2057 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002058 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
2059 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002060 pw.print(prefix); pw.print("Cur insets: overscan=");
2061 mOverscanInsets.printShortString(pw);
2062 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002063 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002064 pw.print(" stable="); mStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002065 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002066 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002067 pw.print(prefix); pw.print("Lst insets: overscan=");
2068 mLastOverscanInsets.printShortString(pw);
2069 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002070 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002071 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002072 pw.print(" physical="); mLastOutsets.printShortString(pw);
2073 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002074 pw.println();
2075 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07002076 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
2077 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002078 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
2079 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
2080 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
2081 pw.print(" mDestroying="); pw.print(mDestroying);
2082 pw.print(" mRemoved="); pw.println(mRemoved);
2083 }
2084 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
2085 pw.print(prefix); pw.print("mOrientationChanging=");
2086 pw.print(mOrientationChanging);
2087 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
2088 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
2089 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07002090 if (mLastFreezeDuration != 0) {
2091 pw.print(prefix); pw.print("mLastFreezeDuration=");
2092 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
2093 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002094 if (mHScale != 1 || mVScale != 1) {
2095 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
2096 pw.print(" mVScale="); pw.println(mVScale);
2097 }
2098 if (mWallpaperX != -1 || mWallpaperY != -1) {
2099 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
2100 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
2101 }
2102 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
2103 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
2104 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
2105 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07002106 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
2107 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
2108 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
2109 pw.print(mWallpaperDisplayOffsetX);
2110 pw.print(" mWallpaperDisplayOffsetY=");
2111 pw.println(mWallpaperDisplayOffsetY);
2112 }
Jeff Brownc2932a12014-11-20 18:04:05 -08002113 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07002114 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08002115 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002116 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002117
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002118 String makeInputChannelName() {
2119 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002120 + " " + getWindowTag();
2121 }
2122
2123 private CharSequence getWindowTag() {
2124 CharSequence tag = mAttrs.getTitle();
2125 if (tag == null || tag.length() <= 0) {
2126 tag = mAttrs.packageName;
2127 }
2128 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002129 }
2130
2131 @Override
2132 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002133 final CharSequence title = getWindowTag();
Dianne Hackbornc2293022013-02-06 23:14:49 -08002134 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mExiting) {
2135 mLastTitle = title;
Dianne Hackborn529e7442012-11-01 14:22:28 -07002136 mWasExiting = mExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002137 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -07002138 + " u" + UserHandle.getUserId(mSession.mUid)
Craig Mautnera987d432012-10-11 14:07:58 -07002139 + " " + mLastTitle + (mExiting ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002140 }
2141 return mStringNameCache;
2142 }
Robert Carr58f29132015-10-29 14:19:05 -07002143
2144 void transformFromScreenToSurfaceSpace(Rect rect) {
2145 if (mHScale >= 0) {
2146 rect.right = rect.left + (int)((rect.right - rect.left) / mHScale);
2147 }
2148 if (mVScale >= 0) {
2149 rect.bottom = rect.top + (int)((rect.bottom - rect.top) / mVScale);
2150 }
2151 }
satokcef37fb2011-10-24 21:49:38 +09002152}