blob: d9ed7a49d9803291ac63bdfbfaf14c30152ec6c9 [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 android.app.ActivityManager;
20import android.app.AppOpsManager;
21import android.content.Context;
22import android.content.res.Configuration;
23import android.graphics.Matrix;
24import android.graphics.PixelFormat;
25import android.graphics.Point;
26import android.graphics.Rect;
27import android.graphics.Region;
28import android.os.IBinder;
29import android.os.PowerManager;
30import android.os.RemoteCallbackList;
31import android.os.RemoteException;
32import android.os.SystemClock;
33import android.os.Trace;
34import android.os.UserHandle;
35import android.os.WorkSource;
36import android.util.DisplayMetrics;
37import android.util.Slog;
38import android.util.TimeUtils;
39import android.view.Display;
40import android.view.DisplayInfo;
41import android.view.Gravity;
42import android.view.IApplicationToken;
43import android.view.IWindow;
44import android.view.IWindowFocusObserver;
45import android.view.IWindowId;
46import android.view.InputChannel;
47import android.view.InputEvent;
48import android.view.InputEventReceiver;
49import android.view.View;
50import android.view.ViewTreeObserver;
51import android.view.WindowManager;
52import android.view.WindowManagerPolicy;
53
Jorim Jaggi9511b0f2016-01-29 19:12:44 -080054import com.android.server.input.InputWindowHandle;
55
Wale Ogunwale053c8e42015-11-16 14:27:21 -080056import java.io.PrintWriter;
57import java.util.ArrayList;
58
Wale Ogunwaled045c822015-12-02 09:14:28 -080059import static android.app.ActivityManager.StackId;
Wale Ogunwalea9f9b372016-02-04 18:04:39 -080060import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
Filip Gruszczynski84fa3352016-01-25 16:28:49 -080061import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
Wale Ogunwalecad05a02015-09-25 10:41:44 -070062import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080063import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
64import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
65import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
66import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080067import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080068import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070069import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080070import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080071import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
72import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080073import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070074import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080075import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080076import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
Robert Carr31e28482015-12-02 16:53:18 -080077import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080078import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080079import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -080080import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
Robert Carra1eb4392015-12-10 12:43:51 -080081import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080082import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
83import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080084import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080085import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070086import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080087import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
88import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
89import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080090import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
91import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
92import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
93import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
94import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
95import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
96import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
97import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
98import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
99import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
100import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
101import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800102
Craig Mautner59c00972012-07-30 12:10:24 -0700103class WindowList extends ArrayList<WindowState> {
104}
105
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800106/**
107 * A window in the window manager.
108 */
Craig Mautnere32c3072012-03-12 15:25:35 -0700109final class WindowState implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800110 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800111
Skuhne81c524a2015-08-12 13:34:14 -0700112 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700113 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
114 // use hard-coded min sizes for now.
115 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
116 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700117
118 // The thickness of a window resize handle outside the window bounds on the free form workspace
119 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700120 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700121
Jorim Jaggidcf467c2015-11-05 13:59:32 +0100122 static final int DRAG_RESIZE_MODE_FREEFORM = 0;
123 static final int DRAG_RESIZE_MODE_DOCKED_DIVIDER = 1;
124
Robert Carr7098dbd2016-02-01 12:31:01 -0800125 static final boolean DEBUG_DISABLE_SAVING_SURFACES = false;
126
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800127 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700128 final WindowManagerPolicy mPolicy;
129 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800130 final Session mSession;
131 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800132 final int mAppOp;
133 // UserId and appId of the owner. Don't display windows of non-current user.
134 final int mOwnerUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800135 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800136 WindowToken mToken;
137 WindowToken mRootToken;
138 AppWindowToken mAppToken;
139 AppWindowToken mTargetAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700140
141 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
142 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800143 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
144 final DeathRecipient mDeathRecipient;
145 final WindowState mAttachedWindow;
Craig Mautner7b1aa772012-11-30 16:14:45 -0800146 final WindowList mChildWindows = new WindowList();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800147 final int mBaseLayer;
148 final int mSubLayer;
149 final boolean mLayoutAttached;
150 final boolean mIsImWindow;
151 final boolean mIsWallpaper;
152 final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700153 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700154 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800155 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700156 int mSystemUiVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800157 boolean mPolicyVisibility = true;
158 boolean mPolicyVisibilityAfterAnim = true;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -0800159 boolean mAppOpVisibility = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800160 boolean mAppFreezing;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800161 boolean mAttachedHidden; // is our parent window hidden?
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800162 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Chong Zhang0275e392015-09-17 10:41:44 -0700163 boolean mDragResizing;
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800164 boolean mDragResizingChangeReported;
Jorim Jaggidcf467c2015-11-05 13:59:32 +0100165 int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700166
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800167 RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
168
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700169 /**
170 * The window size that was requested by the application. These are in
171 * the application's coordinate space (without compatibility scale applied).
172 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800173 int mRequestedWidth;
174 int mRequestedHeight;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700175 int mLastRequestedWidth;
176 int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700177
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800178 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800179 boolean mHaveFrame;
180 boolean mObscured;
181 boolean mTurnOnScreen;
182
183 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700184
Wale Ogunwale60454db2015-01-23 16:05:07 -0800185 private Configuration mConfiguration = Configuration.EMPTY;
186 private Configuration mOverrideConfig = Configuration.EMPTY;
Craig Mautnere8552142012-11-07 13:55:47 -0800187 // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned.
188 // Used only on {@link #TYPE_KEYGUARD}.
189 private boolean mConfigHasChanged;
Craig Mautnera2c77052012-03-26 12:14:43 -0700190
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700191 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700192 * Actual position of the surface shown on-screen (may be modified by animation). These are
193 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700194 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700195 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800196
197 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700198 * Insets that determine the actually visible area. These are in the application's
199 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800200 */
201 final Rect mVisibleInsets = new Rect();
202 final Rect mLastVisibleInsets = new Rect();
203 boolean mVisibleInsetsChanged;
204
205 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700206 * Insets that are covered by system windows (such as the status bar) and
207 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700208 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800209 */
210 final Rect mContentInsets = new Rect();
211 final Rect mLastContentInsets = new Rect();
212 boolean mContentInsetsChanged;
213
214 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800215 * Insets that determine the area covered by the display overscan region. These are in the
216 * application's coordinate space (without compatibility scale applied).
217 */
218 final Rect mOverscanInsets = new Rect();
219 final Rect mLastOverscanInsets = new Rect();
220 boolean mOverscanInsetsChanged;
221
222 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700223 * Insets that determine the area covered by the stable system windows. These are in the
224 * application's coordinate space (without compatibility scale applied).
225 */
226 final Rect mStableInsets = new Rect();
227 final Rect mLastStableInsets = new Rect();
228 boolean mStableInsetsChanged;
229
230 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700231 * Outsets determine the area outside of the surface where we want to pretend that it's possible
232 * to draw anyway.
233 */
234 final Rect mOutsets = new Rect();
235 final Rect mLastOutsets = new Rect();
236 boolean mOutsetsChanged = false;
237
238 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800239 * Set to true if we are waiting for this window to receive its
240 * given internal insets before laying out other windows based on it.
241 */
242 boolean mGivenInsetsPending;
243
244 /**
245 * These are the content insets that were given during layout for
246 * this window, to be applied to windows behind it.
247 */
248 final Rect mGivenContentInsets = new Rect();
249
250 /**
251 * These are the visible insets that were given during layout for
252 * this window, to be applied to windows behind it.
253 */
254 final Rect mGivenVisibleInsets = new Rect();
255
256 /**
257 * This is the given touchable area relative to the window frame, or null if none.
258 */
259 final Region mGivenTouchableRegion = new Region();
260
261 /**
262 * Flag indicating whether the touchable region should be adjusted by
263 * the visible insets; if false the area outside the visible insets is
264 * NOT touchable, so we must use those to adjust the frame during hit
265 * tests.
266 */
267 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
268
269 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400270 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700271 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800272 float mHScale=1, mVScale=1;
273 float mLastHScale=1, mLastVScale=1;
274 final Matrix mTmpMatrix = new Matrix();
275
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700276 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800277 final Rect mFrame = new Rect();
278 final Rect mLastFrame = new Rect();
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700279 // Frame that is scaled to the application's coordinate space when in
280 // screen size compatibility mode.
281 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800282
283 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700284
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800285 final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700286
Wale Ogunwale94596652015-02-06 19:27:34 -0800287 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
288 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700289 final Rect mDisplayFrame = new Rect();
290
291 // The region of the display frame that the display type supports displaying content on. This
292 // is mostly a special case for TV where some displays don’t have the entire display usable.
293 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
294 // window display contents to extend into the overscan region.
295 final Rect mOverscanFrame = new Rect();
296
297 // The display frame minus the stable insets. This value is always constant regardless of if
298 // the status bar or navigation bar is visible.
Adrian Roosfa104232014-06-20 16:10:14 -0700299 final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800300
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700301 // The area not occupied by the status and navigation bars. So, if both status and navigation
302 // bars are visible, the decor frame is equal to the stable frame.
303 final Rect mDecorFrame = new Rect();
304
305 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
306 // minus the area occupied by the IME if the IME is present.
307 final Rect mContentFrame = new Rect();
308
309 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
310 // displays hint text.
311 final Rect mVisibleFrame = new Rect();
312
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700313 // Frame that includes dead area outside of the surface but where we want to pretend that it's
314 // possible to draw.
315 final Rect mOutsetFrame = new Rect();
316
Jorim Jaggidc249c42015-12-15 14:57:31 -0800317 /**
318 * Usually empty. Set to the task's tempInsetFrame. See
319 *{@link android.app.IActivityManager#resizeDockedStack}.
320 */
321 final Rect mInsetFrame = new Rect();
322
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800323 boolean mContentChanged;
324
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800325 // If a window showing a wallpaper: the requested offset for the
326 // wallpaper; if a wallpaper window: the currently applied offset.
327 float mWallpaperX = -1;
328 float mWallpaperY = -1;
329
330 // If a window showing a wallpaper: what fraction of the offset
331 // range corresponds to a full virtual screen.
332 float mWallpaperXStep = -1;
333 float mWallpaperYStep = -1;
334
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700335 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
336 // to its window; if a wallpaper window: not used.
337 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
338 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
339
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800340 // Wallpaper windows: pixels offset based on above variables.
341 int mXOffset;
342 int mYOffset;
343
Craig Mautner2268e7e2012-12-13 15:40:00 -0800344 /**
345 * This is set after IWindowSession.relayout() has been called at
346 * least once for the window. It allows us to detect the situation
347 * where we don't yet have a surface, but should have one soon, so
348 * we can give the window focus before waiting for the relayout.
349 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800350 boolean mRelayoutCalled;
351
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800352 /**
353 * If the application has called relayout() with changes that can
354 * impact its window's size, we need to perform a layout pass on it
355 * even if it is not currently visible for layout. This is set
356 * when in that case until the layout is done.
357 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800358 boolean mLayoutNeeded;
359
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800360 /** Currently running an exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800361 boolean mExiting;
362
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800363 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800364 boolean mDestroying;
365
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800366 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800367 boolean mRemoveOnExit;
368
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800369 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800370 * Whether the app died while it was visible, if true we might need
371 * to continue to show it until it's restarted.
372 */
373 boolean mAppDied;
374
375 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800376 * Set when the orientation is changing and this window has not yet
377 * been updated for the new orientation.
378 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800379 boolean mOrientationChanging;
380
Dianne Hackborna57c6952013-03-29 14:46:40 -0700381 /**
382 * How long we last kept the screen frozen.
383 */
384 int mLastFreezeDuration;
385
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800386 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800387 boolean mRemoved;
388
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800389 /**
Robert Carre12aece2016-02-02 22:43:27 -0800390 * Has the client requested we remove the window? In this case we know
391 * that we can dispose of it when we wish without further synchronization
392 * with the client
393 */
394 boolean mClientRemoveRequested;
395
396 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800397 * Temp for keeping track of windows that have been removed when
398 * rebuilding window list.
399 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800400 boolean mRebuilding;
401
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800402 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700403 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800404 InputChannel mInputChannel;
Chong Zhang112eb8c2015-11-02 11:17:00 -0800405 InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800406
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800407 // Used to improve performance of toString()
408 String mStringNameCache;
409 CharSequence mLastTitle;
Dianne Hackborn529e7442012-11-01 14:22:28 -0700410 boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800411
Craig Mautnera2c77052012-03-26 12:14:43 -0700412 final WindowStateAnimator mWinAnimator;
413
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700414 boolean mHasSurface = false;
415
Craig Mautner19ab8282014-05-07 10:35:34 -0700416 boolean mNotOnAppsDisplay = false;
Craig Mautner59c00972012-07-30 12:10:24 -0700417 DisplayContent mDisplayContent;
Craig Mautner6881a102012-07-27 13:04:51 -0700418
Craig Mautner88400d32012-09-30 12:35:45 -0700419 /** When true this window can be displayed on screens owther than mOwnerUid's */
420 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700421
Robert Carr13f7be9e2015-12-02 18:39:45 -0800422 // Whether the window has a saved surface from last pause, which can be
423 // used to start an entering animation earlier.
424 public boolean mSurfaceSaved = false;
425
Robert Carra1eb4392015-12-10 12:43:51 -0800426 // This window will be replaced due to relaunch. This allows window manager
427 // to differentiate between simple removal of a window and replacement. In the latter case it
428 // will preserve the old window until the new one is drawn.
429 boolean mWillReplaceWindow = false;
430 // If true, the replaced window was already requested to be removed.
431 boolean mReplacingRemoveRequested = false;
432 // Whether the replacement of the window should trigger app transition animation.
433 boolean mAnimateReplacingWindow = false;
434 // If not null, the window that will be used to replace the old one. This is being set when
435 // the window is added and unset when this window reports its first draw.
436 WindowState mReplacingWindow = null;
437
Chong Zhangbd0d9372015-12-28 15:18:29 -0800438 // Whether this window is being moved via the resize API
439 boolean mMovedByResize;
Jeff Brownc2932a12014-11-20 18:04:05 -0800440 /**
441 * Wake lock for drawing.
442 * Even though it's slightly more expensive to do so, we will use a separate wake lock
443 * for each app that is requesting to draw while dozing so that we can accurately track
444 * who is preventing the system from suspending.
445 * This lock is only acquired on first use.
446 */
447 PowerManager.WakeLock mDrawLock;
448
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700449 final private Rect mTmpRect = new Rect();
450
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800451 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800452 WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a,
Craig Mautner59c00972012-07-30 12:10:24 -0700453 int viewVisibility, final DisplayContent displayContent) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800454 mService = service;
455 mSession = s;
456 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800457 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800458 mToken = token;
Craig Mautnera2d7b112012-08-21 15:12:20 -0700459 mOwnerUid = s.mUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800460 mWindowId = new IWindowId.Stub() {
461 @Override
462 public void registerFocusObserver(IWindowFocusObserver observer) {
463 WindowState.this.registerFocusObserver(observer);
464 }
465 @Override
466 public void unregisterFocusObserver(IWindowFocusObserver observer) {
467 WindowState.this.unregisterFocusObserver(observer);
468 }
469 @Override
470 public boolean isFocused() {
471 return WindowState.this.isFocused();
472 }
473 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800474 mAttrs.copyFrom(a);
475 mViewVisibility = viewVisibility;
Craig Mautner59c00972012-07-30 12:10:24 -0700476 mDisplayContent = displayContent;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700477 mPolicy = mService.mPolicy;
478 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800479 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700480 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700481 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800482 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700483 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700484 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800485 try {
486 c.asBinder().linkToDeath(deathRecipient, 0);
487 } catch (RemoteException e) {
488 mDeathRecipient = null;
489 mAttachedWindow = null;
490 mLayoutAttached = false;
491 mIsImWindow = false;
492 mIsWallpaper = false;
493 mIsFloatingLayer = false;
494 mBaseLayer = 0;
495 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700496 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700497 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800498 return;
499 }
500 mDeathRecipient = deathRecipient;
501
502 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
503 mAttrs.type <= LAST_SUB_WINDOW)) {
504 // The multiplier here is to reserve space for multiple
505 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700506 mBaseLayer = mPolicy.windowTypeToLayerLw(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800507 attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
508 + WindowManagerService.TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700509 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800510 mAttachedWindow = attachedWindow;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800511 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
takeda.masayuki18735092012-12-12 11:06:24 +0900512
tiger_huange2a98a72014-11-13 19:46:28 +0800513 final WindowList childWindows = mAttachedWindow.mChildWindows;
514 final int numChildWindows = childWindows.size();
515 if (numChildWindows == 0) {
516 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900517 } else {
tiger_huange2a98a72014-11-13 19:46:28 +0800518 boolean added = false;
519 for (int i = 0; i < numChildWindows; i++) {
520 final int childSubLayer = childWindows.get(i).mSubLayer;
521 if (mSubLayer < childSubLayer
522 || (mSubLayer == childSubLayer && childSubLayer < 0)) {
523 // We insert the child window into the list ordered by the sub-layer. For
524 // same sub-layers, the negative one should go below others; the positive
525 // one should go above others.
526 childWindows.add(i, this);
527 added = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900528 break;
takeda.masayuki18735092012-12-12 11:06:24 +0900529 }
530 }
tiger_huange2a98a72014-11-13 19:46:28 +0800531 if (!added) {
532 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900533 }
534 }
535
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800536 mLayoutAttached = mAttrs.type !=
537 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
538 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
539 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
540 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
541 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
542 } else {
543 // The multiplier here is to reserve space for multiple
544 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700545 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800546 * WindowManagerService.TYPE_LAYER_MULTIPLIER
547 + WindowManagerService.TYPE_LAYER_OFFSET;
548 mSubLayer = 0;
549 mAttachedWindow = null;
550 mLayoutAttached = false;
551 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
552 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
553 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
554 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
555 }
556
557 WindowState appWin = this;
Robert Carr51a1b872015-12-08 14:03:13 -0800558 while (appWin.isChildWindow()) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700559 appWin = appWin.mAttachedWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800560 }
561 WindowToken appToken = appWin.mToken;
562 while (appToken.appWindowToken == null) {
563 WindowToken parent = mService.mTokenMap.get(appToken.token);
564 if (parent == null || appToken == parent) {
565 break;
566 }
567 appToken = parent;
568 }
569 mRootToken = appToken;
570 mAppToken = appToken.appWindowToken;
Craig Mautner19ab8282014-05-07 10:35:34 -0700571 if (mAppToken != null) {
572 final DisplayContent appDisplay = getDisplayContent();
573 mNotOnAppsDisplay = displayContent != appDisplay;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700574
575 if (mAppToken.showForAllUsers) {
576 // Windows for apps that can show for all users should also show when the
577 // device is locked.
578 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
579 }
Craig Mautner19ab8282014-05-07 10:35:34 -0700580 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800581
Craig Mautner322e4032012-07-13 13:35:20 -0700582 mWinAnimator = new WindowStateAnimator(this);
583 mWinAnimator.mAlpha = a.alpha;
584
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800585 mRequestedWidth = 0;
586 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700587 mLastRequestedWidth = 0;
588 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800589 mXOffset = 0;
590 mYOffset = 0;
591 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800592 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700593 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
594 displayContent.getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800595 }
596
597 void attach() {
598 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700599 TAG, "Attaching " + this + " token=" + mToken
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800600 + ", list=" + mToken.windows);
601 mSession.windowAddedLocked();
602 }
603
Craig Mautnera2c77052012-03-26 12:14:43 -0700604 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800605 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800606 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800607 }
608
609 @Override
610 public String getOwningPackage() {
611 return mAttrs.packageName;
612 }
613
614 @Override
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700615 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf, Rect sf,
616 Rect osf) {
Robert Carra1eb4392015-12-10 12:43:51 -0800617 if (mWillReplaceWindow && (mExiting || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700618 // This window is being replaced and either already got information that it's being
619 // removed or we are still waiting for some information. Because of this we don't
620 // want to apply any more changes to it, so it remains in this state until new window
621 // appears.
622 return;
623 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800624 mHaveFrame = true;
625
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700626 final Task task = getTask();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800627 final boolean fullscreenTask = task == null || task.isFullscreen();
Chong Zhang09b21ef2015-09-14 10:20:21 -0700628 final boolean freeformWorkspace = task != null && task.inFreeformWorkspace();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800629
Wale Ogunwale8216eb22015-12-18 10:42:42 -0800630 if (fullscreenTask || (isChildWindow()
631 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0)) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800632 // We use the parent frame as the containing frame for fullscreen and child windows
633 mContainingFrame.set(pf);
634 mDisplayFrame.set(df);
Jorim Jaggidc249c42015-12-15 14:57:31 -0800635 mInsetFrame.setEmpty();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800636 } else {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700637 task.getBounds(mContainingFrame);
Jorim Jaggidc249c42015-12-15 14:57:31 -0800638 task.getTempInsetBounds(mInsetFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100639 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
640
641 // If the bounds are frozen, we still want to translate the window freely and only
642 // freeze the size.
643 Rect frozen = mAppToken.mFrozenBounds.peek();
644 mContainingFrame.right = mContainingFrame.left + frozen.width();
645 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
646 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800647 final WindowState imeWin = mService.mInputMethodWindow;
648 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this
649 && mContainingFrame.bottom > cf.bottom) {
650 // IME is up and obscuring this window. Adjust the window position so it is visible.
651 mContainingFrame.top -= mContainingFrame.bottom - cf.bottom;
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700652 }
Skuhne81c524a2015-08-12 13:34:14 -0700653
Skuhnef932e562015-08-20 12:07:30 -0700654 if (freeformWorkspace) {
Skuhne81c524a2015-08-12 13:34:14 -0700655 // In free form mode we have only to set the rectangle if it wasn't set already. No
656 // need to intersect it with the (visible) "content frame" since it is allowed to
657 // be outside the visible desktop.
658 if (mContainingFrame.isEmpty()) {
659 mContainingFrame.set(cf);
660 }
Doris Liu06d582d2015-06-01 13:18:43 -0700661 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800662 mDisplayFrame.set(mContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700663 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800664
Craig Mautner967212c2013-04-13 21:10:58 -0700665 final int pw = mContainingFrame.width();
666 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800667
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800668 if (!mParentFrame.equals(pf)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800669 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800670 // + " to " + pf);
671 mParentFrame.set(pf);
672 mContentChanged = true;
673 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700674 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
675 mLastRequestedWidth = mRequestedWidth;
676 mLastRequestedHeight = mRequestedHeight;
677 mContentChanged = true;
678 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800679
Craig Mautnereda67292013-04-28 13:50:14 -0700680 mOverscanFrame.set(of);
681 mContentFrame.set(cf);
682 mVisibleFrame.set(vf);
John Spurlock46646232013-09-30 22:32:42 -0400683 mDecorFrame.set(dcf);
Adrian Roosfa104232014-06-20 16:10:14 -0700684 mStableFrame.set(sf);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700685 final boolean hasOutsets = osf != null;
686 if (hasOutsets) {
687 mOutsetFrame.set(osf);
688 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800689
Craig Mautnereda67292013-04-28 13:50:14 -0700690 final int fw = mFrame.width();
691 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800692
Robert Carr31e28482015-12-02 16:53:18 -0800693 applyGravityAndUpdateFrame();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800694
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700695 // Calculate the outsets before the content frame gets shrinked to the window frame.
696 if (hasOutsets) {
697 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
698 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
699 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
700 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
701 } else {
702 mOutsets.set(0, 0, 0, 0);
703 }
704
Jorim Jaggidc249c42015-12-15 14:57:31 -0800705 // Denotes the actual frame used to calculate the insets. When resizing in docked mode,
706 // we'd like to freeze the layout, so we also need to freeze the insets temporarily. By the
707 // notion of a task having a different inset frame, we can achieve that while still moving
708 // the task around.
709 final Rect frame = !mInsetFrame.isEmpty() ? mInsetFrame : mFrame;
710
Craig Mautnera248eee2013-05-07 11:41:27 -0700711 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800712 // final window frame.
Skuhnef932e562015-08-20 12:07:30 -0700713 if (freeformWorkspace && !mFrame.isEmpty()) {
Skuhne81c524a2015-08-12 13:34:14 -0700714 // Keep the frame out of the blocked system area, limit it in size to the content area
715 // and make sure that there is always a minimum visible so that the user can drag it
716 // into a usable area..
717 final int height = Math.min(mFrame.height(), mContentFrame.height());
718 final int width = Math.min(mContentFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700719 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700720 final int minVisibleHeight = WindowManagerService.dipToPixel(
721 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics);
722 final int minVisibleWidth = WindowManagerService.dipToPixel(
723 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics);
Skuhne81c524a2015-08-12 13:34:14 -0700724 final int top = Math.max(mContentFrame.top,
725 Math.min(mFrame.top, mContentFrame.bottom - minVisibleHeight));
726 final int left = Math.max(mContentFrame.left + minVisibleWidth - width,
727 Math.min(mFrame.left, mContentFrame.right - minVisibleWidth));
728 mFrame.set(left, top, left + width, top + height);
729 mContentFrame.set(mFrame);
730 mVisibleFrame.set(mContentFrame);
731 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700732 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800733 if (isVisibleLw() || mWinAnimator.isAnimating()) {
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800734 // We don't adjust the dock divider frame for reasons other than performance. The
735 // real reason is that if it gets adjusted before it is shown for the first time,
736 // it would get size (0, 0). This causes a problem when we finally show the dock
737 // divider and try to draw to it. We do set the surface size at that moment to
738 // the correct size, but it's too late for the Surface Flinger to make it
739 // available for view rendering and as a result the renderer receives size 1, 1.
740 // This way we just keep the divider at the original size and Surface Flinger
741 // will return the correct value to the renderer.
742 mDisplayContent.getDockedDividerController().positionDockedStackedDivider(mFrame);
743 mContentFrame.set(mFrame);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800744 if (!mFrame.equals(mLastFrame)) {
745 mMovedByResize = true;
746 }
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800747 }
Skuhne81c524a2015-08-12 13:34:14 -0700748 } else {
Jorim Jaggidc249c42015-12-15 14:57:31 -0800749 mContentFrame.set(Math.max(mContentFrame.left, frame.left),
750 Math.max(mContentFrame.top, frame.top),
751 Math.min(mContentFrame.right, frame.right),
752 Math.min(mContentFrame.bottom, frame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800753
Jorim Jaggidc249c42015-12-15 14:57:31 -0800754 mVisibleFrame.set(Math.max(mVisibleFrame.left, frame.left),
755 Math.max(mVisibleFrame.top, frame.top),
756 Math.min(mVisibleFrame.right, frame.right),
757 Math.min(mVisibleFrame.bottom, frame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800758
Jorim Jaggidc249c42015-12-15 14:57:31 -0800759 mStableFrame.set(Math.max(mStableFrame.left, frame.left),
760 Math.max(mStableFrame.top, frame.top),
761 Math.min(mStableFrame.right, frame.right),
762 Math.min(mStableFrame.bottom, frame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700763 }
Adrian Roosfa104232014-06-20 16:10:14 -0700764
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800765 if (!inFreeformWorkspace()) {
766 // Freeform windows can be positioned outside of the display frame, but that is not a
767 // reason to provide them with overscan insets.
768 mOverscanInsets.set(Math.max(mOverscanFrame.left - frame.left, 0),
769 Math.max(mOverscanFrame.top - frame.top, 0),
770 Math.max(frame.right - mOverscanFrame.right, 0),
771 Math.max(frame.bottom - mOverscanFrame.bottom, 0));
772 }
Craig Mautnereda67292013-04-28 13:50:14 -0700773
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100774 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100775 // For the docked divider, we calculate the stable insets like a full-screen window
776 // so it can use it to calculate the snap positions.
777 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
778 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
779 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
780 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800781
782 // The divider doesn't care about insets in any case, so set it to empty so we don't
783 // trigger a relayout when moving it.
784 mContentInsets.setEmpty();
785 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100786 } else {
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800787 mContentInsets.set(mContentFrame.left - frame.left,
788 mContentFrame.top - frame.top,
789 frame.right - mContentFrame.right,
790 frame.bottom - mContentFrame.bottom);
791
792 mVisibleInsets.set(mVisibleFrame.left - frame.left,
793 mVisibleFrame.top - frame.top,
794 frame.right - mVisibleFrame.right,
795 frame.bottom - mVisibleFrame.bottom);
796
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100797 mStableInsets.set(Math.max(mStableFrame.left - frame.left, 0),
798 Math.max(mStableFrame.top - frame.top, 0),
799 Math.max(frame.right - mStableFrame.right, 0),
800 Math.max(frame.bottom - mStableFrame.bottom, 0));
801 }
Adrian Roosfa104232014-06-20 16:10:14 -0700802
Jorim Jaggidc249c42015-12-15 14:57:31 -0800803 if (!mInsetFrame.isEmpty()) {
804 mContentFrame.set(mFrame);
805 mContentFrame.top += mContentInsets.top;
806 mContentFrame.bottom += mContentInsets.bottom;
807 mContentFrame.left += mContentInsets.left;
808 mContentFrame.right += mContentInsets.right;
809 mVisibleFrame.set(mFrame);
810 mVisibleFrame.top += mVisibleInsets.top;
811 mVisibleFrame.bottom += mVisibleInsets.bottom;
812 mVisibleFrame.left += mVisibleInsets.left;
813 mVisibleFrame.right += mVisibleInsets.right;
814 mStableFrame.set(mFrame);
815 mStableFrame.top += mStableInsets.top;
816 mStableFrame.bottom += mStableInsets.bottom;
817 mStableFrame.left += mStableInsets.left;
818 mStableFrame.right += mStableInsets.right;
819 }
Craig Mautnereda67292013-04-28 13:50:14 -0700820 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400821 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700822 // If there is a size compatibility scale being applied to the
823 // window, we need to apply this to its insets so that they are
824 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700825 mOverscanInsets.scale(mInvGlobalScale);
826 mContentInsets.scale(mInvGlobalScale);
827 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700828 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700829 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700830
831 // Also the scaled frame that we report to the app needs to be
832 // adjusted to be in its coordinate space.
833 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400834 }
835
Craig Mautnereda67292013-04-28 13:50:14 -0700836 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800837 final DisplayContent displayContent = getDisplayContent();
838 if (displayContent != null) {
839 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700840 mService.mWallpaperControllerLocked.updateWallpaperOffset(
841 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800842 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800843 }
844
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700845 if (DEBUG_LAYOUT || WindowManagerService.localLOGV) Slog.v(TAG,
846 "Resolving (mRequestedWidth="
847 + mRequestedWidth + ", mRequestedheight="
848 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
849 + "): frame=" + mFrame.toShortString()
850 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -0700851 + " vi=" + mVisibleInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700852 + " vi=" + mStableInsets.toShortString()
853 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800854 }
855
Craig Mautnera2c77052012-03-26 12:14:43 -0700856 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800857 public Rect getFrameLw() {
858 return mFrame;
859 }
860
Craig Mautnera2c77052012-03-26 12:14:43 -0700861 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700862 public Point getShownPositionLw() {
863 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800864 }
865
Craig Mautnera2c77052012-03-26 12:14:43 -0700866 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800867 public Rect getDisplayFrameLw() {
868 return mDisplayFrame;
869 }
870
Craig Mautnera2c77052012-03-26 12:14:43 -0700871 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800872 public Rect getOverscanFrameLw() {
873 return mOverscanFrame;
874 }
875
876 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800877 public Rect getContentFrameLw() {
878 return mContentFrame;
879 }
880
Craig Mautnera2c77052012-03-26 12:14:43 -0700881 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800882 public Rect getVisibleFrameLw() {
883 return mVisibleFrame;
884 }
885
Craig Mautnera2c77052012-03-26 12:14:43 -0700886 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800887 public boolean getGivenInsetsPendingLw() {
888 return mGivenInsetsPending;
889 }
890
Craig Mautnera2c77052012-03-26 12:14:43 -0700891 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800892 public Rect getGivenContentInsetsLw() {
893 return mGivenContentInsets;
894 }
895
Craig Mautnera2c77052012-03-26 12:14:43 -0700896 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800897 public Rect getGivenVisibleInsetsLw() {
898 return mGivenVisibleInsets;
899 }
900
Craig Mautnera2c77052012-03-26 12:14:43 -0700901 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800902 public WindowManager.LayoutParams getAttrs() {
903 return mAttrs;
904 }
905
Craig Mautner812d2ca2012-09-27 15:35:34 -0700906 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800907 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
908 int index = -1;
909 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -0700910 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800911 while (true) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -0700912 if (ws.mAttrs.needsMenuKey != WindowManager.LayoutParams.NEEDS_MENU_UNSET) {
913 return ws.mAttrs.needsMenuKey == WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800914 }
915 // If we reached the bottom of the range of windows we are considering,
916 // assume no menu is needed.
917 if (ws == bottom) {
918 return false;
919 }
920 // The current window hasn't specified whether menu key is needed;
921 // look behind it.
922 // First, we may need to determine the starting position.
923 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -0700924 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800925 }
926 index--;
927 if (index < 0) {
928 return false;
929 }
Craig Mautner59c00972012-07-30 12:10:24 -0700930 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800931 }
932 }
933
Craig Mautner19d59bc2012-09-04 11:15:56 -0700934 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700935 public int getSystemUiVisibility() {
936 return mSystemUiVisibility;
937 }
938
Craig Mautner19d59bc2012-09-04 11:15:56 -0700939 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800940 public int getSurfaceLayer() {
941 return mLayer;
942 }
943
Craig Mautner812d2ca2012-09-27 15:35:34 -0700944 @Override
Selim Cinekd6623612015-05-22 18:56:22 -0700945 public int getBaseType() {
946 WindowState win = this;
Robert Carr51a1b872015-12-08 14:03:13 -0800947 while (win.isChildWindow()) {
Selim Cinekd6623612015-05-22 18:56:22 -0700948 win = win.mAttachedWindow;
949 }
950 return win.mAttrs.type;
951 }
952
953 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800954 public IApplicationToken getAppToken() {
955 return mAppToken != null ? mAppToken.appToken : null;
956 }
Craig Mautner19d59bc2012-09-04 11:15:56 -0700957
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700958 @Override
959 public boolean isVoiceInteraction() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700960 return mAppToken != null && mAppToken.voiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700961 }
962
Craig Mautner4c5eb222013-11-18 12:59:05 -0800963 boolean setInsetsChanged() {
964 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
965 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
966 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -0700967 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700968 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
969 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
970 || mOutsetsChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -0800971 }
972
Craig Mautnerdf88d732014-01-27 09:21:32 -0800973 public DisplayContent getDisplayContent() {
Chad Jonesf391ebc2014-06-12 17:45:05 -0700974 if (mAppToken == null || mNotOnAppsDisplay) {
Craig Mautnerbe634952014-06-12 13:39:24 -0700975 return mDisplayContent;
976 }
977 final TaskStack stack = getStack();
978 return stack == null ? mDisplayContent : stack.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -0800979 }
980
Chong Zhang09b21ef2015-09-14 10:20:21 -0700981 public DisplayInfo getDisplayInfo() {
982 final DisplayContent displayContent = getDisplayContent();
983 return displayContent != null ? displayContent.getDisplayInfo() : null;
984 }
985
Craig Mautner19d59bc2012-09-04 11:15:56 -0700986 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800987 final DisplayContent displayContent = getDisplayContent();
988 if (displayContent == null) {
989 return -1;
990 }
991 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -0700992 }
993
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700994 Task getTask() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700995 return mAppToken != null ? mAppToken.mTask : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700996 }
997
998 TaskStack getStack() {
999 Task task = getTask();
1000 if (task != null) {
1001 if (task.mStack != null) {
1002 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001003 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001004 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001005 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1006 // associate them with some stack to enable dimming.
1007 return mAttrs.type >= WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1008 && mDisplayContent != null ? mDisplayContent.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001009 }
1010
Skuhnef932e562015-08-20 12:07:30 -07001011 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001012 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001013 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001014 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001015 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001016 final Task task = getTask();
1017 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001018 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001019 mTmpRect.setEmpty();
1020 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001021 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001022 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001023 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001024 } else {
1025 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001026 }
1027 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001028
Chong Zhang9184ec62015-09-24 12:32:21 -07001029 bounds.set(mVisibleFrame);
1030 if (intersectWithStackBounds) {
1031 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001032 }
1033
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001034 if (bounds.isEmpty()) {
1035 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001036 if (intersectWithStackBounds) {
1037 bounds.intersect(mTmpRect);
1038 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001039 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001040 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001041 }
1042
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001043 public long getInputDispatchingTimeoutNanos() {
1044 return mAppToken != null
1045 ? mAppToken.inputDispatchingTimeoutNanos
1046 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1047 }
1048
Craig Mautnere8552142012-11-07 13:55:47 -08001049 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001050 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001051 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001052 }
1053
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001054 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1055 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1056 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1057 if (dtdx < -.000001f || dtdx > .000001f) return false;
1058 if (dsdy < -.000001f || dsdy > .000001f) return false;
1059 return true;
1060 }
1061
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001062 void prelayout() {
1063 if (mEnforceSizeCompat) {
1064 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001065 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001066 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001067 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001068 }
1069 }
1070
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001071 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001072 * Does the minimal check for visibility. Callers generally want to use one of the public
1073 * methods as they perform additional checks on the app token.
1074 * TODO: See if there are other places we can use this check below instead of duplicating...
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001075 */
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001076 private boolean isVisibleUnchecked() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001077 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001078 && !mExiting && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001079 }
1080
1081 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001082 * Is this window visible? It is not visible if there is no surface, or we are in the process
1083 * of running an exit animation that will remove the surface, or its app token has been hidden.
1084 */
1085 @Override
1086 public boolean isVisibleLw() {
1087 return (mAppToken == null || !mAppToken.hiddenRequested) && isVisibleUnchecked();
1088 }
1089
1090 /**
1091 * Like {@link #isVisibleLw}, but also counts a window that is currently "hidden" behind the
1092 * keyguard as visible. This allows us to apply things like window flags that impact the
1093 * keyguard. XXX I am starting to think we need to have ANOTHER visibility flag for this
1094 * "hidden behind keyguard" state rather than overloading mPolicyVisibility. Ungh.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001095 */
Craig Mautner88400d32012-09-30 12:35:45 -07001096 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001097 public boolean isVisibleOrBehindKeyguardLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001098 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001099 return false;
1100 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001101 final AppWindowToken atoken = mAppToken;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001102 final boolean animating = atoken != null && atoken.mAppAnimator.animation != null;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001103 return mHasSurface && !mDestroying && !mExiting
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001104 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001105 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001106 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001107 }
1108
1109 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001110 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1111 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001112 */
1113 public boolean isWinVisibleLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001114 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.mAppAnimator.animating)
1115 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001116 }
1117
1118 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001119 * The same as isVisible(), but follows the current hidden state of the associated app token,
1120 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001121 */
1122 boolean isVisibleNow() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001123 return (!mRootToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
1124 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001125 }
1126
1127 /**
1128 * Can this window possibly be a drag/drop target? The test here is
1129 * a combination of the above "visible now" with the check that the
1130 * Input Manager uses when discarding windows from input consideration.
1131 */
1132 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001133 return isVisibleNow() && !mRemoved
1134 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001135 }
1136
1137 /**
1138 * Same as isVisible(), but we also count it as visible between the
1139 * call to IWindowSession.add() and the first relayout().
1140 */
1141 boolean isVisibleOrAdding() {
1142 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001143 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001144 && mPolicyVisibility && !mAttachedHidden
1145 && (atoken == null || !atoken.hiddenRequested)
1146 && !mExiting && !mDestroying;
1147 }
1148
1149 /**
1150 * Is this window currently on-screen? It is on-screen either if it
1151 * is visible or it is currently running an animation before no longer
1152 * being visible.
1153 */
1154 boolean isOnScreen() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001155 return mPolicyVisibility && isOnScreenIgnoringKeyguard();
1156 }
1157
1158 /**
1159 * Like isOnScreen(), but ignores any force hiding of the window due
1160 * to the keyguard.
1161 */
1162 boolean isOnScreenIgnoringKeyguard() {
1163 if (!mHasSurface || mDestroying) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001164 return false;
1165 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001166 final AppWindowToken atoken = mAppToken;
1167 if (atoken != null) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001168 return ((!mAttachedHidden && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001169 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001170 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001171 return !mAttachedHidden || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001172 }
1173
1174 /**
1175 * Like isOnScreen(), but we don't return true if the window is part
1176 * of a transition that has not yet been started.
1177 */
1178 boolean isReadyForDisplay() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001179 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001180 return false;
1181 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001182 return mHasSurface && mPolicyVisibility && !mDestroying
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001183 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001184 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001185 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001186 }
1187
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001188 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001189 * Like isReadyForDisplay(), but ignores any force hiding of the window due
1190 * to the keyguard.
1191 */
1192 boolean isReadyForDisplayIgnoringKeyguard() {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001193 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001194 return false;
1195 }
1196 final AppWindowToken atoken = mAppToken;
1197 if (atoken == null && !mPolicyVisibility) {
1198 // If this is not an app window, and the policy has asked to force
1199 // hide, then we really do want to hide.
1200 return false;
1201 }
1202 return mHasSurface && !mDestroying
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001203 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE && !mRootToken.hidden)
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001204 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -07001205 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
1206 && !mWinAnimator.isDummyAnimation()));
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001207 }
1208
1209 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001210 * Like isOnScreen, but returns false if the surface hasn't yet
1211 * been drawn.
1212 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001213 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001214 public boolean isDisplayedLw() {
1215 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001216 return isDrawnLw() && mPolicyVisibility
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001217 && ((!mAttachedHidden &&
1218 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001219 || mWinAnimator.mAnimating
1220 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001221 }
1222
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001223 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001224 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001225 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001226 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001227 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001228 return mWinAnimator.mAnimation != null
1229 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001230 }
1231
Craig Mautner812d2ca2012-09-27 15:35:34 -07001232 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001233 public boolean isGoneForLayoutLw() {
1234 final AppWindowToken atoken = mAppToken;
1235 return mViewVisibility == View.GONE
1236 || !mRelayoutCalled
1237 || (atoken == null && mRootToken.hidden)
Craig Mautner812d2ca2012-09-27 15:35:34 -07001238 || (atoken != null && (atoken.hiddenRequested || atoken.hidden))
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001239 || mAttachedHidden
Craig Mautner0e415c62013-04-29 16:10:58 -07001240 || (mExiting && !isAnimatingLw())
1241 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001242 }
1243
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001244 /**
1245 * Returns true if the window has a surface that it has drawn a
1246 * complete UI in to.
1247 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001248 public boolean isDrawFinishedLw() {
1249 return mHasSurface && !mDestroying &&
1250 (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING
1251 || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1252 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
1253 }
1254
1255 /**
1256 * Returns true if the window has a surface that it has drawn a
1257 * complete UI in to.
1258 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001259 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001260 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001261 return mHasSurface && !mDestroying &&
Craig Mautner749a7bb2012-04-02 13:49:53 -07001262 (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1263 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001264 }
1265
1266 /**
1267 * Return true if the window is opaque and fully drawn. This indicates
1268 * it may obscure windows behind it.
1269 */
1270 boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001271 // When there is keyguard, wallpaper could be placed over the secure app
1272 // window but invisible. We need to check wallpaper visibility explicitly
1273 // to determine if it's occluding apps.
1274 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1275 || (mIsWallpaper && mWallpaperVisible))
Craig Mautnera2c77052012-03-26 12:14:43 -07001276 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001277 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001278 }
1279
1280 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001281 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001282 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1283 */
Craig Mautner4557c082015-04-27 13:07:40 -07001284 boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001285 return mHasSurface && (mContentChanged || mMovedByResize)
1286 && !mExiting && !mWinAnimator.mLastHidden && mService.okToDisplay()
1287 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Craig Mautner4557c082015-04-27 13:07:40 -07001288 && (mAttachedWindow == null || !mAttachedWindow.hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001289 }
1290
Chong Zhang0abb20f2015-11-19 14:17:31 -08001291 boolean isObscuringFullscreen(final DisplayInfo displayInfo) {
1292 Task task = getTask();
1293 if (task != null && task.mStack != null && !task.mStack.isFullscreen()) {
1294 return false;
1295 }
1296 if (!isOpaqueDrawn() || !isFrameFullscreen(displayInfo)) {
1297 return false;
1298 }
1299 return true;
1300 }
1301
1302 boolean isFrameFullscreen(final DisplayInfo displayInfo) {
1303 return mFrame.left <= 0 && mFrame.top <= 0
1304 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001305 }
1306
Craig Mautner812d2ca2012-09-27 15:35:34 -07001307 boolean isConfigChanged() {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001308 final Task task = getTask();
Wale Ogunwale60454db2015-01-23 16:05:07 -08001309 final Configuration overrideConfig =
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001310 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001311 final Configuration serviceConfig = mService.mCurConfiguration;
1312 boolean configChanged =
1313 (mConfiguration != serviceConfig && mConfiguration.diff(serviceConfig) != 0)
1314 || (mOverrideConfig != overrideConfig && !mOverrideConfig.equals(overrideConfig));
Craig Mautnere8552142012-11-07 13:55:47 -08001315
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001316 if ((mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Craig Mautnere8552142012-11-07 13:55:47 -08001317 // Retain configuration changed status until resetConfiguration called.
1318 mConfigHasChanged |= configChanged;
1319 configChanged = mConfigHasChanged;
1320 }
1321
1322 return configChanged;
Craig Mautner812d2ca2012-09-27 15:35:34 -07001323 }
1324
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001325 void removeLocked() {
1326 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001327
Robert Carr51a1b872015-12-08 14:03:13 -08001328 if (isChildWindow()) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001329 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001330 mAttachedWindow.mChildWindows.remove(this);
1331 }
Craig Mautner96868332012-12-04 14:29:11 -08001332 mWinAnimator.destroyDeferredSurfaceLocked();
1333 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001334 mSession.windowRemovedLocked();
1335 try {
1336 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1337 } catch (RuntimeException e) {
1338 // Ignore if it has already been removed (usually because
1339 // we are doing this as part of processing a death note.)
1340 }
1341 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001342
Wale Ogunwale60454db2015-01-23 16:05:07 -08001343 private void setConfiguration(
1344 final Configuration newConfig, final Configuration newOverrideConfig) {
Craig Mautnere8552142012-11-07 13:55:47 -08001345 mConfiguration = newConfig;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001346 mOverrideConfig = newOverrideConfig;
Craig Mautnere8552142012-11-07 13:55:47 -08001347 mConfigHasChanged = false;
1348 }
1349
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001350 void setHasSurface(boolean hasSurface) {
1351 mHasSurface = hasSurface;
1352 }
1353
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001354 int getAnimLayerAdjustment() {
1355 if (mTargetAppToken != null) {
1356 return mTargetAppToken.mAppAnimator.animLayerAdjustment;
1357 } else if (mAppToken != null) {
1358 return mAppToken.mAppAnimator.animLayerAdjustment;
1359 } else {
1360 // Nothing is animating, so there is no animation adjustment.
1361 return 0;
1362 }
1363 }
1364
1365 void scheduleAnimationIfDimming() {
1366 if (mDisplayContent == null) {
1367 return;
1368 }
1369 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1370 if (dimLayerUser != null && mDisplayContent.mDimLayerController.isDimming(
1371 dimLayerUser, mWinAnimator)) {
1372 // Force an animation pass just to update the mDimLayer layer.
1373 mService.scheduleAnimationLocked();
1374 }
1375 }
1376
Chong Zhangacf11402015-11-04 16:23:10 -08001377 private final class DeadWindowEventReceiver extends InputEventReceiver {
1378 DeadWindowEventReceiver(InputChannel inputChannel) {
1379 super(inputChannel, mService.mH.getLooper());
1380 }
1381 @Override
1382 public void onInputEvent(InputEvent event) {
1383 finishInputEvent(event, true);
1384 }
1385 }
1386 /**
1387 * Dummy event receiver for windows that died visible.
1388 */
1389 private DeadWindowEventReceiver mDeadWindowEventReceiver;
1390
Chong Zhang112eb8c2015-11-02 11:17:00 -08001391 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001392 if (mInputChannel != null) {
1393 throw new IllegalStateException("Window already has an input channel.");
1394 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001395 String name = makeInputChannelName();
1396 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1397 mInputChannel = inputChannels[0];
1398 mClientChannel = inputChannels[1];
1399 mInputWindowHandle.inputChannel = inputChannels[0];
1400 if (outInputChannel != null) {
1401 mClientChannel.transferTo(outInputChannel);
1402 mClientChannel.dispose();
1403 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08001404 } else {
1405 // If the window died visible, we setup a dummy input channel, so that taps
1406 // can still detected by input monitor channel, and we can relaunch the app.
1407 // Create dummy event receiver that simply reports all events as handled.
1408 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08001409 }
1410 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001411 }
1412
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001413 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08001414 if (mDeadWindowEventReceiver != null) {
1415 mDeadWindowEventReceiver.dispose();
1416 mDeadWindowEventReceiver = null;
1417 }
1418
1419 // unregister server channel first otherwise it complains about broken channel
1420 if (mInputChannel != null) {
1421 mService.mInputManager.unregisterInputChannel(mInputChannel);
1422 mInputChannel.dispose();
1423 mInputChannel = null;
1424 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001425 if (mClientChannel != null) {
1426 mClientChannel.dispose();
1427 mClientChannel = null;
1428 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001429 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001430 }
1431
Chong Zhang112eb8c2015-11-02 11:17:00 -08001432 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08001433 // When the app is terminated (eg. from Recents), the task might have already been
1434 // removed with the window pending removal. Don't apply dim in such cases, as there
1435 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
1436 final AppWindowToken token = mAppToken;
1437 if (token != null && token.removed) {
1438 return;
1439 }
1440
Chong Zhang112eb8c2015-11-02 11:17:00 -08001441 if (!mExiting && mAppDied) {
1442 // If app died visible, apply a dim over the window to indicate that it's inactive
1443 mDisplayContent.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
1444 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
1445 && mDisplayContent != null && !mExiting && isDisplayedLw()) {
1446 mDisplayContent.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001447 }
1448 }
1449
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001450 DimLayer.DimLayerUser getDimLayerUser() {
1451 Task task = getTask();
1452 if (task != null) {
1453 return task;
1454 }
1455 return getStack();
1456 }
1457
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001458 void maybeRemoveReplacedWindow() {
Robert Carra1eb4392015-12-10 12:43:51 -08001459 if (mAppToken == null) {
1460 return;
1461 }
1462 for (int i = mAppToken.allAppWindows.size() - 1; i >= 0; i--) {
1463 final WindowState win = mAppToken.allAppWindows.get(i);
Robert Carra1eb4392015-12-10 12:43:51 -08001464 if (win.mWillReplaceWindow && win.mReplacingWindow == this) {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08001465 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + win);
Robert Carra1eb4392015-12-10 12:43:51 -08001466 win.mWillReplaceWindow = false;
1467 win.mAnimateReplacingWindow = false;
1468 win.mReplacingRemoveRequested = false;
1469 win.mReplacingWindow = null;
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001470 if (win.mExiting) {
1471 mService.removeWindowInnerLocked(win);
1472 }
1473 }
1474 }
1475 }
1476
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07001477 void setDisplayLayoutNeeded() {
1478 if (mDisplayContent != null) {
1479 mDisplayContent.layoutNeeded = true;
1480 }
1481 }
1482
Filip Gruszczynski955b2fc2015-10-15 14:46:07 -07001483 boolean inDockedWorkspace() {
Chong Zhang2a88fc32016-01-11 17:14:24 -08001484 final Task task = getTask();
Chong Zhangb15758a2015-11-17 12:12:03 -08001485 return task != null && task.inDockedWorkspace();
1486 }
1487
1488 boolean isDockedInEffect() {
Chong Zhang2a88fc32016-01-11 17:14:24 -08001489 final Task task = getTask();
Chong Zhangb15758a2015-11-17 12:12:03 -08001490 return task != null && task.isDockedInEffect();
Filip Gruszczynski955b2fc2015-10-15 14:46:07 -07001491 }
1492
Chong Zhang2a88fc32016-01-11 17:14:24 -08001493 void applyScrollIfNeeded() {
1494 final Task task = getTask();
Chong Zhangf66db432016-01-13 10:39:51 -08001495 if (task != null) {
1496 task.applyScrollToWindowIfNeeded(this);
Chong Zhang2a88fc32016-01-11 17:14:24 -08001497 }
1498 }
1499
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001500 int getTouchableRegion(Region region, int flags) {
1501 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001502 if (modal && mAppToken != null) {
1503 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001504 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001505 // If this is a modal window we need to dismiss it if it's not full screen and the
1506 // touch happens outside of the frame that displays the content. This means we
1507 // need to intercept touches outside of that window. The dim layer user
1508 // associated with the window (task or stack) will give us the good bounds, as
1509 // they would be used to display the dim layer.
1510 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1511 if (dimLayerUser != null) {
1512 dimLayerUser.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001513 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001514 getVisibleBounds(mTmpRect);
1515 }
1516 if (inFreeformWorkspace()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001517 // For freeform windows we the touch region to include the whole surface for the
1518 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001519 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
1520 final int delta = WindowManagerService.dipToPixel(
1521 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
1522 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001523 }
1524 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001525 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001526 } else {
1527 // Not modal or full screen modal
1528 getTouchableRegion(region);
1529 }
1530 return flags;
1531 }
1532
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001533 void checkPolicyVisibilityChange() {
1534 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
1535 if (DEBUG_VISIBILITY) {
1536 Slog.v(TAG, "Policy visibility changing after anim in " +
1537 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
1538 }
1539 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001540 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001541 if (!mPolicyVisibility) {
1542 if (mService.mCurrentFocus == this) {
1543 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
1544 "setAnimationLocked: setting mFocusMayChange true");
1545 mService.mFocusMayChange = true;
1546 }
1547 // Window is no longer visible -- make sure if we were waiting
1548 // for it to be displayed before enabling the display, that
1549 // we allow the display to be enabled now.
1550 mService.enableScreenIfNeededLocked();
1551 }
1552 }
1553 }
1554
1555 void setRequestedSize(int requestedWidth, int requestedHeight) {
1556 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
1557 mLayoutNeeded = true;
1558 mRequestedWidth = requestedWidth;
1559 mRequestedHeight = requestedHeight;
1560 }
1561 }
1562
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001563 void prepareWindowToDisplayDuringRelayout(Configuration outConfig) {
1564 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
1565 == SOFT_INPUT_ADJUST_RESIZE) {
1566 mLayoutNeeded = true;
1567 }
1568 if (isDrawnLw() && mService.okToDisplay()) {
1569 mWinAnimator.applyEnterAnimationLocked();
1570 }
1571 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
1572 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
1573 mTurnOnScreen = true;
1574 }
1575 if (isConfigChanged()) {
1576 if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + this + " visible with new config: "
1577 + mService.mCurConfiguration);
1578 outConfig.setTo(mService.mCurConfiguration);
1579 }
1580 }
1581
1582 void adjustStartingWindowFlags() {
1583 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
1584 && mAppToken.startingWindow != null) {
1585 // Special handling of starting window over the base
1586 // window of the app: propagate lock screen flags to it,
1587 // to provide the correct semantics while starting.
1588 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
1589 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
1590 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
1591 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
1592 }
1593 }
1594
1595 void setWindowScale(int requestedWidth, int requestedHeight) {
1596 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
1597
1598 if (scaledWindow) {
1599 // requested{Width|Height} Surface's physical size
1600 // attrs.{width|height} Size on screen
1601 // TODO: We don't check if attrs != null here. Is it implicitly checked?
1602 mHScale = (mAttrs.width != requestedWidth) ?
1603 (mAttrs.width / (float)requestedWidth) : 1.0f;
1604 mVScale = (mAttrs.height != requestedHeight) ?
1605 (mAttrs.height / (float)requestedHeight) : 1.0f;
1606 } else {
1607 mHScale = mVScale = 1;
1608 }
1609 }
1610
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001611 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08001612 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001613 public void binderDied() {
1614 try {
1615 synchronized(mService.mWindowMap) {
1616 WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07001617 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001618 if (win != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001619 if (win.mAppToken != null && !win.mAppToken.clientHidden) {
1620 win.mAppToken.appDied = true;
1621 }
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001622 mService.removeWindowLocked(win);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08001623 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
1624 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08001625 // just in case they have the divider at an unstable position. Better
1626 // also reset drag resizing state, because the owner can't do it
1627 // anymore.
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08001628 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
1629 if (stack != null) {
1630 stack.resetDockedStackToMiddle();
1631 }
Jorim Jaggidcb68142016-02-09 21:51:30 -08001632 mService.setDockedStackResizing(false);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08001633 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001634 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08001635 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001636 mService.removeWindowLocked(WindowState.this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001637 }
1638 }
1639 } catch (IllegalArgumentException ex) {
1640 // This will happen if the window has already been
1641 // removed.
1642 }
1643 }
1644 }
1645
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08001646 /**
1647 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
1648 * because we want to preserve its location on screen to be re-activated later when the user
1649 * interacts with it.
1650 */
1651 boolean shouldKeepVisibleDeadAppWindow() {
1652 if (!isWinVisibleLw() || mAppToken == null || !mAppToken.appDied) {
1653 // Not a visible app window or the app isn't dead.
1654 return false;
1655 }
1656
1657 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1658 // We don't keep starting windows since they were added by the window manager before
1659 // the app even launched.
1660 return false;
1661 }
1662
1663 final TaskStack stack = getStack();
1664 return stack != null && StackId.keepVisibleDeadAppWindowOnScreen(stack.mStackId);
1665 }
1666
Wale Ogunwaled045c822015-12-02 09:14:28 -08001667 /** @return true if this window desires key events. */
1668 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08001669 return isVisibleOrAdding()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001670 && (mViewVisibility == View.VISIBLE)
Wale Ogunwaled045c822015-12-02 09:14:28 -08001671 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Wale Ogunwale6cae7652015-12-26 07:36:26 -08001672 && (mAppToken == null || mAppToken.windowsAreFocusable());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001673 }
1674
Craig Mautner749a7bb2012-04-02 13:49:53 -07001675 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001676 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001677 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001678 }
1679
Craig Mautner749a7bb2012-04-02 13:49:53 -07001680 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001681 public boolean showLw(boolean doAnimation) {
1682 return showLw(doAnimation, true);
1683 }
1684
1685 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07001686 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001687 return false;
1688 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001689 if (!mAppOpVisibility) {
1690 // Being hidden due to app op request.
1691 return false;
1692 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001693 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001694 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001695 return false;
1696 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001697 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001698 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001699 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07001700 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07001701 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001702 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07001703 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001704 // Check for the case where we are currently visible and
1705 // not animating; we do not want to do animation at such a
1706 // point to become visible when we already are.
1707 doAnimation = false;
1708 }
1709 }
1710 mPolicyVisibility = true;
1711 mPolicyVisibilityAfterAnim = true;
1712 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001713 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001714 }
1715 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001716 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001717 }
1718 return true;
1719 }
1720
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001721 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001722 public boolean hideLw(boolean doAnimation) {
1723 return hideLw(doAnimation, true);
1724 }
1725
1726 boolean hideLw(boolean doAnimation, boolean requestAnim) {
1727 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07001728 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001729 doAnimation = false;
1730 }
1731 }
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001732 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
1733 : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001734 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001735 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001736 return false;
1737 }
1738 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001739 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07001740 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001741 doAnimation = false;
1742 }
1743 }
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001744 if (doAnimation) {
1745 mPolicyVisibilityAfterAnim = false;
1746 } else {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001747 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001748 mPolicyVisibilityAfterAnim = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001749 mPolicyVisibility = false;
1750 // Window is no longer visible -- make sure if we were waiting
1751 // for it to be displayed before enabling the display, that
1752 // we allow the display to be enabled now.
1753 mService.enableScreenIfNeededLocked();
1754 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001755 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07001756 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001757 mService.mFocusMayChange = true;
1758 }
1759 }
1760 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001761 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001762 }
1763 return true;
1764 }
1765
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001766 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001767 if (mAppOpVisibility != state) {
1768 mAppOpVisibility = state;
1769 if (state) {
1770 // If the policy visibility had last been to hide, then this
1771 // will incorrectly show at this point since we lost that
1772 // information. Not a big deal -- for the windows that have app
1773 // ops modifies they should only be hidden by policy due to the
1774 // lock screen, and the user won't be changing this if locked.
1775 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001776 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001777 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001778 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001779 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001780 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001781 }
1782
Jeff Brownc2932a12014-11-20 18:04:05 -08001783 public void pokeDrawLockLw(long timeout) {
1784 if (isVisibleOrAdding()) {
1785 if (mDrawLock == null) {
1786 // We want the tag name to be somewhat stable so that it is easier to correlate
1787 // in wake lock statistics. So in particular, we don't want to include the
1788 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001789 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08001790 mDrawLock = mService.mPowerManager.newWakeLock(
1791 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
1792 mDrawLock.setReferenceCounted(false);
1793 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
1794 }
1795 // Each call to acquire resets the timeout.
1796 if (DEBUG_POWER) {
1797 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
1798 + mAttrs.packageName);
1799 }
1800 mDrawLock.acquire(timeout);
1801 } else if (DEBUG_POWER) {
1802 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
1803 + "owned by " + mAttrs.packageName);
1804 }
1805 }
1806
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001807 @Override
1808 public boolean isAlive() {
1809 return mClient.asBinder().isBinderAlive();
1810 }
1811
Craig Mautnera987d432012-10-11 14:07:58 -07001812 boolean isClosing() {
1813 return mExiting || (mService.mClosingApps.contains(mAppToken));
1814 }
1815
Chong Zhangbef461f2015-10-27 11:38:24 -07001816 boolean isAnimatingWithSavedSurface() {
1817 return mAppToken != null && mAppToken.mAnimatingWithSavedSurface;
1818 }
1819
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001820 private boolean shouldSaveSurface() {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001821 if (ActivityManager.isLowRamDeviceStatic()) {
1822 // Don't save surfaces on Svelte devices.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001823 return false;
1824 }
1825
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001826 Task task = getTask();
1827 if (task == null || task.inHomeStack()) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001828 // Don't save surfaces for home stack apps. These usually resume and draw
1829 // first frame very fast. Saving surfaces are mostly a waste of memory.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001830 return false;
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001831 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001832
1833 final AppWindowToken taskTop = task.getTopVisibleAppToken();
1834 if (taskTop != null && taskTop != mAppToken) {
1835 // Don't save if the window is not the topmost window.
1836 return false;
1837 }
1838
Robert Carr7098dbd2016-02-01 12:31:01 -08001839 if (DEBUG_DISABLE_SAVING_SURFACES) {
1840 return false;
1841 }
1842
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001843 return mAppToken.shouldSaveSurface();
1844 }
1845
1846 void destroyOrSaveSurface() {
1847 mSurfaceSaved = shouldSaveSurface();
1848 if (mSurfaceSaved) {
1849 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1850 Slog.v(TAG, "Saving surface: " + this);
1851 }
1852
1853 mWinAnimator.hide("saved surface");
1854 mWinAnimator.mDrawState = WindowStateAnimator.NO_SURFACE;
1855 setHasSurface(false);
1856 } else {
Robert Carr13f7be9e2015-12-02 18:39:45 -08001857 mWinAnimator.destroySurfaceLocked();
1858 }
Robert Carr13f7be9e2015-12-02 18:39:45 -08001859 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001860
Robert Carr13f7be9e2015-12-02 18:39:45 -08001861 public void destroySavedSurface() {
Robert Carr13f7be9e2015-12-02 18:39:45 -08001862 if (mSurfaceSaved) {
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001863 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1864 Slog.v(TAG, "Destroying saved surface: " + this);
1865 }
Robert Carr13f7be9e2015-12-02 18:39:45 -08001866 mWinAnimator.destroySurfaceLocked();
1867 }
1868 }
1869
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001870 public void restoreSavedSurface() {
Chong Zhang4113ffa2016-02-18 12:39:13 -08001871 if (!mSurfaceSaved) {
1872 return;
1873 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001874 mSurfaceSaved = false;
1875 setHasSurface(true);
1876 mWinAnimator.mDrawState = WindowStateAnimator.READY_TO_SHOW;
1877 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1878 Slog.v(TAG, "Restoring saved surface: " + this);
1879 }
1880 }
1881
Robert Carr13f7be9e2015-12-02 18:39:45 -08001882 public boolean hasSavedSurface() {
1883 return mSurfaceSaved;
1884 }
1885
Craig Mautner69b08182012-09-05 13:07:13 -07001886 @Override
1887 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001888 final DisplayContent displayContent = getDisplayContent();
1889 if (displayContent == null) {
1890 // Only a window that was on a non-default display can be detached from it.
1891 return false;
1892 }
Winson Chung47a3e652014-05-21 16:03:42 -07001893 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07001894 }
1895
Adrian Rooscd3884d2015-02-18 17:25:23 +01001896 @Override
1897 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001898 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1899 return dimLayerUser != null && mDisplayContent != null &&
Chong Zhang112eb8c2015-11-02 11:17:00 -08001900 mDisplayContent.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01001901 }
1902
Craig Mautner88400d32012-09-30 12:35:45 -07001903 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
1904 mShowToOwnerOnly = showToOwnerOnly;
1905 }
1906
Craig Mautner5962b122012-10-05 14:45:52 -07001907 boolean isHiddenFromUserLocked() {
Craig Mautner341220f2012-10-16 15:20:09 -07001908 // Attached windows are evaluated based on the window that they are attached to.
1909 WindowState win = this;
Robert Carr51a1b872015-12-08 14:03:13 -08001910 while (win.isChildWindow()) {
Craig Mautner341220f2012-10-16 15:20:09 -07001911 win = win.mAttachedWindow;
1912 }
1913 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -07001914 && win.mAppToken != null && win.mAppToken.showForAllUsers) {
Craig Mautner341220f2012-10-16 15:20:09 -07001915 // Save some cycles by not calling getDisplayInfo unless it is an application
1916 // window intended for all users.
Craig Mautnerdf88d732014-01-27 09:21:32 -08001917 final DisplayContent displayContent = win.getDisplayContent();
1918 if (displayContent == null) {
1919 return true;
1920 }
1921 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Craig Mautner341220f2012-10-16 15:20:09 -07001922 if (win.mFrame.left <= 0 && win.mFrame.top <= 0
1923 && win.mFrame.right >= displayInfo.appWidth
1924 && win.mFrame.bottom >= displayInfo.appHeight) {
Craig Mautner5962b122012-10-05 14:45:52 -07001925 // Is a fullscreen window, like the clock alarm. Show to everyone.
1926 return false;
1927 }
1928 }
1929
Craig Mautner341220f2012-10-16 15:20:09 -07001930 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01001931 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001932 }
1933
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001934 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
1935 outRegion.set(
1936 frame.left + inset.left, frame.top + inset.top,
1937 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001938 }
1939
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001940 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001941 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001942 switch (mTouchableInsets) {
1943 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001944 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001945 outRegion.set(frame);
1946 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001947 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001948 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001949 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001950 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001951 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001952 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001953 case TOUCHABLE_INSETS_REGION: {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001954 final Region givenTouchableRegion = mGivenTouchableRegion;
1955 outRegion.set(givenTouchableRegion);
1956 outRegion.translate(frame.left, frame.top);
1957 break;
1958 }
1959 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001960 cropRegionToStackBoundsIfNeeded(outRegion);
1961 }
1962
1963 void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001964 final Task task = getTask();
1965 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001966 return;
1967 }
1968
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001969 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001970 if (stack == null) {
1971 return;
1972 }
1973
1974 stack.getDimBounds(mTmpRect);
1975 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001976 }
1977
Craig Mautner59c00972012-07-30 12:10:24 -07001978 WindowList getWindowList() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001979 final DisplayContent displayContent = getDisplayContent();
1980 return displayContent == null ? null : displayContent.getWindowList();
Craig Mautner59c00972012-07-30 12:10:24 -07001981 }
1982
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001983 /**
1984 * Report a focus change. Must be called with no locks held, and consistently
1985 * from the same serialized thread (such as dispatched from a handler).
1986 */
1987 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
1988 try {
1989 mClient.windowFocusChanged(focused, inTouchMode);
1990 } catch (RemoteException e) {
1991 }
1992 if (mFocusCallbacks != null) {
1993 final int N = mFocusCallbacks.beginBroadcast();
1994 for (int i=0; i<N; i++) {
1995 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
1996 try {
1997 if (focused) {
1998 obs.focusGained(mWindowId.asBinder());
1999 } else {
2000 obs.focusLost(mWindowId.asBinder());
2001 }
2002 } catch (RemoteException e) {
2003 }
2004 }
2005 mFocusCallbacks.finishBroadcast();
2006 }
2007 }
2008
Craig Mautnerdf88d732014-01-27 09:21:32 -08002009 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002010 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08002011 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002012 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
2013 + ": " + mCompatFrame);
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002014 final boolean configChanged = isConfigChanged();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002015 final Task task = getTask();
Wale Ogunwale60454db2015-01-23 16:05:07 -08002016 final Configuration overrideConfig =
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07002017 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002018 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) && configChanged) {
2019 Slog.i(TAG, "Sending new config to window " + this + ": "
Robert Carre6a83512015-11-03 16:09:21 -08002020 + " / config="
Wale Ogunwale60454db2015-01-23 16:05:07 -08002021 + mService.mCurConfiguration + " overrideConfig=" + overrideConfig);
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002022 }
Wale Ogunwale60454db2015-01-23 16:05:07 -08002023 setConfiguration(mService.mCurConfiguration, overrideConfig);
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002024 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING)
2025 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
2026
Craig Mautnerdf88d732014-01-27 09:21:32 -08002027 final Rect frame = mFrame;
2028 final Rect overscanInsets = mLastOverscanInsets;
2029 final Rect contentInsets = mLastContentInsets;
2030 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07002031 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002032 final Rect outsets = mLastOutsets;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002033 final boolean reportDraw = mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING;
2034 final Configuration newConfig = configChanged ? mConfiguration : null;
Chet Haase8eb48d22014-09-24 07:31:29 -07002035 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
2036 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002037 // To prevent deadlock simulate one-way call if win.mClient is a local object.
2038 mService.mH.post(new Runnable() {
2039 @Override
2040 public void run() {
2041 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002042 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
2043 stableInsets, outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002044 } catch (RemoteException e) {
2045 // Not a remote call, RemoteException won't be raised.
2046 }
2047 }
2048 });
2049 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002050 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002051 outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002052 }
Svetoslav4604abc2014-06-10 18:59:30 -07002053
2054 //TODO (multidisplay): Accessibility supported only for the default display.
2055 if (mService.mAccessibilityController != null
2056 && getDisplayId() == Display.DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07002057 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07002058 }
2059
Craig Mautnerdf88d732014-01-27 09:21:32 -08002060 mOverscanInsetsChanged = false;
2061 mContentInsetsChanged = false;
2062 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07002063 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002064 mOutsetsChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08002065 mWinAnimator.mSurfaceResized = false;
2066 } catch (RemoteException e) {
2067 mOrientationChanging = false;
2068 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2069 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08002070 // We are assuming the hosting process is dead or in a zombie state.
2071 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
2072 + ", removing this window.");
2073 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002074 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002075 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002076 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002077 }
2078
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002079 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08002080 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
2081 // start even if we haven't received the relayout window, so that the client requests
2082 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
2083 // until the window to small size, otherwise the multithread renderer will shift last
2084 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
2085 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002086 boolean resizing = isDragResizing() || isDragResizeChanged();
2087 if (StackId.useWindowFrameForBackdrop(getStackId()) || !resizing) {
2088 return frame;
2089 }
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002090 DisplayInfo displayInfo = getDisplayInfo();
2091 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002092 return mTmpRect;
2093 }
2094
Jorim Jaggi86905582016-02-09 21:36:09 -08002095 @Override
2096 public int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002097 final TaskStack stack = getStack();
2098 if (stack == null) {
2099 return INVALID_STACK_ID;
2100 }
2101 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002102 }
2103
2104 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
2105 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
2106 Configuration newConfig) throws RemoteException {
Jorim Jaggidc249c42015-12-15 14:57:31 -08002107 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Jorim Jaggia4a58ef2016-01-27 02:10:08 -08002108 reportDraw, newConfig, getBackdropFrame(frame),
2109 isDragResizeChanged() /* forceRelayout */);
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002110 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002111 }
2112
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002113 public void registerFocusObserver(IWindowFocusObserver observer) {
2114 synchronized(mService.mWindowMap) {
2115 if (mFocusCallbacks == null) {
2116 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
2117 }
2118 mFocusCallbacks.register(observer);
2119 }
2120 }
2121
2122 public void unregisterFocusObserver(IWindowFocusObserver observer) {
2123 synchronized(mService.mWindowMap) {
2124 if (mFocusCallbacks != null) {
2125 mFocusCallbacks.unregister(observer);
2126 }
2127 }
2128 }
2129
2130 public boolean isFocused() {
2131 synchronized(mService.mWindowMap) {
2132 return mService.mCurrentFocus == this;
2133 }
2134 }
2135
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07002136 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07002137 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07002138 return task != null && task.inFreeformWorkspace();
2139 }
2140
Chong Zhang3005e752015-09-18 18:46:28 -07002141 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002142 return mDragResizing != computeDragResizing();
2143 }
2144
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002145 /**
2146 * @return Whether we reported a drag resize change to the application or not already.
2147 */
2148 boolean isDragResizingChangeReported() {
2149 return mDragResizingChangeReported;
2150 }
2151
2152 /**
2153 * Resets the state whether we reported a drag resize change to the app.
2154 */
2155 void resetDragResizingChangeReported() {
2156 mDragResizingChangeReported = false;
2157 }
2158
Jorim Jaggidcf467c2015-11-05 13:59:32 +01002159 int getResizeMode() {
2160 return mResizeMode;
2161 }
2162
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002163 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07002164 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002165 if (task == null) {
2166 return false;
2167 }
2168 if (task.isDragResizing()) {
2169 return true;
2170 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01002171
2172 // If the bounds are currently frozen, it means that the layout size that the app sees
2173 // and the bounds we clip this window to might be different. In order to avoid holes, we
2174 // simulate that we are still resizing so the app fills the hole with the resizing
2175 // background.
2176 return (mDisplayContent.mDividerControllerLocked.isResizing()
2177 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Jorim Jaggi69abc192016-02-04 19:34:00 -08002178 !task.inFreeformWorkspace() && isVisibleLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08002179
Chong Zhang3005e752015-09-18 18:46:28 -07002180 }
2181
2182 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002183 final boolean resizing = computeDragResizing();
2184 if (resizing == mDragResizing) {
2185 return;
2186 }
2187 mDragResizing = resizing;
Jorim Jaggidcf467c2015-11-05 13:59:32 +01002188 mResizeMode = mDragResizing && mDisplayContent.mDividerControllerLocked.isResizing()
2189 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
2190 : DRAG_RESIZE_MODE_FREEFORM;
Chong Zhang3005e752015-09-18 18:46:28 -07002191 }
2192
2193 boolean isDragResizing() {
2194 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07002195 }
2196
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002197 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08002198 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002199 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08002200 if (stack != null) {
2201 pw.print(" stackId="); pw.print(stack.mStackId);
2202 }
Craig Mautner59c00972012-07-30 12:10:24 -07002203 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002204 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07002205 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08002206 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
2207 pw.print(" package="); pw.print(mAttrs.packageName);
2208 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002209 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002210 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
2211 pw.print(" h="); pw.print(mRequestedHeight);
2212 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07002213 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
2214 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
2215 pw.print(" h="); pw.println(mLastRequestedHeight);
2216 }
Robert Carr51a1b872015-12-08 14:03:13 -08002217 if (isChildWindow() || mLayoutAttached) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002218 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
2219 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
2220 }
2221 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
2222 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
2223 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
2224 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
2225 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
2226 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002227 if (dumpAll) {
2228 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
2229 pw.print(" mSubLayer="); pw.print(mSubLayer);
2230 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautner59431632012-04-04 11:56:44 -07002231 pw.print((mTargetAppToken != null ?
2232 mTargetAppToken.mAppAnimator.animLayerAdjustment
2233 : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002234 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
2235 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08002236 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002237 if (dumpAll) {
2238 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
2239 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
2240 if (mAppToken != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08002241 pw.print(prefix); pw.print("mAppToken="); pw.print(mAppToken);
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08002242 pw.print(" isAnimatingWithSavedSurface()=");
2243 pw.print(isAnimatingWithSavedSurface());
Chong Zhang112eb8c2015-11-02 11:17:00 -08002244 pw.print(" mAppDied=");pw.println(mAppDied);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002245 }
2246 if (mTargetAppToken != null) {
2247 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
2248 }
2249 pw.print(prefix); pw.print("mViewVisibility=0x");
2250 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002251 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
2252 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07002253 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
2254 pw.print(" mSystemUiVisibility=0x");
2255 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002256 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002257 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
2258 || mAttachedHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002259 pw.print(prefix); pw.print("mPolicyVisibility=");
2260 pw.print(mPolicyVisibility);
2261 pw.print(" mPolicyVisibilityAfterAnim=");
2262 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002263 pw.print(" mAppOpVisibility=");
2264 pw.print(mAppOpVisibility);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002265 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
2266 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08002267 if (!mRelayoutCalled || mLayoutNeeded) {
2268 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
2269 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002270 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002271 if (mXOffset != 0 || mYOffset != 0) {
2272 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
2273 pw.print(" y="); pw.println(mYOffset);
2274 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002275 if (dumpAll) {
2276 pw.print(prefix); pw.print("mGivenContentInsets=");
2277 mGivenContentInsets.printShortString(pw);
2278 pw.print(" mGivenVisibleInsets=");
2279 mGivenVisibleInsets.printShortString(pw);
2280 pw.println();
2281 if (mTouchableInsets != 0 || mGivenInsetsPending) {
2282 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
2283 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07002284 Region region = new Region();
2285 getTouchableRegion(region);
2286 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002287 }
2288 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Wale Ogunwale7c726682015-02-06 17:34:28 -08002289 if (mOverrideConfig != Configuration.EMPTY) {
2290 pw.print(prefix); pw.print("mOverrideConfig="); pw.println(mOverrideConfig);
2291 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002292 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07002293 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07002294 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Chong Zhanga8975bd2016-01-28 17:13:47 -08002295 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
2296 pw.print(" hasSavedSurface()="); pw.println(hasSavedSurface());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002297 if (dumpAll) {
2298 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
2299 pw.print(" last="); mLastFrame.printShortString(pw);
2300 pw.println();
2301 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002302 if (mEnforceSizeCompat) {
2303 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002304 pw.println();
2305 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002306 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002307 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002308 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002309 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002310 pw.println();
2311 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
2312 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002313 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002314 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002315 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002316 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04002317 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
2318 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002319 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
2320 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002321 pw.print(prefix); pw.print("Cur insets: overscan=");
2322 mOverscanInsets.printShortString(pw);
2323 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002324 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002325 pw.print(" stable="); mStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002326 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002327 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002328 pw.print(prefix); pw.print("Lst insets: overscan=");
2329 mLastOverscanInsets.printShortString(pw);
2330 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002331 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002332 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002333 pw.print(" physical="); mLastOutsets.printShortString(pw);
2334 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002335 pw.println();
2336 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07002337 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
2338 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002339 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
2340 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
2341 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
2342 pw.print(" mDestroying="); pw.print(mDestroying);
2343 pw.print(" mRemoved="); pw.println(mRemoved);
2344 }
2345 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
2346 pw.print(prefix); pw.print("mOrientationChanging=");
2347 pw.print(mOrientationChanging);
2348 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
2349 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
2350 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07002351 if (mLastFreezeDuration != 0) {
2352 pw.print(prefix); pw.print("mLastFreezeDuration=");
2353 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
2354 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002355 if (mHScale != 1 || mVScale != 1) {
2356 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
2357 pw.print(" mVScale="); pw.println(mVScale);
2358 }
2359 if (mWallpaperX != -1 || mWallpaperY != -1) {
2360 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
2361 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
2362 }
2363 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
2364 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
2365 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
2366 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07002367 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
2368 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
2369 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
2370 pw.print(mWallpaperDisplayOffsetX);
2371 pw.print(" mWallpaperDisplayOffsetY=");
2372 pw.println(mWallpaperDisplayOffsetY);
2373 }
Jeff Brownc2932a12014-11-20 18:04:05 -08002374 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07002375 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08002376 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08002377 if (isDragResizing()) {
2378 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
2379 }
2380 if (computeDragResizing()) {
2381 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
2382 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002383 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002384
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002385 String makeInputChannelName() {
2386 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002387 + " " + getWindowTag();
2388 }
2389
Robert Carra1eb4392015-12-10 12:43:51 -08002390 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002391 CharSequence tag = mAttrs.getTitle();
2392 if (tag == null || tag.length() <= 0) {
2393 tag = mAttrs.packageName;
2394 }
2395 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002396 }
2397
2398 @Override
2399 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002400 final CharSequence title = getWindowTag();
Dianne Hackbornc2293022013-02-06 23:14:49 -08002401 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mExiting) {
2402 mLastTitle = title;
Dianne Hackborn529e7442012-11-01 14:22:28 -07002403 mWasExiting = mExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002404 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -07002405 + " u" + UserHandle.getUserId(mSession.mUid)
Craig Mautnera987d432012-10-11 14:07:58 -07002406 + " " + mLastTitle + (mExiting ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002407 }
2408 return mStringNameCache;
2409 }
Robert Carr58f29132015-10-29 14:19:05 -07002410
2411 void transformFromScreenToSurfaceSpace(Rect rect) {
2412 if (mHScale >= 0) {
Chong Zhang84389572016-01-13 10:33:27 -08002413 rect.left = (int) (rect.left / mHScale);
2414 rect.right = (int) (rect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07002415 }
2416 if (mVScale >= 0) {
Chong Zhang84389572016-01-13 10:33:27 -08002417 rect.top = (int) (rect.top / mVScale);
2418 rect.bottom = (int) (rect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07002419 }
2420 }
Robert Carr31e28482015-12-02 16:53:18 -08002421
2422 void applyGravityAndUpdateFrame() {
2423 final int pw = mContainingFrame.width();
2424 final int ph = mContainingFrame.height();
2425 final Task task = getTask();
2426 final boolean nonFullscreenTask = task != null && !task.isFullscreen();
2427
2428 float x, y;
2429 int w,h;
2430
2431 if ((mAttrs.flags & FLAG_SCALED) != 0) {
2432 if (mAttrs.width < 0) {
2433 w = pw;
2434 } else if (mEnforceSizeCompat) {
2435 w = (int)(mAttrs.width * mGlobalScale + .5f);
2436 } else {
2437 w = mAttrs.width;
2438 }
2439 if (mAttrs.height < 0) {
2440 h = ph;
2441 } else if (mEnforceSizeCompat) {
2442 h = (int)(mAttrs.height * mGlobalScale + .5f);
2443 } else {
2444 h = mAttrs.height;
2445 }
2446 } else {
2447 if (mAttrs.width == MATCH_PARENT) {
2448 w = pw;
2449 } else if (mEnforceSizeCompat) {
2450 w = (int)(mRequestedWidth * mGlobalScale + .5f);
2451 } else {
2452 w = mRequestedWidth;
2453 }
2454 if (mAttrs.height == MATCH_PARENT) {
2455 h = ph;
2456 } else if (mEnforceSizeCompat) {
2457 h = (int)(mRequestedHeight * mGlobalScale + .5f);
2458 } else {
2459 h = mRequestedHeight;
2460 }
2461 }
2462
2463 if (mEnforceSizeCompat) {
2464 x = mAttrs.x * mGlobalScale;
2465 y = mAttrs.y * mGlobalScale;
2466 } else {
2467 x = mAttrs.x;
2468 y = mAttrs.y;
2469 }
2470
2471 if (nonFullscreenTask) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08002472 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08002473 // required by {@link Gravity#apply} call.
2474 w = Math.min(w, pw);
2475 h = Math.min(h, ph);
2476 }
2477
2478 // Set mFrame
2479 Gravity.apply(mAttrs.gravity, w, h, mContainingFrame,
2480 (int) (x + mAttrs.horizontalMargin * pw),
2481 (int) (y + mAttrs.verticalMargin * ph), mFrame);
2482
2483 // Now make sure the window fits in the overall display frame.
2484 Gravity.applyDisplay(mAttrs.gravity, mDisplayFrame, mFrame);
2485 }
Robert Carr51a1b872015-12-08 14:03:13 -08002486
2487 boolean isChildWindow() {
2488 return mAttachedWindow != null;
2489 }
Robert Carra1eb4392015-12-10 12:43:51 -08002490
2491 void setReplacing(boolean animate) {
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08002492 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
2493 || mAttrs.type == TYPE_APPLICATION_STARTING) {
2494 // We don't set replacing on starting windows since they are added by window manager and
2495 // not the client so won't be replaced by the client.
2496 return;
Robert Carra1eb4392015-12-10 12:43:51 -08002497 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08002498
2499 mWillReplaceWindow = true;
2500 mReplacingWindow = null;
2501 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08002502 }
Chong Zhangf596cd52016-01-05 13:42:44 -08002503
2504 void resetReplacing() {
2505 mWillReplaceWindow = false;
2506 mReplacingWindow = null;
2507 mAnimateReplacingWindow = false;
2508 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08002509
2510 float translateToWindowX(float x) {
2511 float winX = x - mFrame.left;
2512 if (mEnforceSizeCompat) {
2513 winX *= mGlobalScale;
2514 }
2515 return winX;
2516 }
2517
2518 float translateToWindowY(float y) {
2519 float winY = y - mFrame.top;
2520 if (mEnforceSizeCompat) {
2521 winY *= mGlobalScale;
2522 }
2523 return winY;
2524 }
satokcef37fb2011-10-24 21:49:38 +09002525}