blob: 733bc2993d90dc35c538d0320ec827d324478d7f [file] [log] [blame]
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Wale Ogunwale053c8e42015-11-16 14:27:21 -080019import com.android.server.input.InputWindowHandle;
20
21import android.app.ActivityManager;
22import android.app.AppOpsManager;
23import android.content.Context;
24import android.content.res.Configuration;
25import android.graphics.Matrix;
26import android.graphics.PixelFormat;
27import android.graphics.Point;
28import android.graphics.Rect;
29import android.graphics.Region;
30import android.os.IBinder;
31import android.os.PowerManager;
32import android.os.RemoteCallbackList;
33import android.os.RemoteException;
34import android.os.SystemClock;
35import android.os.Trace;
36import android.os.UserHandle;
37import android.os.WorkSource;
38import android.util.DisplayMetrics;
39import android.util.Slog;
40import android.util.TimeUtils;
41import android.view.Display;
42import android.view.DisplayInfo;
43import android.view.Gravity;
44import android.view.IApplicationToken;
45import android.view.IWindow;
46import android.view.IWindowFocusObserver;
47import android.view.IWindowId;
48import android.view.InputChannel;
49import android.view.InputEvent;
50import android.view.InputEventReceiver;
51import android.view.View;
52import android.view.ViewTreeObserver;
53import android.view.WindowManager;
54import android.view.WindowManagerPolicy;
55
56import java.io.PrintWriter;
57import java.util.ArrayList;
58
Wale Ogunwaled045c822015-12-02 09:14:28 -080059import static android.app.ActivityManager.StackId;
Wale Ogunwalecad05a02015-09-25 10:41:44 -070060import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080061import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
62import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
63import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
64import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080065import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080066import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070067import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080068import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080069import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
70import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080071import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070072import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080073import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080074import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
Robert Carr31e28482015-12-02 16:53:18 -080075import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080076import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Wale Ogunwale8216eb22015-12-18 10:42:42 -080077import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080078import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Robert Carra1eb4392015-12-10 12:43:51 -080079import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080080import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
81import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080082import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080083import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070084import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080085import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
86import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
87import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080088import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
89import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
90import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
91import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
92import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
93import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
94import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
95import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
96import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
97import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
98import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
99import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800100
Craig Mautner59c00972012-07-30 12:10:24 -0700101class WindowList extends ArrayList<WindowState> {
102}
103
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800104/**
105 * A window in the window manager.
106 */
Craig Mautnere32c3072012-03-12 15:25:35 -0700107final class WindowState implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800108 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800109
Skuhne81c524a2015-08-12 13:34:14 -0700110 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700111 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
112 // use hard-coded min sizes for now.
113 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
114 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700115
116 // The thickness of a window resize handle outside the window bounds on the free form workspace
117 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700118 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700119
Jorim Jaggidcf467c2015-11-05 13:59:32 +0100120 static final int DRAG_RESIZE_MODE_FREEFORM = 0;
121 static final int DRAG_RESIZE_MODE_DOCKED_DIVIDER = 1;
122
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800123 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700124 final WindowManagerPolicy mPolicy;
125 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800126 final Session mSession;
127 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800128 final int mAppOp;
129 // UserId and appId of the owner. Don't display windows of non-current user.
130 final int mOwnerUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800131 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800132 WindowToken mToken;
133 WindowToken mRootToken;
134 AppWindowToken mAppToken;
135 AppWindowToken mTargetAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700136
137 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
138 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800139 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
140 final DeathRecipient mDeathRecipient;
141 final WindowState mAttachedWindow;
Craig Mautner7b1aa772012-11-30 16:14:45 -0800142 final WindowList mChildWindows = new WindowList();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800143 final int mBaseLayer;
144 final int mSubLayer;
145 final boolean mLayoutAttached;
146 final boolean mIsImWindow;
147 final boolean mIsWallpaper;
148 final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700149 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700150 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800151 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700152 int mSystemUiVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800153 boolean mPolicyVisibility = true;
154 boolean mPolicyVisibilityAfterAnim = true;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -0800155 boolean mAppOpVisibility = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800156 boolean mAppFreezing;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800157 boolean mAttachedHidden; // is our parent window hidden?
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800158 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Chong Zhang0275e392015-09-17 10:41:44 -0700159 boolean mDragResizing;
Jorim Jaggidcf467c2015-11-05 13:59:32 +0100160 int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700161
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800162 RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
163
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700164 /**
165 * The window size that was requested by the application. These are in
166 * the application's coordinate space (without compatibility scale applied).
167 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800168 int mRequestedWidth;
169 int mRequestedHeight;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700170 int mLastRequestedWidth;
171 int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700172
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800173 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800174 boolean mHaveFrame;
175 boolean mObscured;
176 boolean mTurnOnScreen;
177
178 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700179
Wale Ogunwale60454db2015-01-23 16:05:07 -0800180 private Configuration mConfiguration = Configuration.EMPTY;
181 private Configuration mOverrideConfig = Configuration.EMPTY;
Craig Mautnere8552142012-11-07 13:55:47 -0800182 // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned.
183 // Used only on {@link #TYPE_KEYGUARD}.
184 private boolean mConfigHasChanged;
Craig Mautnera2c77052012-03-26 12:14:43 -0700185
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700186 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700187 * Actual position of the surface shown on-screen (may be modified by animation). These are
188 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700189 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700190 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800191
192 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700193 * Insets that determine the actually visible area. These are in the application's
194 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800195 */
196 final Rect mVisibleInsets = new Rect();
197 final Rect mLastVisibleInsets = new Rect();
198 boolean mVisibleInsetsChanged;
199
200 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700201 * Insets that are covered by system windows (such as the status bar) and
202 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700203 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800204 */
205 final Rect mContentInsets = new Rect();
206 final Rect mLastContentInsets = new Rect();
207 boolean mContentInsetsChanged;
208
209 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800210 * Insets that determine the area covered by the display overscan region. These are in the
211 * application's coordinate space (without compatibility scale applied).
212 */
213 final Rect mOverscanInsets = new Rect();
214 final Rect mLastOverscanInsets = new Rect();
215 boolean mOverscanInsetsChanged;
216
217 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700218 * Insets that determine the area covered by the stable system windows. These are in the
219 * application's coordinate space (without compatibility scale applied).
220 */
221 final Rect mStableInsets = new Rect();
222 final Rect mLastStableInsets = new Rect();
223 boolean mStableInsetsChanged;
224
225 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700226 * Outsets determine the area outside of the surface where we want to pretend that it's possible
227 * to draw anyway.
228 */
229 final Rect mOutsets = new Rect();
230 final Rect mLastOutsets = new Rect();
231 boolean mOutsetsChanged = false;
232
233 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800234 * Set to true if we are waiting for this window to receive its
235 * given internal insets before laying out other windows based on it.
236 */
237 boolean mGivenInsetsPending;
238
239 /**
240 * These are the content insets that were given during layout for
241 * this window, to be applied to windows behind it.
242 */
243 final Rect mGivenContentInsets = new Rect();
244
245 /**
246 * These are the visible insets that were given during layout for
247 * this window, to be applied to windows behind it.
248 */
249 final Rect mGivenVisibleInsets = new Rect();
250
251 /**
252 * This is the given touchable area relative to the window frame, or null if none.
253 */
254 final Region mGivenTouchableRegion = new Region();
255
256 /**
257 * Flag indicating whether the touchable region should be adjusted by
258 * the visible insets; if false the area outside the visible insets is
259 * NOT touchable, so we must use those to adjust the frame during hit
260 * tests.
261 */
262 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
263
264 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400265 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700266 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800267 float mHScale=1, mVScale=1;
268 float mLastHScale=1, mLastVScale=1;
269 final Matrix mTmpMatrix = new Matrix();
270
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700271 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800272 final Rect mFrame = new Rect();
273 final Rect mLastFrame = new Rect();
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700274 // Frame that is scaled to the application's coordinate space when in
275 // screen size compatibility mode.
276 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800277
278 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700279
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800280 final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700281
Wale Ogunwale94596652015-02-06 19:27:34 -0800282 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
283 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700284 final Rect mDisplayFrame = new Rect();
285
286 // The region of the display frame that the display type supports displaying content on. This
287 // is mostly a special case for TV where some displays don’t have the entire display usable.
288 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
289 // window display contents to extend into the overscan region.
290 final Rect mOverscanFrame = new Rect();
291
292 // The display frame minus the stable insets. This value is always constant regardless of if
293 // the status bar or navigation bar is visible.
Adrian Roosfa104232014-06-20 16:10:14 -0700294 final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800295
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700296 // The area not occupied by the status and navigation bars. So, if both status and navigation
297 // bars are visible, the decor frame is equal to the stable frame.
298 final Rect mDecorFrame = new Rect();
299
300 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
301 // minus the area occupied by the IME if the IME is present.
302 final Rect mContentFrame = new Rect();
303
304 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
305 // displays hint text.
306 final Rect mVisibleFrame = new Rect();
307
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700308 // Frame that includes dead area outside of the surface but where we want to pretend that it's
309 // possible to draw.
310 final Rect mOutsetFrame = new Rect();
311
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800312 boolean mContentChanged;
313
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800314 // If a window showing a wallpaper: the requested offset for the
315 // wallpaper; if a wallpaper window: the currently applied offset.
316 float mWallpaperX = -1;
317 float mWallpaperY = -1;
318
319 // If a window showing a wallpaper: what fraction of the offset
320 // range corresponds to a full virtual screen.
321 float mWallpaperXStep = -1;
322 float mWallpaperYStep = -1;
323
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700324 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
325 // to its window; if a wallpaper window: not used.
326 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
327 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
328
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800329 // Wallpaper windows: pixels offset based on above variables.
330 int mXOffset;
331 int mYOffset;
332
Craig Mautner2268e7e2012-12-13 15:40:00 -0800333 /**
334 * This is set after IWindowSession.relayout() has been called at
335 * least once for the window. It allows us to detect the situation
336 * where we don't yet have a surface, but should have one soon, so
337 * we can give the window focus before waiting for the relayout.
338 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800339 boolean mRelayoutCalled;
340
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800341 /**
342 * If the application has called relayout() with changes that can
343 * impact its window's size, we need to perform a layout pass on it
344 * even if it is not currently visible for layout. This is set
345 * when in that case until the layout is done.
346 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800347 boolean mLayoutNeeded;
348
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800349 /** Currently running an exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800350 boolean mExiting;
351
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800352 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800353 boolean mDestroying;
354
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800355 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800356 boolean mRemoveOnExit;
357
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800358 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800359 * Whether the app died while it was visible, if true we might need
360 * to continue to show it until it's restarted.
361 */
362 boolean mAppDied;
363
364 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800365 * Set when the orientation is changing and this window has not yet
366 * been updated for the new orientation.
367 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800368 boolean mOrientationChanging;
369
Dianne Hackborna57c6952013-03-29 14:46:40 -0700370 /**
371 * How long we last kept the screen frozen.
372 */
373 int mLastFreezeDuration;
374
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800375 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800376 boolean mRemoved;
377
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800378 /**
379 * Temp for keeping track of windows that have been removed when
380 * rebuilding window list.
381 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800382 boolean mRebuilding;
383
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800384 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700385 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800386 InputChannel mInputChannel;
Chong Zhang112eb8c2015-11-02 11:17:00 -0800387 InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800388
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800389 // Used to improve performance of toString()
390 String mStringNameCache;
391 CharSequence mLastTitle;
Dianne Hackborn529e7442012-11-01 14:22:28 -0700392 boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800393
Craig Mautnera2c77052012-03-26 12:14:43 -0700394 final WindowStateAnimator mWinAnimator;
395
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700396 boolean mHasSurface = false;
397
Craig Mautner19ab8282014-05-07 10:35:34 -0700398 boolean mNotOnAppsDisplay = false;
Craig Mautner59c00972012-07-30 12:10:24 -0700399 DisplayContent mDisplayContent;
Craig Mautner6881a102012-07-27 13:04:51 -0700400
Craig Mautner88400d32012-09-30 12:35:45 -0700401 /** When true this window can be displayed on screens owther than mOwnerUid's */
402 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700403
Robert Carr13f7be9e2015-12-02 18:39:45 -0800404 // Whether the window has a saved surface from last pause, which can be
405 // used to start an entering animation earlier.
406 public boolean mSurfaceSaved = false;
407
Robert Carra1eb4392015-12-10 12:43:51 -0800408 // This window will be replaced due to relaunch. This allows window manager
409 // to differentiate between simple removal of a window and replacement. In the latter case it
410 // will preserve the old window until the new one is drawn.
411 boolean mWillReplaceWindow = false;
412 // If true, the replaced window was already requested to be removed.
413 boolean mReplacingRemoveRequested = false;
414 // Whether the replacement of the window should trigger app transition animation.
415 boolean mAnimateReplacingWindow = false;
416 // If not null, the window that will be used to replace the old one. This is being set when
417 // the window is added and unset when this window reports its first draw.
418 WindowState mReplacingWindow = null;
419
Chong Zhangbd0d9372015-12-28 15:18:29 -0800420 // Whether this window is being moved via the resize API
421 boolean mMovedByResize;
Jeff Brownc2932a12014-11-20 18:04:05 -0800422 /**
423 * Wake lock for drawing.
424 * Even though it's slightly more expensive to do so, we will use a separate wake lock
425 * for each app that is requesting to draw while dozing so that we can accurately track
426 * who is preventing the system from suspending.
427 * This lock is only acquired on first use.
428 */
429 PowerManager.WakeLock mDrawLock;
430
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700431 final private Rect mTmpRect = new Rect();
432
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800433 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800434 WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a,
Craig Mautner59c00972012-07-30 12:10:24 -0700435 int viewVisibility, final DisplayContent displayContent) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800436 mService = service;
437 mSession = s;
438 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800439 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800440 mToken = token;
Craig Mautnera2d7b112012-08-21 15:12:20 -0700441 mOwnerUid = s.mUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800442 mWindowId = new IWindowId.Stub() {
443 @Override
444 public void registerFocusObserver(IWindowFocusObserver observer) {
445 WindowState.this.registerFocusObserver(observer);
446 }
447 @Override
448 public void unregisterFocusObserver(IWindowFocusObserver observer) {
449 WindowState.this.unregisterFocusObserver(observer);
450 }
451 @Override
452 public boolean isFocused() {
453 return WindowState.this.isFocused();
454 }
455 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800456 mAttrs.copyFrom(a);
457 mViewVisibility = viewVisibility;
Craig Mautner59c00972012-07-30 12:10:24 -0700458 mDisplayContent = displayContent;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700459 mPolicy = mService.mPolicy;
460 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800461 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700462 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700463 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800464 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700465 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700466 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800467 try {
468 c.asBinder().linkToDeath(deathRecipient, 0);
469 } catch (RemoteException e) {
470 mDeathRecipient = null;
471 mAttachedWindow = null;
472 mLayoutAttached = false;
473 mIsImWindow = false;
474 mIsWallpaper = false;
475 mIsFloatingLayer = false;
476 mBaseLayer = 0;
477 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700478 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700479 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800480 return;
481 }
482 mDeathRecipient = deathRecipient;
483
484 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
485 mAttrs.type <= LAST_SUB_WINDOW)) {
486 // The multiplier here is to reserve space for multiple
487 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700488 mBaseLayer = mPolicy.windowTypeToLayerLw(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800489 attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
490 + WindowManagerService.TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700491 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800492 mAttachedWindow = attachedWindow;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800493 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
takeda.masayuki18735092012-12-12 11:06:24 +0900494
tiger_huange2a98a72014-11-13 19:46:28 +0800495 final WindowList childWindows = mAttachedWindow.mChildWindows;
496 final int numChildWindows = childWindows.size();
497 if (numChildWindows == 0) {
498 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900499 } else {
tiger_huange2a98a72014-11-13 19:46:28 +0800500 boolean added = false;
501 for (int i = 0; i < numChildWindows; i++) {
502 final int childSubLayer = childWindows.get(i).mSubLayer;
503 if (mSubLayer < childSubLayer
504 || (mSubLayer == childSubLayer && childSubLayer < 0)) {
505 // We insert the child window into the list ordered by the sub-layer. For
506 // same sub-layers, the negative one should go below others; the positive
507 // one should go above others.
508 childWindows.add(i, this);
509 added = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900510 break;
takeda.masayuki18735092012-12-12 11:06:24 +0900511 }
512 }
tiger_huange2a98a72014-11-13 19:46:28 +0800513 if (!added) {
514 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900515 }
516 }
517
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800518 mLayoutAttached = mAttrs.type !=
519 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
520 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
521 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
522 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
523 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
524 } else {
525 // The multiplier here is to reserve space for multiple
526 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700527 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800528 * WindowManagerService.TYPE_LAYER_MULTIPLIER
529 + WindowManagerService.TYPE_LAYER_OFFSET;
530 mSubLayer = 0;
531 mAttachedWindow = null;
532 mLayoutAttached = false;
533 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
534 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
535 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
536 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
537 }
538
539 WindowState appWin = this;
Robert Carr51a1b872015-12-08 14:03:13 -0800540 while (appWin.isChildWindow()) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700541 appWin = appWin.mAttachedWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800542 }
543 WindowToken appToken = appWin.mToken;
544 while (appToken.appWindowToken == null) {
545 WindowToken parent = mService.mTokenMap.get(appToken.token);
546 if (parent == null || appToken == parent) {
547 break;
548 }
549 appToken = parent;
550 }
551 mRootToken = appToken;
552 mAppToken = appToken.appWindowToken;
Craig Mautner19ab8282014-05-07 10:35:34 -0700553 if (mAppToken != null) {
554 final DisplayContent appDisplay = getDisplayContent();
555 mNotOnAppsDisplay = displayContent != appDisplay;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700556
557 if (mAppToken.showForAllUsers) {
558 // Windows for apps that can show for all users should also show when the
559 // device is locked.
560 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
561 }
Craig Mautner19ab8282014-05-07 10:35:34 -0700562 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800563
Craig Mautner322e4032012-07-13 13:35:20 -0700564 mWinAnimator = new WindowStateAnimator(this);
565 mWinAnimator.mAlpha = a.alpha;
566
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800567 mRequestedWidth = 0;
568 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700569 mLastRequestedWidth = 0;
570 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800571 mXOffset = 0;
572 mYOffset = 0;
573 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800574 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700575 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
576 displayContent.getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800577 }
578
579 void attach() {
580 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700581 TAG, "Attaching " + this + " token=" + mToken
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800582 + ", list=" + mToken.windows);
583 mSession.windowAddedLocked();
584 }
585
Craig Mautnera2c77052012-03-26 12:14:43 -0700586 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800587 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800588 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800589 }
590
591 @Override
592 public String getOwningPackage() {
593 return mAttrs.packageName;
594 }
595
596 @Override
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700597 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf, Rect sf,
598 Rect osf) {
Robert Carra1eb4392015-12-10 12:43:51 -0800599 if (mWillReplaceWindow && (mExiting || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700600 // This window is being replaced and either already got information that it's being
601 // removed or we are still waiting for some information. Because of this we don't
602 // want to apply any more changes to it, so it remains in this state until new window
603 // appears.
604 return;
605 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800606 mHaveFrame = true;
607
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700608 final Task task = getTask();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800609 final boolean fullscreenTask = task == null || task.isFullscreen();
Chong Zhang09b21ef2015-09-14 10:20:21 -0700610 final boolean freeformWorkspace = task != null && task.inFreeformWorkspace();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800611
Wale Ogunwale8216eb22015-12-18 10:42:42 -0800612 if (fullscreenTask || (isChildWindow()
613 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0)) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800614 // We use the parent frame as the containing frame for fullscreen and child windows
615 mContainingFrame.set(pf);
616 mDisplayFrame.set(df);
617 } else {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700618 task.getBounds(mContainingFrame);
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800619 final WindowState imeWin = mService.mInputMethodWindow;
620 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this
621 && mContainingFrame.bottom > cf.bottom) {
622 // IME is up and obscuring this window. Adjust the window position so it is visible.
623 mContainingFrame.top -= mContainingFrame.bottom - cf.bottom;
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700624 }
Skuhne81c524a2015-08-12 13:34:14 -0700625
Skuhnef932e562015-08-20 12:07:30 -0700626 if (freeformWorkspace) {
Skuhne81c524a2015-08-12 13:34:14 -0700627 // In free form mode we have only to set the rectangle if it wasn't set already. No
628 // need to intersect it with the (visible) "content frame" since it is allowed to
629 // be outside the visible desktop.
630 if (mContainingFrame.isEmpty()) {
631 mContainingFrame.set(cf);
632 }
Doris Liu06d582d2015-06-01 13:18:43 -0700633 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800634 mDisplayFrame.set(mContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700635 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800636
Craig Mautner967212c2013-04-13 21:10:58 -0700637 final int pw = mContainingFrame.width();
638 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800639
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800640 if (!mParentFrame.equals(pf)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800641 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800642 // + " to " + pf);
643 mParentFrame.set(pf);
644 mContentChanged = true;
645 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700646 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
647 mLastRequestedWidth = mRequestedWidth;
648 mLastRequestedHeight = mRequestedHeight;
649 mContentChanged = true;
650 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800651
Craig Mautnereda67292013-04-28 13:50:14 -0700652 mOverscanFrame.set(of);
653 mContentFrame.set(cf);
654 mVisibleFrame.set(vf);
John Spurlock46646232013-09-30 22:32:42 -0400655 mDecorFrame.set(dcf);
Adrian Roosfa104232014-06-20 16:10:14 -0700656 mStableFrame.set(sf);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700657 final boolean hasOutsets = osf != null;
658 if (hasOutsets) {
659 mOutsetFrame.set(osf);
660 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800661
Craig Mautnereda67292013-04-28 13:50:14 -0700662 final int fw = mFrame.width();
663 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800664
Robert Carr31e28482015-12-02 16:53:18 -0800665 applyGravityAndUpdateFrame();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800666
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700667 // Calculate the outsets before the content frame gets shrinked to the window frame.
668 if (hasOutsets) {
669 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
670 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
671 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
672 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
673 } else {
674 mOutsets.set(0, 0, 0, 0);
675 }
676
Craig Mautnera248eee2013-05-07 11:41:27 -0700677 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800678 // final window frame.
Skuhnef932e562015-08-20 12:07:30 -0700679 if (freeformWorkspace && !mFrame.isEmpty()) {
Skuhne81c524a2015-08-12 13:34:14 -0700680 // Keep the frame out of the blocked system area, limit it in size to the content area
681 // and make sure that there is always a minimum visible so that the user can drag it
682 // into a usable area..
683 final int height = Math.min(mFrame.height(), mContentFrame.height());
684 final int width = Math.min(mContentFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700685 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700686 final int minVisibleHeight = WindowManagerService.dipToPixel(
687 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics);
688 final int minVisibleWidth = WindowManagerService.dipToPixel(
689 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics);
Skuhne81c524a2015-08-12 13:34:14 -0700690 final int top = Math.max(mContentFrame.top,
691 Math.min(mFrame.top, mContentFrame.bottom - minVisibleHeight));
692 final int left = Math.max(mContentFrame.left + minVisibleWidth - width,
693 Math.min(mFrame.left, mContentFrame.right - minVisibleWidth));
694 mFrame.set(left, top, left + width, top + height);
695 mContentFrame.set(mFrame);
696 mVisibleFrame.set(mContentFrame);
697 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700698 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800699 if (isVisibleLw() || mWinAnimator.isAnimating()) {
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800700 // We don't adjust the dock divider frame for reasons other than performance. The
701 // real reason is that if it gets adjusted before it is shown for the first time,
702 // it would get size (0, 0). This causes a problem when we finally show the dock
703 // divider and try to draw to it. We do set the surface size at that moment to
704 // the correct size, but it's too late for the Surface Flinger to make it
705 // available for view rendering and as a result the renderer receives size 1, 1.
706 // This way we just keep the divider at the original size and Surface Flinger
707 // will return the correct value to the renderer.
708 mDisplayContent.getDockedDividerController().positionDockedStackedDivider(mFrame);
709 mContentFrame.set(mFrame);
710 }
Skuhne81c524a2015-08-12 13:34:14 -0700711 } else {
712 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
713 Math.max(mContentFrame.top, mFrame.top),
714 Math.min(mContentFrame.right, mFrame.right),
715 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800716
Skuhne81c524a2015-08-12 13:34:14 -0700717 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
718 Math.max(mVisibleFrame.top, mFrame.top),
719 Math.min(mVisibleFrame.right, mFrame.right),
720 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800721
Skuhne81c524a2015-08-12 13:34:14 -0700722 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
723 Math.max(mStableFrame.top, mFrame.top),
724 Math.min(mStableFrame.right, mFrame.right),
725 Math.min(mStableFrame.bottom, mFrame.bottom));
726 }
Adrian Roosfa104232014-06-20 16:10:14 -0700727
Craig Mautnerc36c8e62013-05-10 13:33:31 -0700728 mOverscanInsets.set(Math.max(mOverscanFrame.left - mFrame.left, 0),
729 Math.max(mOverscanFrame.top - mFrame.top, 0),
Adrian Roos3236f3a2014-12-09 15:06:40 +0000730 Math.max(mFrame.right - mOverscanFrame.right, 0),
731 Math.max(mFrame.bottom - mOverscanFrame.bottom, 0));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800732
Craig Mautnereda67292013-04-28 13:50:14 -0700733 mContentInsets.set(mContentFrame.left - mFrame.left,
734 mContentFrame.top - mFrame.top,
735 mFrame.right - mContentFrame.right,
736 mFrame.bottom - mContentFrame.bottom);
737
738 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
739 mVisibleFrame.top - mFrame.top,
740 mFrame.right - mVisibleFrame.right,
741 mFrame.bottom - mVisibleFrame.bottom);
742
Adrian Roosfa104232014-06-20 16:10:14 -0700743 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
744 Math.max(mStableFrame.top - mFrame.top, 0),
745 Math.max(mFrame.right - mStableFrame.right, 0),
746 Math.max(mFrame.bottom - mStableFrame.bottom, 0));
747
Craig Mautnereda67292013-04-28 13:50:14 -0700748 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400749 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700750 // If there is a size compatibility scale being applied to the
751 // window, we need to apply this to its insets so that they are
752 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700753 mOverscanInsets.scale(mInvGlobalScale);
754 mContentInsets.scale(mInvGlobalScale);
755 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700756 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700757 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700758
759 // Also the scaled frame that we report to the app needs to be
760 // adjusted to be in its coordinate space.
761 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400762 }
763
Craig Mautnereda67292013-04-28 13:50:14 -0700764 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800765 final DisplayContent displayContent = getDisplayContent();
766 if (displayContent != null) {
767 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700768 mService.mWallpaperControllerLocked.updateWallpaperOffset(
769 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800770 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800771 }
772
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700773 if (DEBUG_LAYOUT || WindowManagerService.localLOGV) Slog.v(TAG,
774 "Resolving (mRequestedWidth="
775 + mRequestedWidth + ", mRequestedheight="
776 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
777 + "): frame=" + mFrame.toShortString()
778 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -0700779 + " vi=" + mVisibleInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700780 + " vi=" + mStableInsets.toShortString()
781 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800782 }
783
Craig Mautnera2c77052012-03-26 12:14:43 -0700784 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800785 public Rect getFrameLw() {
786 return mFrame;
787 }
788
Craig Mautnera2c77052012-03-26 12:14:43 -0700789 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700790 public Point getShownPositionLw() {
791 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800792 }
793
Craig Mautnera2c77052012-03-26 12:14:43 -0700794 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800795 public Rect getDisplayFrameLw() {
796 return mDisplayFrame;
797 }
798
Craig Mautnera2c77052012-03-26 12:14:43 -0700799 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800800 public Rect getOverscanFrameLw() {
801 return mOverscanFrame;
802 }
803
804 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800805 public Rect getContentFrameLw() {
806 return mContentFrame;
807 }
808
Craig Mautnera2c77052012-03-26 12:14:43 -0700809 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800810 public Rect getVisibleFrameLw() {
811 return mVisibleFrame;
812 }
813
Craig Mautnera2c77052012-03-26 12:14:43 -0700814 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800815 public boolean getGivenInsetsPendingLw() {
816 return mGivenInsetsPending;
817 }
818
Craig Mautnera2c77052012-03-26 12:14:43 -0700819 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800820 public Rect getGivenContentInsetsLw() {
821 return mGivenContentInsets;
822 }
823
Craig Mautnera2c77052012-03-26 12:14:43 -0700824 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800825 public Rect getGivenVisibleInsetsLw() {
826 return mGivenVisibleInsets;
827 }
828
Craig Mautnera2c77052012-03-26 12:14:43 -0700829 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800830 public WindowManager.LayoutParams getAttrs() {
831 return mAttrs;
832 }
833
Craig Mautner812d2ca2012-09-27 15:35:34 -0700834 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800835 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
836 int index = -1;
837 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -0700838 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800839 while (true) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -0700840 if (ws.mAttrs.needsMenuKey != WindowManager.LayoutParams.NEEDS_MENU_UNSET) {
841 return ws.mAttrs.needsMenuKey == WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800842 }
843 // If we reached the bottom of the range of windows we are considering,
844 // assume no menu is needed.
845 if (ws == bottom) {
846 return false;
847 }
848 // The current window hasn't specified whether menu key is needed;
849 // look behind it.
850 // First, we may need to determine the starting position.
851 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -0700852 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800853 }
854 index--;
855 if (index < 0) {
856 return false;
857 }
Craig Mautner59c00972012-07-30 12:10:24 -0700858 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800859 }
860 }
861
Craig Mautner19d59bc2012-09-04 11:15:56 -0700862 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700863 public int getSystemUiVisibility() {
864 return mSystemUiVisibility;
865 }
866
Craig Mautner19d59bc2012-09-04 11:15:56 -0700867 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800868 public int getSurfaceLayer() {
869 return mLayer;
870 }
871
Craig Mautner812d2ca2012-09-27 15:35:34 -0700872 @Override
Selim Cinekd6623612015-05-22 18:56:22 -0700873 public int getBaseType() {
874 WindowState win = this;
Robert Carr51a1b872015-12-08 14:03:13 -0800875 while (win.isChildWindow()) {
Selim Cinekd6623612015-05-22 18:56:22 -0700876 win = win.mAttachedWindow;
877 }
878 return win.mAttrs.type;
879 }
880
881 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800882 public IApplicationToken getAppToken() {
883 return mAppToken != null ? mAppToken.appToken : null;
884 }
Craig Mautner19d59bc2012-09-04 11:15:56 -0700885
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700886 @Override
887 public boolean isVoiceInteraction() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700888 return mAppToken != null && mAppToken.voiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700889 }
890
Craig Mautner4c5eb222013-11-18 12:59:05 -0800891 boolean setInsetsChanged() {
892 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
893 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
894 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -0700895 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700896 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
897 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
898 || mOutsetsChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -0800899 }
900
Craig Mautnerdf88d732014-01-27 09:21:32 -0800901 public DisplayContent getDisplayContent() {
Chad Jonesf391ebc2014-06-12 17:45:05 -0700902 if (mAppToken == null || mNotOnAppsDisplay) {
Craig Mautnerbe634952014-06-12 13:39:24 -0700903 return mDisplayContent;
904 }
905 final TaskStack stack = getStack();
906 return stack == null ? mDisplayContent : stack.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -0800907 }
908
Chong Zhang09b21ef2015-09-14 10:20:21 -0700909 public DisplayInfo getDisplayInfo() {
910 final DisplayContent displayContent = getDisplayContent();
911 return displayContent != null ? displayContent.getDisplayInfo() : null;
912 }
913
Craig Mautner19d59bc2012-09-04 11:15:56 -0700914 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800915 final DisplayContent displayContent = getDisplayContent();
916 if (displayContent == null) {
917 return -1;
918 }
919 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -0700920 }
921
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700922 Task getTask() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700923 return mAppToken != null ? mAppToken.mTask : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700924 }
925
926 TaskStack getStack() {
927 Task task = getTask();
928 if (task != null) {
929 if (task.mStack != null) {
930 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -0700931 }
Craig Mautnerd9a22882013-03-16 15:00:36 -0700932 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700933 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
934 // associate them with some stack to enable dimming.
935 return mAttrs.type >= WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
936 && mDisplayContent != null ? mDisplayContent.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -0700937 }
938
Skuhnef932e562015-08-20 12:07:30 -0700939 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700940 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -0700941 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -0700942 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800943 void getVisibleBounds(Rect bounds) {
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700944 boolean intersectWithStackBounds = mAppToken != null && mAppToken.mCropWindowsToStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700945 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700946 mTmpRect.setEmpty();
947 if (intersectWithStackBounds) {
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700948 final TaskStack stack = getStack();
949 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800950 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700951 } else {
952 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700953 }
954 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700955
Chong Zhang9184ec62015-09-24 12:32:21 -0700956 bounds.set(mVisibleFrame);
957 if (intersectWithStackBounds) {
958 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700959 }
960
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700961 if (bounds.isEmpty()) {
962 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700963 if (intersectWithStackBounds) {
964 bounds.intersect(mTmpRect);
965 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800966 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700967 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700968 }
969
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800970 public long getInputDispatchingTimeoutNanos() {
971 return mAppToken != null
972 ? mAppToken.inputDispatchingTimeoutNanos
973 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
974 }
975
Craig Mautnere8552142012-11-07 13:55:47 -0800976 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800977 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -0700978 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800979 }
980
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800981 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
982 if (dsdx < .99999f || dsdx > 1.00001f) return false;
983 if (dtdy < .99999f || dtdy > 1.00001f) return false;
984 if (dtdx < -.000001f || dtdx > .000001f) return false;
985 if (dsdy < -.000001f || dsdy > .000001f) return false;
986 return true;
987 }
988
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400989 void prelayout() {
990 if (mEnforceSizeCompat) {
991 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700992 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400993 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700994 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400995 }
996 }
997
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800998 /**
999 * Is this window visible? It is not visible if there is no
1000 * surface, or we are in the process of running an exit animation
1001 * that will remove the surface, or its app token has been hidden.
1002 */
Craig Mautner88400d32012-09-30 12:35:45 -07001003 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001004 public boolean isVisibleLw() {
1005 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001006 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001007 && (atoken == null || !atoken.hiddenRequested)
1008 && !mExiting && !mDestroying;
1009 }
1010
1011 /**
1012 * Like {@link #isVisibleLw}, but also counts a window that is currently
1013 * "hidden" behind the keyguard as visible. This allows us to apply
1014 * things like window flags that impact the keyguard.
1015 * XXX I am starting to think we need to have ANOTHER visibility flag
1016 * for this "hidden behind keyguard" state rather than overloading
1017 * mPolicyVisibility. Ungh.
1018 */
Craig Mautner88400d32012-09-30 12:35:45 -07001019 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001020 public boolean isVisibleOrBehindKeyguardLw() {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001021 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -08001022 mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001023 return false;
1024 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001025 final AppWindowToken atoken = mAppToken;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001026 final boolean animating = atoken != null && atoken.mAppAnimator.animation != null;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001027 return mHasSurface && !mDestroying && !mExiting
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001028 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001029 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
1030 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001031 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001032 }
1033
1034 /**
1035 * Is this window visible, ignoring its app token? It is not visible
1036 * if there is no surface, or we are in the process of running an exit animation
1037 * that will remove the surface.
1038 */
1039 public boolean isWinVisibleLw() {
1040 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001041 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautner59431632012-04-04 11:56:44 -07001042 && (atoken == null || !atoken.hiddenRequested || atoken.mAppAnimator.animating)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001043 && !mExiting && !mDestroying;
1044 }
1045
1046 /**
1047 * The same as isVisible(), but follows the current hidden state of
1048 * the associated app token, not the pending requested hidden state.
1049 */
1050 boolean isVisibleNow() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001051 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07001052 && (!mRootToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
1053 && !mExiting && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001054 }
1055
1056 /**
1057 * Can this window possibly be a drag/drop target? The test here is
1058 * a combination of the above "visible now" with the check that the
1059 * Input Manager uses when discarding windows from input consideration.
1060 */
1061 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001062 return isVisibleNow() && !mRemoved
1063 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001064 }
1065
1066 /**
1067 * Same as isVisible(), but we also count it as visible between the
1068 * call to IWindowSession.add() and the first relayout().
1069 */
1070 boolean isVisibleOrAdding() {
1071 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001072 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001073 && mPolicyVisibility && !mAttachedHidden
1074 && (atoken == null || !atoken.hiddenRequested)
1075 && !mExiting && !mDestroying;
1076 }
1077
1078 /**
1079 * Is this window currently on-screen? It is on-screen either if it
1080 * is visible or it is currently running an animation before no longer
1081 * being visible.
1082 */
1083 boolean isOnScreen() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001084 return mPolicyVisibility && isOnScreenIgnoringKeyguard();
1085 }
1086
1087 /**
1088 * Like isOnScreen(), but ignores any force hiding of the window due
1089 * to the keyguard.
1090 */
1091 boolean isOnScreenIgnoringKeyguard() {
1092 if (!mHasSurface || mDestroying) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001093 return false;
1094 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001095 final AppWindowToken atoken = mAppToken;
1096 if (atoken != null) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001097 return ((!mAttachedHidden && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001098 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001099 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001100 return !mAttachedHidden || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001101 }
1102
1103 /**
1104 * Like isOnScreen(), but we don't return true if the window is part
1105 * of a transition that has not yet been started.
1106 */
1107 boolean isReadyForDisplay() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001108 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001109 return false;
1110 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001111 return mHasSurface && mPolicyVisibility && !mDestroying
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001112 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
1113 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001114 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001115 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001116 }
1117
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001118 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001119 * Like isReadyForDisplay(), but ignores any force hiding of the window due
1120 * to the keyguard.
1121 */
1122 boolean isReadyForDisplayIgnoringKeyguard() {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001123 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001124 return false;
1125 }
1126 final AppWindowToken atoken = mAppToken;
1127 if (atoken == null && !mPolicyVisibility) {
1128 // If this is not an app window, and the policy has asked to force
1129 // hide, then we really do want to hide.
1130 return false;
1131 }
1132 return mHasSurface && !mDestroying
1133 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
1134 && !mRootToken.hidden)
1135 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -07001136 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
1137 && !mWinAnimator.isDummyAnimation()));
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001138 }
1139
1140 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001141 * Like isOnScreen, but returns false if the surface hasn't yet
1142 * been drawn.
1143 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001144 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001145 public boolean isDisplayedLw() {
1146 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001147 return isDrawnLw() && mPolicyVisibility
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001148 && ((!mAttachedHidden &&
1149 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001150 || mWinAnimator.mAnimating
1151 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001152 }
1153
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001154 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001155 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001156 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001157 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001158 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001159 return mWinAnimator.mAnimation != null
1160 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001161 }
1162
Craig Mautner812d2ca2012-09-27 15:35:34 -07001163 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001164 public boolean isGoneForLayoutLw() {
1165 final AppWindowToken atoken = mAppToken;
1166 return mViewVisibility == View.GONE
1167 || !mRelayoutCalled
1168 || (atoken == null && mRootToken.hidden)
Craig Mautner812d2ca2012-09-27 15:35:34 -07001169 || (atoken != null && (atoken.hiddenRequested || atoken.hidden))
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001170 || mAttachedHidden
Craig Mautner0e415c62013-04-29 16:10:58 -07001171 || (mExiting && !isAnimatingLw())
1172 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001173 }
1174
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001175 /**
1176 * Returns true if the window has a surface that it has drawn a
1177 * complete UI in to.
1178 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001179 public boolean isDrawFinishedLw() {
1180 return mHasSurface && !mDestroying &&
1181 (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING
1182 || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1183 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
1184 }
1185
1186 /**
1187 * Returns true if the window has a surface that it has drawn a
1188 * complete UI in to.
1189 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001190 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001191 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001192 return mHasSurface && !mDestroying &&
Craig Mautner749a7bb2012-04-02 13:49:53 -07001193 (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1194 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001195 }
1196
1197 /**
1198 * Return true if the window is opaque and fully drawn. This indicates
1199 * it may obscure windows behind it.
1200 */
1201 boolean isOpaqueDrawn() {
1202 return (mAttrs.format == PixelFormat.OPAQUE
1203 || mAttrs.type == TYPE_WALLPAPER)
Craig Mautnera2c77052012-03-26 12:14:43 -07001204 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001205 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001206 }
1207
1208 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001209 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001210 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1211 */
Craig Mautner4557c082015-04-27 13:07:40 -07001212 boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001213 return mHasSurface && (mContentChanged || mMovedByResize)
1214 && !mExiting && !mWinAnimator.mLastHidden && mService.okToDisplay()
1215 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Craig Mautner4557c082015-04-27 13:07:40 -07001216 && (mAttachedWindow == null || !mAttachedWindow.hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001217 }
1218
Chong Zhang0abb20f2015-11-19 14:17:31 -08001219 boolean isObscuringFullscreen(final DisplayInfo displayInfo) {
1220 Task task = getTask();
1221 if (task != null && task.mStack != null && !task.mStack.isFullscreen()) {
1222 return false;
1223 }
1224 if (!isOpaqueDrawn() || !isFrameFullscreen(displayInfo)) {
1225 return false;
1226 }
1227 return true;
1228 }
1229
1230 boolean isFrameFullscreen(final DisplayInfo displayInfo) {
1231 return mFrame.left <= 0 && mFrame.top <= 0
1232 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001233 }
1234
Craig Mautner812d2ca2012-09-27 15:35:34 -07001235 boolean isConfigChanged() {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001236 final Task task = getTask();
Wale Ogunwale60454db2015-01-23 16:05:07 -08001237 final Configuration overrideConfig =
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001238 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001239 final Configuration serviceConfig = mService.mCurConfiguration;
1240 boolean configChanged =
1241 (mConfiguration != serviceConfig && mConfiguration.diff(serviceConfig) != 0)
1242 || (mOverrideConfig != overrideConfig && !mOverrideConfig.equals(overrideConfig));
Craig Mautnere8552142012-11-07 13:55:47 -08001243
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001244 if ((mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Craig Mautnere8552142012-11-07 13:55:47 -08001245 // Retain configuration changed status until resetConfiguration called.
1246 mConfigHasChanged |= configChanged;
1247 configChanged = mConfigHasChanged;
1248 }
1249
1250 return configChanged;
Craig Mautner812d2ca2012-09-27 15:35:34 -07001251 }
1252
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001253 void removeLocked() {
1254 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001255
Robert Carr51a1b872015-12-08 14:03:13 -08001256 if (isChildWindow()) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001257 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001258 mAttachedWindow.mChildWindows.remove(this);
1259 }
Craig Mautner96868332012-12-04 14:29:11 -08001260 mWinAnimator.destroyDeferredSurfaceLocked();
1261 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001262 mSession.windowRemovedLocked();
1263 try {
1264 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1265 } catch (RuntimeException e) {
1266 // Ignore if it has already been removed (usually because
1267 // we are doing this as part of processing a death note.)
1268 }
1269 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001270
Wale Ogunwale60454db2015-01-23 16:05:07 -08001271 private void setConfiguration(
1272 final Configuration newConfig, final Configuration newOverrideConfig) {
Craig Mautnere8552142012-11-07 13:55:47 -08001273 mConfiguration = newConfig;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001274 mOverrideConfig = newOverrideConfig;
Craig Mautnere8552142012-11-07 13:55:47 -08001275 mConfigHasChanged = false;
1276 }
1277
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001278 void setHasSurface(boolean hasSurface) {
1279 mHasSurface = hasSurface;
1280 }
1281
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001282 int getAnimLayerAdjustment() {
1283 if (mTargetAppToken != null) {
1284 return mTargetAppToken.mAppAnimator.animLayerAdjustment;
1285 } else if (mAppToken != null) {
1286 return mAppToken.mAppAnimator.animLayerAdjustment;
1287 } else {
1288 // Nothing is animating, so there is no animation adjustment.
1289 return 0;
1290 }
1291 }
1292
1293 void scheduleAnimationIfDimming() {
1294 if (mDisplayContent == null) {
1295 return;
1296 }
1297 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1298 if (dimLayerUser != null && mDisplayContent.mDimLayerController.isDimming(
1299 dimLayerUser, mWinAnimator)) {
1300 // Force an animation pass just to update the mDimLayer layer.
1301 mService.scheduleAnimationLocked();
1302 }
1303 }
1304
Chong Zhangacf11402015-11-04 16:23:10 -08001305 private final class DeadWindowEventReceiver extends InputEventReceiver {
1306 DeadWindowEventReceiver(InputChannel inputChannel) {
1307 super(inputChannel, mService.mH.getLooper());
1308 }
1309 @Override
1310 public void onInputEvent(InputEvent event) {
1311 finishInputEvent(event, true);
1312 }
1313 }
1314 /**
1315 * Dummy event receiver for windows that died visible.
1316 */
1317 private DeadWindowEventReceiver mDeadWindowEventReceiver;
1318
Chong Zhang112eb8c2015-11-02 11:17:00 -08001319 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001320 if (mInputChannel != null) {
1321 throw new IllegalStateException("Window already has an input channel.");
1322 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001323 String name = makeInputChannelName();
1324 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1325 mInputChannel = inputChannels[0];
1326 mClientChannel = inputChannels[1];
1327 mInputWindowHandle.inputChannel = inputChannels[0];
1328 if (outInputChannel != null) {
1329 mClientChannel.transferTo(outInputChannel);
1330 mClientChannel.dispose();
1331 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08001332 } else {
1333 // If the window died visible, we setup a dummy input channel, so that taps
1334 // can still detected by input monitor channel, and we can relaunch the app.
1335 // Create dummy event receiver that simply reports all events as handled.
1336 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08001337 }
1338 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001339 }
1340
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001341 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08001342 if (mDeadWindowEventReceiver != null) {
1343 mDeadWindowEventReceiver.dispose();
1344 mDeadWindowEventReceiver = null;
1345 }
1346
1347 // unregister server channel first otherwise it complains about broken channel
1348 if (mInputChannel != null) {
1349 mService.mInputManager.unregisterInputChannel(mInputChannel);
1350 mInputChannel.dispose();
1351 mInputChannel = null;
1352 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001353 if (mClientChannel != null) {
1354 mClientChannel.dispose();
1355 mClientChannel = null;
1356 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001357 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001358 }
1359
Chong Zhang112eb8c2015-11-02 11:17:00 -08001360 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08001361 // When the app is terminated (eg. from Recents), the task might have already been
1362 // removed with the window pending removal. Don't apply dim in such cases, as there
1363 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
1364 final AppWindowToken token = mAppToken;
1365 if (token != null && token.removed) {
1366 return;
1367 }
1368
Chong Zhang112eb8c2015-11-02 11:17:00 -08001369 if (!mExiting && mAppDied) {
1370 // If app died visible, apply a dim over the window to indicate that it's inactive
1371 mDisplayContent.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
1372 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
1373 && mDisplayContent != null && !mExiting && isDisplayedLw()) {
1374 mDisplayContent.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001375 }
1376 }
1377
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001378 DimLayer.DimLayerUser getDimLayerUser() {
1379 Task task = getTask();
1380 if (task != null) {
1381 return task;
1382 }
1383 return getStack();
1384 }
1385
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001386 void maybeRemoveReplacedWindow() {
Robert Carra1eb4392015-12-10 12:43:51 -08001387 if (mAppToken == null) {
1388 return;
1389 }
1390 for (int i = mAppToken.allAppWindows.size() - 1; i >= 0; i--) {
1391 final WindowState win = mAppToken.allAppWindows.get(i);
1392 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + win);
1393 if (win.mWillReplaceWindow && win.mReplacingWindow == this) {
1394 win.mWillReplaceWindow = false;
1395 win.mAnimateReplacingWindow = false;
1396 win.mReplacingRemoveRequested = false;
1397 win.mReplacingWindow = null;
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001398 if (win.mExiting) {
1399 mService.removeWindowInnerLocked(win);
1400 }
1401 }
1402 }
1403 }
1404
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07001405 void setDisplayLayoutNeeded() {
1406 if (mDisplayContent != null) {
1407 mDisplayContent.layoutNeeded = true;
1408 }
1409 }
1410
Filip Gruszczynski955b2fc2015-10-15 14:46:07 -07001411 boolean inDockedWorkspace() {
Chong Zhangb15758a2015-11-17 12:12:03 -08001412 Task task = getTask();
1413 return task != null && task.inDockedWorkspace();
1414 }
1415
1416 boolean isDockedInEffect() {
1417 Task task = getTask();
1418 return task != null && task.isDockedInEffect();
Filip Gruszczynski955b2fc2015-10-15 14:46:07 -07001419 }
1420
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001421 int getTouchableRegion(Region region, int flags) {
1422 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001423 if (modal && mAppToken != null) {
1424 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001425 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001426 // If this is a modal window we need to dismiss it if it's not full screen and the
1427 // touch happens outside of the frame that displays the content. This means we
1428 // need to intercept touches outside of that window. The dim layer user
1429 // associated with the window (task or stack) will give us the good bounds, as
1430 // they would be used to display the dim layer.
1431 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1432 if (dimLayerUser != null) {
1433 dimLayerUser.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001434 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001435 getVisibleBounds(mTmpRect);
1436 }
1437 if (inFreeformWorkspace()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001438 // For freeform windows we the touch region to include the whole surface for the
1439 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001440 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
1441 final int delta = WindowManagerService.dipToPixel(
1442 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
1443 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001444 }
1445 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001446 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001447 } else {
1448 // Not modal or full screen modal
1449 getTouchableRegion(region);
1450 }
1451 return flags;
1452 }
1453
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001454 void checkPolicyVisibilityChange() {
1455 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
1456 if (DEBUG_VISIBILITY) {
1457 Slog.v(TAG, "Policy visibility changing after anim in " +
1458 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
1459 }
1460 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001461 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001462 if (!mPolicyVisibility) {
1463 if (mService.mCurrentFocus == this) {
1464 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
1465 "setAnimationLocked: setting mFocusMayChange true");
1466 mService.mFocusMayChange = true;
1467 }
1468 // Window is no longer visible -- make sure if we were waiting
1469 // for it to be displayed before enabling the display, that
1470 // we allow the display to be enabled now.
1471 mService.enableScreenIfNeededLocked();
1472 }
1473 }
1474 }
1475
1476 void setRequestedSize(int requestedWidth, int requestedHeight) {
1477 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
1478 mLayoutNeeded = true;
1479 mRequestedWidth = requestedWidth;
1480 mRequestedHeight = requestedHeight;
1481 }
1482 }
1483
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001484 void prepareWindowToDisplayDuringRelayout(Configuration outConfig) {
1485 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
1486 == SOFT_INPUT_ADJUST_RESIZE) {
1487 mLayoutNeeded = true;
1488 }
1489 if (isDrawnLw() && mService.okToDisplay()) {
1490 mWinAnimator.applyEnterAnimationLocked();
1491 }
1492 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
1493 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
1494 mTurnOnScreen = true;
1495 }
1496 if (isConfigChanged()) {
1497 if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + this + " visible with new config: "
1498 + mService.mCurConfiguration);
1499 outConfig.setTo(mService.mCurConfiguration);
1500 }
1501 }
1502
1503 void adjustStartingWindowFlags() {
1504 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
1505 && mAppToken.startingWindow != null) {
1506 // Special handling of starting window over the base
1507 // window of the app: propagate lock screen flags to it,
1508 // to provide the correct semantics while starting.
1509 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
1510 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
1511 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
1512 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
1513 }
1514 }
1515
1516 void setWindowScale(int requestedWidth, int requestedHeight) {
1517 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
1518
1519 if (scaledWindow) {
1520 // requested{Width|Height} Surface's physical size
1521 // attrs.{width|height} Size on screen
1522 // TODO: We don't check if attrs != null here. Is it implicitly checked?
1523 mHScale = (mAttrs.width != requestedWidth) ?
1524 (mAttrs.width / (float)requestedWidth) : 1.0f;
1525 mVScale = (mAttrs.height != requestedHeight) ?
1526 (mAttrs.height / (float)requestedHeight) : 1.0f;
1527 } else {
1528 mHScale = mVScale = 1;
1529 }
1530 }
1531
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001532 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08001533 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001534 public void binderDied() {
1535 try {
1536 synchronized(mService.mWindowMap) {
1537 WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07001538 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001539 if (win != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001540 if (win.mAppToken != null && !win.mAppToken.clientHidden) {
1541 win.mAppToken.appDied = true;
1542 }
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001543 mService.removeWindowLocked(win);
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001544 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08001545 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001546 mService.removeWindowLocked(WindowState.this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001547 }
1548 }
1549 } catch (IllegalArgumentException ex) {
1550 // This will happen if the window has already been
1551 // removed.
1552 }
1553 }
1554 }
1555
Wale Ogunwaled045c822015-12-02 09:14:28 -08001556 /** @return true if this window desires key events. */
1557 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08001558 return isVisibleOrAdding()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001559 && (mViewVisibility == View.VISIBLE)
Wale Ogunwaled045c822015-12-02 09:14:28 -08001560 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
1561 && stackCanReceiveKeys();
1562 }
1563
1564 boolean stackCanReceiveKeys() {
1565 final TaskStack stack = getStack();
1566 return stack != null && StackId.canReceiveKeys(stack.mStackId);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001567 }
1568
Craig Mautner749a7bb2012-04-02 13:49:53 -07001569 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001570 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001571 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001572 }
1573
Craig Mautner749a7bb2012-04-02 13:49:53 -07001574 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001575 public boolean showLw(boolean doAnimation) {
1576 return showLw(doAnimation, true);
1577 }
1578
1579 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07001580 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001581 return false;
1582 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001583 if (!mAppOpVisibility) {
1584 // Being hidden due to app op request.
1585 return false;
1586 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001587 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001588 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001589 return false;
1590 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001591 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001592 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001593 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07001594 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07001595 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001596 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07001597 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001598 // Check for the case where we are currently visible and
1599 // not animating; we do not want to do animation at such a
1600 // point to become visible when we already are.
1601 doAnimation = false;
1602 }
1603 }
1604 mPolicyVisibility = true;
1605 mPolicyVisibilityAfterAnim = true;
1606 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001607 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001608 }
1609 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001610 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001611 }
1612 return true;
1613 }
1614
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001615 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001616 public boolean hideLw(boolean doAnimation) {
1617 return hideLw(doAnimation, true);
1618 }
1619
1620 boolean hideLw(boolean doAnimation, boolean requestAnim) {
1621 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07001622 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001623 doAnimation = false;
1624 }
1625 }
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001626 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
1627 : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001628 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001629 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001630 return false;
1631 }
1632 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001633 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07001634 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001635 doAnimation = false;
1636 }
1637 }
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001638 if (doAnimation) {
1639 mPolicyVisibilityAfterAnim = false;
1640 } else {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001641 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001642 mPolicyVisibilityAfterAnim = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001643 mPolicyVisibility = false;
1644 // Window is no longer visible -- make sure if we were waiting
1645 // for it to be displayed before enabling the display, that
1646 // we allow the display to be enabled now.
1647 mService.enableScreenIfNeededLocked();
1648 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001649 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07001650 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001651 mService.mFocusMayChange = true;
1652 }
1653 }
1654 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001655 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001656 }
1657 return true;
1658 }
1659
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001660 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001661 if (mAppOpVisibility != state) {
1662 mAppOpVisibility = state;
1663 if (state) {
1664 // If the policy visibility had last been to hide, then this
1665 // will incorrectly show at this point since we lost that
1666 // information. Not a big deal -- for the windows that have app
1667 // ops modifies they should only be hidden by policy due to the
1668 // lock screen, and the user won't be changing this if locked.
1669 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001670 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001671 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001672 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001673 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001674 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001675 }
1676
Jeff Brownc2932a12014-11-20 18:04:05 -08001677 public void pokeDrawLockLw(long timeout) {
1678 if (isVisibleOrAdding()) {
1679 if (mDrawLock == null) {
1680 // We want the tag name to be somewhat stable so that it is easier to correlate
1681 // in wake lock statistics. So in particular, we don't want to include the
1682 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001683 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08001684 mDrawLock = mService.mPowerManager.newWakeLock(
1685 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
1686 mDrawLock.setReferenceCounted(false);
1687 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
1688 }
1689 // Each call to acquire resets the timeout.
1690 if (DEBUG_POWER) {
1691 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
1692 + mAttrs.packageName);
1693 }
1694 mDrawLock.acquire(timeout);
1695 } else if (DEBUG_POWER) {
1696 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
1697 + "owned by " + mAttrs.packageName);
1698 }
1699 }
1700
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001701 @Override
1702 public boolean isAlive() {
1703 return mClient.asBinder().isBinderAlive();
1704 }
1705
Craig Mautnera987d432012-10-11 14:07:58 -07001706 boolean isClosing() {
1707 return mExiting || (mService.mClosingApps.contains(mAppToken));
1708 }
1709
Chong Zhangbef461f2015-10-27 11:38:24 -07001710 boolean isAnimatingWithSavedSurface() {
1711 return mAppToken != null && mAppToken.mAnimatingWithSavedSurface;
1712 }
1713
Robert Carr13f7be9e2015-12-02 18:39:45 -08001714 // Returns true if the surface is saved.
1715 boolean destroyOrSaveSurface() {
1716 Task task = getTask();
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001717 if (ActivityManager.isLowRamDeviceStatic()) {
1718 // Don't save surfaces on Svelte devices.
Robert Carr13f7be9e2015-12-02 18:39:45 -08001719 mSurfaceSaved = false;
1720 } else if (task == null || task.inHomeStack()
Chong Zhangd8ceb852015-11-11 14:53:41 -08001721 || task.getTopVisibleAppToken() != mAppToken) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001722 // Don't save surfaces for home stack apps. These usually resume and draw
1723 // first frame very fast. Saving surfaces are mostly a waste of memory.
Chong Zhangbef461f2015-10-27 11:38:24 -07001724 // Don't save if the window is not the topmost window.
Robert Carr13f7be9e2015-12-02 18:39:45 -08001725 mSurfaceSaved = false;
Robert Carr51a1b872015-12-08 14:03:13 -08001726 } else if (isChildWindow()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -08001727 mSurfaceSaved = false;
1728 } else {
1729 mSurfaceSaved = mAppToken.shouldSaveSurface();
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001730 }
Robert Carr13f7be9e2015-12-02 18:39:45 -08001731 if (mSurfaceSaved == false) {
1732 mWinAnimator.destroySurfaceLocked();
1733 }
1734 return mSurfaceSaved;
1735 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001736
Robert Carr13f7be9e2015-12-02 18:39:45 -08001737 public void destroySavedSurface() {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001738 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, "Destroying saved surface: " + this);
Robert Carr13f7be9e2015-12-02 18:39:45 -08001739 if (mSurfaceSaved) {
1740 mWinAnimator.destroySurfaceLocked();
1741 }
1742 }
1743
1744 public boolean hasSavedSurface() {
1745 return mSurfaceSaved;
1746 }
1747
1748 public void restoreSavedSurface() {
1749 mSurfaceSaved = false;
1750 mWinAnimator.mDrawState = WindowStateAnimator.READY_TO_SHOW;
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001751 }
1752
Craig Mautner69b08182012-09-05 13:07:13 -07001753 @Override
1754 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001755 final DisplayContent displayContent = getDisplayContent();
1756 if (displayContent == null) {
1757 // Only a window that was on a non-default display can be detached from it.
1758 return false;
1759 }
Winson Chung47a3e652014-05-21 16:03:42 -07001760 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07001761 }
1762
Adrian Rooscd3884d2015-02-18 17:25:23 +01001763 @Override
1764 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001765 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1766 return dimLayerUser != null && mDisplayContent != null &&
Chong Zhang112eb8c2015-11-02 11:17:00 -08001767 mDisplayContent.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01001768 }
1769
Craig Mautner88400d32012-09-30 12:35:45 -07001770 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
1771 mShowToOwnerOnly = showToOwnerOnly;
1772 }
1773
Craig Mautner5962b122012-10-05 14:45:52 -07001774 boolean isHiddenFromUserLocked() {
Craig Mautner341220f2012-10-16 15:20:09 -07001775 // Attached windows are evaluated based on the window that they are attached to.
1776 WindowState win = this;
Robert Carr51a1b872015-12-08 14:03:13 -08001777 while (win.isChildWindow()) {
Craig Mautner341220f2012-10-16 15:20:09 -07001778 win = win.mAttachedWindow;
1779 }
1780 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -07001781 && win.mAppToken != null && win.mAppToken.showForAllUsers) {
Craig Mautner341220f2012-10-16 15:20:09 -07001782 // Save some cycles by not calling getDisplayInfo unless it is an application
1783 // window intended for all users.
Craig Mautnerdf88d732014-01-27 09:21:32 -08001784 final DisplayContent displayContent = win.getDisplayContent();
1785 if (displayContent == null) {
1786 return true;
1787 }
1788 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Craig Mautner341220f2012-10-16 15:20:09 -07001789 if (win.mFrame.left <= 0 && win.mFrame.top <= 0
1790 && win.mFrame.right >= displayInfo.appWidth
1791 && win.mFrame.bottom >= displayInfo.appHeight) {
Craig Mautner5962b122012-10-05 14:45:52 -07001792 // Is a fullscreen window, like the clock alarm. Show to everyone.
1793 return false;
1794 }
1795 }
1796
Craig Mautner341220f2012-10-16 15:20:09 -07001797 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01001798 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001799 }
1800
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001801 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
1802 outRegion.set(
1803 frame.left + inset.left, frame.top + inset.top,
1804 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001805 }
1806
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001807 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001808 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001809 switch (mTouchableInsets) {
1810 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001811 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001812 outRegion.set(frame);
1813 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001814 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001815 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001816 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001817 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001818 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001819 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001820 case TOUCHABLE_INSETS_REGION: {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001821 final Region givenTouchableRegion = mGivenTouchableRegion;
1822 outRegion.set(givenTouchableRegion);
1823 outRegion.translate(frame.left, frame.top);
1824 break;
1825 }
1826 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001827 cropRegionToStackBoundsIfNeeded(outRegion);
1828 }
1829
1830 void cropRegionToStackBoundsIfNeeded(Region region) {
1831 if (mAppToken == null || !mAppToken.mCropWindowsToStack) {
1832 return;
1833 }
1834
1835 final TaskStack stack = getStack();
1836 if (stack == null) {
1837 return;
1838 }
1839
1840 stack.getDimBounds(mTmpRect);
1841 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001842 }
1843
Craig Mautner59c00972012-07-30 12:10:24 -07001844 WindowList getWindowList() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001845 final DisplayContent displayContent = getDisplayContent();
1846 return displayContent == null ? null : displayContent.getWindowList();
Craig Mautner59c00972012-07-30 12:10:24 -07001847 }
1848
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001849 /**
1850 * Report a focus change. Must be called with no locks held, and consistently
1851 * from the same serialized thread (such as dispatched from a handler).
1852 */
1853 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
1854 try {
1855 mClient.windowFocusChanged(focused, inTouchMode);
1856 } catch (RemoteException e) {
1857 }
1858 if (mFocusCallbacks != null) {
1859 final int N = mFocusCallbacks.beginBroadcast();
1860 for (int i=0; i<N; i++) {
1861 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
1862 try {
1863 if (focused) {
1864 obs.focusGained(mWindowId.asBinder());
1865 } else {
1866 obs.focusLost(mWindowId.asBinder());
1867 }
1868 } catch (RemoteException e) {
1869 }
1870 }
1871 mFocusCallbacks.finishBroadcast();
1872 }
1873 }
1874
Craig Mautnerdf88d732014-01-27 09:21:32 -08001875 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001876 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08001877 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001878 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
1879 + ": " + mCompatFrame);
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001880 final boolean configChanged = isConfigChanged();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001881 final Task task = getTask();
Wale Ogunwale60454db2015-01-23 16:05:07 -08001882 final Configuration overrideConfig =
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001883 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001884 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) && configChanged) {
1885 Slog.i(TAG, "Sending new config to window " + this + ": "
Robert Carre6a83512015-11-03 16:09:21 -08001886 + " / config="
Wale Ogunwale60454db2015-01-23 16:05:07 -08001887 + mService.mCurConfiguration + " overrideConfig=" + overrideConfig);
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001888 }
Wale Ogunwale60454db2015-01-23 16:05:07 -08001889 setConfiguration(mService.mCurConfiguration, overrideConfig);
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001890 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING)
1891 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
1892
Craig Mautnerdf88d732014-01-27 09:21:32 -08001893 final Rect frame = mFrame;
1894 final Rect overscanInsets = mLastOverscanInsets;
1895 final Rect contentInsets = mLastContentInsets;
1896 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07001897 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001898 final Rect outsets = mLastOutsets;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001899 final boolean reportDraw = mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING;
1900 final Configuration newConfig = configChanged ? mConfiguration : null;
Chet Haase8eb48d22014-09-24 07:31:29 -07001901 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1902 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001903 // To prevent deadlock simulate one-way call if win.mClient is a local object.
1904 mService.mH.post(new Runnable() {
1905 @Override
1906 public void run() {
1907 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001908 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
1909 stableInsets, outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001910 } catch (RemoteException e) {
1911 // Not a remote call, RemoteException won't be raised.
1912 }
1913 }
1914 });
1915 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001916 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001917 outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001918 }
Svetoslav4604abc2014-06-10 18:59:30 -07001919
1920 //TODO (multidisplay): Accessibility supported only for the default display.
1921 if (mService.mAccessibilityController != null
1922 && getDisplayId() == Display.DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07001923 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07001924 }
1925
Craig Mautnerdf88d732014-01-27 09:21:32 -08001926 mOverscanInsetsChanged = false;
1927 mContentInsetsChanged = false;
1928 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07001929 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001930 mOutsetsChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001931 mWinAnimator.mSurfaceResized = false;
1932 } catch (RemoteException e) {
1933 mOrientationChanging = false;
1934 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1935 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08001936 // We are assuming the hosting process is dead or in a zombie state.
1937 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
1938 + ", removing this window.");
1939 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001940 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001941 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001942 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001943 }
1944
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001945 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
1946 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
1947 Configuration newConfig) throws RemoteException {
1948 DisplayInfo displayInfo = getDisplayInfo();
1949 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Chong Zhangd153c4f2015-11-06 20:26:40 -08001950 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
1951 // start even if we haven't received the relayout window, so that the client requests
1952 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
1953 // until the window to small size, otherwise the multithread renderer will shift last
1954 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
1955 // isDragResizing() or isDragResizeChanged() is true.
1956 boolean resizing = isDragResizing() || isDragResizeChanged();
1957 final Rect backDropFrame = (inFreeformWorkspace() || !resizing) ? frame : mTmpRect;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001958 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Chong Zhangd153c4f2015-11-06 20:26:40 -08001959 outsets, reportDraw, newConfig, backDropFrame);
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001960 }
1961
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001962 public void registerFocusObserver(IWindowFocusObserver observer) {
1963 synchronized(mService.mWindowMap) {
1964 if (mFocusCallbacks == null) {
1965 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
1966 }
1967 mFocusCallbacks.register(observer);
1968 }
1969 }
1970
1971 public void unregisterFocusObserver(IWindowFocusObserver observer) {
1972 synchronized(mService.mWindowMap) {
1973 if (mFocusCallbacks != null) {
1974 mFocusCallbacks.unregister(observer);
1975 }
1976 }
1977 }
1978
1979 public boolean isFocused() {
1980 synchronized(mService.mWindowMap) {
1981 return mService.mCurrentFocus == this;
1982 }
1983 }
1984
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07001985 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07001986 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07001987 return task != null && task.inFreeformWorkspace();
1988 }
1989
Chong Zhang3005e752015-09-18 18:46:28 -07001990 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07001991 return mDragResizing != computeDragResizing();
1992 }
1993
Jorim Jaggidcf467c2015-11-05 13:59:32 +01001994 int getResizeMode() {
1995 return mResizeMode;
1996 }
1997
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07001998 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07001999 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002000 if (task == null) {
2001 return false;
2002 }
2003 if (task.isDragResizing()) {
2004 return true;
2005 }
2006 return mDisplayContent.mDividerControllerLocked.isResizing() &&
2007 !task.inFreeformWorkspace() && !task.isFullscreen();
Chong Zhang3005e752015-09-18 18:46:28 -07002008 }
2009
2010 void setDragResizing() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002011 mDragResizing = computeDragResizing();
Jorim Jaggidcf467c2015-11-05 13:59:32 +01002012 mResizeMode = mDragResizing && mDisplayContent.mDividerControllerLocked.isResizing()
2013 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
2014 : DRAG_RESIZE_MODE_FREEFORM;
Chong Zhang3005e752015-09-18 18:46:28 -07002015 }
2016
2017 boolean isDragResizing() {
2018 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07002019 }
2020
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002021 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08002022 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002023 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08002024 if (stack != null) {
2025 pw.print(" stackId="); pw.print(stack.mStackId);
2026 }
Craig Mautner59c00972012-07-30 12:10:24 -07002027 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002028 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07002029 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08002030 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
2031 pw.print(" package="); pw.print(mAttrs.packageName);
2032 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002033 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002034 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
2035 pw.print(" h="); pw.print(mRequestedHeight);
2036 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07002037 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
2038 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
2039 pw.print(" h="); pw.println(mLastRequestedHeight);
2040 }
Robert Carr51a1b872015-12-08 14:03:13 -08002041 if (isChildWindow() || mLayoutAttached) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002042 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
2043 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
2044 }
2045 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
2046 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
2047 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
2048 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
2049 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
2050 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002051 if (dumpAll) {
2052 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
2053 pw.print(" mSubLayer="); pw.print(mSubLayer);
2054 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautner59431632012-04-04 11:56:44 -07002055 pw.print((mTargetAppToken != null ?
2056 mTargetAppToken.mAppAnimator.animLayerAdjustment
2057 : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002058 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
2059 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08002060 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002061 if (dumpAll) {
2062 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
2063 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
2064 if (mAppToken != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08002065 pw.print(prefix); pw.print("mAppToken="); pw.print(mAppToken);
2066 pw.print(" mAppDied=");pw.println(mAppDied);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002067 }
2068 if (mTargetAppToken != null) {
2069 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
2070 }
2071 pw.print(prefix); pw.print("mViewVisibility=0x");
2072 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002073 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
2074 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07002075 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
2076 pw.print(" mSystemUiVisibility=0x");
2077 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002078 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002079 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
2080 || mAttachedHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002081 pw.print(prefix); pw.print("mPolicyVisibility=");
2082 pw.print(mPolicyVisibility);
2083 pw.print(" mPolicyVisibilityAfterAnim=");
2084 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002085 pw.print(" mAppOpVisibility=");
2086 pw.print(mAppOpVisibility);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002087 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
2088 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08002089 if (!mRelayoutCalled || mLayoutNeeded) {
2090 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
2091 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002092 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002093 if (mXOffset != 0 || mYOffset != 0) {
2094 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
2095 pw.print(" y="); pw.println(mYOffset);
2096 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002097 if (dumpAll) {
2098 pw.print(prefix); pw.print("mGivenContentInsets=");
2099 mGivenContentInsets.printShortString(pw);
2100 pw.print(" mGivenVisibleInsets=");
2101 mGivenVisibleInsets.printShortString(pw);
2102 pw.println();
2103 if (mTouchableInsets != 0 || mGivenInsetsPending) {
2104 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
2105 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07002106 Region region = new Region();
2107 getTouchableRegion(region);
2108 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002109 }
2110 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Wale Ogunwale7c726682015-02-06 17:34:28 -08002111 if (mOverrideConfig != Configuration.EMPTY) {
2112 pw.print(prefix); pw.print("mOverrideConfig="); pw.println(mOverrideConfig);
2113 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002114 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07002115 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07002116 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Craig Mautner178af592012-09-17 10:37:29 -07002117 pw.print(" isReadyForDisplay()="); pw.println(isReadyForDisplay());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002118 if (dumpAll) {
2119 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
2120 pw.print(" last="); mLastFrame.printShortString(pw);
2121 pw.println();
2122 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002123 if (mEnforceSizeCompat) {
2124 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002125 pw.println();
2126 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002127 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002128 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002129 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002130 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002131 pw.println();
2132 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
2133 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002134 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002135 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002136 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002137 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04002138 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
2139 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002140 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
2141 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002142 pw.print(prefix); pw.print("Cur insets: overscan=");
2143 mOverscanInsets.printShortString(pw);
2144 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002145 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002146 pw.print(" stable="); mStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002147 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002148 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002149 pw.print(prefix); pw.print("Lst insets: overscan=");
2150 mLastOverscanInsets.printShortString(pw);
2151 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002152 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002153 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002154 pw.print(" physical="); mLastOutsets.printShortString(pw);
2155 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002156 pw.println();
2157 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07002158 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
2159 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002160 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
2161 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
2162 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
2163 pw.print(" mDestroying="); pw.print(mDestroying);
2164 pw.print(" mRemoved="); pw.println(mRemoved);
2165 }
2166 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
2167 pw.print(prefix); pw.print("mOrientationChanging=");
2168 pw.print(mOrientationChanging);
2169 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
2170 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
2171 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07002172 if (mLastFreezeDuration != 0) {
2173 pw.print(prefix); pw.print("mLastFreezeDuration=");
2174 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
2175 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002176 if (mHScale != 1 || mVScale != 1) {
2177 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
2178 pw.print(" mVScale="); pw.println(mVScale);
2179 }
2180 if (mWallpaperX != -1 || mWallpaperY != -1) {
2181 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
2182 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
2183 }
2184 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
2185 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
2186 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
2187 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07002188 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
2189 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
2190 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
2191 pw.print(mWallpaperDisplayOffsetX);
2192 pw.print(" mWallpaperDisplayOffsetY=");
2193 pw.println(mWallpaperDisplayOffsetY);
2194 }
Jeff Brownc2932a12014-11-20 18:04:05 -08002195 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07002196 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08002197 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002198 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002199
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002200 String makeInputChannelName() {
2201 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002202 + " " + getWindowTag();
2203 }
2204
Robert Carra1eb4392015-12-10 12:43:51 -08002205 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002206 CharSequence tag = mAttrs.getTitle();
2207 if (tag == null || tag.length() <= 0) {
2208 tag = mAttrs.packageName;
2209 }
2210 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002211 }
2212
2213 @Override
2214 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002215 final CharSequence title = getWindowTag();
Dianne Hackbornc2293022013-02-06 23:14:49 -08002216 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mExiting) {
2217 mLastTitle = title;
Dianne Hackborn529e7442012-11-01 14:22:28 -07002218 mWasExiting = mExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002219 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -07002220 + " u" + UserHandle.getUserId(mSession.mUid)
Craig Mautnera987d432012-10-11 14:07:58 -07002221 + " " + mLastTitle + (mExiting ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002222 }
2223 return mStringNameCache;
2224 }
Robert Carr58f29132015-10-29 14:19:05 -07002225
2226 void transformFromScreenToSurfaceSpace(Rect rect) {
2227 if (mHScale >= 0) {
2228 rect.right = rect.left + (int)((rect.right - rect.left) / mHScale);
2229 }
2230 if (mVScale >= 0) {
2231 rect.bottom = rect.top + (int)((rect.bottom - rect.top) / mVScale);
2232 }
2233 }
Robert Carr31e28482015-12-02 16:53:18 -08002234
2235 void applyGravityAndUpdateFrame() {
2236 final int pw = mContainingFrame.width();
2237 final int ph = mContainingFrame.height();
2238 final Task task = getTask();
2239 final boolean nonFullscreenTask = task != null && !task.isFullscreen();
2240
2241 float x, y;
2242 int w,h;
2243
2244 if ((mAttrs.flags & FLAG_SCALED) != 0) {
2245 if (mAttrs.width < 0) {
2246 w = pw;
2247 } else if (mEnforceSizeCompat) {
2248 w = (int)(mAttrs.width * mGlobalScale + .5f);
2249 } else {
2250 w = mAttrs.width;
2251 }
2252 if (mAttrs.height < 0) {
2253 h = ph;
2254 } else if (mEnforceSizeCompat) {
2255 h = (int)(mAttrs.height * mGlobalScale + .5f);
2256 } else {
2257 h = mAttrs.height;
2258 }
2259 } else {
2260 if (mAttrs.width == MATCH_PARENT) {
2261 w = pw;
2262 } else if (mEnforceSizeCompat) {
2263 w = (int)(mRequestedWidth * mGlobalScale + .5f);
2264 } else {
2265 w = mRequestedWidth;
2266 }
2267 if (mAttrs.height == MATCH_PARENT) {
2268 h = ph;
2269 } else if (mEnforceSizeCompat) {
2270 h = (int)(mRequestedHeight * mGlobalScale + .5f);
2271 } else {
2272 h = mRequestedHeight;
2273 }
2274 }
2275
2276 if (mEnforceSizeCompat) {
2277 x = mAttrs.x * mGlobalScale;
2278 y = mAttrs.y * mGlobalScale;
2279 } else {
2280 x = mAttrs.x;
2281 y = mAttrs.y;
2282 }
2283
2284 if (nonFullscreenTask) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08002285 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08002286 // required by {@link Gravity#apply} call.
2287 w = Math.min(w, pw);
2288 h = Math.min(h, ph);
2289 }
2290
2291 // Set mFrame
2292 Gravity.apply(mAttrs.gravity, w, h, mContainingFrame,
2293 (int) (x + mAttrs.horizontalMargin * pw),
2294 (int) (y + mAttrs.verticalMargin * ph), mFrame);
2295
2296 // Now make sure the window fits in the overall display frame.
2297 Gravity.applyDisplay(mAttrs.gravity, mDisplayFrame, mFrame);
2298 }
Robert Carr51a1b872015-12-08 14:03:13 -08002299
2300 boolean isChildWindow() {
2301 return mAttachedWindow != null;
2302 }
Robert Carra1eb4392015-12-10 12:43:51 -08002303
2304 void setReplacing(boolean animate) {
2305 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) == 0) {
2306 mWillReplaceWindow = true;
2307 mReplacingWindow = null;
2308 mAnimateReplacingWindow = animate;
2309 }
2310 }
satokcef37fb2011-10-24 21:49:38 +09002311}