blob: e8de90c93f0aa209e6843874c77ea80b01749c7a [file] [log] [blame]
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Wale Ogunwale053c8e42015-11-16 14:27:21 -080019import com.android.server.input.InputWindowHandle;
20
21import android.app.ActivityManager;
22import android.app.AppOpsManager;
23import android.content.Context;
24import android.content.res.Configuration;
25import android.graphics.Matrix;
26import android.graphics.PixelFormat;
27import android.graphics.Point;
28import android.graphics.Rect;
29import android.graphics.Region;
30import android.os.IBinder;
31import android.os.PowerManager;
32import android.os.RemoteCallbackList;
33import android.os.RemoteException;
34import android.os.SystemClock;
35import android.os.Trace;
36import android.os.UserHandle;
37import android.os.WorkSource;
38import android.util.DisplayMetrics;
39import android.util.Slog;
40import android.util.TimeUtils;
41import android.view.Display;
42import android.view.DisplayInfo;
43import android.view.Gravity;
44import android.view.IApplicationToken;
45import android.view.IWindow;
46import android.view.IWindowFocusObserver;
47import android.view.IWindowId;
48import android.view.InputChannel;
49import android.view.InputEvent;
50import android.view.InputEventReceiver;
51import android.view.View;
52import android.view.ViewTreeObserver;
53import android.view.WindowManager;
54import android.view.WindowManagerPolicy;
55
56import java.io.PrintWriter;
57import java.util.ArrayList;
58
Wale Ogunwaled045c822015-12-02 09:14:28 -080059import static android.app.ActivityManager.StackId;
Wale Ogunwalecad05a02015-09-25 10:41:44 -070060import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080061import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
62import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
63import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
64import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080065import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080066import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070067import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080068import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080069import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
70import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080071import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070072import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080073import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080074import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
Robert Carr31e28482015-12-02 16:53:18 -080075import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080076import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Wale Ogunwale8216eb22015-12-18 10:42:42 -080077import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080078import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Robert Carra1eb4392015-12-10 12:43:51 -080079import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080080import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
81import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080082import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080083import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070084import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080085import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
86import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
87import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080088import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
89import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
90import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
91import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
92import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
93import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
94import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
95import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
96import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
97import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
98import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
99import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800100
Craig Mautner59c00972012-07-30 12:10:24 -0700101class WindowList extends ArrayList<WindowState> {
102}
103
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800104/**
105 * A window in the window manager.
106 */
Craig Mautnere32c3072012-03-12 15:25:35 -0700107final class WindowState implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800108 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800109
Skuhne81c524a2015-08-12 13:34:14 -0700110 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700111 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
112 // use hard-coded min sizes for now.
113 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
114 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700115
116 // The thickness of a window resize handle outside the window bounds on the free form workspace
117 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700118 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700119
Jorim Jaggidcf467c2015-11-05 13:59:32 +0100120 static final int DRAG_RESIZE_MODE_FREEFORM = 0;
121 static final int DRAG_RESIZE_MODE_DOCKED_DIVIDER = 1;
122
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800123 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700124 final WindowManagerPolicy mPolicy;
125 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800126 final Session mSession;
127 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800128 final int mAppOp;
129 // UserId and appId of the owner. Don't display windows of non-current user.
130 final int mOwnerUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800131 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800132 WindowToken mToken;
133 WindowToken mRootToken;
134 AppWindowToken mAppToken;
135 AppWindowToken mTargetAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700136
137 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
138 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800139 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
140 final DeathRecipient mDeathRecipient;
141 final WindowState mAttachedWindow;
Craig Mautner7b1aa772012-11-30 16:14:45 -0800142 final WindowList mChildWindows = new WindowList();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800143 final int mBaseLayer;
144 final int mSubLayer;
145 final boolean mLayoutAttached;
146 final boolean mIsImWindow;
147 final boolean mIsWallpaper;
148 final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700149 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700150 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800151 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700152 int mSystemUiVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800153 boolean mPolicyVisibility = true;
154 boolean mPolicyVisibilityAfterAnim = true;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -0800155 boolean mAppOpVisibility = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800156 boolean mAppFreezing;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800157 boolean mAttachedHidden; // is our parent window hidden?
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800158 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Chong Zhang0275e392015-09-17 10:41:44 -0700159 boolean mDragResizing;
Jorim Jaggidcf467c2015-11-05 13:59:32 +0100160 int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700161
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800162 RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
163
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700164 /**
165 * The window size that was requested by the application. These are in
166 * the application's coordinate space (without compatibility scale applied).
167 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800168 int mRequestedWidth;
169 int mRequestedHeight;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700170 int mLastRequestedWidth;
171 int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700172
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800173 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800174 boolean mHaveFrame;
175 boolean mObscured;
176 boolean mTurnOnScreen;
177
178 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700179
Wale Ogunwale60454db2015-01-23 16:05:07 -0800180 private Configuration mConfiguration = Configuration.EMPTY;
181 private Configuration mOverrideConfig = Configuration.EMPTY;
Craig Mautnere8552142012-11-07 13:55:47 -0800182 // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned.
183 // Used only on {@link #TYPE_KEYGUARD}.
184 private boolean mConfigHasChanged;
Craig Mautnera2c77052012-03-26 12:14:43 -0700185
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700186 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700187 * Actual position of the surface shown on-screen (may be modified by animation). These are
188 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700189 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700190 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800191
192 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700193 * Insets that determine the actually visible area. These are in the application's
194 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800195 */
196 final Rect mVisibleInsets = new Rect();
197 final Rect mLastVisibleInsets = new Rect();
198 boolean mVisibleInsetsChanged;
199
200 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700201 * Insets that are covered by system windows (such as the status bar) and
202 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700203 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800204 */
205 final Rect mContentInsets = new Rect();
206 final Rect mLastContentInsets = new Rect();
207 boolean mContentInsetsChanged;
208
209 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800210 * Insets that determine the area covered by the display overscan region. These are in the
211 * application's coordinate space (without compatibility scale applied).
212 */
213 final Rect mOverscanInsets = new Rect();
214 final Rect mLastOverscanInsets = new Rect();
215 boolean mOverscanInsetsChanged;
216
217 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700218 * Insets that determine the area covered by the stable system windows. These are in the
219 * application's coordinate space (without compatibility scale applied).
220 */
221 final Rect mStableInsets = new Rect();
222 final Rect mLastStableInsets = new Rect();
223 boolean mStableInsetsChanged;
224
225 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700226 * Outsets determine the area outside of the surface where we want to pretend that it's possible
227 * to draw anyway.
228 */
229 final Rect mOutsets = new Rect();
230 final Rect mLastOutsets = new Rect();
231 boolean mOutsetsChanged = false;
232
233 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800234 * Set to true if we are waiting for this window to receive its
235 * given internal insets before laying out other windows based on it.
236 */
237 boolean mGivenInsetsPending;
238
239 /**
240 * These are the content insets that were given during layout for
241 * this window, to be applied to windows behind it.
242 */
243 final Rect mGivenContentInsets = new Rect();
244
245 /**
246 * These are the visible insets that were given during layout for
247 * this window, to be applied to windows behind it.
248 */
249 final Rect mGivenVisibleInsets = new Rect();
250
251 /**
252 * This is the given touchable area relative to the window frame, or null if none.
253 */
254 final Region mGivenTouchableRegion = new Region();
255
256 /**
257 * Flag indicating whether the touchable region should be adjusted by
258 * the visible insets; if false the area outside the visible insets is
259 * NOT touchable, so we must use those to adjust the frame during hit
260 * tests.
261 */
262 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
263
264 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400265 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700266 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800267 float mHScale=1, mVScale=1;
268 float mLastHScale=1, mLastVScale=1;
269 final Matrix mTmpMatrix = new Matrix();
270
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700271 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800272 final Rect mFrame = new Rect();
273 final Rect mLastFrame = new Rect();
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700274 // Frame that is scaled to the application's coordinate space when in
275 // screen size compatibility mode.
276 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800277
278 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700279
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800280 final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700281
Wale Ogunwale94596652015-02-06 19:27:34 -0800282 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
283 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700284 final Rect mDisplayFrame = new Rect();
285
286 // The region of the display frame that the display type supports displaying content on. This
287 // is mostly a special case for TV where some displays don’t have the entire display usable.
288 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
289 // window display contents to extend into the overscan region.
290 final Rect mOverscanFrame = new Rect();
291
292 // The display frame minus the stable insets. This value is always constant regardless of if
293 // the status bar or navigation bar is visible.
Adrian Roosfa104232014-06-20 16:10:14 -0700294 final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800295
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700296 // The area not occupied by the status and navigation bars. So, if both status and navigation
297 // bars are visible, the decor frame is equal to the stable frame.
298 final Rect mDecorFrame = new Rect();
299
300 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
301 // minus the area occupied by the IME if the IME is present.
302 final Rect mContentFrame = new Rect();
303
304 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
305 // displays hint text.
306 final Rect mVisibleFrame = new Rect();
307
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700308 // Frame that includes dead area outside of the surface but where we want to pretend that it's
309 // possible to draw.
310 final Rect mOutsetFrame = new Rect();
311
Jorim Jaggidc249c42015-12-15 14:57:31 -0800312 /**
313 * Usually empty. Set to the task's tempInsetFrame. See
314 *{@link android.app.IActivityManager#resizeDockedStack}.
315 */
316 final Rect mInsetFrame = new Rect();
317
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800318 boolean mContentChanged;
319
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800320 // If a window showing a wallpaper: the requested offset for the
321 // wallpaper; if a wallpaper window: the currently applied offset.
322 float mWallpaperX = -1;
323 float mWallpaperY = -1;
324
325 // If a window showing a wallpaper: what fraction of the offset
326 // range corresponds to a full virtual screen.
327 float mWallpaperXStep = -1;
328 float mWallpaperYStep = -1;
329
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700330 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
331 // to its window; if a wallpaper window: not used.
332 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
333 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
334
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800335 // Wallpaper windows: pixels offset based on above variables.
336 int mXOffset;
337 int mYOffset;
338
Craig Mautner2268e7e2012-12-13 15:40:00 -0800339 /**
340 * This is set after IWindowSession.relayout() has been called at
341 * least once for the window. It allows us to detect the situation
342 * where we don't yet have a surface, but should have one soon, so
343 * we can give the window focus before waiting for the relayout.
344 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800345 boolean mRelayoutCalled;
346
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800347 /**
348 * If the application has called relayout() with changes that can
349 * impact its window's size, we need to perform a layout pass on it
350 * even if it is not currently visible for layout. This is set
351 * when in that case until the layout is done.
352 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800353 boolean mLayoutNeeded;
354
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800355 /** Currently running an exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800356 boolean mExiting;
357
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800358 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800359 boolean mDestroying;
360
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800361 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800362 boolean mRemoveOnExit;
363
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800364 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800365 * Whether the app died while it was visible, if true we might need
366 * to continue to show it until it's restarted.
367 */
368 boolean mAppDied;
369
370 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800371 * Set when the orientation is changing and this window has not yet
372 * been updated for the new orientation.
373 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800374 boolean mOrientationChanging;
375
Dianne Hackborna57c6952013-03-29 14:46:40 -0700376 /**
377 * How long we last kept the screen frozen.
378 */
379 int mLastFreezeDuration;
380
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800381 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800382 boolean mRemoved;
383
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800384 /**
385 * Temp for keeping track of windows that have been removed when
386 * rebuilding window list.
387 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800388 boolean mRebuilding;
389
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800390 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700391 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800392 InputChannel mInputChannel;
Chong Zhang112eb8c2015-11-02 11:17:00 -0800393 InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800394
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800395 // Used to improve performance of toString()
396 String mStringNameCache;
397 CharSequence mLastTitle;
Dianne Hackborn529e7442012-11-01 14:22:28 -0700398 boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800399
Craig Mautnera2c77052012-03-26 12:14:43 -0700400 final WindowStateAnimator mWinAnimator;
401
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700402 boolean mHasSurface = false;
403
Craig Mautner19ab8282014-05-07 10:35:34 -0700404 boolean mNotOnAppsDisplay = false;
Craig Mautner59c00972012-07-30 12:10:24 -0700405 DisplayContent mDisplayContent;
Craig Mautner6881a102012-07-27 13:04:51 -0700406
Craig Mautner88400d32012-09-30 12:35:45 -0700407 /** When true this window can be displayed on screens owther than mOwnerUid's */
408 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700409
Robert Carr13f7be9e2015-12-02 18:39:45 -0800410 // Whether the window has a saved surface from last pause, which can be
411 // used to start an entering animation earlier.
412 public boolean mSurfaceSaved = false;
413
Robert Carra1eb4392015-12-10 12:43:51 -0800414 // This window will be replaced due to relaunch. This allows window manager
415 // to differentiate between simple removal of a window and replacement. In the latter case it
416 // will preserve the old window until the new one is drawn.
417 boolean mWillReplaceWindow = false;
418 // If true, the replaced window was already requested to be removed.
419 boolean mReplacingRemoveRequested = false;
420 // Whether the replacement of the window should trigger app transition animation.
421 boolean mAnimateReplacingWindow = false;
422 // If not null, the window that will be used to replace the old one. This is being set when
423 // the window is added and unset when this window reports its first draw.
424 WindowState mReplacingWindow = null;
425
Chong Zhangbd0d9372015-12-28 15:18:29 -0800426 // Whether this window is being moved via the resize API
427 boolean mMovedByResize;
Jeff Brownc2932a12014-11-20 18:04:05 -0800428 /**
429 * Wake lock for drawing.
430 * Even though it's slightly more expensive to do so, we will use a separate wake lock
431 * for each app that is requesting to draw while dozing so that we can accurately track
432 * who is preventing the system from suspending.
433 * This lock is only acquired on first use.
434 */
435 PowerManager.WakeLock mDrawLock;
436
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700437 final private Rect mTmpRect = new Rect();
438
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800439 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800440 WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a,
Craig Mautner59c00972012-07-30 12:10:24 -0700441 int viewVisibility, final DisplayContent displayContent) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800442 mService = service;
443 mSession = s;
444 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800445 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800446 mToken = token;
Craig Mautnera2d7b112012-08-21 15:12:20 -0700447 mOwnerUid = s.mUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800448 mWindowId = new IWindowId.Stub() {
449 @Override
450 public void registerFocusObserver(IWindowFocusObserver observer) {
451 WindowState.this.registerFocusObserver(observer);
452 }
453 @Override
454 public void unregisterFocusObserver(IWindowFocusObserver observer) {
455 WindowState.this.unregisterFocusObserver(observer);
456 }
457 @Override
458 public boolean isFocused() {
459 return WindowState.this.isFocused();
460 }
461 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800462 mAttrs.copyFrom(a);
463 mViewVisibility = viewVisibility;
Craig Mautner59c00972012-07-30 12:10:24 -0700464 mDisplayContent = displayContent;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700465 mPolicy = mService.mPolicy;
466 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800467 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700468 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700469 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800470 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700471 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700472 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800473 try {
474 c.asBinder().linkToDeath(deathRecipient, 0);
475 } catch (RemoteException e) {
476 mDeathRecipient = null;
477 mAttachedWindow = null;
478 mLayoutAttached = false;
479 mIsImWindow = false;
480 mIsWallpaper = false;
481 mIsFloatingLayer = false;
482 mBaseLayer = 0;
483 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700484 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700485 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800486 return;
487 }
488 mDeathRecipient = deathRecipient;
489
490 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
491 mAttrs.type <= LAST_SUB_WINDOW)) {
492 // The multiplier here is to reserve space for multiple
493 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700494 mBaseLayer = mPolicy.windowTypeToLayerLw(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800495 attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
496 + WindowManagerService.TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700497 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800498 mAttachedWindow = attachedWindow;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800499 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
takeda.masayuki18735092012-12-12 11:06:24 +0900500
tiger_huange2a98a72014-11-13 19:46:28 +0800501 final WindowList childWindows = mAttachedWindow.mChildWindows;
502 final int numChildWindows = childWindows.size();
503 if (numChildWindows == 0) {
504 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900505 } else {
tiger_huange2a98a72014-11-13 19:46:28 +0800506 boolean added = false;
507 for (int i = 0; i < numChildWindows; i++) {
508 final int childSubLayer = childWindows.get(i).mSubLayer;
509 if (mSubLayer < childSubLayer
510 || (mSubLayer == childSubLayer && childSubLayer < 0)) {
511 // We insert the child window into the list ordered by the sub-layer. For
512 // same sub-layers, the negative one should go below others; the positive
513 // one should go above others.
514 childWindows.add(i, this);
515 added = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900516 break;
takeda.masayuki18735092012-12-12 11:06:24 +0900517 }
518 }
tiger_huange2a98a72014-11-13 19:46:28 +0800519 if (!added) {
520 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900521 }
522 }
523
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800524 mLayoutAttached = mAttrs.type !=
525 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
526 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
527 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
528 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
529 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
530 } else {
531 // The multiplier here is to reserve space for multiple
532 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700533 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800534 * WindowManagerService.TYPE_LAYER_MULTIPLIER
535 + WindowManagerService.TYPE_LAYER_OFFSET;
536 mSubLayer = 0;
537 mAttachedWindow = null;
538 mLayoutAttached = false;
539 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
540 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
541 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
542 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
543 }
544
545 WindowState appWin = this;
Robert Carr51a1b872015-12-08 14:03:13 -0800546 while (appWin.isChildWindow()) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700547 appWin = appWin.mAttachedWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800548 }
549 WindowToken appToken = appWin.mToken;
550 while (appToken.appWindowToken == null) {
551 WindowToken parent = mService.mTokenMap.get(appToken.token);
552 if (parent == null || appToken == parent) {
553 break;
554 }
555 appToken = parent;
556 }
557 mRootToken = appToken;
558 mAppToken = appToken.appWindowToken;
Craig Mautner19ab8282014-05-07 10:35:34 -0700559 if (mAppToken != null) {
560 final DisplayContent appDisplay = getDisplayContent();
561 mNotOnAppsDisplay = displayContent != appDisplay;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700562
563 if (mAppToken.showForAllUsers) {
564 // Windows for apps that can show for all users should also show when the
565 // device is locked.
566 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
567 }
Craig Mautner19ab8282014-05-07 10:35:34 -0700568 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800569
Craig Mautner322e4032012-07-13 13:35:20 -0700570 mWinAnimator = new WindowStateAnimator(this);
571 mWinAnimator.mAlpha = a.alpha;
572
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800573 mRequestedWidth = 0;
574 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700575 mLastRequestedWidth = 0;
576 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800577 mXOffset = 0;
578 mYOffset = 0;
579 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800580 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700581 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
582 displayContent.getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800583 }
584
585 void attach() {
586 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700587 TAG, "Attaching " + this + " token=" + mToken
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800588 + ", list=" + mToken.windows);
589 mSession.windowAddedLocked();
590 }
591
Craig Mautnera2c77052012-03-26 12:14:43 -0700592 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800593 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800594 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800595 }
596
597 @Override
598 public String getOwningPackage() {
599 return mAttrs.packageName;
600 }
601
602 @Override
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700603 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf, Rect sf,
604 Rect osf) {
Robert Carra1eb4392015-12-10 12:43:51 -0800605 if (mWillReplaceWindow && (mExiting || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700606 // This window is being replaced and either already got information that it's being
607 // removed or we are still waiting for some information. Because of this we don't
608 // want to apply any more changes to it, so it remains in this state until new window
609 // appears.
610 return;
611 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800612 mHaveFrame = true;
613
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700614 final Task task = getTask();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800615 final boolean fullscreenTask = task == null || task.isFullscreen();
Chong Zhang09b21ef2015-09-14 10:20:21 -0700616 final boolean freeformWorkspace = task != null && task.inFreeformWorkspace();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800617
Wale Ogunwale8216eb22015-12-18 10:42:42 -0800618 if (fullscreenTask || (isChildWindow()
619 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0)) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800620 // We use the parent frame as the containing frame for fullscreen and child windows
621 mContainingFrame.set(pf);
622 mDisplayFrame.set(df);
Jorim Jaggidc249c42015-12-15 14:57:31 -0800623 mInsetFrame.setEmpty();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800624 } else {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700625 task.getBounds(mContainingFrame);
Jorim Jaggidc249c42015-12-15 14:57:31 -0800626 task.getTempInsetBounds(mInsetFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100627 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
628
629 // If the bounds are frozen, we still want to translate the window freely and only
630 // freeze the size.
631 Rect frozen = mAppToken.mFrozenBounds.peek();
632 mContainingFrame.right = mContainingFrame.left + frozen.width();
633 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
634 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800635 final WindowState imeWin = mService.mInputMethodWindow;
636 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this
637 && mContainingFrame.bottom > cf.bottom) {
638 // IME is up and obscuring this window. Adjust the window position so it is visible.
639 mContainingFrame.top -= mContainingFrame.bottom - cf.bottom;
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700640 }
Skuhne81c524a2015-08-12 13:34:14 -0700641
Skuhnef932e562015-08-20 12:07:30 -0700642 if (freeformWorkspace) {
Skuhne81c524a2015-08-12 13:34:14 -0700643 // In free form mode we have only to set the rectangle if it wasn't set already. No
644 // need to intersect it with the (visible) "content frame" since it is allowed to
645 // be outside the visible desktop.
646 if (mContainingFrame.isEmpty()) {
647 mContainingFrame.set(cf);
648 }
Doris Liu06d582d2015-06-01 13:18:43 -0700649 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800650 mDisplayFrame.set(mContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700651 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800652
Craig Mautner967212c2013-04-13 21:10:58 -0700653 final int pw = mContainingFrame.width();
654 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800655
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800656 if (!mParentFrame.equals(pf)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800657 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800658 // + " to " + pf);
659 mParentFrame.set(pf);
660 mContentChanged = true;
661 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700662 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
663 mLastRequestedWidth = mRequestedWidth;
664 mLastRequestedHeight = mRequestedHeight;
665 mContentChanged = true;
666 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800667
Craig Mautnereda67292013-04-28 13:50:14 -0700668 mOverscanFrame.set(of);
669 mContentFrame.set(cf);
670 mVisibleFrame.set(vf);
John Spurlock46646232013-09-30 22:32:42 -0400671 mDecorFrame.set(dcf);
Adrian Roosfa104232014-06-20 16:10:14 -0700672 mStableFrame.set(sf);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700673 final boolean hasOutsets = osf != null;
674 if (hasOutsets) {
675 mOutsetFrame.set(osf);
676 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800677
Craig Mautnereda67292013-04-28 13:50:14 -0700678 final int fw = mFrame.width();
679 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800680
Robert Carr31e28482015-12-02 16:53:18 -0800681 applyGravityAndUpdateFrame();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800682
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700683 // Calculate the outsets before the content frame gets shrinked to the window frame.
684 if (hasOutsets) {
685 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
686 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
687 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
688 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
689 } else {
690 mOutsets.set(0, 0, 0, 0);
691 }
692
Jorim Jaggidc249c42015-12-15 14:57:31 -0800693 // Denotes the actual frame used to calculate the insets. When resizing in docked mode,
694 // we'd like to freeze the layout, so we also need to freeze the insets temporarily. By the
695 // notion of a task having a different inset frame, we can achieve that while still moving
696 // the task around.
697 final Rect frame = !mInsetFrame.isEmpty() ? mInsetFrame : mFrame;
698
Craig Mautnera248eee2013-05-07 11:41:27 -0700699 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800700 // final window frame.
Skuhnef932e562015-08-20 12:07:30 -0700701 if (freeformWorkspace && !mFrame.isEmpty()) {
Skuhne81c524a2015-08-12 13:34:14 -0700702 // Keep the frame out of the blocked system area, limit it in size to the content area
703 // and make sure that there is always a minimum visible so that the user can drag it
704 // into a usable area..
705 final int height = Math.min(mFrame.height(), mContentFrame.height());
706 final int width = Math.min(mContentFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700707 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700708 final int minVisibleHeight = WindowManagerService.dipToPixel(
709 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics);
710 final int minVisibleWidth = WindowManagerService.dipToPixel(
711 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics);
Skuhne81c524a2015-08-12 13:34:14 -0700712 final int top = Math.max(mContentFrame.top,
713 Math.min(mFrame.top, mContentFrame.bottom - minVisibleHeight));
714 final int left = Math.max(mContentFrame.left + minVisibleWidth - width,
715 Math.min(mFrame.left, mContentFrame.right - minVisibleWidth));
716 mFrame.set(left, top, left + width, top + height);
717 mContentFrame.set(mFrame);
718 mVisibleFrame.set(mContentFrame);
719 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700720 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800721 if (isVisibleLw() || mWinAnimator.isAnimating()) {
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800722 // We don't adjust the dock divider frame for reasons other than performance. The
723 // real reason is that if it gets adjusted before it is shown for the first time,
724 // it would get size (0, 0). This causes a problem when we finally show the dock
725 // divider and try to draw to it. We do set the surface size at that moment to
726 // the correct size, but it's too late for the Surface Flinger to make it
727 // available for view rendering and as a result the renderer receives size 1, 1.
728 // This way we just keep the divider at the original size and Surface Flinger
729 // will return the correct value to the renderer.
730 mDisplayContent.getDockedDividerController().positionDockedStackedDivider(mFrame);
731 mContentFrame.set(mFrame);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800732 if (!mFrame.equals(mLastFrame)) {
733 mMovedByResize = true;
734 }
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800735 }
Skuhne81c524a2015-08-12 13:34:14 -0700736 } else {
Jorim Jaggidc249c42015-12-15 14:57:31 -0800737 mContentFrame.set(Math.max(mContentFrame.left, frame.left),
738 Math.max(mContentFrame.top, frame.top),
739 Math.min(mContentFrame.right, frame.right),
740 Math.min(mContentFrame.bottom, frame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800741
Jorim Jaggidc249c42015-12-15 14:57:31 -0800742 mVisibleFrame.set(Math.max(mVisibleFrame.left, frame.left),
743 Math.max(mVisibleFrame.top, frame.top),
744 Math.min(mVisibleFrame.right, frame.right),
745 Math.min(mVisibleFrame.bottom, frame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800746
Jorim Jaggidc249c42015-12-15 14:57:31 -0800747 mStableFrame.set(Math.max(mStableFrame.left, frame.left),
748 Math.max(mStableFrame.top, frame.top),
749 Math.min(mStableFrame.right, frame.right),
750 Math.min(mStableFrame.bottom, frame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700751 }
Adrian Roosfa104232014-06-20 16:10:14 -0700752
Jorim Jaggidc249c42015-12-15 14:57:31 -0800753 mOverscanInsets.set(Math.max(mOverscanFrame.left - frame.left, 0),
754 Math.max(mOverscanFrame.top - frame.top, 0),
755 Math.max(frame.right - mOverscanFrame.right, 0),
756 Math.max(frame.bottom - mOverscanFrame.bottom, 0));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800757
Craig Mautnereda67292013-04-28 13:50:14 -0700758
Craig Mautnereda67292013-04-28 13:50:14 -0700759
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100760 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
761
762 // For the docked divider, we calculate the stable insets like a full-screen window
763 // so it can use it to calculate the snap positions.
764 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
765 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
766 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
767 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800768
769 // The divider doesn't care about insets in any case, so set it to empty so we don't
770 // trigger a relayout when moving it.
771 mContentInsets.setEmpty();
772 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100773 } else {
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800774 mContentInsets.set(mContentFrame.left - frame.left,
775 mContentFrame.top - frame.top,
776 frame.right - mContentFrame.right,
777 frame.bottom - mContentFrame.bottom);
778
779 mVisibleInsets.set(mVisibleFrame.left - frame.left,
780 mVisibleFrame.top - frame.top,
781 frame.right - mVisibleFrame.right,
782 frame.bottom - mVisibleFrame.bottom);
783
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100784 mStableInsets.set(Math.max(mStableFrame.left - frame.left, 0),
785 Math.max(mStableFrame.top - frame.top, 0),
786 Math.max(frame.right - mStableFrame.right, 0),
787 Math.max(frame.bottom - mStableFrame.bottom, 0));
788 }
Adrian Roosfa104232014-06-20 16:10:14 -0700789
Jorim Jaggidc249c42015-12-15 14:57:31 -0800790 if (!mInsetFrame.isEmpty()) {
791 mContentFrame.set(mFrame);
792 mContentFrame.top += mContentInsets.top;
793 mContentFrame.bottom += mContentInsets.bottom;
794 mContentFrame.left += mContentInsets.left;
795 mContentFrame.right += mContentInsets.right;
796 mVisibleFrame.set(mFrame);
797 mVisibleFrame.top += mVisibleInsets.top;
798 mVisibleFrame.bottom += mVisibleInsets.bottom;
799 mVisibleFrame.left += mVisibleInsets.left;
800 mVisibleFrame.right += mVisibleInsets.right;
801 mStableFrame.set(mFrame);
802 mStableFrame.top += mStableInsets.top;
803 mStableFrame.bottom += mStableInsets.bottom;
804 mStableFrame.left += mStableInsets.left;
805 mStableFrame.right += mStableInsets.right;
806 }
Craig Mautnereda67292013-04-28 13:50:14 -0700807 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400808 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700809 // If there is a size compatibility scale being applied to the
810 // window, we need to apply this to its insets so that they are
811 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700812 mOverscanInsets.scale(mInvGlobalScale);
813 mContentInsets.scale(mInvGlobalScale);
814 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700815 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700816 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700817
818 // Also the scaled frame that we report to the app needs to be
819 // adjusted to be in its coordinate space.
820 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400821 }
822
Craig Mautnereda67292013-04-28 13:50:14 -0700823 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800824 final DisplayContent displayContent = getDisplayContent();
825 if (displayContent != null) {
826 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700827 mService.mWallpaperControllerLocked.updateWallpaperOffset(
828 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800829 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800830 }
831
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700832 if (DEBUG_LAYOUT || WindowManagerService.localLOGV) Slog.v(TAG,
833 "Resolving (mRequestedWidth="
834 + mRequestedWidth + ", mRequestedheight="
835 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
836 + "): frame=" + mFrame.toShortString()
837 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -0700838 + " vi=" + mVisibleInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700839 + " vi=" + mStableInsets.toShortString()
840 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800841 }
842
Craig Mautnera2c77052012-03-26 12:14:43 -0700843 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800844 public Rect getFrameLw() {
845 return mFrame;
846 }
847
Craig Mautnera2c77052012-03-26 12:14:43 -0700848 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700849 public Point getShownPositionLw() {
850 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800851 }
852
Craig Mautnera2c77052012-03-26 12:14:43 -0700853 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800854 public Rect getDisplayFrameLw() {
855 return mDisplayFrame;
856 }
857
Craig Mautnera2c77052012-03-26 12:14:43 -0700858 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800859 public Rect getOverscanFrameLw() {
860 return mOverscanFrame;
861 }
862
863 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800864 public Rect getContentFrameLw() {
865 return mContentFrame;
866 }
867
Craig Mautnera2c77052012-03-26 12:14:43 -0700868 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800869 public Rect getVisibleFrameLw() {
870 return mVisibleFrame;
871 }
872
Craig Mautnera2c77052012-03-26 12:14:43 -0700873 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800874 public boolean getGivenInsetsPendingLw() {
875 return mGivenInsetsPending;
876 }
877
Craig Mautnera2c77052012-03-26 12:14:43 -0700878 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800879 public Rect getGivenContentInsetsLw() {
880 return mGivenContentInsets;
881 }
882
Craig Mautnera2c77052012-03-26 12:14:43 -0700883 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800884 public Rect getGivenVisibleInsetsLw() {
885 return mGivenVisibleInsets;
886 }
887
Craig Mautnera2c77052012-03-26 12:14:43 -0700888 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800889 public WindowManager.LayoutParams getAttrs() {
890 return mAttrs;
891 }
892
Craig Mautner812d2ca2012-09-27 15:35:34 -0700893 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800894 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
895 int index = -1;
896 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -0700897 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800898 while (true) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -0700899 if (ws.mAttrs.needsMenuKey != WindowManager.LayoutParams.NEEDS_MENU_UNSET) {
900 return ws.mAttrs.needsMenuKey == WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800901 }
902 // If we reached the bottom of the range of windows we are considering,
903 // assume no menu is needed.
904 if (ws == bottom) {
905 return false;
906 }
907 // The current window hasn't specified whether menu key is needed;
908 // look behind it.
909 // First, we may need to determine the starting position.
910 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -0700911 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800912 }
913 index--;
914 if (index < 0) {
915 return false;
916 }
Craig Mautner59c00972012-07-30 12:10:24 -0700917 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800918 }
919 }
920
Craig Mautner19d59bc2012-09-04 11:15:56 -0700921 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700922 public int getSystemUiVisibility() {
923 return mSystemUiVisibility;
924 }
925
Craig Mautner19d59bc2012-09-04 11:15:56 -0700926 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800927 public int getSurfaceLayer() {
928 return mLayer;
929 }
930
Craig Mautner812d2ca2012-09-27 15:35:34 -0700931 @Override
Selim Cinekd6623612015-05-22 18:56:22 -0700932 public int getBaseType() {
933 WindowState win = this;
Robert Carr51a1b872015-12-08 14:03:13 -0800934 while (win.isChildWindow()) {
Selim Cinekd6623612015-05-22 18:56:22 -0700935 win = win.mAttachedWindow;
936 }
937 return win.mAttrs.type;
938 }
939
940 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800941 public IApplicationToken getAppToken() {
942 return mAppToken != null ? mAppToken.appToken : null;
943 }
Craig Mautner19d59bc2012-09-04 11:15:56 -0700944
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700945 @Override
946 public boolean isVoiceInteraction() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700947 return mAppToken != null && mAppToken.voiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700948 }
949
Craig Mautner4c5eb222013-11-18 12:59:05 -0800950 boolean setInsetsChanged() {
951 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
952 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
953 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -0700954 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700955 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
956 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
957 || mOutsetsChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -0800958 }
959
Craig Mautnerdf88d732014-01-27 09:21:32 -0800960 public DisplayContent getDisplayContent() {
Chad Jonesf391ebc2014-06-12 17:45:05 -0700961 if (mAppToken == null || mNotOnAppsDisplay) {
Craig Mautnerbe634952014-06-12 13:39:24 -0700962 return mDisplayContent;
963 }
964 final TaskStack stack = getStack();
965 return stack == null ? mDisplayContent : stack.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -0800966 }
967
Chong Zhang09b21ef2015-09-14 10:20:21 -0700968 public DisplayInfo getDisplayInfo() {
969 final DisplayContent displayContent = getDisplayContent();
970 return displayContent != null ? displayContent.getDisplayInfo() : null;
971 }
972
Craig Mautner19d59bc2012-09-04 11:15:56 -0700973 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800974 final DisplayContent displayContent = getDisplayContent();
975 if (displayContent == null) {
976 return -1;
977 }
978 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -0700979 }
980
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700981 Task getTask() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700982 return mAppToken != null ? mAppToken.mTask : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700983 }
984
985 TaskStack getStack() {
986 Task task = getTask();
987 if (task != null) {
988 if (task.mStack != null) {
989 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -0700990 }
Craig Mautnerd9a22882013-03-16 15:00:36 -0700991 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700992 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
993 // associate them with some stack to enable dimming.
994 return mAttrs.type >= WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
995 && mDisplayContent != null ? mDisplayContent.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -0700996 }
997
Skuhnef932e562015-08-20 12:07:30 -0700998 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700999 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001000 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001001 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001002 void getVisibleBounds(Rect bounds) {
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001003 boolean intersectWithStackBounds = mAppToken != null && mAppToken.mCropWindowsToStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001004 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001005 mTmpRect.setEmpty();
1006 if (intersectWithStackBounds) {
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001007 final TaskStack stack = getStack();
1008 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001009 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001010 } else {
1011 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001012 }
1013 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001014
Chong Zhang9184ec62015-09-24 12:32:21 -07001015 bounds.set(mVisibleFrame);
1016 if (intersectWithStackBounds) {
1017 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001018 }
1019
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001020 if (bounds.isEmpty()) {
1021 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001022 if (intersectWithStackBounds) {
1023 bounds.intersect(mTmpRect);
1024 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001025 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001026 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001027 }
1028
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001029 public long getInputDispatchingTimeoutNanos() {
1030 return mAppToken != null
1031 ? mAppToken.inputDispatchingTimeoutNanos
1032 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1033 }
1034
Craig Mautnere8552142012-11-07 13:55:47 -08001035 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001036 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001037 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001038 }
1039
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001040 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1041 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1042 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1043 if (dtdx < -.000001f || dtdx > .000001f) return false;
1044 if (dsdy < -.000001f || dsdy > .000001f) return false;
1045 return true;
1046 }
1047
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001048 void prelayout() {
1049 if (mEnforceSizeCompat) {
1050 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001051 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001052 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001053 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001054 }
1055 }
1056
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001057 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001058 * Does the minimal check for visibility. Callers generally want to use one of the public
1059 * methods as they perform additional checks on the app token.
1060 * TODO: See if there are other places we can use this check below instead of duplicating...
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001061 */
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001062 private boolean isVisibleUnchecked() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001063 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001064 && !mExiting && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001065 }
1066
1067 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001068 * Is this window visible? It is not visible if there is no surface, or we are in the process
1069 * of running an exit animation that will remove the surface, or its app token has been hidden.
1070 */
1071 @Override
1072 public boolean isVisibleLw() {
1073 return (mAppToken == null || !mAppToken.hiddenRequested) && isVisibleUnchecked();
1074 }
1075
1076 /**
1077 * Like {@link #isVisibleLw}, but also counts a window that is currently "hidden" behind the
1078 * keyguard as visible. This allows us to apply things like window flags that impact the
1079 * keyguard. XXX I am starting to think we need to have ANOTHER visibility flag for this
1080 * "hidden behind keyguard" state rather than overloading mPolicyVisibility. Ungh.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001081 */
Craig Mautner88400d32012-09-30 12:35:45 -07001082 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001083 public boolean isVisibleOrBehindKeyguardLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001084 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001085 return false;
1086 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001087 final AppWindowToken atoken = mAppToken;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001088 final boolean animating = atoken != null && atoken.mAppAnimator.animation != null;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001089 return mHasSurface && !mDestroying && !mExiting
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001090 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001091 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001092 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001093 }
1094
1095 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001096 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1097 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001098 */
1099 public boolean isWinVisibleLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001100 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.mAppAnimator.animating)
1101 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001102 }
1103
1104 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001105 * The same as isVisible(), but follows the current hidden state of the associated app token,
1106 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001107 */
1108 boolean isVisibleNow() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001109 return (!mRootToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
1110 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001111 }
1112
1113 /**
1114 * Can this window possibly be a drag/drop target? The test here is
1115 * a combination of the above "visible now" with the check that the
1116 * Input Manager uses when discarding windows from input consideration.
1117 */
1118 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001119 return isVisibleNow() && !mRemoved
1120 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001121 }
1122
1123 /**
1124 * Same as isVisible(), but we also count it as visible between the
1125 * call to IWindowSession.add() and the first relayout().
1126 */
1127 boolean isVisibleOrAdding() {
1128 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001129 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001130 && mPolicyVisibility && !mAttachedHidden
1131 && (atoken == null || !atoken.hiddenRequested)
1132 && !mExiting && !mDestroying;
1133 }
1134
1135 /**
1136 * Is this window currently on-screen? It is on-screen either if it
1137 * is visible or it is currently running an animation before no longer
1138 * being visible.
1139 */
1140 boolean isOnScreen() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001141 return mPolicyVisibility && isOnScreenIgnoringKeyguard();
1142 }
1143
1144 /**
1145 * Like isOnScreen(), but ignores any force hiding of the window due
1146 * to the keyguard.
1147 */
1148 boolean isOnScreenIgnoringKeyguard() {
1149 if (!mHasSurface || mDestroying) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001150 return false;
1151 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001152 final AppWindowToken atoken = mAppToken;
1153 if (atoken != null) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001154 return ((!mAttachedHidden && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001155 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001156 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001157 return !mAttachedHidden || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001158 }
1159
1160 /**
1161 * Like isOnScreen(), but we don't return true if the window is part
1162 * of a transition that has not yet been started.
1163 */
1164 boolean isReadyForDisplay() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001165 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001166 return false;
1167 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001168 return mHasSurface && mPolicyVisibility && !mDestroying
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001169 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001170 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001171 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001172 }
1173
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001174 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001175 * Like isReadyForDisplay(), but ignores any force hiding of the window due
1176 * to the keyguard.
1177 */
1178 boolean isReadyForDisplayIgnoringKeyguard() {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001179 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001180 return false;
1181 }
1182 final AppWindowToken atoken = mAppToken;
1183 if (atoken == null && !mPolicyVisibility) {
1184 // If this is not an app window, and the policy has asked to force
1185 // hide, then we really do want to hide.
1186 return false;
1187 }
1188 return mHasSurface && !mDestroying
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001189 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE && !mRootToken.hidden)
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001190 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -07001191 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
1192 && !mWinAnimator.isDummyAnimation()));
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001193 }
1194
1195 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001196 * Like isOnScreen, but returns false if the surface hasn't yet
1197 * been drawn.
1198 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001199 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001200 public boolean isDisplayedLw() {
1201 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001202 return isDrawnLw() && mPolicyVisibility
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001203 && ((!mAttachedHidden &&
1204 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001205 || mWinAnimator.mAnimating
1206 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001207 }
1208
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001209 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001210 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001211 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001212 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001213 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001214 return mWinAnimator.mAnimation != null
1215 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001216 }
1217
Craig Mautner812d2ca2012-09-27 15:35:34 -07001218 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001219 public boolean isGoneForLayoutLw() {
1220 final AppWindowToken atoken = mAppToken;
1221 return mViewVisibility == View.GONE
1222 || !mRelayoutCalled
1223 || (atoken == null && mRootToken.hidden)
Craig Mautner812d2ca2012-09-27 15:35:34 -07001224 || (atoken != null && (atoken.hiddenRequested || atoken.hidden))
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001225 || mAttachedHidden
Craig Mautner0e415c62013-04-29 16:10:58 -07001226 || (mExiting && !isAnimatingLw())
1227 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001228 }
1229
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001230 /**
1231 * Returns true if the window has a surface that it has drawn a
1232 * complete UI in to.
1233 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001234 public boolean isDrawFinishedLw() {
1235 return mHasSurface && !mDestroying &&
1236 (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING
1237 || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1238 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
1239 }
1240
1241 /**
1242 * Returns true if the window has a surface that it has drawn a
1243 * complete UI in to.
1244 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001245 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001246 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001247 return mHasSurface && !mDestroying &&
Craig Mautner749a7bb2012-04-02 13:49:53 -07001248 (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1249 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001250 }
1251
1252 /**
1253 * Return true if the window is opaque and fully drawn. This indicates
1254 * it may obscure windows behind it.
1255 */
1256 boolean isOpaqueDrawn() {
1257 return (mAttrs.format == PixelFormat.OPAQUE
1258 || mAttrs.type == TYPE_WALLPAPER)
Craig Mautnera2c77052012-03-26 12:14:43 -07001259 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001260 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001261 }
1262
1263 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001264 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001265 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1266 */
Craig Mautner4557c082015-04-27 13:07:40 -07001267 boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001268 return mHasSurface && (mContentChanged || mMovedByResize)
1269 && !mExiting && !mWinAnimator.mLastHidden && mService.okToDisplay()
1270 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Craig Mautner4557c082015-04-27 13:07:40 -07001271 && (mAttachedWindow == null || !mAttachedWindow.hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001272 }
1273
Chong Zhang0abb20f2015-11-19 14:17:31 -08001274 boolean isObscuringFullscreen(final DisplayInfo displayInfo) {
1275 Task task = getTask();
1276 if (task != null && task.mStack != null && !task.mStack.isFullscreen()) {
1277 return false;
1278 }
1279 if (!isOpaqueDrawn() || !isFrameFullscreen(displayInfo)) {
1280 return false;
1281 }
1282 return true;
1283 }
1284
1285 boolean isFrameFullscreen(final DisplayInfo displayInfo) {
1286 return mFrame.left <= 0 && mFrame.top <= 0
1287 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001288 }
1289
Craig Mautner812d2ca2012-09-27 15:35:34 -07001290 boolean isConfigChanged() {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001291 final Task task = getTask();
Wale Ogunwale60454db2015-01-23 16:05:07 -08001292 final Configuration overrideConfig =
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001293 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001294 final Configuration serviceConfig = mService.mCurConfiguration;
1295 boolean configChanged =
1296 (mConfiguration != serviceConfig && mConfiguration.diff(serviceConfig) != 0)
1297 || (mOverrideConfig != overrideConfig && !mOverrideConfig.equals(overrideConfig));
Craig Mautnere8552142012-11-07 13:55:47 -08001298
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001299 if ((mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Craig Mautnere8552142012-11-07 13:55:47 -08001300 // Retain configuration changed status until resetConfiguration called.
1301 mConfigHasChanged |= configChanged;
1302 configChanged = mConfigHasChanged;
1303 }
1304
1305 return configChanged;
Craig Mautner812d2ca2012-09-27 15:35:34 -07001306 }
1307
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001308 void removeLocked() {
1309 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001310
Robert Carr51a1b872015-12-08 14:03:13 -08001311 if (isChildWindow()) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001312 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001313 mAttachedWindow.mChildWindows.remove(this);
1314 }
Craig Mautner96868332012-12-04 14:29:11 -08001315 mWinAnimator.destroyDeferredSurfaceLocked();
1316 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001317 mSession.windowRemovedLocked();
1318 try {
1319 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1320 } catch (RuntimeException e) {
1321 // Ignore if it has already been removed (usually because
1322 // we are doing this as part of processing a death note.)
1323 }
1324 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001325
Wale Ogunwale60454db2015-01-23 16:05:07 -08001326 private void setConfiguration(
1327 final Configuration newConfig, final Configuration newOverrideConfig) {
Craig Mautnere8552142012-11-07 13:55:47 -08001328 mConfiguration = newConfig;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001329 mOverrideConfig = newOverrideConfig;
Craig Mautnere8552142012-11-07 13:55:47 -08001330 mConfigHasChanged = false;
1331 }
1332
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001333 void setHasSurface(boolean hasSurface) {
1334 mHasSurface = hasSurface;
1335 }
1336
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001337 int getAnimLayerAdjustment() {
1338 if (mTargetAppToken != null) {
1339 return mTargetAppToken.mAppAnimator.animLayerAdjustment;
1340 } else if (mAppToken != null) {
1341 return mAppToken.mAppAnimator.animLayerAdjustment;
1342 } else {
1343 // Nothing is animating, so there is no animation adjustment.
1344 return 0;
1345 }
1346 }
1347
1348 void scheduleAnimationIfDimming() {
1349 if (mDisplayContent == null) {
1350 return;
1351 }
1352 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1353 if (dimLayerUser != null && mDisplayContent.mDimLayerController.isDimming(
1354 dimLayerUser, mWinAnimator)) {
1355 // Force an animation pass just to update the mDimLayer layer.
1356 mService.scheduleAnimationLocked();
1357 }
1358 }
1359
Chong Zhangacf11402015-11-04 16:23:10 -08001360 private final class DeadWindowEventReceiver extends InputEventReceiver {
1361 DeadWindowEventReceiver(InputChannel inputChannel) {
1362 super(inputChannel, mService.mH.getLooper());
1363 }
1364 @Override
1365 public void onInputEvent(InputEvent event) {
1366 finishInputEvent(event, true);
1367 }
1368 }
1369 /**
1370 * Dummy event receiver for windows that died visible.
1371 */
1372 private DeadWindowEventReceiver mDeadWindowEventReceiver;
1373
Chong Zhang112eb8c2015-11-02 11:17:00 -08001374 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001375 if (mInputChannel != null) {
1376 throw new IllegalStateException("Window already has an input channel.");
1377 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001378 String name = makeInputChannelName();
1379 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1380 mInputChannel = inputChannels[0];
1381 mClientChannel = inputChannels[1];
1382 mInputWindowHandle.inputChannel = inputChannels[0];
1383 if (outInputChannel != null) {
1384 mClientChannel.transferTo(outInputChannel);
1385 mClientChannel.dispose();
1386 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08001387 } else {
1388 // If the window died visible, we setup a dummy input channel, so that taps
1389 // can still detected by input monitor channel, and we can relaunch the app.
1390 // Create dummy event receiver that simply reports all events as handled.
1391 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08001392 }
1393 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001394 }
1395
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001396 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08001397 if (mDeadWindowEventReceiver != null) {
1398 mDeadWindowEventReceiver.dispose();
1399 mDeadWindowEventReceiver = null;
1400 }
1401
1402 // unregister server channel first otherwise it complains about broken channel
1403 if (mInputChannel != null) {
1404 mService.mInputManager.unregisterInputChannel(mInputChannel);
1405 mInputChannel.dispose();
1406 mInputChannel = null;
1407 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001408 if (mClientChannel != null) {
1409 mClientChannel.dispose();
1410 mClientChannel = null;
1411 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001412 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001413 }
1414
Chong Zhang112eb8c2015-11-02 11:17:00 -08001415 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08001416 // When the app is terminated (eg. from Recents), the task might have already been
1417 // removed with the window pending removal. Don't apply dim in such cases, as there
1418 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
1419 final AppWindowToken token = mAppToken;
1420 if (token != null && token.removed) {
1421 return;
1422 }
1423
Chong Zhang112eb8c2015-11-02 11:17:00 -08001424 if (!mExiting && mAppDied) {
1425 // If app died visible, apply a dim over the window to indicate that it's inactive
1426 mDisplayContent.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
1427 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
1428 && mDisplayContent != null && !mExiting && isDisplayedLw()) {
1429 mDisplayContent.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001430 }
1431 }
1432
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001433 DimLayer.DimLayerUser getDimLayerUser() {
1434 Task task = getTask();
1435 if (task != null) {
1436 return task;
1437 }
1438 return getStack();
1439 }
1440
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001441 void maybeRemoveReplacedWindow() {
Robert Carra1eb4392015-12-10 12:43:51 -08001442 if (mAppToken == null) {
1443 return;
1444 }
1445 for (int i = mAppToken.allAppWindows.size() - 1; i >= 0; i--) {
1446 final WindowState win = mAppToken.allAppWindows.get(i);
1447 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + win);
1448 if (win.mWillReplaceWindow && win.mReplacingWindow == this) {
1449 win.mWillReplaceWindow = false;
1450 win.mAnimateReplacingWindow = false;
1451 win.mReplacingRemoveRequested = false;
1452 win.mReplacingWindow = null;
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001453 if (win.mExiting) {
1454 mService.removeWindowInnerLocked(win);
1455 }
1456 }
1457 }
1458 }
1459
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07001460 void setDisplayLayoutNeeded() {
1461 if (mDisplayContent != null) {
1462 mDisplayContent.layoutNeeded = true;
1463 }
1464 }
1465
Filip Gruszczynski955b2fc2015-10-15 14:46:07 -07001466 boolean inDockedWorkspace() {
Chong Zhang2a88fc32016-01-11 17:14:24 -08001467 final Task task = getTask();
Chong Zhangb15758a2015-11-17 12:12:03 -08001468 return task != null && task.inDockedWorkspace();
1469 }
1470
1471 boolean isDockedInEffect() {
Chong Zhang2a88fc32016-01-11 17:14:24 -08001472 final Task task = getTask();
Chong Zhangb15758a2015-11-17 12:12:03 -08001473 return task != null && task.isDockedInEffect();
Filip Gruszczynski955b2fc2015-10-15 14:46:07 -07001474 }
1475
Chong Zhang2a88fc32016-01-11 17:14:24 -08001476 void applyScrollIfNeeded() {
1477 final Task task = getTask();
Chong Zhangf66db432016-01-13 10:39:51 -08001478 if (task != null) {
1479 task.applyScrollToWindowIfNeeded(this);
Chong Zhang2a88fc32016-01-11 17:14:24 -08001480 }
1481 }
1482
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001483 int getTouchableRegion(Region region, int flags) {
1484 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001485 if (modal && mAppToken != null) {
1486 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001487 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001488 // If this is a modal window we need to dismiss it if it's not full screen and the
1489 // touch happens outside of the frame that displays the content. This means we
1490 // need to intercept touches outside of that window. The dim layer user
1491 // associated with the window (task or stack) will give us the good bounds, as
1492 // they would be used to display the dim layer.
1493 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1494 if (dimLayerUser != null) {
1495 dimLayerUser.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001496 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001497 getVisibleBounds(mTmpRect);
1498 }
1499 if (inFreeformWorkspace()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001500 // For freeform windows we the touch region to include the whole surface for the
1501 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001502 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
1503 final int delta = WindowManagerService.dipToPixel(
1504 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
1505 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001506 }
1507 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001508 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001509 } else {
1510 // Not modal or full screen modal
1511 getTouchableRegion(region);
1512 }
1513 return flags;
1514 }
1515
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001516 void checkPolicyVisibilityChange() {
1517 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
1518 if (DEBUG_VISIBILITY) {
1519 Slog.v(TAG, "Policy visibility changing after anim in " +
1520 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
1521 }
1522 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001523 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001524 if (!mPolicyVisibility) {
1525 if (mService.mCurrentFocus == this) {
1526 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
1527 "setAnimationLocked: setting mFocusMayChange true");
1528 mService.mFocusMayChange = true;
1529 }
1530 // Window is no longer visible -- make sure if we were waiting
1531 // for it to be displayed before enabling the display, that
1532 // we allow the display to be enabled now.
1533 mService.enableScreenIfNeededLocked();
1534 }
1535 }
1536 }
1537
1538 void setRequestedSize(int requestedWidth, int requestedHeight) {
1539 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
1540 mLayoutNeeded = true;
1541 mRequestedWidth = requestedWidth;
1542 mRequestedHeight = requestedHeight;
1543 }
1544 }
1545
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001546 void prepareWindowToDisplayDuringRelayout(Configuration outConfig) {
1547 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
1548 == SOFT_INPUT_ADJUST_RESIZE) {
1549 mLayoutNeeded = true;
1550 }
1551 if (isDrawnLw() && mService.okToDisplay()) {
1552 mWinAnimator.applyEnterAnimationLocked();
1553 }
1554 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
1555 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
1556 mTurnOnScreen = true;
1557 }
1558 if (isConfigChanged()) {
1559 if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + this + " visible with new config: "
1560 + mService.mCurConfiguration);
1561 outConfig.setTo(mService.mCurConfiguration);
1562 }
1563 }
1564
1565 void adjustStartingWindowFlags() {
1566 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
1567 && mAppToken.startingWindow != null) {
1568 // Special handling of starting window over the base
1569 // window of the app: propagate lock screen flags to it,
1570 // to provide the correct semantics while starting.
1571 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
1572 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
1573 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
1574 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
1575 }
1576 }
1577
1578 void setWindowScale(int requestedWidth, int requestedHeight) {
1579 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
1580
1581 if (scaledWindow) {
1582 // requested{Width|Height} Surface's physical size
1583 // attrs.{width|height} Size on screen
1584 // TODO: We don't check if attrs != null here. Is it implicitly checked?
1585 mHScale = (mAttrs.width != requestedWidth) ?
1586 (mAttrs.width / (float)requestedWidth) : 1.0f;
1587 mVScale = (mAttrs.height != requestedHeight) ?
1588 (mAttrs.height / (float)requestedHeight) : 1.0f;
1589 } else {
1590 mHScale = mVScale = 1;
1591 }
1592 }
1593
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001594 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08001595 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001596 public void binderDied() {
1597 try {
1598 synchronized(mService.mWindowMap) {
1599 WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07001600 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001601 if (win != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001602 if (win.mAppToken != null && !win.mAppToken.clientHidden) {
1603 win.mAppToken.appDied = true;
1604 }
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001605 mService.removeWindowLocked(win);
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001606 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08001607 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001608 mService.removeWindowLocked(WindowState.this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001609 }
1610 }
1611 } catch (IllegalArgumentException ex) {
1612 // This will happen if the window has already been
1613 // removed.
1614 }
1615 }
1616 }
1617
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08001618 /**
1619 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
1620 * because we want to preserve its location on screen to be re-activated later when the user
1621 * interacts with it.
1622 */
1623 boolean shouldKeepVisibleDeadAppWindow() {
1624 if (!isWinVisibleLw() || mAppToken == null || !mAppToken.appDied) {
1625 // Not a visible app window or the app isn't dead.
1626 return false;
1627 }
1628
1629 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1630 // We don't keep starting windows since they were added by the window manager before
1631 // the app even launched.
1632 return false;
1633 }
1634
1635 final TaskStack stack = getStack();
1636 return stack != null && StackId.keepVisibleDeadAppWindowOnScreen(stack.mStackId);
1637 }
1638
Wale Ogunwaled045c822015-12-02 09:14:28 -08001639 /** @return true if this window desires key events. */
1640 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08001641 return isVisibleOrAdding()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001642 && (mViewVisibility == View.VISIBLE)
Wale Ogunwaled045c822015-12-02 09:14:28 -08001643 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Wale Ogunwale6cae7652015-12-26 07:36:26 -08001644 && (mAppToken == null || mAppToken.windowsAreFocusable());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001645 }
1646
Craig Mautner749a7bb2012-04-02 13:49:53 -07001647 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001648 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001649 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001650 }
1651
Craig Mautner749a7bb2012-04-02 13:49:53 -07001652 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001653 public boolean showLw(boolean doAnimation) {
1654 return showLw(doAnimation, true);
1655 }
1656
1657 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07001658 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001659 return false;
1660 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001661 if (!mAppOpVisibility) {
1662 // Being hidden due to app op request.
1663 return false;
1664 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001665 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001666 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001667 return false;
1668 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001669 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001670 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001671 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07001672 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07001673 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001674 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07001675 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001676 // Check for the case where we are currently visible and
1677 // not animating; we do not want to do animation at such a
1678 // point to become visible when we already are.
1679 doAnimation = false;
1680 }
1681 }
1682 mPolicyVisibility = true;
1683 mPolicyVisibilityAfterAnim = true;
1684 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001685 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001686 }
1687 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001688 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001689 }
1690 return true;
1691 }
1692
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001693 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001694 public boolean hideLw(boolean doAnimation) {
1695 return hideLw(doAnimation, true);
1696 }
1697
1698 boolean hideLw(boolean doAnimation, boolean requestAnim) {
1699 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07001700 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001701 doAnimation = false;
1702 }
1703 }
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001704 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
1705 : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001706 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001707 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001708 return false;
1709 }
1710 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001711 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07001712 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001713 doAnimation = false;
1714 }
1715 }
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001716 if (doAnimation) {
1717 mPolicyVisibilityAfterAnim = false;
1718 } else {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001719 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001720 mPolicyVisibilityAfterAnim = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001721 mPolicyVisibility = false;
1722 // Window is no longer visible -- make sure if we were waiting
1723 // for it to be displayed before enabling the display, that
1724 // we allow the display to be enabled now.
1725 mService.enableScreenIfNeededLocked();
1726 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001727 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07001728 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001729 mService.mFocusMayChange = true;
1730 }
1731 }
1732 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001733 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001734 }
1735 return true;
1736 }
1737
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001738 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001739 if (mAppOpVisibility != state) {
1740 mAppOpVisibility = state;
1741 if (state) {
1742 // If the policy visibility had last been to hide, then this
1743 // will incorrectly show at this point since we lost that
1744 // information. Not a big deal -- for the windows that have app
1745 // ops modifies they should only be hidden by policy due to the
1746 // lock screen, and the user won't be changing this if locked.
1747 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001748 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001749 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001750 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001751 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001752 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001753 }
1754
Jeff Brownc2932a12014-11-20 18:04:05 -08001755 public void pokeDrawLockLw(long timeout) {
1756 if (isVisibleOrAdding()) {
1757 if (mDrawLock == null) {
1758 // We want the tag name to be somewhat stable so that it is easier to correlate
1759 // in wake lock statistics. So in particular, we don't want to include the
1760 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001761 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08001762 mDrawLock = mService.mPowerManager.newWakeLock(
1763 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
1764 mDrawLock.setReferenceCounted(false);
1765 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
1766 }
1767 // Each call to acquire resets the timeout.
1768 if (DEBUG_POWER) {
1769 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
1770 + mAttrs.packageName);
1771 }
1772 mDrawLock.acquire(timeout);
1773 } else if (DEBUG_POWER) {
1774 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
1775 + "owned by " + mAttrs.packageName);
1776 }
1777 }
1778
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001779 @Override
1780 public boolean isAlive() {
1781 return mClient.asBinder().isBinderAlive();
1782 }
1783
Craig Mautnera987d432012-10-11 14:07:58 -07001784 boolean isClosing() {
1785 return mExiting || (mService.mClosingApps.contains(mAppToken));
1786 }
1787
Chong Zhangbef461f2015-10-27 11:38:24 -07001788 boolean isAnimatingWithSavedSurface() {
1789 return mAppToken != null && mAppToken.mAnimatingWithSavedSurface;
1790 }
1791
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001792 private boolean shouldSaveSurface() {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001793 if (ActivityManager.isLowRamDeviceStatic()) {
1794 // Don't save surfaces on Svelte devices.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001795 return false;
1796 }
1797
1798 if (isChildWindow()) {
1799 return false;
1800 }
1801
1802 Task task = getTask();
1803 if (task == null || task.inHomeStack()) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001804 // Don't save surfaces for home stack apps. These usually resume and draw
1805 // first frame very fast. Saving surfaces are mostly a waste of memory.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001806 return false;
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001807 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001808
1809 final AppWindowToken taskTop = task.getTopVisibleAppToken();
1810 if (taskTop != null && taskTop != mAppToken) {
1811 // Don't save if the window is not the topmost window.
1812 return false;
1813 }
1814
1815 return mAppToken.shouldSaveSurface();
1816 }
1817
1818 void destroyOrSaveSurface() {
1819 mSurfaceSaved = shouldSaveSurface();
1820 if (mSurfaceSaved) {
1821 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1822 Slog.v(TAG, "Saving surface: " + this);
1823 }
1824
1825 mWinAnimator.hide("saved surface");
1826 mWinAnimator.mDrawState = WindowStateAnimator.NO_SURFACE;
1827 setHasSurface(false);
1828 } else {
Robert Carr13f7be9e2015-12-02 18:39:45 -08001829 mWinAnimator.destroySurfaceLocked();
1830 }
Robert Carr13f7be9e2015-12-02 18:39:45 -08001831 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001832
Robert Carr13f7be9e2015-12-02 18:39:45 -08001833 public void destroySavedSurface() {
Robert Carr13f7be9e2015-12-02 18:39:45 -08001834 if (mSurfaceSaved) {
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001835 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1836 Slog.v(TAG, "Destroying saved surface: " + this);
1837 }
Robert Carr13f7be9e2015-12-02 18:39:45 -08001838 mWinAnimator.destroySurfaceLocked();
1839 }
1840 }
1841
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001842 public void restoreSavedSurface() {
1843 mSurfaceSaved = false;
1844 setHasSurface(true);
1845 mWinAnimator.mDrawState = WindowStateAnimator.READY_TO_SHOW;
1846 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1847 Slog.v(TAG, "Restoring saved surface: " + this);
1848 }
1849 }
1850
Robert Carr13f7be9e2015-12-02 18:39:45 -08001851 public boolean hasSavedSurface() {
1852 return mSurfaceSaved;
1853 }
1854
Craig Mautner69b08182012-09-05 13:07:13 -07001855 @Override
1856 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001857 final DisplayContent displayContent = getDisplayContent();
1858 if (displayContent == null) {
1859 // Only a window that was on a non-default display can be detached from it.
1860 return false;
1861 }
Winson Chung47a3e652014-05-21 16:03:42 -07001862 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07001863 }
1864
Adrian Rooscd3884d2015-02-18 17:25:23 +01001865 @Override
1866 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001867 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1868 return dimLayerUser != null && mDisplayContent != null &&
Chong Zhang112eb8c2015-11-02 11:17:00 -08001869 mDisplayContent.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01001870 }
1871
Craig Mautner88400d32012-09-30 12:35:45 -07001872 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
1873 mShowToOwnerOnly = showToOwnerOnly;
1874 }
1875
Craig Mautner5962b122012-10-05 14:45:52 -07001876 boolean isHiddenFromUserLocked() {
Craig Mautner341220f2012-10-16 15:20:09 -07001877 // Attached windows are evaluated based on the window that they are attached to.
1878 WindowState win = this;
Robert Carr51a1b872015-12-08 14:03:13 -08001879 while (win.isChildWindow()) {
Craig Mautner341220f2012-10-16 15:20:09 -07001880 win = win.mAttachedWindow;
1881 }
1882 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -07001883 && win.mAppToken != null && win.mAppToken.showForAllUsers) {
Craig Mautner341220f2012-10-16 15:20:09 -07001884 // Save some cycles by not calling getDisplayInfo unless it is an application
1885 // window intended for all users.
Craig Mautnerdf88d732014-01-27 09:21:32 -08001886 final DisplayContent displayContent = win.getDisplayContent();
1887 if (displayContent == null) {
1888 return true;
1889 }
1890 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Craig Mautner341220f2012-10-16 15:20:09 -07001891 if (win.mFrame.left <= 0 && win.mFrame.top <= 0
1892 && win.mFrame.right >= displayInfo.appWidth
1893 && win.mFrame.bottom >= displayInfo.appHeight) {
Craig Mautner5962b122012-10-05 14:45:52 -07001894 // Is a fullscreen window, like the clock alarm. Show to everyone.
1895 return false;
1896 }
1897 }
1898
Craig Mautner341220f2012-10-16 15:20:09 -07001899 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01001900 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001901 }
1902
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001903 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
1904 outRegion.set(
1905 frame.left + inset.left, frame.top + inset.top,
1906 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001907 }
1908
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001909 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001910 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001911 switch (mTouchableInsets) {
1912 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001913 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001914 outRegion.set(frame);
1915 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001916 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001917 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001918 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001919 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001920 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001921 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001922 case TOUCHABLE_INSETS_REGION: {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001923 final Region givenTouchableRegion = mGivenTouchableRegion;
1924 outRegion.set(givenTouchableRegion);
1925 outRegion.translate(frame.left, frame.top);
1926 break;
1927 }
1928 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001929 cropRegionToStackBoundsIfNeeded(outRegion);
1930 }
1931
1932 void cropRegionToStackBoundsIfNeeded(Region region) {
1933 if (mAppToken == null || !mAppToken.mCropWindowsToStack) {
1934 return;
1935 }
1936
1937 final TaskStack stack = getStack();
1938 if (stack == null) {
1939 return;
1940 }
1941
1942 stack.getDimBounds(mTmpRect);
1943 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001944 }
1945
Craig Mautner59c00972012-07-30 12:10:24 -07001946 WindowList getWindowList() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001947 final DisplayContent displayContent = getDisplayContent();
1948 return displayContent == null ? null : displayContent.getWindowList();
Craig Mautner59c00972012-07-30 12:10:24 -07001949 }
1950
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001951 /**
1952 * Report a focus change. Must be called with no locks held, and consistently
1953 * from the same serialized thread (such as dispatched from a handler).
1954 */
1955 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
1956 try {
1957 mClient.windowFocusChanged(focused, inTouchMode);
1958 } catch (RemoteException e) {
1959 }
1960 if (mFocusCallbacks != null) {
1961 final int N = mFocusCallbacks.beginBroadcast();
1962 for (int i=0; i<N; i++) {
1963 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
1964 try {
1965 if (focused) {
1966 obs.focusGained(mWindowId.asBinder());
1967 } else {
1968 obs.focusLost(mWindowId.asBinder());
1969 }
1970 } catch (RemoteException e) {
1971 }
1972 }
1973 mFocusCallbacks.finishBroadcast();
1974 }
1975 }
1976
Craig Mautnerdf88d732014-01-27 09:21:32 -08001977 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001978 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08001979 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001980 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
1981 + ": " + mCompatFrame);
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001982 final boolean configChanged = isConfigChanged();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001983 final Task task = getTask();
Wale Ogunwale60454db2015-01-23 16:05:07 -08001984 final Configuration overrideConfig =
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001985 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001986 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) && configChanged) {
1987 Slog.i(TAG, "Sending new config to window " + this + ": "
Robert Carre6a83512015-11-03 16:09:21 -08001988 + " / config="
Wale Ogunwale60454db2015-01-23 16:05:07 -08001989 + mService.mCurConfiguration + " overrideConfig=" + overrideConfig);
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001990 }
Wale Ogunwale60454db2015-01-23 16:05:07 -08001991 setConfiguration(mService.mCurConfiguration, overrideConfig);
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001992 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING)
1993 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
1994
Craig Mautnerdf88d732014-01-27 09:21:32 -08001995 final Rect frame = mFrame;
1996 final Rect overscanInsets = mLastOverscanInsets;
1997 final Rect contentInsets = mLastContentInsets;
1998 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07001999 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002000 final Rect outsets = mLastOutsets;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002001 final boolean reportDraw = mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING;
2002 final Configuration newConfig = configChanged ? mConfiguration : null;
Chet Haase8eb48d22014-09-24 07:31:29 -07002003 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
2004 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002005 // To prevent deadlock simulate one-way call if win.mClient is a local object.
2006 mService.mH.post(new Runnable() {
2007 @Override
2008 public void run() {
2009 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002010 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
2011 stableInsets, outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002012 } catch (RemoteException e) {
2013 // Not a remote call, RemoteException won't be raised.
2014 }
2015 }
2016 });
2017 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002018 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002019 outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002020 }
Svetoslav4604abc2014-06-10 18:59:30 -07002021
2022 //TODO (multidisplay): Accessibility supported only for the default display.
2023 if (mService.mAccessibilityController != null
2024 && getDisplayId() == Display.DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07002025 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07002026 }
2027
Craig Mautnerdf88d732014-01-27 09:21:32 -08002028 mOverscanInsetsChanged = false;
2029 mContentInsetsChanged = false;
2030 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07002031 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002032 mOutsetsChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08002033 mWinAnimator.mSurfaceResized = false;
2034 } catch (RemoteException e) {
2035 mOrientationChanging = false;
2036 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2037 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08002038 // We are assuming the hosting process is dead or in a zombie state.
2039 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
2040 + ", removing this window.");
2041 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002042 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002043 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002044 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002045 }
2046
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002047 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08002048 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
2049 // start even if we haven't received the relayout window, so that the client requests
2050 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
2051 // until the window to small size, otherwise the multithread renderer will shift last
2052 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
2053 // isDragResizing() or isDragResizeChanged() is true.
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002054 DisplayInfo displayInfo = getDisplayInfo();
2055 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Chong Zhangd153c4f2015-11-06 20:26:40 -08002056 boolean resizing = isDragResizing() || isDragResizeChanged();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002057 return (inFreeformWorkspace() || !resizing) ? frame : mTmpRect;
2058 }
2059
2060 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
2061 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
2062 Configuration newConfig) throws RemoteException {
Jorim Jaggidc249c42015-12-15 14:57:31 -08002063 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002064 reportDraw, newConfig, getBackdropFrame(frame));
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002065 }
2066
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002067 public void registerFocusObserver(IWindowFocusObserver observer) {
2068 synchronized(mService.mWindowMap) {
2069 if (mFocusCallbacks == null) {
2070 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
2071 }
2072 mFocusCallbacks.register(observer);
2073 }
2074 }
2075
2076 public void unregisterFocusObserver(IWindowFocusObserver observer) {
2077 synchronized(mService.mWindowMap) {
2078 if (mFocusCallbacks != null) {
2079 mFocusCallbacks.unregister(observer);
2080 }
2081 }
2082 }
2083
2084 public boolean isFocused() {
2085 synchronized(mService.mWindowMap) {
2086 return mService.mCurrentFocus == this;
2087 }
2088 }
2089
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07002090 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07002091 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07002092 return task != null && task.inFreeformWorkspace();
2093 }
2094
Chong Zhang3005e752015-09-18 18:46:28 -07002095 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002096 return mDragResizing != computeDragResizing();
2097 }
2098
Jorim Jaggidcf467c2015-11-05 13:59:32 +01002099 int getResizeMode() {
2100 return mResizeMode;
2101 }
2102
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002103 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07002104 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002105 if (task == null) {
2106 return false;
2107 }
2108 if (task.isDragResizing()) {
2109 return true;
2110 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01002111
2112 // If the bounds are currently frozen, it means that the layout size that the app sees
2113 // and the bounds we clip this window to might be different. In order to avoid holes, we
2114 // simulate that we are still resizing so the app fills the hole with the resizing
2115 // background.
2116 return (mDisplayContent.mDividerControllerLocked.isResizing()
2117 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002118 !task.inFreeformWorkspace() && !task.isFullscreen();
Chong Zhang3005e752015-09-18 18:46:28 -07002119 }
2120
2121 void setDragResizing() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002122 mDragResizing = computeDragResizing();
Jorim Jaggidcf467c2015-11-05 13:59:32 +01002123 mResizeMode = mDragResizing && mDisplayContent.mDividerControllerLocked.isResizing()
2124 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
2125 : DRAG_RESIZE_MODE_FREEFORM;
Chong Zhang3005e752015-09-18 18:46:28 -07002126 }
2127
2128 boolean isDragResizing() {
2129 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07002130 }
2131
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002132 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08002133 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002134 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08002135 if (stack != null) {
2136 pw.print(" stackId="); pw.print(stack.mStackId);
2137 }
Craig Mautner59c00972012-07-30 12:10:24 -07002138 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002139 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07002140 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08002141 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
2142 pw.print(" package="); pw.print(mAttrs.packageName);
2143 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002144 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002145 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
2146 pw.print(" h="); pw.print(mRequestedHeight);
2147 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07002148 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
2149 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
2150 pw.print(" h="); pw.println(mLastRequestedHeight);
2151 }
Robert Carr51a1b872015-12-08 14:03:13 -08002152 if (isChildWindow() || mLayoutAttached) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002153 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
2154 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
2155 }
2156 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
2157 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
2158 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
2159 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
2160 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
2161 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002162 if (dumpAll) {
2163 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
2164 pw.print(" mSubLayer="); pw.print(mSubLayer);
2165 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautner59431632012-04-04 11:56:44 -07002166 pw.print((mTargetAppToken != null ?
2167 mTargetAppToken.mAppAnimator.animLayerAdjustment
2168 : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002169 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
2170 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08002171 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002172 if (dumpAll) {
2173 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
2174 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
2175 if (mAppToken != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08002176 pw.print(prefix); pw.print("mAppToken="); pw.print(mAppToken);
2177 pw.print(" mAppDied=");pw.println(mAppDied);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002178 }
2179 if (mTargetAppToken != null) {
2180 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
2181 }
2182 pw.print(prefix); pw.print("mViewVisibility=0x");
2183 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002184 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
2185 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07002186 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
2187 pw.print(" mSystemUiVisibility=0x");
2188 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002189 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002190 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
2191 || mAttachedHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002192 pw.print(prefix); pw.print("mPolicyVisibility=");
2193 pw.print(mPolicyVisibility);
2194 pw.print(" mPolicyVisibilityAfterAnim=");
2195 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002196 pw.print(" mAppOpVisibility=");
2197 pw.print(mAppOpVisibility);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002198 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
2199 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08002200 if (!mRelayoutCalled || mLayoutNeeded) {
2201 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
2202 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002203 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002204 if (mXOffset != 0 || mYOffset != 0) {
2205 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
2206 pw.print(" y="); pw.println(mYOffset);
2207 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002208 if (dumpAll) {
2209 pw.print(prefix); pw.print("mGivenContentInsets=");
2210 mGivenContentInsets.printShortString(pw);
2211 pw.print(" mGivenVisibleInsets=");
2212 mGivenVisibleInsets.printShortString(pw);
2213 pw.println();
2214 if (mTouchableInsets != 0 || mGivenInsetsPending) {
2215 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
2216 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07002217 Region region = new Region();
2218 getTouchableRegion(region);
2219 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002220 }
2221 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Wale Ogunwale7c726682015-02-06 17:34:28 -08002222 if (mOverrideConfig != Configuration.EMPTY) {
2223 pw.print(prefix); pw.print("mOverrideConfig="); pw.println(mOverrideConfig);
2224 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002225 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07002226 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07002227 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Craig Mautner178af592012-09-17 10:37:29 -07002228 pw.print(" isReadyForDisplay()="); pw.println(isReadyForDisplay());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002229 if (dumpAll) {
2230 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
2231 pw.print(" last="); mLastFrame.printShortString(pw);
2232 pw.println();
2233 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002234 if (mEnforceSizeCompat) {
2235 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002236 pw.println();
2237 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002238 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002239 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002240 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002241 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002242 pw.println();
2243 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
2244 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002245 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002246 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002247 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002248 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04002249 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
2250 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002251 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
2252 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002253 pw.print(prefix); pw.print("Cur insets: overscan=");
2254 mOverscanInsets.printShortString(pw);
2255 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002256 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002257 pw.print(" stable="); mStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002258 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002259 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002260 pw.print(prefix); pw.print("Lst insets: overscan=");
2261 mLastOverscanInsets.printShortString(pw);
2262 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002263 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002264 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002265 pw.print(" physical="); mLastOutsets.printShortString(pw);
2266 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002267 pw.println();
2268 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07002269 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
2270 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002271 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
2272 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
2273 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
2274 pw.print(" mDestroying="); pw.print(mDestroying);
2275 pw.print(" mRemoved="); pw.println(mRemoved);
2276 }
2277 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
2278 pw.print(prefix); pw.print("mOrientationChanging=");
2279 pw.print(mOrientationChanging);
2280 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
2281 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
2282 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07002283 if (mLastFreezeDuration != 0) {
2284 pw.print(prefix); pw.print("mLastFreezeDuration=");
2285 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
2286 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002287 if (mHScale != 1 || mVScale != 1) {
2288 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
2289 pw.print(" mVScale="); pw.println(mVScale);
2290 }
2291 if (mWallpaperX != -1 || mWallpaperY != -1) {
2292 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
2293 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
2294 }
2295 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
2296 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
2297 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
2298 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07002299 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
2300 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
2301 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
2302 pw.print(mWallpaperDisplayOffsetX);
2303 pw.print(" mWallpaperDisplayOffsetY=");
2304 pw.println(mWallpaperDisplayOffsetY);
2305 }
Jeff Brownc2932a12014-11-20 18:04:05 -08002306 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07002307 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08002308 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002309 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002310
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002311 String makeInputChannelName() {
2312 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002313 + " " + getWindowTag();
2314 }
2315
Robert Carra1eb4392015-12-10 12:43:51 -08002316 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002317 CharSequence tag = mAttrs.getTitle();
2318 if (tag == null || tag.length() <= 0) {
2319 tag = mAttrs.packageName;
2320 }
2321 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002322 }
2323
2324 @Override
2325 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002326 final CharSequence title = getWindowTag();
Dianne Hackbornc2293022013-02-06 23:14:49 -08002327 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mExiting) {
2328 mLastTitle = title;
Dianne Hackborn529e7442012-11-01 14:22:28 -07002329 mWasExiting = mExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002330 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -07002331 + " u" + UserHandle.getUserId(mSession.mUid)
Craig Mautnera987d432012-10-11 14:07:58 -07002332 + " " + mLastTitle + (mExiting ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002333 }
2334 return mStringNameCache;
2335 }
Robert Carr58f29132015-10-29 14:19:05 -07002336
2337 void transformFromScreenToSurfaceSpace(Rect rect) {
2338 if (mHScale >= 0) {
Chong Zhang84389572016-01-13 10:33:27 -08002339 rect.left = (int) (rect.left / mHScale);
2340 rect.right = (int) (rect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07002341 }
2342 if (mVScale >= 0) {
Chong Zhang84389572016-01-13 10:33:27 -08002343 rect.top = (int) (rect.top / mVScale);
2344 rect.bottom = (int) (rect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07002345 }
2346 }
Robert Carr31e28482015-12-02 16:53:18 -08002347
2348 void applyGravityAndUpdateFrame() {
2349 final int pw = mContainingFrame.width();
2350 final int ph = mContainingFrame.height();
2351 final Task task = getTask();
2352 final boolean nonFullscreenTask = task != null && !task.isFullscreen();
2353
2354 float x, y;
2355 int w,h;
2356
2357 if ((mAttrs.flags & FLAG_SCALED) != 0) {
2358 if (mAttrs.width < 0) {
2359 w = pw;
2360 } else if (mEnforceSizeCompat) {
2361 w = (int)(mAttrs.width * mGlobalScale + .5f);
2362 } else {
2363 w = mAttrs.width;
2364 }
2365 if (mAttrs.height < 0) {
2366 h = ph;
2367 } else if (mEnforceSizeCompat) {
2368 h = (int)(mAttrs.height * mGlobalScale + .5f);
2369 } else {
2370 h = mAttrs.height;
2371 }
2372 } else {
2373 if (mAttrs.width == MATCH_PARENT) {
2374 w = pw;
2375 } else if (mEnforceSizeCompat) {
2376 w = (int)(mRequestedWidth * mGlobalScale + .5f);
2377 } else {
2378 w = mRequestedWidth;
2379 }
2380 if (mAttrs.height == MATCH_PARENT) {
2381 h = ph;
2382 } else if (mEnforceSizeCompat) {
2383 h = (int)(mRequestedHeight * mGlobalScale + .5f);
2384 } else {
2385 h = mRequestedHeight;
2386 }
2387 }
2388
2389 if (mEnforceSizeCompat) {
2390 x = mAttrs.x * mGlobalScale;
2391 y = mAttrs.y * mGlobalScale;
2392 } else {
2393 x = mAttrs.x;
2394 y = mAttrs.y;
2395 }
2396
2397 if (nonFullscreenTask) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08002398 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08002399 // required by {@link Gravity#apply} call.
2400 w = Math.min(w, pw);
2401 h = Math.min(h, ph);
2402 }
2403
2404 // Set mFrame
2405 Gravity.apply(mAttrs.gravity, w, h, mContainingFrame,
2406 (int) (x + mAttrs.horizontalMargin * pw),
2407 (int) (y + mAttrs.verticalMargin * ph), mFrame);
2408
2409 // Now make sure the window fits in the overall display frame.
2410 Gravity.applyDisplay(mAttrs.gravity, mDisplayFrame, mFrame);
2411 }
Robert Carr51a1b872015-12-08 14:03:13 -08002412
2413 boolean isChildWindow() {
2414 return mAttachedWindow != null;
2415 }
Robert Carra1eb4392015-12-10 12:43:51 -08002416
2417 void setReplacing(boolean animate) {
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08002418 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
2419 || mAttrs.type == TYPE_APPLICATION_STARTING) {
2420 // We don't set replacing on starting windows since they are added by window manager and
2421 // not the client so won't be replaced by the client.
2422 return;
Robert Carra1eb4392015-12-10 12:43:51 -08002423 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08002424
2425 mWillReplaceWindow = true;
2426 mReplacingWindow = null;
2427 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08002428 }
Chong Zhangf596cd52016-01-05 13:42:44 -08002429
2430 void resetReplacing() {
2431 mWillReplaceWindow = false;
2432 mReplacingWindow = null;
2433 mAnimateReplacingWindow = false;
2434 }
satokcef37fb2011-10-24 21:49:38 +09002435}