blob: 144b8239f327a86aafb581116fa091b977d167b6 [file] [log] [blame]
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Wale Ogunwale053c8e42015-11-16 14:27:21 -080019import android.app.ActivityManager;
20import android.app.AppOpsManager;
21import android.content.Context;
22import android.content.res.Configuration;
23import android.graphics.Matrix;
24import android.graphics.PixelFormat;
25import android.graphics.Point;
26import android.graphics.Rect;
27import android.graphics.Region;
28import android.os.IBinder;
29import android.os.PowerManager;
30import android.os.RemoteCallbackList;
31import android.os.RemoteException;
32import android.os.SystemClock;
33import android.os.Trace;
34import android.os.UserHandle;
35import android.os.WorkSource;
36import android.util.DisplayMetrics;
37import android.util.Slog;
38import android.util.TimeUtils;
39import android.view.Display;
40import android.view.DisplayInfo;
41import android.view.Gravity;
42import android.view.IApplicationToken;
43import android.view.IWindow;
44import android.view.IWindowFocusObserver;
45import android.view.IWindowId;
46import android.view.InputChannel;
47import android.view.InputEvent;
48import android.view.InputEventReceiver;
49import android.view.View;
50import android.view.ViewTreeObserver;
51import android.view.WindowManager;
52import android.view.WindowManagerPolicy;
53
Jorim Jaggi9511b0f2016-01-29 19:12:44 -080054import com.android.server.input.InputWindowHandle;
55
Wale Ogunwale053c8e42015-11-16 14:27:21 -080056import java.io.PrintWriter;
57import java.util.ArrayList;
58
Wale Ogunwaled045c822015-12-02 09:14:28 -080059import static android.app.ActivityManager.StackId;
Wale Ogunwalea9f9b372016-02-04 18:04:39 -080060import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
Filip Gruszczynski84fa3352016-01-25 16:28:49 -080061import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
Wale Ogunwalecad05a02015-09-25 10:41:44 -070062import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080063import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
64import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
65import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
66import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080067import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080068import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070069import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080070import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080071import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
72import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080073import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Wale Ogunwale945d1972016-03-23 13:16:41 -070074import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070075import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080076import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080077import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
Robert Carr31e28482015-12-02 16:53:18 -080078import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080079import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080080import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -080081import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
Robert Carra1eb4392015-12-10 12:43:51 -080082import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080083import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
84import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080085import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080086import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070087import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080088import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
89import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
90import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +010091import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
92import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080093import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
94import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
95import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
96import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
97import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
98import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
99import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
100import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
101import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
102import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
103import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
104import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800105
Craig Mautner59c00972012-07-30 12:10:24 -0700106class WindowList extends ArrayList<WindowState> {
Wale Ogunwale33fde7d2016-03-05 22:38:51 -0800107 WindowList() {}
108 WindowList(WindowList windowList) {
109 super(windowList);
110 }
Craig Mautner59c00972012-07-30 12:10:24 -0700111}
112
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800113/**
114 * A window in the window manager.
115 */
Craig Mautnere32c3072012-03-12 15:25:35 -0700116final class WindowState implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800117 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800118
Skuhne81c524a2015-08-12 13:34:14 -0700119 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700120 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
121 // use hard-coded min sizes for now.
122 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
123 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700124
125 // The thickness of a window resize handle outside the window bounds on the free form workspace
126 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700127 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700128
Robert Carr7098dbd2016-02-01 12:31:01 -0800129 static final boolean DEBUG_DISABLE_SAVING_SURFACES = false;
130
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800131 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700132 final WindowManagerPolicy mPolicy;
133 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800134 final Session mSession;
135 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800136 final int mAppOp;
137 // UserId and appId of the owner. Don't display windows of non-current user.
138 final int mOwnerUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800139 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800140 WindowToken mToken;
141 WindowToken mRootToken;
142 AppWindowToken mAppToken;
143 AppWindowToken mTargetAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700144
145 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
146 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800147 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
148 final DeathRecipient mDeathRecipient;
149 final WindowState mAttachedWindow;
Craig Mautner7b1aa772012-11-30 16:14:45 -0800150 final WindowList mChildWindows = new WindowList();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800151 final int mBaseLayer;
152 final int mSubLayer;
153 final boolean mLayoutAttached;
154 final boolean mIsImWindow;
155 final boolean mIsWallpaper;
156 final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700157 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700158 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800159 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700160 int mSystemUiVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800161 boolean mPolicyVisibility = true;
162 boolean mPolicyVisibilityAfterAnim = true;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -0800163 boolean mAppOpVisibility = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800164 boolean mAppFreezing;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800165 boolean mAttachedHidden; // is our parent window hidden?
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800166 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Chong Zhang0275e392015-09-17 10:41:44 -0700167 boolean mDragResizing;
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800168 boolean mDragResizingChangeReported;
Jorim Jaggidcf467c2015-11-05 13:59:32 +0100169 int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700170
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800171 RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
172
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700173 /**
174 * The window size that was requested by the application. These are in
175 * the application's coordinate space (without compatibility scale applied).
176 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800177 int mRequestedWidth;
178 int mRequestedHeight;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700179 int mLastRequestedWidth;
180 int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700181
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800182 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800183 boolean mHaveFrame;
184 boolean mObscured;
185 boolean mTurnOnScreen;
186
187 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700188
Wale Ogunwale60454db2015-01-23 16:05:07 -0800189 private Configuration mConfiguration = Configuration.EMPTY;
190 private Configuration mOverrideConfig = Configuration.EMPTY;
Robert Carrc24d8f92016-02-29 16:24:33 -0800191 // Represents the changes from our override configuration applied
192 // to the global configuration. This is the only form of configuration
193 // which is suitable for delivery to the client.
194 private Configuration mMergedConfiguration = new Configuration();
Craig Mautnere8552142012-11-07 13:55:47 -0800195 // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned.
196 // Used only on {@link #TYPE_KEYGUARD}.
197 private boolean mConfigHasChanged;
Craig Mautnera2c77052012-03-26 12:14:43 -0700198
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700199 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700200 * Actual position of the surface shown on-screen (may be modified by animation). These are
201 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700202 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700203 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800204
205 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700206 * Insets that determine the actually visible area. These are in the application's
207 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800208 */
209 final Rect mVisibleInsets = new Rect();
210 final Rect mLastVisibleInsets = new Rect();
211 boolean mVisibleInsetsChanged;
212
213 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700214 * Insets that are covered by system windows (such as the status bar) and
215 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700216 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800217 */
218 final Rect mContentInsets = new Rect();
219 final Rect mLastContentInsets = new Rect();
220 boolean mContentInsetsChanged;
221
222 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800223 * Insets that determine the area covered by the display overscan region. These are in the
224 * application's coordinate space (without compatibility scale applied).
225 */
226 final Rect mOverscanInsets = new Rect();
227 final Rect mLastOverscanInsets = new Rect();
228 boolean mOverscanInsetsChanged;
229
230 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700231 * Insets that determine the area covered by the stable system windows. These are in the
232 * application's coordinate space (without compatibility scale applied).
233 */
234 final Rect mStableInsets = new Rect();
235 final Rect mLastStableInsets = new Rect();
236 boolean mStableInsetsChanged;
237
238 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700239 * Outsets determine the area outside of the surface where we want to pretend that it's possible
240 * to draw anyway.
241 */
242 final Rect mOutsets = new Rect();
243 final Rect mLastOutsets = new Rect();
244 boolean mOutsetsChanged = false;
245
246 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800247 * Set to true if we are waiting for this window to receive its
248 * given internal insets before laying out other windows based on it.
249 */
250 boolean mGivenInsetsPending;
251
252 /**
253 * These are the content insets that were given during layout for
254 * this window, to be applied to windows behind it.
255 */
256 final Rect mGivenContentInsets = new Rect();
257
258 /**
259 * These are the visible insets that were given during layout for
260 * this window, to be applied to windows behind it.
261 */
262 final Rect mGivenVisibleInsets = new Rect();
263
264 /**
265 * This is the given touchable area relative to the window frame, or null if none.
266 */
267 final Region mGivenTouchableRegion = new Region();
268
269 /**
270 * Flag indicating whether the touchable region should be adjusted by
271 * the visible insets; if false the area outside the visible insets is
272 * NOT touchable, so we must use those to adjust the frame during hit
273 * tests.
274 */
275 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
276
277 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400278 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700279 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800280 float mHScale=1, mVScale=1;
281 float mLastHScale=1, mLastVScale=1;
282 final Matrix mTmpMatrix = new Matrix();
283
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700284 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800285 final Rect mFrame = new Rect();
286 final Rect mLastFrame = new Rect();
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700287 // Frame that is scaled to the application's coordinate space when in
288 // screen size compatibility mode.
289 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800290
291 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700292
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800293 final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700294
Wale Ogunwale94596652015-02-06 19:27:34 -0800295 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
296 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700297 final Rect mDisplayFrame = new Rect();
298
299 // The region of the display frame that the display type supports displaying content on. This
300 // is mostly a special case for TV where some displays don’t have the entire display usable.
301 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
302 // window display contents to extend into the overscan region.
303 final Rect mOverscanFrame = new Rect();
304
305 // The display frame minus the stable insets. This value is always constant regardless of if
306 // the status bar or navigation bar is visible.
Adrian Roosfa104232014-06-20 16:10:14 -0700307 final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800308
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700309 // The area not occupied by the status and navigation bars. So, if both status and navigation
310 // bars are visible, the decor frame is equal to the stable frame.
311 final Rect mDecorFrame = new Rect();
312
313 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
314 // minus the area occupied by the IME if the IME is present.
315 final Rect mContentFrame = new Rect();
316
317 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
318 // displays hint text.
319 final Rect mVisibleFrame = new Rect();
320
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700321 // Frame that includes dead area outside of the surface but where we want to pretend that it's
322 // possible to draw.
323 final Rect mOutsetFrame = new Rect();
324
Jorim Jaggidc249c42015-12-15 14:57:31 -0800325 /**
326 * Usually empty. Set to the task's tempInsetFrame. See
327 *{@link android.app.IActivityManager#resizeDockedStack}.
328 */
329 final Rect mInsetFrame = new Rect();
330
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800331 boolean mContentChanged;
332
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800333 // If a window showing a wallpaper: the requested offset for the
334 // wallpaper; if a wallpaper window: the currently applied offset.
335 float mWallpaperX = -1;
336 float mWallpaperY = -1;
337
338 // If a window showing a wallpaper: what fraction of the offset
339 // range corresponds to a full virtual screen.
340 float mWallpaperXStep = -1;
341 float mWallpaperYStep = -1;
342
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700343 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
344 // to its window; if a wallpaper window: not used.
345 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
346 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
347
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800348 // Wallpaper windows: pixels offset based on above variables.
349 int mXOffset;
350 int mYOffset;
351
Craig Mautner2268e7e2012-12-13 15:40:00 -0800352 /**
353 * This is set after IWindowSession.relayout() has been called at
354 * least once for the window. It allows us to detect the situation
355 * where we don't yet have a surface, but should have one soon, so
356 * we can give the window focus before waiting for the relayout.
357 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800358 boolean mRelayoutCalled;
359
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800360 /**
361 * If the application has called relayout() with changes that can
362 * impact its window's size, we need to perform a layout pass on it
363 * even if it is not currently visible for layout. This is set
364 * when in that case until the layout is done.
365 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800366 boolean mLayoutNeeded;
367
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800368 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800369 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800370
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800371 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800372 boolean mDestroying;
373
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800374 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800375 boolean mRemoveOnExit;
376
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800377 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800378 * Whether the app died while it was visible, if true we might need
379 * to continue to show it until it's restarted.
380 */
381 boolean mAppDied;
382
383 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800384 * Set when the orientation is changing and this window has not yet
385 * been updated for the new orientation.
386 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800387 boolean mOrientationChanging;
388
Dianne Hackborna57c6952013-03-29 14:46:40 -0700389 /**
390 * How long we last kept the screen frozen.
391 */
392 int mLastFreezeDuration;
393
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800394 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800395 boolean mRemoved;
396
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800397 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800398 * It is save to remove the window and destroy the surface because the client requested removal
399 * or some other higher level component said so (e.g. activity manager).
400 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800401 */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800402 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800403
404 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800405 * Temp for keeping track of windows that have been removed when
406 * rebuilding window list.
407 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800408 boolean mRebuilding;
409
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800410 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700411 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800412 InputChannel mInputChannel;
Chong Zhang112eb8c2015-11-02 11:17:00 -0800413 InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800414
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800415 // Used to improve performance of toString()
416 String mStringNameCache;
417 CharSequence mLastTitle;
Dianne Hackborn529e7442012-11-01 14:22:28 -0700418 boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800419
Craig Mautnera2c77052012-03-26 12:14:43 -0700420 final WindowStateAnimator mWinAnimator;
421
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700422 boolean mHasSurface = false;
423
Craig Mautner19ab8282014-05-07 10:35:34 -0700424 boolean mNotOnAppsDisplay = false;
Craig Mautner59c00972012-07-30 12:10:24 -0700425 DisplayContent mDisplayContent;
Craig Mautner6881a102012-07-27 13:04:51 -0700426
Craig Mautner88400d32012-09-30 12:35:45 -0700427 /** When true this window can be displayed on screens owther than mOwnerUid's */
428 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700429
Robert Carr13f7be9e2015-12-02 18:39:45 -0800430 // Whether the window has a saved surface from last pause, which can be
431 // used to start an entering animation earlier.
432 public boolean mSurfaceSaved = false;
433
Robert Carra1eb4392015-12-10 12:43:51 -0800434 // This window will be replaced due to relaunch. This allows window manager
435 // to differentiate between simple removal of a window and replacement. In the latter case it
436 // will preserve the old window until the new one is drawn.
437 boolean mWillReplaceWindow = false;
438 // If true, the replaced window was already requested to be removed.
439 boolean mReplacingRemoveRequested = false;
440 // Whether the replacement of the window should trigger app transition animation.
441 boolean mAnimateReplacingWindow = false;
442 // If not null, the window that will be used to replace the old one. This is being set when
443 // the window is added and unset when this window reports its first draw.
444 WindowState mReplacingWindow = null;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800445 // Whether this window is being moved via the resize API
446 boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800447
Jeff Brownc2932a12014-11-20 18:04:05 -0800448 /**
449 * Wake lock for drawing.
450 * Even though it's slightly more expensive to do so, we will use a separate wake lock
451 * for each app that is requesting to draw while dozing so that we can accurately track
452 * who is preventing the system from suspending.
453 * This lock is only acquired on first use.
454 */
455 PowerManager.WakeLock mDrawLock;
456
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700457 final private Rect mTmpRect = new Rect();
458
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800459 /**
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800460 * See {@link #notifyMovedInStack}.
461 */
462 private boolean mJustMovedInStack;
463
464 /**
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800465 * Whether the window was resized by us while it was gone for layout.
466 */
467 boolean mResizedWhileGone = false;
468
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800469 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800470 WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a,
Craig Mautner59c00972012-07-30 12:10:24 -0700471 int viewVisibility, final DisplayContent displayContent) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800472 mService = service;
473 mSession = s;
474 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800475 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800476 mToken = token;
Craig Mautnera2d7b112012-08-21 15:12:20 -0700477 mOwnerUid = s.mUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800478 mWindowId = new IWindowId.Stub() {
479 @Override
480 public void registerFocusObserver(IWindowFocusObserver observer) {
481 WindowState.this.registerFocusObserver(observer);
482 }
483 @Override
484 public void unregisterFocusObserver(IWindowFocusObserver observer) {
485 WindowState.this.unregisterFocusObserver(observer);
486 }
487 @Override
488 public boolean isFocused() {
489 return WindowState.this.isFocused();
490 }
491 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800492 mAttrs.copyFrom(a);
493 mViewVisibility = viewVisibility;
Craig Mautner59c00972012-07-30 12:10:24 -0700494 mDisplayContent = displayContent;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700495 mPolicy = mService.mPolicy;
496 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800497 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700498 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700499 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800500 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700501 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700502 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800503 try {
504 c.asBinder().linkToDeath(deathRecipient, 0);
505 } catch (RemoteException e) {
506 mDeathRecipient = null;
507 mAttachedWindow = null;
508 mLayoutAttached = false;
509 mIsImWindow = false;
510 mIsWallpaper = false;
511 mIsFloatingLayer = false;
512 mBaseLayer = 0;
513 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700514 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700515 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800516 return;
517 }
518 mDeathRecipient = deathRecipient;
519
520 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
521 mAttrs.type <= LAST_SUB_WINDOW)) {
522 // The multiplier here is to reserve space for multiple
523 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700524 mBaseLayer = mPolicy.windowTypeToLayerLw(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800525 attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
526 + WindowManagerService.TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700527 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800528 mAttachedWindow = attachedWindow;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800529 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
takeda.masayuki18735092012-12-12 11:06:24 +0900530
tiger_huange2a98a72014-11-13 19:46:28 +0800531 final WindowList childWindows = mAttachedWindow.mChildWindows;
532 final int numChildWindows = childWindows.size();
533 if (numChildWindows == 0) {
534 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900535 } else {
tiger_huange2a98a72014-11-13 19:46:28 +0800536 boolean added = false;
537 for (int i = 0; i < numChildWindows; i++) {
538 final int childSubLayer = childWindows.get(i).mSubLayer;
539 if (mSubLayer < childSubLayer
540 || (mSubLayer == childSubLayer && childSubLayer < 0)) {
541 // We insert the child window into the list ordered by the sub-layer. For
542 // same sub-layers, the negative one should go below others; the positive
543 // one should go above others.
544 childWindows.add(i, this);
545 added = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900546 break;
takeda.masayuki18735092012-12-12 11:06:24 +0900547 }
548 }
tiger_huange2a98a72014-11-13 19:46:28 +0800549 if (!added) {
550 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900551 }
552 }
553
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800554 mLayoutAttached = mAttrs.type !=
555 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
556 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
557 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
558 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
559 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
560 } else {
561 // The multiplier here is to reserve space for multiple
562 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700563 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800564 * WindowManagerService.TYPE_LAYER_MULTIPLIER
565 + WindowManagerService.TYPE_LAYER_OFFSET;
566 mSubLayer = 0;
567 mAttachedWindow = null;
568 mLayoutAttached = false;
569 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
570 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
571 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
572 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
573 }
574
575 WindowState appWin = this;
Robert Carr51a1b872015-12-08 14:03:13 -0800576 while (appWin.isChildWindow()) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700577 appWin = appWin.mAttachedWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800578 }
579 WindowToken appToken = appWin.mToken;
580 while (appToken.appWindowToken == null) {
581 WindowToken parent = mService.mTokenMap.get(appToken.token);
582 if (parent == null || appToken == parent) {
583 break;
584 }
585 appToken = parent;
586 }
587 mRootToken = appToken;
588 mAppToken = appToken.appWindowToken;
Craig Mautner19ab8282014-05-07 10:35:34 -0700589 if (mAppToken != null) {
590 final DisplayContent appDisplay = getDisplayContent();
591 mNotOnAppsDisplay = displayContent != appDisplay;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700592
593 if (mAppToken.showForAllUsers) {
594 // Windows for apps that can show for all users should also show when the
595 // device is locked.
596 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
597 }
Craig Mautner19ab8282014-05-07 10:35:34 -0700598 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800599
Craig Mautner322e4032012-07-13 13:35:20 -0700600 mWinAnimator = new WindowStateAnimator(this);
601 mWinAnimator.mAlpha = a.alpha;
602
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800603 mRequestedWidth = 0;
604 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700605 mLastRequestedWidth = 0;
606 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800607 mXOffset = 0;
608 mYOffset = 0;
609 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800610 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700611 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
612 displayContent.getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800613 }
614
615 void attach() {
616 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700617 TAG, "Attaching " + this + " token=" + mToken
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800618 + ", list=" + mToken.windows);
619 mSession.windowAddedLocked();
620 }
621
Craig Mautnera2c77052012-03-26 12:14:43 -0700622 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800623 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800624 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800625 }
626
627 @Override
628 public String getOwningPackage() {
629 return mAttrs.packageName;
630 }
631
632 @Override
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700633 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf, Rect sf,
634 Rect osf) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800635 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700636 // This window is being replaced and either already got information that it's being
637 // removed or we are still waiting for some information. Because of this we don't
638 // want to apply any more changes to it, so it remains in this state until new window
639 // appears.
640 return;
641 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800642 mHaveFrame = true;
643
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700644 final Task task = getTask();
Wale Ogunwale9185fb02016-03-11 18:06:14 -0800645 final boolean fullscreenTask = !inMultiWindowMode();
Robert Carre6275582016-02-29 15:45:45 -0800646 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800647
Chong Zhangae35fef2016-03-16 15:56:55 -0700648 // If the task has temp inset bounds set, we have to make sure all its windows uses
649 // the temp inset frame. Otherwise different display frames get applied to the main
650 // window and the child window, making them misaligned.
651 if (fullscreenTask) {
652 mInsetFrame.setEmpty();
653 } else {
654 task.getTempInsetBounds(mInsetFrame);
655 }
656
657 if (mInsetFrame.isEmpty() && (fullscreenTask
Robert Carrf3b72c72016-03-21 18:16:39 -0700658 || layoutInParentFrame())) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800659 // We use the parent frame as the containing frame for fullscreen and child windows
660 mContainingFrame.set(pf);
661 mDisplayFrame.set(df);
662 } else {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700663 task.getBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100664 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
665
666 // If the bounds are frozen, we still want to translate the window freely and only
667 // freeze the size.
668 Rect frozen = mAppToken.mFrozenBounds.peek();
669 mContainingFrame.right = mContainingFrame.left + frozen.width();
670 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
671 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800672 final WindowState imeWin = mService.mInputMethodWindow;
673 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this
674 && mContainingFrame.bottom > cf.bottom) {
675 // IME is up and obscuring this window. Adjust the window position so it is visible.
676 mContainingFrame.top -= mContainingFrame.bottom - cf.bottom;
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700677 }
Skuhne81c524a2015-08-12 13:34:14 -0700678
Robert Carre6275582016-02-29 15:45:45 -0800679 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700680 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
681 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800682 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700683 if (mContainingFrame.isEmpty()) {
684 mContainingFrame.set(cf);
685 }
Doris Liu06d582d2015-06-01 13:18:43 -0700686 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800687 mDisplayFrame.set(mContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700688 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800689
Craig Mautner967212c2013-04-13 21:10:58 -0700690 final int pw = mContainingFrame.width();
691 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800692
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800693 if (!mParentFrame.equals(pf)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800694 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800695 // + " to " + pf);
696 mParentFrame.set(pf);
697 mContentChanged = true;
698 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700699 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
700 mLastRequestedWidth = mRequestedWidth;
701 mLastRequestedHeight = mRequestedHeight;
702 mContentChanged = true;
703 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800704
Craig Mautnereda67292013-04-28 13:50:14 -0700705 mOverscanFrame.set(of);
706 mContentFrame.set(cf);
707 mVisibleFrame.set(vf);
John Spurlock46646232013-09-30 22:32:42 -0400708 mDecorFrame.set(dcf);
Adrian Roosfa104232014-06-20 16:10:14 -0700709 mStableFrame.set(sf);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700710 final boolean hasOutsets = osf != null;
711 if (hasOutsets) {
712 mOutsetFrame.set(osf);
713 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800714
Craig Mautnereda67292013-04-28 13:50:14 -0700715 final int fw = mFrame.width();
716 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800717
Robert Carr31e28482015-12-02 16:53:18 -0800718 applyGravityAndUpdateFrame();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800719
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700720 // Calculate the outsets before the content frame gets shrinked to the window frame.
721 if (hasOutsets) {
722 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
723 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
724 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
725 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
726 } else {
727 mOutsets.set(0, 0, 0, 0);
728 }
729
Jorim Jaggidc249c42015-12-15 14:57:31 -0800730 // Denotes the actual frame used to calculate the insets. When resizing in docked mode,
731 // we'd like to freeze the layout, so we also need to freeze the insets temporarily. By the
732 // notion of a task having a different inset frame, we can achieve that while still moving
733 // the task around.
734 final Rect frame = !mInsetFrame.isEmpty() ? mInsetFrame : mFrame;
735
Craig Mautnera248eee2013-05-07 11:41:27 -0700736 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800737 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -0800738 if (windowsAreFloating && !mFrame.isEmpty()) {
Skuhne81c524a2015-08-12 13:34:14 -0700739 // Keep the frame out of the blocked system area, limit it in size to the content area
740 // and make sure that there is always a minimum visible so that the user can drag it
741 // into a usable area..
742 final int height = Math.min(mFrame.height(), mContentFrame.height());
743 final int width = Math.min(mContentFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700744 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700745 final int minVisibleHeight = WindowManagerService.dipToPixel(
746 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics);
747 final int minVisibleWidth = WindowManagerService.dipToPixel(
748 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics);
Skuhne81c524a2015-08-12 13:34:14 -0700749 final int top = Math.max(mContentFrame.top,
750 Math.min(mFrame.top, mContentFrame.bottom - minVisibleHeight));
751 final int left = Math.max(mContentFrame.left + minVisibleWidth - width,
752 Math.min(mFrame.left, mContentFrame.right - minVisibleWidth));
753 mFrame.set(left, top, left + width, top + height);
754 mContentFrame.set(mFrame);
755 mVisibleFrame.set(mContentFrame);
756 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700757 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi192086e2016-03-11 17:17:03 +0100758 mDisplayContent.getDockedDividerController().positionDockedStackedDivider(mFrame);
759 mContentFrame.set(mFrame);
760 if (!mFrame.equals(mLastFrame)) {
761 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800762 }
Skuhne81c524a2015-08-12 13:34:14 -0700763 } else {
Jorim Jaggidc249c42015-12-15 14:57:31 -0800764 mContentFrame.set(Math.max(mContentFrame.left, frame.left),
765 Math.max(mContentFrame.top, frame.top),
766 Math.min(mContentFrame.right, frame.right),
767 Math.min(mContentFrame.bottom, frame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800768
Jorim Jaggidc249c42015-12-15 14:57:31 -0800769 mVisibleFrame.set(Math.max(mVisibleFrame.left, frame.left),
770 Math.max(mVisibleFrame.top, frame.top),
771 Math.min(mVisibleFrame.right, frame.right),
772 Math.min(mVisibleFrame.bottom, frame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800773
Jorim Jaggidc249c42015-12-15 14:57:31 -0800774 mStableFrame.set(Math.max(mStableFrame.left, frame.left),
775 Math.max(mStableFrame.top, frame.top),
776 Math.min(mStableFrame.right, frame.right),
777 Math.min(mStableFrame.bottom, frame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700778 }
Adrian Roosfa104232014-06-20 16:10:14 -0700779
Jorim Jaggi899327f2016-02-25 20:44:18 -0500780 if (fullscreenTask && !windowsAreFloating) {
781 // Windows that are not fullscreen can be positioned outside of the display frame,
782 // but that is not a reason to provide them with overscan insets.
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800783 mOverscanInsets.set(Math.max(mOverscanFrame.left - frame.left, 0),
784 Math.max(mOverscanFrame.top - frame.top, 0),
785 Math.max(frame.right - mOverscanFrame.right, 0),
786 Math.max(frame.bottom - mOverscanFrame.bottom, 0));
787 }
Craig Mautnereda67292013-04-28 13:50:14 -0700788
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100789 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100790 // For the docked divider, we calculate the stable insets like a full-screen window
791 // so it can use it to calculate the snap positions.
792 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
793 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
794 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
795 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800796
797 // The divider doesn't care about insets in any case, so set it to empty so we don't
798 // trigger a relayout when moving it.
799 mContentInsets.setEmpty();
800 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100801 } else {
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700802 // Using mContentInsets as a temp rect. It is safe because we're setting it below.
803 getDisplayContent().getLogicalDisplayRect(mContentInsets);
804 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
805 // non-fullscreen mode.
806 boolean overrideRightInset = !fullscreenTask && mFrame.right > mContentInsets.right;
807 boolean overrideBottomInset = !fullscreenTask && mFrame.bottom > mContentInsets.bottom;
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800808 mContentInsets.set(mContentFrame.left - frame.left,
809 mContentFrame.top - frame.top,
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700810 overrideRightInset ? 0 : frame.right - mContentFrame.right,
811 overrideBottomInset ? 0 : frame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800812
813 mVisibleInsets.set(mVisibleFrame.left - frame.left,
814 mVisibleFrame.top - frame.top,
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700815 overrideRightInset ? 0 : frame.right - mVisibleFrame.right,
816 overrideBottomInset ? 0 : frame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800817
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100818 mStableInsets.set(Math.max(mStableFrame.left - frame.left, 0),
819 Math.max(mStableFrame.top - frame.top, 0),
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700820 overrideRightInset ? 0 : Math.max(frame.right - mStableFrame.right, 0),
821 overrideBottomInset ? 0 : Math.max(frame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100822 }
Adrian Roosfa104232014-06-20 16:10:14 -0700823
Jorim Jaggidc249c42015-12-15 14:57:31 -0800824 if (!mInsetFrame.isEmpty()) {
825 mContentFrame.set(mFrame);
826 mContentFrame.top += mContentInsets.top;
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700827 mContentFrame.bottom -= mContentInsets.bottom;
Jorim Jaggidc249c42015-12-15 14:57:31 -0800828 mContentFrame.left += mContentInsets.left;
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700829 mContentFrame.right -= mContentInsets.right;
Jorim Jaggidc249c42015-12-15 14:57:31 -0800830 mVisibleFrame.set(mFrame);
831 mVisibleFrame.top += mVisibleInsets.top;
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700832 mVisibleFrame.bottom -= mVisibleInsets.bottom;
Jorim Jaggidc249c42015-12-15 14:57:31 -0800833 mVisibleFrame.left += mVisibleInsets.left;
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700834 mVisibleFrame.right -= mVisibleInsets.right;
Jorim Jaggidc249c42015-12-15 14:57:31 -0800835 mStableFrame.set(mFrame);
836 mStableFrame.top += mStableInsets.top;
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700837 mStableFrame.bottom -= mStableInsets.bottom;
Jorim Jaggidc249c42015-12-15 14:57:31 -0800838 mStableFrame.left += mStableInsets.left;
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700839 mStableFrame.right -= mStableInsets.right;
Jorim Jaggidc249c42015-12-15 14:57:31 -0800840 }
Craig Mautnereda67292013-04-28 13:50:14 -0700841 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400842 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700843 // If there is a size compatibility scale being applied to the
844 // window, we need to apply this to its insets so that they are
845 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700846 mOverscanInsets.scale(mInvGlobalScale);
847 mContentInsets.scale(mInvGlobalScale);
848 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700849 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700850 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700851
852 // Also the scaled frame that we report to the app needs to be
853 // adjusted to be in its coordinate space.
854 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400855 }
856
Craig Mautnereda67292013-04-28 13:50:14 -0700857 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800858 final DisplayContent displayContent = getDisplayContent();
859 if (displayContent != null) {
860 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700861 mService.mWallpaperControllerLocked.updateWallpaperOffset(
862 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800863 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800864 }
865
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700866 if (DEBUG_LAYOUT || WindowManagerService.localLOGV) Slog.v(TAG,
867 "Resolving (mRequestedWidth="
868 + mRequestedWidth + ", mRequestedheight="
869 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
870 + "): frame=" + mFrame.toShortString()
871 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -0700872 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700873 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700874 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800875 }
876
Craig Mautnera2c77052012-03-26 12:14:43 -0700877 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800878 public Rect getFrameLw() {
879 return mFrame;
880 }
881
Craig Mautnera2c77052012-03-26 12:14:43 -0700882 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700883 public Point getShownPositionLw() {
884 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800885 }
886
Craig Mautnera2c77052012-03-26 12:14:43 -0700887 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800888 public Rect getDisplayFrameLw() {
889 return mDisplayFrame;
890 }
891
Craig Mautnera2c77052012-03-26 12:14:43 -0700892 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800893 public Rect getOverscanFrameLw() {
894 return mOverscanFrame;
895 }
896
897 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800898 public Rect getContentFrameLw() {
899 return mContentFrame;
900 }
901
Craig Mautnera2c77052012-03-26 12:14:43 -0700902 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800903 public Rect getVisibleFrameLw() {
904 return mVisibleFrame;
905 }
906
Craig Mautnera2c77052012-03-26 12:14:43 -0700907 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800908 public boolean getGivenInsetsPendingLw() {
909 return mGivenInsetsPending;
910 }
911
Craig Mautnera2c77052012-03-26 12:14:43 -0700912 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800913 public Rect getGivenContentInsetsLw() {
914 return mGivenContentInsets;
915 }
916
Craig Mautnera2c77052012-03-26 12:14:43 -0700917 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800918 public Rect getGivenVisibleInsetsLw() {
919 return mGivenVisibleInsets;
920 }
921
Craig Mautnera2c77052012-03-26 12:14:43 -0700922 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800923 public WindowManager.LayoutParams getAttrs() {
924 return mAttrs;
925 }
926
Craig Mautner812d2ca2012-09-27 15:35:34 -0700927 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800928 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
929 int index = -1;
930 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -0700931 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800932 while (true) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -0700933 if (ws.mAttrs.needsMenuKey != WindowManager.LayoutParams.NEEDS_MENU_UNSET) {
934 return ws.mAttrs.needsMenuKey == WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800935 }
936 // If we reached the bottom of the range of windows we are considering,
937 // assume no menu is needed.
938 if (ws == bottom) {
939 return false;
940 }
941 // The current window hasn't specified whether menu key is needed;
942 // look behind it.
943 // First, we may need to determine the starting position.
944 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -0700945 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800946 }
947 index--;
948 if (index < 0) {
949 return false;
950 }
Craig Mautner59c00972012-07-30 12:10:24 -0700951 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800952 }
953 }
954
Craig Mautner19d59bc2012-09-04 11:15:56 -0700955 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700956 public int getSystemUiVisibility() {
957 return mSystemUiVisibility;
958 }
959
Craig Mautner19d59bc2012-09-04 11:15:56 -0700960 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800961 public int getSurfaceLayer() {
962 return mLayer;
963 }
964
Craig Mautner812d2ca2012-09-27 15:35:34 -0700965 @Override
Selim Cinekd6623612015-05-22 18:56:22 -0700966 public int getBaseType() {
967 WindowState win = this;
Robert Carr51a1b872015-12-08 14:03:13 -0800968 while (win.isChildWindow()) {
Selim Cinekd6623612015-05-22 18:56:22 -0700969 win = win.mAttachedWindow;
970 }
971 return win.mAttrs.type;
972 }
973
974 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800975 public IApplicationToken getAppToken() {
976 return mAppToken != null ? mAppToken.appToken : null;
977 }
Craig Mautner19d59bc2012-09-04 11:15:56 -0700978
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700979 @Override
980 public boolean isVoiceInteraction() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700981 return mAppToken != null && mAppToken.voiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700982 }
983
Craig Mautner4c5eb222013-11-18 12:59:05 -0800984 boolean setInsetsChanged() {
985 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
986 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
987 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -0700988 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700989 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
990 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
991 || mOutsetsChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -0800992 }
993
Craig Mautnerdf88d732014-01-27 09:21:32 -0800994 public DisplayContent getDisplayContent() {
Chad Jonesf391ebc2014-06-12 17:45:05 -0700995 if (mAppToken == null || mNotOnAppsDisplay) {
Craig Mautnerbe634952014-06-12 13:39:24 -0700996 return mDisplayContent;
997 }
998 final TaskStack stack = getStack();
999 return stack == null ? mDisplayContent : stack.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001000 }
1001
Chong Zhang09b21ef2015-09-14 10:20:21 -07001002 public DisplayInfo getDisplayInfo() {
1003 final DisplayContent displayContent = getDisplayContent();
1004 return displayContent != null ? displayContent.getDisplayInfo() : null;
1005 }
1006
Craig Mautner19d59bc2012-09-04 11:15:56 -07001007 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001008 final DisplayContent displayContent = getDisplayContent();
1009 if (displayContent == null) {
1010 return -1;
1011 }
1012 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001013 }
1014
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001015 Task getTask() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07001016 return mAppToken != null ? mAppToken.mTask : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001017 }
1018
1019 TaskStack getStack() {
1020 Task task = getTask();
1021 if (task != null) {
1022 if (task.mStack != null) {
1023 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001024 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001025 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001026 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1027 // associate them with some stack to enable dimming.
1028 return mAttrs.type >= WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1029 && mDisplayContent != null ? mDisplayContent.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001030 }
1031
Skuhnef932e562015-08-20 12:07:30 -07001032 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001033 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001034 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001035 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001036 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001037 final Task task = getTask();
1038 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001039 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001040 mTmpRect.setEmpty();
1041 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001042 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001043 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001044 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001045 } else {
1046 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001047 }
1048 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001049
Chong Zhang9184ec62015-09-24 12:32:21 -07001050 bounds.set(mVisibleFrame);
1051 if (intersectWithStackBounds) {
1052 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001053 }
1054
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001055 if (bounds.isEmpty()) {
1056 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001057 if (intersectWithStackBounds) {
1058 bounds.intersect(mTmpRect);
1059 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001060 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001061 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001062 }
1063
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001064 public long getInputDispatchingTimeoutNanos() {
1065 return mAppToken != null
1066 ? mAppToken.inputDispatchingTimeoutNanos
1067 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1068 }
1069
Craig Mautnere8552142012-11-07 13:55:47 -08001070 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001071 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001072 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001073 }
1074
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001075 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1076 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1077 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1078 if (dtdx < -.000001f || dtdx > .000001f) return false;
1079 if (dsdy < -.000001f || dsdy > .000001f) return false;
1080 return true;
1081 }
1082
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001083 void prelayout() {
1084 if (mEnforceSizeCompat) {
1085 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001086 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001087 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001088 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001089 }
1090 }
1091
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001092 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001093 * Does the minimal check for visibility. Callers generally want to use one of the public
1094 * methods as they perform additional checks on the app token.
1095 * TODO: See if there are other places we can use this check below instead of duplicating...
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001096 */
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001097 private boolean isVisibleUnchecked() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001098 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001099 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001100 }
1101
1102 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001103 * Is this window visible? It is not visible if there is no surface, or we are in the process
1104 * of running an exit animation that will remove the surface, or its app token has been hidden.
1105 */
1106 @Override
1107 public boolean isVisibleLw() {
1108 return (mAppToken == null || !mAppToken.hiddenRequested) && isVisibleUnchecked();
1109 }
1110
1111 /**
1112 * Like {@link #isVisibleLw}, but also counts a window that is currently "hidden" behind the
1113 * keyguard as visible. This allows us to apply things like window flags that impact the
1114 * keyguard. XXX I am starting to think we need to have ANOTHER visibility flag for this
1115 * "hidden behind keyguard" state rather than overloading mPolicyVisibility. Ungh.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001116 */
Craig Mautner88400d32012-09-30 12:35:45 -07001117 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001118 public boolean isVisibleOrBehindKeyguardLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001119 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001120 return false;
1121 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001122 final AppWindowToken atoken = mAppToken;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001123 final boolean animating = atoken != null && atoken.mAppAnimator.animation != null;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001124 return mHasSurface && !mDestroying && !mAnimatingExit
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001125 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001126 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001127 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001128 }
1129
1130 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001131 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1132 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001133 */
1134 public boolean isWinVisibleLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001135 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.mAppAnimator.animating)
1136 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001137 }
1138
1139 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001140 * The same as isVisible(), but follows the current hidden state of the associated app token,
1141 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001142 */
1143 boolean isVisibleNow() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001144 return (!mRootToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
1145 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001146 }
1147
1148 /**
1149 * Can this window possibly be a drag/drop target? The test here is
1150 * a combination of the above "visible now" with the check that the
1151 * Input Manager uses when discarding windows from input consideration.
1152 */
1153 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001154 return isVisibleNow() && !mRemoved
1155 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001156 }
1157
1158 /**
1159 * Same as isVisible(), but we also count it as visible between the
1160 * call to IWindowSession.add() and the first relayout().
1161 */
1162 boolean isVisibleOrAdding() {
1163 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001164 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001165 && mPolicyVisibility && !mAttachedHidden
1166 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001167 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001168 }
1169
1170 /**
1171 * Is this window currently on-screen? It is on-screen either if it
1172 * is visible or it is currently running an animation before no longer
1173 * being visible.
1174 */
1175 boolean isOnScreen() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001176 return mPolicyVisibility && isOnScreenIgnoringKeyguard();
1177 }
1178
1179 /**
1180 * Like isOnScreen(), but ignores any force hiding of the window due
1181 * to the keyguard.
1182 */
1183 boolean isOnScreenIgnoringKeyguard() {
1184 if (!mHasSurface || mDestroying) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001185 return false;
1186 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001187 final AppWindowToken atoken = mAppToken;
1188 if (atoken != null) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001189 return ((!mAttachedHidden && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001190 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001191 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001192 return !mAttachedHidden || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001193 }
1194
1195 /**
1196 * Like isOnScreen(), but we don't return true if the window is part
1197 * of a transition that has not yet been started.
1198 */
1199 boolean isReadyForDisplay() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001200 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001201 return false;
1202 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001203 return mHasSurface && mPolicyVisibility && !mDestroying
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001204 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001205 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001206 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001207 }
1208
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001209 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001210 * Like isReadyForDisplay(), but ignores any force hiding of the window due
1211 * to the keyguard.
1212 */
1213 boolean isReadyForDisplayIgnoringKeyguard() {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001214 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001215 return false;
1216 }
1217 final AppWindowToken atoken = mAppToken;
1218 if (atoken == null && !mPolicyVisibility) {
1219 // If this is not an app window, and the policy has asked to force
1220 // hide, then we really do want to hide.
1221 return false;
1222 }
1223 return mHasSurface && !mDestroying
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001224 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE && !mRootToken.hidden)
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001225 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -07001226 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
1227 && !mWinAnimator.isDummyAnimation()));
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001228 }
1229
1230 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001231 * Like isOnScreen, but returns false if the surface hasn't yet
1232 * been drawn.
1233 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001234 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001235 public boolean isDisplayedLw() {
1236 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001237 return isDrawnLw() && mPolicyVisibility
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001238 && ((!mAttachedHidden &&
1239 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001240 || mWinAnimator.mAnimating
1241 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001242 }
1243
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001244 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001245 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001246 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001247 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001248 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001249 return mWinAnimator.mAnimation != null
1250 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001251 }
1252
Craig Mautner812d2ca2012-09-27 15:35:34 -07001253 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001254 public boolean isGoneForLayoutLw() {
1255 final AppWindowToken atoken = mAppToken;
1256 return mViewVisibility == View.GONE
1257 || !mRelayoutCalled
1258 || (atoken == null && mRootToken.hidden)
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001259 || (atoken != null && atoken.hiddenRequested)
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001260 || mAttachedHidden
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001261 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001262 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001263 }
1264
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001265 /**
1266 * Returns true if the window has a surface that it has drawn a
1267 * complete UI in to.
1268 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001269 public boolean isDrawFinishedLw() {
1270 return mHasSurface && !mDestroying &&
1271 (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING
1272 || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1273 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
1274 }
1275
1276 /**
1277 * Returns true if the window has a surface that it has drawn a
1278 * complete UI in to.
1279 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001280 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001281 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001282 return mHasSurface && !mDestroying &&
Craig Mautner749a7bb2012-04-02 13:49:53 -07001283 (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1284 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001285 }
1286
1287 /**
1288 * Return true if the window is opaque and fully drawn. This indicates
1289 * it may obscure windows behind it.
1290 */
1291 boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001292 // When there is keyguard, wallpaper could be placed over the secure app
1293 // window but invisible. We need to check wallpaper visibility explicitly
1294 // to determine if it's occluding apps.
1295 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1296 || (mIsWallpaper && mWallpaperVisible))
Craig Mautnera2c77052012-03-26 12:14:43 -07001297 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001298 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001299 }
1300
1301 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001302 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001303 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1304 */
Craig Mautner4557c082015-04-27 13:07:40 -07001305 boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001306 return mHasSurface && (mContentChanged || mMovedByResize)
Jorim Jaggi192086e2016-03-11 17:17:03 +01001307 && !mAnimatingExit && mService.okToDisplay()
Chong Zhangbd0d9372015-12-28 15:18:29 -08001308 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Craig Mautner4557c082015-04-27 13:07:40 -07001309 && (mAttachedWindow == null || !mAttachedWindow.hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001310 }
1311
Chong Zhang0abb20f2015-11-19 14:17:31 -08001312 boolean isObscuringFullscreen(final DisplayInfo displayInfo) {
1313 Task task = getTask();
1314 if (task != null && task.mStack != null && !task.mStack.isFullscreen()) {
1315 return false;
1316 }
1317 if (!isOpaqueDrawn() || !isFrameFullscreen(displayInfo)) {
1318 return false;
1319 }
1320 return true;
1321 }
1322
1323 boolean isFrameFullscreen(final DisplayInfo displayInfo) {
1324 return mFrame.left <= 0 && mFrame.top <= 0
1325 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001326 }
1327
Craig Mautner812d2ca2012-09-27 15:35:34 -07001328 boolean isConfigChanged() {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001329 final Task task = getTask();
Wale Ogunwale60454db2015-01-23 16:05:07 -08001330 final Configuration overrideConfig =
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001331 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001332 final Configuration serviceConfig = mService.mCurConfiguration;
1333 boolean configChanged =
1334 (mConfiguration != serviceConfig && mConfiguration.diff(serviceConfig) != 0)
1335 || (mOverrideConfig != overrideConfig && !mOverrideConfig.equals(overrideConfig));
Craig Mautnere8552142012-11-07 13:55:47 -08001336
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001337 if ((mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Craig Mautnere8552142012-11-07 13:55:47 -08001338 // Retain configuration changed status until resetConfiguration called.
1339 mConfigHasChanged |= configChanged;
1340 configChanged = mConfigHasChanged;
1341 }
1342
1343 return configChanged;
Craig Mautner812d2ca2012-09-27 15:35:34 -07001344 }
1345
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001346 void removeLocked() {
1347 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001348
Robert Carr51a1b872015-12-08 14:03:13 -08001349 if (isChildWindow()) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001350 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001351 mAttachedWindow.mChildWindows.remove(this);
1352 }
Craig Mautner96868332012-12-04 14:29:11 -08001353 mWinAnimator.destroyDeferredSurfaceLocked();
1354 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001355 mSession.windowRemovedLocked();
1356 try {
1357 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1358 } catch (RuntimeException e) {
1359 // Ignore if it has already been removed (usually because
1360 // we are doing this as part of processing a death note.)
1361 }
1362 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001363
Wale Ogunwale60454db2015-01-23 16:05:07 -08001364 private void setConfiguration(
1365 final Configuration newConfig, final Configuration newOverrideConfig) {
Craig Mautnere8552142012-11-07 13:55:47 -08001366 mConfiguration = newConfig;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001367 mOverrideConfig = newOverrideConfig;
Craig Mautnere8552142012-11-07 13:55:47 -08001368 mConfigHasChanged = false;
Robert Carrc24d8f92016-02-29 16:24:33 -08001369
1370 mMergedConfiguration.setTo(newConfig);
1371 if (newOverrideConfig != null && newOverrideConfig != Configuration.EMPTY) {
1372 mMergedConfiguration.updateFrom(newOverrideConfig);
1373 }
Craig Mautnere8552142012-11-07 13:55:47 -08001374 }
1375
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001376 void setHasSurface(boolean hasSurface) {
1377 mHasSurface = hasSurface;
1378 }
1379
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001380 int getAnimLayerAdjustment() {
1381 if (mTargetAppToken != null) {
1382 return mTargetAppToken.mAppAnimator.animLayerAdjustment;
1383 } else if (mAppToken != null) {
1384 return mAppToken.mAppAnimator.animLayerAdjustment;
1385 } else {
1386 // Nothing is animating, so there is no animation adjustment.
1387 return 0;
1388 }
1389 }
1390
1391 void scheduleAnimationIfDimming() {
1392 if (mDisplayContent == null) {
1393 return;
1394 }
1395 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1396 if (dimLayerUser != null && mDisplayContent.mDimLayerController.isDimming(
1397 dimLayerUser, mWinAnimator)) {
1398 // Force an animation pass just to update the mDimLayer layer.
1399 mService.scheduleAnimationLocked();
1400 }
1401 }
1402
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08001403 /**
1404 * Notifies this window that the corresponding task has just moved in the stack.
1405 * <p>
1406 * This is used to fix the following: If we moved in the stack, and if the last clip rect was
1407 * empty, meaning that our task was completely offscreen, we need to keep it invisible because
1408 * the actual app transition that updates the visibility is delayed by a few transactions.
1409 * Instead of messing around with the ordering and timing how transitions and transactions are
1410 * executed, we introduce this little hack which prevents this window of getting visible again
1411 * with the wrong bounds until the app transitions has started.
1412 * <p>
1413 * This method notifies the window about that we just moved in the stack so we can apply this
1414 * logic in {@link WindowStateAnimator#updateSurfaceWindowCrop}
1415 */
1416 void notifyMovedInStack() {
1417 mJustMovedInStack = true;
1418 }
1419
1420 /**
1421 * See {@link #notifyMovedInStack}.
1422 *
1423 * @return Whether we just got moved in the corresponding stack.
1424 */
1425 boolean hasJustMovedInStack() {
1426 return mJustMovedInStack;
1427 }
1428
1429 /**
1430 * Resets that we just moved in the corresponding stack. See {@link #notifyMovedInStack}.
1431 */
1432 void resetJustMovedInStack() {
1433 mJustMovedInStack = false;
1434 }
1435
Chong Zhangacf11402015-11-04 16:23:10 -08001436 private final class DeadWindowEventReceiver extends InputEventReceiver {
1437 DeadWindowEventReceiver(InputChannel inputChannel) {
1438 super(inputChannel, mService.mH.getLooper());
1439 }
1440 @Override
1441 public void onInputEvent(InputEvent event) {
1442 finishInputEvent(event, true);
1443 }
1444 }
1445 /**
1446 * Dummy event receiver for windows that died visible.
1447 */
1448 private DeadWindowEventReceiver mDeadWindowEventReceiver;
1449
Chong Zhang112eb8c2015-11-02 11:17:00 -08001450 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001451 if (mInputChannel != null) {
1452 throw new IllegalStateException("Window already has an input channel.");
1453 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001454 String name = makeInputChannelName();
1455 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1456 mInputChannel = inputChannels[0];
1457 mClientChannel = inputChannels[1];
1458 mInputWindowHandle.inputChannel = inputChannels[0];
1459 if (outInputChannel != null) {
1460 mClientChannel.transferTo(outInputChannel);
1461 mClientChannel.dispose();
1462 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08001463 } else {
1464 // If the window died visible, we setup a dummy input channel, so that taps
1465 // can still detected by input monitor channel, and we can relaunch the app.
1466 // Create dummy event receiver that simply reports all events as handled.
1467 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08001468 }
1469 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001470 }
1471
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001472 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08001473 if (mDeadWindowEventReceiver != null) {
1474 mDeadWindowEventReceiver.dispose();
1475 mDeadWindowEventReceiver = null;
1476 }
1477
1478 // unregister server channel first otherwise it complains about broken channel
1479 if (mInputChannel != null) {
1480 mService.mInputManager.unregisterInputChannel(mInputChannel);
1481 mInputChannel.dispose();
1482 mInputChannel = null;
1483 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001484 if (mClientChannel != null) {
1485 mClientChannel.dispose();
1486 mClientChannel = null;
1487 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001488 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001489 }
1490
Chong Zhang112eb8c2015-11-02 11:17:00 -08001491 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08001492 // When the app is terminated (eg. from Recents), the task might have already been
1493 // removed with the window pending removal. Don't apply dim in such cases, as there
1494 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
1495 final AppWindowToken token = mAppToken;
1496 if (token != null && token.removed) {
1497 return;
1498 }
1499
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001500 if (!mAnimatingExit && mAppDied) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001501 // If app died visible, apply a dim over the window to indicate that it's inactive
1502 mDisplayContent.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
1503 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001504 && mDisplayContent != null && !mAnimatingExit && isDisplayedLw()) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001505 mDisplayContent.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001506 }
1507 }
1508
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001509 DimLayer.DimLayerUser getDimLayerUser() {
1510 Task task = getTask();
1511 if (task != null) {
1512 return task;
1513 }
1514 return getStack();
1515 }
1516
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001517 void maybeRemoveReplacedWindow() {
Robert Carra1eb4392015-12-10 12:43:51 -08001518 if (mAppToken == null) {
1519 return;
1520 }
1521 for (int i = mAppToken.allAppWindows.size() - 1; i >= 0; i--) {
1522 final WindowState win = mAppToken.allAppWindows.get(i);
Robert Carra1eb4392015-12-10 12:43:51 -08001523 if (win.mWillReplaceWindow && win.mReplacingWindow == this) {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08001524 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + win);
Robert Carra1eb4392015-12-10 12:43:51 -08001525 win.mWillReplaceWindow = false;
1526 win.mAnimateReplacingWindow = false;
1527 win.mReplacingRemoveRequested = false;
1528 win.mReplacingWindow = null;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001529 if (win.mAnimatingExit) {
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001530 mService.removeWindowInnerLocked(win);
1531 }
1532 }
1533 }
1534 }
1535
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07001536 void setDisplayLayoutNeeded() {
1537 if (mDisplayContent != null) {
1538 mDisplayContent.layoutNeeded = true;
1539 }
1540 }
1541
Filip Gruszczynski955b2fc2015-10-15 14:46:07 -07001542 boolean inDockedWorkspace() {
Chong Zhang2a88fc32016-01-11 17:14:24 -08001543 final Task task = getTask();
Chong Zhangb15758a2015-11-17 12:12:03 -08001544 return task != null && task.inDockedWorkspace();
1545 }
1546
1547 boolean isDockedInEffect() {
Chong Zhang2a88fc32016-01-11 17:14:24 -08001548 final Task task = getTask();
Chong Zhangb15758a2015-11-17 12:12:03 -08001549 return task != null && task.isDockedInEffect();
Filip Gruszczynski955b2fc2015-10-15 14:46:07 -07001550 }
1551
Chong Zhang2a88fc32016-01-11 17:14:24 -08001552 void applyScrollIfNeeded() {
1553 final Task task = getTask();
Chong Zhangf66db432016-01-13 10:39:51 -08001554 if (task != null) {
1555 task.applyScrollToWindowIfNeeded(this);
Chong Zhang2a88fc32016-01-11 17:14:24 -08001556 }
1557 }
1558
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001559 int getTouchableRegion(Region region, int flags) {
1560 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001561 if (modal && mAppToken != null) {
1562 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001563 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001564 // If this is a modal window we need to dismiss it if it's not full screen and the
1565 // touch happens outside of the frame that displays the content. This means we
1566 // need to intercept touches outside of that window. The dim layer user
1567 // associated with the window (task or stack) will give us the good bounds, as
1568 // they would be used to display the dim layer.
1569 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1570 if (dimLayerUser != null) {
1571 dimLayerUser.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001572 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001573 getVisibleBounds(mTmpRect);
1574 }
1575 if (inFreeformWorkspace()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001576 // For freeform windows we the touch region to include the whole surface for the
1577 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001578 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
1579 final int delta = WindowManagerService.dipToPixel(
1580 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
1581 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001582 }
1583 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001584 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001585 } else {
1586 // Not modal or full screen modal
1587 getTouchableRegion(region);
1588 }
1589 return flags;
1590 }
1591
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001592 void checkPolicyVisibilityChange() {
1593 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
1594 if (DEBUG_VISIBILITY) {
1595 Slog.v(TAG, "Policy visibility changing after anim in " +
1596 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
1597 }
1598 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001599 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001600 if (!mPolicyVisibility) {
1601 if (mService.mCurrentFocus == this) {
1602 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
1603 "setAnimationLocked: setting mFocusMayChange true");
1604 mService.mFocusMayChange = true;
1605 }
1606 // Window is no longer visible -- make sure if we were waiting
1607 // for it to be displayed before enabling the display, that
1608 // we allow the display to be enabled now.
1609 mService.enableScreenIfNeededLocked();
1610 }
1611 }
1612 }
1613
1614 void setRequestedSize(int requestedWidth, int requestedHeight) {
1615 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
1616 mLayoutNeeded = true;
1617 mRequestedWidth = requestedWidth;
1618 mRequestedHeight = requestedHeight;
1619 }
1620 }
1621
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001622 void prepareWindowToDisplayDuringRelayout(Configuration outConfig) {
1623 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
1624 == SOFT_INPUT_ADJUST_RESIZE) {
1625 mLayoutNeeded = true;
1626 }
1627 if (isDrawnLw() && mService.okToDisplay()) {
1628 mWinAnimator.applyEnterAnimationLocked();
1629 }
1630 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
1631 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
1632 mTurnOnScreen = true;
1633 }
1634 if (isConfigChanged()) {
Robert Carrc24d8f92016-02-29 16:24:33 -08001635 final Configuration newConfig = updateConfiguration();
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001636 if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + this + " visible with new config: "
Robert Carrc24d8f92016-02-29 16:24:33 -08001637 + newConfig);
1638 outConfig.setTo(newConfig);
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001639 }
1640 }
1641
1642 void adjustStartingWindowFlags() {
1643 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
1644 && mAppToken.startingWindow != null) {
1645 // Special handling of starting window over the base
1646 // window of the app: propagate lock screen flags to it,
1647 // to provide the correct semantics while starting.
1648 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
1649 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
1650 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
1651 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
1652 }
1653 }
1654
1655 void setWindowScale(int requestedWidth, int requestedHeight) {
1656 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
1657
1658 if (scaledWindow) {
1659 // requested{Width|Height} Surface's physical size
1660 // attrs.{width|height} Size on screen
1661 // TODO: We don't check if attrs != null here. Is it implicitly checked?
1662 mHScale = (mAttrs.width != requestedWidth) ?
1663 (mAttrs.width / (float)requestedWidth) : 1.0f;
1664 mVScale = (mAttrs.height != requestedHeight) ?
1665 (mAttrs.height / (float)requestedHeight) : 1.0f;
1666 } else {
1667 mHScale = mVScale = 1;
1668 }
1669 }
1670
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001671 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08001672 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001673 public void binderDied() {
1674 try {
1675 synchronized(mService.mWindowMap) {
1676 WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07001677 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001678 if (win != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001679 if (win.mAppToken != null && !win.mAppToken.clientHidden) {
1680 win.mAppToken.appDied = true;
1681 }
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001682 mService.removeWindowLocked(win);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08001683 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
1684 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08001685 // just in case they have the divider at an unstable position. Better
1686 // also reset drag resizing state, because the owner can't do it
1687 // anymore.
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08001688 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
1689 if (stack != null) {
1690 stack.resetDockedStackToMiddle();
1691 }
Jorim Jaggidcb68142016-02-09 21:51:30 -08001692 mService.setDockedStackResizing(false);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08001693 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001694 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08001695 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001696 mService.removeWindowLocked(WindowState.this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001697 }
1698 }
1699 } catch (IllegalArgumentException ex) {
1700 // This will happen if the window has already been
1701 // removed.
1702 }
1703 }
1704 }
1705
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08001706 /**
1707 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
1708 * because we want to preserve its location on screen to be re-activated later when the user
1709 * interacts with it.
1710 */
1711 boolean shouldKeepVisibleDeadAppWindow() {
1712 if (!isWinVisibleLw() || mAppToken == null || !mAppToken.appDied) {
1713 // Not a visible app window or the app isn't dead.
1714 return false;
1715 }
1716
1717 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1718 // We don't keep starting windows since they were added by the window manager before
1719 // the app even launched.
1720 return false;
1721 }
1722
1723 final TaskStack stack = getStack();
1724 return stack != null && StackId.keepVisibleDeadAppWindowOnScreen(stack.mStackId);
1725 }
1726
Wale Ogunwaled045c822015-12-02 09:14:28 -08001727 /** @return true if this window desires key events. */
1728 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08001729 return isVisibleOrAdding()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001730 && (mViewVisibility == View.VISIBLE)
Wale Ogunwaled045c822015-12-02 09:14:28 -08001731 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Wale Ogunwale6cae7652015-12-26 07:36:26 -08001732 && (mAppToken == null || mAppToken.windowsAreFocusable());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001733 }
1734
Craig Mautner749a7bb2012-04-02 13:49:53 -07001735 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001736 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001737 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001738 }
1739
Craig Mautner749a7bb2012-04-02 13:49:53 -07001740 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001741 public boolean showLw(boolean doAnimation) {
1742 return showLw(doAnimation, true);
1743 }
1744
1745 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07001746 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001747 return false;
1748 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001749 if (!mAppOpVisibility) {
1750 // Being hidden due to app op request.
1751 return false;
1752 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001753 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001754 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001755 return false;
1756 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001757 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001758 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001759 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07001760 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07001761 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001762 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07001763 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001764 // Check for the case where we are currently visible and
1765 // not animating; we do not want to do animation at such a
1766 // point to become visible when we already are.
1767 doAnimation = false;
1768 }
1769 }
1770 mPolicyVisibility = true;
1771 mPolicyVisibilityAfterAnim = true;
1772 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001773 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001774 }
1775 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001776 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001777 }
1778 return true;
1779 }
1780
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001781 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001782 public boolean hideLw(boolean doAnimation) {
1783 return hideLw(doAnimation, true);
1784 }
1785
1786 boolean hideLw(boolean doAnimation, boolean requestAnim) {
1787 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07001788 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001789 doAnimation = false;
1790 }
1791 }
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001792 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
1793 : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001794 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001795 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001796 return false;
1797 }
1798 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001799 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07001800 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001801 doAnimation = false;
1802 }
1803 }
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001804 if (doAnimation) {
1805 mPolicyVisibilityAfterAnim = false;
1806 } else {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001807 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001808 mPolicyVisibilityAfterAnim = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001809 mPolicyVisibility = false;
1810 // Window is no longer visible -- make sure if we were waiting
1811 // for it to be displayed before enabling the display, that
1812 // we allow the display to be enabled now.
1813 mService.enableScreenIfNeededLocked();
1814 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001815 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07001816 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001817 mService.mFocusMayChange = true;
1818 }
1819 }
1820 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001821 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001822 }
1823 return true;
1824 }
1825
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001826 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001827 if (mAppOpVisibility != state) {
1828 mAppOpVisibility = state;
1829 if (state) {
1830 // If the policy visibility had last been to hide, then this
1831 // will incorrectly show at this point since we lost that
1832 // information. Not a big deal -- for the windows that have app
1833 // ops modifies they should only be hidden by policy due to the
1834 // lock screen, and the user won't be changing this if locked.
1835 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001836 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001837 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001838 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001839 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001840 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001841 }
1842
Jeff Brownc2932a12014-11-20 18:04:05 -08001843 public void pokeDrawLockLw(long timeout) {
1844 if (isVisibleOrAdding()) {
1845 if (mDrawLock == null) {
1846 // We want the tag name to be somewhat stable so that it is easier to correlate
1847 // in wake lock statistics. So in particular, we don't want to include the
1848 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001849 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08001850 mDrawLock = mService.mPowerManager.newWakeLock(
1851 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
1852 mDrawLock.setReferenceCounted(false);
1853 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
1854 }
1855 // Each call to acquire resets the timeout.
1856 if (DEBUG_POWER) {
1857 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
1858 + mAttrs.packageName);
1859 }
1860 mDrawLock.acquire(timeout);
1861 } else if (DEBUG_POWER) {
1862 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
1863 + "owned by " + mAttrs.packageName);
1864 }
1865 }
1866
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001867 @Override
1868 public boolean isAlive() {
1869 return mClient.asBinder().isBinderAlive();
1870 }
1871
Craig Mautnera987d432012-10-11 14:07:58 -07001872 boolean isClosing() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001873 return mAnimatingExit || (mService.mClosingApps.contains(mAppToken));
Craig Mautnera987d432012-10-11 14:07:58 -07001874 }
1875
Chong Zhangbef461f2015-10-27 11:38:24 -07001876 boolean isAnimatingWithSavedSurface() {
1877 return mAppToken != null && mAppToken.mAnimatingWithSavedSurface;
1878 }
1879
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001880 private boolean shouldSaveSurface() {
Wale Ogunwale945d1972016-03-23 13:16:41 -07001881 if ((mAttrs.flags & FLAG_SECURE) != 0) {
1882 // We don't save secure surfaces since their content shouldn't be shown while the app
1883 // isn't on screen and content might leak through during the transition animation with
1884 // saved surface.
1885 return false;
1886 }
1887
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001888 if (ActivityManager.isLowRamDeviceStatic()) {
1889 // Don't save surfaces on Svelte devices.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001890 return false;
1891 }
1892
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001893 Task task = getTask();
1894 if (task == null || task.inHomeStack()) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001895 // Don't save surfaces for home stack apps. These usually resume and draw
1896 // first frame very fast. Saving surfaces are mostly a waste of memory.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001897 return false;
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001898 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001899
1900 final AppWindowToken taskTop = task.getTopVisibleAppToken();
1901 if (taskTop != null && taskTop != mAppToken) {
1902 // Don't save if the window is not the topmost window.
1903 return false;
1904 }
1905
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001906 if (mResizedWhileGone) {
1907 // Somebody resized our window while we were gone for layout, which means that the
1908 // client got an old size, so we have an outdated surface here.
1909 return false;
1910 }
1911
Robert Carr7098dbd2016-02-01 12:31:01 -08001912 if (DEBUG_DISABLE_SAVING_SURFACES) {
1913 return false;
1914 }
1915
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001916 return mAppToken.shouldSaveSurface();
1917 }
1918
1919 void destroyOrSaveSurface() {
1920 mSurfaceSaved = shouldSaveSurface();
1921 if (mSurfaceSaved) {
1922 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1923 Slog.v(TAG, "Saving surface: " + this);
1924 }
1925
1926 mWinAnimator.hide("saved surface");
1927 mWinAnimator.mDrawState = WindowStateAnimator.NO_SURFACE;
1928 setHasSurface(false);
Chong Zhang47e36a32016-02-29 16:44:33 -08001929 // The client should have disconnected at this point, but if it doesn't,
1930 // we need to make sure it's disconnected. Otherwise when we reuse the surface
1931 // the client can't reconnect to the buffer queue, and rendering will fail.
1932 if (mWinAnimator.mSurfaceController != null) {
1933 mWinAnimator.mSurfaceController.disconnectInTransaction();
1934 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001935 } else {
Robert Carr13f7be9e2015-12-02 18:39:45 -08001936 mWinAnimator.destroySurfaceLocked();
1937 }
Robert Carr13f7be9e2015-12-02 18:39:45 -08001938 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001939
Robert Carr13f7be9e2015-12-02 18:39:45 -08001940 public void destroySavedSurface() {
Robert Carr13f7be9e2015-12-02 18:39:45 -08001941 if (mSurfaceSaved) {
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001942 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1943 Slog.v(TAG, "Destroying saved surface: " + this);
1944 }
Robert Carr13f7be9e2015-12-02 18:39:45 -08001945 mWinAnimator.destroySurfaceLocked();
1946 }
1947 }
1948
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001949 public void restoreSavedSurface() {
Chong Zhang4113ffa2016-02-18 12:39:13 -08001950 if (!mSurfaceSaved) {
1951 return;
1952 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001953 mSurfaceSaved = false;
1954 setHasSurface(true);
1955 mWinAnimator.mDrawState = WindowStateAnimator.READY_TO_SHOW;
1956 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1957 Slog.v(TAG, "Restoring saved surface: " + this);
1958 }
1959 }
1960
Robert Carr13f7be9e2015-12-02 18:39:45 -08001961 public boolean hasSavedSurface() {
1962 return mSurfaceSaved;
1963 }
1964
Craig Mautner69b08182012-09-05 13:07:13 -07001965 @Override
1966 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001967 final DisplayContent displayContent = getDisplayContent();
1968 if (displayContent == null) {
1969 // Only a window that was on a non-default display can be detached from it.
1970 return false;
1971 }
Winson Chung47a3e652014-05-21 16:03:42 -07001972 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07001973 }
1974
Adrian Rooscd3884d2015-02-18 17:25:23 +01001975 @Override
1976 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001977 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1978 return dimLayerUser != null && mDisplayContent != null &&
Chong Zhang112eb8c2015-11-02 11:17:00 -08001979 mDisplayContent.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01001980 }
1981
Craig Mautner88400d32012-09-30 12:35:45 -07001982 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
1983 mShowToOwnerOnly = showToOwnerOnly;
1984 }
1985
Craig Mautner5962b122012-10-05 14:45:52 -07001986 boolean isHiddenFromUserLocked() {
Craig Mautner341220f2012-10-16 15:20:09 -07001987 // Attached windows are evaluated based on the window that they are attached to.
1988 WindowState win = this;
Robert Carr51a1b872015-12-08 14:03:13 -08001989 while (win.isChildWindow()) {
Craig Mautner341220f2012-10-16 15:20:09 -07001990 win = win.mAttachedWindow;
1991 }
1992 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -07001993 && win.mAppToken != null && win.mAppToken.showForAllUsers) {
Craig Mautner341220f2012-10-16 15:20:09 -07001994 // Save some cycles by not calling getDisplayInfo unless it is an application
1995 // window intended for all users.
Craig Mautnerdf88d732014-01-27 09:21:32 -08001996 final DisplayContent displayContent = win.getDisplayContent();
1997 if (displayContent == null) {
1998 return true;
1999 }
2000 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Craig Mautner341220f2012-10-16 15:20:09 -07002001 if (win.mFrame.left <= 0 && win.mFrame.top <= 0
2002 && win.mFrame.right >= displayInfo.appWidth
2003 && win.mFrame.bottom >= displayInfo.appHeight) {
Craig Mautner5962b122012-10-05 14:45:52 -07002004 // Is a fullscreen window, like the clock alarm. Show to everyone.
2005 return false;
2006 }
2007 }
2008
Craig Mautner341220f2012-10-16 15:20:09 -07002009 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01002010 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002011 }
2012
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002013 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2014 outRegion.set(
2015 frame.left + inset.left, frame.top + inset.top,
2016 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002017 }
2018
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002019 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002020 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002021 switch (mTouchableInsets) {
2022 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002023 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002024 outRegion.set(frame);
2025 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002026 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002027 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002028 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002029 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002030 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002031 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002032 case TOUCHABLE_INSETS_REGION: {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002033 final Region givenTouchableRegion = mGivenTouchableRegion;
2034 outRegion.set(givenTouchableRegion);
2035 outRegion.translate(frame.left, frame.top);
2036 break;
2037 }
2038 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002039 cropRegionToStackBoundsIfNeeded(outRegion);
2040 }
2041
2042 void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002043 final Task task = getTask();
2044 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002045 return;
2046 }
2047
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002048 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002049 if (stack == null) {
2050 return;
2051 }
2052
2053 stack.getDimBounds(mTmpRect);
2054 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002055 }
2056
Craig Mautner59c00972012-07-30 12:10:24 -07002057 WindowList getWindowList() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002058 final DisplayContent displayContent = getDisplayContent();
2059 return displayContent == null ? null : displayContent.getWindowList();
Craig Mautner59c00972012-07-30 12:10:24 -07002060 }
2061
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002062 /**
2063 * Report a focus change. Must be called with no locks held, and consistently
2064 * from the same serialized thread (such as dispatched from a handler).
2065 */
2066 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
2067 try {
2068 mClient.windowFocusChanged(focused, inTouchMode);
2069 } catch (RemoteException e) {
2070 }
2071 if (mFocusCallbacks != null) {
2072 final int N = mFocusCallbacks.beginBroadcast();
2073 for (int i=0; i<N; i++) {
2074 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2075 try {
2076 if (focused) {
2077 obs.focusGained(mWindowId.asBinder());
2078 } else {
2079 obs.focusLost(mWindowId.asBinder());
2080 }
2081 } catch (RemoteException e) {
2082 }
2083 }
2084 mFocusCallbacks.finishBroadcast();
2085 }
2086 }
2087
Robert Carrc24d8f92016-02-29 16:24:33 -08002088 /**
2089 * Update our current configurations, based on task configuration.
2090 *
2091 * @return A configuration suitable for sending to the client.
2092 */
2093 private Configuration updateConfiguration() {
2094 final Task task = getTask();
2095 final Configuration overrideConfig =
2096 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
2097 final boolean configChanged = isConfigChanged();
2098 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) && configChanged) {
2099 Slog.i(TAG, "Sending new config to window " + this + ": " +
2100 " / config=" + mService.mCurConfiguration + " overrideConfig=" + overrideConfig);
2101 }
2102 setConfiguration(mService.mCurConfiguration, overrideConfig);
2103 return mMergedConfiguration;
2104 }
2105
Craig Mautnerdf88d732014-01-27 09:21:32 -08002106 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002107 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08002108 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002109 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
2110 + ": " + mCompatFrame);
Robert Carrc24d8f92016-02-29 16:24:33 -08002111 final Configuration newConfig = isConfigChanged() ? updateConfiguration() : null;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002112 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING)
2113 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
2114
Craig Mautnerdf88d732014-01-27 09:21:32 -08002115 final Rect frame = mFrame;
2116 final Rect overscanInsets = mLastOverscanInsets;
2117 final Rect contentInsets = mLastContentInsets;
2118 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07002119 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002120 final Rect outsets = mLastOutsets;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002121 final boolean reportDraw = mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING;
Chet Haase8eb48d22014-09-24 07:31:29 -07002122 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
2123 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002124 // To prevent deadlock simulate one-way call if win.mClient is a local object.
2125 mService.mH.post(new Runnable() {
2126 @Override
2127 public void run() {
2128 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002129 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
2130 stableInsets, outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002131 } catch (RemoteException e) {
2132 // Not a remote call, RemoteException won't be raised.
2133 }
2134 }
2135 });
2136 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002137 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002138 outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002139 }
Svetoslav4604abc2014-06-10 18:59:30 -07002140
2141 //TODO (multidisplay): Accessibility supported only for the default display.
2142 if (mService.mAccessibilityController != null
2143 && getDisplayId() == Display.DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07002144 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07002145 }
2146
Craig Mautnerdf88d732014-01-27 09:21:32 -08002147 mOverscanInsetsChanged = false;
2148 mContentInsetsChanged = false;
2149 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07002150 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002151 mOutsetsChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08002152 mWinAnimator.mSurfaceResized = false;
2153 } catch (RemoteException e) {
2154 mOrientationChanging = false;
2155 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2156 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08002157 // We are assuming the hosting process is dead or in a zombie state.
2158 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
2159 + ", removing this window.");
2160 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002161 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002162 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002163 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002164 }
2165
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002166 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08002167 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
2168 // start even if we haven't received the relayout window, so that the client requests
2169 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
2170 // until the window to small size, otherwise the multithread renderer will shift last
2171 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
2172 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002173 boolean resizing = isDragResizing() || isDragResizeChanged();
2174 if (StackId.useWindowFrameForBackdrop(getStackId()) || !resizing) {
2175 return frame;
2176 }
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002177 DisplayInfo displayInfo = getDisplayInfo();
2178 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002179 return mTmpRect;
2180 }
2181
Jorim Jaggi86905582016-02-09 21:36:09 -08002182 @Override
2183 public int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002184 final TaskStack stack = getStack();
2185 if (stack == null) {
2186 return INVALID_STACK_ID;
2187 }
2188 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002189 }
2190
2191 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
2192 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
2193 Configuration newConfig) throws RemoteException {
Jorim Jaggidc249c42015-12-15 14:57:31 -08002194 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Jorim Jaggia4a58ef2016-01-27 02:10:08 -08002195 reportDraw, newConfig, getBackdropFrame(frame),
Jorim Jaggi0ffd49c2016-02-12 15:04:21 -08002196 isDragResizeChanged() /* forceRelayout */, mPolicy.isNavBarForcedShownLw(this));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002197 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002198 }
2199
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002200 public void registerFocusObserver(IWindowFocusObserver observer) {
2201 synchronized(mService.mWindowMap) {
2202 if (mFocusCallbacks == null) {
2203 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
2204 }
2205 mFocusCallbacks.register(observer);
2206 }
2207 }
2208
2209 public void unregisterFocusObserver(IWindowFocusObserver observer) {
2210 synchronized(mService.mWindowMap) {
2211 if (mFocusCallbacks != null) {
2212 mFocusCallbacks.unregister(observer);
2213 }
2214 }
2215 }
2216
2217 public boolean isFocused() {
2218 synchronized(mService.mWindowMap) {
2219 return mService.mCurrentFocus == this;
2220 }
2221 }
2222
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07002223 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07002224 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07002225 return task != null && task.inFreeformWorkspace();
2226 }
2227
Wale Ogunwale9185fb02016-03-11 18:06:14 -08002228 @Override
2229 public boolean inMultiWindowMode() {
2230 final Task task = getTask();
2231 return task != null && !task.isFullscreen();
2232 }
2233
Chong Zhang3005e752015-09-18 18:46:28 -07002234 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002235 return mDragResizing != computeDragResizing();
2236 }
2237
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002238 /**
2239 * @return Whether we reported a drag resize change to the application or not already.
2240 */
2241 boolean isDragResizingChangeReported() {
2242 return mDragResizingChangeReported;
2243 }
2244
2245 /**
2246 * Resets the state whether we reported a drag resize change to the app.
2247 */
2248 void resetDragResizingChangeReported() {
2249 mDragResizingChangeReported = false;
2250 }
2251
Jorim Jaggidcf467c2015-11-05 13:59:32 +01002252 int getResizeMode() {
2253 return mResizeMode;
2254 }
2255
Jorim Jaggi192086e2016-03-11 17:17:03 +01002256 boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07002257 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002258 if (task == null) {
2259 return false;
2260 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08002261 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
2262
2263 // Floating windows never enter drag resize mode.
2264 return false;
2265 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002266 if (task.isDragResizing()) {
2267 return true;
2268 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01002269
2270 // If the bounds are currently frozen, it means that the layout size that the app sees
2271 // and the bounds we clip this window to might be different. In order to avoid holes, we
2272 // simulate that we are still resizing so the app fills the hole with the resizing
2273 // background.
2274 return (mDisplayContent.mDividerControllerLocked.isResizing()
2275 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Jorim Jaggi899327f2016-02-25 20:44:18 -05002276 !task.inFreeformWorkspace() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08002277
Chong Zhang3005e752015-09-18 18:46:28 -07002278 }
2279
2280 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002281 final boolean resizing = computeDragResizing();
2282 if (resizing == mDragResizing) {
2283 return;
2284 }
2285 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01002286 final Task task = getTask();
2287 if (task != null && task.isDragResizing()) {
2288 mResizeMode = task.getDragResizeMode();
2289 } else {
2290 mResizeMode = mDragResizing && mDisplayContent.mDividerControllerLocked.isResizing()
2291 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
2292 : DRAG_RESIZE_MODE_FREEFORM;
2293 }
Chong Zhang3005e752015-09-18 18:46:28 -07002294 }
2295
2296 boolean isDragResizing() {
2297 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07002298 }
2299
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002300 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08002301 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002302 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08002303 if (stack != null) {
2304 pw.print(" stackId="); pw.print(stack.mStackId);
2305 }
Craig Mautner59c00972012-07-30 12:10:24 -07002306 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002307 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07002308 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08002309 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
2310 pw.print(" package="); pw.print(mAttrs.packageName);
2311 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002312 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002313 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
2314 pw.print(" h="); pw.print(mRequestedHeight);
2315 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07002316 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
2317 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
2318 pw.print(" h="); pw.println(mLastRequestedHeight);
2319 }
Robert Carr51a1b872015-12-08 14:03:13 -08002320 if (isChildWindow() || mLayoutAttached) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002321 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
2322 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
2323 }
2324 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
2325 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
2326 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
2327 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
2328 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
2329 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002330 if (dumpAll) {
2331 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
2332 pw.print(" mSubLayer="); pw.print(mSubLayer);
2333 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautner59431632012-04-04 11:56:44 -07002334 pw.print((mTargetAppToken != null ?
2335 mTargetAppToken.mAppAnimator.animLayerAdjustment
2336 : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002337 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
2338 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08002339 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002340 if (dumpAll) {
2341 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
2342 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
2343 if (mAppToken != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08002344 pw.print(prefix); pw.print("mAppToken="); pw.print(mAppToken);
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08002345 pw.print(" isAnimatingWithSavedSurface()=");
2346 pw.print(isAnimatingWithSavedSurface());
Chong Zhang112eb8c2015-11-02 11:17:00 -08002347 pw.print(" mAppDied=");pw.println(mAppDied);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002348 }
2349 if (mTargetAppToken != null) {
2350 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
2351 }
2352 pw.print(prefix); pw.print("mViewVisibility=0x");
2353 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002354 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
2355 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07002356 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
2357 pw.print(" mSystemUiVisibility=0x");
2358 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002359 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002360 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
2361 || mAttachedHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002362 pw.print(prefix); pw.print("mPolicyVisibility=");
2363 pw.print(mPolicyVisibility);
2364 pw.print(" mPolicyVisibilityAfterAnim=");
2365 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002366 pw.print(" mAppOpVisibility=");
2367 pw.print(mAppOpVisibility);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002368 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
2369 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08002370 if (!mRelayoutCalled || mLayoutNeeded) {
2371 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
2372 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002373 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002374 if (mXOffset != 0 || mYOffset != 0) {
2375 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
2376 pw.print(" y="); pw.println(mYOffset);
2377 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002378 if (dumpAll) {
2379 pw.print(prefix); pw.print("mGivenContentInsets=");
2380 mGivenContentInsets.printShortString(pw);
2381 pw.print(" mGivenVisibleInsets=");
2382 mGivenVisibleInsets.printShortString(pw);
2383 pw.println();
2384 if (mTouchableInsets != 0 || mGivenInsetsPending) {
2385 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
2386 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07002387 Region region = new Region();
2388 getTouchableRegion(region);
2389 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002390 }
2391 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Wale Ogunwale7c726682015-02-06 17:34:28 -08002392 if (mOverrideConfig != Configuration.EMPTY) {
2393 pw.print(prefix); pw.print("mOverrideConfig="); pw.println(mOverrideConfig);
2394 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002395 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07002396 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07002397 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Chong Zhanga8975bd2016-01-28 17:13:47 -08002398 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08002399 pw.print(" hasSavedSurface()="); pw.print(hasSavedSurface());
2400 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002401 if (dumpAll) {
2402 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
2403 pw.print(" last="); mLastFrame.printShortString(pw);
2404 pw.println();
2405 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002406 if (mEnforceSizeCompat) {
2407 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002408 pw.println();
2409 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002410 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002411 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002412 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002413 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002414 pw.println();
2415 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
2416 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002417 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002418 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002419 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002420 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04002421 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
2422 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002423 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
2424 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002425 pw.print(prefix); pw.print("Cur insets: overscan=");
2426 mOverscanInsets.printShortString(pw);
2427 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002428 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002429 pw.print(" stable="); mStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002430 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002431 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002432 pw.print(prefix); pw.print("Lst insets: overscan=");
2433 mLastOverscanInsets.printShortString(pw);
2434 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002435 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002436 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002437 pw.print(" physical="); mLastOutsets.printShortString(pw);
2438 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002439 pw.println();
2440 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07002441 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
2442 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002443 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
2444 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002445 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
2446 pw.print(" mDestroying="); pw.print(mDestroying);
2447 pw.print(" mRemoved="); pw.println(mRemoved);
2448 }
2449 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
2450 pw.print(prefix); pw.print("mOrientationChanging=");
2451 pw.print(mOrientationChanging);
2452 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
2453 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
2454 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07002455 if (mLastFreezeDuration != 0) {
2456 pw.print(prefix); pw.print("mLastFreezeDuration=");
2457 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
2458 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002459 if (mHScale != 1 || mVScale != 1) {
2460 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
2461 pw.print(" mVScale="); pw.println(mVScale);
2462 }
2463 if (mWallpaperX != -1 || mWallpaperY != -1) {
2464 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
2465 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
2466 }
2467 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
2468 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
2469 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
2470 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07002471 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
2472 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
2473 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
2474 pw.print(mWallpaperDisplayOffsetX);
2475 pw.print(" mWallpaperDisplayOffsetY=");
2476 pw.println(mWallpaperDisplayOffsetY);
2477 }
Jeff Brownc2932a12014-11-20 18:04:05 -08002478 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07002479 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08002480 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08002481 if (isDragResizing()) {
2482 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
2483 }
2484 if (computeDragResizing()) {
2485 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
2486 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002487 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002488
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002489 String makeInputChannelName() {
2490 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002491 + " " + getWindowTag();
2492 }
2493
Robert Carra1eb4392015-12-10 12:43:51 -08002494 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002495 CharSequence tag = mAttrs.getTitle();
2496 if (tag == null || tag.length() <= 0) {
2497 tag = mAttrs.packageName;
2498 }
2499 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002500 }
2501
2502 @Override
2503 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002504 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002505 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08002506 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002507 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002508 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -07002509 + " u" + UserHandle.getUserId(mSession.mUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002510 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002511 }
2512 return mStringNameCache;
2513 }
Robert Carr58f29132015-10-29 14:19:05 -07002514
2515 void transformFromScreenToSurfaceSpace(Rect rect) {
2516 if (mHScale >= 0) {
Chong Zhang84389572016-01-13 10:33:27 -08002517 rect.left = (int) (rect.left / mHScale);
2518 rect.right = (int) (rect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07002519 }
2520 if (mVScale >= 0) {
Chong Zhang84389572016-01-13 10:33:27 -08002521 rect.top = (int) (rect.top / mVScale);
2522 rect.bottom = (int) (rect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07002523 }
2524 }
Robert Carr31e28482015-12-02 16:53:18 -08002525
2526 void applyGravityAndUpdateFrame() {
2527 final int pw = mContainingFrame.width();
2528 final int ph = mContainingFrame.height();
2529 final Task task = getTask();
Wale Ogunwale9185fb02016-03-11 18:06:14 -08002530 final boolean nonFullscreenTask = inMultiWindowMode();
Robert Carr3d938972016-03-23 23:00:59 -07002531 final boolean fitToDisplay = task != null && !task.isFloating() && !layoutInParentFrame();
Robert Carr31e28482015-12-02 16:53:18 -08002532 float x, y;
2533 int w,h;
2534
2535 if ((mAttrs.flags & FLAG_SCALED) != 0) {
2536 if (mAttrs.width < 0) {
2537 w = pw;
2538 } else if (mEnforceSizeCompat) {
2539 w = (int)(mAttrs.width * mGlobalScale + .5f);
2540 } else {
2541 w = mAttrs.width;
2542 }
2543 if (mAttrs.height < 0) {
2544 h = ph;
2545 } else if (mEnforceSizeCompat) {
2546 h = (int)(mAttrs.height * mGlobalScale + .5f);
2547 } else {
2548 h = mAttrs.height;
2549 }
2550 } else {
2551 if (mAttrs.width == MATCH_PARENT) {
2552 w = pw;
2553 } else if (mEnforceSizeCompat) {
2554 w = (int)(mRequestedWidth * mGlobalScale + .5f);
2555 } else {
2556 w = mRequestedWidth;
2557 }
2558 if (mAttrs.height == MATCH_PARENT) {
2559 h = ph;
2560 } else if (mEnforceSizeCompat) {
2561 h = (int)(mRequestedHeight * mGlobalScale + .5f);
2562 } else {
2563 h = mRequestedHeight;
2564 }
2565 }
2566
2567 if (mEnforceSizeCompat) {
2568 x = mAttrs.x * mGlobalScale;
2569 y = mAttrs.y * mGlobalScale;
2570 } else {
2571 x = mAttrs.x;
2572 y = mAttrs.y;
2573 }
2574
Robert Carr1d2bacb2016-03-30 14:29:35 -07002575 if (nonFullscreenTask && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08002576 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08002577 // required by {@link Gravity#apply} call.
2578 w = Math.min(w, pw);
2579 h = Math.min(h, ph);
2580 }
2581
2582 // Set mFrame
2583 Gravity.apply(mAttrs.gravity, w, h, mContainingFrame,
2584 (int) (x + mAttrs.horizontalMargin * pw),
2585 (int) (y + mAttrs.verticalMargin * ph), mFrame);
2586
2587 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08002588 if (fitToDisplay) {
2589 Gravity.applyDisplay(mAttrs.gravity, mDisplayFrame, mFrame);
2590 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08002591
2592 // We need to make sure we update the CompatFrame as it is used for
2593 // cropping decisions, etc, on systems where we lack a decor layer.
2594 mCompatFrame.set(mFrame);
2595 if (mEnforceSizeCompat) {
2596 // See comparable block in computeFrameLw.
2597 mCompatFrame.scale(mInvGlobalScale);
2598 }
Robert Carr31e28482015-12-02 16:53:18 -08002599 }
Robert Carr51a1b872015-12-08 14:03:13 -08002600
2601 boolean isChildWindow() {
2602 return mAttachedWindow != null;
2603 }
Robert Carra1eb4392015-12-10 12:43:51 -08002604
Robert Carrf3b72c72016-03-21 18:16:39 -07002605 boolean layoutInParentFrame() {
2606 return isChildWindow() && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
2607 }
2608
Robert Carra1eb4392015-12-10 12:43:51 -08002609 void setReplacing(boolean animate) {
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08002610 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
2611 || mAttrs.type == TYPE_APPLICATION_STARTING) {
2612 // We don't set replacing on starting windows since they are added by window manager and
2613 // not the client so won't be replaced by the client.
2614 return;
Robert Carra1eb4392015-12-10 12:43:51 -08002615 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08002616
2617 mWillReplaceWindow = true;
2618 mReplacingWindow = null;
2619 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08002620 }
Chong Zhangf596cd52016-01-05 13:42:44 -08002621
2622 void resetReplacing() {
2623 mWillReplaceWindow = false;
2624 mReplacingWindow = null;
2625 mAnimateReplacingWindow = false;
2626 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08002627
2628 float translateToWindowX(float x) {
2629 float winX = x - mFrame.left;
2630 if (mEnforceSizeCompat) {
2631 winX *= mGlobalScale;
2632 }
2633 return winX;
2634 }
2635
2636 float translateToWindowY(float y) {
2637 float winY = y - mFrame.top;
2638 if (mEnforceSizeCompat) {
2639 winY *= mGlobalScale;
2640 }
2641 return winY;
2642 }
satokcef37fb2011-10-24 21:49:38 +09002643}