blob: 86024ac314297951bf340449f2003c2dee1302e9 [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
Jorim Jaggidcf467c2015-11-05 13:59:32 +0100111 static final int DRAG_RESIZE_MODE_FREEFORM = 0;
112 static final int DRAG_RESIZE_MODE_DOCKED_DIVIDER = 1;
113
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800114 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700115 final WindowManagerPolicy mPolicy;
116 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800117 final Session mSession;
118 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800119 final int mAppOp;
120 // UserId and appId of the owner. Don't display windows of non-current user.
121 final int mOwnerUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800122 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800123 WindowToken mToken;
124 WindowToken mRootToken;
125 AppWindowToken mAppToken;
126 AppWindowToken mTargetAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700127
128 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
129 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800130 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
131 final DeathRecipient mDeathRecipient;
132 final WindowState mAttachedWindow;
Craig Mautner7b1aa772012-11-30 16:14:45 -0800133 final WindowList mChildWindows = new WindowList();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800134 final int mBaseLayer;
135 final int mSubLayer;
136 final boolean mLayoutAttached;
137 final boolean mIsImWindow;
138 final boolean mIsWallpaper;
139 final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700140 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700141 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800142 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700143 int mSystemUiVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800144 boolean mPolicyVisibility = true;
145 boolean mPolicyVisibilityAfterAnim = true;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -0800146 boolean mAppOpVisibility = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800147 boolean mAppFreezing;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800148 boolean mAttachedHidden; // is our parent window hidden?
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800149 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Chong Zhang0275e392015-09-17 10:41:44 -0700150 boolean mDragResizing;
Jorim Jaggidcf467c2015-11-05 13:59:32 +0100151 int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700152
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800153 RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
154
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700155 /**
156 * The window size that was requested by the application. These are in
157 * the application's coordinate space (without compatibility scale applied).
158 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800159 int mRequestedWidth;
160 int mRequestedHeight;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700161 int mLastRequestedWidth;
162 int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700163
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800164 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800165 boolean mHaveFrame;
166 boolean mObscured;
167 boolean mTurnOnScreen;
168
169 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700170
Wale Ogunwale60454db2015-01-23 16:05:07 -0800171 private Configuration mConfiguration = Configuration.EMPTY;
172 private Configuration mOverrideConfig = Configuration.EMPTY;
Craig Mautnere8552142012-11-07 13:55:47 -0800173 // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned.
174 // Used only on {@link #TYPE_KEYGUARD}.
175 private boolean mConfigHasChanged;
Craig Mautnera2c77052012-03-26 12:14:43 -0700176
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700177 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700178 * Actual position of the surface shown on-screen (may be modified by animation). These are
179 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700180 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700181 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800182
183 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700184 * Insets that determine the actually visible area. These are in the application's
185 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800186 */
187 final Rect mVisibleInsets = new Rect();
188 final Rect mLastVisibleInsets = new Rect();
189 boolean mVisibleInsetsChanged;
190
191 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700192 * Insets that are covered by system windows (such as the status bar) and
193 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700194 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800195 */
196 final Rect mContentInsets = new Rect();
197 final Rect mLastContentInsets = new Rect();
198 boolean mContentInsetsChanged;
199
200 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800201 * Insets that determine the area covered by the display overscan region. These are in the
202 * application's coordinate space (without compatibility scale applied).
203 */
204 final Rect mOverscanInsets = new Rect();
205 final Rect mLastOverscanInsets = new Rect();
206 boolean mOverscanInsetsChanged;
207
208 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700209 * Insets that determine the area covered by the stable system windows. These are in the
210 * application's coordinate space (without compatibility scale applied).
211 */
212 final Rect mStableInsets = new Rect();
213 final Rect mLastStableInsets = new Rect();
214 boolean mStableInsetsChanged;
215
216 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700217 * Outsets determine the area outside of the surface where we want to pretend that it's possible
218 * to draw anyway.
219 */
220 final Rect mOutsets = new Rect();
221 final Rect mLastOutsets = new Rect();
222 boolean mOutsetsChanged = false;
223
224 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800225 * Set to true if we are waiting for this window to receive its
226 * given internal insets before laying out other windows based on it.
227 */
228 boolean mGivenInsetsPending;
229
230 /**
231 * These are the content insets that were given during layout for
232 * this window, to be applied to windows behind it.
233 */
234 final Rect mGivenContentInsets = new Rect();
235
236 /**
237 * These are the visible insets that were given during layout for
238 * this window, to be applied to windows behind it.
239 */
240 final Rect mGivenVisibleInsets = new Rect();
241
242 /**
243 * This is the given touchable area relative to the window frame, or null if none.
244 */
245 final Region mGivenTouchableRegion = new Region();
246
247 /**
248 * Flag indicating whether the touchable region should be adjusted by
249 * the visible insets; if false the area outside the visible insets is
250 * NOT touchable, so we must use those to adjust the frame during hit
251 * tests.
252 */
253 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
254
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700255 /**
256 * This is rectangle of the window's surface that is not covered by
257 * system decorations.
258 */
259 final Rect mSystemDecorRect = new Rect();
260 final Rect mLastSystemDecorRect = new Rect();
261
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800262 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400263 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700264 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800265 float mHScale=1, mVScale=1;
266 float mLastHScale=1, mLastVScale=1;
267 final Matrix mTmpMatrix = new Matrix();
268
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700269 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800270 final Rect mFrame = new Rect();
271 final Rect mLastFrame = new Rect();
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700272 // Frame that is scaled to the application's coordinate space when in
273 // screen size compatibility mode.
274 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800275
276 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700277
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800278 final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700279
Wale Ogunwale94596652015-02-06 19:27:34 -0800280 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
281 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700282 final Rect mDisplayFrame = new Rect();
283
284 // The region of the display frame that the display type supports displaying content on. This
285 // is mostly a special case for TV where some displays don’t have the entire display usable.
286 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
287 // window display contents to extend into the overscan region.
288 final Rect mOverscanFrame = new Rect();
289
290 // The display frame minus the stable insets. This value is always constant regardless of if
291 // the status bar or navigation bar is visible.
Adrian Roosfa104232014-06-20 16:10:14 -0700292 final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800293
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700294 // The area not occupied by the status and navigation bars. So, if both status and navigation
295 // bars are visible, the decor frame is equal to the stable frame.
296 final Rect mDecorFrame = new Rect();
297
298 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
299 // minus the area occupied by the IME if the IME is present.
300 final Rect mContentFrame = new Rect();
301
302 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
303 // displays hint text.
304 final Rect mVisibleFrame = new Rect();
305
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700306 // Frame that includes dead area outside of the surface but where we want to pretend that it's
307 // possible to draw.
308 final Rect mOutsetFrame = new Rect();
309
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800310 boolean mContentChanged;
311
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800312 // If a window showing a wallpaper: the requested offset for the
313 // wallpaper; if a wallpaper window: the currently applied offset.
314 float mWallpaperX = -1;
315 float mWallpaperY = -1;
316
317 // If a window showing a wallpaper: what fraction of the offset
318 // range corresponds to a full virtual screen.
319 float mWallpaperXStep = -1;
320 float mWallpaperYStep = -1;
321
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700322 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
323 // to its window; if a wallpaper window: not used.
324 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
325 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
326
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800327 // Wallpaper windows: pixels offset based on above variables.
328 int mXOffset;
329 int mYOffset;
330
Craig Mautner2268e7e2012-12-13 15:40:00 -0800331 /**
332 * This is set after IWindowSession.relayout() has been called at
333 * least once for the window. It allows us to detect the situation
334 * where we don't yet have a surface, but should have one soon, so
335 * we can give the window focus before waiting for the relayout.
336 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800337 boolean mRelayoutCalled;
338
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800339 /**
340 * If the application has called relayout() with changes that can
341 * impact its window's size, we need to perform a layout pass on it
342 * even if it is not currently visible for layout. This is set
343 * when in that case until the layout is done.
344 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800345 boolean mLayoutNeeded;
346
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800347 /** Currently running an exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800348 boolean mExiting;
349
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800350 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800351 boolean mDestroying;
352
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800353 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800354 boolean mRemoveOnExit;
355
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800356 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800357 * Whether the app died while it was visible, if true we might need
358 * to continue to show it until it's restarted.
359 */
360 boolean mAppDied;
361
362 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800363 * Set when the orientation is changing and this window has not yet
364 * been updated for the new orientation.
365 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800366 boolean mOrientationChanging;
367
Dianne Hackborna57c6952013-03-29 14:46:40 -0700368 /**
369 * How long we last kept the screen frozen.
370 */
371 int mLastFreezeDuration;
372
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800373 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800374 boolean mRemoved;
375
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800376 /**
377 * Temp for keeping track of windows that have been removed when
378 * rebuilding window list.
379 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800380 boolean mRebuilding;
381
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800382 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700383 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800384 InputChannel mInputChannel;
Chong Zhang112eb8c2015-11-02 11:17:00 -0800385 InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800386
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800387 // Used to improve performance of toString()
388 String mStringNameCache;
389 CharSequence mLastTitle;
Dianne Hackborn529e7442012-11-01 14:22:28 -0700390 boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800391
Craig Mautnera2c77052012-03-26 12:14:43 -0700392 final WindowStateAnimator mWinAnimator;
393
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700394 boolean mHasSurface = false;
395
Craig Mautner19ab8282014-05-07 10:35:34 -0700396 boolean mNotOnAppsDisplay = false;
Craig Mautner59c00972012-07-30 12:10:24 -0700397 DisplayContent mDisplayContent;
Craig Mautner6881a102012-07-27 13:04:51 -0700398
Craig Mautner88400d32012-09-30 12:35:45 -0700399 /** When true this window can be displayed on screens owther than mOwnerUid's */
400 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700401
Jeff Brownc2932a12014-11-20 18:04:05 -0800402 /**
403 * Wake lock for drawing.
404 * Even though it's slightly more expensive to do so, we will use a separate wake lock
405 * for each app that is requesting to draw while dozing so that we can accurately track
406 * who is preventing the system from suspending.
407 * This lock is only acquired on first use.
408 */
409 PowerManager.WakeLock mDrawLock;
410
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700411 final private Rect mTmpRect = new Rect();
412
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800413 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800414 WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a,
Craig Mautner59c00972012-07-30 12:10:24 -0700415 int viewVisibility, final DisplayContent displayContent) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800416 mService = service;
417 mSession = s;
418 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800419 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800420 mToken = token;
Craig Mautnera2d7b112012-08-21 15:12:20 -0700421 mOwnerUid = s.mUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800422 mWindowId = new IWindowId.Stub() {
423 @Override
424 public void registerFocusObserver(IWindowFocusObserver observer) {
425 WindowState.this.registerFocusObserver(observer);
426 }
427 @Override
428 public void unregisterFocusObserver(IWindowFocusObserver observer) {
429 WindowState.this.unregisterFocusObserver(observer);
430 }
431 @Override
432 public boolean isFocused() {
433 return WindowState.this.isFocused();
434 }
435 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800436 mAttrs.copyFrom(a);
437 mViewVisibility = viewVisibility;
Craig Mautner59c00972012-07-30 12:10:24 -0700438 mDisplayContent = displayContent;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700439 mPolicy = mService.mPolicy;
440 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800441 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700442 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700443 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800444 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700445 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700446 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800447 try {
448 c.asBinder().linkToDeath(deathRecipient, 0);
449 } catch (RemoteException e) {
450 mDeathRecipient = null;
451 mAttachedWindow = null;
452 mLayoutAttached = false;
453 mIsImWindow = false;
454 mIsWallpaper = false;
455 mIsFloatingLayer = false;
456 mBaseLayer = 0;
457 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700458 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700459 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800460 return;
461 }
462 mDeathRecipient = deathRecipient;
463
464 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
465 mAttrs.type <= LAST_SUB_WINDOW)) {
466 // The multiplier here is to reserve space for multiple
467 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700468 mBaseLayer = mPolicy.windowTypeToLayerLw(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800469 attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
470 + WindowManagerService.TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700471 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800472 mAttachedWindow = attachedWindow;
Filip Gruszczynskib6e66622015-10-25 16:05:27 -0700473 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to "
474 + mAttachedWindow);
takeda.masayuki18735092012-12-12 11:06:24 +0900475
tiger_huange2a98a72014-11-13 19:46:28 +0800476 final WindowList childWindows = mAttachedWindow.mChildWindows;
477 final int numChildWindows = childWindows.size();
478 if (numChildWindows == 0) {
479 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900480 } else {
tiger_huange2a98a72014-11-13 19:46:28 +0800481 boolean added = false;
482 for (int i = 0; i < numChildWindows; i++) {
483 final int childSubLayer = childWindows.get(i).mSubLayer;
484 if (mSubLayer < childSubLayer
485 || (mSubLayer == childSubLayer && childSubLayer < 0)) {
486 // We insert the child window into the list ordered by the sub-layer. For
487 // same sub-layers, the negative one should go below others; the positive
488 // one should go above others.
489 childWindows.add(i, this);
490 added = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900491 break;
takeda.masayuki18735092012-12-12 11:06:24 +0900492 }
493 }
tiger_huange2a98a72014-11-13 19:46:28 +0800494 if (!added) {
495 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900496 }
497 }
498
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800499 mLayoutAttached = mAttrs.type !=
500 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
501 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
502 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
503 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
504 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
505 } else {
506 // The multiplier here is to reserve space for multiple
507 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700508 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800509 * WindowManagerService.TYPE_LAYER_MULTIPLIER
510 + WindowManagerService.TYPE_LAYER_OFFSET;
511 mSubLayer = 0;
512 mAttachedWindow = null;
513 mLayoutAttached = false;
514 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
515 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
516 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
517 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
518 }
519
520 WindowState appWin = this;
521 while (appWin.mAttachedWindow != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700522 appWin = appWin.mAttachedWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800523 }
524 WindowToken appToken = appWin.mToken;
525 while (appToken.appWindowToken == null) {
526 WindowToken parent = mService.mTokenMap.get(appToken.token);
527 if (parent == null || appToken == parent) {
528 break;
529 }
530 appToken = parent;
531 }
532 mRootToken = appToken;
533 mAppToken = appToken.appWindowToken;
Craig Mautner19ab8282014-05-07 10:35:34 -0700534 if (mAppToken != null) {
535 final DisplayContent appDisplay = getDisplayContent();
536 mNotOnAppsDisplay = displayContent != appDisplay;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700537
538 if (mAppToken.showForAllUsers) {
539 // Windows for apps that can show for all users should also show when the
540 // device is locked.
541 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
542 }
Craig Mautner19ab8282014-05-07 10:35:34 -0700543 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800544
Craig Mautner322e4032012-07-13 13:35:20 -0700545 mWinAnimator = new WindowStateAnimator(this);
546 mWinAnimator.mAlpha = a.alpha;
547
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800548 mRequestedWidth = 0;
549 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700550 mLastRequestedWidth = 0;
551 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800552 mXOffset = 0;
553 mYOffset = 0;
554 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800555 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700556 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
557 displayContent.getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800558 }
559
560 void attach() {
561 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700562 TAG, "Attaching " + this + " token=" + mToken
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800563 + ", list=" + mToken.windows);
564 mSession.windowAddedLocked();
565 }
566
Craig Mautnera2c77052012-03-26 12:14:43 -0700567 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800568 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800569 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800570 }
571
572 @Override
573 public String getOwningPackage() {
574 return mAttrs.packageName;
575 }
576
577 @Override
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700578 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf, Rect sf,
579 Rect osf) {
Filip Gruszczynskib6e66622015-10-25 16:05:27 -0700580 if (mAppToken != null && mAppToken.mWillReplaceWindow
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700581 && (mExiting || !mAppToken.mReplacingRemoveRequested)) {
582 // This window is being replaced and either already got information that it's being
583 // removed or we are still waiting for some information. Because of this we don't
584 // want to apply any more changes to it, so it remains in this state until new window
585 // appears.
586 return;
587 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800588 mHaveFrame = true;
589
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700590 final Task task = getTask();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700591 final boolean nonFullscreenTask = task != null && !task.isFullscreen();
Chong Zhang09b21ef2015-09-14 10:20:21 -0700592 final boolean freeformWorkspace = task != null && task.inFreeformWorkspace();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700593 if (nonFullscreenTask) {
594 task.getBounds(mContainingFrame);
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800595 final WindowState imeWin = mService.mInputMethodWindow;
596 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this
597 && mContainingFrame.bottom > cf.bottom) {
598 // IME is up and obscuring this window. Adjust the window position so it is visible.
599 mContainingFrame.top -= mContainingFrame.bottom - cf.bottom;
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700600 }
Skuhne81c524a2015-08-12 13:34:14 -0700601
Skuhnef932e562015-08-20 12:07:30 -0700602 if (freeformWorkspace) {
Skuhne81c524a2015-08-12 13:34:14 -0700603 // In free form mode we have only to set the rectangle if it wasn't set already. No
604 // need to intersect it with the (visible) "content frame" since it is allowed to
605 // be outside the visible desktop.
606 if (mContainingFrame.isEmpty()) {
607 mContainingFrame.set(cf);
608 }
Doris Liu06d582d2015-06-01 13:18:43 -0700609 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800610 mDisplayFrame.set(mContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700611 } else {
612 mContainingFrame.set(pf);
Wale Ogunwale94596652015-02-06 19:27:34 -0800613 mDisplayFrame.set(df);
Craig Mautner967212c2013-04-13 21:10:58 -0700614 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800615
Craig Mautner967212c2013-04-13 21:10:58 -0700616 final int pw = mContainingFrame.width();
617 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800618
619 int w,h;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -0800620 if ((mAttrs.flags & FLAG_SCALED) != 0) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700621 if (mAttrs.width < 0) {
622 w = pw;
623 } else if (mEnforceSizeCompat) {
624 w = (int)(mAttrs.width * mGlobalScale + .5f);
625 } else {
626 w = mAttrs.width;
627 }
628 if (mAttrs.height < 0) {
629 h = ph;
630 } else if (mEnforceSizeCompat) {
631 h = (int)(mAttrs.height * mGlobalScale + .5f);
632 } else {
633 h = mAttrs.height;
634 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800635 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700636 if (mAttrs.width == WindowManager.LayoutParams.MATCH_PARENT) {
637 w = pw;
638 } else if (mEnforceSizeCompat) {
639 w = (int)(mRequestedWidth * mGlobalScale + .5f);
640 } else {
641 w = mRequestedWidth;
642 }
643 if (mAttrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
644 h = ph;
645 } else if (mEnforceSizeCompat) {
646 h = (int)(mRequestedHeight * mGlobalScale + .5f);
647 } else {
648 h = mRequestedHeight;
649 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800650 }
651
652 if (!mParentFrame.equals(pf)) {
653 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
654 // + " to " + pf);
655 mParentFrame.set(pf);
656 mContentChanged = true;
657 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700658 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
659 mLastRequestedWidth = mRequestedWidth;
660 mLastRequestedHeight = mRequestedHeight;
661 mContentChanged = true;
662 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800663
Craig Mautnereda67292013-04-28 13:50:14 -0700664 mOverscanFrame.set(of);
665 mContentFrame.set(cf);
666 mVisibleFrame.set(vf);
John Spurlock46646232013-09-30 22:32:42 -0400667 mDecorFrame.set(dcf);
Adrian Roosfa104232014-06-20 16:10:14 -0700668 mStableFrame.set(sf);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700669 final boolean hasOutsets = osf != null;
670 if (hasOutsets) {
671 mOutsetFrame.set(osf);
672 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800673
Craig Mautnereda67292013-04-28 13:50:14 -0700674 final int fw = mFrame.width();
675 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800676
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700677 float x, y;
678 if (mEnforceSizeCompat) {
679 x = mAttrs.x * mGlobalScale;
680 y = mAttrs.y * mGlobalScale;
681 } else {
682 x = mAttrs.x;
683 y = mAttrs.y;
684 }
685
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700686 if (nonFullscreenTask) {
Wale Ogunwaleb171abb2015-04-22 12:47:17 -0700687 // Make sure window fits in containing frame since it is in a non-fullscreen stack as
688 // required by {@link Gravity#apply} call.
689 w = Math.min(w, pw);
690 h = Math.min(h, ph);
691 }
692
Craig Mautner967212c2013-04-13 21:10:58 -0700693 Gravity.apply(mAttrs.gravity, w, h, mContainingFrame,
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700694 (int) (x + mAttrs.horizontalMargin * pw),
Craig Mautnereda67292013-04-28 13:50:14 -0700695 (int) (y + mAttrs.verticalMargin * ph), mFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800696
Wale Ogunwale94596652015-02-06 19:27:34 -0800697 // Now make sure the window fits in the overall display frame.
698 Gravity.applyDisplay(mAttrs.gravity, mDisplayFrame, mFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800699
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700700 // Calculate the outsets before the content frame gets shrinked to the window frame.
701 if (hasOutsets) {
702 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
703 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
704 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
705 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
706 } else {
707 mOutsets.set(0, 0, 0, 0);
708 }
709
Craig Mautnera248eee2013-05-07 11:41:27 -0700710 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800711 // final window frame.
Skuhnef932e562015-08-20 12:07:30 -0700712 if (freeformWorkspace && !mFrame.isEmpty()) {
Skuhne81c524a2015-08-12 13:34:14 -0700713 // Keep the frame out of the blocked system area, limit it in size to the content area
714 // and make sure that there is always a minimum visible so that the user can drag it
715 // into a usable area..
716 final int height = Math.min(mFrame.height(), mContentFrame.height());
717 final int width = Math.min(mContentFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700718 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700719 final int minVisibleHeight = WindowManagerService.dipToPixel(
720 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics);
721 final int minVisibleWidth = WindowManagerService.dipToPixel(
722 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics);
Skuhne81c524a2015-08-12 13:34:14 -0700723 final int top = Math.max(mContentFrame.top,
724 Math.min(mFrame.top, mContentFrame.bottom - minVisibleHeight));
725 final int left = Math.max(mContentFrame.left + minVisibleWidth - width,
726 Math.min(mFrame.left, mContentFrame.right - minVisibleWidth));
727 mFrame.set(left, top, left + width, top + height);
728 mContentFrame.set(mFrame);
729 mVisibleFrame.set(mContentFrame);
730 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700731 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800732 if (isVisibleLw()) {
733 // We don't adjust the dock divider frame for reasons other than performance. The
734 // real reason is that if it gets adjusted before it is shown for the first time,
735 // it would get size (0, 0). This causes a problem when we finally show the dock
736 // divider and try to draw to it. We do set the surface size at that moment to
737 // the correct size, but it's too late for the Surface Flinger to make it
738 // available for view rendering and as a result the renderer receives size 1, 1.
739 // This way we just keep the divider at the original size and Surface Flinger
740 // will return the correct value to the renderer.
741 mDisplayContent.getDockedDividerController().positionDockedStackedDivider(mFrame);
742 mContentFrame.set(mFrame);
743 }
Skuhne81c524a2015-08-12 13:34:14 -0700744 } else {
745 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
746 Math.max(mContentFrame.top, mFrame.top),
747 Math.min(mContentFrame.right, mFrame.right),
748 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800749
Skuhne81c524a2015-08-12 13:34:14 -0700750 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
751 Math.max(mVisibleFrame.top, mFrame.top),
752 Math.min(mVisibleFrame.right, mFrame.right),
753 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800754
Skuhne81c524a2015-08-12 13:34:14 -0700755 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
756 Math.max(mStableFrame.top, mFrame.top),
757 Math.min(mStableFrame.right, mFrame.right),
758 Math.min(mStableFrame.bottom, mFrame.bottom));
759 }
Adrian Roosfa104232014-06-20 16:10:14 -0700760
Craig Mautnerc36c8e62013-05-10 13:33:31 -0700761 mOverscanInsets.set(Math.max(mOverscanFrame.left - mFrame.left, 0),
762 Math.max(mOverscanFrame.top - mFrame.top, 0),
Adrian Roos3236f3a2014-12-09 15:06:40 +0000763 Math.max(mFrame.right - mOverscanFrame.right, 0),
764 Math.max(mFrame.bottom - mOverscanFrame.bottom, 0));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800765
Craig Mautnereda67292013-04-28 13:50:14 -0700766 mContentInsets.set(mContentFrame.left - mFrame.left,
767 mContentFrame.top - mFrame.top,
768 mFrame.right - mContentFrame.right,
769 mFrame.bottom - mContentFrame.bottom);
770
771 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
772 mVisibleFrame.top - mFrame.top,
773 mFrame.right - mVisibleFrame.right,
774 mFrame.bottom - mVisibleFrame.bottom);
775
Adrian Roosfa104232014-06-20 16:10:14 -0700776 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
777 Math.max(mStableFrame.top - mFrame.top, 0),
778 Math.max(mFrame.right - mStableFrame.right, 0),
779 Math.max(mFrame.bottom - mStableFrame.bottom, 0));
780
Craig Mautnereda67292013-04-28 13:50:14 -0700781 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400782 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700783 // If there is a size compatibility scale being applied to the
784 // window, we need to apply this to its insets so that they are
785 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700786 mOverscanInsets.scale(mInvGlobalScale);
787 mContentInsets.scale(mInvGlobalScale);
788 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700789 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700790 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700791
792 // Also the scaled frame that we report to the app needs to be
793 // adjusted to be in its coordinate space.
794 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400795 }
796
Craig Mautnereda67292013-04-28 13:50:14 -0700797 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800798 final DisplayContent displayContent = getDisplayContent();
799 if (displayContent != null) {
800 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700801 mService.mWallpaperControllerLocked.updateWallpaperOffset(
802 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800803 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800804 }
805
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700806 if (DEBUG_LAYOUT || WindowManagerService.localLOGV) Slog.v(TAG,
807 "Resolving (mRequestedWidth="
808 + mRequestedWidth + ", mRequestedheight="
809 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
810 + "): frame=" + mFrame.toShortString()
811 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -0700812 + " vi=" + mVisibleInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700813 + " vi=" + mStableInsets.toShortString()
814 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800815 }
816
Craig Mautnera2c77052012-03-26 12:14:43 -0700817 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800818 public Rect getFrameLw() {
819 return mFrame;
820 }
821
Craig Mautnera2c77052012-03-26 12:14:43 -0700822 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700823 public Point getShownPositionLw() {
824 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800825 }
826
Craig Mautnera2c77052012-03-26 12:14:43 -0700827 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800828 public Rect getDisplayFrameLw() {
829 return mDisplayFrame;
830 }
831
Craig Mautnera2c77052012-03-26 12:14:43 -0700832 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800833 public Rect getOverscanFrameLw() {
834 return mOverscanFrame;
835 }
836
837 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800838 public Rect getContentFrameLw() {
839 return mContentFrame;
840 }
841
Craig Mautnera2c77052012-03-26 12:14:43 -0700842 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800843 public Rect getVisibleFrameLw() {
844 return mVisibleFrame;
845 }
846
Craig Mautnera2c77052012-03-26 12:14:43 -0700847 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800848 public boolean getGivenInsetsPendingLw() {
849 return mGivenInsetsPending;
850 }
851
Craig Mautnera2c77052012-03-26 12:14:43 -0700852 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800853 public Rect getGivenContentInsetsLw() {
854 return mGivenContentInsets;
855 }
856
Craig Mautnera2c77052012-03-26 12:14:43 -0700857 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800858 public Rect getGivenVisibleInsetsLw() {
859 return mGivenVisibleInsets;
860 }
861
Craig Mautnera2c77052012-03-26 12:14:43 -0700862 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800863 public WindowManager.LayoutParams getAttrs() {
864 return mAttrs;
865 }
866
Craig Mautner812d2ca2012-09-27 15:35:34 -0700867 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800868 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
869 int index = -1;
870 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -0700871 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800872 while (true) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -0700873 if (ws.mAttrs.needsMenuKey != WindowManager.LayoutParams.NEEDS_MENU_UNSET) {
874 return ws.mAttrs.needsMenuKey == WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800875 }
876 // If we reached the bottom of the range of windows we are considering,
877 // assume no menu is needed.
878 if (ws == bottom) {
879 return false;
880 }
881 // The current window hasn't specified whether menu key is needed;
882 // look behind it.
883 // First, we may need to determine the starting position.
884 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -0700885 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800886 }
887 index--;
888 if (index < 0) {
889 return false;
890 }
Craig Mautner59c00972012-07-30 12:10:24 -0700891 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800892 }
893 }
894
Craig Mautner19d59bc2012-09-04 11:15:56 -0700895 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700896 public int getSystemUiVisibility() {
897 return mSystemUiVisibility;
898 }
899
Craig Mautner19d59bc2012-09-04 11:15:56 -0700900 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800901 public int getSurfaceLayer() {
902 return mLayer;
903 }
904
Craig Mautner812d2ca2012-09-27 15:35:34 -0700905 @Override
Selim Cinekd6623612015-05-22 18:56:22 -0700906 public int getBaseType() {
907 WindowState win = this;
908 while (win.mAttachedWindow != null) {
909 win = win.mAttachedWindow;
910 }
911 return win.mAttrs.type;
912 }
913
914 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800915 public IApplicationToken getAppToken() {
916 return mAppToken != null ? mAppToken.appToken : null;
917 }
Craig Mautner19d59bc2012-09-04 11:15:56 -0700918
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700919 @Override
920 public boolean isVoiceInteraction() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700921 return mAppToken != null && mAppToken.voiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700922 }
923
Craig Mautner4c5eb222013-11-18 12:59:05 -0800924 boolean setInsetsChanged() {
925 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
926 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
927 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -0700928 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700929 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
930 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
931 || mOutsetsChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -0800932 }
933
Craig Mautnerdf88d732014-01-27 09:21:32 -0800934 public DisplayContent getDisplayContent() {
Chad Jonesf391ebc2014-06-12 17:45:05 -0700935 if (mAppToken == null || mNotOnAppsDisplay) {
Craig Mautnerbe634952014-06-12 13:39:24 -0700936 return mDisplayContent;
937 }
938 final TaskStack stack = getStack();
939 return stack == null ? mDisplayContent : stack.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -0800940 }
941
Chong Zhang09b21ef2015-09-14 10:20:21 -0700942 public DisplayInfo getDisplayInfo() {
943 final DisplayContent displayContent = getDisplayContent();
944 return displayContent != null ? displayContent.getDisplayInfo() : null;
945 }
946
Craig Mautner19d59bc2012-09-04 11:15:56 -0700947 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800948 final DisplayContent displayContent = getDisplayContent();
949 if (displayContent == null) {
950 return -1;
951 }
952 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -0700953 }
954
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700955 Task getTask() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700956 return mAppToken != null ? mAppToken.mTask : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700957 }
958
959 TaskStack getStack() {
960 Task task = getTask();
961 if (task != null) {
962 if (task.mStack != null) {
963 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -0700964 }
Craig Mautnerd9a22882013-03-16 15:00:36 -0700965 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700966 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
967 // associate them with some stack to enable dimming.
968 return mAttrs.type >= WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
969 && mDisplayContent != null ? mDisplayContent.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -0700970 }
971
Skuhnef932e562015-08-20 12:07:30 -0700972 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700973 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -0700974 * @param bounds The rect which gets the bounds.
975 * @param forTouch Pass in BOUNDS_FOR_TOUCH to get touch related bounds, otherwise visible
976 * bounds will be returned.
977 */
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700978 void getVisibleBounds(Rect bounds, boolean forTouch) {
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700979 boolean intersectWithStackBounds = mAppToken != null && mAppToken.mCropWindowsToStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700980 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700981 mTmpRect.setEmpty();
982 if (intersectWithStackBounds) {
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700983 final TaskStack stack = getStack();
984 if (stack != null) {
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700985 stack.getBounds(mTmpRect);
986 } else {
987 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700988 }
989 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700990
Chong Zhang9184ec62015-09-24 12:32:21 -0700991 bounds.set(mVisibleFrame);
992 if (intersectWithStackBounds) {
993 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700994 }
995
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700996 if (bounds.isEmpty()) {
997 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700998 if (intersectWithStackBounds) {
999 bounds.intersect(mTmpRect);
1000 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001001 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001002 }
Chong Zhang9184ec62015-09-24 12:32:21 -07001003 if (forTouch && inFreeformWorkspace()) {
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001004 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001005 final int delta = WindowManagerService.dipToPixel(
1006 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001007 bounds.inset(-delta, -delta);
1008 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001009 }
1010
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001011 public long getInputDispatchingTimeoutNanos() {
1012 return mAppToken != null
1013 ? mAppToken.inputDispatchingTimeoutNanos
1014 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1015 }
1016
Craig Mautnere8552142012-11-07 13:55:47 -08001017 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001018 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001019 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001020 }
1021
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001022 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1023 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1024 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1025 if (dtdx < -.000001f || dtdx > .000001f) return false;
1026 if (dsdy < -.000001f || dsdy > .000001f) return false;
1027 return true;
1028 }
1029
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001030 void prelayout() {
1031 if (mEnforceSizeCompat) {
1032 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001033 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001034 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001035 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001036 }
1037 }
1038
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001039 /**
1040 * Is this window visible? It is not visible if there is no
1041 * surface, or we are in the process of running an exit animation
1042 * that will remove the surface, or its app token has been hidden.
1043 */
Craig Mautner88400d32012-09-30 12:35:45 -07001044 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001045 public boolean isVisibleLw() {
1046 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001047 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001048 && (atoken == null || !atoken.hiddenRequested)
1049 && !mExiting && !mDestroying;
1050 }
1051
1052 /**
1053 * Like {@link #isVisibleLw}, but also counts a window that is currently
1054 * "hidden" behind the keyguard as visible. This allows us to apply
1055 * things like window flags that impact the keyguard.
1056 * XXX I am starting to think we need to have ANOTHER visibility flag
1057 * for this "hidden behind keyguard" state rather than overloading
1058 * mPolicyVisibility. Ungh.
1059 */
Craig Mautner88400d32012-09-30 12:35:45 -07001060 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001061 public boolean isVisibleOrBehindKeyguardLw() {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001062 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -08001063 mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001064 return false;
1065 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001066 final AppWindowToken atoken = mAppToken;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001067 final boolean animating = atoken != null && atoken.mAppAnimator.animation != null;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001068 return mHasSurface && !mDestroying && !mExiting
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001069 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001070 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
1071 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001072 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001073 }
1074
1075 /**
1076 * Is this window visible, ignoring its app token? It is not visible
1077 * if there is no surface, or we are in the process of running an exit animation
1078 * that will remove the surface.
1079 */
1080 public boolean isWinVisibleLw() {
1081 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001082 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautner59431632012-04-04 11:56:44 -07001083 && (atoken == null || !atoken.hiddenRequested || atoken.mAppAnimator.animating)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001084 && !mExiting && !mDestroying;
1085 }
1086
1087 /**
1088 * The same as isVisible(), but follows the current hidden state of
1089 * the associated app token, not the pending requested hidden state.
1090 */
1091 boolean isVisibleNow() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001092 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07001093 && (!mRootToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
1094 && !mExiting && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001095 }
1096
1097 /**
1098 * Can this window possibly be a drag/drop target? The test here is
1099 * a combination of the above "visible now" with the check that the
1100 * Input Manager uses when discarding windows from input consideration.
1101 */
1102 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001103 return isVisibleNow() && !mRemoved
1104 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001105 }
1106
1107 /**
1108 * Same as isVisible(), but we also count it as visible between the
1109 * call to IWindowSession.add() and the first relayout().
1110 */
1111 boolean isVisibleOrAdding() {
1112 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001113 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001114 && mPolicyVisibility && !mAttachedHidden
1115 && (atoken == null || !atoken.hiddenRequested)
1116 && !mExiting && !mDestroying;
1117 }
1118
1119 /**
1120 * Is this window currently on-screen? It is on-screen either if it
1121 * is visible or it is currently running an animation before no longer
1122 * being visible.
1123 */
1124 boolean isOnScreen() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001125 return mPolicyVisibility && isOnScreenIgnoringKeyguard();
1126 }
1127
1128 /**
1129 * Like isOnScreen(), but ignores any force hiding of the window due
1130 * to the keyguard.
1131 */
1132 boolean isOnScreenIgnoringKeyguard() {
1133 if (!mHasSurface || mDestroying) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001134 return false;
1135 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001136 final AppWindowToken atoken = mAppToken;
1137 if (atoken != null) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001138 return ((!mAttachedHidden && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001139 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001140 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001141 return !mAttachedHidden || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001142 }
1143
1144 /**
1145 * Like isOnScreen(), but we don't return true if the window is part
1146 * of a transition that has not yet been started.
1147 */
1148 boolean isReadyForDisplay() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001149 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001150 return false;
1151 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001152 return mHasSurface && mPolicyVisibility && !mDestroying
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001153 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
1154 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001155 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001156 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001157 }
1158
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001159 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001160 * Like isReadyForDisplay(), but ignores any force hiding of the window due
1161 * to the keyguard.
1162 */
1163 boolean isReadyForDisplayIgnoringKeyguard() {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001164 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001165 return false;
1166 }
1167 final AppWindowToken atoken = mAppToken;
1168 if (atoken == null && !mPolicyVisibility) {
1169 // If this is not an app window, and the policy has asked to force
1170 // hide, then we really do want to hide.
1171 return false;
1172 }
1173 return mHasSurface && !mDestroying
1174 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
1175 && !mRootToken.hidden)
1176 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -07001177 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
1178 && !mWinAnimator.isDummyAnimation()));
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001179 }
1180
1181 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001182 * Like isOnScreen, but returns false if the surface hasn't yet
1183 * been drawn.
1184 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001185 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001186 public boolean isDisplayedLw() {
1187 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001188 return isDrawnLw() && mPolicyVisibility
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001189 && ((!mAttachedHidden &&
1190 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001191 || mWinAnimator.mAnimating
1192 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001193 }
1194
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001195 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001196 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001197 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001198 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001199 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001200 return mWinAnimator.mAnimation != null
1201 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001202 }
1203
Craig Mautner812d2ca2012-09-27 15:35:34 -07001204 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001205 public boolean isGoneForLayoutLw() {
1206 final AppWindowToken atoken = mAppToken;
1207 return mViewVisibility == View.GONE
1208 || !mRelayoutCalled
1209 || (atoken == null && mRootToken.hidden)
Craig Mautner812d2ca2012-09-27 15:35:34 -07001210 || (atoken != null && (atoken.hiddenRequested || atoken.hidden))
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001211 || mAttachedHidden
Craig Mautner0e415c62013-04-29 16:10:58 -07001212 || (mExiting && !isAnimatingLw())
1213 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001214 }
1215
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001216 /**
1217 * Returns true if the window has a surface that it has drawn a
1218 * complete UI in to.
1219 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001220 public boolean isDrawFinishedLw() {
1221 return mHasSurface && !mDestroying &&
1222 (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING
1223 || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1224 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
1225 }
1226
1227 /**
1228 * Returns true if the window has a surface that it has drawn a
1229 * complete UI in to.
1230 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001231 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001232 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001233 return mHasSurface && !mDestroying &&
Craig Mautner749a7bb2012-04-02 13:49:53 -07001234 (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1235 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001236 }
1237
1238 /**
1239 * Return true if the window is opaque and fully drawn. This indicates
1240 * it may obscure windows behind it.
1241 */
1242 boolean isOpaqueDrawn() {
1243 return (mAttrs.format == PixelFormat.OPAQUE
1244 || mAttrs.type == TYPE_WALLPAPER)
Craig Mautnera2c77052012-03-26 12:14:43 -07001245 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001246 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001247 }
1248
1249 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001250 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001251 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1252 */
Craig Mautner4557c082015-04-27 13:07:40 -07001253 boolean hasMoved() {
1254 return mHasSurface && mContentChanged && !mExiting && !mWinAnimator.mLastHidden
1255 && mService.okToDisplay() && (mFrame.top != mLastFrame.top
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001256 || mFrame.left != mLastFrame.left)
Craig Mautner4557c082015-04-27 13:07:40 -07001257 && (mAttachedWindow == null || !mAttachedWindow.hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001258 }
1259
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001260 boolean isFullscreen(int screenWidth, int screenHeight) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001261 return mFrame.left <= 0 && mFrame.top <= 0 &&
1262 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001263 }
1264
Craig Mautner812d2ca2012-09-27 15:35:34 -07001265 boolean isConfigChanged() {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001266 final Task task = getTask();
Wale Ogunwale60454db2015-01-23 16:05:07 -08001267 final Configuration overrideConfig =
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001268 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001269 final Configuration serviceConfig = mService.mCurConfiguration;
1270 boolean configChanged =
1271 (mConfiguration != serviceConfig && mConfiguration.diff(serviceConfig) != 0)
1272 || (mOverrideConfig != overrideConfig && !mOverrideConfig.equals(overrideConfig));
Craig Mautnere8552142012-11-07 13:55:47 -08001273
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001274 if ((mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Craig Mautnere8552142012-11-07 13:55:47 -08001275 // Retain configuration changed status until resetConfiguration called.
1276 mConfigHasChanged |= configChanged;
1277 configChanged = mConfigHasChanged;
1278 }
1279
1280 return configChanged;
Craig Mautner812d2ca2012-09-27 15:35:34 -07001281 }
1282
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001283 void removeLocked() {
1284 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001285
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001286 if (mAttachedWindow != null) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001287 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001288 mAttachedWindow.mChildWindows.remove(this);
1289 }
Craig Mautner96868332012-12-04 14:29:11 -08001290 mWinAnimator.destroyDeferredSurfaceLocked();
1291 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001292 mSession.windowRemovedLocked();
1293 try {
1294 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1295 } catch (RuntimeException e) {
1296 // Ignore if it has already been removed (usually because
1297 // we are doing this as part of processing a death note.)
1298 }
1299 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001300
Wale Ogunwale60454db2015-01-23 16:05:07 -08001301 private void setConfiguration(
1302 final Configuration newConfig, final Configuration newOverrideConfig) {
Craig Mautnere8552142012-11-07 13:55:47 -08001303 mConfiguration = newConfig;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001304 mOverrideConfig = newOverrideConfig;
Craig Mautnere8552142012-11-07 13:55:47 -08001305 mConfigHasChanged = false;
1306 }
1307
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001308 void setHasSurface(boolean hasSurface) {
1309 mHasSurface = hasSurface;
1310 }
1311
Chong Zhangacf11402015-11-04 16:23:10 -08001312 private final class DeadWindowEventReceiver extends InputEventReceiver {
1313 DeadWindowEventReceiver(InputChannel inputChannel) {
1314 super(inputChannel, mService.mH.getLooper());
1315 }
1316 @Override
1317 public void onInputEvent(InputEvent event) {
1318 finishInputEvent(event, true);
1319 }
1320 }
1321 /**
1322 * Dummy event receiver for windows that died visible.
1323 */
1324 private DeadWindowEventReceiver mDeadWindowEventReceiver;
1325
Chong Zhang112eb8c2015-11-02 11:17:00 -08001326 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001327 if (mInputChannel != null) {
1328 throw new IllegalStateException("Window already has an input channel.");
1329 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001330 String name = makeInputChannelName();
1331 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1332 mInputChannel = inputChannels[0];
1333 mClientChannel = inputChannels[1];
1334 mInputWindowHandle.inputChannel = inputChannels[0];
1335 if (outInputChannel != null) {
1336 mClientChannel.transferTo(outInputChannel);
1337 mClientChannel.dispose();
1338 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08001339 } else {
1340 // If the window died visible, we setup a dummy input channel, so that taps
1341 // can still detected by input monitor channel, and we can relaunch the app.
1342 // Create dummy event receiver that simply reports all events as handled.
1343 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08001344 }
1345 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001346 }
1347
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001348 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08001349 if (mDeadWindowEventReceiver != null) {
1350 mDeadWindowEventReceiver.dispose();
1351 mDeadWindowEventReceiver = null;
1352 }
1353
1354 // unregister server channel first otherwise it complains about broken channel
1355 if (mInputChannel != null) {
1356 mService.mInputManager.unregisterInputChannel(mInputChannel);
1357 mInputChannel.dispose();
1358 mInputChannel = null;
1359 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001360 if (mClientChannel != null) {
1361 mClientChannel.dispose();
1362 mClientChannel = null;
1363 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001364 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001365 }
1366
Chong Zhang112eb8c2015-11-02 11:17:00 -08001367 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08001368 // When the app is terminated (eg. from Recents), the task might have already been
1369 // removed with the window pending removal. Don't apply dim in such cases, as there
1370 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
1371 final AppWindowToken token = mAppToken;
1372 if (token != null && token.removed) {
1373 return;
1374 }
1375
Chong Zhang112eb8c2015-11-02 11:17:00 -08001376 if (!mExiting && mAppDied) {
1377 // If app died visible, apply a dim over the window to indicate that it's inactive
1378 mDisplayContent.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
1379 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
1380 && mDisplayContent != null && !mExiting && isDisplayedLw()) {
1381 mDisplayContent.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001382 }
1383 }
1384
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001385 DimLayer.DimLayerUser getDimLayerUser() {
1386 Task task = getTask();
1387 if (task != null) {
1388 return task;
1389 }
1390 return getStack();
1391 }
1392
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001393 void maybeRemoveReplacedWindow() {
1394 AppWindowToken token = mAppToken;
Filip Gruszczynski78a08ee2015-11-08 18:04:32 -08001395 if (token != null && token.mWillReplaceWindow && token.mReplacingWindow == this
1396 && token.mHasReplacedWindow) {
Filip Gruszczynskib6e66622015-10-25 16:05:27 -07001397 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replacing window: " + this);
1398 token.mWillReplaceWindow = false;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001399 token.mAnimateReplacingWindow = false;
1400 token.mReplacingRemoveRequested = false;
Filip Gruszczynskib6e66622015-10-25 16:05:27 -07001401 token.mReplacingWindow = null;
Filip Gruszczynski78a08ee2015-11-08 18:04:32 -08001402 token.mHasReplacedWindow = false;
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001403 for (int i = token.allAppWindows.size() - 1; i >= 0; i--) {
Filip Gruszczynski78a08ee2015-11-08 18:04:32 -08001404 final WindowState win = token.allAppWindows.get(i);
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001405 if (win.mExiting) {
1406 mService.removeWindowInnerLocked(win);
1407 }
1408 }
1409 }
1410 }
1411
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07001412 void setDisplayLayoutNeeded() {
1413 if (mDisplayContent != null) {
1414 mDisplayContent.layoutNeeded = true;
1415 }
1416 }
1417
Filip Gruszczynski955b2fc2015-10-15 14:46:07 -07001418 boolean inDockedWorkspace() {
1419 return mAppToken != null && mAppToken.mTask != null && mAppToken.mTask.inDockedWorkspace();
1420 }
1421
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001422 int getTouchableRegion(Region region, int flags, InputMonitor inputMonitor) {
1423 final boolean modal = (flags & (WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
1424 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) == 0;
1425 if (modal && mAppToken != null) {
1426 // Limit the outer touch to the activity stack region.
1427 flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
1428 if (!inFreeformWorkspace()) {
1429 // If this is a modal window we need to dismiss it if it's not full screen and the
1430 // touch happens outside of the frame that displays the content. This means we
1431 // need to intercept touches outside of that window. The dim layer user
1432 // associated with the window (task or stack) will give us the good bounds, as
1433 // they would be used to display the dim layer.
1434 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1435 if (dimLayerUser != null) {
1436 dimLayerUser.getBounds(mTmpRect);
1437 } else {
1438 getVisibleBounds(mTmpRect, BOUNDS_FOR_TOUCH);
1439 }
1440 } else {
1441 // For freeform windows we the touch region to include the whole surface for the
1442 // shadows.
1443 getVisibleBounds(mTmpRect, BOUNDS_FOR_TOUCH);
1444 }
1445 region.set(mTmpRect);
1446 } else {
1447 // Not modal or full screen modal
1448 getTouchableRegion(region);
1449 }
1450 return flags;
1451 }
1452
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001453 void checkPolicyVisibilityChange() {
1454 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
1455 if (DEBUG_VISIBILITY) {
1456 Slog.v(TAG, "Policy visibility changing after anim in " +
1457 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
1458 }
1459 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001460 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001461 if (!mPolicyVisibility) {
1462 if (mService.mCurrentFocus == this) {
1463 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
1464 "setAnimationLocked: setting mFocusMayChange true");
1465 mService.mFocusMayChange = true;
1466 }
1467 // Window is no longer visible -- make sure if we were waiting
1468 // for it to be displayed before enabling the display, that
1469 // we allow the display to be enabled now.
1470 mService.enableScreenIfNeededLocked();
1471 }
1472 }
1473 }
1474
1475 void setRequestedSize(int requestedWidth, int requestedHeight) {
1476 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
1477 mLayoutNeeded = true;
1478 mRequestedWidth = requestedWidth;
1479 mRequestedHeight = requestedHeight;
1480 }
1481 }
1482
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001483 void prepareWindowToDisplayDuringRelayout(Configuration outConfig) {
1484 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
1485 == SOFT_INPUT_ADJUST_RESIZE) {
1486 mLayoutNeeded = true;
1487 }
1488 if (isDrawnLw() && mService.okToDisplay()) {
1489 mWinAnimator.applyEnterAnimationLocked();
1490 }
1491 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
1492 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
1493 mTurnOnScreen = true;
1494 }
1495 if (isConfigChanged()) {
1496 if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + this + " visible with new config: "
1497 + mService.mCurConfiguration);
1498 outConfig.setTo(mService.mCurConfiguration);
1499 }
1500 }
1501
1502 void adjustStartingWindowFlags() {
1503 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
1504 && mAppToken.startingWindow != null) {
1505 // Special handling of starting window over the base
1506 // window of the app: propagate lock screen flags to it,
1507 // to provide the correct semantics while starting.
1508 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
1509 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
1510 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
1511 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
1512 }
1513 }
1514
1515 void setWindowScale(int requestedWidth, int requestedHeight) {
1516 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
1517
1518 if (scaledWindow) {
1519 // requested{Width|Height} Surface's physical size
1520 // attrs.{width|height} Size on screen
1521 // TODO: We don't check if attrs != null here. Is it implicitly checked?
1522 mHScale = (mAttrs.width != requestedWidth) ?
1523 (mAttrs.width / (float)requestedWidth) : 1.0f;
1524 mVScale = (mAttrs.height != requestedHeight) ?
1525 (mAttrs.height / (float)requestedHeight) : 1.0f;
1526 } else {
1527 mHScale = mVScale = 1;
1528 }
1529 }
1530
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001531 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08001532 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001533 public void binderDied() {
1534 try {
1535 synchronized(mService.mWindowMap) {
1536 WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07001537 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001538 if (win != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001539 if (win.mAppToken != null && !win.mAppToken.clientHidden) {
1540 win.mAppToken.appDied = true;
1541 }
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001542 mService.removeWindowLocked(win);
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001543 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08001544 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001545 mService.removeWindowLocked(WindowState.this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001546 }
1547 }
1548 } catch (IllegalArgumentException ex) {
1549 // This will happen if the window has already been
1550 // removed.
1551 }
1552 }
1553 }
1554
Craig Mautner58106812012-12-28 12:27:40 -08001555 /**
1556 * @return true if this window desires key events.
Craig Mautneref25d7a2012-05-15 23:01:47 -07001557 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001558 public final boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08001559 return isVisibleOrAdding()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001560 && (mViewVisibility == View.VISIBLE)
1561 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
1562 }
1563
Craig Mautner749a7bb2012-04-02 13:49:53 -07001564 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001565 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001566 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001567 }
1568
Craig Mautner749a7bb2012-04-02 13:49:53 -07001569 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001570 public boolean showLw(boolean doAnimation) {
1571 return showLw(doAnimation, true);
1572 }
1573
1574 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07001575 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001576 return false;
1577 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001578 if (!mAppOpVisibility) {
1579 // Being hidden due to app op request.
1580 return false;
1581 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001582 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001583 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001584 return false;
1585 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001586 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001587 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001588 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07001589 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07001590 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001591 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07001592 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001593 // Check for the case where we are currently visible and
1594 // not animating; we do not want to do animation at such a
1595 // point to become visible when we already are.
1596 doAnimation = false;
1597 }
1598 }
1599 mPolicyVisibility = true;
1600 mPolicyVisibilityAfterAnim = true;
1601 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001602 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001603 }
1604 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001605 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001606 }
1607 return true;
1608 }
1609
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001610 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001611 public boolean hideLw(boolean doAnimation) {
1612 return hideLw(doAnimation, true);
1613 }
1614
1615 boolean hideLw(boolean doAnimation, boolean requestAnim) {
1616 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07001617 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001618 doAnimation = false;
1619 }
1620 }
1621 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
1622 : mPolicyVisibility;
1623 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001624 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001625 return false;
1626 }
1627 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001628 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07001629 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001630 doAnimation = false;
1631 }
1632 }
1633 if (doAnimation) {
1634 mPolicyVisibilityAfterAnim = false;
1635 } else {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001636 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001637 mPolicyVisibilityAfterAnim = false;
1638 mPolicyVisibility = false;
1639 // Window is no longer visible -- make sure if we were waiting
1640 // for it to be displayed before enabling the display, that
1641 // we allow the display to be enabled now.
1642 mService.enableScreenIfNeededLocked();
1643 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001644 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07001645 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001646 mService.mFocusMayChange = true;
1647 }
1648 }
1649 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001650 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001651 }
1652 return true;
1653 }
1654
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001655 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001656 if (mAppOpVisibility != state) {
1657 mAppOpVisibility = state;
1658 if (state) {
1659 // If the policy visibility had last been to hide, then this
1660 // will incorrectly show at this point since we lost that
1661 // information. Not a big deal -- for the windows that have app
1662 // ops modifies they should only be hidden by policy due to the
1663 // lock screen, and the user won't be changing this if locked.
1664 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001665 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001666 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001667 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001668 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001669 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001670 }
1671
Jeff Brownc2932a12014-11-20 18:04:05 -08001672 public void pokeDrawLockLw(long timeout) {
1673 if (isVisibleOrAdding()) {
1674 if (mDrawLock == null) {
1675 // We want the tag name to be somewhat stable so that it is easier to correlate
1676 // in wake lock statistics. So in particular, we don't want to include the
1677 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001678 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08001679 mDrawLock = mService.mPowerManager.newWakeLock(
1680 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
1681 mDrawLock.setReferenceCounted(false);
1682 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
1683 }
1684 // Each call to acquire resets the timeout.
1685 if (DEBUG_POWER) {
1686 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
1687 + mAttrs.packageName);
1688 }
1689 mDrawLock.acquire(timeout);
1690 } else if (DEBUG_POWER) {
1691 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
1692 + "owned by " + mAttrs.packageName);
1693 }
1694 }
1695
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001696 @Override
1697 public boolean isAlive() {
1698 return mClient.asBinder().isBinderAlive();
1699 }
1700
Craig Mautnera987d432012-10-11 14:07:58 -07001701 boolean isClosing() {
1702 return mExiting || (mService.mClosingApps.contains(mAppToken));
1703 }
1704
Chong Zhangbef461f2015-10-27 11:38:24 -07001705 boolean isAnimatingWithSavedSurface() {
1706 return mAppToken != null && mAppToken.mAnimatingWithSavedSurface;
1707 }
1708
1709 boolean shouldSaveSurface() {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001710 if (ActivityManager.isLowRamDeviceStatic()) {
1711 // Don't save surfaces on Svelte devices.
1712 return false;
1713 }
1714
1715 Task task = getTask();
Chong Zhangbef461f2015-10-27 11:38:24 -07001716 if (task == null || task.inHomeStack()
1717 || task.getTopAppWindowToken() != mAppToken) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001718 // Don't save surfaces for home stack apps. These usually resume and draw
1719 // first frame very fast. Saving surfaces are mostly a waste of memory.
Chong Zhangbef461f2015-10-27 11:38:24 -07001720 // Don't save if the window is not the topmost window.
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001721 return false;
1722 }
1723
Chong Zhangbef461f2015-10-27 11:38:24 -07001724 return mAppToken.shouldSaveSurface();
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001725 }
1726
Craig Mautner69b08182012-09-05 13:07:13 -07001727 @Override
1728 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001729 final DisplayContent displayContent = getDisplayContent();
1730 if (displayContent == null) {
1731 // Only a window that was on a non-default display can be detached from it.
1732 return false;
1733 }
Winson Chung47a3e652014-05-21 16:03:42 -07001734 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07001735 }
1736
Adrian Rooscd3884d2015-02-18 17:25:23 +01001737 @Override
1738 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001739 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1740 return dimLayerUser != null && mDisplayContent != null &&
Chong Zhang112eb8c2015-11-02 11:17:00 -08001741 mDisplayContent.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01001742 }
1743
Craig Mautner88400d32012-09-30 12:35:45 -07001744 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
1745 mShowToOwnerOnly = showToOwnerOnly;
1746 }
1747
Craig Mautner5962b122012-10-05 14:45:52 -07001748 boolean isHiddenFromUserLocked() {
Craig Mautner341220f2012-10-16 15:20:09 -07001749 // Attached windows are evaluated based on the window that they are attached to.
1750 WindowState win = this;
1751 while (win.mAttachedWindow != null) {
1752 win = win.mAttachedWindow;
1753 }
1754 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -07001755 && win.mAppToken != null && win.mAppToken.showForAllUsers) {
Craig Mautner341220f2012-10-16 15:20:09 -07001756 // Save some cycles by not calling getDisplayInfo unless it is an application
1757 // window intended for all users.
Craig Mautnerdf88d732014-01-27 09:21:32 -08001758 final DisplayContent displayContent = win.getDisplayContent();
1759 if (displayContent == null) {
1760 return true;
1761 }
1762 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Craig Mautner341220f2012-10-16 15:20:09 -07001763 if (win.mFrame.left <= 0 && win.mFrame.top <= 0
1764 && win.mFrame.right >= displayInfo.appWidth
1765 && win.mFrame.bottom >= displayInfo.appHeight) {
Craig Mautner5962b122012-10-05 14:45:52 -07001766 // Is a fullscreen window, like the clock alarm. Show to everyone.
1767 return false;
1768 }
1769 }
1770
Craig Mautner341220f2012-10-16 15:20:09 -07001771 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01001772 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001773 }
1774
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001775 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
1776 outRegion.set(
1777 frame.left + inset.left, frame.top + inset.top,
1778 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001779 }
1780
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001781 public void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001782 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001783 switch (mTouchableInsets) {
1784 default:
1785 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
1786 outRegion.set(frame);
1787 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001788 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001789 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001790 break;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001791 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001792 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001793 break;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001794 case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
1795 final Region givenTouchableRegion = mGivenTouchableRegion;
1796 outRegion.set(givenTouchableRegion);
1797 outRegion.translate(frame.left, frame.top);
1798 break;
1799 }
1800 }
1801 }
1802
Craig Mautner59c00972012-07-30 12:10:24 -07001803 WindowList getWindowList() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001804 final DisplayContent displayContent = getDisplayContent();
1805 return displayContent == null ? null : displayContent.getWindowList();
Craig Mautner59c00972012-07-30 12:10:24 -07001806 }
1807
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001808 /**
1809 * Report a focus change. Must be called with no locks held, and consistently
1810 * from the same serialized thread (such as dispatched from a handler).
1811 */
1812 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
1813 try {
1814 mClient.windowFocusChanged(focused, inTouchMode);
1815 } catch (RemoteException e) {
1816 }
1817 if (mFocusCallbacks != null) {
1818 final int N = mFocusCallbacks.beginBroadcast();
1819 for (int i=0; i<N; i++) {
1820 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
1821 try {
1822 if (focused) {
1823 obs.focusGained(mWindowId.asBinder());
1824 } else {
1825 obs.focusLost(mWindowId.asBinder());
1826 }
1827 } catch (RemoteException e) {
1828 }
1829 }
1830 mFocusCallbacks.finishBroadcast();
1831 }
1832 }
1833
Craig Mautnerdf88d732014-01-27 09:21:32 -08001834 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001835 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08001836 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001837 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
1838 + ": " + mCompatFrame);
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001839 final boolean configChanged = isConfigChanged();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001840 final Task task = getTask();
Wale Ogunwale60454db2015-01-23 16:05:07 -08001841 final Configuration overrideConfig =
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001842 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001843 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) && configChanged) {
1844 Slog.i(TAG, "Sending new config to window " + this + ": "
Robert Carre6a83512015-11-03 16:09:21 -08001845 + " / config="
Wale Ogunwale60454db2015-01-23 16:05:07 -08001846 + mService.mCurConfiguration + " overrideConfig=" + overrideConfig);
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001847 }
Wale Ogunwale60454db2015-01-23 16:05:07 -08001848 setConfiguration(mService.mCurConfiguration, overrideConfig);
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001849 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING)
1850 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
1851
Craig Mautnerdf88d732014-01-27 09:21:32 -08001852 final Rect frame = mFrame;
1853 final Rect overscanInsets = mLastOverscanInsets;
1854 final Rect contentInsets = mLastContentInsets;
1855 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07001856 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001857 final Rect outsets = mLastOutsets;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001858 final boolean reportDraw = mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING;
1859 final Configuration newConfig = configChanged ? mConfiguration : null;
Chet Haase8eb48d22014-09-24 07:31:29 -07001860 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1861 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001862 // To prevent deadlock simulate one-way call if win.mClient is a local object.
1863 mService.mH.post(new Runnable() {
1864 @Override
1865 public void run() {
1866 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001867 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
1868 stableInsets, outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001869 } catch (RemoteException e) {
1870 // Not a remote call, RemoteException won't be raised.
1871 }
1872 }
1873 });
1874 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001875 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001876 outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001877 }
Svetoslav4604abc2014-06-10 18:59:30 -07001878
1879 //TODO (multidisplay): Accessibility supported only for the default display.
1880 if (mService.mAccessibilityController != null
1881 && getDisplayId() == Display.DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07001882 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07001883 }
1884
Craig Mautnerdf88d732014-01-27 09:21:32 -08001885 mOverscanInsetsChanged = false;
1886 mContentInsetsChanged = false;
1887 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07001888 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001889 mOutsetsChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001890 mWinAnimator.mSurfaceResized = false;
1891 } catch (RemoteException e) {
1892 mOrientationChanging = false;
1893 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1894 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08001895 // We are assuming the hosting process is dead or in a zombie state.
1896 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
1897 + ", removing this window.");
1898 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001899 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001900 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001901 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001902 }
1903
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001904 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
1905 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
1906 Configuration newConfig) throws RemoteException {
1907 DisplayInfo displayInfo = getDisplayInfo();
1908 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Chong Zhangd153c4f2015-11-06 20:26:40 -08001909 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
1910 // start even if we haven't received the relayout window, so that the client requests
1911 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
1912 // until the window to small size, otherwise the multithread renderer will shift last
1913 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
1914 // isDragResizing() or isDragResizeChanged() is true.
1915 boolean resizing = isDragResizing() || isDragResizeChanged();
1916 final Rect backDropFrame = (inFreeformWorkspace() || !resizing) ? frame : mTmpRect;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001917 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Chong Zhangd153c4f2015-11-06 20:26:40 -08001918 outsets, reportDraw, newConfig, backDropFrame);
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001919 }
1920
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001921 public void registerFocusObserver(IWindowFocusObserver observer) {
1922 synchronized(mService.mWindowMap) {
1923 if (mFocusCallbacks == null) {
1924 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
1925 }
1926 mFocusCallbacks.register(observer);
1927 }
1928 }
1929
1930 public void unregisterFocusObserver(IWindowFocusObserver observer) {
1931 synchronized(mService.mWindowMap) {
1932 if (mFocusCallbacks != null) {
1933 mFocusCallbacks.unregister(observer);
1934 }
1935 }
1936 }
1937
1938 public boolean isFocused() {
1939 synchronized(mService.mWindowMap) {
1940 return mService.mCurrentFocus == this;
1941 }
1942 }
1943
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07001944 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07001945 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07001946 return task != null && task.inFreeformWorkspace();
1947 }
1948
Chong Zhang3005e752015-09-18 18:46:28 -07001949 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07001950 return mDragResizing != computeDragResizing();
1951 }
1952
Jorim Jaggidcf467c2015-11-05 13:59:32 +01001953 int getResizeMode() {
1954 return mResizeMode;
1955 }
1956
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07001957 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07001958 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07001959 if (task == null) {
1960 return false;
1961 }
1962 if (task.isDragResizing()) {
1963 return true;
1964 }
1965 return mDisplayContent.mDividerControllerLocked.isResizing() &&
1966 !task.inFreeformWorkspace() && !task.isFullscreen();
Chong Zhang3005e752015-09-18 18:46:28 -07001967 }
1968
1969 void setDragResizing() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07001970 mDragResizing = computeDragResizing();
Jorim Jaggidcf467c2015-11-05 13:59:32 +01001971 mResizeMode = mDragResizing && mDisplayContent.mDividerControllerLocked.isResizing()
1972 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
1973 : DRAG_RESIZE_MODE_FREEFORM;
Chong Zhang3005e752015-09-18 18:46:28 -07001974 }
1975
1976 boolean isDragResizing() {
1977 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07001978 }
1979
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001980 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08001981 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001982 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08001983 if (stack != null) {
1984 pw.print(" stackId="); pw.print(stack.mStackId);
1985 }
Craig Mautner59c00972012-07-30 12:10:24 -07001986 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001987 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07001988 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08001989 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
1990 pw.print(" package="); pw.print(mAttrs.packageName);
1991 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001992 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001993 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
1994 pw.print(" h="); pw.print(mRequestedHeight);
1995 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07001996 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
1997 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
1998 pw.print(" h="); pw.println(mLastRequestedHeight);
1999 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002000 if (mAttachedWindow != null || mLayoutAttached) {
2001 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
2002 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
2003 }
2004 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
2005 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
2006 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
2007 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
2008 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
2009 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002010 if (dumpAll) {
2011 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
2012 pw.print(" mSubLayer="); pw.print(mSubLayer);
2013 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautner59431632012-04-04 11:56:44 -07002014 pw.print((mTargetAppToken != null ?
2015 mTargetAppToken.mAppAnimator.animLayerAdjustment
2016 : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002017 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
2018 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08002019 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002020 if (dumpAll) {
2021 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
2022 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
2023 if (mAppToken != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08002024 pw.print(prefix); pw.print("mAppToken="); pw.print(mAppToken);
2025 pw.print(" mAppDied=");pw.println(mAppDied);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002026 }
2027 if (mTargetAppToken != null) {
2028 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
2029 }
2030 pw.print(prefix); pw.print("mViewVisibility=0x");
2031 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002032 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
2033 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07002034 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
2035 pw.print(" mSystemUiVisibility=0x");
2036 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002037 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002038 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
2039 || mAttachedHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002040 pw.print(prefix); pw.print("mPolicyVisibility=");
2041 pw.print(mPolicyVisibility);
2042 pw.print(" mPolicyVisibilityAfterAnim=");
2043 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002044 pw.print(" mAppOpVisibility=");
2045 pw.print(mAppOpVisibility);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002046 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
2047 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08002048 if (!mRelayoutCalled || mLayoutNeeded) {
2049 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
2050 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002051 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002052 if (mXOffset != 0 || mYOffset != 0) {
2053 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
2054 pw.print(" y="); pw.println(mYOffset);
2055 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002056 if (dumpAll) {
2057 pw.print(prefix); pw.print("mGivenContentInsets=");
2058 mGivenContentInsets.printShortString(pw);
2059 pw.print(" mGivenVisibleInsets=");
2060 mGivenVisibleInsets.printShortString(pw);
2061 pw.println();
2062 if (mTouchableInsets != 0 || mGivenInsetsPending) {
2063 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
2064 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07002065 Region region = new Region();
2066 getTouchableRegion(region);
2067 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002068 }
2069 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Wale Ogunwale7c726682015-02-06 17:34:28 -08002070 if (mOverrideConfig != Configuration.EMPTY) {
2071 pw.print(prefix); pw.print("mOverrideConfig="); pw.println(mOverrideConfig);
2072 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002073 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07002074 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07002075 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Craig Mautner178af592012-09-17 10:37:29 -07002076 pw.print(" isReadyForDisplay()="); pw.println(isReadyForDisplay());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002077 if (dumpAll) {
2078 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
2079 pw.print(" last="); mLastFrame.printShortString(pw);
2080 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002081 pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw);
2082 pw.print(" last="); mLastSystemDecorRect.printShortString(pw);
Craig Mautner80b1f642015-04-22 10:59:09 -07002083 if (mWinAnimator.mHasClipRect) {
2084 pw.print(" mLastClipRect=");
2085 mWinAnimator.mLastClipRect.printShortString(pw);
2086 }
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002087 pw.println();
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002088 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002089 if (mEnforceSizeCompat) {
2090 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002091 pw.println();
2092 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002093 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002094 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002095 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002096 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002097 pw.println();
2098 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
2099 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002100 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002101 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002102 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002103 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04002104 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
2105 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002106 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
2107 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002108 pw.print(prefix); pw.print("Cur insets: overscan=");
2109 mOverscanInsets.printShortString(pw);
2110 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002111 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002112 pw.print(" stable="); mStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002113 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002114 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002115 pw.print(prefix); pw.print("Lst insets: overscan=");
2116 mLastOverscanInsets.printShortString(pw);
2117 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002118 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002119 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002120 pw.print(" physical="); mLastOutsets.printShortString(pw);
2121 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002122 pw.println();
2123 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07002124 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
2125 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002126 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
2127 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
2128 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
2129 pw.print(" mDestroying="); pw.print(mDestroying);
2130 pw.print(" mRemoved="); pw.println(mRemoved);
2131 }
2132 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
2133 pw.print(prefix); pw.print("mOrientationChanging=");
2134 pw.print(mOrientationChanging);
2135 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
2136 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
2137 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07002138 if (mLastFreezeDuration != 0) {
2139 pw.print(prefix); pw.print("mLastFreezeDuration=");
2140 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
2141 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002142 if (mHScale != 1 || mVScale != 1) {
2143 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
2144 pw.print(" mVScale="); pw.println(mVScale);
2145 }
2146 if (mWallpaperX != -1 || mWallpaperY != -1) {
2147 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
2148 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
2149 }
2150 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
2151 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
2152 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
2153 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07002154 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
2155 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
2156 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
2157 pw.print(mWallpaperDisplayOffsetX);
2158 pw.print(" mWallpaperDisplayOffsetY=");
2159 pw.println(mWallpaperDisplayOffsetY);
2160 }
Jeff Brownc2932a12014-11-20 18:04:05 -08002161 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07002162 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08002163 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002164 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002165
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002166 String makeInputChannelName() {
2167 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002168 + " " + getWindowTag();
2169 }
2170
2171 private CharSequence getWindowTag() {
2172 CharSequence tag = mAttrs.getTitle();
2173 if (tag == null || tag.length() <= 0) {
2174 tag = mAttrs.packageName;
2175 }
2176 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002177 }
2178
2179 @Override
2180 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002181 final CharSequence title = getWindowTag();
Dianne Hackbornc2293022013-02-06 23:14:49 -08002182 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mExiting) {
2183 mLastTitle = title;
Dianne Hackborn529e7442012-11-01 14:22:28 -07002184 mWasExiting = mExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002185 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -07002186 + " u" + UserHandle.getUserId(mSession.mUid)
Craig Mautnera987d432012-10-11 14:07:58 -07002187 + " " + mLastTitle + (mExiting ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002188 }
2189 return mStringNameCache;
2190 }
Robert Carr58f29132015-10-29 14:19:05 -07002191
2192 void transformFromScreenToSurfaceSpace(Rect rect) {
2193 if (mHScale >= 0) {
2194 rect.right = rect.left + (int)((rect.right - rect.left) / mHScale);
2195 }
2196 if (mVScale >= 0) {
2197 rect.bottom = rect.top + (int)((rect.bottom - rect.top) / mVScale);
2198 }
2199 }
satokcef37fb2011-10-24 21:49:38 +09002200}