blob: 498259f4cfa62d7cec10852f956da95d0748a6cf [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 Ogunwale79f268d2015-12-18 08:25:47 -0800606 final boolean fullscreenTask = task == null || task.isFullscreen();
Chong Zhang09b21ef2015-09-14 10:20:21 -0700607 final boolean freeformWorkspace = task != null && task.inFreeformWorkspace();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800608
609 if (fullscreenTask || isChildWindow()) {
610 // We use the parent frame as the containing frame for fullscreen and child windows
611 mContainingFrame.set(pf);
612 mDisplayFrame.set(df);
613 } else {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700614 task.getBounds(mContainingFrame);
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800615 final WindowState imeWin = mService.mInputMethodWindow;
616 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this
617 && mContainingFrame.bottom > cf.bottom) {
618 // IME is up and obscuring this window. Adjust the window position so it is visible.
619 mContainingFrame.top -= mContainingFrame.bottom - cf.bottom;
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700620 }
Skuhne81c524a2015-08-12 13:34:14 -0700621
Skuhnef932e562015-08-20 12:07:30 -0700622 if (freeformWorkspace) {
Skuhne81c524a2015-08-12 13:34:14 -0700623 // In free form mode we have only to set the rectangle if it wasn't set already. No
624 // need to intersect it with the (visible) "content frame" since it is allowed to
625 // be outside the visible desktop.
626 if (mContainingFrame.isEmpty()) {
627 mContainingFrame.set(cf);
628 }
Doris Liu06d582d2015-06-01 13:18:43 -0700629 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800630 mDisplayFrame.set(mContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700631 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800632
Craig Mautner967212c2013-04-13 21:10:58 -0700633 final int pw = mContainingFrame.width();
634 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800635
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800636 if (!mParentFrame.equals(pf)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800637 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800638 // + " to " + pf);
639 mParentFrame.set(pf);
640 mContentChanged = true;
641 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700642 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
643 mLastRequestedWidth = mRequestedWidth;
644 mLastRequestedHeight = mRequestedHeight;
645 mContentChanged = true;
646 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800647
Craig Mautnereda67292013-04-28 13:50:14 -0700648 mOverscanFrame.set(of);
649 mContentFrame.set(cf);
650 mVisibleFrame.set(vf);
John Spurlock46646232013-09-30 22:32:42 -0400651 mDecorFrame.set(dcf);
Adrian Roosfa104232014-06-20 16:10:14 -0700652 mStableFrame.set(sf);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700653 final boolean hasOutsets = osf != null;
654 if (hasOutsets) {
655 mOutsetFrame.set(osf);
656 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800657
Craig Mautnereda67292013-04-28 13:50:14 -0700658 final int fw = mFrame.width();
659 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800660
Robert Carr31e28482015-12-02 16:53:18 -0800661 applyGravityAndUpdateFrame();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800662
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700663 // Calculate the outsets before the content frame gets shrinked to the window frame.
664 if (hasOutsets) {
665 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
666 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
667 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
668 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
669 } else {
670 mOutsets.set(0, 0, 0, 0);
671 }
672
Craig Mautnera248eee2013-05-07 11:41:27 -0700673 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800674 // final window frame.
Skuhnef932e562015-08-20 12:07:30 -0700675 if (freeformWorkspace && !mFrame.isEmpty()) {
Skuhne81c524a2015-08-12 13:34:14 -0700676 // Keep the frame out of the blocked system area, limit it in size to the content area
677 // and make sure that there is always a minimum visible so that the user can drag it
678 // into a usable area..
679 final int height = Math.min(mFrame.height(), mContentFrame.height());
680 final int width = Math.min(mContentFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700681 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700682 final int minVisibleHeight = WindowManagerService.dipToPixel(
683 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics);
684 final int minVisibleWidth = WindowManagerService.dipToPixel(
685 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics);
Skuhne81c524a2015-08-12 13:34:14 -0700686 final int top = Math.max(mContentFrame.top,
687 Math.min(mFrame.top, mContentFrame.bottom - minVisibleHeight));
688 final int left = Math.max(mContentFrame.left + minVisibleWidth - width,
689 Math.min(mFrame.left, mContentFrame.right - minVisibleWidth));
690 mFrame.set(left, top, left + width, top + height);
691 mContentFrame.set(mFrame);
692 mVisibleFrame.set(mContentFrame);
693 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700694 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800695 if (isVisibleLw() || mWinAnimator.isAnimating()) {
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800696 // We don't adjust the dock divider frame for reasons other than performance. The
697 // real reason is that if it gets adjusted before it is shown for the first time,
698 // it would get size (0, 0). This causes a problem when we finally show the dock
699 // divider and try to draw to it. We do set the surface size at that moment to
700 // the correct size, but it's too late for the Surface Flinger to make it
701 // available for view rendering and as a result the renderer receives size 1, 1.
702 // This way we just keep the divider at the original size and Surface Flinger
703 // will return the correct value to the renderer.
704 mDisplayContent.getDockedDividerController().positionDockedStackedDivider(mFrame);
705 mContentFrame.set(mFrame);
706 }
Skuhne81c524a2015-08-12 13:34:14 -0700707 } else {
708 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
709 Math.max(mContentFrame.top, mFrame.top),
710 Math.min(mContentFrame.right, mFrame.right),
711 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800712
Skuhne81c524a2015-08-12 13:34:14 -0700713 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
714 Math.max(mVisibleFrame.top, mFrame.top),
715 Math.min(mVisibleFrame.right, mFrame.right),
716 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800717
Skuhne81c524a2015-08-12 13:34:14 -0700718 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
719 Math.max(mStableFrame.top, mFrame.top),
720 Math.min(mStableFrame.right, mFrame.right),
721 Math.min(mStableFrame.bottom, mFrame.bottom));
722 }
Adrian Roosfa104232014-06-20 16:10:14 -0700723
Craig Mautnerc36c8e62013-05-10 13:33:31 -0700724 mOverscanInsets.set(Math.max(mOverscanFrame.left - mFrame.left, 0),
725 Math.max(mOverscanFrame.top - mFrame.top, 0),
Adrian Roos3236f3a2014-12-09 15:06:40 +0000726 Math.max(mFrame.right - mOverscanFrame.right, 0),
727 Math.max(mFrame.bottom - mOverscanFrame.bottom, 0));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800728
Craig Mautnereda67292013-04-28 13:50:14 -0700729 mContentInsets.set(mContentFrame.left - mFrame.left,
730 mContentFrame.top - mFrame.top,
731 mFrame.right - mContentFrame.right,
732 mFrame.bottom - mContentFrame.bottom);
733
734 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
735 mVisibleFrame.top - mFrame.top,
736 mFrame.right - mVisibleFrame.right,
737 mFrame.bottom - mVisibleFrame.bottom);
738
Adrian Roosfa104232014-06-20 16:10:14 -0700739 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
740 Math.max(mStableFrame.top - mFrame.top, 0),
741 Math.max(mFrame.right - mStableFrame.right, 0),
742 Math.max(mFrame.bottom - mStableFrame.bottom, 0));
743
Craig Mautnereda67292013-04-28 13:50:14 -0700744 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400745 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700746 // If there is a size compatibility scale being applied to the
747 // window, we need to apply this to its insets so that they are
748 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700749 mOverscanInsets.scale(mInvGlobalScale);
750 mContentInsets.scale(mInvGlobalScale);
751 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700752 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700753 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700754
755 // Also the scaled frame that we report to the app needs to be
756 // adjusted to be in its coordinate space.
757 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400758 }
759
Craig Mautnereda67292013-04-28 13:50:14 -0700760 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800761 final DisplayContent displayContent = getDisplayContent();
762 if (displayContent != null) {
763 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700764 mService.mWallpaperControllerLocked.updateWallpaperOffset(
765 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800766 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800767 }
768
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700769 if (DEBUG_LAYOUT || WindowManagerService.localLOGV) Slog.v(TAG,
770 "Resolving (mRequestedWidth="
771 + mRequestedWidth + ", mRequestedheight="
772 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
773 + "): frame=" + mFrame.toShortString()
774 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -0700775 + " vi=" + mVisibleInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700776 + " vi=" + mStableInsets.toShortString()
777 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800778 }
779
Craig Mautnera2c77052012-03-26 12:14:43 -0700780 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800781 public Rect getFrameLw() {
782 return mFrame;
783 }
784
Craig Mautnera2c77052012-03-26 12:14:43 -0700785 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700786 public Point getShownPositionLw() {
787 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800788 }
789
Craig Mautnera2c77052012-03-26 12:14:43 -0700790 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800791 public Rect getDisplayFrameLw() {
792 return mDisplayFrame;
793 }
794
Craig Mautnera2c77052012-03-26 12:14:43 -0700795 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800796 public Rect getOverscanFrameLw() {
797 return mOverscanFrame;
798 }
799
800 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800801 public Rect getContentFrameLw() {
802 return mContentFrame;
803 }
804
Craig Mautnera2c77052012-03-26 12:14:43 -0700805 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800806 public Rect getVisibleFrameLw() {
807 return mVisibleFrame;
808 }
809
Craig Mautnera2c77052012-03-26 12:14:43 -0700810 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800811 public boolean getGivenInsetsPendingLw() {
812 return mGivenInsetsPending;
813 }
814
Craig Mautnera2c77052012-03-26 12:14:43 -0700815 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800816 public Rect getGivenContentInsetsLw() {
817 return mGivenContentInsets;
818 }
819
Craig Mautnera2c77052012-03-26 12:14:43 -0700820 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800821 public Rect getGivenVisibleInsetsLw() {
822 return mGivenVisibleInsets;
823 }
824
Craig Mautnera2c77052012-03-26 12:14:43 -0700825 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800826 public WindowManager.LayoutParams getAttrs() {
827 return mAttrs;
828 }
829
Craig Mautner812d2ca2012-09-27 15:35:34 -0700830 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800831 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
832 int index = -1;
833 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -0700834 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800835 while (true) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -0700836 if (ws.mAttrs.needsMenuKey != WindowManager.LayoutParams.NEEDS_MENU_UNSET) {
837 return ws.mAttrs.needsMenuKey == WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800838 }
839 // If we reached the bottom of the range of windows we are considering,
840 // assume no menu is needed.
841 if (ws == bottom) {
842 return false;
843 }
844 // The current window hasn't specified whether menu key is needed;
845 // look behind it.
846 // First, we may need to determine the starting position.
847 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -0700848 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800849 }
850 index--;
851 if (index < 0) {
852 return false;
853 }
Craig Mautner59c00972012-07-30 12:10:24 -0700854 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800855 }
856 }
857
Craig Mautner19d59bc2012-09-04 11:15:56 -0700858 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700859 public int getSystemUiVisibility() {
860 return mSystemUiVisibility;
861 }
862
Craig Mautner19d59bc2012-09-04 11:15:56 -0700863 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800864 public int getSurfaceLayer() {
865 return mLayer;
866 }
867
Craig Mautner812d2ca2012-09-27 15:35:34 -0700868 @Override
Selim Cinekd6623612015-05-22 18:56:22 -0700869 public int getBaseType() {
870 WindowState win = this;
Robert Carr51a1b872015-12-08 14:03:13 -0800871 while (win.isChildWindow()) {
Selim Cinekd6623612015-05-22 18:56:22 -0700872 win = win.mAttachedWindow;
873 }
874 return win.mAttrs.type;
875 }
876
877 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800878 public IApplicationToken getAppToken() {
879 return mAppToken != null ? mAppToken.appToken : null;
880 }
Craig Mautner19d59bc2012-09-04 11:15:56 -0700881
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700882 @Override
883 public boolean isVoiceInteraction() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700884 return mAppToken != null && mAppToken.voiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700885 }
886
Craig Mautner4c5eb222013-11-18 12:59:05 -0800887 boolean setInsetsChanged() {
888 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
889 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
890 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -0700891 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700892 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
893 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
894 || mOutsetsChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -0800895 }
896
Craig Mautnerdf88d732014-01-27 09:21:32 -0800897 public DisplayContent getDisplayContent() {
Chad Jonesf391ebc2014-06-12 17:45:05 -0700898 if (mAppToken == null || mNotOnAppsDisplay) {
Craig Mautnerbe634952014-06-12 13:39:24 -0700899 return mDisplayContent;
900 }
901 final TaskStack stack = getStack();
902 return stack == null ? mDisplayContent : stack.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -0800903 }
904
Chong Zhang09b21ef2015-09-14 10:20:21 -0700905 public DisplayInfo getDisplayInfo() {
906 final DisplayContent displayContent = getDisplayContent();
907 return displayContent != null ? displayContent.getDisplayInfo() : null;
908 }
909
Craig Mautner19d59bc2012-09-04 11:15:56 -0700910 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800911 final DisplayContent displayContent = getDisplayContent();
912 if (displayContent == null) {
913 return -1;
914 }
915 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -0700916 }
917
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700918 Task getTask() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700919 return mAppToken != null ? mAppToken.mTask : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700920 }
921
922 TaskStack getStack() {
923 Task task = getTask();
924 if (task != null) {
925 if (task.mStack != null) {
926 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -0700927 }
Craig Mautnerd9a22882013-03-16 15:00:36 -0700928 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700929 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
930 // associate them with some stack to enable dimming.
931 return mAttrs.type >= WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
932 && mDisplayContent != null ? mDisplayContent.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -0700933 }
934
Skuhnef932e562015-08-20 12:07:30 -0700935 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700936 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -0700937 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -0700938 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800939 void getVisibleBounds(Rect bounds) {
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700940 boolean intersectWithStackBounds = mAppToken != null && mAppToken.mCropWindowsToStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700941 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700942 mTmpRect.setEmpty();
943 if (intersectWithStackBounds) {
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700944 final TaskStack stack = getStack();
945 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800946 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700947 } else {
948 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700949 }
950 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700951
Chong Zhang9184ec62015-09-24 12:32:21 -0700952 bounds.set(mVisibleFrame);
953 if (intersectWithStackBounds) {
954 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700955 }
956
Wale Ogunwale61b009e2015-09-16 15:43:05 -0700957 if (bounds.isEmpty()) {
958 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700959 if (intersectWithStackBounds) {
960 bounds.intersect(mTmpRect);
961 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -0800962 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700963 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -0700964 }
965
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800966 public long getInputDispatchingTimeoutNanos() {
967 return mAppToken != null
968 ? mAppToken.inputDispatchingTimeoutNanos
969 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
970 }
971
Craig Mautnere8552142012-11-07 13:55:47 -0800972 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800973 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -0700974 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800975 }
976
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800977 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
978 if (dsdx < .99999f || dsdx > 1.00001f) return false;
979 if (dtdy < .99999f || dtdy > 1.00001f) return false;
980 if (dtdx < -.000001f || dtdx > .000001f) return false;
981 if (dsdy < -.000001f || dsdy > .000001f) return false;
982 return true;
983 }
984
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400985 void prelayout() {
986 if (mEnforceSizeCompat) {
987 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700988 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400989 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700990 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400991 }
992 }
993
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800994 /**
995 * Is this window visible? It is not visible if there is no
996 * surface, or we are in the process of running an exit animation
997 * that will remove the surface, or its app token has been hidden.
998 */
Craig Mautner88400d32012-09-30 12:35:45 -0700999 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001000 public boolean isVisibleLw() {
1001 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001002 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001003 && (atoken == null || !atoken.hiddenRequested)
1004 && !mExiting && !mDestroying;
1005 }
1006
1007 /**
1008 * Like {@link #isVisibleLw}, but also counts a window that is currently
1009 * "hidden" behind the keyguard as visible. This allows us to apply
1010 * things like window flags that impact the keyguard.
1011 * XXX I am starting to think we need to have ANOTHER visibility flag
1012 * for this "hidden behind keyguard" state rather than overloading
1013 * mPolicyVisibility. Ungh.
1014 */
Craig Mautner88400d32012-09-30 12:35:45 -07001015 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001016 public boolean isVisibleOrBehindKeyguardLw() {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001017 if (mRootToken.waitingToShow &&
Craig Mautner164d4bb2012-11-26 13:51:23 -08001018 mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001019 return false;
1020 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001021 final AppWindowToken atoken = mAppToken;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001022 final boolean animating = atoken != null && atoken.mAppAnimator.animation != null;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001023 return mHasSurface && !mDestroying && !mExiting
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001024 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001025 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
1026 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001027 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001028 }
1029
1030 /**
1031 * Is this window visible, ignoring its app token? It is not visible
1032 * if there is no surface, or we are in the process of running an exit animation
1033 * that will remove the surface.
1034 */
1035 public boolean isWinVisibleLw() {
1036 final AppWindowToken atoken = mAppToken;
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001037 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautner59431632012-04-04 11:56:44 -07001038 && (atoken == null || !atoken.hiddenRequested || atoken.mAppAnimator.animating)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001039 && !mExiting && !mDestroying;
1040 }
1041
1042 /**
1043 * The same as isVisible(), but follows the current hidden state of
1044 * the associated app token, not the pending requested hidden state.
1045 */
1046 boolean isVisibleNow() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001047 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07001048 && (!mRootToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
1049 && !mExiting && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001050 }
1051
1052 /**
1053 * Can this window possibly be a drag/drop target? The test here is
1054 * a combination of the above "visible now" with the check that the
1055 * Input Manager uses when discarding windows from input consideration.
1056 */
1057 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001058 return isVisibleNow() && !mRemoved
1059 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001060 }
1061
1062 /**
1063 * Same as isVisible(), but we also count it as visible between the
1064 * call to IWindowSession.add() and the first relayout().
1065 */
1066 boolean isVisibleOrAdding() {
1067 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001068 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001069 && mPolicyVisibility && !mAttachedHidden
1070 && (atoken == null || !atoken.hiddenRequested)
1071 && !mExiting && !mDestroying;
1072 }
1073
1074 /**
1075 * Is this window currently on-screen? It is on-screen either if it
1076 * is visible or it is currently running an animation before no longer
1077 * being visible.
1078 */
1079 boolean isOnScreen() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001080 return mPolicyVisibility && isOnScreenIgnoringKeyguard();
1081 }
1082
1083 /**
1084 * Like isOnScreen(), but ignores any force hiding of the window due
1085 * to the keyguard.
1086 */
1087 boolean isOnScreenIgnoringKeyguard() {
1088 if (!mHasSurface || mDestroying) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001089 return false;
1090 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001091 final AppWindowToken atoken = mAppToken;
1092 if (atoken != null) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001093 return ((!mAttachedHidden && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001094 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001095 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001096 return !mAttachedHidden || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001097 }
1098
1099 /**
1100 * Like isOnScreen(), but we don't return true if the window is part
1101 * of a transition that has not yet been started.
1102 */
1103 boolean isReadyForDisplay() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001104 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001105 return false;
1106 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001107 return mHasSurface && mPolicyVisibility && !mDestroying
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001108 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
1109 && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001110 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001111 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001112 }
1113
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001114 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001115 * Like isReadyForDisplay(), but ignores any force hiding of the window due
1116 * to the keyguard.
1117 */
1118 boolean isReadyForDisplayIgnoringKeyguard() {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001119 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001120 return false;
1121 }
1122 final AppWindowToken atoken = mAppToken;
1123 if (atoken == null && !mPolicyVisibility) {
1124 // If this is not an app window, and the policy has asked to force
1125 // hide, then we really do want to hide.
1126 return false;
1127 }
1128 return mHasSurface && !mDestroying
1129 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
1130 && !mRootToken.hidden)
1131 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -07001132 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
1133 && !mWinAnimator.isDummyAnimation()));
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001134 }
1135
1136 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001137 * Like isOnScreen, but returns false if the surface hasn't yet
1138 * been drawn.
1139 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001140 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001141 public boolean isDisplayedLw() {
1142 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001143 return isDrawnLw() && mPolicyVisibility
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001144 && ((!mAttachedHidden &&
1145 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001146 || mWinAnimator.mAnimating
1147 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001148 }
1149
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001150 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001151 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001152 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001153 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001154 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001155 return mWinAnimator.mAnimation != null
1156 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001157 }
1158
Craig Mautner812d2ca2012-09-27 15:35:34 -07001159 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001160 public boolean isGoneForLayoutLw() {
1161 final AppWindowToken atoken = mAppToken;
1162 return mViewVisibility == View.GONE
1163 || !mRelayoutCalled
1164 || (atoken == null && mRootToken.hidden)
Craig Mautner812d2ca2012-09-27 15:35:34 -07001165 || (atoken != null && (atoken.hiddenRequested || atoken.hidden))
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001166 || mAttachedHidden
Craig Mautner0e415c62013-04-29 16:10:58 -07001167 || (mExiting && !isAnimatingLw())
1168 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001169 }
1170
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001171 /**
1172 * Returns true if the window has a surface that it has drawn a
1173 * complete UI in to.
1174 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001175 public boolean isDrawFinishedLw() {
1176 return mHasSurface && !mDestroying &&
1177 (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING
1178 || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1179 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
1180 }
1181
1182 /**
1183 * Returns true if the window has a surface that it has drawn a
1184 * complete UI in to.
1185 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001186 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001187 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001188 return mHasSurface && !mDestroying &&
Craig Mautner749a7bb2012-04-02 13:49:53 -07001189 (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1190 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001191 }
1192
1193 /**
1194 * Return true if the window is opaque and fully drawn. This indicates
1195 * it may obscure windows behind it.
1196 */
1197 boolean isOpaqueDrawn() {
1198 return (mAttrs.format == PixelFormat.OPAQUE
1199 || mAttrs.type == TYPE_WALLPAPER)
Craig Mautnera2c77052012-03-26 12:14:43 -07001200 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001201 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001202 }
1203
1204 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001205 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001206 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1207 */
Craig Mautner4557c082015-04-27 13:07:40 -07001208 boolean hasMoved() {
1209 return mHasSurface && mContentChanged && !mExiting && !mWinAnimator.mLastHidden
1210 && mService.okToDisplay() && (mFrame.top != mLastFrame.top
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001211 || mFrame.left != mLastFrame.left)
Craig Mautner4557c082015-04-27 13:07:40 -07001212 && (mAttachedWindow == null || !mAttachedWindow.hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001213 }
1214
Chong Zhang0abb20f2015-11-19 14:17:31 -08001215 boolean isObscuringFullscreen(final DisplayInfo displayInfo) {
1216 Task task = getTask();
1217 if (task != null && task.mStack != null && !task.mStack.isFullscreen()) {
1218 return false;
1219 }
1220 if (!isOpaqueDrawn() || !isFrameFullscreen(displayInfo)) {
1221 return false;
1222 }
1223 return true;
1224 }
1225
1226 boolean isFrameFullscreen(final DisplayInfo displayInfo) {
1227 return mFrame.left <= 0 && mFrame.top <= 0
1228 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001229 }
1230
Craig Mautner812d2ca2012-09-27 15:35:34 -07001231 boolean isConfigChanged() {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001232 final Task task = getTask();
Wale Ogunwale60454db2015-01-23 16:05:07 -08001233 final Configuration overrideConfig =
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001234 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001235 final Configuration serviceConfig = mService.mCurConfiguration;
1236 boolean configChanged =
1237 (mConfiguration != serviceConfig && mConfiguration.diff(serviceConfig) != 0)
1238 || (mOverrideConfig != overrideConfig && !mOverrideConfig.equals(overrideConfig));
Craig Mautnere8552142012-11-07 13:55:47 -08001239
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001240 if ((mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Craig Mautnere8552142012-11-07 13:55:47 -08001241 // Retain configuration changed status until resetConfiguration called.
1242 mConfigHasChanged |= configChanged;
1243 configChanged = mConfigHasChanged;
1244 }
1245
1246 return configChanged;
Craig Mautner812d2ca2012-09-27 15:35:34 -07001247 }
1248
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001249 void removeLocked() {
1250 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001251
Robert Carr51a1b872015-12-08 14:03:13 -08001252 if (isChildWindow()) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001253 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001254 mAttachedWindow.mChildWindows.remove(this);
1255 }
Craig Mautner96868332012-12-04 14:29:11 -08001256 mWinAnimator.destroyDeferredSurfaceLocked();
1257 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001258 mSession.windowRemovedLocked();
1259 try {
1260 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1261 } catch (RuntimeException e) {
1262 // Ignore if it has already been removed (usually because
1263 // we are doing this as part of processing a death note.)
1264 }
1265 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001266
Wale Ogunwale60454db2015-01-23 16:05:07 -08001267 private void setConfiguration(
1268 final Configuration newConfig, final Configuration newOverrideConfig) {
Craig Mautnere8552142012-11-07 13:55:47 -08001269 mConfiguration = newConfig;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001270 mOverrideConfig = newOverrideConfig;
Craig Mautnere8552142012-11-07 13:55:47 -08001271 mConfigHasChanged = false;
1272 }
1273
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001274 void setHasSurface(boolean hasSurface) {
1275 mHasSurface = hasSurface;
1276 }
1277
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001278 int getAnimLayerAdjustment() {
1279 if (mTargetAppToken != null) {
1280 return mTargetAppToken.mAppAnimator.animLayerAdjustment;
1281 } else if (mAppToken != null) {
1282 return mAppToken.mAppAnimator.animLayerAdjustment;
1283 } else {
1284 // Nothing is animating, so there is no animation adjustment.
1285 return 0;
1286 }
1287 }
1288
1289 void scheduleAnimationIfDimming() {
1290 if (mDisplayContent == null) {
1291 return;
1292 }
1293 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1294 if (dimLayerUser != null && mDisplayContent.mDimLayerController.isDimming(
1295 dimLayerUser, mWinAnimator)) {
1296 // Force an animation pass just to update the mDimLayer layer.
1297 mService.scheduleAnimationLocked();
1298 }
1299 }
1300
Chong Zhangacf11402015-11-04 16:23:10 -08001301 private final class DeadWindowEventReceiver extends InputEventReceiver {
1302 DeadWindowEventReceiver(InputChannel inputChannel) {
1303 super(inputChannel, mService.mH.getLooper());
1304 }
1305 @Override
1306 public void onInputEvent(InputEvent event) {
1307 finishInputEvent(event, true);
1308 }
1309 }
1310 /**
1311 * Dummy event receiver for windows that died visible.
1312 */
1313 private DeadWindowEventReceiver mDeadWindowEventReceiver;
1314
Chong Zhang112eb8c2015-11-02 11:17:00 -08001315 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001316 if (mInputChannel != null) {
1317 throw new IllegalStateException("Window already has an input channel.");
1318 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001319 String name = makeInputChannelName();
1320 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1321 mInputChannel = inputChannels[0];
1322 mClientChannel = inputChannels[1];
1323 mInputWindowHandle.inputChannel = inputChannels[0];
1324 if (outInputChannel != null) {
1325 mClientChannel.transferTo(outInputChannel);
1326 mClientChannel.dispose();
1327 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08001328 } else {
1329 // If the window died visible, we setup a dummy input channel, so that taps
1330 // can still detected by input monitor channel, and we can relaunch the app.
1331 // Create dummy event receiver that simply reports all events as handled.
1332 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08001333 }
1334 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001335 }
1336
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001337 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08001338 if (mDeadWindowEventReceiver != null) {
1339 mDeadWindowEventReceiver.dispose();
1340 mDeadWindowEventReceiver = null;
1341 }
1342
1343 // unregister server channel first otherwise it complains about broken channel
1344 if (mInputChannel != null) {
1345 mService.mInputManager.unregisterInputChannel(mInputChannel);
1346 mInputChannel.dispose();
1347 mInputChannel = null;
1348 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001349 if (mClientChannel != null) {
1350 mClientChannel.dispose();
1351 mClientChannel = null;
1352 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001353 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001354 }
1355
Chong Zhang112eb8c2015-11-02 11:17:00 -08001356 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08001357 // When the app is terminated (eg. from Recents), the task might have already been
1358 // removed with the window pending removal. Don't apply dim in such cases, as there
1359 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
1360 final AppWindowToken token = mAppToken;
1361 if (token != null && token.removed) {
1362 return;
1363 }
1364
Chong Zhang112eb8c2015-11-02 11:17:00 -08001365 if (!mExiting && mAppDied) {
1366 // If app died visible, apply a dim over the window to indicate that it's inactive
1367 mDisplayContent.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
1368 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
1369 && mDisplayContent != null && !mExiting && isDisplayedLw()) {
1370 mDisplayContent.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001371 }
1372 }
1373
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001374 DimLayer.DimLayerUser getDimLayerUser() {
1375 Task task = getTask();
1376 if (task != null) {
1377 return task;
1378 }
1379 return getStack();
1380 }
1381
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001382 void maybeRemoveReplacedWindow() {
Robert Carra1eb4392015-12-10 12:43:51 -08001383 if (mAppToken == null) {
1384 return;
1385 }
1386 for (int i = mAppToken.allAppWindows.size() - 1; i >= 0; i--) {
1387 final WindowState win = mAppToken.allAppWindows.get(i);
1388 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + win);
1389 if (win.mWillReplaceWindow && win.mReplacingWindow == this) {
1390 win.mWillReplaceWindow = false;
1391 win.mAnimateReplacingWindow = false;
1392 win.mReplacingRemoveRequested = false;
1393 win.mReplacingWindow = null;
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001394 if (win.mExiting) {
1395 mService.removeWindowInnerLocked(win);
1396 }
1397 }
1398 }
1399 }
1400
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07001401 void setDisplayLayoutNeeded() {
1402 if (mDisplayContent != null) {
1403 mDisplayContent.layoutNeeded = true;
1404 }
1405 }
1406
Filip Gruszczynski955b2fc2015-10-15 14:46:07 -07001407 boolean inDockedWorkspace() {
Chong Zhangb15758a2015-11-17 12:12:03 -08001408 Task task = getTask();
1409 return task != null && task.inDockedWorkspace();
1410 }
1411
1412 boolean isDockedInEffect() {
1413 Task task = getTask();
1414 return task != null && task.isDockedInEffect();
Filip Gruszczynski955b2fc2015-10-15 14:46:07 -07001415 }
1416
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001417 int getTouchableRegion(Region region, int flags) {
1418 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001419 if (modal && mAppToken != null) {
1420 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001421 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001422 // If this is a modal window we need to dismiss it if it's not full screen and the
1423 // touch happens outside of the frame that displays the content. This means we
1424 // need to intercept touches outside of that window. The dim layer user
1425 // associated with the window (task or stack) will give us the good bounds, as
1426 // they would be used to display the dim layer.
1427 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1428 if (dimLayerUser != null) {
1429 dimLayerUser.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001430 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001431 getVisibleBounds(mTmpRect);
1432 }
1433 if (inFreeformWorkspace()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001434 // For freeform windows we the touch region to include the whole surface for the
1435 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001436 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
1437 final int delta = WindowManagerService.dipToPixel(
1438 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
1439 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001440 }
1441 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001442 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001443 } else {
1444 // Not modal or full screen modal
1445 getTouchableRegion(region);
1446 }
1447 return flags;
1448 }
1449
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001450 void checkPolicyVisibilityChange() {
1451 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
1452 if (DEBUG_VISIBILITY) {
1453 Slog.v(TAG, "Policy visibility changing after anim in " +
1454 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
1455 }
1456 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001457 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001458 if (!mPolicyVisibility) {
1459 if (mService.mCurrentFocus == this) {
1460 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
1461 "setAnimationLocked: setting mFocusMayChange true");
1462 mService.mFocusMayChange = true;
1463 }
1464 // Window is no longer visible -- make sure if we were waiting
1465 // for it to be displayed before enabling the display, that
1466 // we allow the display to be enabled now.
1467 mService.enableScreenIfNeededLocked();
1468 }
1469 }
1470 }
1471
1472 void setRequestedSize(int requestedWidth, int requestedHeight) {
1473 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
1474 mLayoutNeeded = true;
1475 mRequestedWidth = requestedWidth;
1476 mRequestedHeight = requestedHeight;
1477 }
1478 }
1479
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001480 void prepareWindowToDisplayDuringRelayout(Configuration outConfig) {
1481 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
1482 == SOFT_INPUT_ADJUST_RESIZE) {
1483 mLayoutNeeded = true;
1484 }
1485 if (isDrawnLw() && mService.okToDisplay()) {
1486 mWinAnimator.applyEnterAnimationLocked();
1487 }
1488 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
1489 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
1490 mTurnOnScreen = true;
1491 }
1492 if (isConfigChanged()) {
1493 if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + this + " visible with new config: "
1494 + mService.mCurConfiguration);
1495 outConfig.setTo(mService.mCurConfiguration);
1496 }
1497 }
1498
1499 void adjustStartingWindowFlags() {
1500 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
1501 && mAppToken.startingWindow != null) {
1502 // Special handling of starting window over the base
1503 // window of the app: propagate lock screen flags to it,
1504 // to provide the correct semantics while starting.
1505 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
1506 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
1507 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
1508 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
1509 }
1510 }
1511
1512 void setWindowScale(int requestedWidth, int requestedHeight) {
1513 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
1514
1515 if (scaledWindow) {
1516 // requested{Width|Height} Surface's physical size
1517 // attrs.{width|height} Size on screen
1518 // TODO: We don't check if attrs != null here. Is it implicitly checked?
1519 mHScale = (mAttrs.width != requestedWidth) ?
1520 (mAttrs.width / (float)requestedWidth) : 1.0f;
1521 mVScale = (mAttrs.height != requestedHeight) ?
1522 (mAttrs.height / (float)requestedHeight) : 1.0f;
1523 } else {
1524 mHScale = mVScale = 1;
1525 }
1526 }
1527
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001528 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08001529 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001530 public void binderDied() {
1531 try {
1532 synchronized(mService.mWindowMap) {
1533 WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07001534 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001535 if (win != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001536 if (win.mAppToken != null && !win.mAppToken.clientHidden) {
1537 win.mAppToken.appDied = true;
1538 }
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001539 mService.removeWindowLocked(win);
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001540 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08001541 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001542 mService.removeWindowLocked(WindowState.this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001543 }
1544 }
1545 } catch (IllegalArgumentException ex) {
1546 // This will happen if the window has already been
1547 // removed.
1548 }
1549 }
1550 }
1551
Wale Ogunwaled045c822015-12-02 09:14:28 -08001552 /** @return true if this window desires key events. */
1553 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08001554 return isVisibleOrAdding()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001555 && (mViewVisibility == View.VISIBLE)
Wale Ogunwaled045c822015-12-02 09:14:28 -08001556 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
1557 && stackCanReceiveKeys();
1558 }
1559
1560 boolean stackCanReceiveKeys() {
1561 final TaskStack stack = getStack();
1562 return stack != null && StackId.canReceiveKeys(stack.mStackId);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001563 }
1564
Craig Mautner749a7bb2012-04-02 13:49:53 -07001565 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001566 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001567 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001568 }
1569
Craig Mautner749a7bb2012-04-02 13:49:53 -07001570 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001571 public boolean showLw(boolean doAnimation) {
1572 return showLw(doAnimation, true);
1573 }
1574
1575 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07001576 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001577 return false;
1578 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001579 if (!mAppOpVisibility) {
1580 // Being hidden due to app op request.
1581 return false;
1582 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001583 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001584 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001585 return false;
1586 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001587 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001588 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001589 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07001590 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07001591 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001592 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07001593 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001594 // Check for the case where we are currently visible and
1595 // not animating; we do not want to do animation at such a
1596 // point to become visible when we already are.
1597 doAnimation = false;
1598 }
1599 }
1600 mPolicyVisibility = true;
1601 mPolicyVisibilityAfterAnim = true;
1602 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001603 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001604 }
1605 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001606 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001607 }
1608 return true;
1609 }
1610
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001611 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001612 public boolean hideLw(boolean doAnimation) {
1613 return hideLw(doAnimation, true);
1614 }
1615
1616 boolean hideLw(boolean doAnimation, boolean requestAnim) {
1617 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07001618 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001619 doAnimation = false;
1620 }
1621 }
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001622 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
1623 : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001624 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001625 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001626 return false;
1627 }
1628 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001629 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07001630 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001631 doAnimation = false;
1632 }
1633 }
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001634 if (doAnimation) {
1635 mPolicyVisibilityAfterAnim = false;
1636 } else {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001637 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001638 mPolicyVisibilityAfterAnim = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001639 mPolicyVisibility = false;
1640 // Window is no longer visible -- make sure if we were waiting
1641 // for it to be displayed before enabling the display, that
1642 // we allow the display to be enabled now.
1643 mService.enableScreenIfNeededLocked();
1644 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001645 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07001646 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001647 mService.mFocusMayChange = true;
1648 }
1649 }
1650 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001651 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001652 }
1653 return true;
1654 }
1655
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001656 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001657 if (mAppOpVisibility != state) {
1658 mAppOpVisibility = state;
1659 if (state) {
1660 // If the policy visibility had last been to hide, then this
1661 // will incorrectly show at this point since we lost that
1662 // information. Not a big deal -- for the windows that have app
1663 // ops modifies they should only be hidden by policy due to the
1664 // lock screen, and the user won't be changing this if locked.
1665 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001666 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001667 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001668 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001669 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001670 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001671 }
1672
Jeff Brownc2932a12014-11-20 18:04:05 -08001673 public void pokeDrawLockLw(long timeout) {
1674 if (isVisibleOrAdding()) {
1675 if (mDrawLock == null) {
1676 // We want the tag name to be somewhat stable so that it is easier to correlate
1677 // in wake lock statistics. So in particular, we don't want to include the
1678 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001679 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08001680 mDrawLock = mService.mPowerManager.newWakeLock(
1681 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
1682 mDrawLock.setReferenceCounted(false);
1683 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
1684 }
1685 // Each call to acquire resets the timeout.
1686 if (DEBUG_POWER) {
1687 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
1688 + mAttrs.packageName);
1689 }
1690 mDrawLock.acquire(timeout);
1691 } else if (DEBUG_POWER) {
1692 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
1693 + "owned by " + mAttrs.packageName);
1694 }
1695 }
1696
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001697 @Override
1698 public boolean isAlive() {
1699 return mClient.asBinder().isBinderAlive();
1700 }
1701
Craig Mautnera987d432012-10-11 14:07:58 -07001702 boolean isClosing() {
1703 return mExiting || (mService.mClosingApps.contains(mAppToken));
1704 }
1705
Chong Zhangbef461f2015-10-27 11:38:24 -07001706 boolean isAnimatingWithSavedSurface() {
1707 return mAppToken != null && mAppToken.mAnimatingWithSavedSurface;
1708 }
1709
Robert Carr13f7be9e2015-12-02 18:39:45 -08001710 // Returns true if the surface is saved.
1711 boolean destroyOrSaveSurface() {
1712 Task task = getTask();
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001713 if (ActivityManager.isLowRamDeviceStatic()) {
1714 // Don't save surfaces on Svelte devices.
Robert Carr13f7be9e2015-12-02 18:39:45 -08001715 mSurfaceSaved = false;
1716 } else if (task == null || task.inHomeStack()
Chong Zhangd8ceb852015-11-11 14:53:41 -08001717 || task.getTopVisibleAppToken() != mAppToken) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001718 // Don't save surfaces for home stack apps. These usually resume and draw
1719 // first frame very fast. Saving surfaces are mostly a waste of memory.
Chong Zhangbef461f2015-10-27 11:38:24 -07001720 // Don't save if the window is not the topmost window.
Robert Carr13f7be9e2015-12-02 18:39:45 -08001721 mSurfaceSaved = false;
Robert Carr51a1b872015-12-08 14:03:13 -08001722 } else if (isChildWindow()) {
Robert Carr13f7be9e2015-12-02 18:39:45 -08001723 mSurfaceSaved = false;
1724 } else {
1725 mSurfaceSaved = mAppToken.shouldSaveSurface();
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001726 }
Robert Carr13f7be9e2015-12-02 18:39:45 -08001727 if (mSurfaceSaved == false) {
1728 mWinAnimator.destroySurfaceLocked();
1729 }
1730 return mSurfaceSaved;
1731 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001732
Robert Carr13f7be9e2015-12-02 18:39:45 -08001733 public void destroySavedSurface() {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001734 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, "Destroying saved surface: " + this);
Robert Carr13f7be9e2015-12-02 18:39:45 -08001735 if (mSurfaceSaved) {
1736 mWinAnimator.destroySurfaceLocked();
1737 }
1738 }
1739
1740 public boolean hasSavedSurface() {
1741 return mSurfaceSaved;
1742 }
1743
1744 public void restoreSavedSurface() {
1745 mSurfaceSaved = false;
1746 mWinAnimator.mDrawState = WindowStateAnimator.READY_TO_SHOW;
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001747 }
1748
Craig Mautner69b08182012-09-05 13:07:13 -07001749 @Override
1750 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001751 final DisplayContent displayContent = getDisplayContent();
1752 if (displayContent == null) {
1753 // Only a window that was on a non-default display can be detached from it.
1754 return false;
1755 }
Winson Chung47a3e652014-05-21 16:03:42 -07001756 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07001757 }
1758
Adrian Rooscd3884d2015-02-18 17:25:23 +01001759 @Override
1760 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001761 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1762 return dimLayerUser != null && mDisplayContent != null &&
Chong Zhang112eb8c2015-11-02 11:17:00 -08001763 mDisplayContent.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01001764 }
1765
Craig Mautner88400d32012-09-30 12:35:45 -07001766 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
1767 mShowToOwnerOnly = showToOwnerOnly;
1768 }
1769
Craig Mautner5962b122012-10-05 14:45:52 -07001770 boolean isHiddenFromUserLocked() {
Craig Mautner341220f2012-10-16 15:20:09 -07001771 // Attached windows are evaluated based on the window that they are attached to.
1772 WindowState win = this;
Robert Carr51a1b872015-12-08 14:03:13 -08001773 while (win.isChildWindow()) {
Craig Mautner341220f2012-10-16 15:20:09 -07001774 win = win.mAttachedWindow;
1775 }
1776 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -07001777 && win.mAppToken != null && win.mAppToken.showForAllUsers) {
Craig Mautner341220f2012-10-16 15:20:09 -07001778 // Save some cycles by not calling getDisplayInfo unless it is an application
1779 // window intended for all users.
Craig Mautnerdf88d732014-01-27 09:21:32 -08001780 final DisplayContent displayContent = win.getDisplayContent();
1781 if (displayContent == null) {
1782 return true;
1783 }
1784 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Craig Mautner341220f2012-10-16 15:20:09 -07001785 if (win.mFrame.left <= 0 && win.mFrame.top <= 0
1786 && win.mFrame.right >= displayInfo.appWidth
1787 && win.mFrame.bottom >= displayInfo.appHeight) {
Craig Mautner5962b122012-10-05 14:45:52 -07001788 // Is a fullscreen window, like the clock alarm. Show to everyone.
1789 return false;
1790 }
1791 }
1792
Craig Mautner341220f2012-10-16 15:20:09 -07001793 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01001794 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001795 }
1796
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001797 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
1798 outRegion.set(
1799 frame.left + inset.left, frame.top + inset.top,
1800 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001801 }
1802
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001803 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001804 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001805 switch (mTouchableInsets) {
1806 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001807 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001808 outRegion.set(frame);
1809 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001810 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001811 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001812 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001813 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001814 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001815 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001816 case TOUCHABLE_INSETS_REGION: {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001817 final Region givenTouchableRegion = mGivenTouchableRegion;
1818 outRegion.set(givenTouchableRegion);
1819 outRegion.translate(frame.left, frame.top);
1820 break;
1821 }
1822 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001823 cropRegionToStackBoundsIfNeeded(outRegion);
1824 }
1825
1826 void cropRegionToStackBoundsIfNeeded(Region region) {
1827 if (mAppToken == null || !mAppToken.mCropWindowsToStack) {
1828 return;
1829 }
1830
1831 final TaskStack stack = getStack();
1832 if (stack == null) {
1833 return;
1834 }
1835
1836 stack.getDimBounds(mTmpRect);
1837 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001838 }
1839
Craig Mautner59c00972012-07-30 12:10:24 -07001840 WindowList getWindowList() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001841 final DisplayContent displayContent = getDisplayContent();
1842 return displayContent == null ? null : displayContent.getWindowList();
Craig Mautner59c00972012-07-30 12:10:24 -07001843 }
1844
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001845 /**
1846 * Report a focus change. Must be called with no locks held, and consistently
1847 * from the same serialized thread (such as dispatched from a handler).
1848 */
1849 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
1850 try {
1851 mClient.windowFocusChanged(focused, inTouchMode);
1852 } catch (RemoteException e) {
1853 }
1854 if (mFocusCallbacks != null) {
1855 final int N = mFocusCallbacks.beginBroadcast();
1856 for (int i=0; i<N; i++) {
1857 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
1858 try {
1859 if (focused) {
1860 obs.focusGained(mWindowId.asBinder());
1861 } else {
1862 obs.focusLost(mWindowId.asBinder());
1863 }
1864 } catch (RemoteException e) {
1865 }
1866 }
1867 mFocusCallbacks.finishBroadcast();
1868 }
1869 }
1870
Craig Mautnerdf88d732014-01-27 09:21:32 -08001871 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001872 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08001873 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001874 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
1875 + ": " + mCompatFrame);
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001876 final boolean configChanged = isConfigChanged();
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001877 final Task task = getTask();
Wale Ogunwale60454db2015-01-23 16:05:07 -08001878 final Configuration overrideConfig =
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001879 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001880 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) && configChanged) {
1881 Slog.i(TAG, "Sending new config to window " + this + ": "
Robert Carre6a83512015-11-03 16:09:21 -08001882 + " / config="
Wale Ogunwale60454db2015-01-23 16:05:07 -08001883 + mService.mCurConfiguration + " overrideConfig=" + overrideConfig);
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001884 }
Wale Ogunwale60454db2015-01-23 16:05:07 -08001885 setConfiguration(mService.mCurConfiguration, overrideConfig);
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001886 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING)
1887 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
1888
Craig Mautnerdf88d732014-01-27 09:21:32 -08001889 final Rect frame = mFrame;
1890 final Rect overscanInsets = mLastOverscanInsets;
1891 final Rect contentInsets = mLastContentInsets;
1892 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07001893 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001894 final Rect outsets = mLastOutsets;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08001895 final boolean reportDraw = mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING;
1896 final Configuration newConfig = configChanged ? mConfiguration : null;
Chet Haase8eb48d22014-09-24 07:31:29 -07001897 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
1898 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001899 // To prevent deadlock simulate one-way call if win.mClient is a local object.
1900 mService.mH.post(new Runnable() {
1901 @Override
1902 public void run() {
1903 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001904 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
1905 stableInsets, outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001906 } catch (RemoteException e) {
1907 // Not a remote call, RemoteException won't be raised.
1908 }
1909 }
1910 });
1911 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001912 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001913 outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001914 }
Svetoslav4604abc2014-06-10 18:59:30 -07001915
1916 //TODO (multidisplay): Accessibility supported only for the default display.
1917 if (mService.mAccessibilityController != null
1918 && getDisplayId() == Display.DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07001919 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07001920 }
1921
Craig Mautnerdf88d732014-01-27 09:21:32 -08001922 mOverscanInsetsChanged = false;
1923 mContentInsetsChanged = false;
1924 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07001925 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001926 mOutsetsChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001927 mWinAnimator.mSurfaceResized = false;
1928 } catch (RemoteException e) {
1929 mOrientationChanging = false;
1930 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1931 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08001932 // We are assuming the hosting process is dead or in a zombie state.
1933 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
1934 + ", removing this window.");
1935 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07001936 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001937 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001938 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001939 }
1940
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001941 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
1942 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
1943 Configuration newConfig) throws RemoteException {
1944 DisplayInfo displayInfo = getDisplayInfo();
1945 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Chong Zhangd153c4f2015-11-06 20:26:40 -08001946 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
1947 // start even if we haven't received the relayout window, so that the client requests
1948 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
1949 // until the window to small size, otherwise the multithread renderer will shift last
1950 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
1951 // isDragResizing() or isDragResizeChanged() is true.
1952 boolean resizing = isDragResizing() || isDragResizeChanged();
1953 final Rect backDropFrame = (inFreeformWorkspace() || !resizing) ? frame : mTmpRect;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001954 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Chong Zhangd153c4f2015-11-06 20:26:40 -08001955 outsets, reportDraw, newConfig, backDropFrame);
Jorim Jaggi253a20f2015-11-03 12:38:42 +01001956 }
1957
Dianne Hackborne3f23a32013-03-01 13:25:35 -08001958 public void registerFocusObserver(IWindowFocusObserver observer) {
1959 synchronized(mService.mWindowMap) {
1960 if (mFocusCallbacks == null) {
1961 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
1962 }
1963 mFocusCallbacks.register(observer);
1964 }
1965 }
1966
1967 public void unregisterFocusObserver(IWindowFocusObserver observer) {
1968 synchronized(mService.mWindowMap) {
1969 if (mFocusCallbacks != null) {
1970 mFocusCallbacks.unregister(observer);
1971 }
1972 }
1973 }
1974
1975 public boolean isFocused() {
1976 synchronized(mService.mWindowMap) {
1977 return mService.mCurrentFocus == this;
1978 }
1979 }
1980
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07001981 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07001982 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07001983 return task != null && task.inFreeformWorkspace();
1984 }
1985
Chong Zhang3005e752015-09-18 18:46:28 -07001986 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07001987 return mDragResizing != computeDragResizing();
1988 }
1989
Jorim Jaggidcf467c2015-11-05 13:59:32 +01001990 int getResizeMode() {
1991 return mResizeMode;
1992 }
1993
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07001994 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07001995 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07001996 if (task == null) {
1997 return false;
1998 }
1999 if (task.isDragResizing()) {
2000 return true;
2001 }
2002 return mDisplayContent.mDividerControllerLocked.isResizing() &&
2003 !task.inFreeformWorkspace() && !task.isFullscreen();
Chong Zhang3005e752015-09-18 18:46:28 -07002004 }
2005
2006 void setDragResizing() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002007 mDragResizing = computeDragResizing();
Jorim Jaggidcf467c2015-11-05 13:59:32 +01002008 mResizeMode = mDragResizing && mDisplayContent.mDividerControllerLocked.isResizing()
2009 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
2010 : DRAG_RESIZE_MODE_FREEFORM;
Chong Zhang3005e752015-09-18 18:46:28 -07002011 }
2012
2013 boolean isDragResizing() {
2014 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07002015 }
2016
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002017 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08002018 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002019 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08002020 if (stack != null) {
2021 pw.print(" stackId="); pw.print(stack.mStackId);
2022 }
Craig Mautner59c00972012-07-30 12:10:24 -07002023 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002024 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07002025 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08002026 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
2027 pw.print(" package="); pw.print(mAttrs.packageName);
2028 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002029 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002030 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
2031 pw.print(" h="); pw.print(mRequestedHeight);
2032 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07002033 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
2034 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
2035 pw.print(" h="); pw.println(mLastRequestedHeight);
2036 }
Robert Carr51a1b872015-12-08 14:03:13 -08002037 if (isChildWindow() || mLayoutAttached) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002038 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
2039 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
2040 }
2041 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
2042 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
2043 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
2044 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
2045 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
2046 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002047 if (dumpAll) {
2048 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
2049 pw.print(" mSubLayer="); pw.print(mSubLayer);
2050 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautner59431632012-04-04 11:56:44 -07002051 pw.print((mTargetAppToken != null ?
2052 mTargetAppToken.mAppAnimator.animLayerAdjustment
2053 : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002054 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
2055 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08002056 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002057 if (dumpAll) {
2058 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
2059 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
2060 if (mAppToken != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08002061 pw.print(prefix); pw.print("mAppToken="); pw.print(mAppToken);
2062 pw.print(" mAppDied=");pw.println(mAppDied);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002063 }
2064 if (mTargetAppToken != null) {
2065 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
2066 }
2067 pw.print(prefix); pw.print("mViewVisibility=0x");
2068 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002069 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
2070 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07002071 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
2072 pw.print(" mSystemUiVisibility=0x");
2073 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002074 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002075 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
2076 || mAttachedHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002077 pw.print(prefix); pw.print("mPolicyVisibility=");
2078 pw.print(mPolicyVisibility);
2079 pw.print(" mPolicyVisibilityAfterAnim=");
2080 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002081 pw.print(" mAppOpVisibility=");
2082 pw.print(mAppOpVisibility);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002083 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
2084 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08002085 if (!mRelayoutCalled || mLayoutNeeded) {
2086 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
2087 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002088 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002089 if (mXOffset != 0 || mYOffset != 0) {
2090 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
2091 pw.print(" y="); pw.println(mYOffset);
2092 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002093 if (dumpAll) {
2094 pw.print(prefix); pw.print("mGivenContentInsets=");
2095 mGivenContentInsets.printShortString(pw);
2096 pw.print(" mGivenVisibleInsets=");
2097 mGivenVisibleInsets.printShortString(pw);
2098 pw.println();
2099 if (mTouchableInsets != 0 || mGivenInsetsPending) {
2100 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
2101 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07002102 Region region = new Region();
2103 getTouchableRegion(region);
2104 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002105 }
2106 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Wale Ogunwale7c726682015-02-06 17:34:28 -08002107 if (mOverrideConfig != Configuration.EMPTY) {
2108 pw.print(prefix); pw.print("mOverrideConfig="); pw.println(mOverrideConfig);
2109 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002110 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07002111 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07002112 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Craig Mautner178af592012-09-17 10:37:29 -07002113 pw.print(" isReadyForDisplay()="); pw.println(isReadyForDisplay());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002114 if (dumpAll) {
2115 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
2116 pw.print(" last="); mLastFrame.printShortString(pw);
2117 pw.println();
2118 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002119 if (mEnforceSizeCompat) {
2120 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002121 pw.println();
2122 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002123 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002124 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002125 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002126 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002127 pw.println();
2128 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
2129 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002130 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002131 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002132 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002133 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04002134 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
2135 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002136 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
2137 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002138 pw.print(prefix); pw.print("Cur insets: overscan=");
2139 mOverscanInsets.printShortString(pw);
2140 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002141 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002142 pw.print(" stable="); mStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002143 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002144 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002145 pw.print(prefix); pw.print("Lst insets: overscan=");
2146 mLastOverscanInsets.printShortString(pw);
2147 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002148 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002149 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002150 pw.print(" physical="); mLastOutsets.printShortString(pw);
2151 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002152 pw.println();
2153 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07002154 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
2155 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002156 if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
2157 pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
2158 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
2159 pw.print(" mDestroying="); pw.print(mDestroying);
2160 pw.print(" mRemoved="); pw.println(mRemoved);
2161 }
2162 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
2163 pw.print(prefix); pw.print("mOrientationChanging=");
2164 pw.print(mOrientationChanging);
2165 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
2166 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
2167 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07002168 if (mLastFreezeDuration != 0) {
2169 pw.print(prefix); pw.print("mLastFreezeDuration=");
2170 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
2171 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002172 if (mHScale != 1 || mVScale != 1) {
2173 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
2174 pw.print(" mVScale="); pw.println(mVScale);
2175 }
2176 if (mWallpaperX != -1 || mWallpaperY != -1) {
2177 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
2178 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
2179 }
2180 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
2181 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
2182 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
2183 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07002184 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
2185 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
2186 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
2187 pw.print(mWallpaperDisplayOffsetX);
2188 pw.print(" mWallpaperDisplayOffsetY=");
2189 pw.println(mWallpaperDisplayOffsetY);
2190 }
Jeff Brownc2932a12014-11-20 18:04:05 -08002191 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07002192 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08002193 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002194 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002195
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002196 String makeInputChannelName() {
2197 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002198 + " " + getWindowTag();
2199 }
2200
Robert Carra1eb4392015-12-10 12:43:51 -08002201 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002202 CharSequence tag = mAttrs.getTitle();
2203 if (tag == null || tag.length() <= 0) {
2204 tag = mAttrs.packageName;
2205 }
2206 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002207 }
2208
2209 @Override
2210 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002211 final CharSequence title = getWindowTag();
Dianne Hackbornc2293022013-02-06 23:14:49 -08002212 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mExiting) {
2213 mLastTitle = title;
Dianne Hackborn529e7442012-11-01 14:22:28 -07002214 mWasExiting = mExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002215 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -07002216 + " u" + UserHandle.getUserId(mSession.mUid)
Craig Mautnera987d432012-10-11 14:07:58 -07002217 + " " + mLastTitle + (mExiting ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002218 }
2219 return mStringNameCache;
2220 }
Robert Carr58f29132015-10-29 14:19:05 -07002221
2222 void transformFromScreenToSurfaceSpace(Rect rect) {
2223 if (mHScale >= 0) {
2224 rect.right = rect.left + (int)((rect.right - rect.left) / mHScale);
2225 }
2226 if (mVScale >= 0) {
2227 rect.bottom = rect.top + (int)((rect.bottom - rect.top) / mVScale);
2228 }
2229 }
Robert Carr31e28482015-12-02 16:53:18 -08002230
2231 void applyGravityAndUpdateFrame() {
2232 final int pw = mContainingFrame.width();
2233 final int ph = mContainingFrame.height();
2234 final Task task = getTask();
2235 final boolean nonFullscreenTask = task != null && !task.isFullscreen();
2236
2237 float x, y;
2238 int w,h;
2239
2240 if ((mAttrs.flags & FLAG_SCALED) != 0) {
2241 if (mAttrs.width < 0) {
2242 w = pw;
2243 } else if (mEnforceSizeCompat) {
2244 w = (int)(mAttrs.width * mGlobalScale + .5f);
2245 } else {
2246 w = mAttrs.width;
2247 }
2248 if (mAttrs.height < 0) {
2249 h = ph;
2250 } else if (mEnforceSizeCompat) {
2251 h = (int)(mAttrs.height * mGlobalScale + .5f);
2252 } else {
2253 h = mAttrs.height;
2254 }
2255 } else {
2256 if (mAttrs.width == MATCH_PARENT) {
2257 w = pw;
2258 } else if (mEnforceSizeCompat) {
2259 w = (int)(mRequestedWidth * mGlobalScale + .5f);
2260 } else {
2261 w = mRequestedWidth;
2262 }
2263 if (mAttrs.height == MATCH_PARENT) {
2264 h = ph;
2265 } else if (mEnforceSizeCompat) {
2266 h = (int)(mRequestedHeight * mGlobalScale + .5f);
2267 } else {
2268 h = mRequestedHeight;
2269 }
2270 }
2271
2272 if (mEnforceSizeCompat) {
2273 x = mAttrs.x * mGlobalScale;
2274 y = mAttrs.y * mGlobalScale;
2275 } else {
2276 x = mAttrs.x;
2277 y = mAttrs.y;
2278 }
2279
2280 if (nonFullscreenTask) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08002281 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08002282 // required by {@link Gravity#apply} call.
2283 w = Math.min(w, pw);
2284 h = Math.min(h, ph);
2285 }
2286
2287 // Set mFrame
2288 Gravity.apply(mAttrs.gravity, w, h, mContainingFrame,
2289 (int) (x + mAttrs.horizontalMargin * pw),
2290 (int) (y + mAttrs.verticalMargin * ph), mFrame);
2291
2292 // Now make sure the window fits in the overall display frame.
2293 Gravity.applyDisplay(mAttrs.gravity, mDisplayFrame, mFrame);
2294 }
Robert Carr51a1b872015-12-08 14:03:13 -08002295
2296 boolean isChildWindow() {
2297 return mAttachedWindow != null;
2298 }
Robert Carra1eb4392015-12-10 12:43:51 -08002299
2300 void setReplacing(boolean animate) {
2301 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) == 0) {
2302 mWillReplaceWindow = true;
2303 mReplacingWindow = null;
2304 mAnimateReplacingWindow = animate;
2305 }
2306 }
satokcef37fb2011-10-24 21:49:38 +09002307}