blob: 6a19e5af4e0c101e5a17f86bba50ae1ee6feb49a [file] [log] [blame]
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Wale Ogunwale053c8e42015-11-16 14:27:21 -080019import com.android.server.input.InputWindowHandle;
20
21import android.app.ActivityManager;
22import android.app.AppOpsManager;
23import android.content.Context;
24import android.content.res.Configuration;
25import android.graphics.Matrix;
26import android.graphics.PixelFormat;
27import android.graphics.Point;
28import android.graphics.Rect;
29import android.graphics.Region;
30import android.os.IBinder;
31import android.os.PowerManager;
32import android.os.RemoteCallbackList;
33import android.os.RemoteException;
34import android.os.SystemClock;
35import android.os.Trace;
36import android.os.UserHandle;
37import android.os.WorkSource;
38import android.util.DisplayMetrics;
39import android.util.Slog;
40import android.util.TimeUtils;
41import android.view.Display;
42import android.view.DisplayInfo;
43import android.view.Gravity;
44import android.view.IApplicationToken;
45import android.view.IWindow;
46import android.view.IWindowFocusObserver;
47import android.view.IWindowId;
48import android.view.InputChannel;
49import android.view.InputEvent;
50import android.view.InputEventReceiver;
51import android.view.View;
52import android.view.ViewTreeObserver;
53import android.view.WindowManager;
54import android.view.WindowManagerPolicy;
55
56import java.io.PrintWriter;
57import java.util.ArrayList;
58
Wale Ogunwalecad05a02015-09-25 10:41:44 -070059import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080060import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
61import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
62import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
63import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080064import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080065import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070066import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080067import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080068import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
69import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080070import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070071import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080072import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080073import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
74import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080075import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080076import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
77import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080078import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080079import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070080import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080081import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
82import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
83import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Filip Gruszczynskib6e66622015-10-25 16:05:27 -070084import static com.android.server.wm.WindowManagerService.DEBUG_ADD_REMOVE;
Craig Mautnerd1c2c542014-02-06 10:31:41 -080085import static com.android.server.wm.WindowManagerService.DEBUG_CONFIGURATION;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -080086import static com.android.server.wm.WindowManagerService.DEBUG_FOCUS_LIGHT;
Craig Mautnerb3b36ba2013-05-20 13:21:10 -070087import static com.android.server.wm.WindowManagerService.DEBUG_LAYOUT;
Craig Mautnerd1c2c542014-02-06 10:31:41 -080088import static com.android.server.wm.WindowManagerService.DEBUG_ORIENTATION;
Jeff Brownc2932a12014-11-20 18:04:05 -080089import static com.android.server.wm.WindowManagerService.DEBUG_POWER;
Craig Mautnerd1c2c542014-02-06 10:31:41 -080090import static com.android.server.wm.WindowManagerService.DEBUG_RESIZE;
91import static com.android.server.wm.WindowManagerService.DEBUG_VISIBILITY;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080092
Craig Mautner59c00972012-07-30 12:10:24 -070093class WindowList extends ArrayList<WindowState> {
94}
95
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080096/**
97 * A window in the window manager.
98 */
Craig Mautnere32c3072012-03-12 15:25:35 -070099final class WindowState implements WindowManagerPolicy.WindowState {
Craig Mautnerd87946b2012-03-29 18:00:19 -0700100 static final String TAG = "WindowState";
Craig Mautner164d4bb2012-11-26 13:51:23 -0800101
Skuhne81c524a2015-08-12 13:34:14 -0700102 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700103 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
104 // use hard-coded min sizes for now.
105 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
106 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700107
108 // The thickness of a window resize handle outside the window bounds on the free form workspace
109 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700110 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700111
112 static final boolean BOUNDS_FOR_TOUCH = true;
Skuhne81c524a2015-08-12 13:34:14 -0700113
Jorim Jaggidcf467c2015-11-05 13:59:32 +0100114 static final int DRAG_RESIZE_MODE_FREEFORM = 0;
115 static final int DRAG_RESIZE_MODE_DOCKED_DIVIDER = 1;
116
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800117 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700118 final WindowManagerPolicy mPolicy;
119 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800120 final Session mSession;
121 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800122 final int mAppOp;
123 // UserId and appId of the owner. Don't display windows of non-current user.
124 final int mOwnerUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800125 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800126 WindowToken mToken;
127 WindowToken mRootToken;
128 AppWindowToken mAppToken;
129 AppWindowToken mTargetAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700130
131 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
132 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800133 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
134 final DeathRecipient mDeathRecipient;
135 final WindowState mAttachedWindow;
Craig Mautner7b1aa772012-11-30 16:14:45 -0800136 final WindowList mChildWindows = new WindowList();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800137 final int mBaseLayer;
138 final int mSubLayer;
139 final boolean mLayoutAttached;
140 final boolean mIsImWindow;
141 final boolean mIsWallpaper;
142 final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700143 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700144 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800145 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700146 int mSystemUiVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800147 boolean mPolicyVisibility = true;
148 boolean mPolicyVisibilityAfterAnim = true;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -0800149 boolean mAppOpVisibility = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800150 boolean mAppFreezing;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800151 boolean mAttachedHidden; // is our parent window hidden?
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800152 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Chong Zhang0275e392015-09-17 10:41:44 -0700153 boolean mDragResizing;
Jorim Jaggidcf467c2015-11-05 13:59:32 +0100154 int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700155
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800156 RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
157
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700158 /**
159 * The window size that was requested by the application. These are in
160 * the application's coordinate space (without compatibility scale applied).
161 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800162 int mRequestedWidth;
163 int mRequestedHeight;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700164 int mLastRequestedWidth;
165 int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700166
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800167 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800168 boolean mHaveFrame;
169 boolean mObscured;
170 boolean mTurnOnScreen;
171
172 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700173
Wale Ogunwale60454db2015-01-23 16:05:07 -0800174 private Configuration mConfiguration = Configuration.EMPTY;
175 private Configuration mOverrideConfig = Configuration.EMPTY;
Craig Mautnere8552142012-11-07 13:55:47 -0800176 // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned.
177 // Used only on {@link #TYPE_KEYGUARD}.
178 private boolean mConfigHasChanged;
Craig Mautnera2c77052012-03-26 12:14:43 -0700179
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700180 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700181 * Actual position of the surface shown on-screen (may be modified by animation). These are
182 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700183 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700184 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800185
186 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700187 * Insets that determine the actually visible area. These are in the application's
188 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800189 */
190 final Rect mVisibleInsets = new Rect();
191 final Rect mLastVisibleInsets = new Rect();
192 boolean mVisibleInsetsChanged;
193
194 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700195 * Insets that are covered by system windows (such as the status bar) and
196 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700197 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800198 */
199 final Rect mContentInsets = new Rect();
200 final Rect mLastContentInsets = new Rect();
201 boolean mContentInsetsChanged;
202
203 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800204 * Insets that determine the area covered by the display overscan region. These are in the
205 * application's coordinate space (without compatibility scale applied).
206 */
207 final Rect mOverscanInsets = new Rect();
208 final Rect mLastOverscanInsets = new Rect();
209 boolean mOverscanInsetsChanged;
210
211 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700212 * Insets that determine the area covered by the stable system windows. These are in the
213 * application's coordinate space (without compatibility scale applied).
214 */
215 final Rect mStableInsets = new Rect();
216 final Rect mLastStableInsets = new Rect();
217 boolean mStableInsetsChanged;
218
219 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700220 * Outsets determine the area outside of the surface where we want to pretend that it's possible
221 * to draw anyway.
222 */
223 final Rect mOutsets = new Rect();
224 final Rect mLastOutsets = new Rect();
225 boolean mOutsetsChanged = false;
226
227 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800228 * Set to true if we are waiting for this window to receive its
229 * given internal insets before laying out other windows based on it.
230 */
231 boolean mGivenInsetsPending;
232
233 /**
234 * These are the content insets that were given during layout for
235 * this window, to be applied to windows behind it.
236 */
237 final Rect mGivenContentInsets = new Rect();
238
239 /**
240 * These are the visible insets that were given during layout for
241 * this window, to be applied to windows behind it.
242 */
243 final Rect mGivenVisibleInsets = new Rect();
244
245 /**
246 * This is the given touchable area relative to the window frame, or null if none.
247 */
248 final Region mGivenTouchableRegion = new Region();
249
250 /**
251 * Flag indicating whether the touchable region should be adjusted by
252 * the visible insets; if false the area outside the visible insets is
253 * NOT touchable, so we must use those to adjust the frame during hit
254 * tests.
255 */
256 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
257
Dianne Hackborn85afd1b2012-05-13 13:31:06 -0700258 /**
259 * This is rectangle of the window's surface that is not covered by
260 * system decorations.
261 */
262 final Rect mSystemDecorRect = new Rect();
263 final Rect mLastSystemDecorRect = new Rect();
264
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800265 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400266 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700267 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800268 float mHScale=1, mVScale=1;
269 float mLastHScale=1, mLastVScale=1;
270 final Matrix mTmpMatrix = new Matrix();
271
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700272 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800273 final Rect mFrame = new Rect();
274 final Rect mLastFrame = new Rect();
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700275 // Frame that is scaled to the application's coordinate space when in
276 // screen size compatibility mode.
277 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800278
279 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700280
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800281 final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700282
Wale Ogunwale94596652015-02-06 19:27:34 -0800283 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
284 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700285 final Rect mDisplayFrame = new Rect();
286
287 // The region of the display frame that the display type supports displaying content on. This
288 // is mostly a special case for TV where some displays don’t have the entire display usable.
289 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
290 // window display contents to extend into the overscan region.
291 final Rect mOverscanFrame = new Rect();
292
293 // The display frame minus the stable insets. This value is always constant regardless of if
294 // the status bar or navigation bar is visible.
Adrian Roosfa104232014-06-20 16:10:14 -0700295 final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800296
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700297 // The area not occupied by the status and navigation bars. So, if both status and navigation
298 // bars are visible, the decor frame is equal to the stable frame.
299 final Rect mDecorFrame = new Rect();
300
301 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
302 // minus the area occupied by the IME if the IME is present.
303 final Rect mContentFrame = new Rect();
304
305 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
306 // displays hint text.
307 final Rect mVisibleFrame = new Rect();
308
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700309 // Frame that includes dead area outside of the surface but where we want to pretend that it's
310 // possible to draw.
311 final Rect mOutsetFrame = new Rect();
312
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800313 boolean mContentChanged;
314
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800315 // If a window showing a wallpaper: the requested offset for the
316 // wallpaper; if a wallpaper window: the currently applied offset.
317 float mWallpaperX = -1;
318 float mWallpaperY = -1;
319
320 // If a window showing a wallpaper: what fraction of the offset
321 // range corresponds to a full virtual screen.
322 float mWallpaperXStep = -1;
323 float mWallpaperYStep = -1;
324
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700325 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
326 // to its window; if a wallpaper window: not used.
327 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
328 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
329
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800330 // Wallpaper windows: pixels offset based on above variables.
331 int mXOffset;
332 int mYOffset;
333
Craig Mautner2268e7e2012-12-13 15:40:00 -0800334 /**
335 * This is set after IWindowSession.relayout() has been called at
336 * least once for the window. It allows us to detect the situation
337 * where we don't yet have a surface, but should have one soon, so
338 * we can give the window focus before waiting for the relayout.
339 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800340 boolean mRelayoutCalled;
341
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800342 /**
343 * If the application has called relayout() with changes that can
344 * impact its window's size, we need to perform a layout pass on it
345 * even if it is not currently visible for layout. This is set
346 * when in that case until the layout is done.
347 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800348 boolean mLayoutNeeded;
349
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800350 /** Currently running an exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800351 boolean mExiting;
352
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800353 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800354 boolean mDestroying;
355
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800356 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800357 boolean mRemoveOnExit;
358
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800359 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800360 * Whether the app died while it was visible, if true we might need
361 * to continue to show it until it's restarted.
362 */
363 boolean mAppDied;
364
365 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800366 * Set when the orientation is changing and this window has not yet
367 * been updated for the new orientation.
368 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800369 boolean mOrientationChanging;
370
Dianne Hackborna57c6952013-03-29 14:46:40 -0700371 /**
372 * How long we last kept the screen frozen.
373 */
374 int mLastFreezeDuration;
375
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800376 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800377 boolean mRemoved;
378
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800379 /**
380 * Temp for keeping track of windows that have been removed when
381 * rebuilding window list.
382 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800383 boolean mRebuilding;
384
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800385 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700386 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800387 InputChannel mInputChannel;
Chong Zhang112eb8c2015-11-02 11:17:00 -0800388 InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800389
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800390 // Used to improve performance of toString()
391 String mStringNameCache;
392 CharSequence mLastTitle;
Dianne Hackborn529e7442012-11-01 14:22:28 -0700393 boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800394
Craig Mautnera2c77052012-03-26 12:14:43 -0700395 final WindowStateAnimator mWinAnimator;
396
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700397 boolean mHasSurface = false;
398
Craig Mautner19ab8282014-05-07 10:35:34 -0700399 boolean mNotOnAppsDisplay = false;
Craig Mautner59c00972012-07-30 12:10:24 -0700400 DisplayContent mDisplayContent;
Craig Mautner6881a102012-07-27 13:04:51 -0700401
Craig Mautner88400d32012-09-30 12:35:45 -0700402 /** When true this window can be displayed on screens owther than mOwnerUid's */
403 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700404
Jeff Brownc2932a12014-11-20 18:04:05 -0800405 /**
406 * Wake lock for drawing.
407 * Even though it's slightly more expensive to do so, we will use a separate wake lock
408 * for each app that is requesting to draw while dozing so that we can accurately track
409 * who is preventing the system from suspending.
410 * This lock is only acquired on first use.
411 */
412 PowerManager.WakeLock mDrawLock;
413
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700414 final private Rect mTmpRect = new Rect();
415
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800416 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800417 WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a,
Craig Mautner59c00972012-07-30 12:10:24 -0700418 int viewVisibility, final DisplayContent displayContent) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800419 mService = service;
420 mSession = s;
421 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800422 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800423 mToken = token;
Craig Mautnera2d7b112012-08-21 15:12:20 -0700424 mOwnerUid = s.mUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800425 mWindowId = new IWindowId.Stub() {
426 @Override
427 public void registerFocusObserver(IWindowFocusObserver observer) {
428 WindowState.this.registerFocusObserver(observer);
429 }
430 @Override
431 public void unregisterFocusObserver(IWindowFocusObserver observer) {
432 WindowState.this.unregisterFocusObserver(observer);
433 }
434 @Override
435 public boolean isFocused() {
436 return WindowState.this.isFocused();
437 }
438 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800439 mAttrs.copyFrom(a);
440 mViewVisibility = viewVisibility;
Craig Mautner59c00972012-07-30 12:10:24 -0700441 mDisplayContent = displayContent;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700442 mPolicy = mService.mPolicy;
443 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800444 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700445 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700446 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800447 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700448 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700449 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800450 try {
451 c.asBinder().linkToDeath(deathRecipient, 0);
452 } catch (RemoteException e) {
453 mDeathRecipient = null;
454 mAttachedWindow = null;
455 mLayoutAttached = false;
456 mIsImWindow = false;
457 mIsWallpaper = false;
458 mIsFloatingLayer = false;
459 mBaseLayer = 0;
460 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700461 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700462 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800463 return;
464 }
465 mDeathRecipient = deathRecipient;
466
467 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
468 mAttrs.type <= LAST_SUB_WINDOW)) {
469 // The multiplier here is to reserve space for multiple
470 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700471 mBaseLayer = mPolicy.windowTypeToLayerLw(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800472 attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
473 + WindowManagerService.TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700474 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800475 mAttachedWindow = attachedWindow;
Filip Gruszczynskib6e66622015-10-25 16:05:27 -0700476 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to "
477 + mAttachedWindow);
takeda.masayuki18735092012-12-12 11:06:24 +0900478
tiger_huange2a98a72014-11-13 19:46:28 +0800479 final WindowList childWindows = mAttachedWindow.mChildWindows;
480 final int numChildWindows = childWindows.size();
481 if (numChildWindows == 0) {
482 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900483 } else {
tiger_huange2a98a72014-11-13 19:46:28 +0800484 boolean added = false;
485 for (int i = 0; i < numChildWindows; i++) {
486 final int childSubLayer = childWindows.get(i).mSubLayer;
487 if (mSubLayer < childSubLayer
488 || (mSubLayer == childSubLayer && childSubLayer < 0)) {
489 // We insert the child window into the list ordered by the sub-layer. For
490 // same sub-layers, the negative one should go below others; the positive
491 // one should go above others.
492 childWindows.add(i, this);
493 added = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900494 break;
takeda.masayuki18735092012-12-12 11:06:24 +0900495 }
496 }
tiger_huange2a98a72014-11-13 19:46:28 +0800497 if (!added) {
498 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900499 }
500 }
501
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800502 mLayoutAttached = mAttrs.type !=
503 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
504 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
505 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
506 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
507 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
508 } else {
509 // The multiplier here is to reserve space for multiple
510 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700511 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800512 * WindowManagerService.TYPE_LAYER_MULTIPLIER
513 + WindowManagerService.TYPE_LAYER_OFFSET;
514 mSubLayer = 0;
515 mAttachedWindow = null;
516 mLayoutAttached = false;
517 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
518 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
519 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
520 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
521 }
522
523 WindowState appWin = this;
524 while (appWin.mAttachedWindow != null) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700525 appWin = appWin.mAttachedWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800526 }
527 WindowToken appToken = appWin.mToken;
528 while (appToken.appWindowToken == null) {
529 WindowToken parent = mService.mTokenMap.get(appToken.token);
530 if (parent == null || appToken == parent) {
531 break;
532 }
533 appToken = parent;
534 }
535 mRootToken = appToken;
536 mAppToken = appToken.appWindowToken;
Craig Mautner19ab8282014-05-07 10:35:34 -0700537 if (mAppToken != null) {
538 final DisplayContent appDisplay = getDisplayContent();
539 mNotOnAppsDisplay = displayContent != appDisplay;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700540
541 if (mAppToken.showForAllUsers) {
542 // Windows for apps that can show for all users should also show when the
543 // device is locked.
544 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
545 }
Craig Mautner19ab8282014-05-07 10:35:34 -0700546 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800547
Craig Mautner322e4032012-07-13 13:35:20 -0700548 mWinAnimator = new WindowStateAnimator(this);
549 mWinAnimator.mAlpha = a.alpha;
550
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800551 mRequestedWidth = 0;
552 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700553 mLastRequestedWidth = 0;
554 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800555 mXOffset = 0;
556 mYOffset = 0;
557 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800558 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700559 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
560 displayContent.getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800561 }
562
563 void attach() {
564 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700565 TAG, "Attaching " + this + " token=" + mToken
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800566 + ", list=" + mToken.windows);
567 mSession.windowAddedLocked();
568 }
569
Craig Mautnera2c77052012-03-26 12:14:43 -0700570 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800571 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800572 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800573 }
574
575 @Override
576 public String getOwningPackage() {
577 return mAttrs.packageName;
578 }
579
580 @Override
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700581 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf, Rect sf,
582 Rect osf) {
Filip Gruszczynskib6e66622015-10-25 16:05:27 -0700583 if (mAppToken != null && mAppToken.mWillReplaceWindow
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700584 && (mExiting || !mAppToken.mReplacingRemoveRequested)) {
585 // This window is being replaced and either already got information that it's being
586 // removed or we are still waiting for some information. Because of this we don't
587 // want to apply any more changes to it, so it remains in this state until new window
588 // appears.
589 return;
590 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800591 mHaveFrame = true;
592
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700593 final Task task = getTask();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700594 final boolean nonFullscreenTask = task != null && !task.isFullscreen();
Chong Zhang09b21ef2015-09-14 10:20:21 -0700595 final boolean freeformWorkspace = task != null && task.inFreeformWorkspace();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700596 if (nonFullscreenTask) {
597 task.getBounds(mContainingFrame);
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800598 final WindowState imeWin = mService.mInputMethodWindow;
599 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this
600 && mContainingFrame.bottom > cf.bottom) {
601 // IME is up and obscuring this window. Adjust the window position so it is visible.
602 mContainingFrame.top -= mContainingFrame.bottom - cf.bottom;
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700603 }
Skuhne81c524a2015-08-12 13:34:14 -0700604
Skuhnef932e562015-08-20 12:07:30 -0700605 if (freeformWorkspace) {
Skuhne81c524a2015-08-12 13:34:14 -0700606 // In free form mode we have only to set the rectangle if it wasn't set already. No
607 // need to intersect it with the (visible) "content frame" since it is allowed to
608 // be outside the visible desktop.
609 if (mContainingFrame.isEmpty()) {
610 mContainingFrame.set(cf);
611 }
Doris Liu06d582d2015-06-01 13:18:43 -0700612 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800613 mDisplayFrame.set(mContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700614 } else {
615 mContainingFrame.set(pf);
Wale Ogunwale94596652015-02-06 19:27:34 -0800616 mDisplayFrame.set(df);
Craig Mautner967212c2013-04-13 21:10:58 -0700617 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800618
Craig Mautner967212c2013-04-13 21:10:58 -0700619 final int pw = mContainingFrame.width();
620 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800621
622 int w,h;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -0800623 if ((mAttrs.flags & FLAG_SCALED) != 0) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700624 if (mAttrs.width < 0) {
625 w = pw;
626 } else if (mEnforceSizeCompat) {
627 w = (int)(mAttrs.width * mGlobalScale + .5f);
628 } else {
629 w = mAttrs.width;
630 }
631 if (mAttrs.height < 0) {
632 h = ph;
633 } else if (mEnforceSizeCompat) {
634 h = (int)(mAttrs.height * mGlobalScale + .5f);
635 } else {
636 h = mAttrs.height;
637 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800638 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700639 if (mAttrs.width == WindowManager.LayoutParams.MATCH_PARENT) {
640 w = pw;
641 } else if (mEnforceSizeCompat) {
642 w = (int)(mRequestedWidth * mGlobalScale + .5f);
643 } else {
644 w = mRequestedWidth;
645 }
646 if (mAttrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
647 h = ph;
648 } else if (mEnforceSizeCompat) {
649 h = (int)(mRequestedHeight * mGlobalScale + .5f);
650 } else {
651 h = mRequestedHeight;
652 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800653 }
654
655 if (!mParentFrame.equals(pf)) {
656 //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
657 // + " to " + pf);
658 mParentFrame.set(pf);
659 mContentChanged = true;
660 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700661 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
662 mLastRequestedWidth = mRequestedWidth;
663 mLastRequestedHeight = mRequestedHeight;
664 mContentChanged = true;
665 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800666
Craig Mautnereda67292013-04-28 13:50:14 -0700667 mOverscanFrame.set(of);
668 mContentFrame.set(cf);
669 mVisibleFrame.set(vf);
John Spurlock46646232013-09-30 22:32:42 -0400670 mDecorFrame.set(dcf);
Adrian Roosfa104232014-06-20 16:10:14 -0700671 mStableFrame.set(sf);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700672 final boolean hasOutsets = osf != null;
673 if (hasOutsets) {
674 mOutsetFrame.set(osf);
675 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800676
Craig Mautnereda67292013-04-28 13:50:14 -0700677 final int fw = mFrame.width();
678 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800679
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700680 float x, y;
681 if (mEnforceSizeCompat) {
682 x = mAttrs.x * mGlobalScale;
683 y = mAttrs.y * mGlobalScale;
684 } else {
685 x = mAttrs.x;
686 y = mAttrs.y;
687 }
688
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700689 if (nonFullscreenTask) {
Wale Ogunwaleb171abb2015-04-22 12:47:17 -0700690 // Make sure window fits in containing frame since it is in a non-fullscreen stack as
691 // required by {@link Gravity#apply} call.
692 w = Math.min(w, pw);
693 h = Math.min(h, ph);
694 }
695
Craig Mautner967212c2013-04-13 21:10:58 -0700696 Gravity.apply(mAttrs.gravity, w, h, mContainingFrame,
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700697 (int) (x + mAttrs.horizontalMargin * pw),
Craig Mautnereda67292013-04-28 13:50:14 -0700698 (int) (y + mAttrs.verticalMargin * ph), mFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800699
Wale Ogunwale94596652015-02-06 19:27:34 -0800700 // Now make sure the window fits in the overall display frame.
701 Gravity.applyDisplay(mAttrs.gravity, mDisplayFrame, mFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800702
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700703 // Calculate the outsets before the content frame gets shrinked to the window frame.
704 if (hasOutsets) {
705 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
706 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
707 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
708 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
709 } else {
710 mOutsets.set(0, 0, 0, 0);
711 }
712
Craig Mautnera248eee2013-05-07 11:41:27 -0700713 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800714 // final window frame.
Skuhnef932e562015-08-20 12:07:30 -0700715 if (freeformWorkspace && !mFrame.isEmpty()) {
Skuhne81c524a2015-08-12 13:34:14 -0700716 // Keep the frame out of the blocked system area, limit it in size to the content area
717 // and make sure that there is always a minimum visible so that the user can drag it
718 // into a usable area..
719 final int height = Math.min(mFrame.height(), mContentFrame.height());
720 final int width = Math.min(mContentFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700721 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700722 final int minVisibleHeight = WindowManagerService.dipToPixel(
723 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics);
724 final int minVisibleWidth = WindowManagerService.dipToPixel(
725 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics);
Skuhne81c524a2015-08-12 13:34:14 -0700726 final int top = Math.max(mContentFrame.top,
727 Math.min(mFrame.top, mContentFrame.bottom - minVisibleHeight));
728 final int left = Math.max(mContentFrame.left + minVisibleWidth - width,
729 Math.min(mFrame.left, mContentFrame.right - minVisibleWidth));
730 mFrame.set(left, top, left + width, top + height);
731 mContentFrame.set(mFrame);
732 mVisibleFrame.set(mContentFrame);
733 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700734 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800735 if (isVisibleLw()) {
736 // We don't adjust the dock divider frame for reasons other than performance. The
737 // real reason is that if it gets adjusted before it is shown for the first time,
738 // it would get size (0, 0). This causes a problem when we finally show the dock
739 // divider and try to draw to it. We do set the surface size at that moment to
740 // the correct size, but it's too late for the Surface Flinger to make it
741 // available for view rendering and as a result the renderer receives size 1, 1.
742 // This way we just keep the divider at the original size and Surface Flinger
743 // will return the correct value to the renderer.
744 mDisplayContent.getDockedDividerController().positionDockedStackedDivider(mFrame);
745 mContentFrame.set(mFrame);
746 }
Skuhne81c524a2015-08-12 13:34:14 -0700747 } else {
748 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
749 Math.max(mContentFrame.top, mFrame.top),
750 Math.min(mContentFrame.right, mFrame.right),
751 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800752
Skuhne81c524a2015-08-12 13:34:14 -0700753 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
754 Math.max(mVisibleFrame.top, mFrame.top),
755 Math.min(mVisibleFrame.right, mFrame.right),
756 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800757
Skuhne81c524a2015-08-12 13:34:14 -0700758 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
759 Math.max(mStableFrame.top, mFrame.top),
760 Math.min(mStableFrame.right, mFrame.right),
761 Math.min(mStableFrame.bottom, mFrame.bottom));
762 }
Adrian Roosfa104232014-06-20 16:10:14 -0700763
Craig Mautnerc36c8e62013-05-10 13:33:31 -0700764 mOverscanInsets.set(Math.max(mOverscanFrame.left - mFrame.left, 0),
765 Math.max(mOverscanFrame.top - mFrame.top, 0),
Adrian Roos3236f3a2014-12-09 15:06:40 +0000766 Math.max(mFrame.right - mOverscanFrame.right, 0),
767 Math.max(mFrame.bottom - mOverscanFrame.bottom, 0));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800768
Craig Mautnereda67292013-04-28 13:50:14 -0700769 mContentInsets.set(mContentFrame.left - mFrame.left,
770 mContentFrame.top - mFrame.top,
771 mFrame.right - mContentFrame.right,
772 mFrame.bottom - mContentFrame.bottom);
773
774 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
775 mVisibleFrame.top - mFrame.top,
776 mFrame.right - mVisibleFrame.right,
777 mFrame.bottom - mVisibleFrame.bottom);
778
Adrian Roosfa104232014-06-20 16:10:14 -0700779 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
780 Math.max(mStableFrame.top - mFrame.top, 0),
781 Math.max(mFrame.right - mStableFrame.right, 0),
782 Math.max(mFrame.bottom - mStableFrame.bottom, 0));
783
Craig Mautnereda67292013-04-28 13:50:14 -0700784 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400785 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700786 // If there is a size compatibility scale being applied to the
787 // window, we need to apply this to its insets so that they are
788 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700789 mOverscanInsets.scale(mInvGlobalScale);
790 mContentInsets.scale(mInvGlobalScale);
791 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700792 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700793 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700794
795 // Also the scaled frame that we report to the app needs to be
796 // adjusted to be in its coordinate space.
797 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400798 }
799
Craig Mautnereda67292013-04-28 13:50:14 -0700800 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800801 final DisplayContent displayContent = getDisplayContent();
802 if (displayContent != null) {
803 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700804 mService.mWallpaperControllerLocked.updateWallpaperOffset(
805 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800806 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800807 }
808
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700809 if (DEBUG_LAYOUT || WindowManagerService.localLOGV) Slog.v(TAG,
810 "Resolving (mRequestedWidth="
811 + mRequestedWidth + ", mRequestedheight="
812 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
813 + "): frame=" + mFrame.toShortString()
814 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -0700815 + " vi=" + mVisibleInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700816 + " vi=" + mStableInsets.toShortString()
817 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800818 }
819
Craig Mautnera2c77052012-03-26 12:14:43 -0700820 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800821 public Rect getFrameLw() {
822 return mFrame;
823 }
824
Craig Mautnera2c77052012-03-26 12:14:43 -0700825 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700826 public Point getShownPositionLw() {
827 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800828 }
829
Craig Mautnera2c77052012-03-26 12:14:43 -0700830 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800831 public Rect getDisplayFrameLw() {
832 return mDisplayFrame;
833 }
834
Craig Mautnera2c77052012-03-26 12:14:43 -0700835 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800836 public Rect getOverscanFrameLw() {
837 return mOverscanFrame;
838 }
839
840 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800841 public Rect getContentFrameLw() {
842 return mContentFrame;
843 }
844
Craig Mautnera2c77052012-03-26 12:14:43 -0700845 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800846 public Rect getVisibleFrameLw() {
847 return mVisibleFrame;
848 }
849
Craig Mautnera2c77052012-03-26 12:14:43 -0700850 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800851 public boolean getGivenInsetsPendingLw() {
852 return mGivenInsetsPending;
853 }
854
Craig Mautnera2c77052012-03-26 12:14:43 -0700855 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800856 public Rect getGivenContentInsetsLw() {
857 return mGivenContentInsets;
858 }
859
Craig Mautnera2c77052012-03-26 12:14:43 -0700860 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800861 public Rect getGivenVisibleInsetsLw() {
862 return mGivenVisibleInsets;
863 }
864
Craig Mautnera2c77052012-03-26 12:14:43 -0700865 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800866 public WindowManager.LayoutParams getAttrs() {
867 return mAttrs;
868 }
869
Craig Mautner812d2ca2012-09-27 15:35:34 -0700870 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800871 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
872 int index = -1;
873 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -0700874 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800875 while (true) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -0700876 if (ws.mAttrs.needsMenuKey != WindowManager.LayoutParams.NEEDS_MENU_UNSET) {
877 return ws.mAttrs.needsMenuKey == WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800878 }
879 // If we reached the bottom of the range of windows we are considering,
880 // assume no menu is needed.
881 if (ws == bottom) {
882 return false;
883 }
884 // The current window hasn't specified whether menu key is needed;
885 // look behind it.
886 // First, we may need to determine the starting position.
887 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -0700888 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800889 }
890 index--;
891 if (index < 0) {
892 return false;
893 }
Craig Mautner59c00972012-07-30 12:10:24 -0700894 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800895 }
896 }
897
Craig Mautner19d59bc2012-09-04 11:15:56 -0700898 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700899 public int getSystemUiVisibility() {
900 return mSystemUiVisibility;
901 }
902
Craig Mautner19d59bc2012-09-04 11:15:56 -0700903 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800904 public int getSurfaceLayer() {
905 return mLayer;
906 }
907
Craig Mautner812d2ca2012-09-27 15:35:34 -0700908 @Override
Selim Cinekd6623612015-05-22 18:56:22 -0700909 public int getBaseType() {
910 WindowState win = this;
911 while (win.mAttachedWindow != null) {
912 win = win.mAttachedWindow;
913 }
914 return win.mAttrs.type;
915 }
916
917 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800918 public IApplicationToken getAppToken() {
919 return mAppToken != null ? mAppToken.appToken : null;
920 }
Craig Mautner19d59bc2012-09-04 11:15:56 -0700921
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700922 @Override
923 public boolean isVoiceInteraction() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700924 return mAppToken != null && mAppToken.voiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700925 }
926
Craig Mautner4c5eb222013-11-18 12:59:05 -0800927 boolean setInsetsChanged() {
928 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
929 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
930 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -0700931 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700932 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
933 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
934 || mOutsetsChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -0800935 }
936
Craig Mautnerdf88d732014-01-27 09:21:32 -0800937 public DisplayContent getDisplayContent() {
Chad Jonesf391ebc2014-06-12 17:45:05 -0700938 if (mAppToken == null || mNotOnAppsDisplay) {
Craig Mautnerbe634952014-06-12 13:39:24 -0700939 return mDisplayContent;
940 }
941 final TaskStack stack = getStack();
942 return stack == null ? mDisplayContent : stack.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -0800943 }
944
Chong Zhang09b21ef2015-09-14 10:20:21 -0700945 public DisplayInfo getDisplayInfo() {
946 final DisplayContent displayContent = getDisplayContent();
947 return displayContent != null ? displayContent.getDisplayInfo() : null;
948 }
949
Craig Mautner19d59bc2012-09-04 11:15:56 -0700950 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800951 final DisplayContent displayContent = getDisplayContent();
952 if (displayContent == null) {
953 return -1;
954 }
955 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -0700956 }
957
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700958 Task getTask() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700959 return mAppToken != null ? mAppToken.mTask : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700960 }
961
962 TaskStack getStack() {
963 Task task = getTask();
964 if (task != null) {
965 if (task.mStack != null) {
966 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -0700967 }
Craig Mautnerd9a22882013-03-16 15:00:36 -0700968 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700969 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
970 // associate them with some stack to enable dimming.
971 return mAttrs.type >= WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
972 && mDisplayContent != null ? mDisplayContent.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -0700973 }
974
Skuhnef932e562015-08-20 12:07:30 -0700975 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700976 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -0700977 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -0700978 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800979 void getVisibleBounds(Rect bounds) {
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700980 boolean intersectWithStackBounds = mAppToken != null && mAppToken.mCropWindowsToStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700981 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700982 mTmpRect.setEmpty();
983 if (intersectWithStackBounds) {
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700984 final TaskStack stack = getStack();
985 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800986 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700987 } else {
988 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700989 }
990 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700991
Chong Zhang9184ec62015-09-24 12:32:21 -0700992 bounds.set(mVisibleFrame);
993 if (intersectWithStackBounds) {
994 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700995 }
996
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700997 if (bounds.isEmpty()) {
998 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700999 if (intersectWithStackBounds) {
1000 bounds.intersect(mTmpRect);
1001 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001002 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001003 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001004 }
1005
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001006 public long getInputDispatchingTimeoutNanos() {
1007 return mAppToken != null
1008 ? mAppToken.inputDispatchingTimeoutNanos
1009 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1010 }
1011
Craig Mautnere8552142012-11-07 13:55:47 -08001012 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001013 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001014 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001015 }
1016
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001017 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1018 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1019 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1020 if (dtdx < -.000001f || dtdx > .000001f) return false;
1021 if (dsdy < -.000001f || dsdy > .000001f) return false;
1022 return true;
1023 }
1024
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001025 void prelayout() {
1026 if (mEnforceSizeCompat) {
1027 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001028 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001029 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001030 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001031 }
1032 }
1033
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001034 /**
1035 * Is this window visible? It is not visible if there is no
1036 * surface, or we are in the process of running an exit animation
1037 * that will remove the surface, or its app token has been hidden.
1038 */
Craig Mautner88400d32012-09-30 12:35:45 -07001039 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001040 public boolean isVisibleLw() {
1041 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001042 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001043 && (atoken == null || !atoken.hiddenRequested)
1044 && !mExiting && !mDestroying;
1045 }
1046
1047 /**
1048 * Like {@link #isVisibleLw}, but also counts a window that is currently
1049 * "hidden" behind the keyguard as visible. This allows us to apply
1050 * things like window flags that impact the keyguard.
1051 * XXX I am starting to think we need to have ANOTHER visibility flag
1052 * for this "hidden behind keyguard" state rather than overloading
1053 * mPolicyVisibility. Ungh.
1054 */
Craig Mautner88400d32012-09-30 12:35:45 -07001055 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001056 public boolean isVisibleOrBehindKeyguardLw() {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001057 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -08001058 mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001059 return false;
1060 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001061 final AppWindowToken atoken = mAppToken;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001062 final boolean animating = atoken != null && atoken.mAppAnimator.animation != null;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001063 return mHasSurface && !mDestroying && !mExiting
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001064 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001065 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
1066 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001067 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001068 }
1069
1070 /**
1071 * Is this window visible, ignoring its app token? It is not visible
1072 * if there is no surface, or we are in the process of running an exit animation
1073 * that will remove the surface.
1074 */
1075 public boolean isWinVisibleLw() {
1076 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001077 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautner59431632012-04-04 11:56:44 -07001078 && (atoken == null || !atoken.hiddenRequested || atoken.mAppAnimator.animating)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001079 && !mExiting && !mDestroying;
1080 }
1081
1082 /**
1083 * The same as isVisible(), but follows the current hidden state of
1084 * the associated app token, not the pending requested hidden state.
1085 */
1086 boolean isVisibleNow() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001087 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07001088 && (!mRootToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
1089 && !mExiting && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001090 }
1091
1092 /**
1093 * Can this window possibly be a drag/drop target? The test here is
1094 * a combination of the above "visible now" with the check that the
1095 * Input Manager uses when discarding windows from input consideration.
1096 */
1097 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001098 return isVisibleNow() && !mRemoved
1099 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001100 }
1101
1102 /**
1103 * Same as isVisible(), but we also count it as visible between the
1104 * call to IWindowSession.add() and the first relayout().
1105 */
1106 boolean isVisibleOrAdding() {
1107 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001108 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001109 && mPolicyVisibility && !mAttachedHidden
1110 && (atoken == null || !atoken.hiddenRequested)
1111 && !mExiting && !mDestroying;
1112 }
1113
1114 /**
1115 * Is this window currently on-screen? It is on-screen either if it
1116 * is visible or it is currently running an animation before no longer
1117 * being visible.
1118 */
1119 boolean isOnScreen() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001120 return mPolicyVisibility && isOnScreenIgnoringKeyguard();
1121 }
1122
1123 /**
1124 * Like isOnScreen(), but ignores any force hiding of the window due
1125 * to the keyguard.
1126 */
1127 boolean isOnScreenIgnoringKeyguard() {
1128 if (!mHasSurface || mDestroying) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001129 return false;
1130 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001131 final AppWindowToken atoken = mAppToken;
1132 if (atoken != null) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001133 return ((!mAttachedHidden && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001134 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001135 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001136 return !mAttachedHidden || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001137 }
1138
1139 /**
1140 * Like isOnScreen(), but we don't return true if the window is part
1141 * of a transition that has not yet been started.
1142 */
1143 boolean isReadyForDisplay() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001144 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001145 return false;
1146 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001147 return mHasSurface && mPolicyVisibility && !mDestroying
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001148 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
1149 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001150 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001151 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001152 }
1153
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001154 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001155 * Like isReadyForDisplay(), but ignores any force hiding of the window due
1156 * to the keyguard.
1157 */
1158 boolean isReadyForDisplayIgnoringKeyguard() {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001159 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001160 return false;
1161 }
1162 final AppWindowToken atoken = mAppToken;
1163 if (atoken == null && !mPolicyVisibility) {
1164 // If this is not an app window, and the policy has asked to force
1165 // hide, then we really do want to hide.
1166 return false;
1167 }
1168 return mHasSurface && !mDestroying
1169 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
1170 && !mRootToken.hidden)
1171 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -07001172 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
1173 && !mWinAnimator.isDummyAnimation()));
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001174 }
1175
1176 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001177 * Like isOnScreen, but returns false if the surface hasn't yet
1178 * been drawn.
1179 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001180 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001181 public boolean isDisplayedLw() {
1182 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001183 return isDrawnLw() && mPolicyVisibility
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001184 && ((!mAttachedHidden &&
1185 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001186 || mWinAnimator.mAnimating
1187 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001188 }
1189
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001190 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001191 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001192 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001193 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001194 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001195 return mWinAnimator.mAnimation != null
1196 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001197 }
1198
Craig Mautner812d2ca2012-09-27 15:35:34 -07001199 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001200 public boolean isGoneForLayoutLw() {
1201 final AppWindowToken atoken = mAppToken;
1202 return mViewVisibility == View.GONE
1203 || !mRelayoutCalled
1204 || (atoken == null && mRootToken.hidden)
Craig Mautner812d2ca2012-09-27 15:35:34 -07001205 || (atoken != null && (atoken.hiddenRequested || atoken.hidden))
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001206 || mAttachedHidden
Craig Mautner0e415c62013-04-29 16:10:58 -07001207 || (mExiting && !isAnimatingLw())
1208 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001209 }
1210
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001211 /**
1212 * Returns true if the window has a surface that it has drawn a
1213 * complete UI in to.
1214 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001215 public boolean isDrawFinishedLw() {
1216 return mHasSurface && !mDestroying &&
1217 (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING
1218 || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1219 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
1220 }
1221
1222 /**
1223 * Returns true if the window has a surface that it has drawn a
1224 * complete UI in to.
1225 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001226 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001227 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001228 return mHasSurface && !mDestroying &&
Craig Mautner749a7bb2012-04-02 13:49:53 -07001229 (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1230 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001231 }
1232
1233 /**
1234 * Return true if the window is opaque and fully drawn. This indicates
1235 * it may obscure windows behind it.
1236 */
1237 boolean isOpaqueDrawn() {
1238 return (mAttrs.format == PixelFormat.OPAQUE
1239 || mAttrs.type == TYPE_WALLPAPER)
Craig Mautnera2c77052012-03-26 12:14:43 -07001240 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001241 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001242 }
1243
1244 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001245 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001246 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1247 */
Craig Mautner4557c082015-04-27 13:07:40 -07001248 boolean hasMoved() {
1249 return mHasSurface && mContentChanged && !mExiting && !mWinAnimator.mLastHidden
1250 && mService.okToDisplay() && (mFrame.top != mLastFrame.top
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001251 || mFrame.left != mLastFrame.left)
Craig Mautner4557c082015-04-27 13:07:40 -07001252 && (mAttachedWindow == null || !mAttachedWindow.hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001253 }
1254
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001255 boolean isFullscreen(int screenWidth, int screenHeight) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001256 return mFrame.left <= 0 && mFrame.top <= 0 &&
1257 mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001258 }
1259
Craig Mautner812d2ca2012-09-27 15:35:34 -07001260 boolean isConfigChanged() {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001261 final Task task = getTask();
Wale Ogunwale60454db2015-01-23 16:05:07 -08001262 final Configuration overrideConfig =
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001263 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001264 final Configuration serviceConfig = mService.mCurConfiguration;
1265 boolean configChanged =
1266 (mConfiguration != serviceConfig && mConfiguration.diff(serviceConfig) != 0)
1267 || (mOverrideConfig != overrideConfig && !mOverrideConfig.equals(overrideConfig));
Craig Mautnere8552142012-11-07 13:55:47 -08001268
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001269 if ((mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Craig Mautnere8552142012-11-07 13:55:47 -08001270 // Retain configuration changed status until resetConfiguration called.
1271 mConfigHasChanged |= configChanged;
1272 configChanged = mConfigHasChanged;
1273 }
1274
1275 return configChanged;
Craig Mautner812d2ca2012-09-27 15:35:34 -07001276 }
1277
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001278 void removeLocked() {
1279 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001280
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001281 if (mAttachedWindow != null) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001282 if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001283 mAttachedWindow.mChildWindows.remove(this);
1284 }
Craig Mautner96868332012-12-04 14:29:11 -08001285 mWinAnimator.destroyDeferredSurfaceLocked();
1286 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001287 mSession.windowRemovedLocked();
1288 try {
1289 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1290 } catch (RuntimeException e) {
1291 // Ignore if it has already been removed (usually because
1292 // we are doing this as part of processing a death note.)
1293 }
1294 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001295
Wale Ogunwale60454db2015-01-23 16:05:07 -08001296 private void setConfiguration(
1297 final Configuration newConfig, final Configuration newOverrideConfig) {
Craig Mautnere8552142012-11-07 13:55:47 -08001298 mConfiguration = newConfig;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001299 mOverrideConfig = newOverrideConfig;
Craig Mautnere8552142012-11-07 13:55:47 -08001300 mConfigHasChanged = false;
1301 }
1302
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001303 void setHasSurface(boolean hasSurface) {
1304 mHasSurface = hasSurface;
1305 }
1306
Chong Zhangacf11402015-11-04 16:23:10 -08001307 private final class DeadWindowEventReceiver extends InputEventReceiver {
1308 DeadWindowEventReceiver(InputChannel inputChannel) {
1309 super(inputChannel, mService.mH.getLooper());
1310 }
1311 @Override
1312 public void onInputEvent(InputEvent event) {
1313 finishInputEvent(event, true);
1314 }
1315 }
1316 /**
1317 * Dummy event receiver for windows that died visible.
1318 */
1319 private DeadWindowEventReceiver mDeadWindowEventReceiver;
1320
Chong Zhang112eb8c2015-11-02 11:17:00 -08001321 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001322 if (mInputChannel != null) {
1323 throw new IllegalStateException("Window already has an input channel.");
1324 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001325 String name = makeInputChannelName();
1326 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1327 mInputChannel = inputChannels[0];
1328 mClientChannel = inputChannels[1];
1329 mInputWindowHandle.inputChannel = inputChannels[0];
1330 if (outInputChannel != null) {
1331 mClientChannel.transferTo(outInputChannel);
1332 mClientChannel.dispose();
1333 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08001334 } else {
1335 // If the window died visible, we setup a dummy input channel, so that taps
1336 // can still detected by input monitor channel, and we can relaunch the app.
1337 // Create dummy event receiver that simply reports all events as handled.
1338 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08001339 }
1340 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001341 }
1342
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001343 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08001344 if (mDeadWindowEventReceiver != null) {
1345 mDeadWindowEventReceiver.dispose();
1346 mDeadWindowEventReceiver = null;
1347 }
1348
1349 // unregister server channel first otherwise it complains about broken channel
1350 if (mInputChannel != null) {
1351 mService.mInputManager.unregisterInputChannel(mInputChannel);
1352 mInputChannel.dispose();
1353 mInputChannel = null;
1354 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001355 if (mClientChannel != null) {
1356 mClientChannel.dispose();
1357 mClientChannel = null;
1358 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001359 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001360 }
1361
Chong Zhang112eb8c2015-11-02 11:17:00 -08001362 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08001363 // When the app is terminated (eg. from Recents), the task might have already been
1364 // removed with the window pending removal. Don't apply dim in such cases, as there
1365 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
1366 final AppWindowToken token = mAppToken;
1367 if (token != null && token.removed) {
1368 return;
1369 }
1370
Chong Zhang112eb8c2015-11-02 11:17:00 -08001371 if (!mExiting && mAppDied) {
1372 // If app died visible, apply a dim over the window to indicate that it's inactive
1373 mDisplayContent.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
1374 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
1375 && mDisplayContent != null && !mExiting && isDisplayedLw()) {
1376 mDisplayContent.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001377 }
1378 }
1379
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001380 DimLayer.DimLayerUser getDimLayerUser() {
1381 Task task = getTask();
1382 if (task != null) {
1383 return task;
1384 }
1385 return getStack();
1386 }
1387
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001388 void maybeRemoveReplacedWindow() {
1389 AppWindowToken token = mAppToken;
Filip Gruszczynski78a08ee2015-11-08 18:04:32 -08001390 if (token != null && token.mWillReplaceWindow && token.mReplacingWindow == this
1391 && token.mHasReplacedWindow) {
Filip Gruszczynskib6e66622015-10-25 16:05:27 -07001392 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replacing window: " + this);
1393 token.mWillReplaceWindow = false;
Filip Gruszczynski55a309f2015-09-04 17:15:01 -07001394 token.mReplacingRemoveRequested = false;
Filip Gruszczynskib6e66622015-10-25 16:05:27 -07001395 token.mReplacingWindow = null;
Filip Gruszczynski78a08ee2015-11-08 18:04:32 -08001396 token.mHasReplacedWindow = false;
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001397 for (int i = token.allAppWindows.size() - 1; i >= 0; i--) {
Filip Gruszczynski78a08ee2015-11-08 18:04:32 -08001398 final WindowState win = token.allAppWindows.get(i);
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001399 if (win.mExiting) {
1400 mService.removeWindowInnerLocked(win);
1401 }
1402 }
1403 }
1404 }
1405
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07001406 void setDisplayLayoutNeeded() {
1407 if (mDisplayContent != null) {
1408 mDisplayContent.layoutNeeded = true;
1409 }
1410 }
1411
Filip Gruszczynski955b2fc2015-10-15 14:46:07 -07001412 boolean inDockedWorkspace() {
1413 return mAppToken != null && mAppToken.mTask != null && mAppToken.mTask.inDockedWorkspace();
1414 }
1415
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001416 int getTouchableRegion(Region region, int flags) {
1417 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001418 if (modal && mAppToken != null) {
1419 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001420 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001421 // If this is a modal window we need to dismiss it if it's not full screen and the
1422 // touch happens outside of the frame that displays the content. This means we
1423 // need to intercept touches outside of that window. The dim layer user
1424 // associated with the window (task or stack) will give us the good bounds, as
1425 // they would be used to display the dim layer.
1426 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1427 if (dimLayerUser != null) {
1428 dimLayerUser.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001429 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001430 getVisibleBounds(mTmpRect);
1431 }
1432 if (inFreeformWorkspace()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001433 // For freeform windows we the touch region to include the whole surface for the
1434 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001435 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
1436 final int delta = WindowManagerService.dipToPixel(
1437 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
1438 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001439 }
1440 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001441 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001442 } else {
1443 // Not modal or full screen modal
1444 getTouchableRegion(region);
1445 }
1446 return flags;
1447 }
1448
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001449 void checkPolicyVisibilityChange() {
1450 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
1451 if (DEBUG_VISIBILITY) {
1452 Slog.v(TAG, "Policy visibility changing after anim in " +
1453 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
1454 }
1455 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001456 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001457 if (!mPolicyVisibility) {
1458 if (mService.mCurrentFocus == this) {
1459 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
1460 "setAnimationLocked: setting mFocusMayChange true");
1461 mService.mFocusMayChange = true;
1462 }
1463 // Window is no longer visible -- make sure if we were waiting
1464 // for it to be displayed before enabling the display, that
1465 // we allow the display to be enabled now.
1466 mService.enableScreenIfNeededLocked();
1467 }
1468 }
1469 }
1470
1471 void setRequestedSize(int requestedWidth, int requestedHeight) {
1472 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
1473 mLayoutNeeded = true;
1474 mRequestedWidth = requestedWidth;
1475 mRequestedHeight = requestedHeight;
1476 }
1477 }
1478
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001479 void prepareWindowToDisplayDuringRelayout(Configuration outConfig) {
1480 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
1481 == SOFT_INPUT_ADJUST_RESIZE) {
1482 mLayoutNeeded = true;
1483 }
1484 if (isDrawnLw() && mService.okToDisplay()) {
1485 mWinAnimator.applyEnterAnimationLocked();
1486 }
1487 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
1488 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
1489 mTurnOnScreen = true;
1490 }
1491 if (isConfigChanged()) {
1492 if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + this + " visible with new config: "
1493 + mService.mCurConfiguration);
1494 outConfig.setTo(mService.mCurConfiguration);
1495 }
1496 }
1497
1498 void adjustStartingWindowFlags() {
1499 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
1500 && mAppToken.startingWindow != null) {
1501 // Special handling of starting window over the base
1502 // window of the app: propagate lock screen flags to it,
1503 // to provide the correct semantics while starting.
1504 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
1505 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
1506 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
1507 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
1508 }
1509 }
1510
1511 void setWindowScale(int requestedWidth, int requestedHeight) {
1512 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
1513
1514 if (scaledWindow) {
1515 // requested{Width|Height} Surface's physical size
1516 // attrs.{width|height} Size on screen
1517 // TODO: We don't check if attrs != null here. Is it implicitly checked?
1518 mHScale = (mAttrs.width != requestedWidth) ?
1519 (mAttrs.width / (float)requestedWidth) : 1.0f;
1520 mVScale = (mAttrs.height != requestedHeight) ?
1521 (mAttrs.height / (float)requestedHeight) : 1.0f;
1522 } else {
1523 mHScale = mVScale = 1;
1524 }
1525 }
1526
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001527 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08001528 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001529 public void binderDied() {
1530 try {
1531 synchronized(mService.mWindowMap) {
1532 WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07001533 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001534 if (win != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001535 if (win.mAppToken != null && !win.mAppToken.clientHidden) {
1536 win.mAppToken.appDied = true;
1537 }
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001538 mService.removeWindowLocked(win);
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001539 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08001540 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001541 mService.removeWindowLocked(WindowState.this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001542 }
1543 }
1544 } catch (IllegalArgumentException ex) {
1545 // This will happen if the window has already been
1546 // removed.
1547 }
1548 }
1549 }
1550
Craig Mautner58106812012-12-28 12:27:40 -08001551 /**
1552 * @return true if this window desires key events.
Craig Mautneref25d7a2012-05-15 23:01:47 -07001553 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001554 public final boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08001555 return isVisibleOrAdding()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001556 && (mViewVisibility == View.VISIBLE)
1557 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
1558 }
1559
Craig Mautner749a7bb2012-04-02 13:49:53 -07001560 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001561 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001562 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001563 }
1564
Craig Mautner749a7bb2012-04-02 13:49:53 -07001565 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001566 public boolean showLw(boolean doAnimation) {
1567 return showLw(doAnimation, true);
1568 }
1569
1570 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07001571 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001572 return false;
1573 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001574 if (!mAppOpVisibility) {
1575 // Being hidden due to app op request.
1576 return false;
1577 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001578 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001579 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001580 return false;
1581 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001582 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001583 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001584 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07001585 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07001586 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001587 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07001588 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001589 // Check for the case where we are currently visible and
1590 // not animating; we do not want to do animation at such a
1591 // point to become visible when we already are.
1592 doAnimation = false;
1593 }
1594 }
1595 mPolicyVisibility = true;
1596 mPolicyVisibilityAfterAnim = true;
1597 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001598 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001599 }
1600 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001601 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001602 }
1603 return true;
1604 }
1605
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001606 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001607 public boolean hideLw(boolean doAnimation) {
1608 return hideLw(doAnimation, true);
1609 }
1610
1611 boolean hideLw(boolean doAnimation, boolean requestAnim) {
1612 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07001613 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001614 doAnimation = false;
1615 }
1616 }
1617 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
1618 : mPolicyVisibility;
1619 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001620 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001621 return false;
1622 }
1623 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001624 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07001625 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001626 doAnimation = false;
1627 }
1628 }
1629 if (doAnimation) {
1630 mPolicyVisibilityAfterAnim = false;
1631 } else {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001632 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001633 mPolicyVisibilityAfterAnim = false;
1634 mPolicyVisibility = false;
1635 // Window is no longer visible -- make sure if we were waiting
1636 // for it to be displayed before enabling the display, that
1637 // we allow the display to be enabled now.
1638 mService.enableScreenIfNeededLocked();
1639 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001640 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07001641 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001642 mService.mFocusMayChange = true;
1643 }
1644 }
1645 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001646 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001647 }
1648 return true;
1649 }
1650
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001651 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001652 if (mAppOpVisibility != state) {
1653 mAppOpVisibility = state;
1654 if (state) {
1655 // If the policy visibility had last been to hide, then this
1656 // will incorrectly show at this point since we lost that
1657 // information. Not a big deal -- for the windows that have app
1658 // ops modifies they should only be hidden by policy due to the
1659 // lock screen, and the user won't be changing this if locked.
1660 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001661 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001662 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001663 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001664 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001665 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001666 }
1667
Jeff Brownc2932a12014-11-20 18:04:05 -08001668 public void pokeDrawLockLw(long timeout) {
1669 if (isVisibleOrAdding()) {
1670 if (mDrawLock == null) {
1671 // We want the tag name to be somewhat stable so that it is easier to correlate
1672 // in wake lock statistics. So in particular, we don't want to include the
1673 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001674 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08001675 mDrawLock = mService.mPowerManager.newWakeLock(
1676 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
1677 mDrawLock.setReferenceCounted(false);
1678 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
1679 }
1680 // Each call to acquire resets the timeout.
1681 if (DEBUG_POWER) {
1682 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
1683 + mAttrs.packageName);
1684 }
1685 mDrawLock.acquire(timeout);
1686 } else if (DEBUG_POWER) {
1687 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
1688 + "owned by " + mAttrs.packageName);
1689 }
1690 }
1691
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001692 @Override
1693 public boolean isAlive() {
1694 return mClient.asBinder().isBinderAlive();
1695 }
1696
Craig Mautnera987d432012-10-11 14:07:58 -07001697 boolean isClosing() {
1698 return mExiting || (mService.mClosingApps.contains(mAppToken));
1699 }
1700
Chong Zhangbef461f2015-10-27 11:38:24 -07001701 boolean isAnimatingWithSavedSurface() {
1702 return mAppToken != null && mAppToken.mAnimatingWithSavedSurface;
1703 }
1704
1705 boolean shouldSaveSurface() {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001706 if (ActivityManager.isLowRamDeviceStatic()) {
1707 // Don't save surfaces on Svelte devices.
1708 return false;
1709 }
1710
1711 Task task = getTask();
Chong Zhangbef461f2015-10-27 11:38:24 -07001712 if (task == null || task.inHomeStack()
Chong Zhangd8ceb852015-11-11 14:53:41 -08001713 || task.getTopVisibleAppToken() != mAppToken) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001714 // Don't save surfaces for home stack apps. These usually resume and draw
1715 // first frame very fast. Saving surfaces are mostly a waste of memory.
Chong Zhangbef461f2015-10-27 11:38:24 -07001716 // Don't save if the window is not the topmost window.
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001717 return false;
1718 }
1719
Chong Zhangbef461f2015-10-27 11:38:24 -07001720 return mAppToken.shouldSaveSurface();
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001721 }
1722
Craig Mautner69b08182012-09-05 13:07:13 -07001723 @Override
1724 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001725 final DisplayContent displayContent = getDisplayContent();
1726 if (displayContent == null) {
1727 // Only a window that was on a non-default display can be detached from it.
1728 return false;
1729 }
Winson Chung47a3e652014-05-21 16:03:42 -07001730 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07001731 }
1732
Adrian Rooscd3884d2015-02-18 17:25:23 +01001733 @Override
1734 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001735 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1736 return dimLayerUser != null && mDisplayContent != null &&
Chong Zhang112eb8c2015-11-02 11:17:00 -08001737 mDisplayContent.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01001738 }
1739
Craig Mautner88400d32012-09-30 12:35:45 -07001740 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
1741 mShowToOwnerOnly = showToOwnerOnly;
1742 }
1743
Craig Mautner5962b122012-10-05 14:45:52 -07001744 boolean isHiddenFromUserLocked() {
Craig Mautner341220f2012-10-16 15:20:09 -07001745 // Attached windows are evaluated based on the window that they are attached to.
1746 WindowState win = this;
1747 while (win.mAttachedWindow != null) {
1748 win = win.mAttachedWindow;
1749 }
1750 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -07001751 && win.mAppToken != null && win.mAppToken.showForAllUsers) {
Craig Mautner341220f2012-10-16 15:20:09 -07001752 // Save some cycles by not calling getDisplayInfo unless it is an application
1753 // window intended for all users.
Craig Mautnerdf88d732014-01-27 09:21:32 -08001754 final DisplayContent displayContent = win.getDisplayContent();
1755 if (displayContent == null) {
1756 return true;
1757 }
1758 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Craig Mautner341220f2012-10-16 15:20:09 -07001759 if (win.mFrame.left <= 0 && win.mFrame.top <= 0
1760 && win.mFrame.right >= displayInfo.appWidth
1761 && win.mFrame.bottom >= displayInfo.appHeight) {
Craig Mautner5962b122012-10-05 14:45:52 -07001762 // Is a fullscreen window, like the clock alarm. Show to everyone.
1763 return false;
1764 }
1765 }
1766
Craig Mautner341220f2012-10-16 15:20:09 -07001767 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01001768 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001769 }
1770
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001771 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
1772 outRegion.set(
1773 frame.left + inset.left, frame.top + inset.top,
1774 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001775 }
1776
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001777 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001778 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001779 switch (mTouchableInsets) {
1780 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001781 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001782 outRegion.set(frame);
1783 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001784 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001785 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001786 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001787 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001788 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001789 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001790 case TOUCHABLE_INSETS_REGION: {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001791 final Region givenTouchableRegion = mGivenTouchableRegion;
1792 outRegion.set(givenTouchableRegion);
1793 outRegion.translate(frame.left, frame.top);
1794 break;
1795 }
1796 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001797 cropRegionToStackBoundsIfNeeded(outRegion);
1798 }
1799
1800 void cropRegionToStackBoundsIfNeeded(Region region) {
1801 if (mAppToken == null || !mAppToken.mCropWindowsToStack) {
1802 return;
1803 }
1804
1805 final TaskStack stack = getStack();
1806 if (stack == null) {
1807 return;
1808 }
1809
1810 stack.getDimBounds(mTmpRect);
1811 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001812 }
1813
Craig Mautner59c00972012-07-30 12:10:24 -07001814 WindowList getWindowList() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001815 final DisplayContent displayContent = getDisplayContent();
1816 return displayContent == null ? null : displayContent.getWindowList();
Craig Mautner59c00972012-07-30 12:10:24 -07001817 }
1818
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001819 /**
1820 * Report a focus change. Must be called with no locks held, and consistently
1821 * from the same serialized thread (such as dispatched from a handler).
1822 */
1823 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
1824 try {
1825 mClient.windowFocusChanged(focused, inTouchMode);
1826 } catch (RemoteException e) {
1827 }
1828 if (mFocusCallbacks != null) {
1829 final int N = mFocusCallbacks.beginBroadcast();
1830 for (int i=0; i<N; i++) {
1831 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
1832 try {
1833 if (focused) {
1834 obs.focusGained(mWindowId.asBinder());
1835 } else {
1836 obs.focusLost(mWindowId.asBinder());
1837 }
1838 } catch (RemoteException e) {
1839 }
1840 }
1841 mFocusCallbacks.finishBroadcast();
1842 }
1843 }
1844
Craig Mautnerdf88d732014-01-27 09:21:32 -08001845 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001846 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08001847 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001848 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
1849 + ": " + mCompatFrame);
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001850 final boolean configChanged = isConfigChanged();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001851 final Task task = getTask();
Wale Ogunwale60454db2015-01-23 16:05:07 -08001852 final Configuration overrideConfig =
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001853 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001854 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) && configChanged) {
1855 Slog.i(TAG, "Sending new config to window " + this + ": "
Robert Carre6a83512015-11-03 16:09:21 -08001856 + " / config="
Wale Ogunwale60454db2015-01-23 16:05:07 -08001857 + mService.mCurConfiguration + " overrideConfig=" + overrideConfig);
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001858 }
Wale Ogunwale60454db2015-01-23 16:05:07 -08001859 setConfiguration(mService.mCurConfiguration, overrideConfig);
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001860 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING)
1861 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
1862
Craig Mautnerdf88d732014-01-27 09:21:32 -08001863 final Rect frame = mFrame;
1864 final Rect overscanInsets = mLastOverscanInsets;
1865 final Rect contentInsets = mLastContentInsets;
1866 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07001867 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001868 final Rect outsets = mLastOutsets;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001869 final boolean reportDraw = mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING;
1870 final Configuration newConfig = configChanged ? mConfiguration : null;
Chet Haase8eb48d22014-09-24 07:31:29 -07001871 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1872 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001873 // To prevent deadlock simulate one-way call if win.mClient is a local object.
1874 mService.mH.post(new Runnable() {
1875 @Override
1876 public void run() {
1877 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001878 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
1879 stableInsets, outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001880 } catch (RemoteException e) {
1881 // Not a remote call, RemoteException won't be raised.
1882 }
1883 }
1884 });
1885 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001886 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001887 outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001888 }
Svetoslav4604abc2014-06-10 18:59:30 -07001889
1890 //TODO (multidisplay): Accessibility supported only for the default display.
1891 if (mService.mAccessibilityController != null
1892 && getDisplayId() == Display.DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07001893 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07001894 }
1895
Craig Mautnerdf88d732014-01-27 09:21:32 -08001896 mOverscanInsetsChanged = false;
1897 mContentInsetsChanged = false;
1898 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07001899 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001900 mOutsetsChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001901 mWinAnimator.mSurfaceResized = false;
1902 } catch (RemoteException e) {
1903 mOrientationChanging = false;
1904 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1905 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08001906 // We are assuming the hosting process is dead or in a zombie state.
1907 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
1908 + ", removing this window.");
1909 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001910 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001911 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001912 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001913 }
1914
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001915 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
1916 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
1917 Configuration newConfig) throws RemoteException {
1918 DisplayInfo displayInfo = getDisplayInfo();
1919 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Chong Zhangd153c4f2015-11-06 20:26:40 -08001920 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
1921 // start even if we haven't received the relayout window, so that the client requests
1922 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
1923 // until the window to small size, otherwise the multithread renderer will shift last
1924 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
1925 // isDragResizing() or isDragResizeChanged() is true.
1926 boolean resizing = isDragResizing() || isDragResizeChanged();
1927 final Rect backDropFrame = (inFreeformWorkspace() || !resizing) ? frame : mTmpRect;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001928 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Chong Zhangd153c4f2015-11-06 20:26:40 -08001929 outsets, reportDraw, newConfig, backDropFrame);
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001930 }
1931
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001932 public void registerFocusObserver(IWindowFocusObserver observer) {
1933 synchronized(mService.mWindowMap) {
1934 if (mFocusCallbacks == null) {
1935 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
1936 }
1937 mFocusCallbacks.register(observer);
1938 }
1939 }
1940
1941 public void unregisterFocusObserver(IWindowFocusObserver observer) {
1942 synchronized(mService.mWindowMap) {
1943 if (mFocusCallbacks != null) {
1944 mFocusCallbacks.unregister(observer);
1945 }
1946 }
1947 }
1948
1949 public boolean isFocused() {
1950 synchronized(mService.mWindowMap) {
1951 return mService.mCurrentFocus == this;
1952 }
1953 }
1954
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07001955 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07001956 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07001957 return task != null && task.inFreeformWorkspace();
1958 }
1959
Chong Zhang3005e752015-09-18 18:46:28 -07001960 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07001961 return mDragResizing != computeDragResizing();
1962 }
1963
Jorim Jaggidcf467c2015-11-05 13:59:32 +01001964 int getResizeMode() {
1965 return mResizeMode;
1966 }
1967
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07001968 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07001969 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07001970 if (task == null) {
1971 return false;
1972 }
1973 if (task.isDragResizing()) {
1974 return true;
1975 }
1976 return mDisplayContent.mDividerControllerLocked.isResizing() &&
1977 !task.inFreeformWorkspace() && !task.isFullscreen();
Chong Zhang3005e752015-09-18 18:46:28 -07001978 }
1979
1980 void setDragResizing() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07001981 mDragResizing = computeDragResizing();
Jorim Jaggidcf467c2015-11-05 13:59:32 +01001982 mResizeMode = mDragResizing && mDisplayContent.mDividerControllerLocked.isResizing()
1983 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
1984 : DRAG_RESIZE_MODE_FREEFORM;
Chong Zhang3005e752015-09-18 18:46:28 -07001985 }
1986
1987 boolean isDragResizing() {
1988 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07001989 }
1990
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001991 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08001992 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001993 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08001994 if (stack != null) {
1995 pw.print(" stackId="); pw.print(stack.mStackId);
1996 }
Craig Mautner59c00972012-07-30 12:10:24 -07001997 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001998 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07001999 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08002000 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
2001 pw.print(" package="); pw.print(mAttrs.packageName);
2002 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002003 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002004 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
2005 pw.print(" h="); pw.print(mRequestedHeight);
2006 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07002007 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
2008 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
2009 pw.print(" h="); pw.println(mLastRequestedHeight);
2010 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002011 if (mAttachedWindow != null || mLayoutAttached) {
2012 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
2013 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
2014 }
2015 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
2016 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
2017 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
2018 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
2019 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
2020 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002021 if (dumpAll) {
2022 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
2023 pw.print(" mSubLayer="); pw.print(mSubLayer);
2024 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautner59431632012-04-04 11:56:44 -07002025 pw.print((mTargetAppToken != null ?
2026 mTargetAppToken.mAppAnimator.animLayerAdjustment
2027 : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002028 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
2029 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08002030 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002031 if (dumpAll) {
2032 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
2033 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
2034 if (mAppToken != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08002035 pw.print(prefix); pw.print("mAppToken="); pw.print(mAppToken);
2036 pw.print(" mAppDied=");pw.println(mAppDied);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002037 }
2038 if (mTargetAppToken != null) {
2039 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
2040 }
2041 pw.print(prefix); pw.print("mViewVisibility=0x");
2042 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002043 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
2044 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07002045 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
2046 pw.print(" mSystemUiVisibility=0x");
2047 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002048 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002049 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
2050 || mAttachedHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002051 pw.print(prefix); pw.print("mPolicyVisibility=");
2052 pw.print(mPolicyVisibility);
2053 pw.print(" mPolicyVisibilityAfterAnim=");
2054 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002055 pw.print(" mAppOpVisibility=");
2056 pw.print(mAppOpVisibility);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002057 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
2058 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08002059 if (!mRelayoutCalled || mLayoutNeeded) {
2060 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
2061 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002062 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002063 if (mXOffset != 0 || mYOffset != 0) {
2064 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
2065 pw.print(" y="); pw.println(mYOffset);
2066 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002067 if (dumpAll) {
2068 pw.print(prefix); pw.print("mGivenContentInsets=");
2069 mGivenContentInsets.printShortString(pw);
2070 pw.print(" mGivenVisibleInsets=");
2071 mGivenVisibleInsets.printShortString(pw);
2072 pw.println();
2073 if (mTouchableInsets != 0 || mGivenInsetsPending) {
2074 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
2075 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07002076 Region region = new Region();
2077 getTouchableRegion(region);
2078 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002079 }
2080 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Wale Ogunwale7c726682015-02-06 17:34:28 -08002081 if (mOverrideConfig != Configuration.EMPTY) {
2082 pw.print(prefix); pw.print("mOverrideConfig="); pw.println(mOverrideConfig);
2083 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002084 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07002085 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07002086 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Craig Mautner178af592012-09-17 10:37:29 -07002087 pw.print(" isReadyForDisplay()="); pw.println(isReadyForDisplay());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002088 if (dumpAll) {
2089 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
2090 pw.print(" last="); mLastFrame.printShortString(pw);
2091 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002092 pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw);
2093 pw.print(" last="); mLastSystemDecorRect.printShortString(pw);
Craig Mautner80b1f642015-04-22 10:59:09 -07002094 if (mWinAnimator.mHasClipRect) {
2095 pw.print(" mLastClipRect=");
2096 mWinAnimator.mLastClipRect.printShortString(pw);
2097 }
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002098 pw.println();
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002099 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002100 if (mEnforceSizeCompat) {
2101 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002102 pw.println();
2103 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002104 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002105 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002106 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002107 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002108 pw.println();
2109 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
2110 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002111 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002112 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002113 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002114 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04002115 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
2116 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002117 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
2118 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002119 pw.print(prefix); pw.print("Cur insets: overscan=");
2120 mOverscanInsets.printShortString(pw);
2121 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002122 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002123 pw.print(" stable="); mStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002124 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002125 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002126 pw.print(prefix); pw.print("Lst insets: overscan=");
2127 mLastOverscanInsets.printShortString(pw);
2128 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002129 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002130 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002131 pw.print(" physical="); mLastOutsets.printShortString(pw);
2132 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002133 pw.println();
2134 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07002135 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
2136 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002137 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
2138 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
2139 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
2140 pw.print(" mDestroying="); pw.print(mDestroying);
2141 pw.print(" mRemoved="); pw.println(mRemoved);
2142 }
2143 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
2144 pw.print(prefix); pw.print("mOrientationChanging=");
2145 pw.print(mOrientationChanging);
2146 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
2147 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
2148 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07002149 if (mLastFreezeDuration != 0) {
2150 pw.print(prefix); pw.print("mLastFreezeDuration=");
2151 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
2152 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002153 if (mHScale != 1 || mVScale != 1) {
2154 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
2155 pw.print(" mVScale="); pw.println(mVScale);
2156 }
2157 if (mWallpaperX != -1 || mWallpaperY != -1) {
2158 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
2159 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
2160 }
2161 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
2162 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
2163 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
2164 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07002165 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
2166 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
2167 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
2168 pw.print(mWallpaperDisplayOffsetX);
2169 pw.print(" mWallpaperDisplayOffsetY=");
2170 pw.println(mWallpaperDisplayOffsetY);
2171 }
Jeff Brownc2932a12014-11-20 18:04:05 -08002172 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07002173 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08002174 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002175 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002176
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002177 String makeInputChannelName() {
2178 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002179 + " " + getWindowTag();
2180 }
2181
2182 private CharSequence getWindowTag() {
2183 CharSequence tag = mAttrs.getTitle();
2184 if (tag == null || tag.length() <= 0) {
2185 tag = mAttrs.packageName;
2186 }
2187 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002188 }
2189
2190 @Override
2191 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002192 final CharSequence title = getWindowTag();
Dianne Hackbornc2293022013-02-06 23:14:49 -08002193 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mExiting) {
2194 mLastTitle = title;
Dianne Hackborn529e7442012-11-01 14:22:28 -07002195 mWasExiting = mExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002196 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -07002197 + " u" + UserHandle.getUserId(mSession.mUid)
Craig Mautnera987d432012-10-11 14:07:58 -07002198 + " " + mLastTitle + (mExiting ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002199 }
2200 return mStringNameCache;
2201 }
Robert Carr58f29132015-10-29 14:19:05 -07002202
2203 void transformFromScreenToSurfaceSpace(Rect rect) {
2204 if (mHScale >= 0) {
2205 rect.right = rect.left + (int)((rect.right - rect.left) / mHScale);
2206 }
2207 if (mVScale >= 0) {
2208 rect.bottom = rect.top + (int)((rect.bottom - rect.top) / mVScale);
2209 }
2210 }
satokcef37fb2011-10-24 21:49:38 +09002211}