blob: e4a6806621ffd095b9f76d7e574b47d4cfee34d5 [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 Ogunwalef9c81492015-02-25 18:06:17 -080077import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Robert Carra1eb4392015-12-10 12:43:51 -080078import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080079import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
80import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080081import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080082import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070083import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080084import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
85import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
86import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080087import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
88import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
89import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
90import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
91import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
92import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
93import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
94import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
95import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
96import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
97import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
98import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -080099
Craig Mautner59c00972012-07-30 12:10:24 -0700100class WindowList extends ArrayList<WindowState> {
101}
102
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800103/**
104 * A window in the window manager.
105 */
Craig Mautnere32c3072012-03-12 15:25:35 -0700106final class WindowState implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800107 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800108
Skuhne81c524a2015-08-12 13:34:14 -0700109 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700110 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
111 // use hard-coded min sizes for now.
112 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
113 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700114
115 // The thickness of a window resize handle outside the window bounds on the free form workspace
116 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700117 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700118
Jorim Jaggidcf467c2015-11-05 13:59:32 +0100119 static final int DRAG_RESIZE_MODE_FREEFORM = 0;
120 static final int DRAG_RESIZE_MODE_DOCKED_DIVIDER = 1;
121
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800122 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700123 final WindowManagerPolicy mPolicy;
124 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800125 final Session mSession;
126 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800127 final int mAppOp;
128 // UserId and appId of the owner. Don't display windows of non-current user.
129 final int mOwnerUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800130 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800131 WindowToken mToken;
132 WindowToken mRootToken;
133 AppWindowToken mAppToken;
134 AppWindowToken mTargetAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700135
136 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
137 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800138 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
139 final DeathRecipient mDeathRecipient;
140 final WindowState mAttachedWindow;
Craig Mautner7b1aa772012-11-30 16:14:45 -0800141 final WindowList mChildWindows = new WindowList();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800142 final int mBaseLayer;
143 final int mSubLayer;
144 final boolean mLayoutAttached;
145 final boolean mIsImWindow;
146 final boolean mIsWallpaper;
147 final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700148 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700149 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800150 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700151 int mSystemUiVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800152 boolean mPolicyVisibility = true;
153 boolean mPolicyVisibilityAfterAnim = true;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -0800154 boolean mAppOpVisibility = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800155 boolean mAppFreezing;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800156 boolean mAttachedHidden; // is our parent window hidden?
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800157 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Chong Zhang0275e392015-09-17 10:41:44 -0700158 boolean mDragResizing;
Jorim Jaggidcf467c2015-11-05 13:59:32 +0100159 int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700160
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800161 RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
162
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700163 /**
164 * The window size that was requested by the application. These are in
165 * the application's coordinate space (without compatibility scale applied).
166 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800167 int mRequestedWidth;
168 int mRequestedHeight;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700169 int mLastRequestedWidth;
170 int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700171
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800172 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800173 boolean mHaveFrame;
174 boolean mObscured;
175 boolean mTurnOnScreen;
176
177 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700178
Wale Ogunwale60454db2015-01-23 16:05:07 -0800179 private Configuration mConfiguration = Configuration.EMPTY;
180 private Configuration mOverrideConfig = Configuration.EMPTY;
Craig Mautnere8552142012-11-07 13:55:47 -0800181 // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned.
182 // Used only on {@link #TYPE_KEYGUARD}.
183 private boolean mConfigHasChanged;
Craig Mautnera2c77052012-03-26 12:14:43 -0700184
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700185 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700186 * Actual position of the surface shown on-screen (may be modified by animation). These are
187 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700188 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700189 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800190
191 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700192 * Insets that determine the actually visible area. These are in the application's
193 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800194 */
195 final Rect mVisibleInsets = new Rect();
196 final Rect mLastVisibleInsets = new Rect();
197 boolean mVisibleInsetsChanged;
198
199 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700200 * Insets that are covered by system windows (such as the status bar) and
201 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700202 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800203 */
204 final Rect mContentInsets = new Rect();
205 final Rect mLastContentInsets = new Rect();
206 boolean mContentInsetsChanged;
207
208 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800209 * Insets that determine the area covered by the display overscan region. These are in the
210 * application's coordinate space (without compatibility scale applied).
211 */
212 final Rect mOverscanInsets = new Rect();
213 final Rect mLastOverscanInsets = new Rect();
214 boolean mOverscanInsetsChanged;
215
216 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700217 * Insets that determine the area covered by the stable system windows. These are in the
218 * application's coordinate space (without compatibility scale applied).
219 */
220 final Rect mStableInsets = new Rect();
221 final Rect mLastStableInsets = new Rect();
222 boolean mStableInsetsChanged;
223
224 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700225 * Outsets determine the area outside of the surface where we want to pretend that it's possible
226 * to draw anyway.
227 */
228 final Rect mOutsets = new Rect();
229 final Rect mLastOutsets = new Rect();
230 boolean mOutsetsChanged = false;
231
232 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800233 * Set to true if we are waiting for this window to receive its
234 * given internal insets before laying out other windows based on it.
235 */
236 boolean mGivenInsetsPending;
237
238 /**
239 * These are the content insets that were given during layout for
240 * this window, to be applied to windows behind it.
241 */
242 final Rect mGivenContentInsets = new Rect();
243
244 /**
245 * These are the visible insets that were given during layout for
246 * this window, to be applied to windows behind it.
247 */
248 final Rect mGivenVisibleInsets = new Rect();
249
250 /**
251 * This is the given touchable area relative to the window frame, or null if none.
252 */
253 final Region mGivenTouchableRegion = new Region();
254
255 /**
256 * Flag indicating whether the touchable region should be adjusted by
257 * the visible insets; if false the area outside the visible insets is
258 * NOT touchable, so we must use those to adjust the frame during hit
259 * tests.
260 */
261 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
262
263 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400264 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700265 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800266 float mHScale=1, mVScale=1;
267 float mLastHScale=1, mLastVScale=1;
268 final Matrix mTmpMatrix = new Matrix();
269
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700270 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800271 final Rect mFrame = new Rect();
272 final Rect mLastFrame = new Rect();
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700273 // Frame that is scaled to the application's coordinate space when in
274 // screen size compatibility mode.
275 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800276
277 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700278
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800279 final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700280
Wale Ogunwale94596652015-02-06 19:27:34 -0800281 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
282 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700283 final Rect mDisplayFrame = new Rect();
284
285 // The region of the display frame that the display type supports displaying content on. This
286 // is mostly a special case for TV where some displays don’t have the entire display usable.
287 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
288 // window display contents to extend into the overscan region.
289 final Rect mOverscanFrame = new Rect();
290
291 // The display frame minus the stable insets. This value is always constant regardless of if
292 // the status bar or navigation bar is visible.
Adrian Roosfa104232014-06-20 16:10:14 -0700293 final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800294
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700295 // The area not occupied by the status and navigation bars. So, if both status and navigation
296 // bars are visible, the decor frame is equal to the stable frame.
297 final Rect mDecorFrame = new Rect();
298
299 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
300 // minus the area occupied by the IME if the IME is present.
301 final Rect mContentFrame = new Rect();
302
303 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
304 // displays hint text.
305 final Rect mVisibleFrame = new Rect();
306
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700307 // Frame that includes dead area outside of the surface but where we want to pretend that it's
308 // possible to draw.
309 final Rect mOutsetFrame = new Rect();
310
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800311 boolean mContentChanged;
312
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800313 // If a window showing a wallpaper: the requested offset for the
314 // wallpaper; if a wallpaper window: the currently applied offset.
315 float mWallpaperX = -1;
316 float mWallpaperY = -1;
317
318 // If a window showing a wallpaper: what fraction of the offset
319 // range corresponds to a full virtual screen.
320 float mWallpaperXStep = -1;
321 float mWallpaperYStep = -1;
322
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700323 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
324 // to its window; if a wallpaper window: not used.
325 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
326 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
327
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800328 // Wallpaper windows: pixels offset based on above variables.
329 int mXOffset;
330 int mYOffset;
331
Craig Mautner2268e7e2012-12-13 15:40:00 -0800332 /**
333 * This is set after IWindowSession.relayout() has been called at
334 * least once for the window. It allows us to detect the situation
335 * where we don't yet have a surface, but should have one soon, so
336 * we can give the window focus before waiting for the relayout.
337 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800338 boolean mRelayoutCalled;
339
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800340 /**
341 * If the application has called relayout() with changes that can
342 * impact its window's size, we need to perform a layout pass on it
343 * even if it is not currently visible for layout. This is set
344 * when in that case until the layout is done.
345 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800346 boolean mLayoutNeeded;
347
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800348 /** Currently running an exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800349 boolean mExiting;
350
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800351 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800352 boolean mDestroying;
353
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800354 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800355 boolean mRemoveOnExit;
356
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800357 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800358 * Whether the app died while it was visible, if true we might need
359 * to continue to show it until it's restarted.
360 */
361 boolean mAppDied;
362
363 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800364 * Set when the orientation is changing and this window has not yet
365 * been updated for the new orientation.
366 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800367 boolean mOrientationChanging;
368
Dianne Hackborna57c6952013-03-29 14:46:40 -0700369 /**
370 * How long we last kept the screen frozen.
371 */
372 int mLastFreezeDuration;
373
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800374 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800375 boolean mRemoved;
376
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800377 /**
378 * Temp for keeping track of windows that have been removed when
379 * rebuilding window list.
380 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800381 boolean mRebuilding;
382
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800383 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700384 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800385 InputChannel mInputChannel;
Chong Zhang112eb8c2015-11-02 11:17:00 -0800386 InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800387
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800388 // Used to improve performance of toString()
389 String mStringNameCache;
390 CharSequence mLastTitle;
Dianne Hackborn529e7442012-11-01 14:22:28 -0700391 boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800392
Craig Mautnera2c77052012-03-26 12:14:43 -0700393 final WindowStateAnimator mWinAnimator;
394
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700395 boolean mHasSurface = false;
396
Craig Mautner19ab8282014-05-07 10:35:34 -0700397 boolean mNotOnAppsDisplay = false;
Craig Mautner59c00972012-07-30 12:10:24 -0700398 DisplayContent mDisplayContent;
Craig Mautner6881a102012-07-27 13:04:51 -0700399
Craig Mautner88400d32012-09-30 12:35:45 -0700400 /** When true this window can be displayed on screens owther than mOwnerUid's */
401 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700402
Robert Carr13f7be9e2015-12-02 18:39:45 -0800403 // Whether the window has a saved surface from last pause, which can be
404 // used to start an entering animation earlier.
405 public boolean mSurfaceSaved = false;
406
Robert Carra1eb4392015-12-10 12:43:51 -0800407 // This window will be replaced due to relaunch. This allows window manager
408 // to differentiate between simple removal of a window and replacement. In the latter case it
409 // will preserve the old window until the new one is drawn.
410 boolean mWillReplaceWindow = false;
411 // If true, the replaced window was already requested to be removed.
412 boolean mReplacingRemoveRequested = false;
413 // Whether the replacement of the window should trigger app transition animation.
414 boolean mAnimateReplacingWindow = false;
415 // If not null, the window that will be used to replace the old one. This is being set when
416 // the window is added and unset when this window reports its first draw.
417 WindowState mReplacingWindow = null;
418
Jeff Brownc2932a12014-11-20 18:04:05 -0800419 /**
420 * Wake lock for drawing.
421 * Even though it's slightly more expensive to do so, we will use a separate wake lock
422 * for each app that is requesting to draw while dozing so that we can accurately track
423 * who is preventing the system from suspending.
424 * This lock is only acquired on first use.
425 */
426 PowerManager.WakeLock mDrawLock;
427
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700428 final private Rect mTmpRect = new Rect();
429
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800430 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800431 WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a,
Craig Mautner59c00972012-07-30 12:10:24 -0700432 int viewVisibility, final DisplayContent displayContent) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800433 mService = service;
434 mSession = s;
435 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800436 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800437 mToken = token;
Craig Mautnera2d7b112012-08-21 15:12:20 -0700438 mOwnerUid = s.mUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800439 mWindowId = new IWindowId.Stub() {
440 @Override
441 public void registerFocusObserver(IWindowFocusObserver observer) {
442 WindowState.this.registerFocusObserver(observer);
443 }
444 @Override
445 public void unregisterFocusObserver(IWindowFocusObserver observer) {
446 WindowState.this.unregisterFocusObserver(observer);
447 }
448 @Override
449 public boolean isFocused() {
450 return WindowState.this.isFocused();
451 }
452 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800453 mAttrs.copyFrom(a);
454 mViewVisibility = viewVisibility;
Craig Mautner59c00972012-07-30 12:10:24 -0700455 mDisplayContent = displayContent;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700456 mPolicy = mService.mPolicy;
457 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800458 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700459 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700460 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800461 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700462 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700463 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800464 try {
465 c.asBinder().linkToDeath(deathRecipient, 0);
466 } catch (RemoteException e) {
467 mDeathRecipient = null;
468 mAttachedWindow = null;
469 mLayoutAttached = false;
470 mIsImWindow = false;
471 mIsWallpaper = false;
472 mIsFloatingLayer = false;
473 mBaseLayer = 0;
474 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700475 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700476 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800477 return;
478 }
479 mDeathRecipient = deathRecipient;
480
481 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
482 mAttrs.type <= LAST_SUB_WINDOW)) {
483 // The multiplier here is to reserve space for multiple
484 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700485 mBaseLayer = mPolicy.windowTypeToLayerLw(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800486 attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
487 + WindowManagerService.TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700488 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800489 mAttachedWindow = attachedWindow;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800490 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
takeda.masayuki18735092012-12-12 11:06:24 +0900491
tiger_huange2a98a72014-11-13 19:46:28 +0800492 final WindowList childWindows = mAttachedWindow.mChildWindows;
493 final int numChildWindows = childWindows.size();
494 if (numChildWindows == 0) {
495 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900496 } else {
tiger_huange2a98a72014-11-13 19:46:28 +0800497 boolean added = false;
498 for (int i = 0; i < numChildWindows; i++) {
499 final int childSubLayer = childWindows.get(i).mSubLayer;
500 if (mSubLayer < childSubLayer
501 || (mSubLayer == childSubLayer && childSubLayer < 0)) {
502 // We insert the child window into the list ordered by the sub-layer. For
503 // same sub-layers, the negative one should go below others; the positive
504 // one should go above others.
505 childWindows.add(i, this);
506 added = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900507 break;
takeda.masayuki18735092012-12-12 11:06:24 +0900508 }
509 }
tiger_huange2a98a72014-11-13 19:46:28 +0800510 if (!added) {
511 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900512 }
513 }
514
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800515 mLayoutAttached = mAttrs.type !=
516 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
517 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
518 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
519 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
520 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
521 } else {
522 // The multiplier here is to reserve space for multiple
523 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700524 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800525 * WindowManagerService.TYPE_LAYER_MULTIPLIER
526 + WindowManagerService.TYPE_LAYER_OFFSET;
527 mSubLayer = 0;
528 mAttachedWindow = null;
529 mLayoutAttached = false;
530 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
531 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
532 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
533 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
534 }
535
536 WindowState appWin = this;
Robert Carr51a1b872015-12-08 14:03:13 -0800537 while (appWin.isChildWindow()) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700538 appWin = appWin.mAttachedWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800539 }
540 WindowToken appToken = appWin.mToken;
541 while (appToken.appWindowToken == null) {
542 WindowToken parent = mService.mTokenMap.get(appToken.token);
543 if (parent == null || appToken == parent) {
544 break;
545 }
546 appToken = parent;
547 }
548 mRootToken = appToken;
549 mAppToken = appToken.appWindowToken;
Craig Mautner19ab8282014-05-07 10:35:34 -0700550 if (mAppToken != null) {
551 final DisplayContent appDisplay = getDisplayContent();
552 mNotOnAppsDisplay = displayContent != appDisplay;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700553
554 if (mAppToken.showForAllUsers) {
555 // Windows for apps that can show for all users should also show when the
556 // device is locked.
557 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
558 }
Craig Mautner19ab8282014-05-07 10:35:34 -0700559 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800560
Craig Mautner322e4032012-07-13 13:35:20 -0700561 mWinAnimator = new WindowStateAnimator(this);
562 mWinAnimator.mAlpha = a.alpha;
563
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800564 mRequestedWidth = 0;
565 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700566 mLastRequestedWidth = 0;
567 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800568 mXOffset = 0;
569 mYOffset = 0;
570 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800571 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700572 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
573 displayContent.getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800574 }
575
576 void attach() {
577 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700578 TAG, "Attaching " + this + " token=" + mToken
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800579 + ", list=" + mToken.windows);
580 mSession.windowAddedLocked();
581 }
582
Craig Mautnera2c77052012-03-26 12:14:43 -0700583 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800584 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800585 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800586 }
587
588 @Override
589 public String getOwningPackage() {
590 return mAttrs.packageName;
591 }
592
593 @Override
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700594 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf, Rect sf,
595 Rect osf) {
Robert Carra1eb4392015-12-10 12:43:51 -0800596 if (mWillReplaceWindow && (mExiting || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700597 // This window is being replaced and either already got information that it's being
598 // removed or we are still waiting for some information. Because of this we don't
599 // want to apply any more changes to it, so it remains in this state until new window
600 // appears.
601 return;
602 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800603 mHaveFrame = true;
604
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700605 final Task task = getTask();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700606 final boolean nonFullscreenTask = task != null && !task.isFullscreen();
Chong Zhang09b21ef2015-09-14 10:20:21 -0700607 final boolean freeformWorkspace = task != null && task.inFreeformWorkspace();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700608 if (nonFullscreenTask) {
609 task.getBounds(mContainingFrame);
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800610 final WindowState imeWin = mService.mInputMethodWindow;
611 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this
612 && mContainingFrame.bottom > cf.bottom) {
613 // IME is up and obscuring this window. Adjust the window position so it is visible.
614 mContainingFrame.top -= mContainingFrame.bottom - cf.bottom;
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700615 }
Skuhne81c524a2015-08-12 13:34:14 -0700616
Skuhnef932e562015-08-20 12:07:30 -0700617 if (freeformWorkspace) {
Skuhne81c524a2015-08-12 13:34:14 -0700618 // In free form mode we have only to set the rectangle if it wasn't set already. No
619 // need to intersect it with the (visible) "content frame" since it is allowed to
620 // be outside the visible desktop.
621 if (mContainingFrame.isEmpty()) {
622 mContainingFrame.set(cf);
623 }
Doris Liu06d582d2015-06-01 13:18:43 -0700624 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800625 mDisplayFrame.set(mContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700626 } else {
627 mContainingFrame.set(pf);
Wale Ogunwale94596652015-02-06 19:27:34 -0800628 mDisplayFrame.set(df);
Craig Mautner967212c2013-04-13 21:10:58 -0700629 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800630
Craig Mautner967212c2013-04-13 21:10:58 -0700631 final int pw = mContainingFrame.width();
632 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800633
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800634 if (!mParentFrame.equals(pf)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800635 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800636 // + " to " + pf);
637 mParentFrame.set(pf);
638 mContentChanged = true;
639 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700640 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
641 mLastRequestedWidth = mRequestedWidth;
642 mLastRequestedHeight = mRequestedHeight;
643 mContentChanged = true;
644 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800645
Craig Mautnereda67292013-04-28 13:50:14 -0700646 mOverscanFrame.set(of);
647 mContentFrame.set(cf);
648 mVisibleFrame.set(vf);
John Spurlock46646232013-09-30 22:32:42 -0400649 mDecorFrame.set(dcf);
Adrian Roosfa104232014-06-20 16:10:14 -0700650 mStableFrame.set(sf);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700651 final boolean hasOutsets = osf != null;
652 if (hasOutsets) {
653 mOutsetFrame.set(osf);
654 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800655
Craig Mautnereda67292013-04-28 13:50:14 -0700656 final int fw = mFrame.width();
657 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800658
Robert Carr31e28482015-12-02 16:53:18 -0800659 applyGravityAndUpdateFrame();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800660
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700661 // Calculate the outsets before the content frame gets shrinked to the window frame.
662 if (hasOutsets) {
663 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
664 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
665 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
666 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
667 } else {
668 mOutsets.set(0, 0, 0, 0);
669 }
670
Craig Mautnera248eee2013-05-07 11:41:27 -0700671 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800672 // final window frame.
Skuhnef932e562015-08-20 12:07:30 -0700673 if (freeformWorkspace && !mFrame.isEmpty()) {
Skuhne81c524a2015-08-12 13:34:14 -0700674 // Keep the frame out of the blocked system area, limit it in size to the content area
675 // and make sure that there is always a minimum visible so that the user can drag it
676 // into a usable area..
677 final int height = Math.min(mFrame.height(), mContentFrame.height());
678 final int width = Math.min(mContentFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700679 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700680 final int minVisibleHeight = WindowManagerService.dipToPixel(
681 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics);
682 final int minVisibleWidth = WindowManagerService.dipToPixel(
683 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics);
Skuhne81c524a2015-08-12 13:34:14 -0700684 final int top = Math.max(mContentFrame.top,
685 Math.min(mFrame.top, mContentFrame.bottom - minVisibleHeight));
686 final int left = Math.max(mContentFrame.left + minVisibleWidth - width,
687 Math.min(mFrame.left, mContentFrame.right - minVisibleWidth));
688 mFrame.set(left, top, left + width, top + height);
689 mContentFrame.set(mFrame);
690 mVisibleFrame.set(mContentFrame);
691 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700692 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800693 if (isVisibleLw() || mWinAnimator.isAnimating()) {
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800694 // We don't adjust the dock divider frame for reasons other than performance. The
695 // real reason is that if it gets adjusted before it is shown for the first time,
696 // it would get size (0, 0). This causes a problem when we finally show the dock
697 // divider and try to draw to it. We do set the surface size at that moment to
698 // the correct size, but it's too late for the Surface Flinger to make it
699 // available for view rendering and as a result the renderer receives size 1, 1.
700 // This way we just keep the divider at the original size and Surface Flinger
701 // will return the correct value to the renderer.
702 mDisplayContent.getDockedDividerController().positionDockedStackedDivider(mFrame);
703 mContentFrame.set(mFrame);
704 }
Skuhne81c524a2015-08-12 13:34:14 -0700705 } else {
706 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
707 Math.max(mContentFrame.top, mFrame.top),
708 Math.min(mContentFrame.right, mFrame.right),
709 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800710
Skuhne81c524a2015-08-12 13:34:14 -0700711 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
712 Math.max(mVisibleFrame.top, mFrame.top),
713 Math.min(mVisibleFrame.right, mFrame.right),
714 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800715
Skuhne81c524a2015-08-12 13:34:14 -0700716 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
717 Math.max(mStableFrame.top, mFrame.top),
718 Math.min(mStableFrame.right, mFrame.right),
719 Math.min(mStableFrame.bottom, mFrame.bottom));
720 }
Adrian Roosfa104232014-06-20 16:10:14 -0700721
Craig Mautnerc36c8e62013-05-10 13:33:31 -0700722 mOverscanInsets.set(Math.max(mOverscanFrame.left - mFrame.left, 0),
723 Math.max(mOverscanFrame.top - mFrame.top, 0),
Adrian Roos3236f3a2014-12-09 15:06:40 +0000724 Math.max(mFrame.right - mOverscanFrame.right, 0),
725 Math.max(mFrame.bottom - mOverscanFrame.bottom, 0));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800726
Craig Mautnereda67292013-04-28 13:50:14 -0700727 mContentInsets.set(mContentFrame.left - mFrame.left,
728 mContentFrame.top - mFrame.top,
729 mFrame.right - mContentFrame.right,
730 mFrame.bottom - mContentFrame.bottom);
731
732 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
733 mVisibleFrame.top - mFrame.top,
734 mFrame.right - mVisibleFrame.right,
735 mFrame.bottom - mVisibleFrame.bottom);
736
Adrian Roosfa104232014-06-20 16:10:14 -0700737 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
738 Math.max(mStableFrame.top - mFrame.top, 0),
739 Math.max(mFrame.right - mStableFrame.right, 0),
740 Math.max(mFrame.bottom - mStableFrame.bottom, 0));
741
Craig Mautnereda67292013-04-28 13:50:14 -0700742 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400743 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700744 // If there is a size compatibility scale being applied to the
745 // window, we need to apply this to its insets so that they are
746 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700747 mOverscanInsets.scale(mInvGlobalScale);
748 mContentInsets.scale(mInvGlobalScale);
749 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700750 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700751 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700752
753 // Also the scaled frame that we report to the app needs to be
754 // adjusted to be in its coordinate space.
755 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400756 }
757
Craig Mautnereda67292013-04-28 13:50:14 -0700758 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800759 final DisplayContent displayContent = getDisplayContent();
760 if (displayContent != null) {
761 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700762 mService.mWallpaperControllerLocked.updateWallpaperOffset(
763 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800764 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800765 }
766
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700767 if (DEBUG_LAYOUT || WindowManagerService.localLOGV) Slog.v(TAG,
768 "Resolving (mRequestedWidth="
769 + mRequestedWidth + ", mRequestedheight="
770 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
771 + "): frame=" + mFrame.toShortString()
772 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -0700773 + " vi=" + mVisibleInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700774 + " vi=" + mStableInsets.toShortString()
775 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800776 }
777
Craig Mautnera2c77052012-03-26 12:14:43 -0700778 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800779 public Rect getFrameLw() {
780 return mFrame;
781 }
782
Craig Mautnera2c77052012-03-26 12:14:43 -0700783 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700784 public Point getShownPositionLw() {
785 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800786 }
787
Craig Mautnera2c77052012-03-26 12:14:43 -0700788 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800789 public Rect getDisplayFrameLw() {
790 return mDisplayFrame;
791 }
792
Craig Mautnera2c77052012-03-26 12:14:43 -0700793 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800794 public Rect getOverscanFrameLw() {
795 return mOverscanFrame;
796 }
797
798 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800799 public Rect getContentFrameLw() {
800 return mContentFrame;
801 }
802
Craig Mautnera2c77052012-03-26 12:14:43 -0700803 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800804 public Rect getVisibleFrameLw() {
805 return mVisibleFrame;
806 }
807
Craig Mautnera2c77052012-03-26 12:14:43 -0700808 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800809 public boolean getGivenInsetsPendingLw() {
810 return mGivenInsetsPending;
811 }
812
Craig Mautnera2c77052012-03-26 12:14:43 -0700813 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800814 public Rect getGivenContentInsetsLw() {
815 return mGivenContentInsets;
816 }
817
Craig Mautnera2c77052012-03-26 12:14:43 -0700818 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800819 public Rect getGivenVisibleInsetsLw() {
820 return mGivenVisibleInsets;
821 }
822
Craig Mautnera2c77052012-03-26 12:14:43 -0700823 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800824 public WindowManager.LayoutParams getAttrs() {
825 return mAttrs;
826 }
827
Craig Mautner812d2ca2012-09-27 15:35:34 -0700828 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800829 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
830 int index = -1;
831 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -0700832 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800833 while (true) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -0700834 if (ws.mAttrs.needsMenuKey != WindowManager.LayoutParams.NEEDS_MENU_UNSET) {
835 return ws.mAttrs.needsMenuKey == WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800836 }
837 // If we reached the bottom of the range of windows we are considering,
838 // assume no menu is needed.
839 if (ws == bottom) {
840 return false;
841 }
842 // The current window hasn't specified whether menu key is needed;
843 // look behind it.
844 // First, we may need to determine the starting position.
845 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -0700846 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800847 }
848 index--;
849 if (index < 0) {
850 return false;
851 }
Craig Mautner59c00972012-07-30 12:10:24 -0700852 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800853 }
854 }
855
Craig Mautner19d59bc2012-09-04 11:15:56 -0700856 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700857 public int getSystemUiVisibility() {
858 return mSystemUiVisibility;
859 }
860
Craig Mautner19d59bc2012-09-04 11:15:56 -0700861 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800862 public int getSurfaceLayer() {
863 return mLayer;
864 }
865
Craig Mautner812d2ca2012-09-27 15:35:34 -0700866 @Override
Selim Cinekd6623612015-05-22 18:56:22 -0700867 public int getBaseType() {
868 WindowState win = this;
Robert Carr51a1b872015-12-08 14:03:13 -0800869 while (win.isChildWindow()) {
Selim Cinekd6623612015-05-22 18:56:22 -0700870 win = win.mAttachedWindow;
871 }
872 return win.mAttrs.type;
873 }
874
875 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800876 public IApplicationToken getAppToken() {
877 return mAppToken != null ? mAppToken.appToken : null;
878 }
Craig Mautner19d59bc2012-09-04 11:15:56 -0700879
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700880 @Override
881 public boolean isVoiceInteraction() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700882 return mAppToken != null && mAppToken.voiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700883 }
884
Craig Mautner4c5eb222013-11-18 12:59:05 -0800885 boolean setInsetsChanged() {
886 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
887 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
888 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -0700889 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700890 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
891 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
892 || mOutsetsChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -0800893 }
894
Craig Mautnerdf88d732014-01-27 09:21:32 -0800895 public DisplayContent getDisplayContent() {
Chad Jonesf391ebc2014-06-12 17:45:05 -0700896 if (mAppToken == null || mNotOnAppsDisplay) {
Craig Mautnerbe634952014-06-12 13:39:24 -0700897 return mDisplayContent;
898 }
899 final TaskStack stack = getStack();
900 return stack == null ? mDisplayContent : stack.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -0800901 }
902
Chong Zhang09b21ef2015-09-14 10:20:21 -0700903 public DisplayInfo getDisplayInfo() {
904 final DisplayContent displayContent = getDisplayContent();
905 return displayContent != null ? displayContent.getDisplayInfo() : null;
906 }
907
Craig Mautner19d59bc2012-09-04 11:15:56 -0700908 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800909 final DisplayContent displayContent = getDisplayContent();
910 if (displayContent == null) {
911 return -1;
912 }
913 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -0700914 }
915
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700916 Task getTask() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700917 return mAppToken != null ? mAppToken.mTask : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700918 }
919
920 TaskStack getStack() {
921 Task task = getTask();
922 if (task != null) {
923 if (task.mStack != null) {
924 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -0700925 }
Craig Mautnerd9a22882013-03-16 15:00:36 -0700926 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700927 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
928 // associate them with some stack to enable dimming.
929 return mAttrs.type >= WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
930 && mDisplayContent != null ? mDisplayContent.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -0700931 }
932
Skuhnef932e562015-08-20 12:07:30 -0700933 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700934 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -0700935 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -0700936 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800937 void getVisibleBounds(Rect bounds) {
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700938 boolean intersectWithStackBounds = mAppToken != null && mAppToken.mCropWindowsToStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700939 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700940 mTmpRect.setEmpty();
941 if (intersectWithStackBounds) {
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700942 final TaskStack stack = getStack();
943 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800944 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700945 } else {
946 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700947 }
948 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700949
Chong Zhang9184ec62015-09-24 12:32:21 -0700950 bounds.set(mVisibleFrame);
951 if (intersectWithStackBounds) {
952 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700953 }
954
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700955 if (bounds.isEmpty()) {
956 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700957 if (intersectWithStackBounds) {
958 bounds.intersect(mTmpRect);
959 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800960 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700961 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700962 }
963
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800964 public long getInputDispatchingTimeoutNanos() {
965 return mAppToken != null
966 ? mAppToken.inputDispatchingTimeoutNanos
967 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
968 }
969
Craig Mautnere8552142012-11-07 13:55:47 -0800970 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800971 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -0700972 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800973 }
974
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800975 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
976 if (dsdx < .99999f || dsdx > 1.00001f) return false;
977 if (dtdy < .99999f || dtdy > 1.00001f) return false;
978 if (dtdx < -.000001f || dtdx > .000001f) return false;
979 if (dsdy < -.000001f || dsdy > .000001f) return false;
980 return true;
981 }
982
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400983 void prelayout() {
984 if (mEnforceSizeCompat) {
985 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700986 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400987 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700988 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400989 }
990 }
991
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800992 /**
993 * Is this window visible? It is not visible if there is no
994 * surface, or we are in the process of running an exit animation
995 * that will remove the surface, or its app token has been hidden.
996 */
Craig Mautner88400d32012-09-30 12:35:45 -0700997 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800998 public boolean isVisibleLw() {
999 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001000 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001001 && (atoken == null || !atoken.hiddenRequested)
1002 && !mExiting && !mDestroying;
1003 }
1004
1005 /**
1006 * Like {@link #isVisibleLw}, but also counts a window that is currently
1007 * "hidden" behind the keyguard as visible. This allows us to apply
1008 * things like window flags that impact the keyguard.
1009 * XXX I am starting to think we need to have ANOTHER visibility flag
1010 * for this "hidden behind keyguard" state rather than overloading
1011 * mPolicyVisibility. Ungh.
1012 */
Craig Mautner88400d32012-09-30 12:35:45 -07001013 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001014 public boolean isVisibleOrBehindKeyguardLw() {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001015 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -08001016 mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001017 return false;
1018 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001019 final AppWindowToken atoken = mAppToken;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001020 final boolean animating = atoken != null && atoken.mAppAnimator.animation != null;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001021 return mHasSurface && !mDestroying && !mExiting
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001022 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001023 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
1024 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001025 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001026 }
1027
1028 /**
1029 * Is this window visible, ignoring its app token? It is not visible
1030 * if there is no surface, or we are in the process of running an exit animation
1031 * that will remove the surface.
1032 */
1033 public boolean isWinVisibleLw() {
1034 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001035 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautner59431632012-04-04 11:56:44 -07001036 && (atoken == null || !atoken.hiddenRequested || atoken.mAppAnimator.animating)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001037 && !mExiting && !mDestroying;
1038 }
1039
1040 /**
1041 * The same as isVisible(), but follows the current hidden state of
1042 * the associated app token, not the pending requested hidden state.
1043 */
1044 boolean isVisibleNow() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001045 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07001046 && (!mRootToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
1047 && !mExiting && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001048 }
1049
1050 /**
1051 * Can this window possibly be a drag/drop target? The test here is
1052 * a combination of the above "visible now" with the check that the
1053 * Input Manager uses when discarding windows from input consideration.
1054 */
1055 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001056 return isVisibleNow() && !mRemoved
1057 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001058 }
1059
1060 /**
1061 * Same as isVisible(), but we also count it as visible between the
1062 * call to IWindowSession.add() and the first relayout().
1063 */
1064 boolean isVisibleOrAdding() {
1065 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001066 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001067 && mPolicyVisibility && !mAttachedHidden
1068 && (atoken == null || !atoken.hiddenRequested)
1069 && !mExiting && !mDestroying;
1070 }
1071
1072 /**
1073 * Is this window currently on-screen? It is on-screen either if it
1074 * is visible or it is currently running an animation before no longer
1075 * being visible.
1076 */
1077 boolean isOnScreen() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001078 return mPolicyVisibility && isOnScreenIgnoringKeyguard();
1079 }
1080
1081 /**
1082 * Like isOnScreen(), but ignores any force hiding of the window due
1083 * to the keyguard.
1084 */
1085 boolean isOnScreenIgnoringKeyguard() {
1086 if (!mHasSurface || mDestroying) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001087 return false;
1088 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001089 final AppWindowToken atoken = mAppToken;
1090 if (atoken != null) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001091 return ((!mAttachedHidden && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001092 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001093 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001094 return !mAttachedHidden || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001095 }
1096
1097 /**
1098 * Like isOnScreen(), but we don't return true if the window is part
1099 * of a transition that has not yet been started.
1100 */
1101 boolean isReadyForDisplay() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001102 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001103 return false;
1104 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001105 return mHasSurface && mPolicyVisibility && !mDestroying
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001106 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
1107 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001108 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001109 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001110 }
1111
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001112 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001113 * Like isReadyForDisplay(), but ignores any force hiding of the window due
1114 * to the keyguard.
1115 */
1116 boolean isReadyForDisplayIgnoringKeyguard() {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001117 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001118 return false;
1119 }
1120 final AppWindowToken atoken = mAppToken;
1121 if (atoken == null && !mPolicyVisibility) {
1122 // If this is not an app window, and the policy has asked to force
1123 // hide, then we really do want to hide.
1124 return false;
1125 }
1126 return mHasSurface && !mDestroying
1127 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
1128 && !mRootToken.hidden)
1129 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -07001130 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
1131 && !mWinAnimator.isDummyAnimation()));
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001132 }
1133
1134 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001135 * Like isOnScreen, but returns false if the surface hasn't yet
1136 * been drawn.
1137 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001138 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001139 public boolean isDisplayedLw() {
1140 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001141 return isDrawnLw() && mPolicyVisibility
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001142 && ((!mAttachedHidden &&
1143 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001144 || mWinAnimator.mAnimating
1145 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001146 }
1147
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001148 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001149 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001150 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001151 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001152 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001153 return mWinAnimator.mAnimation != null
1154 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001155 }
1156
Craig Mautner812d2ca2012-09-27 15:35:34 -07001157 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001158 public boolean isGoneForLayoutLw() {
1159 final AppWindowToken atoken = mAppToken;
1160 return mViewVisibility == View.GONE
1161 || !mRelayoutCalled
1162 || (atoken == null && mRootToken.hidden)
Craig Mautner812d2ca2012-09-27 15:35:34 -07001163 || (atoken != null && (atoken.hiddenRequested || atoken.hidden))
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001164 || mAttachedHidden
Craig Mautner0e415c62013-04-29 16:10:58 -07001165 || (mExiting && !isAnimatingLw())
1166 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001167 }
1168
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001169 /**
1170 * Returns true if the window has a surface that it has drawn a
1171 * complete UI in to.
1172 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001173 public boolean isDrawFinishedLw() {
1174 return mHasSurface && !mDestroying &&
1175 (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING
1176 || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1177 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
1178 }
1179
1180 /**
1181 * Returns true if the window has a surface that it has drawn a
1182 * complete UI in to.
1183 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001184 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001185 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001186 return mHasSurface && !mDestroying &&
Craig Mautner749a7bb2012-04-02 13:49:53 -07001187 (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1188 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001189 }
1190
1191 /**
1192 * Return true if the window is opaque and fully drawn. This indicates
1193 * it may obscure windows behind it.
1194 */
1195 boolean isOpaqueDrawn() {
1196 return (mAttrs.format == PixelFormat.OPAQUE
1197 || mAttrs.type == TYPE_WALLPAPER)
Craig Mautnera2c77052012-03-26 12:14:43 -07001198 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001199 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001200 }
1201
1202 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001203 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001204 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1205 */
Craig Mautner4557c082015-04-27 13:07:40 -07001206 boolean hasMoved() {
1207 return mHasSurface && mContentChanged && !mExiting && !mWinAnimator.mLastHidden
1208 && mService.okToDisplay() && (mFrame.top != mLastFrame.top
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001209 || mFrame.left != mLastFrame.left)
Craig Mautner4557c082015-04-27 13:07:40 -07001210 && (mAttachedWindow == null || !mAttachedWindow.hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001211 }
1212
Chong Zhang0abb20f2015-11-19 14:17:31 -08001213 boolean isObscuringFullscreen(final DisplayInfo displayInfo) {
1214 Task task = getTask();
1215 if (task != null && task.mStack != null && !task.mStack.isFullscreen()) {
1216 return false;
1217 }
1218 if (!isOpaqueDrawn() || !isFrameFullscreen(displayInfo)) {
1219 return false;
1220 }
1221 return true;
1222 }
1223
1224 boolean isFrameFullscreen(final DisplayInfo displayInfo) {
1225 return mFrame.left <= 0 && mFrame.top <= 0
1226 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001227 }
1228
Craig Mautner812d2ca2012-09-27 15:35:34 -07001229 boolean isConfigChanged() {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001230 final Task task = getTask();
Wale Ogunwale60454db2015-01-23 16:05:07 -08001231 final Configuration overrideConfig =
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001232 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001233 final Configuration serviceConfig = mService.mCurConfiguration;
1234 boolean configChanged =
1235 (mConfiguration != serviceConfig && mConfiguration.diff(serviceConfig) != 0)
1236 || (mOverrideConfig != overrideConfig && !mOverrideConfig.equals(overrideConfig));
Craig Mautnere8552142012-11-07 13:55:47 -08001237
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001238 if ((mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Craig Mautnere8552142012-11-07 13:55:47 -08001239 // Retain configuration changed status until resetConfiguration called.
1240 mConfigHasChanged |= configChanged;
1241 configChanged = mConfigHasChanged;
1242 }
1243
1244 return configChanged;
Craig Mautner812d2ca2012-09-27 15:35:34 -07001245 }
1246
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001247 void removeLocked() {
1248 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001249
Robert Carr51a1b872015-12-08 14:03:13 -08001250 if (isChildWindow()) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001251 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001252 mAttachedWindow.mChildWindows.remove(this);
1253 }
Craig Mautner96868332012-12-04 14:29:11 -08001254 mWinAnimator.destroyDeferredSurfaceLocked();
1255 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001256 mSession.windowRemovedLocked();
1257 try {
1258 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1259 } catch (RuntimeException e) {
1260 // Ignore if it has already been removed (usually because
1261 // we are doing this as part of processing a death note.)
1262 }
1263 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001264
Wale Ogunwale60454db2015-01-23 16:05:07 -08001265 private void setConfiguration(
1266 final Configuration newConfig, final Configuration newOverrideConfig) {
Craig Mautnere8552142012-11-07 13:55:47 -08001267 mConfiguration = newConfig;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001268 mOverrideConfig = newOverrideConfig;
Craig Mautnere8552142012-11-07 13:55:47 -08001269 mConfigHasChanged = false;
1270 }
1271
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001272 void setHasSurface(boolean hasSurface) {
1273 mHasSurface = hasSurface;
1274 }
1275
Chong Zhangacf11402015-11-04 16:23:10 -08001276 private final class DeadWindowEventReceiver extends InputEventReceiver {
1277 DeadWindowEventReceiver(InputChannel inputChannel) {
1278 super(inputChannel, mService.mH.getLooper());
1279 }
1280 @Override
1281 public void onInputEvent(InputEvent event) {
1282 finishInputEvent(event, true);
1283 }
1284 }
1285 /**
1286 * Dummy event receiver for windows that died visible.
1287 */
1288 private DeadWindowEventReceiver mDeadWindowEventReceiver;
1289
Chong Zhang112eb8c2015-11-02 11:17:00 -08001290 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001291 if (mInputChannel != null) {
1292 throw new IllegalStateException("Window already has an input channel.");
1293 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001294 String name = makeInputChannelName();
1295 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1296 mInputChannel = inputChannels[0];
1297 mClientChannel = inputChannels[1];
1298 mInputWindowHandle.inputChannel = inputChannels[0];
1299 if (outInputChannel != null) {
1300 mClientChannel.transferTo(outInputChannel);
1301 mClientChannel.dispose();
1302 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08001303 } else {
1304 // If the window died visible, we setup a dummy input channel, so that taps
1305 // can still detected by input monitor channel, and we can relaunch the app.
1306 // Create dummy event receiver that simply reports all events as handled.
1307 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08001308 }
1309 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001310 }
1311
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001312 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08001313 if (mDeadWindowEventReceiver != null) {
1314 mDeadWindowEventReceiver.dispose();
1315 mDeadWindowEventReceiver = null;
1316 }
1317
1318 // unregister server channel first otherwise it complains about broken channel
1319 if (mInputChannel != null) {
1320 mService.mInputManager.unregisterInputChannel(mInputChannel);
1321 mInputChannel.dispose();
1322 mInputChannel = null;
1323 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001324 if (mClientChannel != null) {
1325 mClientChannel.dispose();
1326 mClientChannel = null;
1327 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001328 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001329 }
1330
Chong Zhang112eb8c2015-11-02 11:17:00 -08001331 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08001332 // When the app is terminated (eg. from Recents), the task might have already been
1333 // removed with the window pending removal. Don't apply dim in such cases, as there
1334 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
1335 final AppWindowToken token = mAppToken;
1336 if (token != null && token.removed) {
1337 return;
1338 }
1339
Chong Zhang112eb8c2015-11-02 11:17:00 -08001340 if (!mExiting && mAppDied) {
1341 // If app died visible, apply a dim over the window to indicate that it's inactive
1342 mDisplayContent.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
1343 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
1344 && mDisplayContent != null && !mExiting && isDisplayedLw()) {
1345 mDisplayContent.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001346 }
1347 }
1348
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001349 DimLayer.DimLayerUser getDimLayerUser() {
1350 Task task = getTask();
1351 if (task != null) {
1352 return task;
1353 }
1354 return getStack();
1355 }
1356
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001357 void maybeRemoveReplacedWindow() {
Robert Carra1eb4392015-12-10 12:43:51 -08001358 if (mAppToken == null) {
1359 return;
1360 }
1361 for (int i = mAppToken.allAppWindows.size() - 1; i >= 0; i--) {
1362 final WindowState win = mAppToken.allAppWindows.get(i);
1363 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + win);
1364 if (win.mWillReplaceWindow && win.mReplacingWindow == this) {
1365 win.mWillReplaceWindow = false;
1366 win.mAnimateReplacingWindow = false;
1367 win.mReplacingRemoveRequested = false;
1368 win.mReplacingWindow = null;
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001369 if (win.mExiting) {
1370 mService.removeWindowInnerLocked(win);
1371 }
1372 }
1373 }
1374 }
1375
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07001376 void setDisplayLayoutNeeded() {
1377 if (mDisplayContent != null) {
1378 mDisplayContent.layoutNeeded = true;
1379 }
1380 }
1381
Filip Gruszczynski955b2fc2015-10-15 14:46:07 -07001382 boolean inDockedWorkspace() {
Chong Zhangb15758a2015-11-17 12:12:03 -08001383 Task task = getTask();
1384 return task != null && task.inDockedWorkspace();
1385 }
1386
1387 boolean isDockedInEffect() {
1388 Task task = getTask();
1389 return task != null && task.isDockedInEffect();
Filip Gruszczynski955b2fc2015-10-15 14:46:07 -07001390 }
1391
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001392 int getTouchableRegion(Region region, int flags) {
1393 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001394 if (modal && mAppToken != null) {
1395 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001396 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001397 // If this is a modal window we need to dismiss it if it's not full screen and the
1398 // touch happens outside of the frame that displays the content. This means we
1399 // need to intercept touches outside of that window. The dim layer user
1400 // associated with the window (task or stack) will give us the good bounds, as
1401 // they would be used to display the dim layer.
1402 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1403 if (dimLayerUser != null) {
1404 dimLayerUser.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001405 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001406 getVisibleBounds(mTmpRect);
1407 }
1408 if (inFreeformWorkspace()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001409 // For freeform windows we the touch region to include the whole surface for the
1410 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001411 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
1412 final int delta = WindowManagerService.dipToPixel(
1413 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
1414 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001415 }
1416 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001417 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001418 } else {
1419 // Not modal or full screen modal
1420 getTouchableRegion(region);
1421 }
1422 return flags;
1423 }
1424
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001425 void checkPolicyVisibilityChange() {
1426 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
1427 if (DEBUG_VISIBILITY) {
1428 Slog.v(TAG, "Policy visibility changing after anim in " +
1429 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
1430 }
1431 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001432 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001433 if (!mPolicyVisibility) {
1434 if (mService.mCurrentFocus == this) {
1435 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
1436 "setAnimationLocked: setting mFocusMayChange true");
1437 mService.mFocusMayChange = true;
1438 }
1439 // Window is no longer visible -- make sure if we were waiting
1440 // for it to be displayed before enabling the display, that
1441 // we allow the display to be enabled now.
1442 mService.enableScreenIfNeededLocked();
1443 }
1444 }
1445 }
1446
1447 void setRequestedSize(int requestedWidth, int requestedHeight) {
1448 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
1449 mLayoutNeeded = true;
1450 mRequestedWidth = requestedWidth;
1451 mRequestedHeight = requestedHeight;
1452 }
1453 }
1454
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001455 void prepareWindowToDisplayDuringRelayout(Configuration outConfig) {
1456 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
1457 == SOFT_INPUT_ADJUST_RESIZE) {
1458 mLayoutNeeded = true;
1459 }
1460 if (isDrawnLw() && mService.okToDisplay()) {
1461 mWinAnimator.applyEnterAnimationLocked();
1462 }
1463 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
1464 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
1465 mTurnOnScreen = true;
1466 }
1467 if (isConfigChanged()) {
1468 if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + this + " visible with new config: "
1469 + mService.mCurConfiguration);
1470 outConfig.setTo(mService.mCurConfiguration);
1471 }
1472 }
1473
1474 void adjustStartingWindowFlags() {
1475 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
1476 && mAppToken.startingWindow != null) {
1477 // Special handling of starting window over the base
1478 // window of the app: propagate lock screen flags to it,
1479 // to provide the correct semantics while starting.
1480 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
1481 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
1482 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
1483 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
1484 }
1485 }
1486
1487 void setWindowScale(int requestedWidth, int requestedHeight) {
1488 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
1489
1490 if (scaledWindow) {
1491 // requested{Width|Height} Surface's physical size
1492 // attrs.{width|height} Size on screen
1493 // TODO: We don't check if attrs != null here. Is it implicitly checked?
1494 mHScale = (mAttrs.width != requestedWidth) ?
1495 (mAttrs.width / (float)requestedWidth) : 1.0f;
1496 mVScale = (mAttrs.height != requestedHeight) ?
1497 (mAttrs.height / (float)requestedHeight) : 1.0f;
1498 } else {
1499 mHScale = mVScale = 1;
1500 }
1501 }
1502
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001503 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08001504 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001505 public void binderDied() {
1506 try {
1507 synchronized(mService.mWindowMap) {
1508 WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07001509 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001510 if (win != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001511 if (win.mAppToken != null && !win.mAppToken.clientHidden) {
1512 win.mAppToken.appDied = true;
1513 }
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001514 mService.removeWindowLocked(win);
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001515 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08001516 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001517 mService.removeWindowLocked(WindowState.this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001518 }
1519 }
1520 } catch (IllegalArgumentException ex) {
1521 // This will happen if the window has already been
1522 // removed.
1523 }
1524 }
1525 }
1526
Wale Ogunwaled045c822015-12-02 09:14:28 -08001527 /** @return true if this window desires key events. */
1528 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08001529 return isVisibleOrAdding()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001530 && (mViewVisibility == View.VISIBLE)
Wale Ogunwaled045c822015-12-02 09:14:28 -08001531 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
1532 && stackCanReceiveKeys();
1533 }
1534
1535 boolean stackCanReceiveKeys() {
1536 final TaskStack stack = getStack();
1537 return stack != null && StackId.canReceiveKeys(stack.mStackId);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001538 }
1539
Craig Mautner749a7bb2012-04-02 13:49:53 -07001540 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001541 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001542 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001543 }
1544
Craig Mautner749a7bb2012-04-02 13:49:53 -07001545 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001546 public boolean showLw(boolean doAnimation) {
1547 return showLw(doAnimation, true);
1548 }
1549
1550 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07001551 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001552 return false;
1553 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001554 if (!mAppOpVisibility) {
1555 // Being hidden due to app op request.
1556 return false;
1557 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001558 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001559 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001560 return false;
1561 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001562 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001563 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001564 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07001565 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07001566 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001567 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07001568 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001569 // Check for the case where we are currently visible and
1570 // not animating; we do not want to do animation at such a
1571 // point to become visible when we already are.
1572 doAnimation = false;
1573 }
1574 }
1575 mPolicyVisibility = true;
1576 mPolicyVisibilityAfterAnim = true;
1577 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001578 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001579 }
1580 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001581 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001582 }
1583 return true;
1584 }
1585
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001586 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001587 public boolean hideLw(boolean doAnimation) {
1588 return hideLw(doAnimation, true);
1589 }
1590
1591 boolean hideLw(boolean doAnimation, boolean requestAnim) {
1592 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07001593 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001594 doAnimation = false;
1595 }
1596 }
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001597 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
1598 : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001599 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001600 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001601 return false;
1602 }
1603 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001604 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07001605 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001606 doAnimation = false;
1607 }
1608 }
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001609 if (doAnimation) {
1610 mPolicyVisibilityAfterAnim = false;
1611 } else {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001612 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001613 mPolicyVisibilityAfterAnim = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001614 mPolicyVisibility = false;
1615 // Window is no longer visible -- make sure if we were waiting
1616 // for it to be displayed before enabling the display, that
1617 // we allow the display to be enabled now.
1618 mService.enableScreenIfNeededLocked();
1619 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001620 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07001621 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001622 mService.mFocusMayChange = true;
1623 }
1624 }
1625 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001626 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001627 }
1628 return true;
1629 }
1630
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001631 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001632 if (mAppOpVisibility != state) {
1633 mAppOpVisibility = state;
1634 if (state) {
1635 // If the policy visibility had last been to hide, then this
1636 // will incorrectly show at this point since we lost that
1637 // information. Not a big deal -- for the windows that have app
1638 // ops modifies they should only be hidden by policy due to the
1639 // lock screen, and the user won't be changing this if locked.
1640 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001641 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001642 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001643 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001644 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001645 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001646 }
1647
Jeff Brownc2932a12014-11-20 18:04:05 -08001648 public void pokeDrawLockLw(long timeout) {
1649 if (isVisibleOrAdding()) {
1650 if (mDrawLock == null) {
1651 // We want the tag name to be somewhat stable so that it is easier to correlate
1652 // in wake lock statistics. So in particular, we don't want to include the
1653 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001654 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08001655 mDrawLock = mService.mPowerManager.newWakeLock(
1656 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
1657 mDrawLock.setReferenceCounted(false);
1658 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
1659 }
1660 // Each call to acquire resets the timeout.
1661 if (DEBUG_POWER) {
1662 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
1663 + mAttrs.packageName);
1664 }
1665 mDrawLock.acquire(timeout);
1666 } else if (DEBUG_POWER) {
1667 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
1668 + "owned by " + mAttrs.packageName);
1669 }
1670 }
1671
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001672 @Override
1673 public boolean isAlive() {
1674 return mClient.asBinder().isBinderAlive();
1675 }
1676
Craig Mautnera987d432012-10-11 14:07:58 -07001677 boolean isClosing() {
1678 return mExiting || (mService.mClosingApps.contains(mAppToken));
1679 }
1680
Chong Zhangbef461f2015-10-27 11:38:24 -07001681 boolean isAnimatingWithSavedSurface() {
1682 return mAppToken != null && mAppToken.mAnimatingWithSavedSurface;
1683 }
1684
Robert Carr13f7be9e2015-12-02 18:39:45 -08001685 // Returns true if the surface is saved.
1686 boolean destroyOrSaveSurface() {
1687 Task task = getTask();
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001688 if (ActivityManager.isLowRamDeviceStatic()) {
1689 // Don't save surfaces on Svelte devices.
Robert Carr13f7be9e2015-12-02 18:39:45 -08001690 mSurfaceSaved = false;
1691 } else if (task == null || task.inHomeStack()
Chong Zhangd8ceb852015-11-11 14:53:41 -08001692 || task.getTopVisibleAppToken() != mAppToken) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001693 // Don't save surfaces for home stack apps. These usually resume and draw
1694 // first frame very fast. Saving surfaces are mostly a waste of memory.
Chong Zhangbef461f2015-10-27 11:38:24 -07001695 // Don't save if the window is not the topmost window.
Robert Carr13f7be9e2015-12-02 18:39:45 -08001696 mSurfaceSaved = false;
Robert Carr51a1b872015-12-08 14:03:13 -08001697 } else if (isChildWindow()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -08001698 mSurfaceSaved = false;
1699 } else {
1700 mSurfaceSaved = mAppToken.shouldSaveSurface();
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001701 }
Robert Carr13f7be9e2015-12-02 18:39:45 -08001702 if (mSurfaceSaved == false) {
1703 mWinAnimator.destroySurfaceLocked();
1704 }
1705 return mSurfaceSaved;
1706 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001707
Robert Carr13f7be9e2015-12-02 18:39:45 -08001708 public void destroySavedSurface() {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001709 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, "Destroying saved surface: " + this);
Robert Carr13f7be9e2015-12-02 18:39:45 -08001710 if (mSurfaceSaved) {
1711 mWinAnimator.destroySurfaceLocked();
1712 }
1713 }
1714
1715 public boolean hasSavedSurface() {
1716 return mSurfaceSaved;
1717 }
1718
1719 public void restoreSavedSurface() {
1720 mSurfaceSaved = false;
1721 mWinAnimator.mDrawState = WindowStateAnimator.READY_TO_SHOW;
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001722 }
1723
Craig Mautner69b08182012-09-05 13:07:13 -07001724 @Override
1725 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001726 final DisplayContent displayContent = getDisplayContent();
1727 if (displayContent == null) {
1728 // Only a window that was on a non-default display can be detached from it.
1729 return false;
1730 }
Winson Chung47a3e652014-05-21 16:03:42 -07001731 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07001732 }
1733
Adrian Rooscd3884d2015-02-18 17:25:23 +01001734 @Override
1735 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001736 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1737 return dimLayerUser != null && mDisplayContent != null &&
Chong Zhang112eb8c2015-11-02 11:17:00 -08001738 mDisplayContent.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01001739 }
1740
Craig Mautner88400d32012-09-30 12:35:45 -07001741 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
1742 mShowToOwnerOnly = showToOwnerOnly;
1743 }
1744
Craig Mautner5962b122012-10-05 14:45:52 -07001745 boolean isHiddenFromUserLocked() {
Craig Mautner341220f2012-10-16 15:20:09 -07001746 // Attached windows are evaluated based on the window that they are attached to.
1747 WindowState win = this;
Robert Carr51a1b872015-12-08 14:03:13 -08001748 while (win.isChildWindow()) {
Craig Mautner341220f2012-10-16 15:20:09 -07001749 win = win.mAttachedWindow;
1750 }
1751 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -07001752 && win.mAppToken != null && win.mAppToken.showForAllUsers) {
Craig Mautner341220f2012-10-16 15:20:09 -07001753 // Save some cycles by not calling getDisplayInfo unless it is an application
1754 // window intended for all users.
Craig Mautnerdf88d732014-01-27 09:21:32 -08001755 final DisplayContent displayContent = win.getDisplayContent();
1756 if (displayContent == null) {
1757 return true;
1758 }
1759 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Craig Mautner341220f2012-10-16 15:20:09 -07001760 if (win.mFrame.left <= 0 && win.mFrame.top <= 0
1761 && win.mFrame.right >= displayInfo.appWidth
1762 && win.mFrame.bottom >= displayInfo.appHeight) {
Craig Mautner5962b122012-10-05 14:45:52 -07001763 // Is a fullscreen window, like the clock alarm. Show to everyone.
1764 return false;
1765 }
1766 }
1767
Craig Mautner341220f2012-10-16 15:20:09 -07001768 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01001769 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001770 }
1771
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001772 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
1773 outRegion.set(
1774 frame.left + inset.left, frame.top + inset.top,
1775 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001776 }
1777
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001778 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001779 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001780 switch (mTouchableInsets) {
1781 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001782 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001783 outRegion.set(frame);
1784 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001785 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001786 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001787 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001788 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001789 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001790 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001791 case TOUCHABLE_INSETS_REGION: {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001792 final Region givenTouchableRegion = mGivenTouchableRegion;
1793 outRegion.set(givenTouchableRegion);
1794 outRegion.translate(frame.left, frame.top);
1795 break;
1796 }
1797 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001798 cropRegionToStackBoundsIfNeeded(outRegion);
1799 }
1800
1801 void cropRegionToStackBoundsIfNeeded(Region region) {
1802 if (mAppToken == null || !mAppToken.mCropWindowsToStack) {
1803 return;
1804 }
1805
1806 final TaskStack stack = getStack();
1807 if (stack == null) {
1808 return;
1809 }
1810
1811 stack.getDimBounds(mTmpRect);
1812 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001813 }
1814
Craig Mautner59c00972012-07-30 12:10:24 -07001815 WindowList getWindowList() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001816 final DisplayContent displayContent = getDisplayContent();
1817 return displayContent == null ? null : displayContent.getWindowList();
Craig Mautner59c00972012-07-30 12:10:24 -07001818 }
1819
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001820 /**
1821 * Report a focus change. Must be called with no locks held, and consistently
1822 * from the same serialized thread (such as dispatched from a handler).
1823 */
1824 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
1825 try {
1826 mClient.windowFocusChanged(focused, inTouchMode);
1827 } catch (RemoteException e) {
1828 }
1829 if (mFocusCallbacks != null) {
1830 final int N = mFocusCallbacks.beginBroadcast();
1831 for (int i=0; i<N; i++) {
1832 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
1833 try {
1834 if (focused) {
1835 obs.focusGained(mWindowId.asBinder());
1836 } else {
1837 obs.focusLost(mWindowId.asBinder());
1838 }
1839 } catch (RemoteException e) {
1840 }
1841 }
1842 mFocusCallbacks.finishBroadcast();
1843 }
1844 }
1845
Craig Mautnerdf88d732014-01-27 09:21:32 -08001846 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001847 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08001848 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001849 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
1850 + ": " + mCompatFrame);
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001851 final boolean configChanged = isConfigChanged();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001852 final Task task = getTask();
Wale Ogunwale60454db2015-01-23 16:05:07 -08001853 final Configuration overrideConfig =
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001854 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001855 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) && configChanged) {
1856 Slog.i(TAG, "Sending new config to window " + this + ": "
Robert Carre6a83512015-11-03 16:09:21 -08001857 + " / config="
Wale Ogunwale60454db2015-01-23 16:05:07 -08001858 + mService.mCurConfiguration + " overrideConfig=" + overrideConfig);
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001859 }
Wale Ogunwale60454db2015-01-23 16:05:07 -08001860 setConfiguration(mService.mCurConfiguration, overrideConfig);
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001861 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING)
1862 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
1863
Craig Mautnerdf88d732014-01-27 09:21:32 -08001864 final Rect frame = mFrame;
1865 final Rect overscanInsets = mLastOverscanInsets;
1866 final Rect contentInsets = mLastContentInsets;
1867 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07001868 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001869 final Rect outsets = mLastOutsets;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001870 final boolean reportDraw = mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING;
1871 final Configuration newConfig = configChanged ? mConfiguration : null;
Chet Haase8eb48d22014-09-24 07:31:29 -07001872 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1873 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001874 // To prevent deadlock simulate one-way call if win.mClient is a local object.
1875 mService.mH.post(new Runnable() {
1876 @Override
1877 public void run() {
1878 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001879 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
1880 stableInsets, outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001881 } catch (RemoteException e) {
1882 // Not a remote call, RemoteException won't be raised.
1883 }
1884 }
1885 });
1886 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001887 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001888 outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001889 }
Svetoslav4604abc2014-06-10 18:59:30 -07001890
1891 //TODO (multidisplay): Accessibility supported only for the default display.
1892 if (mService.mAccessibilityController != null
1893 && getDisplayId() == Display.DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07001894 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07001895 }
1896
Craig Mautnerdf88d732014-01-27 09:21:32 -08001897 mOverscanInsetsChanged = false;
1898 mContentInsetsChanged = false;
1899 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07001900 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001901 mOutsetsChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001902 mWinAnimator.mSurfaceResized = false;
1903 } catch (RemoteException e) {
1904 mOrientationChanging = false;
1905 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1906 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08001907 // We are assuming the hosting process is dead or in a zombie state.
1908 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
1909 + ", removing this window.");
1910 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001911 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001912 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001913 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001914 }
1915
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001916 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
1917 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
1918 Configuration newConfig) throws RemoteException {
1919 DisplayInfo displayInfo = getDisplayInfo();
1920 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Chong Zhangd153c4f2015-11-06 20:26:40 -08001921 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
1922 // start even if we haven't received the relayout window, so that the client requests
1923 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
1924 // until the window to small size, otherwise the multithread renderer will shift last
1925 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
1926 // isDragResizing() or isDragResizeChanged() is true.
1927 boolean resizing = isDragResizing() || isDragResizeChanged();
1928 final Rect backDropFrame = (inFreeformWorkspace() || !resizing) ? frame : mTmpRect;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001929 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Chong Zhangd153c4f2015-11-06 20:26:40 -08001930 outsets, reportDraw, newConfig, backDropFrame);
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001931 }
1932
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001933 public void registerFocusObserver(IWindowFocusObserver observer) {
1934 synchronized(mService.mWindowMap) {
1935 if (mFocusCallbacks == null) {
1936 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
1937 }
1938 mFocusCallbacks.register(observer);
1939 }
1940 }
1941
1942 public void unregisterFocusObserver(IWindowFocusObserver observer) {
1943 synchronized(mService.mWindowMap) {
1944 if (mFocusCallbacks != null) {
1945 mFocusCallbacks.unregister(observer);
1946 }
1947 }
1948 }
1949
1950 public boolean isFocused() {
1951 synchronized(mService.mWindowMap) {
1952 return mService.mCurrentFocus == this;
1953 }
1954 }
1955
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07001956 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07001957 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07001958 return task != null && task.inFreeformWorkspace();
1959 }
1960
Chong Zhang3005e752015-09-18 18:46:28 -07001961 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07001962 return mDragResizing != computeDragResizing();
1963 }
1964
Jorim Jaggidcf467c2015-11-05 13:59:32 +01001965 int getResizeMode() {
1966 return mResizeMode;
1967 }
1968
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07001969 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07001970 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07001971 if (task == null) {
1972 return false;
1973 }
1974 if (task.isDragResizing()) {
1975 return true;
1976 }
1977 return mDisplayContent.mDividerControllerLocked.isResizing() &&
1978 !task.inFreeformWorkspace() && !task.isFullscreen();
Chong Zhang3005e752015-09-18 18:46:28 -07001979 }
1980
1981 void setDragResizing() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07001982 mDragResizing = computeDragResizing();
Jorim Jaggidcf467c2015-11-05 13:59:32 +01001983 mResizeMode = mDragResizing && mDisplayContent.mDividerControllerLocked.isResizing()
1984 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
1985 : DRAG_RESIZE_MODE_FREEFORM;
Chong Zhang3005e752015-09-18 18:46:28 -07001986 }
1987
1988 boolean isDragResizing() {
1989 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07001990 }
1991
Dianne Hackborna44abeb2011-08-08 19:24:01 -07001992 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08001993 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001994 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08001995 if (stack != null) {
1996 pw.print(" stackId="); pw.print(stack.mStackId);
1997 }
Craig Mautner59c00972012-07-30 12:10:24 -07001998 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001999 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07002000 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08002001 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
2002 pw.print(" package="); pw.print(mAttrs.packageName);
2003 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002004 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002005 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
2006 pw.print(" h="); pw.print(mRequestedHeight);
2007 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07002008 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
2009 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
2010 pw.print(" h="); pw.println(mLastRequestedHeight);
2011 }
Robert Carr51a1b872015-12-08 14:03:13 -08002012 if (isChildWindow() || mLayoutAttached) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002013 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
2014 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
2015 }
2016 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
2017 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
2018 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
2019 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
2020 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
2021 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002022 if (dumpAll) {
2023 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
2024 pw.print(" mSubLayer="); pw.print(mSubLayer);
2025 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautner59431632012-04-04 11:56:44 -07002026 pw.print((mTargetAppToken != null ?
2027 mTargetAppToken.mAppAnimator.animLayerAdjustment
2028 : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002029 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
2030 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08002031 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002032 if (dumpAll) {
2033 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
2034 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
2035 if (mAppToken != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08002036 pw.print(prefix); pw.print("mAppToken="); pw.print(mAppToken);
2037 pw.print(" mAppDied=");pw.println(mAppDied);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002038 }
2039 if (mTargetAppToken != null) {
2040 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
2041 }
2042 pw.print(prefix); pw.print("mViewVisibility=0x");
2043 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002044 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
2045 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07002046 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
2047 pw.print(" mSystemUiVisibility=0x");
2048 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002049 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002050 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
2051 || mAttachedHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002052 pw.print(prefix); pw.print("mPolicyVisibility=");
2053 pw.print(mPolicyVisibility);
2054 pw.print(" mPolicyVisibilityAfterAnim=");
2055 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002056 pw.print(" mAppOpVisibility=");
2057 pw.print(mAppOpVisibility);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002058 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
2059 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08002060 if (!mRelayoutCalled || mLayoutNeeded) {
2061 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
2062 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002063 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002064 if (mXOffset != 0 || mYOffset != 0) {
2065 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
2066 pw.print(" y="); pw.println(mYOffset);
2067 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002068 if (dumpAll) {
2069 pw.print(prefix); pw.print("mGivenContentInsets=");
2070 mGivenContentInsets.printShortString(pw);
2071 pw.print(" mGivenVisibleInsets=");
2072 mGivenVisibleInsets.printShortString(pw);
2073 pw.println();
2074 if (mTouchableInsets != 0 || mGivenInsetsPending) {
2075 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
2076 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07002077 Region region = new Region();
2078 getTouchableRegion(region);
2079 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002080 }
2081 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Wale Ogunwale7c726682015-02-06 17:34:28 -08002082 if (mOverrideConfig != Configuration.EMPTY) {
2083 pw.print(prefix); pw.print("mOverrideConfig="); pw.println(mOverrideConfig);
2084 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002085 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07002086 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07002087 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Craig Mautner178af592012-09-17 10:37:29 -07002088 pw.print(" isReadyForDisplay()="); pw.println(isReadyForDisplay());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002089 if (dumpAll) {
2090 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
2091 pw.print(" last="); mLastFrame.printShortString(pw);
2092 pw.println();
2093 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002094 if (mEnforceSizeCompat) {
2095 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002096 pw.println();
2097 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002098 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002099 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002100 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002101 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002102 pw.println();
2103 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
2104 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002105 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002106 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002107 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002108 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04002109 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
2110 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002111 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
2112 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002113 pw.print(prefix); pw.print("Cur insets: overscan=");
2114 mOverscanInsets.printShortString(pw);
2115 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002116 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002117 pw.print(" stable="); mStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002118 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002119 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002120 pw.print(prefix); pw.print("Lst insets: overscan=");
2121 mLastOverscanInsets.printShortString(pw);
2122 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002123 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002124 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002125 pw.print(" physical="); mLastOutsets.printShortString(pw);
2126 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002127 pw.println();
2128 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07002129 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
2130 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002131 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
2132 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
2133 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
2134 pw.print(" mDestroying="); pw.print(mDestroying);
2135 pw.print(" mRemoved="); pw.println(mRemoved);
2136 }
2137 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
2138 pw.print(prefix); pw.print("mOrientationChanging=");
2139 pw.print(mOrientationChanging);
2140 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
2141 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
2142 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07002143 if (mLastFreezeDuration != 0) {
2144 pw.print(prefix); pw.print("mLastFreezeDuration=");
2145 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
2146 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002147 if (mHScale != 1 || mVScale != 1) {
2148 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
2149 pw.print(" mVScale="); pw.println(mVScale);
2150 }
2151 if (mWallpaperX != -1 || mWallpaperY != -1) {
2152 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
2153 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
2154 }
2155 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
2156 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
2157 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
2158 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07002159 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
2160 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
2161 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
2162 pw.print(mWallpaperDisplayOffsetX);
2163 pw.print(" mWallpaperDisplayOffsetY=");
2164 pw.println(mWallpaperDisplayOffsetY);
2165 }
Jeff Brownc2932a12014-11-20 18:04:05 -08002166 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07002167 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08002168 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002169 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002170
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002171 String makeInputChannelName() {
2172 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002173 + " " + getWindowTag();
2174 }
2175
Robert Carra1eb4392015-12-10 12:43:51 -08002176 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002177 CharSequence tag = mAttrs.getTitle();
2178 if (tag == null || tag.length() <= 0) {
2179 tag = mAttrs.packageName;
2180 }
2181 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002182 }
2183
2184 @Override
2185 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002186 final CharSequence title = getWindowTag();
Dianne Hackbornc2293022013-02-06 23:14:49 -08002187 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mExiting) {
2188 mLastTitle = title;
Dianne Hackborn529e7442012-11-01 14:22:28 -07002189 mWasExiting = mExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002190 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -07002191 + " u" + UserHandle.getUserId(mSession.mUid)
Craig Mautnera987d432012-10-11 14:07:58 -07002192 + " " + mLastTitle + (mExiting ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002193 }
2194 return mStringNameCache;
2195 }
Robert Carr58f29132015-10-29 14:19:05 -07002196
2197 void transformFromScreenToSurfaceSpace(Rect rect) {
2198 if (mHScale >= 0) {
2199 rect.right = rect.left + (int)((rect.right - rect.left) / mHScale);
2200 }
2201 if (mVScale >= 0) {
2202 rect.bottom = rect.top + (int)((rect.bottom - rect.top) / mVScale);
2203 }
2204 }
Robert Carr31e28482015-12-02 16:53:18 -08002205
2206 void applyGravityAndUpdateFrame() {
2207 final int pw = mContainingFrame.width();
2208 final int ph = mContainingFrame.height();
2209 final Task task = getTask();
2210 final boolean nonFullscreenTask = task != null && !task.isFullscreen();
2211
2212 float x, y;
2213 int w,h;
2214
2215 if ((mAttrs.flags & FLAG_SCALED) != 0) {
2216 if (mAttrs.width < 0) {
2217 w = pw;
2218 } else if (mEnforceSizeCompat) {
2219 w = (int)(mAttrs.width * mGlobalScale + .5f);
2220 } else {
2221 w = mAttrs.width;
2222 }
2223 if (mAttrs.height < 0) {
2224 h = ph;
2225 } else if (mEnforceSizeCompat) {
2226 h = (int)(mAttrs.height * mGlobalScale + .5f);
2227 } else {
2228 h = mAttrs.height;
2229 }
2230 } else {
2231 if (mAttrs.width == MATCH_PARENT) {
2232 w = pw;
2233 } else if (mEnforceSizeCompat) {
2234 w = (int)(mRequestedWidth * mGlobalScale + .5f);
2235 } else {
2236 w = mRequestedWidth;
2237 }
2238 if (mAttrs.height == MATCH_PARENT) {
2239 h = ph;
2240 } else if (mEnforceSizeCompat) {
2241 h = (int)(mRequestedHeight * mGlobalScale + .5f);
2242 } else {
2243 h = mRequestedHeight;
2244 }
2245 }
2246
2247 if (mEnforceSizeCompat) {
2248 x = mAttrs.x * mGlobalScale;
2249 y = mAttrs.y * mGlobalScale;
2250 } else {
2251 x = mAttrs.x;
2252 y = mAttrs.y;
2253 }
2254
2255 if (nonFullscreenTask) {
2256 // Make sure window fits in containing frame since it is in a non-fullscreen stack as
2257 // required by {@link Gravity#apply} call.
2258 w = Math.min(w, pw);
2259 h = Math.min(h, ph);
2260 }
2261
2262 // Set mFrame
2263 Gravity.apply(mAttrs.gravity, w, h, mContainingFrame,
2264 (int) (x + mAttrs.horizontalMargin * pw),
2265 (int) (y + mAttrs.verticalMargin * ph), mFrame);
2266
2267 // Now make sure the window fits in the overall display frame.
2268 Gravity.applyDisplay(mAttrs.gravity, mDisplayFrame, mFrame);
2269 }
Robert Carr51a1b872015-12-08 14:03:13 -08002270
2271 boolean isChildWindow() {
2272 return mAttachedWindow != null;
2273 }
Robert Carra1eb4392015-12-10 12:43:51 -08002274
2275 void setReplacing(boolean animate) {
2276 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) == 0) {
2277 mWillReplaceWindow = true;
2278 mReplacingWindow = null;
2279 mAnimateReplacingWindow = animate;
2280 }
2281 }
satokcef37fb2011-10-24 21:49:38 +09002282}