blob: e73d547a7b8713d1f081e6dd6d1903d71c50b287 [file] [log] [blame]
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Wale Ogunwale053c8e42015-11-16 14:27:21 -080019import android.app.ActivityManager;
20import android.app.AppOpsManager;
21import android.content.Context;
22import android.content.res.Configuration;
23import android.graphics.Matrix;
24import android.graphics.PixelFormat;
25import android.graphics.Point;
26import android.graphics.Rect;
27import android.graphics.Region;
28import android.os.IBinder;
29import android.os.PowerManager;
30import android.os.RemoteCallbackList;
31import android.os.RemoteException;
32import android.os.SystemClock;
33import android.os.Trace;
34import android.os.UserHandle;
35import android.os.WorkSource;
36import android.util.DisplayMetrics;
37import android.util.Slog;
38import android.util.TimeUtils;
39import android.view.Display;
40import android.view.DisplayInfo;
41import android.view.Gravity;
42import android.view.IApplicationToken;
43import android.view.IWindow;
44import android.view.IWindowFocusObserver;
45import android.view.IWindowId;
46import android.view.InputChannel;
47import android.view.InputEvent;
48import android.view.InputEventReceiver;
49import android.view.View;
50import android.view.ViewTreeObserver;
51import android.view.WindowManager;
52import android.view.WindowManagerPolicy;
53
Jorim Jaggi9511b0f2016-01-29 19:12:44 -080054import com.android.server.input.InputWindowHandle;
55
Wale Ogunwale053c8e42015-11-16 14:27:21 -080056import java.io.PrintWriter;
57import java.util.ArrayList;
58
Wale Ogunwaled045c822015-12-02 09:14:28 -080059import static android.app.ActivityManager.StackId;
Wale Ogunwalea9f9b372016-02-04 18:04:39 -080060import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
Filip Gruszczynski84fa3352016-01-25 16:28:49 -080061import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
Wale Ogunwalecad05a02015-09-25 10:41:44 -070062import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080063import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
64import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
65import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
66import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080067import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080068import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070069import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080070import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Jorim Jaggi5f23a572016-04-22 15:05:50 -070071import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080072import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
73import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080074import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Wale Ogunwale945d1972016-03-23 13:16:41 -070075import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Chong Zhang4d7369a2016-04-25 16:09:14 -070076import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070077import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080078import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080079import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
Robert Carr31e28482015-12-02 16:53:18 -080080import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080081import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080082import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -080083import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
Robert Carra1eb4392015-12-10 12:43:51 -080084import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080085import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
86import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
Robert Carrd1a010f2016-04-07 22:36:22 -070087import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080088import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080089import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070090import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080091import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
92import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
93import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Chong Zhang4d7369a2016-04-25 16:09:14 -070094import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +010095import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
96import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080097import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
98import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
99import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
100import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
101import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
102import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
103import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
104import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
105import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
106import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
107import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
108import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800109
Craig Mautner59c00972012-07-30 12:10:24 -0700110class WindowList extends ArrayList<WindowState> {
Wale Ogunwale33fde7d2016-03-05 22:38:51 -0800111 WindowList() {}
112 WindowList(WindowList windowList) {
113 super(windowList);
114 }
Craig Mautner59c00972012-07-30 12:10:24 -0700115}
116
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800117/**
118 * A window in the window manager.
119 */
Craig Mautnere32c3072012-03-12 15:25:35 -0700120final class WindowState implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800121 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800122
Skuhne81c524a2015-08-12 13:34:14 -0700123 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700124 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
125 // use hard-coded min sizes for now.
126 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
127 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700128
129 // The thickness of a window resize handle outside the window bounds on the free form workspace
130 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700131 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700132
Robert Carr7098dbd2016-02-01 12:31:01 -0800133 static final boolean DEBUG_DISABLE_SAVING_SURFACES = false;
134
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800135 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700136 final WindowManagerPolicy mPolicy;
137 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800138 final Session mSession;
139 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800140 final int mAppOp;
141 // UserId and appId of the owner. Don't display windows of non-current user.
142 final int mOwnerUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800143 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800144 WindowToken mToken;
145 WindowToken mRootToken;
146 AppWindowToken mAppToken;
147 AppWindowToken mTargetAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700148
149 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
150 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800151 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
152 final DeathRecipient mDeathRecipient;
153 final WindowState mAttachedWindow;
Craig Mautner7b1aa772012-11-30 16:14:45 -0800154 final WindowList mChildWindows = new WindowList();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800155 final int mBaseLayer;
156 final int mSubLayer;
157 final boolean mLayoutAttached;
158 final boolean mIsImWindow;
159 final boolean mIsWallpaper;
160 final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700161 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700162 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800163 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700164 int mSystemUiVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800165 boolean mPolicyVisibility = true;
166 boolean mPolicyVisibilityAfterAnim = true;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -0800167 boolean mAppOpVisibility = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800168 boolean mAppFreezing;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800169 boolean mAttachedHidden; // is our parent window hidden?
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800170 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Chong Zhang0275e392015-09-17 10:41:44 -0700171 boolean mDragResizing;
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800172 boolean mDragResizingChangeReported;
Jorim Jaggidcf467c2015-11-05 13:59:32 +0100173 int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700174
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800175 RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
176
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700177 /**
178 * The window size that was requested by the application. These are in
179 * the application's coordinate space (without compatibility scale applied).
180 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800181 int mRequestedWidth;
182 int mRequestedHeight;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700183 int mLastRequestedWidth;
184 int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700185
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800186 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800187 boolean mHaveFrame;
188 boolean mObscured;
189 boolean mTurnOnScreen;
190
191 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700192
Wale Ogunwale60454db2015-01-23 16:05:07 -0800193 private Configuration mConfiguration = Configuration.EMPTY;
194 private Configuration mOverrideConfig = Configuration.EMPTY;
Robert Carrc24d8f92016-02-29 16:24:33 -0800195 // Represents the changes from our override configuration applied
196 // to the global configuration. This is the only form of configuration
197 // which is suitable for delivery to the client.
198 private Configuration mMergedConfiguration = new Configuration();
Craig Mautnere8552142012-11-07 13:55:47 -0800199 // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned.
200 // Used only on {@link #TYPE_KEYGUARD}.
201 private boolean mConfigHasChanged;
Craig Mautnera2c77052012-03-26 12:14:43 -0700202
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700203 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700204 * Actual position of the surface shown on-screen (may be modified by animation). These are
205 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700206 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700207 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800208
209 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700210 * Insets that determine the actually visible area. These are in the application's
211 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800212 */
213 final Rect mVisibleInsets = new Rect();
214 final Rect mLastVisibleInsets = new Rect();
215 boolean mVisibleInsetsChanged;
216
217 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700218 * Insets that are covered by system windows (such as the status bar) and
219 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700220 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800221 */
222 final Rect mContentInsets = new Rect();
223 final Rect mLastContentInsets = new Rect();
224 boolean mContentInsetsChanged;
225
226 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800227 * Insets that determine the area covered by the display overscan region. These are in the
228 * application's coordinate space (without compatibility scale applied).
229 */
230 final Rect mOverscanInsets = new Rect();
231 final Rect mLastOverscanInsets = new Rect();
232 boolean mOverscanInsetsChanged;
233
234 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700235 * Insets that determine the area covered by the stable system windows. These are in the
236 * application's coordinate space (without compatibility scale applied).
237 */
238 final Rect mStableInsets = new Rect();
239 final Rect mLastStableInsets = new Rect();
240 boolean mStableInsetsChanged;
241
242 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700243 * Outsets determine the area outside of the surface where we want to pretend that it's possible
244 * to draw anyway.
245 */
246 final Rect mOutsets = new Rect();
247 final Rect mLastOutsets = new Rect();
248 boolean mOutsetsChanged = false;
249
250 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800251 * Set to true if we are waiting for this window to receive its
252 * given internal insets before laying out other windows based on it.
253 */
254 boolean mGivenInsetsPending;
255
256 /**
257 * These are the content insets that were given during layout for
258 * this window, to be applied to windows behind it.
259 */
260 final Rect mGivenContentInsets = new Rect();
261
262 /**
263 * These are the visible insets that were given during layout for
264 * this window, to be applied to windows behind it.
265 */
266 final Rect mGivenVisibleInsets = new Rect();
267
268 /**
269 * This is the given touchable area relative to the window frame, or null if none.
270 */
271 final Region mGivenTouchableRegion = new Region();
272
273 /**
274 * Flag indicating whether the touchable region should be adjusted by
275 * the visible insets; if false the area outside the visible insets is
276 * NOT touchable, so we must use those to adjust the frame during hit
277 * tests.
278 */
279 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
280
281 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400282 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700283 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800284 float mHScale=1, mVScale=1;
285 float mLastHScale=1, mLastVScale=1;
286 final Matrix mTmpMatrix = new Matrix();
287
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700288 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800289 final Rect mFrame = new Rect();
290 final Rect mLastFrame = new Rect();
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700291 // Frame that is scaled to the application's coordinate space when in
292 // screen size compatibility mode.
293 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800294
295 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700296
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800297 final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700298
Wale Ogunwale94596652015-02-06 19:27:34 -0800299 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
300 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700301 final Rect mDisplayFrame = new Rect();
302
303 // The region of the display frame that the display type supports displaying content on. This
304 // is mostly a special case for TV where some displays don’t have the entire display usable.
305 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
306 // window display contents to extend into the overscan region.
307 final Rect mOverscanFrame = new Rect();
308
309 // The display frame minus the stable insets. This value is always constant regardless of if
310 // the status bar or navigation bar is visible.
Adrian Roosfa104232014-06-20 16:10:14 -0700311 final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800312
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700313 // The area not occupied by the status and navigation bars. So, if both status and navigation
314 // bars are visible, the decor frame is equal to the stable frame.
315 final Rect mDecorFrame = new Rect();
316
317 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
318 // minus the area occupied by the IME if the IME is present.
319 final Rect mContentFrame = new Rect();
320
321 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
322 // displays hint text.
323 final Rect mVisibleFrame = new Rect();
324
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700325 // Frame that includes dead area outside of the surface but where we want to pretend that it's
326 // possible to draw.
327 final Rect mOutsetFrame = new Rect();
328
Jorim Jaggidc249c42015-12-15 14:57:31 -0800329 /**
330 * Usually empty. Set to the task's tempInsetFrame. See
331 *{@link android.app.IActivityManager#resizeDockedStack}.
332 */
333 final Rect mInsetFrame = new Rect();
334
Jorim Jaggif5834272016-04-04 20:25:41 -0700335 private static final Rect sTmpRect = new Rect();
336
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800337 boolean mContentChanged;
338
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800339 // If a window showing a wallpaper: the requested offset for the
340 // wallpaper; if a wallpaper window: the currently applied offset.
341 float mWallpaperX = -1;
342 float mWallpaperY = -1;
343
344 // If a window showing a wallpaper: what fraction of the offset
345 // range corresponds to a full virtual screen.
346 float mWallpaperXStep = -1;
347 float mWallpaperYStep = -1;
348
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700349 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
350 // to its window; if a wallpaper window: not used.
351 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
352 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
353
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800354 // Wallpaper windows: pixels offset based on above variables.
355 int mXOffset;
356 int mYOffset;
357
Craig Mautner2268e7e2012-12-13 15:40:00 -0800358 /**
359 * This is set after IWindowSession.relayout() has been called at
360 * least once for the window. It allows us to detect the situation
361 * where we don't yet have a surface, but should have one soon, so
362 * we can give the window focus before waiting for the relayout.
363 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800364 boolean mRelayoutCalled;
365
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800366 /**
367 * If the application has called relayout() with changes that can
368 * impact its window's size, we need to perform a layout pass on it
369 * even if it is not currently visible for layout. This is set
370 * when in that case until the layout is done.
371 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800372 boolean mLayoutNeeded;
373
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800374 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800375 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800376
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800377 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800378 boolean mDestroying;
379
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800380 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800381 boolean mRemoveOnExit;
382
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800383 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800384 * Whether the app died while it was visible, if true we might need
385 * to continue to show it until it's restarted.
386 */
387 boolean mAppDied;
388
389 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800390 * Set when the orientation is changing and this window has not yet
391 * been updated for the new orientation.
392 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800393 boolean mOrientationChanging;
394
Dianne Hackborna57c6952013-03-29 14:46:40 -0700395 /**
396 * How long we last kept the screen frozen.
397 */
398 int mLastFreezeDuration;
399
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800400 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800401 boolean mRemoved;
402
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800403 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800404 * It is save to remove the window and destroy the surface because the client requested removal
405 * or some other higher level component said so (e.g. activity manager).
406 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800407 */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800408 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800409
410 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800411 * Temp for keeping track of windows that have been removed when
412 * rebuilding window list.
413 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800414 boolean mRebuilding;
415
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800416 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700417 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800418 InputChannel mInputChannel;
Chong Zhang112eb8c2015-11-02 11:17:00 -0800419 InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800420
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800421 // Used to improve performance of toString()
422 String mStringNameCache;
423 CharSequence mLastTitle;
Dianne Hackborn529e7442012-11-01 14:22:28 -0700424 boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800425
Craig Mautnera2c77052012-03-26 12:14:43 -0700426 final WindowStateAnimator mWinAnimator;
427
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700428 boolean mHasSurface = false;
429
Craig Mautner19ab8282014-05-07 10:35:34 -0700430 boolean mNotOnAppsDisplay = false;
Craig Mautner59c00972012-07-30 12:10:24 -0700431 DisplayContent mDisplayContent;
Craig Mautner6881a102012-07-27 13:04:51 -0700432
Craig Mautner88400d32012-09-30 12:35:45 -0700433 /** When true this window can be displayed on screens owther than mOwnerUid's */
434 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700435
Robert Carr13f7be9e2015-12-02 18:39:45 -0800436 // Whether the window has a saved surface from last pause, which can be
437 // used to start an entering animation earlier.
438 public boolean mSurfaceSaved = false;
439
Robert Carra1eb4392015-12-10 12:43:51 -0800440 // This window will be replaced due to relaunch. This allows window manager
441 // to differentiate between simple removal of a window and replacement. In the latter case it
442 // will preserve the old window until the new one is drawn.
443 boolean mWillReplaceWindow = false;
444 // If true, the replaced window was already requested to be removed.
445 boolean mReplacingRemoveRequested = false;
446 // Whether the replacement of the window should trigger app transition animation.
447 boolean mAnimateReplacingWindow = false;
448 // If not null, the window that will be used to replace the old one. This is being set when
449 // the window is added and unset when this window reports its first draw.
450 WindowState mReplacingWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700451 // For the new window in the replacement transition, if we have
452 // requested to replace without animation, then we should
453 // make sure we also don't apply an enter animation for
454 // the new window.
455 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800456 // Whether this window is being moved via the resize API
457 boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800458
Jeff Brownc2932a12014-11-20 18:04:05 -0800459 /**
460 * Wake lock for drawing.
461 * Even though it's slightly more expensive to do so, we will use a separate wake lock
462 * for each app that is requesting to draw while dozing so that we can accurately track
463 * who is preventing the system from suspending.
464 * This lock is only acquired on first use.
465 */
466 PowerManager.WakeLock mDrawLock;
467
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700468 final private Rect mTmpRect = new Rect();
469
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800470 /**
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800471 * See {@link #notifyMovedInStack}.
472 */
473 private boolean mJustMovedInStack;
474
475 /**
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800476 * Whether the window was resized by us while it was gone for layout.
477 */
478 boolean mResizedWhileGone = false;
479
Jorim Jaggif3df0aa2016-04-06 15:56:33 -0700480 /**
481 * Indicates whether we got resized but drag resizing flag was false. In this case, we also
482 * need to recreate the surface and defer surface bound updates in order to make sure the
483 * buffer contents and the positioning/size stay in sync.
484 */
485 boolean mResizedWhileNotDragResizing;
486
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800487 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800488 WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a,
Craig Mautner59c00972012-07-30 12:10:24 -0700489 int viewVisibility, final DisplayContent displayContent) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800490 mService = service;
491 mSession = s;
492 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800493 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800494 mToken = token;
Craig Mautnera2d7b112012-08-21 15:12:20 -0700495 mOwnerUid = s.mUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800496 mWindowId = new IWindowId.Stub() {
497 @Override
498 public void registerFocusObserver(IWindowFocusObserver observer) {
499 WindowState.this.registerFocusObserver(observer);
500 }
501 @Override
502 public void unregisterFocusObserver(IWindowFocusObserver observer) {
503 WindowState.this.unregisterFocusObserver(observer);
504 }
505 @Override
506 public boolean isFocused() {
507 return WindowState.this.isFocused();
508 }
509 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800510 mAttrs.copyFrom(a);
511 mViewVisibility = viewVisibility;
Craig Mautner59c00972012-07-30 12:10:24 -0700512 mDisplayContent = displayContent;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700513 mPolicy = mService.mPolicy;
514 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800515 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700516 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700517 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800518 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700519 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700520 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800521 try {
522 c.asBinder().linkToDeath(deathRecipient, 0);
523 } catch (RemoteException e) {
524 mDeathRecipient = null;
525 mAttachedWindow = null;
526 mLayoutAttached = false;
527 mIsImWindow = false;
528 mIsWallpaper = false;
529 mIsFloatingLayer = false;
530 mBaseLayer = 0;
531 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700532 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700533 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800534 return;
535 }
536 mDeathRecipient = deathRecipient;
537
538 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
539 mAttrs.type <= LAST_SUB_WINDOW)) {
540 // The multiplier here is to reserve space for multiple
541 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700542 mBaseLayer = mPolicy.windowTypeToLayerLw(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800543 attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
544 + WindowManagerService.TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700545 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800546 mAttachedWindow = attachedWindow;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800547 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
takeda.masayuki18735092012-12-12 11:06:24 +0900548
tiger_huange2a98a72014-11-13 19:46:28 +0800549 final WindowList childWindows = mAttachedWindow.mChildWindows;
550 final int numChildWindows = childWindows.size();
551 if (numChildWindows == 0) {
552 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900553 } else {
tiger_huange2a98a72014-11-13 19:46:28 +0800554 boolean added = false;
555 for (int i = 0; i < numChildWindows; i++) {
556 final int childSubLayer = childWindows.get(i).mSubLayer;
557 if (mSubLayer < childSubLayer
558 || (mSubLayer == childSubLayer && childSubLayer < 0)) {
559 // We insert the child window into the list ordered by the sub-layer. For
560 // same sub-layers, the negative one should go below others; the positive
561 // one should go above others.
562 childWindows.add(i, this);
563 added = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900564 break;
takeda.masayuki18735092012-12-12 11:06:24 +0900565 }
566 }
tiger_huange2a98a72014-11-13 19:46:28 +0800567 if (!added) {
568 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900569 }
570 }
571
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800572 mLayoutAttached = mAttrs.type !=
573 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
574 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
575 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
576 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
577 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
578 } else {
579 // The multiplier here is to reserve space for multiple
580 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700581 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800582 * WindowManagerService.TYPE_LAYER_MULTIPLIER
583 + WindowManagerService.TYPE_LAYER_OFFSET;
584 mSubLayer = 0;
585 mAttachedWindow = null;
586 mLayoutAttached = false;
587 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
588 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
589 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
590 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
591 }
592
593 WindowState appWin = this;
Robert Carr51a1b872015-12-08 14:03:13 -0800594 while (appWin.isChildWindow()) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700595 appWin = appWin.mAttachedWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800596 }
597 WindowToken appToken = appWin.mToken;
598 while (appToken.appWindowToken == null) {
599 WindowToken parent = mService.mTokenMap.get(appToken.token);
600 if (parent == null || appToken == parent) {
601 break;
602 }
603 appToken = parent;
604 }
605 mRootToken = appToken;
606 mAppToken = appToken.appWindowToken;
Craig Mautner19ab8282014-05-07 10:35:34 -0700607 if (mAppToken != null) {
608 final DisplayContent appDisplay = getDisplayContent();
609 mNotOnAppsDisplay = displayContent != appDisplay;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700610
611 if (mAppToken.showForAllUsers) {
612 // Windows for apps that can show for all users should also show when the
613 // device is locked.
614 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
615 }
Craig Mautner19ab8282014-05-07 10:35:34 -0700616 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800617
Craig Mautner322e4032012-07-13 13:35:20 -0700618 mWinAnimator = new WindowStateAnimator(this);
619 mWinAnimator.mAlpha = a.alpha;
620
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800621 mRequestedWidth = 0;
622 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700623 mLastRequestedWidth = 0;
624 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800625 mXOffset = 0;
626 mYOffset = 0;
627 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800628 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700629 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
630 displayContent.getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800631 }
632
633 void attach() {
634 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700635 TAG, "Attaching " + this + " token=" + mToken
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800636 + ", list=" + mToken.windows);
637 mSession.windowAddedLocked();
638 }
639
Craig Mautnera2c77052012-03-26 12:14:43 -0700640 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800641 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800642 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800643 }
644
645 @Override
646 public String getOwningPackage() {
647 return mAttrs.packageName;
648 }
649
Jorim Jaggif5834272016-04-04 20:25:41 -0700650 /**
651 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
652 * from {@param frame}. In other words, it applies the insets that would result if
653 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700654 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
655 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700656 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700657 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
658 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
659 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
660 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
661 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700662 frame.inset(left, top, right, bottom);
663 }
664
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800665 @Override
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700666 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf, Rect sf,
667 Rect osf) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800668 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700669 // This window is being replaced and either already got information that it's being
670 // removed or we are still waiting for some information. Because of this we don't
671 // want to apply any more changes to it, so it remains in this state until new window
672 // appears.
673 return;
674 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800675 mHaveFrame = true;
676
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700677 final Task task = getTask();
Andrii Kulian933076d2016-03-29 17:04:42 -0700678 final boolean fullscreenTask = !isInMultiWindowMode();
Robert Carre6275582016-02-29 15:45:45 -0800679 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800680
Chong Zhangae35fef2016-03-16 15:56:55 -0700681 // If the task has temp inset bounds set, we have to make sure all its windows uses
682 // the temp inset frame. Otherwise different display frames get applied to the main
683 // window and the child window, making them misaligned.
684 if (fullscreenTask) {
685 mInsetFrame.setEmpty();
686 } else {
687 task.getTempInsetBounds(mInsetFrame);
688 }
689
Jorim Jaggif5834272016-04-04 20:25:41 -0700690 // Denotes the actual frame used to calculate the insets and to perform the layout. When
691 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
692 // insets temporarily. By the notion of a task having a different layout frame, we can
693 // achieve that while still moving the task around.
694 final Rect layoutContainingFrame;
695 final Rect layoutDisplayFrame;
696
697 // The offset from the layout containing frame to the actual containing frame.
698 final int layoutXDiff;
699 final int layoutYDiff;
Andrii Kuliandaea3572016-04-08 13:20:51 -0700700 if (mInsetFrame.isEmpty() && (fullscreenTask || layoutInParentFrame())) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800701 // We use the parent frame as the containing frame for fullscreen and child windows
702 mContainingFrame.set(pf);
703 mDisplayFrame.set(df);
Jorim Jaggif5834272016-04-04 20:25:41 -0700704 layoutDisplayFrame = df;
705 layoutContainingFrame = pf;
706 layoutXDiff = 0;
707 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800708 } else {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700709 task.getBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100710 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
711
712 // If the bounds are frozen, we still want to translate the window freely and only
713 // freeze the size.
714 Rect frozen = mAppToken.mFrozenBounds.peek();
715 mContainingFrame.right = mContainingFrame.left + frozen.width();
716 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
717 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800718 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700719 // IME is up and obscuring this window. Adjust the window position so it is visible.
720 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this) {
721 if (windowsAreFloating && mContainingFrame.bottom > cf.bottom) {
722 // In freeform we want to move the top up directly.
723 // TODO: Investigate why this is cf not pf.
724 mContainingFrame.top -= mContainingFrame.bottom - cf.bottom;
725 } else if (mContainingFrame.bottom > pf.bottom) {
726 // But in docked we want to behave like fullscreen
727 // and behave as if the task were given smaller bounds
728 // for the purposes of layout.
729 mContainingFrame.bottom = pf.bottom;
730 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700731 }
Skuhne81c524a2015-08-12 13:34:14 -0700732
Robert Carre6275582016-02-29 15:45:45 -0800733 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700734 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
735 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800736 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700737 if (mContainingFrame.isEmpty()) {
738 mContainingFrame.set(cf);
739 }
Doris Liu06d582d2015-06-01 13:18:43 -0700740 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800741 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700742 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
743 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
744 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Andrii Kuliandaea3572016-04-08 13:20:51 -0700745 mTmpRect.set(0, 0, mDisplayContent.getDisplayInfo().logicalWidth,
746 mDisplayContent.getDisplayInfo().logicalHeight);
747 subtractInsets(mDisplayFrame, layoutContainingFrame, df, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700748 if (!layoutInParentFrame()) {
Andrii Kuliandaea3572016-04-08 13:20:51 -0700749 subtractInsets(mContainingFrame, layoutContainingFrame, pf, mTmpRect);
750 subtractInsets(mInsetFrame, layoutContainingFrame, pf, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700751 }
Jorim Jaggif5834272016-04-04 20:25:41 -0700752 layoutDisplayFrame = df;
753 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700754 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800755
Craig Mautner967212c2013-04-13 21:10:58 -0700756 final int pw = mContainingFrame.width();
757 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800758
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800759 if (!mParentFrame.equals(pf)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800760 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800761 // + " to " + pf);
762 mParentFrame.set(pf);
763 mContentChanged = true;
764 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700765 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
766 mLastRequestedWidth = mRequestedWidth;
767 mLastRequestedHeight = mRequestedHeight;
768 mContentChanged = true;
769 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800770
Craig Mautnereda67292013-04-28 13:50:14 -0700771 mOverscanFrame.set(of);
772 mContentFrame.set(cf);
773 mVisibleFrame.set(vf);
John Spurlock46646232013-09-30 22:32:42 -0400774 mDecorFrame.set(dcf);
Adrian Roosfa104232014-06-20 16:10:14 -0700775 mStableFrame.set(sf);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700776 final boolean hasOutsets = osf != null;
777 if (hasOutsets) {
778 mOutsetFrame.set(osf);
779 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800780
Craig Mautnereda67292013-04-28 13:50:14 -0700781 final int fw = mFrame.width();
782 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800783
Jorim Jaggif5834272016-04-04 20:25:41 -0700784 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
785
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700786 // Calculate the outsets before the content frame gets shrinked to the window frame.
787 if (hasOutsets) {
788 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
789 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
790 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
791 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
792 } else {
793 mOutsets.set(0, 0, 0, 0);
794 }
795
Craig Mautnera248eee2013-05-07 11:41:27 -0700796 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800797 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -0800798 if (windowsAreFloating && !mFrame.isEmpty()) {
Skuhne81c524a2015-08-12 13:34:14 -0700799 // Keep the frame out of the blocked system area, limit it in size to the content area
800 // and make sure that there is always a minimum visible so that the user can drag it
801 // into a usable area..
802 final int height = Math.min(mFrame.height(), mContentFrame.height());
803 final int width = Math.min(mContentFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700804 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700805 final int minVisibleHeight = WindowManagerService.dipToPixel(
806 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics);
807 final int minVisibleWidth = WindowManagerService.dipToPixel(
808 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics);
Skuhne81c524a2015-08-12 13:34:14 -0700809 final int top = Math.max(mContentFrame.top,
810 Math.min(mFrame.top, mContentFrame.bottom - minVisibleHeight));
811 final int left = Math.max(mContentFrame.left + minVisibleWidth - width,
812 Math.min(mFrame.left, mContentFrame.right - minVisibleWidth));
813 mFrame.set(left, top, left + width, top + height);
814 mContentFrame.set(mFrame);
815 mVisibleFrame.set(mContentFrame);
816 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700817 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi192086e2016-03-11 17:17:03 +0100818 mDisplayContent.getDockedDividerController().positionDockedStackedDivider(mFrame);
819 mContentFrame.set(mFrame);
820 if (!mFrame.equals(mLastFrame)) {
821 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800822 }
Skuhne81c524a2015-08-12 13:34:14 -0700823 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -0700824 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
825 Math.max(mContentFrame.top, mFrame.top),
826 Math.min(mContentFrame.right, mFrame.right),
827 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800828
Jorim Jaggi656f6502016-04-11 21:08:17 -0700829 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
830 Math.max(mVisibleFrame.top, mFrame.top),
831 Math.min(mVisibleFrame.right, mFrame.right),
832 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800833
Jorim Jaggi656f6502016-04-11 21:08:17 -0700834 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
835 Math.max(mStableFrame.top, mFrame.top),
836 Math.min(mStableFrame.right, mFrame.right),
837 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700838 }
Adrian Roosfa104232014-06-20 16:10:14 -0700839
Jorim Jaggi899327f2016-02-25 20:44:18 -0500840 if (fullscreenTask && !windowsAreFloating) {
841 // Windows that are not fullscreen can be positioned outside of the display frame,
842 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -0700843 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
844 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
845 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
846 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800847 }
Craig Mautnereda67292013-04-28 13:50:14 -0700848
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100849 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100850 // For the docked divider, we calculate the stable insets like a full-screen window
851 // so it can use it to calculate the snap positions.
852 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
853 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
854 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
855 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800856
857 // The divider doesn't care about insets in any case, so set it to empty so we don't
858 // trigger a relayout when moving it.
859 mContentInsets.setEmpty();
860 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100861 } else {
Andrii Kuliand9003372016-04-04 17:46:59 -0700862 getDisplayContent().getLogicalDisplayRect(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700863 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
864 // non-fullscreen mode.
Jorim Jaggi656f6502016-04-11 21:08:17 -0700865 boolean overrideRightInset = !fullscreenTask && mFrame.right > mTmpRect.right;
866 boolean overrideBottomInset = !fullscreenTask && mFrame.bottom > mTmpRect.bottom;
867 mContentInsets.set(mContentFrame.left - mFrame.left,
868 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700869 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700870 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700871 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700872 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800873
Jorim Jaggi656f6502016-04-11 21:08:17 -0700874 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
875 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700876 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700877 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700878 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700879 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800880
Jorim Jaggi656f6502016-04-11 21:08:17 -0700881 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
882 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700883 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700884 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700885 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700886 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100887 }
Adrian Roosfa104232014-06-20 16:10:14 -0700888
Jorim Jaggi656f6502016-04-11 21:08:17 -0700889 // Offset the actual frame by the amount layout frame is off.
890 mFrame.offset(-layoutXDiff, -layoutYDiff);
891 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -0700892 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
893 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
894 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
895
Craig Mautnereda67292013-04-28 13:50:14 -0700896 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400897 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700898 // If there is a size compatibility scale being applied to the
899 // window, we need to apply this to its insets so that they are
900 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700901 mOverscanInsets.scale(mInvGlobalScale);
902 mContentInsets.scale(mInvGlobalScale);
903 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700904 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700905 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700906
907 // Also the scaled frame that we report to the app needs to be
908 // adjusted to be in its coordinate space.
909 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400910 }
911
Craig Mautnereda67292013-04-28 13:50:14 -0700912 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800913 final DisplayContent displayContent = getDisplayContent();
914 if (displayContent != null) {
915 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700916 mService.mWallpaperControllerLocked.updateWallpaperOffset(
917 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800918 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800919 }
920
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700921 if (DEBUG_LAYOUT || WindowManagerService.localLOGV) Slog.v(TAG,
922 "Resolving (mRequestedWidth="
923 + mRequestedWidth + ", mRequestedheight="
924 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
925 + "): frame=" + mFrame.toShortString()
926 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -0700927 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700928 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700929 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800930 }
931
Craig Mautnera2c77052012-03-26 12:14:43 -0700932 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800933 public Rect getFrameLw() {
934 return mFrame;
935 }
936
Craig Mautnera2c77052012-03-26 12:14:43 -0700937 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700938 public Point getShownPositionLw() {
939 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800940 }
941
Craig Mautnera2c77052012-03-26 12:14:43 -0700942 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800943 public Rect getDisplayFrameLw() {
944 return mDisplayFrame;
945 }
946
Craig Mautnera2c77052012-03-26 12:14:43 -0700947 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800948 public Rect getOverscanFrameLw() {
949 return mOverscanFrame;
950 }
951
952 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800953 public Rect getContentFrameLw() {
954 return mContentFrame;
955 }
956
Craig Mautnera2c77052012-03-26 12:14:43 -0700957 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800958 public Rect getVisibleFrameLw() {
959 return mVisibleFrame;
960 }
961
Craig Mautnera2c77052012-03-26 12:14:43 -0700962 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800963 public boolean getGivenInsetsPendingLw() {
964 return mGivenInsetsPending;
965 }
966
Craig Mautnera2c77052012-03-26 12:14:43 -0700967 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800968 public Rect getGivenContentInsetsLw() {
969 return mGivenContentInsets;
970 }
971
Craig Mautnera2c77052012-03-26 12:14:43 -0700972 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800973 public Rect getGivenVisibleInsetsLw() {
974 return mGivenVisibleInsets;
975 }
976
Craig Mautnera2c77052012-03-26 12:14:43 -0700977 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800978 public WindowManager.LayoutParams getAttrs() {
979 return mAttrs;
980 }
981
Craig Mautner812d2ca2012-09-27 15:35:34 -0700982 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800983 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
984 int index = -1;
985 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -0700986 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800987 while (true) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -0700988 if (ws.mAttrs.needsMenuKey != WindowManager.LayoutParams.NEEDS_MENU_UNSET) {
989 return ws.mAttrs.needsMenuKey == WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800990 }
991 // If we reached the bottom of the range of windows we are considering,
992 // assume no menu is needed.
993 if (ws == bottom) {
994 return false;
995 }
996 // The current window hasn't specified whether menu key is needed;
997 // look behind it.
998 // First, we may need to determine the starting position.
999 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -07001000 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001001 }
1002 index--;
1003 if (index < 0) {
1004 return false;
1005 }
Craig Mautner59c00972012-07-30 12:10:24 -07001006 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001007 }
1008 }
1009
Craig Mautner19d59bc2012-09-04 11:15:56 -07001010 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001011 public int getSystemUiVisibility() {
1012 return mSystemUiVisibility;
1013 }
1014
Craig Mautner19d59bc2012-09-04 11:15:56 -07001015 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001016 public int getSurfaceLayer() {
1017 return mLayer;
1018 }
1019
Craig Mautner812d2ca2012-09-27 15:35:34 -07001020 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001021 public int getBaseType() {
1022 WindowState win = this;
Robert Carr51a1b872015-12-08 14:03:13 -08001023 while (win.isChildWindow()) {
Selim Cinekd6623612015-05-22 18:56:22 -07001024 win = win.mAttachedWindow;
1025 }
1026 return win.mAttrs.type;
1027 }
1028
1029 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001030 public IApplicationToken getAppToken() {
1031 return mAppToken != null ? mAppToken.appToken : null;
1032 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001033
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001034 @Override
1035 public boolean isVoiceInteraction() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001036 return mAppToken != null && mAppToken.voiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001037 }
1038
Craig Mautner4c5eb222013-11-18 12:59:05 -08001039 boolean setInsetsChanged() {
1040 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1041 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1042 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001043 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001044 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
1045 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
1046 || mOutsetsChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001047 }
1048
Craig Mautnerdf88d732014-01-27 09:21:32 -08001049 public DisplayContent getDisplayContent() {
Chad Jonesf391ebc2014-06-12 17:45:05 -07001050 if (mAppToken == null || mNotOnAppsDisplay) {
Craig Mautnerbe634952014-06-12 13:39:24 -07001051 return mDisplayContent;
1052 }
1053 final TaskStack stack = getStack();
1054 return stack == null ? mDisplayContent : stack.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001055 }
1056
Chong Zhang09b21ef2015-09-14 10:20:21 -07001057 public DisplayInfo getDisplayInfo() {
1058 final DisplayContent displayContent = getDisplayContent();
1059 return displayContent != null ? displayContent.getDisplayInfo() : null;
1060 }
1061
Craig Mautner19d59bc2012-09-04 11:15:56 -07001062 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001063 final DisplayContent displayContent = getDisplayContent();
1064 if (displayContent == null) {
1065 return -1;
1066 }
1067 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001068 }
1069
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001070 Task getTask() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07001071 return mAppToken != null ? mAppToken.mTask : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001072 }
1073
1074 TaskStack getStack() {
1075 Task task = getTask();
1076 if (task != null) {
1077 if (task.mStack != null) {
1078 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001079 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001080 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001081 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1082 // associate them with some stack to enable dimming.
1083 return mAttrs.type >= WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1084 && mDisplayContent != null ? mDisplayContent.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001085 }
1086
Skuhnef932e562015-08-20 12:07:30 -07001087 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001088 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001089 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001090 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001091 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001092 final Task task = getTask();
1093 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001094 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001095 mTmpRect.setEmpty();
1096 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001097 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001098 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001099 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001100 } else {
1101 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001102 }
1103 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001104
Chong Zhang9184ec62015-09-24 12:32:21 -07001105 bounds.set(mVisibleFrame);
1106 if (intersectWithStackBounds) {
1107 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001108 }
1109
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001110 if (bounds.isEmpty()) {
1111 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001112 if (intersectWithStackBounds) {
1113 bounds.intersect(mTmpRect);
1114 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001115 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001116 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001117 }
1118
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001119 public long getInputDispatchingTimeoutNanos() {
1120 return mAppToken != null
1121 ? mAppToken.inputDispatchingTimeoutNanos
1122 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1123 }
1124
Craig Mautnere8552142012-11-07 13:55:47 -08001125 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001126 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001127 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001128 }
1129
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001130 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1131 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1132 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1133 if (dtdx < -.000001f || dtdx > .000001f) return false;
1134 if (dsdy < -.000001f || dsdy > .000001f) return false;
1135 return true;
1136 }
1137
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001138 void prelayout() {
1139 if (mEnforceSizeCompat) {
1140 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001141 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001142 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001143 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001144 }
1145 }
1146
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001147 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001148 * Does the minimal check for visibility. Callers generally want to use one of the public
1149 * methods as they perform additional checks on the app token.
1150 * TODO: See if there are other places we can use this check below instead of duplicating...
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001151 */
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001152 private boolean isVisibleUnchecked() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001153 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001154 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001155 }
1156
1157 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001158 * Is this window visible? It is not visible if there is no surface, or we are in the process
1159 * of running an exit animation that will remove the surface, or its app token has been hidden.
1160 */
1161 @Override
1162 public boolean isVisibleLw() {
1163 return (mAppToken == null || !mAppToken.hiddenRequested) && isVisibleUnchecked();
1164 }
1165
1166 /**
1167 * Like {@link #isVisibleLw}, but also counts a window that is currently "hidden" behind the
1168 * keyguard as visible. This allows us to apply things like window flags that impact the
1169 * keyguard. XXX I am starting to think we need to have ANOTHER visibility flag for this
1170 * "hidden behind keyguard" state rather than overloading mPolicyVisibility. Ungh.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001171 */
Craig Mautner88400d32012-09-30 12:35:45 -07001172 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001173 public boolean isVisibleOrBehindKeyguardLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001174 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001175 return false;
1176 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001177 final AppWindowToken atoken = mAppToken;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001178 final boolean animating = atoken != null && atoken.mAppAnimator.animation != null;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001179 return mHasSurface && !mDestroying && !mAnimatingExit
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001180 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001181 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001182 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001183 }
1184
1185 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001186 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1187 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001188 */
1189 public boolean isWinVisibleLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001190 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.mAppAnimator.animating)
1191 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001192 }
1193
1194 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001195 * The same as isVisible(), but follows the current hidden state of the associated app token,
1196 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001197 */
1198 boolean isVisibleNow() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001199 return (!mRootToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
1200 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001201 }
1202
1203 /**
1204 * Can this window possibly be a drag/drop target? The test here is
1205 * a combination of the above "visible now" with the check that the
1206 * Input Manager uses when discarding windows from input consideration.
1207 */
1208 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001209 return isVisibleNow() && !mRemoved
1210 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001211 }
1212
1213 /**
1214 * Same as isVisible(), but we also count it as visible between the
1215 * call to IWindowSession.add() and the first relayout().
1216 */
1217 boolean isVisibleOrAdding() {
1218 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001219 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001220 && mPolicyVisibility && !mAttachedHidden
1221 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001222 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001223 }
1224
1225 /**
1226 * Is this window currently on-screen? It is on-screen either if it
1227 * is visible or it is currently running an animation before no longer
1228 * being visible.
1229 */
1230 boolean isOnScreen() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001231 return mPolicyVisibility && isOnScreenIgnoringKeyguard();
1232 }
1233
1234 /**
1235 * Like isOnScreen(), but ignores any force hiding of the window due
1236 * to the keyguard.
1237 */
1238 boolean isOnScreenIgnoringKeyguard() {
1239 if (!mHasSurface || mDestroying) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001240 return false;
1241 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001242 final AppWindowToken atoken = mAppToken;
1243 if (atoken != null) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001244 return ((!mAttachedHidden && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001245 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001246 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001247 return !mAttachedHidden || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001248 }
1249
1250 /**
1251 * Like isOnScreen(), but we don't return true if the window is part
1252 * of a transition that has not yet been started.
1253 */
1254 boolean isReadyForDisplay() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001255 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001256 return false;
1257 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001258 return mHasSurface && mPolicyVisibility && !mDestroying
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001259 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001260 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001261 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001262 }
1263
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001264 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001265 * Like isReadyForDisplay(), but ignores any force hiding of the window due
1266 * to the keyguard.
1267 */
1268 boolean isReadyForDisplayIgnoringKeyguard() {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001269 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001270 return false;
1271 }
1272 final AppWindowToken atoken = mAppToken;
1273 if (atoken == null && !mPolicyVisibility) {
1274 // If this is not an app window, and the policy has asked to force
1275 // hide, then we really do want to hide.
1276 return false;
1277 }
1278 return mHasSurface && !mDestroying
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001279 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE && !mRootToken.hidden)
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001280 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -07001281 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
1282 && !mWinAnimator.isDummyAnimation()));
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001283 }
1284
1285 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001286 * Like isOnScreen, but returns false if the surface hasn't yet
1287 * been drawn.
1288 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001289 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001290 public boolean isDisplayedLw() {
1291 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001292 return isDrawnLw() && mPolicyVisibility
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001293 && ((!mAttachedHidden &&
1294 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001295 || mWinAnimator.mAnimating
1296 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001297 }
1298
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001299 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001300 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001301 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001302 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001303 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001304 return mWinAnimator.mAnimation != null
1305 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001306 }
1307
Craig Mautner812d2ca2012-09-27 15:35:34 -07001308 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001309 public boolean isGoneForLayoutLw() {
1310 final AppWindowToken atoken = mAppToken;
1311 return mViewVisibility == View.GONE
1312 || !mRelayoutCalled
1313 || (atoken == null && mRootToken.hidden)
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001314 || (atoken != null && atoken.hiddenRequested)
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001315 || mAttachedHidden
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001316 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001317 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001318 }
1319
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001320 /**
1321 * Returns true if the window has a surface that it has drawn a
1322 * complete UI in to.
1323 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001324 public boolean isDrawFinishedLw() {
1325 return mHasSurface && !mDestroying &&
1326 (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING
1327 || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1328 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
1329 }
1330
1331 /**
1332 * Returns true if the window has a surface that it has drawn a
1333 * complete UI in to.
1334 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001335 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001336 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001337 return mHasSurface && !mDestroying &&
Craig Mautner749a7bb2012-04-02 13:49:53 -07001338 (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1339 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001340 }
1341
1342 /**
1343 * Return true if the window is opaque and fully drawn. This indicates
1344 * it may obscure windows behind it.
1345 */
1346 boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001347 // When there is keyguard, wallpaper could be placed over the secure app
1348 // window but invisible. We need to check wallpaper visibility explicitly
1349 // to determine if it's occluding apps.
1350 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1351 || (mIsWallpaper && mWallpaperVisible))
Craig Mautnera2c77052012-03-26 12:14:43 -07001352 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001353 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001354 }
1355
1356 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001357 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001358 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1359 */
Craig Mautner4557c082015-04-27 13:07:40 -07001360 boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001361 return mHasSurface && (mContentChanged || mMovedByResize)
Jorim Jaggi192086e2016-03-11 17:17:03 +01001362 && !mAnimatingExit && mService.okToDisplay()
Chong Zhangbd0d9372015-12-28 15:18:29 -08001363 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Craig Mautner4557c082015-04-27 13:07:40 -07001364 && (mAttachedWindow == null || !mAttachedWindow.hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001365 }
1366
Chong Zhang0abb20f2015-11-19 14:17:31 -08001367 boolean isObscuringFullscreen(final DisplayInfo displayInfo) {
1368 Task task = getTask();
1369 if (task != null && task.mStack != null && !task.mStack.isFullscreen()) {
1370 return false;
1371 }
1372 if (!isOpaqueDrawn() || !isFrameFullscreen(displayInfo)) {
1373 return false;
1374 }
1375 return true;
1376 }
1377
1378 boolean isFrameFullscreen(final DisplayInfo displayInfo) {
1379 return mFrame.left <= 0 && mFrame.top <= 0
1380 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001381 }
1382
Craig Mautner812d2ca2012-09-27 15:35:34 -07001383 boolean isConfigChanged() {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001384 final Task task = getTask();
Wale Ogunwale60454db2015-01-23 16:05:07 -08001385 final Configuration overrideConfig =
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001386 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001387 final Configuration serviceConfig = mService.mCurConfiguration;
1388 boolean configChanged =
1389 (mConfiguration != serviceConfig && mConfiguration.diff(serviceConfig) != 0)
1390 || (mOverrideConfig != overrideConfig && !mOverrideConfig.equals(overrideConfig));
Craig Mautnere8552142012-11-07 13:55:47 -08001391
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001392 if ((mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Craig Mautnere8552142012-11-07 13:55:47 -08001393 // Retain configuration changed status until resetConfiguration called.
1394 mConfigHasChanged |= configChanged;
1395 configChanged = mConfigHasChanged;
1396 }
1397
1398 return configChanged;
Craig Mautner812d2ca2012-09-27 15:35:34 -07001399 }
1400
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07001401 boolean isAdjustedForMinimizedDock() {
1402 return mAppToken != null && mAppToken.mTask != null
1403 && mAppToken.mTask.mStack.isAdjustedForMinimizedDock();
1404 }
1405
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001406 void removeLocked() {
1407 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001408
Robert Carr51a1b872015-12-08 14:03:13 -08001409 if (isChildWindow()) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001410 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001411 mAttachedWindow.mChildWindows.remove(this);
1412 }
Craig Mautner96868332012-12-04 14:29:11 -08001413 mWinAnimator.destroyDeferredSurfaceLocked();
1414 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001415 mSession.windowRemovedLocked();
1416 try {
1417 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1418 } catch (RuntimeException e) {
1419 // Ignore if it has already been removed (usually because
1420 // we are doing this as part of processing a death note.)
1421 }
1422 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001423
Wale Ogunwale60454db2015-01-23 16:05:07 -08001424 private void setConfiguration(
1425 final Configuration newConfig, final Configuration newOverrideConfig) {
Craig Mautnere8552142012-11-07 13:55:47 -08001426 mConfiguration = newConfig;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001427 mOverrideConfig = newOverrideConfig;
Craig Mautnere8552142012-11-07 13:55:47 -08001428 mConfigHasChanged = false;
Robert Carrc24d8f92016-02-29 16:24:33 -08001429
1430 mMergedConfiguration.setTo(newConfig);
1431 if (newOverrideConfig != null && newOverrideConfig != Configuration.EMPTY) {
1432 mMergedConfiguration.updateFrom(newOverrideConfig);
1433 }
Craig Mautnere8552142012-11-07 13:55:47 -08001434 }
1435
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001436 void setHasSurface(boolean hasSurface) {
1437 mHasSurface = hasSurface;
1438 }
1439
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001440 int getAnimLayerAdjustment() {
1441 if (mTargetAppToken != null) {
1442 return mTargetAppToken.mAppAnimator.animLayerAdjustment;
1443 } else if (mAppToken != null) {
1444 return mAppToken.mAppAnimator.animLayerAdjustment;
1445 } else {
1446 // Nothing is animating, so there is no animation adjustment.
1447 return 0;
1448 }
1449 }
1450
1451 void scheduleAnimationIfDimming() {
1452 if (mDisplayContent == null) {
1453 return;
1454 }
1455 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1456 if (dimLayerUser != null && mDisplayContent.mDimLayerController.isDimming(
1457 dimLayerUser, mWinAnimator)) {
1458 // Force an animation pass just to update the mDimLayer layer.
1459 mService.scheduleAnimationLocked();
1460 }
1461 }
1462
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08001463 /**
1464 * Notifies this window that the corresponding task has just moved in the stack.
1465 * <p>
1466 * This is used to fix the following: If we moved in the stack, and if the last clip rect was
1467 * empty, meaning that our task was completely offscreen, we need to keep it invisible because
1468 * the actual app transition that updates the visibility is delayed by a few transactions.
1469 * Instead of messing around with the ordering and timing how transitions and transactions are
1470 * executed, we introduce this little hack which prevents this window of getting visible again
1471 * with the wrong bounds until the app transitions has started.
1472 * <p>
1473 * This method notifies the window about that we just moved in the stack so we can apply this
1474 * logic in {@link WindowStateAnimator#updateSurfaceWindowCrop}
1475 */
1476 void notifyMovedInStack() {
1477 mJustMovedInStack = true;
1478 }
1479
1480 /**
1481 * See {@link #notifyMovedInStack}.
1482 *
1483 * @return Whether we just got moved in the corresponding stack.
1484 */
1485 boolean hasJustMovedInStack() {
1486 return mJustMovedInStack;
1487 }
1488
1489 /**
1490 * Resets that we just moved in the corresponding stack. See {@link #notifyMovedInStack}.
1491 */
1492 void resetJustMovedInStack() {
1493 mJustMovedInStack = false;
1494 }
1495
Chong Zhangacf11402015-11-04 16:23:10 -08001496 private final class DeadWindowEventReceiver extends InputEventReceiver {
1497 DeadWindowEventReceiver(InputChannel inputChannel) {
1498 super(inputChannel, mService.mH.getLooper());
1499 }
1500 @Override
1501 public void onInputEvent(InputEvent event) {
1502 finishInputEvent(event, true);
1503 }
1504 }
1505 /**
1506 * Dummy event receiver for windows that died visible.
1507 */
1508 private DeadWindowEventReceiver mDeadWindowEventReceiver;
1509
Chong Zhang112eb8c2015-11-02 11:17:00 -08001510 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001511 if (mInputChannel != null) {
1512 throw new IllegalStateException("Window already has an input channel.");
1513 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001514 String name = makeInputChannelName();
1515 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1516 mInputChannel = inputChannels[0];
1517 mClientChannel = inputChannels[1];
1518 mInputWindowHandle.inputChannel = inputChannels[0];
1519 if (outInputChannel != null) {
1520 mClientChannel.transferTo(outInputChannel);
1521 mClientChannel.dispose();
1522 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08001523 } else {
1524 // If the window died visible, we setup a dummy input channel, so that taps
1525 // can still detected by input monitor channel, and we can relaunch the app.
1526 // Create dummy event receiver that simply reports all events as handled.
1527 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08001528 }
1529 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001530 }
1531
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001532 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08001533 if (mDeadWindowEventReceiver != null) {
1534 mDeadWindowEventReceiver.dispose();
1535 mDeadWindowEventReceiver = null;
1536 }
1537
1538 // unregister server channel first otherwise it complains about broken channel
1539 if (mInputChannel != null) {
1540 mService.mInputManager.unregisterInputChannel(mInputChannel);
1541 mInputChannel.dispose();
1542 mInputChannel = null;
1543 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001544 if (mClientChannel != null) {
1545 mClientChannel.dispose();
1546 mClientChannel = null;
1547 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001548 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001549 }
1550
Chong Zhang112eb8c2015-11-02 11:17:00 -08001551 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08001552 // When the app is terminated (eg. from Recents), the task might have already been
1553 // removed with the window pending removal. Don't apply dim in such cases, as there
1554 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
1555 final AppWindowToken token = mAppToken;
1556 if (token != null && token.removed) {
1557 return;
1558 }
1559
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001560 if (!mAnimatingExit && mAppDied) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001561 // If app died visible, apply a dim over the window to indicate that it's inactive
1562 mDisplayContent.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
1563 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
Robert Carr9fe459d2016-04-07 23:32:28 -07001564 && mDisplayContent != null && !mAnimatingExit && isVisibleUnchecked()) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001565 mDisplayContent.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001566 }
1567 }
1568
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001569 DimLayer.DimLayerUser getDimLayerUser() {
1570 Task task = getTask();
1571 if (task != null) {
1572 return task;
1573 }
1574 return getStack();
1575 }
1576
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001577 void maybeRemoveReplacedWindow() {
Robert Carra1eb4392015-12-10 12:43:51 -08001578 if (mAppToken == null) {
1579 return;
1580 }
1581 for (int i = mAppToken.allAppWindows.size() - 1; i >= 0; i--) {
1582 final WindowState win = mAppToken.allAppWindows.get(i);
Robert Carrdcdca582016-04-07 22:59:24 -07001583 if (win.mWillReplaceWindow && win.mReplacingWindow == this && hasDrawnLw()) {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08001584 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + win);
Robert Carr9fe459d2016-04-07 23:32:28 -07001585 if (win.isDimming()) {
1586 win.transferDimToReplacement();
1587 }
Robert Carra1eb4392015-12-10 12:43:51 -08001588 win.mWillReplaceWindow = false;
1589 win.mAnimateReplacingWindow = false;
1590 win.mReplacingRemoveRequested = false;
1591 win.mReplacingWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -07001592 mSkipEnterAnimationForSeamlessReplacement = false;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001593 if (win.mAnimatingExit) {
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001594 mService.removeWindowInnerLocked(win);
1595 }
1596 }
1597 }
1598 }
1599
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07001600 void setDisplayLayoutNeeded() {
1601 if (mDisplayContent != null) {
1602 mDisplayContent.layoutNeeded = true;
1603 }
1604 }
1605
Filip Gruszczynski955b2fc2015-10-15 14:46:07 -07001606 boolean inDockedWorkspace() {
Chong Zhang2a88fc32016-01-11 17:14:24 -08001607 final Task task = getTask();
Chong Zhangb15758a2015-11-17 12:12:03 -08001608 return task != null && task.inDockedWorkspace();
1609 }
1610
1611 boolean isDockedInEffect() {
Chong Zhang2a88fc32016-01-11 17:14:24 -08001612 final Task task = getTask();
Chong Zhangb15758a2015-11-17 12:12:03 -08001613 return task != null && task.isDockedInEffect();
Filip Gruszczynski955b2fc2015-10-15 14:46:07 -07001614 }
1615
Chong Zhang2a88fc32016-01-11 17:14:24 -08001616 void applyScrollIfNeeded() {
1617 final Task task = getTask();
Chong Zhangf66db432016-01-13 10:39:51 -08001618 if (task != null) {
1619 task.applyScrollToWindowIfNeeded(this);
Chong Zhang2a88fc32016-01-11 17:14:24 -08001620 }
1621 }
1622
Chong Zhang5117e272016-05-03 12:47:34 -07001623 void applyAdjustForImeIfNeeded() {
1624 final Task task = getTask();
1625 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
1626 task.mStack.applyAdjustForImeIfNeeded(task);
1627 }
1628 }
1629
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001630 int getTouchableRegion(Region region, int flags) {
1631 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001632 if (modal && mAppToken != null) {
1633 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001634 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001635 // If this is a modal window we need to dismiss it if it's not full screen and the
1636 // touch happens outside of the frame that displays the content. This means we
1637 // need to intercept touches outside of that window. The dim layer user
1638 // associated with the window (task or stack) will give us the good bounds, as
1639 // they would be used to display the dim layer.
1640 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1641 if (dimLayerUser != null) {
1642 dimLayerUser.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001643 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001644 getVisibleBounds(mTmpRect);
1645 }
1646 if (inFreeformWorkspace()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001647 // For freeform windows we the touch region to include the whole surface for the
1648 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001649 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
1650 final int delta = WindowManagerService.dipToPixel(
1651 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
1652 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001653 }
1654 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001655 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001656 } else {
1657 // Not modal or full screen modal
1658 getTouchableRegion(region);
1659 }
1660 return flags;
1661 }
1662
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001663 void checkPolicyVisibilityChange() {
1664 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
1665 if (DEBUG_VISIBILITY) {
1666 Slog.v(TAG, "Policy visibility changing after anim in " +
1667 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
1668 }
1669 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001670 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001671 if (!mPolicyVisibility) {
1672 if (mService.mCurrentFocus == this) {
1673 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
1674 "setAnimationLocked: setting mFocusMayChange true");
1675 mService.mFocusMayChange = true;
1676 }
1677 // Window is no longer visible -- make sure if we were waiting
1678 // for it to be displayed before enabling the display, that
1679 // we allow the display to be enabled now.
1680 mService.enableScreenIfNeededLocked();
1681 }
1682 }
1683 }
1684
1685 void setRequestedSize(int requestedWidth, int requestedHeight) {
1686 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
1687 mLayoutNeeded = true;
1688 mRequestedWidth = requestedWidth;
1689 mRequestedHeight = requestedHeight;
1690 }
1691 }
1692
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001693 void prepareWindowToDisplayDuringRelayout(Configuration outConfig) {
1694 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
1695 == SOFT_INPUT_ADJUST_RESIZE) {
1696 mLayoutNeeded = true;
1697 }
1698 if (isDrawnLw() && mService.okToDisplay()) {
1699 mWinAnimator.applyEnterAnimationLocked();
1700 }
1701 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
1702 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
1703 mTurnOnScreen = true;
1704 }
1705 if (isConfigChanged()) {
Robert Carrc24d8f92016-02-29 16:24:33 -08001706 final Configuration newConfig = updateConfiguration();
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001707 if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + this + " visible with new config: "
Robert Carrc24d8f92016-02-29 16:24:33 -08001708 + newConfig);
1709 outConfig.setTo(newConfig);
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001710 }
1711 }
1712
1713 void adjustStartingWindowFlags() {
1714 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
1715 && mAppToken.startingWindow != null) {
1716 // Special handling of starting window over the base
1717 // window of the app: propagate lock screen flags to it,
1718 // to provide the correct semantics while starting.
1719 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
1720 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
1721 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
1722 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
1723 }
1724 }
1725
1726 void setWindowScale(int requestedWidth, int requestedHeight) {
1727 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
1728
1729 if (scaledWindow) {
1730 // requested{Width|Height} Surface's physical size
1731 // attrs.{width|height} Size on screen
1732 // TODO: We don't check if attrs != null here. Is it implicitly checked?
1733 mHScale = (mAttrs.width != requestedWidth) ?
1734 (mAttrs.width / (float)requestedWidth) : 1.0f;
1735 mVScale = (mAttrs.height != requestedHeight) ?
1736 (mAttrs.height / (float)requestedHeight) : 1.0f;
1737 } else {
1738 mHScale = mVScale = 1;
1739 }
1740 }
1741
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001742 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08001743 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001744 public void binderDied() {
1745 try {
1746 synchronized(mService.mWindowMap) {
1747 WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07001748 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001749 if (win != null) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07001750 mService.removeWindowLocked(win, shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08001751 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
1752 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08001753 // just in case they have the divider at an unstable position. Better
1754 // also reset drag resizing state, because the owner can't do it
1755 // anymore.
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08001756 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
1757 if (stack != null) {
1758 stack.resetDockedStackToMiddle();
1759 }
Jorim Jaggidcb68142016-02-09 21:51:30 -08001760 mService.setDockedStackResizing(false);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08001761 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001762 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08001763 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001764 mService.removeWindowLocked(WindowState.this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001765 }
1766 }
1767 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07001768 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001769 }
1770 }
1771 }
1772
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08001773 /**
1774 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
1775 * because we want to preserve its location on screen to be re-activated later when the user
1776 * interacts with it.
1777 */
1778 boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07001779 if (!isWinVisibleLw() || mAppToken == null || mAppToken.clientHidden) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08001780 // Not a visible app window or the app isn't dead.
1781 return false;
1782 }
1783
Wale Ogunwale51d1d912016-05-04 13:27:18 -07001784 if (mAttrs.token != mClient.asBinder()) {
1785 // The window was add by a client using another client's app token. We don't want to
1786 // keep the dead window around for this case since this is meant for 'real' apps.
1787 return false;
1788 }
1789
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08001790 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1791 // We don't keep starting windows since they were added by the window manager before
1792 // the app even launched.
1793 return false;
1794 }
1795
1796 final TaskStack stack = getStack();
1797 return stack != null && StackId.keepVisibleDeadAppWindowOnScreen(stack.mStackId);
1798 }
1799
Wale Ogunwaled045c822015-12-02 09:14:28 -08001800 /** @return true if this window desires key events. */
1801 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08001802 return isVisibleOrAdding()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001803 && (mViewVisibility == View.VISIBLE)
Wale Ogunwaled045c822015-12-02 09:14:28 -08001804 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07001805 && (mAppToken == null || mAppToken.windowsAreFocusable())
1806 && !isAdjustedForMinimizedDock();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001807 }
1808
Craig Mautner749a7bb2012-04-02 13:49:53 -07001809 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001810 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001811 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001812 }
1813
Craig Mautner749a7bb2012-04-02 13:49:53 -07001814 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001815 public boolean showLw(boolean doAnimation) {
1816 return showLw(doAnimation, true);
1817 }
1818
1819 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07001820 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001821 return false;
1822 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001823 if (!mAppOpVisibility) {
1824 // Being hidden due to app op request.
1825 return false;
1826 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001827 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001828 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001829 return false;
1830 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001831 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001832 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001833 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07001834 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07001835 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001836 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07001837 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001838 // Check for the case where we are currently visible and
1839 // not animating; we do not want to do animation at such a
1840 // point to become visible when we already are.
1841 doAnimation = false;
1842 }
1843 }
1844 mPolicyVisibility = true;
1845 mPolicyVisibilityAfterAnim = true;
1846 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001847 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001848 }
1849 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001850 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001851 }
1852 return true;
1853 }
1854
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001855 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001856 public boolean hideLw(boolean doAnimation) {
1857 return hideLw(doAnimation, true);
1858 }
1859
1860 boolean hideLw(boolean doAnimation, boolean requestAnim) {
1861 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07001862 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001863 doAnimation = false;
1864 }
1865 }
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001866 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
1867 : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001868 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001869 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001870 return false;
1871 }
1872 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001873 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07001874 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001875 doAnimation = false;
1876 }
1877 }
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001878 if (doAnimation) {
1879 mPolicyVisibilityAfterAnim = false;
1880 } else {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001881 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001882 mPolicyVisibilityAfterAnim = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001883 mPolicyVisibility = false;
1884 // Window is no longer visible -- make sure if we were waiting
1885 // for it to be displayed before enabling the display, that
1886 // we allow the display to be enabled now.
1887 mService.enableScreenIfNeededLocked();
1888 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001889 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07001890 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001891 mService.mFocusMayChange = true;
1892 }
1893 }
1894 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001895 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001896 }
1897 return true;
1898 }
1899
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001900 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001901 if (mAppOpVisibility != state) {
1902 mAppOpVisibility = state;
1903 if (state) {
1904 // If the policy visibility had last been to hide, then this
1905 // will incorrectly show at this point since we lost that
1906 // information. Not a big deal -- for the windows that have app
1907 // ops modifies they should only be hidden by policy due to the
1908 // lock screen, and the user won't be changing this if locked.
1909 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001910 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001911 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001912 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001913 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001914 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001915 }
1916
Jeff Brownc2932a12014-11-20 18:04:05 -08001917 public void pokeDrawLockLw(long timeout) {
1918 if (isVisibleOrAdding()) {
1919 if (mDrawLock == null) {
1920 // We want the tag name to be somewhat stable so that it is easier to correlate
1921 // in wake lock statistics. So in particular, we don't want to include the
1922 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001923 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08001924 mDrawLock = mService.mPowerManager.newWakeLock(
1925 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
1926 mDrawLock.setReferenceCounted(false);
1927 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
1928 }
1929 // Each call to acquire resets the timeout.
1930 if (DEBUG_POWER) {
1931 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
1932 + mAttrs.packageName);
1933 }
1934 mDrawLock.acquire(timeout);
1935 } else if (DEBUG_POWER) {
1936 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
1937 + "owned by " + mAttrs.packageName);
1938 }
1939 }
1940
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001941 @Override
1942 public boolean isAlive() {
1943 return mClient.asBinder().isBinderAlive();
1944 }
1945
Craig Mautnera987d432012-10-11 14:07:58 -07001946 boolean isClosing() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001947 return mAnimatingExit || (mService.mClosingApps.contains(mAppToken));
Craig Mautnera987d432012-10-11 14:07:58 -07001948 }
1949
Chong Zhangbef461f2015-10-27 11:38:24 -07001950 boolean isAnimatingWithSavedSurface() {
1951 return mAppToken != null && mAppToken.mAnimatingWithSavedSurface;
1952 }
1953
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001954 private boolean shouldSaveSurface() {
Chong Zhang6c71c0b2016-04-01 15:10:31 -07001955 if (mWinAnimator.mSurfaceController == null) {
1956 // Don't bother if the surface controller is gone for any reason.
1957 return false;
1958 }
1959
Wale Ogunwale945d1972016-03-23 13:16:41 -07001960 if ((mAttrs.flags & FLAG_SECURE) != 0) {
1961 // We don't save secure surfaces since their content shouldn't be shown while the app
1962 // isn't on screen and content might leak through during the transition animation with
1963 // saved surface.
1964 return false;
1965 }
1966
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001967 if (ActivityManager.isLowRamDeviceStatic()) {
1968 // Don't save surfaces on Svelte devices.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001969 return false;
1970 }
1971
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001972 Task task = getTask();
1973 if (task == null || task.inHomeStack()) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001974 // Don't save surfaces for home stack apps. These usually resume and draw
1975 // first frame very fast. Saving surfaces are mostly a waste of memory.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001976 return false;
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001977 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001978
1979 final AppWindowToken taskTop = task.getTopVisibleAppToken();
1980 if (taskTop != null && taskTop != mAppToken) {
1981 // Don't save if the window is not the topmost window.
1982 return false;
1983 }
1984
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001985 if (mResizedWhileGone) {
1986 // Somebody resized our window while we were gone for layout, which means that the
1987 // client got an old size, so we have an outdated surface here.
1988 return false;
1989 }
1990
Robert Carr7098dbd2016-02-01 12:31:01 -08001991 if (DEBUG_DISABLE_SAVING_SURFACES) {
1992 return false;
1993 }
1994
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001995 return mAppToken.shouldSaveSurface();
1996 }
1997
1998 void destroyOrSaveSurface() {
1999 mSurfaceSaved = shouldSaveSurface();
2000 if (mSurfaceSaved) {
2001 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2002 Slog.v(TAG, "Saving surface: " + this);
2003 }
2004
2005 mWinAnimator.hide("saved surface");
2006 mWinAnimator.mDrawState = WindowStateAnimator.NO_SURFACE;
2007 setHasSurface(false);
Chong Zhang47e36a32016-02-29 16:44:33 -08002008 // The client should have disconnected at this point, but if it doesn't,
2009 // we need to make sure it's disconnected. Otherwise when we reuse the surface
2010 // the client can't reconnect to the buffer queue, and rendering will fail.
2011 if (mWinAnimator.mSurfaceController != null) {
2012 mWinAnimator.mSurfaceController.disconnectInTransaction();
2013 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002014 } else {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002015 mWinAnimator.destroySurfaceLocked();
2016 }
Robert Carr13f7be9e2015-12-02 18:39:45 -08002017 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002018
Robert Carr13f7be9e2015-12-02 18:39:45 -08002019 public void destroySavedSurface() {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002020 if (mSurfaceSaved) {
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002021 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2022 Slog.v(TAG, "Destroying saved surface: " + this);
2023 }
Robert Carr13f7be9e2015-12-02 18:39:45 -08002024 mWinAnimator.destroySurfaceLocked();
2025 }
2026 }
2027
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002028 public void restoreSavedSurface() {
Chong Zhang4113ffa2016-02-18 12:39:13 -08002029 if (!mSurfaceSaved) {
2030 return;
2031 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002032 mSurfaceSaved = false;
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002033 if (mWinAnimator.mSurfaceController != null) {
2034 setHasSurface(true);
2035 mWinAnimator.mDrawState = WindowStateAnimator.READY_TO_SHOW;
2036
2037 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2038 Slog.v(TAG, "Restoring saved surface: " + this);
2039 }
2040 } else {
2041 // mSurfaceController shouldn't be null if mSurfaceSaved was still true at
2042 // this point. Even if we destroyed the saved surface because of rotation
2043 // or resize, mSurfaceSaved flag should have been cleared. So this is a wtf.
2044 Slog.wtf(TAG, "Failed to restore saved surface: surface gone! " + this);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002045 }
2046 }
2047
Robert Carr13f7be9e2015-12-02 18:39:45 -08002048 public boolean hasSavedSurface() {
2049 return mSurfaceSaved;
2050 }
2051
Craig Mautner69b08182012-09-05 13:07:13 -07002052 @Override
2053 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002054 final DisplayContent displayContent = getDisplayContent();
2055 if (displayContent == null) {
2056 // Only a window that was on a non-default display can be detached from it.
2057 return false;
2058 }
Winson Chung47a3e652014-05-21 16:03:42 -07002059 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002060 }
2061
Adrian Rooscd3884d2015-02-18 17:25:23 +01002062 @Override
2063 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002064 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
2065 return dimLayerUser != null && mDisplayContent != null &&
Chong Zhang112eb8c2015-11-02 11:17:00 -08002066 mDisplayContent.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01002067 }
2068
Craig Mautner88400d32012-09-30 12:35:45 -07002069 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
2070 mShowToOwnerOnly = showToOwnerOnly;
2071 }
2072
Craig Mautner5962b122012-10-05 14:45:52 -07002073 boolean isHiddenFromUserLocked() {
Craig Mautner341220f2012-10-16 15:20:09 -07002074 // Attached windows are evaluated based on the window that they are attached to.
2075 WindowState win = this;
Robert Carr51a1b872015-12-08 14:03:13 -08002076 while (win.isChildWindow()) {
Craig Mautner341220f2012-10-16 15:20:09 -07002077 win = win.mAttachedWindow;
2078 }
2079 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -07002080 && win.mAppToken != null && win.mAppToken.showForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002081
2082 // All window frames that are fullscreen extend above status bar, but some don't extend
2083 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2084 // bottom right.
2085 if (win.mFrame.left <= win.mDisplayFrame.left
2086 && win.mFrame.top <= win.mDisplayFrame.top
2087 && win.mFrame.right >= win.mStableFrame.right
2088 && win.mFrame.bottom >= win.mStableFrame.bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002089 // Is a fullscreen window, like the clock alarm. Show to everyone.
2090 return false;
2091 }
2092 }
2093
Craig Mautner341220f2012-10-16 15:20:09 -07002094 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01002095 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002096 }
2097
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002098 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2099 outRegion.set(
2100 frame.left + inset.left, frame.top + inset.top,
2101 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002102 }
2103
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002104 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002105 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002106 switch (mTouchableInsets) {
2107 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002108 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002109 outRegion.set(frame);
2110 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002111 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002112 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002113 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002114 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002115 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002116 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002117 case TOUCHABLE_INSETS_REGION: {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002118 final Region givenTouchableRegion = mGivenTouchableRegion;
2119 outRegion.set(givenTouchableRegion);
2120 outRegion.translate(frame.left, frame.top);
2121 break;
2122 }
2123 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002124 cropRegionToStackBoundsIfNeeded(outRegion);
2125 }
2126
2127 void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002128 final Task task = getTask();
2129 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002130 return;
2131 }
2132
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002133 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002134 if (stack == null) {
2135 return;
2136 }
2137
2138 stack.getDimBounds(mTmpRect);
2139 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002140 }
2141
Craig Mautner59c00972012-07-30 12:10:24 -07002142 WindowList getWindowList() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002143 final DisplayContent displayContent = getDisplayContent();
2144 return displayContent == null ? null : displayContent.getWindowList();
Craig Mautner59c00972012-07-30 12:10:24 -07002145 }
2146
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002147 /**
2148 * Report a focus change. Must be called with no locks held, and consistently
2149 * from the same serialized thread (such as dispatched from a handler).
2150 */
2151 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
2152 try {
2153 mClient.windowFocusChanged(focused, inTouchMode);
2154 } catch (RemoteException e) {
2155 }
2156 if (mFocusCallbacks != null) {
2157 final int N = mFocusCallbacks.beginBroadcast();
2158 for (int i=0; i<N; i++) {
2159 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2160 try {
2161 if (focused) {
2162 obs.focusGained(mWindowId.asBinder());
2163 } else {
2164 obs.focusLost(mWindowId.asBinder());
2165 }
2166 } catch (RemoteException e) {
2167 }
2168 }
2169 mFocusCallbacks.finishBroadcast();
2170 }
2171 }
2172
Robert Carrc24d8f92016-02-29 16:24:33 -08002173 /**
2174 * Update our current configurations, based on task configuration.
2175 *
2176 * @return A configuration suitable for sending to the client.
2177 */
2178 private Configuration updateConfiguration() {
2179 final Task task = getTask();
2180 final Configuration overrideConfig =
2181 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
2182 final boolean configChanged = isConfigChanged();
2183 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) && configChanged) {
2184 Slog.i(TAG, "Sending new config to window " + this + ": " +
2185 " / config=" + mService.mCurConfiguration + " overrideConfig=" + overrideConfig);
2186 }
2187 setConfiguration(mService.mCurConfiguration, overrideConfig);
2188 return mMergedConfiguration;
2189 }
2190
Craig Mautnerdf88d732014-01-27 09:21:32 -08002191 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002192 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08002193 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002194 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
2195 + ": " + mCompatFrame);
Robert Carrc24d8f92016-02-29 16:24:33 -08002196 final Configuration newConfig = isConfigChanged() ? updateConfiguration() : null;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002197 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING)
2198 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
2199
Craig Mautnerdf88d732014-01-27 09:21:32 -08002200 final Rect frame = mFrame;
2201 final Rect overscanInsets = mLastOverscanInsets;
2202 final Rect contentInsets = mLastContentInsets;
2203 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07002204 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002205 final Rect outsets = mLastOutsets;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002206 final boolean reportDraw = mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING;
Chet Haase8eb48d22014-09-24 07:31:29 -07002207 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
2208 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002209 // To prevent deadlock simulate one-way call if win.mClient is a local object.
2210 mService.mH.post(new Runnable() {
2211 @Override
2212 public void run() {
2213 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002214 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
2215 stableInsets, outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002216 } catch (RemoteException e) {
2217 // Not a remote call, RemoteException won't be raised.
2218 }
2219 }
2220 });
2221 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002222 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002223 outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002224 }
Svetoslav4604abc2014-06-10 18:59:30 -07002225
2226 //TODO (multidisplay): Accessibility supported only for the default display.
2227 if (mService.mAccessibilityController != null
2228 && getDisplayId() == Display.DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07002229 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07002230 }
2231
Craig Mautnerdf88d732014-01-27 09:21:32 -08002232 mOverscanInsetsChanged = false;
2233 mContentInsetsChanged = false;
2234 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07002235 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002236 mOutsetsChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08002237 mWinAnimator.mSurfaceResized = false;
2238 } catch (RemoteException e) {
2239 mOrientationChanging = false;
2240 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2241 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08002242 // We are assuming the hosting process is dead or in a zombie state.
2243 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
2244 + ", removing this window.");
2245 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002246 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002247 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002248 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002249 }
2250
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002251 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08002252 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
2253 // start even if we haven't received the relayout window, so that the client requests
2254 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
2255 // until the window to small size, otherwise the multithread renderer will shift last
2256 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
2257 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002258 boolean resizing = isDragResizing() || isDragResizeChanged();
2259 if (StackId.useWindowFrameForBackdrop(getStackId()) || !resizing) {
2260 return frame;
2261 }
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002262 DisplayInfo displayInfo = getDisplayInfo();
2263 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002264 return mTmpRect;
2265 }
2266
Jorim Jaggi86905582016-02-09 21:36:09 -08002267 @Override
2268 public int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002269 final TaskStack stack = getStack();
2270 if (stack == null) {
2271 return INVALID_STACK_ID;
2272 }
2273 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002274 }
2275
2276 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
2277 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
2278 Configuration newConfig) throws RemoteException {
Chong Zhangedaf3052016-04-22 15:04:31 -07002279 final boolean forceRelayout = isDragResizeChanged() || mResizedWhileNotDragResizing;
2280
Jorim Jaggidc249c42015-12-15 14:57:31 -08002281 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Jorim Jaggia4a58ef2016-01-27 02:10:08 -08002282 reportDraw, newConfig, getBackdropFrame(frame),
Chong Zhangedaf3052016-04-22 15:04:31 -07002283 forceRelayout, mPolicy.isNavBarForcedShownLw(this));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002284 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002285 }
2286
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002287 public void registerFocusObserver(IWindowFocusObserver observer) {
2288 synchronized(mService.mWindowMap) {
2289 if (mFocusCallbacks == null) {
2290 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
2291 }
2292 mFocusCallbacks.register(observer);
2293 }
2294 }
2295
2296 public void unregisterFocusObserver(IWindowFocusObserver observer) {
2297 synchronized(mService.mWindowMap) {
2298 if (mFocusCallbacks != null) {
2299 mFocusCallbacks.unregister(observer);
2300 }
2301 }
2302 }
2303
2304 public boolean isFocused() {
2305 synchronized(mService.mWindowMap) {
2306 return mService.mCurrentFocus == this;
2307 }
2308 }
2309
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07002310 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07002311 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07002312 return task != null && task.inFreeformWorkspace();
2313 }
2314
Wale Ogunwale9185fb02016-03-11 18:06:14 -08002315 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07002316 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08002317 final Task task = getTask();
2318 return task != null && !task.isFullscreen();
2319 }
2320
Chong Zhang3005e752015-09-18 18:46:28 -07002321 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002322 return mDragResizing != computeDragResizing();
2323 }
2324
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002325 /**
2326 * @return Whether we reported a drag resize change to the application or not already.
2327 */
2328 boolean isDragResizingChangeReported() {
2329 return mDragResizingChangeReported;
2330 }
2331
2332 /**
2333 * Resets the state whether we reported a drag resize change to the app.
2334 */
2335 void resetDragResizingChangeReported() {
2336 mDragResizingChangeReported = false;
2337 }
2338
Jorim Jaggidcf467c2015-11-05 13:59:32 +01002339 int getResizeMode() {
2340 return mResizeMode;
2341 }
2342
Jorim Jaggi192086e2016-03-11 17:17:03 +01002343 boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07002344 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002345 if (task == null) {
2346 return false;
2347 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08002348 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
2349
2350 // Floating windows never enter drag resize mode.
2351 return false;
2352 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002353 if (task.isDragResizing()) {
2354 return true;
2355 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01002356
2357 // If the bounds are currently frozen, it means that the layout size that the app sees
2358 // and the bounds we clip this window to might be different. In order to avoid holes, we
2359 // simulate that we are still resizing so the app fills the hole with the resizing
2360 // background.
2361 return (mDisplayContent.mDividerControllerLocked.isResizing()
2362 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Jorim Jaggi899327f2016-02-25 20:44:18 -05002363 !task.inFreeformWorkspace() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08002364
Chong Zhang3005e752015-09-18 18:46:28 -07002365 }
2366
2367 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002368 final boolean resizing = computeDragResizing();
2369 if (resizing == mDragResizing) {
2370 return;
2371 }
2372 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01002373 final Task task = getTask();
2374 if (task != null && task.isDragResizing()) {
2375 mResizeMode = task.getDragResizeMode();
2376 } else {
2377 mResizeMode = mDragResizing && mDisplayContent.mDividerControllerLocked.isResizing()
2378 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
2379 : DRAG_RESIZE_MODE_FREEFORM;
2380 }
Chong Zhang3005e752015-09-18 18:46:28 -07002381 }
2382
2383 boolean isDragResizing() {
2384 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07002385 }
2386
Robert Carr2487ce72016-04-07 15:18:45 -07002387 boolean isDockedResizing() {
2388 return mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
2389 }
2390
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002391 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08002392 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002393 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08002394 if (stack != null) {
2395 pw.print(" stackId="); pw.print(stack.mStackId);
2396 }
Wale Ogunwale4c5aa5172016-04-19 11:29:05 -07002397 if (mNotOnAppsDisplay) {
2398 pw.print(" mNotOnAppsDisplay="); pw.print(mNotOnAppsDisplay);
2399 }
Craig Mautner59c00972012-07-30 12:10:24 -07002400 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002401 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07002402 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08002403 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
2404 pw.print(" package="); pw.print(mAttrs.packageName);
2405 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002406 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002407 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
2408 pw.print(" h="); pw.print(mRequestedHeight);
2409 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07002410 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
2411 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
2412 pw.print(" h="); pw.println(mLastRequestedHeight);
2413 }
Robert Carr51a1b872015-12-08 14:03:13 -08002414 if (isChildWindow() || mLayoutAttached) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002415 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
2416 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
2417 }
2418 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
2419 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
2420 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
2421 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
2422 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
2423 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002424 if (dumpAll) {
2425 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
2426 pw.print(" mSubLayer="); pw.print(mSubLayer);
2427 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautner59431632012-04-04 11:56:44 -07002428 pw.print((mTargetAppToken != null ?
2429 mTargetAppToken.mAppAnimator.animLayerAdjustment
2430 : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002431 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
2432 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08002433 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002434 if (dumpAll) {
2435 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
2436 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
2437 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07002438 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
2439 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08002440 pw.print(isAnimatingWithSavedSurface());
Chong Zhang112eb8c2015-11-02 11:17:00 -08002441 pw.print(" mAppDied=");pw.println(mAppDied);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002442 }
2443 if (mTargetAppToken != null) {
2444 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
2445 }
2446 pw.print(prefix); pw.print("mViewVisibility=0x");
2447 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002448 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
2449 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07002450 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
2451 pw.print(" mSystemUiVisibility=0x");
2452 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002453 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002454 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
2455 || mAttachedHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002456 pw.print(prefix); pw.print("mPolicyVisibility=");
2457 pw.print(mPolicyVisibility);
2458 pw.print(" mPolicyVisibilityAfterAnim=");
2459 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002460 pw.print(" mAppOpVisibility=");
2461 pw.print(mAppOpVisibility);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002462 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
2463 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08002464 if (!mRelayoutCalled || mLayoutNeeded) {
2465 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
2466 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002467 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002468 if (mXOffset != 0 || mYOffset != 0) {
2469 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
2470 pw.print(" y="); pw.println(mYOffset);
2471 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002472 if (dumpAll) {
2473 pw.print(prefix); pw.print("mGivenContentInsets=");
2474 mGivenContentInsets.printShortString(pw);
2475 pw.print(" mGivenVisibleInsets=");
2476 mGivenVisibleInsets.printShortString(pw);
2477 pw.println();
2478 if (mTouchableInsets != 0 || mGivenInsetsPending) {
2479 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
2480 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07002481 Region region = new Region();
2482 getTouchableRegion(region);
2483 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002484 }
2485 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Wale Ogunwale7c726682015-02-06 17:34:28 -08002486 if (mOverrideConfig != Configuration.EMPTY) {
2487 pw.print(prefix); pw.print("mOverrideConfig="); pw.println(mOverrideConfig);
2488 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002489 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07002490 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07002491 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Chong Zhanga8975bd2016-01-28 17:13:47 -08002492 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08002493 pw.print(" hasSavedSurface()="); pw.print(hasSavedSurface());
2494 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002495 if (dumpAll) {
2496 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
2497 pw.print(" last="); mLastFrame.printShortString(pw);
2498 pw.println();
2499 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002500 if (mEnforceSizeCompat) {
2501 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002502 pw.println();
2503 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002504 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002505 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002506 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002507 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002508 pw.println();
2509 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
2510 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002511 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002512 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002513 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002514 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04002515 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
2516 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002517 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
2518 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002519 pw.print(prefix); pw.print("Cur insets: overscan=");
2520 mOverscanInsets.printShortString(pw);
2521 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002522 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002523 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07002524 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002525 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002526 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002527 pw.print(prefix); pw.print("Lst insets: overscan=");
2528 mLastOverscanInsets.printShortString(pw);
2529 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002530 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002531 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002532 pw.print(" physical="); mLastOutsets.printShortString(pw);
2533 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002534 pw.println();
2535 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07002536 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
2537 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002538 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
2539 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002540 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
2541 pw.print(" mDestroying="); pw.print(mDestroying);
2542 pw.print(" mRemoved="); pw.println(mRemoved);
2543 }
2544 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
2545 pw.print(prefix); pw.print("mOrientationChanging=");
2546 pw.print(mOrientationChanging);
2547 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
2548 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
2549 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07002550 if (mLastFreezeDuration != 0) {
2551 pw.print(prefix); pw.print("mLastFreezeDuration=");
2552 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
2553 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002554 if (mHScale != 1 || mVScale != 1) {
2555 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
2556 pw.print(" mVScale="); pw.println(mVScale);
2557 }
2558 if (mWallpaperX != -1 || mWallpaperY != -1) {
2559 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
2560 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
2561 }
2562 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
2563 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
2564 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
2565 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07002566 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
2567 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
2568 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
2569 pw.print(mWallpaperDisplayOffsetX);
2570 pw.print(" mWallpaperDisplayOffsetY=");
2571 pw.println(mWallpaperDisplayOffsetY);
2572 }
Jeff Brownc2932a12014-11-20 18:04:05 -08002573 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07002574 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08002575 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08002576 if (isDragResizing()) {
2577 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
2578 }
2579 if (computeDragResizing()) {
2580 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
2581 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002582 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002583
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002584 String makeInputChannelName() {
2585 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002586 + " " + getWindowTag();
2587 }
2588
Robert Carra1eb4392015-12-10 12:43:51 -08002589 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002590 CharSequence tag = mAttrs.getTitle();
2591 if (tag == null || tag.length() <= 0) {
2592 tag = mAttrs.packageName;
2593 }
2594 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002595 }
2596
2597 @Override
2598 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002599 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002600 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08002601 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002602 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002603 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -07002604 + " u" + UserHandle.getUserId(mSession.mUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002605 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002606 }
2607 return mStringNameCache;
2608 }
Robert Carr58f29132015-10-29 14:19:05 -07002609
2610 void transformFromScreenToSurfaceSpace(Rect rect) {
2611 if (mHScale >= 0) {
Chong Zhang84389572016-01-13 10:33:27 -08002612 rect.left = (int) (rect.left / mHScale);
2613 rect.right = (int) (rect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07002614 }
2615 if (mVScale >= 0) {
Chong Zhang84389572016-01-13 10:33:27 -08002616 rect.top = (int) (rect.top / mVScale);
2617 rect.bottom = (int) (rect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07002618 }
2619 }
Robert Carr31e28482015-12-02 16:53:18 -08002620
Jorim Jaggif5834272016-04-04 20:25:41 -07002621 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
2622 final int pw = containingFrame.width();
2623 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08002624 final Task task = getTask();
Andrii Kulian933076d2016-03-29 17:04:42 -07002625 final boolean nonFullscreenTask = isInMultiWindowMode();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07002626 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
2627
2628 // We need to fit it to the display if either
2629 // a) The task is fullscreen, or we don't have a task (we assume fullscreen for the taskless
2630 // windows)
2631 // b) If it's a child window, we also need to fit it to the display unless
2632 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popup and similar windows on screen,
2633 // but SurfaceViews want to be always at a specific location so we don't fit it to the
2634 // display.
2635 final boolean fitToDisplay = (task == null || !nonFullscreenTask)
2636 || (isChildWindow() && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08002637 float x, y;
2638 int w,h;
2639
2640 if ((mAttrs.flags & FLAG_SCALED) != 0) {
2641 if (mAttrs.width < 0) {
2642 w = pw;
2643 } else if (mEnforceSizeCompat) {
2644 w = (int)(mAttrs.width * mGlobalScale + .5f);
2645 } else {
2646 w = mAttrs.width;
2647 }
2648 if (mAttrs.height < 0) {
2649 h = ph;
2650 } else if (mEnforceSizeCompat) {
2651 h = (int)(mAttrs.height * mGlobalScale + .5f);
2652 } else {
2653 h = mAttrs.height;
2654 }
2655 } else {
2656 if (mAttrs.width == MATCH_PARENT) {
2657 w = pw;
2658 } else if (mEnforceSizeCompat) {
2659 w = (int)(mRequestedWidth * mGlobalScale + .5f);
2660 } else {
2661 w = mRequestedWidth;
2662 }
2663 if (mAttrs.height == MATCH_PARENT) {
2664 h = ph;
2665 } else if (mEnforceSizeCompat) {
2666 h = (int)(mRequestedHeight * mGlobalScale + .5f);
2667 } else {
2668 h = mRequestedHeight;
2669 }
2670 }
2671
2672 if (mEnforceSizeCompat) {
2673 x = mAttrs.x * mGlobalScale;
2674 y = mAttrs.y * mGlobalScale;
2675 } else {
2676 x = mAttrs.x;
2677 y = mAttrs.y;
2678 }
2679
Robert Carr1d2bacb2016-03-30 14:29:35 -07002680 if (nonFullscreenTask && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08002681 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08002682 // required by {@link Gravity#apply} call.
2683 w = Math.min(w, pw);
2684 h = Math.min(h, ph);
2685 }
2686
2687 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07002688 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08002689 (int) (x + mAttrs.horizontalMargin * pw),
2690 (int) (y + mAttrs.verticalMargin * ph), mFrame);
2691
2692 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08002693 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07002694 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08002695 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08002696
2697 // We need to make sure we update the CompatFrame as it is used for
2698 // cropping decisions, etc, on systems where we lack a decor layer.
2699 mCompatFrame.set(mFrame);
2700 if (mEnforceSizeCompat) {
2701 // See comparable block in computeFrameLw.
2702 mCompatFrame.scale(mInvGlobalScale);
2703 }
Robert Carr31e28482015-12-02 16:53:18 -08002704 }
Robert Carr51a1b872015-12-08 14:03:13 -08002705
2706 boolean isChildWindow() {
2707 return mAttachedWindow != null;
2708 }
Robert Carra1eb4392015-12-10 12:43:51 -08002709
Robert Carrf3b72c72016-03-21 18:16:39 -07002710 boolean layoutInParentFrame() {
2711 return isChildWindow() && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
2712 }
2713
Robert Carra1eb4392015-12-10 12:43:51 -08002714 void setReplacing(boolean animate) {
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08002715 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
2716 || mAttrs.type == TYPE_APPLICATION_STARTING) {
2717 // We don't set replacing on starting windows since they are added by window manager and
2718 // not the client so won't be replaced by the client.
2719 return;
Robert Carra1eb4392015-12-10 12:43:51 -08002720 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08002721
2722 mWillReplaceWindow = true;
2723 mReplacingWindow = null;
2724 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08002725 }
Chong Zhangf596cd52016-01-05 13:42:44 -08002726
2727 void resetReplacing() {
2728 mWillReplaceWindow = false;
2729 mReplacingWindow = null;
2730 mAnimateReplacingWindow = false;
2731 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08002732
Chong Zhang4d7369a2016-04-25 16:09:14 -07002733 void requestUpdateWallpaperIfNeeded() {
2734 if (mDisplayContent != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
2735 mDisplayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
2736 mDisplayContent.layoutNeeded = true;
2737 mService.mWindowPlacerLocked.requestTraversal();
2738 }
2739 }
2740
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08002741 float translateToWindowX(float x) {
2742 float winX = x - mFrame.left;
2743 if (mEnforceSizeCompat) {
2744 winX *= mGlobalScale;
2745 }
2746 return winX;
2747 }
2748
2749 float translateToWindowY(float y) {
2750 float winY = y - mFrame.top;
2751 if (mEnforceSizeCompat) {
2752 winY *= mGlobalScale;
2753 }
2754 return winY;
2755 }
Robert Carrd1a010f2016-04-07 22:36:22 -07002756
Robert Carr9fe459d2016-04-07 23:32:28 -07002757 void transferDimToReplacement() {
2758 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
2759 if (dimLayerUser != null && mDisplayContent != null) {
2760 mDisplayContent.mDimLayerController.applyDim(dimLayerUser,
2761 mReplacingWindow.mWinAnimator,
2762 (mAttrs.flags & FLAG_DIM_BEHIND) != 0 ? true : false);
2763 }
2764 }
2765
Robert Carrd1a010f2016-04-07 22:36:22 -07002766 // During activity relaunch due to resize, we sometimes use window replacement
2767 // for only child windows (as the main window is handled by window preservation)
2768 // and the big surface.
2769 //
2770 // Though windows of TYPE_APPLICATION (as opposed to TYPE_BASE_APPLICATION)
2771 // are not children in the sense of an attached window, we also want to replace
2772 // them at such phases, as they won't be covered by window preservation,
2773 // and in general we expect them to return following relaunch.
2774 boolean shouldBeReplacedWithChildren() {
2775 return isChildWindow() || mAttrs.type == TYPE_APPLICATION;
2776 }
satokcef37fb2011-10-24 21:49:38 +09002777}