blob: 19184fed4d4da7cbf804e496b3dcfff718097bdd [file] [log] [blame]
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Wale Ogunwale053c8e42015-11-16 14:27:21 -080019import android.app.ActivityManager;
20import android.app.AppOpsManager;
21import android.content.Context;
22import android.content.res.Configuration;
23import android.graphics.Matrix;
24import android.graphics.PixelFormat;
25import android.graphics.Point;
26import android.graphics.Rect;
27import android.graphics.Region;
28import android.os.IBinder;
29import android.os.PowerManager;
30import android.os.RemoteCallbackList;
31import android.os.RemoteException;
32import android.os.SystemClock;
33import android.os.Trace;
34import android.os.UserHandle;
35import android.os.WorkSource;
36import android.util.DisplayMetrics;
37import android.util.Slog;
38import android.util.TimeUtils;
39import android.view.Display;
40import android.view.DisplayInfo;
41import android.view.Gravity;
42import android.view.IApplicationToken;
43import android.view.IWindow;
44import android.view.IWindowFocusObserver;
45import android.view.IWindowId;
46import android.view.InputChannel;
47import android.view.InputEvent;
48import android.view.InputEventReceiver;
49import android.view.View;
50import android.view.ViewTreeObserver;
51import android.view.WindowManager;
52import android.view.WindowManagerPolicy;
53
Jorim Jaggi9511b0f2016-01-29 19:12:44 -080054import com.android.server.input.InputWindowHandle;
55
Wale Ogunwale053c8e42015-11-16 14:27:21 -080056import java.io.PrintWriter;
57import java.util.ArrayList;
58
Wale Ogunwaled045c822015-12-02 09:14:28 -080059import static android.app.ActivityManager.StackId;
Wale Ogunwalea9f9b372016-02-04 18:04:39 -080060import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
Filip Gruszczynski84fa3352016-01-25 16:28:49 -080061import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
Wale Ogunwalecad05a02015-09-25 10:41:44 -070062import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080063import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
64import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
65import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
66import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080067import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080068import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070069import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080070import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Jorim Jaggi5f23a572016-04-22 15:05:50 -070071import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080072import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
73import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080074import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Wale Ogunwale945d1972016-03-23 13:16:41 -070075import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070076import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080077import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080078import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
Robert Carr31e28482015-12-02 16:53:18 -080079import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080080import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080081import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -080082import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
Robert Carra1eb4392015-12-10 12:43:51 -080083import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080084import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
85import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
Robert Carrd1a010f2016-04-07 22:36:22 -070086import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080087import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080088import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070089import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080090import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
91import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
92import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +010093import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
94import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080095import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
96import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
97import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
98import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
99import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
100import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
101import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
102import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
103import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
104import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
105import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
106import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800107
Craig Mautner59c00972012-07-30 12:10:24 -0700108class WindowList extends ArrayList<WindowState> {
Wale Ogunwale33fde7d2016-03-05 22:38:51 -0800109 WindowList() {}
110 WindowList(WindowList windowList) {
111 super(windowList);
112 }
Craig Mautner59c00972012-07-30 12:10:24 -0700113}
114
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800115/**
116 * A window in the window manager.
117 */
Craig Mautnere32c3072012-03-12 15:25:35 -0700118final class WindowState implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800119 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800120
Skuhne81c524a2015-08-12 13:34:14 -0700121 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700122 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
123 // use hard-coded min sizes for now.
124 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
125 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700126
127 // The thickness of a window resize handle outside the window bounds on the free form workspace
128 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700129 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700130
Robert Carr7098dbd2016-02-01 12:31:01 -0800131 static final boolean DEBUG_DISABLE_SAVING_SURFACES = false;
132
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800133 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700134 final WindowManagerPolicy mPolicy;
135 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800136 final Session mSession;
137 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800138 final int mAppOp;
139 // UserId and appId of the owner. Don't display windows of non-current user.
140 final int mOwnerUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800141 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800142 WindowToken mToken;
143 WindowToken mRootToken;
144 AppWindowToken mAppToken;
145 AppWindowToken mTargetAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700146
147 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
148 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800149 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
150 final DeathRecipient mDeathRecipient;
151 final WindowState mAttachedWindow;
Craig Mautner7b1aa772012-11-30 16:14:45 -0800152 final WindowList mChildWindows = new WindowList();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800153 final int mBaseLayer;
154 final int mSubLayer;
155 final boolean mLayoutAttached;
156 final boolean mIsImWindow;
157 final boolean mIsWallpaper;
158 final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700159 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700160 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800161 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700162 int mSystemUiVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800163 boolean mPolicyVisibility = true;
164 boolean mPolicyVisibilityAfterAnim = true;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -0800165 boolean mAppOpVisibility = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800166 boolean mAppFreezing;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800167 boolean mAttachedHidden; // is our parent window hidden?
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800168 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Chong Zhang0275e392015-09-17 10:41:44 -0700169 boolean mDragResizing;
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800170 boolean mDragResizingChangeReported;
Jorim Jaggidcf467c2015-11-05 13:59:32 +0100171 int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700172
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800173 RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
174
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700175 /**
176 * The window size that was requested by the application. These are in
177 * the application's coordinate space (without compatibility scale applied).
178 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800179 int mRequestedWidth;
180 int mRequestedHeight;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700181 int mLastRequestedWidth;
182 int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700183
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800184 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800185 boolean mHaveFrame;
186 boolean mObscured;
187 boolean mTurnOnScreen;
188
189 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700190
Wale Ogunwale60454db2015-01-23 16:05:07 -0800191 private Configuration mConfiguration = Configuration.EMPTY;
192 private Configuration mOverrideConfig = Configuration.EMPTY;
Robert Carrc24d8f92016-02-29 16:24:33 -0800193 // Represents the changes from our override configuration applied
194 // to the global configuration. This is the only form of configuration
195 // which is suitable for delivery to the client.
196 private Configuration mMergedConfiguration = new Configuration();
Craig Mautnere8552142012-11-07 13:55:47 -0800197 // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned.
198 // Used only on {@link #TYPE_KEYGUARD}.
199 private boolean mConfigHasChanged;
Craig Mautnera2c77052012-03-26 12:14:43 -0700200
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700201 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700202 * Actual position of the surface shown on-screen (may be modified by animation). These are
203 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700204 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700205 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800206
207 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700208 * Insets that determine the actually visible area. These are in the application's
209 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800210 */
211 final Rect mVisibleInsets = new Rect();
212 final Rect mLastVisibleInsets = new Rect();
213 boolean mVisibleInsetsChanged;
214
215 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700216 * Insets that are covered by system windows (such as the status bar) and
217 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700218 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800219 */
220 final Rect mContentInsets = new Rect();
221 final Rect mLastContentInsets = new Rect();
222 boolean mContentInsetsChanged;
223
224 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800225 * Insets that determine the area covered by the display overscan region. These are in the
226 * application's coordinate space (without compatibility scale applied).
227 */
228 final Rect mOverscanInsets = new Rect();
229 final Rect mLastOverscanInsets = new Rect();
230 boolean mOverscanInsetsChanged;
231
232 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700233 * Insets that determine the area covered by the stable system windows. These are in the
234 * application's coordinate space (without compatibility scale applied).
235 */
236 final Rect mStableInsets = new Rect();
237 final Rect mLastStableInsets = new Rect();
238 boolean mStableInsetsChanged;
239
240 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700241 * Outsets determine the area outside of the surface where we want to pretend that it's possible
242 * to draw anyway.
243 */
244 final Rect mOutsets = new Rect();
245 final Rect mLastOutsets = new Rect();
246 boolean mOutsetsChanged = false;
247
248 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800249 * Set to true if we are waiting for this window to receive its
250 * given internal insets before laying out other windows based on it.
251 */
252 boolean mGivenInsetsPending;
253
254 /**
255 * These are the content insets that were given during layout for
256 * this window, to be applied to windows behind it.
257 */
258 final Rect mGivenContentInsets = new Rect();
259
260 /**
261 * These are the visible insets that were given during layout for
262 * this window, to be applied to windows behind it.
263 */
264 final Rect mGivenVisibleInsets = new Rect();
265
266 /**
267 * This is the given touchable area relative to the window frame, or null if none.
268 */
269 final Region mGivenTouchableRegion = new Region();
270
271 /**
272 * Flag indicating whether the touchable region should be adjusted by
273 * the visible insets; if false the area outside the visible insets is
274 * NOT touchable, so we must use those to adjust the frame during hit
275 * tests.
276 */
277 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
278
279 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400280 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700281 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800282 float mHScale=1, mVScale=1;
283 float mLastHScale=1, mLastVScale=1;
284 final Matrix mTmpMatrix = new Matrix();
285
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700286 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800287 final Rect mFrame = new Rect();
288 final Rect mLastFrame = new Rect();
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700289 // Frame that is scaled to the application's coordinate space when in
290 // screen size compatibility mode.
291 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800292
293 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700294
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800295 final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700296
Wale Ogunwale94596652015-02-06 19:27:34 -0800297 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
298 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700299 final Rect mDisplayFrame = new Rect();
300
301 // The region of the display frame that the display type supports displaying content on. This
302 // is mostly a special case for TV where some displays don’t have the entire display usable.
303 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
304 // window display contents to extend into the overscan region.
305 final Rect mOverscanFrame = new Rect();
306
307 // The display frame minus the stable insets. This value is always constant regardless of if
308 // the status bar or navigation bar is visible.
Adrian Roosfa104232014-06-20 16:10:14 -0700309 final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800310
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700311 // The area not occupied by the status and navigation bars. So, if both status and navigation
312 // bars are visible, the decor frame is equal to the stable frame.
313 final Rect mDecorFrame = new Rect();
314
315 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
316 // minus the area occupied by the IME if the IME is present.
317 final Rect mContentFrame = new Rect();
318
319 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
320 // displays hint text.
321 final Rect mVisibleFrame = new Rect();
322
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700323 // Frame that includes dead area outside of the surface but where we want to pretend that it's
324 // possible to draw.
325 final Rect mOutsetFrame = new Rect();
326
Jorim Jaggidc249c42015-12-15 14:57:31 -0800327 /**
328 * Usually empty. Set to the task's tempInsetFrame. See
329 *{@link android.app.IActivityManager#resizeDockedStack}.
330 */
331 final Rect mInsetFrame = new Rect();
332
Jorim Jaggif5834272016-04-04 20:25:41 -0700333 private static final Rect sTmpRect = new Rect();
334
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800335 boolean mContentChanged;
336
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800337 // If a window showing a wallpaper: the requested offset for the
338 // wallpaper; if a wallpaper window: the currently applied offset.
339 float mWallpaperX = -1;
340 float mWallpaperY = -1;
341
342 // If a window showing a wallpaper: what fraction of the offset
343 // range corresponds to a full virtual screen.
344 float mWallpaperXStep = -1;
345 float mWallpaperYStep = -1;
346
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700347 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
348 // to its window; if a wallpaper window: not used.
349 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
350 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
351
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800352 // Wallpaper windows: pixels offset based on above variables.
353 int mXOffset;
354 int mYOffset;
355
Craig Mautner2268e7e2012-12-13 15:40:00 -0800356 /**
357 * This is set after IWindowSession.relayout() has been called at
358 * least once for the window. It allows us to detect the situation
359 * where we don't yet have a surface, but should have one soon, so
360 * we can give the window focus before waiting for the relayout.
361 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800362 boolean mRelayoutCalled;
363
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800364 /**
365 * If the application has called relayout() with changes that can
366 * impact its window's size, we need to perform a layout pass on it
367 * even if it is not currently visible for layout. This is set
368 * when in that case until the layout is done.
369 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800370 boolean mLayoutNeeded;
371
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800372 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800373 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800374
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800375 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800376 boolean mDestroying;
377
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800378 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800379 boolean mRemoveOnExit;
380
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800381 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800382 * Whether the app died while it was visible, if true we might need
383 * to continue to show it until it's restarted.
384 */
385 boolean mAppDied;
386
387 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800388 * Set when the orientation is changing and this window has not yet
389 * been updated for the new orientation.
390 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800391 boolean mOrientationChanging;
392
Dianne Hackborna57c6952013-03-29 14:46:40 -0700393 /**
394 * How long we last kept the screen frozen.
395 */
396 int mLastFreezeDuration;
397
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800398 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800399 boolean mRemoved;
400
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800401 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800402 * It is save to remove the window and destroy the surface because the client requested removal
403 * or some other higher level component said so (e.g. activity manager).
404 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800405 */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800406 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800407
408 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800409 * Temp for keeping track of windows that have been removed when
410 * rebuilding window list.
411 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800412 boolean mRebuilding;
413
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800414 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700415 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800416 InputChannel mInputChannel;
Chong Zhang112eb8c2015-11-02 11:17:00 -0800417 InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800418
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800419 // Used to improve performance of toString()
420 String mStringNameCache;
421 CharSequence mLastTitle;
Dianne Hackborn529e7442012-11-01 14:22:28 -0700422 boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800423
Craig Mautnera2c77052012-03-26 12:14:43 -0700424 final WindowStateAnimator mWinAnimator;
425
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700426 boolean mHasSurface = false;
427
Craig Mautner19ab8282014-05-07 10:35:34 -0700428 boolean mNotOnAppsDisplay = false;
Craig Mautner59c00972012-07-30 12:10:24 -0700429 DisplayContent mDisplayContent;
Craig Mautner6881a102012-07-27 13:04:51 -0700430
Craig Mautner88400d32012-09-30 12:35:45 -0700431 /** When true this window can be displayed on screens owther than mOwnerUid's */
432 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700433
Robert Carr13f7be9e2015-12-02 18:39:45 -0800434 // Whether the window has a saved surface from last pause, which can be
435 // used to start an entering animation earlier.
436 public boolean mSurfaceSaved = false;
437
Robert Carra1eb4392015-12-10 12:43:51 -0800438 // This window will be replaced due to relaunch. This allows window manager
439 // to differentiate between simple removal of a window and replacement. In the latter case it
440 // will preserve the old window until the new one is drawn.
441 boolean mWillReplaceWindow = false;
442 // If true, the replaced window was already requested to be removed.
443 boolean mReplacingRemoveRequested = false;
444 // Whether the replacement of the window should trigger app transition animation.
445 boolean mAnimateReplacingWindow = false;
446 // If not null, the window that will be used to replace the old one. This is being set when
447 // the window is added and unset when this window reports its first draw.
448 WindowState mReplacingWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700449 // For the new window in the replacement transition, if we have
450 // requested to replace without animation, then we should
451 // make sure we also don't apply an enter animation for
452 // the new window.
453 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800454 // Whether this window is being moved via the resize API
455 boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800456
Jeff Brownc2932a12014-11-20 18:04:05 -0800457 /**
458 * Wake lock for drawing.
459 * Even though it's slightly more expensive to do so, we will use a separate wake lock
460 * for each app that is requesting to draw while dozing so that we can accurately track
461 * who is preventing the system from suspending.
462 * This lock is only acquired on first use.
463 */
464 PowerManager.WakeLock mDrawLock;
465
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700466 final private Rect mTmpRect = new Rect();
467
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800468 /**
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800469 * See {@link #notifyMovedInStack}.
470 */
471 private boolean mJustMovedInStack;
472
473 /**
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800474 * Whether the window was resized by us while it was gone for layout.
475 */
476 boolean mResizedWhileGone = false;
477
Jorim Jaggif3df0aa2016-04-06 15:56:33 -0700478 /**
479 * Indicates whether we got resized but drag resizing flag was false. In this case, we also
480 * need to recreate the surface and defer surface bound updates in order to make sure the
481 * buffer contents and the positioning/size stay in sync.
482 */
483 boolean mResizedWhileNotDragResizing;
484
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800485 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800486 WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a,
Craig Mautner59c00972012-07-30 12:10:24 -0700487 int viewVisibility, final DisplayContent displayContent) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800488 mService = service;
489 mSession = s;
490 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800491 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800492 mToken = token;
Craig Mautnera2d7b112012-08-21 15:12:20 -0700493 mOwnerUid = s.mUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800494 mWindowId = new IWindowId.Stub() {
495 @Override
496 public void registerFocusObserver(IWindowFocusObserver observer) {
497 WindowState.this.registerFocusObserver(observer);
498 }
499 @Override
500 public void unregisterFocusObserver(IWindowFocusObserver observer) {
501 WindowState.this.unregisterFocusObserver(observer);
502 }
503 @Override
504 public boolean isFocused() {
505 return WindowState.this.isFocused();
506 }
507 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800508 mAttrs.copyFrom(a);
509 mViewVisibility = viewVisibility;
Craig Mautner59c00972012-07-30 12:10:24 -0700510 mDisplayContent = displayContent;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700511 mPolicy = mService.mPolicy;
512 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800513 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700514 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700515 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800516 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700517 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700518 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800519 try {
520 c.asBinder().linkToDeath(deathRecipient, 0);
521 } catch (RemoteException e) {
522 mDeathRecipient = null;
523 mAttachedWindow = null;
524 mLayoutAttached = false;
525 mIsImWindow = false;
526 mIsWallpaper = false;
527 mIsFloatingLayer = false;
528 mBaseLayer = 0;
529 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700530 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700531 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800532 return;
533 }
534 mDeathRecipient = deathRecipient;
535
536 if ((mAttrs.type >= FIRST_SUB_WINDOW &&
537 mAttrs.type <= LAST_SUB_WINDOW)) {
538 // The multiplier here is to reserve space for multiple
539 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700540 mBaseLayer = mPolicy.windowTypeToLayerLw(
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800541 attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
542 + WindowManagerService.TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700543 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800544 mAttachedWindow = attachedWindow;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800545 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
takeda.masayuki18735092012-12-12 11:06:24 +0900546
tiger_huange2a98a72014-11-13 19:46:28 +0800547 final WindowList childWindows = mAttachedWindow.mChildWindows;
548 final int numChildWindows = childWindows.size();
549 if (numChildWindows == 0) {
550 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900551 } else {
tiger_huange2a98a72014-11-13 19:46:28 +0800552 boolean added = false;
553 for (int i = 0; i < numChildWindows; i++) {
554 final int childSubLayer = childWindows.get(i).mSubLayer;
555 if (mSubLayer < childSubLayer
556 || (mSubLayer == childSubLayer && childSubLayer < 0)) {
557 // We insert the child window into the list ordered by the sub-layer. For
558 // same sub-layers, the negative one should go below others; the positive
559 // one should go above others.
560 childWindows.add(i, this);
561 added = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900562 break;
takeda.masayuki18735092012-12-12 11:06:24 +0900563 }
564 }
tiger_huange2a98a72014-11-13 19:46:28 +0800565 if (!added) {
566 childWindows.add(this);
takeda.masayuki18735092012-12-12 11:06:24 +0900567 }
568 }
569
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800570 mLayoutAttached = mAttrs.type !=
571 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
572 mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
573 || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
574 mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
575 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
576 } else {
577 // The multiplier here is to reserve space for multiple
578 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700579 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800580 * WindowManagerService.TYPE_LAYER_MULTIPLIER
581 + WindowManagerService.TYPE_LAYER_OFFSET;
582 mSubLayer = 0;
583 mAttachedWindow = null;
584 mLayoutAttached = false;
585 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
586 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
587 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
588 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
589 }
590
591 WindowState appWin = this;
Robert Carr51a1b872015-12-08 14:03:13 -0800592 while (appWin.isChildWindow()) {
Craig Mautnera2c77052012-03-26 12:14:43 -0700593 appWin = appWin.mAttachedWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800594 }
595 WindowToken appToken = appWin.mToken;
596 while (appToken.appWindowToken == null) {
597 WindowToken parent = mService.mTokenMap.get(appToken.token);
598 if (parent == null || appToken == parent) {
599 break;
600 }
601 appToken = parent;
602 }
603 mRootToken = appToken;
604 mAppToken = appToken.appWindowToken;
Craig Mautner19ab8282014-05-07 10:35:34 -0700605 if (mAppToken != null) {
606 final DisplayContent appDisplay = getDisplayContent();
607 mNotOnAppsDisplay = displayContent != appDisplay;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700608
609 if (mAppToken.showForAllUsers) {
610 // Windows for apps that can show for all users should also show when the
611 // device is locked.
612 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
613 }
Craig Mautner19ab8282014-05-07 10:35:34 -0700614 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800615
Craig Mautner322e4032012-07-13 13:35:20 -0700616 mWinAnimator = new WindowStateAnimator(this);
617 mWinAnimator.mAlpha = a.alpha;
618
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800619 mRequestedWidth = 0;
620 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700621 mLastRequestedWidth = 0;
622 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800623 mXOffset = 0;
624 mYOffset = 0;
625 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800626 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700627 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
628 displayContent.getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800629 }
630
631 void attach() {
632 if (WindowManagerService.localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700633 TAG, "Attaching " + this + " token=" + mToken
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800634 + ", list=" + mToken.windows);
635 mSession.windowAddedLocked();
636 }
637
Craig Mautnera2c77052012-03-26 12:14:43 -0700638 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800639 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800640 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800641 }
642
643 @Override
644 public String getOwningPackage() {
645 return mAttrs.packageName;
646 }
647
Jorim Jaggif5834272016-04-04 20:25:41 -0700648 /**
649 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
650 * from {@param frame}. In other words, it applies the insets that would result if
651 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700652 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
653 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700654 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700655 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
656 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
657 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
658 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
659 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700660 frame.inset(left, top, right, bottom);
661 }
662
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800663 @Override
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700664 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf, Rect sf,
665 Rect osf) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800666 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700667 // This window is being replaced and either already got information that it's being
668 // removed or we are still waiting for some information. Because of this we don't
669 // want to apply any more changes to it, so it remains in this state until new window
670 // appears.
671 return;
672 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800673 mHaveFrame = true;
674
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700675 final Task task = getTask();
Andrii Kulian933076d2016-03-29 17:04:42 -0700676 final boolean fullscreenTask = !isInMultiWindowMode();
Robert Carre6275582016-02-29 15:45:45 -0800677 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800678
Chong Zhangae35fef2016-03-16 15:56:55 -0700679 // If the task has temp inset bounds set, we have to make sure all its windows uses
680 // the temp inset frame. Otherwise different display frames get applied to the main
681 // window and the child window, making them misaligned.
682 if (fullscreenTask) {
683 mInsetFrame.setEmpty();
684 } else {
685 task.getTempInsetBounds(mInsetFrame);
686 }
687
Jorim Jaggif5834272016-04-04 20:25:41 -0700688 // Denotes the actual frame used to calculate the insets and to perform the layout. When
689 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
690 // insets temporarily. By the notion of a task having a different layout frame, we can
691 // achieve that while still moving the task around.
692 final Rect layoutContainingFrame;
693 final Rect layoutDisplayFrame;
694
695 // The offset from the layout containing frame to the actual containing frame.
696 final int layoutXDiff;
697 final int layoutYDiff;
Andrii Kuliandaea3572016-04-08 13:20:51 -0700698 if (mInsetFrame.isEmpty() && (fullscreenTask || layoutInParentFrame())) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800699 // We use the parent frame as the containing frame for fullscreen and child windows
700 mContainingFrame.set(pf);
701 mDisplayFrame.set(df);
Jorim Jaggif5834272016-04-04 20:25:41 -0700702 layoutDisplayFrame = df;
703 layoutContainingFrame = pf;
704 layoutXDiff = 0;
705 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800706 } else {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700707 task.getBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100708 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
709
710 // If the bounds are frozen, we still want to translate the window freely and only
711 // freeze the size.
712 Rect frozen = mAppToken.mFrozenBounds.peek();
713 mContainingFrame.right = mContainingFrame.left + frozen.width();
714 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
715 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800716 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700717 // IME is up and obscuring this window. Adjust the window position so it is visible.
718 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this) {
719 if (windowsAreFloating && mContainingFrame.bottom > cf.bottom) {
720 // In freeform we want to move the top up directly.
721 // TODO: Investigate why this is cf not pf.
722 mContainingFrame.top -= mContainingFrame.bottom - cf.bottom;
723 } else if (mContainingFrame.bottom > pf.bottom) {
724 // But in docked we want to behave like fullscreen
725 // and behave as if the task were given smaller bounds
726 // for the purposes of layout.
727 mContainingFrame.bottom = pf.bottom;
728 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700729 }
Skuhne81c524a2015-08-12 13:34:14 -0700730
Robert Carre6275582016-02-29 15:45:45 -0800731 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700732 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
733 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800734 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700735 if (mContainingFrame.isEmpty()) {
736 mContainingFrame.set(cf);
737 }
Doris Liu06d582d2015-06-01 13:18:43 -0700738 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800739 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700740 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
741 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
742 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Andrii Kuliandaea3572016-04-08 13:20:51 -0700743 mTmpRect.set(0, 0, mDisplayContent.getDisplayInfo().logicalWidth,
744 mDisplayContent.getDisplayInfo().logicalHeight);
745 subtractInsets(mDisplayFrame, layoutContainingFrame, df, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700746 if (!layoutInParentFrame()) {
Andrii Kuliandaea3572016-04-08 13:20:51 -0700747 subtractInsets(mContainingFrame, layoutContainingFrame, pf, mTmpRect);
748 subtractInsets(mInsetFrame, layoutContainingFrame, pf, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700749 }
Jorim Jaggif5834272016-04-04 20:25:41 -0700750 layoutDisplayFrame = df;
751 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700752 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800753
Craig Mautner967212c2013-04-13 21:10:58 -0700754 final int pw = mContainingFrame.width();
755 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800756
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800757 if (!mParentFrame.equals(pf)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800758 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800759 // + " to " + pf);
760 mParentFrame.set(pf);
761 mContentChanged = true;
762 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700763 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
764 mLastRequestedWidth = mRequestedWidth;
765 mLastRequestedHeight = mRequestedHeight;
766 mContentChanged = true;
767 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800768
Craig Mautnereda67292013-04-28 13:50:14 -0700769 mOverscanFrame.set(of);
770 mContentFrame.set(cf);
771 mVisibleFrame.set(vf);
John Spurlock46646232013-09-30 22:32:42 -0400772 mDecorFrame.set(dcf);
Adrian Roosfa104232014-06-20 16:10:14 -0700773 mStableFrame.set(sf);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700774 final boolean hasOutsets = osf != null;
775 if (hasOutsets) {
776 mOutsetFrame.set(osf);
777 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800778
Craig Mautnereda67292013-04-28 13:50:14 -0700779 final int fw = mFrame.width();
780 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800781
Jorim Jaggif5834272016-04-04 20:25:41 -0700782 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
783
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700784 // Calculate the outsets before the content frame gets shrinked to the window frame.
785 if (hasOutsets) {
786 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
787 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
788 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
789 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
790 } else {
791 mOutsets.set(0, 0, 0, 0);
792 }
793
Craig Mautnera248eee2013-05-07 11:41:27 -0700794 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800795 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -0800796 if (windowsAreFloating && !mFrame.isEmpty()) {
Skuhne81c524a2015-08-12 13:34:14 -0700797 // Keep the frame out of the blocked system area, limit it in size to the content area
798 // and make sure that there is always a minimum visible so that the user can drag it
799 // into a usable area..
800 final int height = Math.min(mFrame.height(), mContentFrame.height());
801 final int width = Math.min(mContentFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700802 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Filip Gruszczynski0689ae92015-10-01 12:30:31 -0700803 final int minVisibleHeight = WindowManagerService.dipToPixel(
804 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics);
805 final int minVisibleWidth = WindowManagerService.dipToPixel(
806 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics);
Skuhne81c524a2015-08-12 13:34:14 -0700807 final int top = Math.max(mContentFrame.top,
808 Math.min(mFrame.top, mContentFrame.bottom - minVisibleHeight));
809 final int left = Math.max(mContentFrame.left + minVisibleWidth - width,
810 Math.min(mFrame.left, mContentFrame.right - minVisibleWidth));
811 mFrame.set(left, top, left + width, top + height);
812 mContentFrame.set(mFrame);
813 mVisibleFrame.set(mContentFrame);
814 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700815 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi192086e2016-03-11 17:17:03 +0100816 mDisplayContent.getDockedDividerController().positionDockedStackedDivider(mFrame);
817 mContentFrame.set(mFrame);
818 if (!mFrame.equals(mLastFrame)) {
819 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800820 }
Skuhne81c524a2015-08-12 13:34:14 -0700821 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -0700822 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
823 Math.max(mContentFrame.top, mFrame.top),
824 Math.min(mContentFrame.right, mFrame.right),
825 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800826
Jorim Jaggi656f6502016-04-11 21:08:17 -0700827 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
828 Math.max(mVisibleFrame.top, mFrame.top),
829 Math.min(mVisibleFrame.right, mFrame.right),
830 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800831
Jorim Jaggi656f6502016-04-11 21:08:17 -0700832 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
833 Math.max(mStableFrame.top, mFrame.top),
834 Math.min(mStableFrame.right, mFrame.right),
835 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700836 }
Adrian Roosfa104232014-06-20 16:10:14 -0700837
Jorim Jaggi899327f2016-02-25 20:44:18 -0500838 if (fullscreenTask && !windowsAreFloating) {
839 // Windows that are not fullscreen can be positioned outside of the display frame,
840 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -0700841 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
842 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
843 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
844 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800845 }
Craig Mautnereda67292013-04-28 13:50:14 -0700846
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100847 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100848 // For the docked divider, we calculate the stable insets like a full-screen window
849 // so it can use it to calculate the snap positions.
850 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
851 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
852 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
853 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800854
855 // The divider doesn't care about insets in any case, so set it to empty so we don't
856 // trigger a relayout when moving it.
857 mContentInsets.setEmpty();
858 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100859 } else {
Andrii Kuliand9003372016-04-04 17:46:59 -0700860 getDisplayContent().getLogicalDisplayRect(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700861 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
862 // non-fullscreen mode.
Jorim Jaggi656f6502016-04-11 21:08:17 -0700863 boolean overrideRightInset = !fullscreenTask && mFrame.right > mTmpRect.right;
864 boolean overrideBottomInset = !fullscreenTask && mFrame.bottom > mTmpRect.bottom;
865 mContentInsets.set(mContentFrame.left - mFrame.left,
866 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700867 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700868 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700869 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700870 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800871
Jorim Jaggi656f6502016-04-11 21:08:17 -0700872 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
873 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700874 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700875 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700876 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700877 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800878
Jorim Jaggi656f6502016-04-11 21:08:17 -0700879 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
880 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700881 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700882 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700883 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700884 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100885 }
Adrian Roosfa104232014-06-20 16:10:14 -0700886
Jorim Jaggi656f6502016-04-11 21:08:17 -0700887 // Offset the actual frame by the amount layout frame is off.
888 mFrame.offset(-layoutXDiff, -layoutYDiff);
889 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -0700890 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
891 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
892 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
893
Craig Mautnereda67292013-04-28 13:50:14 -0700894 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400895 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700896 // If there is a size compatibility scale being applied to the
897 // window, we need to apply this to its insets so that they are
898 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700899 mOverscanInsets.scale(mInvGlobalScale);
900 mContentInsets.scale(mInvGlobalScale);
901 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700902 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700903 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700904
905 // Also the scaled frame that we report to the app needs to be
906 // adjusted to be in its coordinate space.
907 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400908 }
909
Craig Mautnereda67292013-04-28 13:50:14 -0700910 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800911 final DisplayContent displayContent = getDisplayContent();
912 if (displayContent != null) {
913 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700914 mService.mWallpaperControllerLocked.updateWallpaperOffset(
915 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800916 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800917 }
918
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700919 if (DEBUG_LAYOUT || WindowManagerService.localLOGV) Slog.v(TAG,
920 "Resolving (mRequestedWidth="
921 + mRequestedWidth + ", mRequestedheight="
922 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
923 + "): frame=" + mFrame.toShortString()
924 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -0700925 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700926 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700927 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800928 }
929
Craig Mautnera2c77052012-03-26 12:14:43 -0700930 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800931 public Rect getFrameLw() {
932 return mFrame;
933 }
934
Craig Mautnera2c77052012-03-26 12:14:43 -0700935 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700936 public Point getShownPositionLw() {
937 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800938 }
939
Craig Mautnera2c77052012-03-26 12:14:43 -0700940 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800941 public Rect getDisplayFrameLw() {
942 return mDisplayFrame;
943 }
944
Craig Mautnera2c77052012-03-26 12:14:43 -0700945 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800946 public Rect getOverscanFrameLw() {
947 return mOverscanFrame;
948 }
949
950 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800951 public Rect getContentFrameLw() {
952 return mContentFrame;
953 }
954
Craig Mautnera2c77052012-03-26 12:14:43 -0700955 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800956 public Rect getVisibleFrameLw() {
957 return mVisibleFrame;
958 }
959
Craig Mautnera2c77052012-03-26 12:14:43 -0700960 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800961 public boolean getGivenInsetsPendingLw() {
962 return mGivenInsetsPending;
963 }
964
Craig Mautnera2c77052012-03-26 12:14:43 -0700965 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800966 public Rect getGivenContentInsetsLw() {
967 return mGivenContentInsets;
968 }
969
Craig Mautnera2c77052012-03-26 12:14:43 -0700970 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800971 public Rect getGivenVisibleInsetsLw() {
972 return mGivenVisibleInsets;
973 }
974
Craig Mautnera2c77052012-03-26 12:14:43 -0700975 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800976 public WindowManager.LayoutParams getAttrs() {
977 return mAttrs;
978 }
979
Craig Mautner812d2ca2012-09-27 15:35:34 -0700980 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800981 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
982 int index = -1;
983 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -0700984 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800985 while (true) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -0700986 if (ws.mAttrs.needsMenuKey != WindowManager.LayoutParams.NEEDS_MENU_UNSET) {
987 return ws.mAttrs.needsMenuKey == WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800988 }
989 // If we reached the bottom of the range of windows we are considering,
990 // assume no menu is needed.
991 if (ws == bottom) {
992 return false;
993 }
994 // The current window hasn't specified whether menu key is needed;
995 // look behind it.
996 // First, we may need to determine the starting position.
997 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -0700998 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -0800999 }
1000 index--;
1001 if (index < 0) {
1002 return false;
1003 }
Craig Mautner59c00972012-07-30 12:10:24 -07001004 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001005 }
1006 }
1007
Craig Mautner19d59bc2012-09-04 11:15:56 -07001008 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001009 public int getSystemUiVisibility() {
1010 return mSystemUiVisibility;
1011 }
1012
Craig Mautner19d59bc2012-09-04 11:15:56 -07001013 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001014 public int getSurfaceLayer() {
1015 return mLayer;
1016 }
1017
Craig Mautner812d2ca2012-09-27 15:35:34 -07001018 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001019 public int getBaseType() {
1020 WindowState win = this;
Robert Carr51a1b872015-12-08 14:03:13 -08001021 while (win.isChildWindow()) {
Selim Cinekd6623612015-05-22 18:56:22 -07001022 win = win.mAttachedWindow;
1023 }
1024 return win.mAttrs.type;
1025 }
1026
1027 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001028 public IApplicationToken getAppToken() {
1029 return mAppToken != null ? mAppToken.appToken : null;
1030 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001031
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001032 @Override
1033 public boolean isVoiceInteraction() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001034 return mAppToken != null && mAppToken.voiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001035 }
1036
Craig Mautner4c5eb222013-11-18 12:59:05 -08001037 boolean setInsetsChanged() {
1038 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1039 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1040 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001041 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001042 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
1043 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
1044 || mOutsetsChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001045 }
1046
Craig Mautnerdf88d732014-01-27 09:21:32 -08001047 public DisplayContent getDisplayContent() {
Chad Jonesf391ebc2014-06-12 17:45:05 -07001048 if (mAppToken == null || mNotOnAppsDisplay) {
Craig Mautnerbe634952014-06-12 13:39:24 -07001049 return mDisplayContent;
1050 }
1051 final TaskStack stack = getStack();
1052 return stack == null ? mDisplayContent : stack.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001053 }
1054
Chong Zhang09b21ef2015-09-14 10:20:21 -07001055 public DisplayInfo getDisplayInfo() {
1056 final DisplayContent displayContent = getDisplayContent();
1057 return displayContent != null ? displayContent.getDisplayInfo() : null;
1058 }
1059
Craig Mautner19d59bc2012-09-04 11:15:56 -07001060 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001061 final DisplayContent displayContent = getDisplayContent();
1062 if (displayContent == null) {
1063 return -1;
1064 }
1065 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001066 }
1067
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001068 Task getTask() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07001069 return mAppToken != null ? mAppToken.mTask : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001070 }
1071
1072 TaskStack getStack() {
1073 Task task = getTask();
1074 if (task != null) {
1075 if (task.mStack != null) {
1076 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001077 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001078 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001079 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1080 // associate them with some stack to enable dimming.
1081 return mAttrs.type >= WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1082 && mDisplayContent != null ? mDisplayContent.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001083 }
1084
Skuhnef932e562015-08-20 12:07:30 -07001085 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001086 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001087 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001088 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001089 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001090 final Task task = getTask();
1091 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001092 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001093 mTmpRect.setEmpty();
1094 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001095 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001096 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001097 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001098 } else {
1099 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001100 }
1101 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001102
Chong Zhang9184ec62015-09-24 12:32:21 -07001103 bounds.set(mVisibleFrame);
1104 if (intersectWithStackBounds) {
1105 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001106 }
1107
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001108 if (bounds.isEmpty()) {
1109 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001110 if (intersectWithStackBounds) {
1111 bounds.intersect(mTmpRect);
1112 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001113 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001114 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001115 }
1116
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001117 public long getInputDispatchingTimeoutNanos() {
1118 return mAppToken != null
1119 ? mAppToken.inputDispatchingTimeoutNanos
1120 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1121 }
1122
Craig Mautnere8552142012-11-07 13:55:47 -08001123 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001124 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001125 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001126 }
1127
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001128 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1129 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1130 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1131 if (dtdx < -.000001f || dtdx > .000001f) return false;
1132 if (dsdy < -.000001f || dsdy > .000001f) return false;
1133 return true;
1134 }
1135
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001136 void prelayout() {
1137 if (mEnforceSizeCompat) {
1138 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001139 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001140 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001141 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001142 }
1143 }
1144
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001145 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001146 * Does the minimal check for visibility. Callers generally want to use one of the public
1147 * methods as they perform additional checks on the app token.
1148 * TODO: See if there are other places we can use this check below instead of duplicating...
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001149 */
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001150 private boolean isVisibleUnchecked() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001151 return mHasSurface && mPolicyVisibility && !mAttachedHidden
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001152 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001153 }
1154
1155 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001156 * Is this window visible? It is not visible if there is no surface, or we are in the process
1157 * of running an exit animation that will remove the surface, or its app token has been hidden.
1158 */
1159 @Override
1160 public boolean isVisibleLw() {
1161 return (mAppToken == null || !mAppToken.hiddenRequested) && isVisibleUnchecked();
1162 }
1163
1164 /**
1165 * Like {@link #isVisibleLw}, but also counts a window that is currently "hidden" behind the
1166 * keyguard as visible. This allows us to apply things like window flags that impact the
1167 * keyguard. XXX I am starting to think we need to have ANOTHER visibility flag for this
1168 * "hidden behind keyguard" state rather than overloading mPolicyVisibility. Ungh.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001169 */
Craig Mautner88400d32012-09-30 12:35:45 -07001170 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001171 public boolean isVisibleOrBehindKeyguardLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001172 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001173 return false;
1174 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001175 final AppWindowToken atoken = mAppToken;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001176 final boolean animating = atoken != null && atoken.mAppAnimator.animation != null;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001177 return mHasSurface && !mDestroying && !mAnimatingExit
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001178 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001179 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001180 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001181 }
1182
1183 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001184 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1185 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001186 */
1187 public boolean isWinVisibleLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001188 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.mAppAnimator.animating)
1189 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001190 }
1191
1192 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001193 * The same as isVisible(), but follows the current hidden state of the associated app token,
1194 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001195 */
1196 boolean isVisibleNow() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001197 return (!mRootToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
1198 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001199 }
1200
1201 /**
1202 * Can this window possibly be a drag/drop target? The test here is
1203 * a combination of the above "visible now" with the check that the
1204 * Input Manager uses when discarding windows from input consideration.
1205 */
1206 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001207 return isVisibleNow() && !mRemoved
1208 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001209 }
1210
1211 /**
1212 * Same as isVisible(), but we also count it as visible between the
1213 * call to IWindowSession.add() and the first relayout().
1214 */
1215 boolean isVisibleOrAdding() {
1216 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001217 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001218 && mPolicyVisibility && !mAttachedHidden
1219 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001220 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001221 }
1222
1223 /**
1224 * Is this window currently on-screen? It is on-screen either if it
1225 * is visible or it is currently running an animation before no longer
1226 * being visible.
1227 */
1228 boolean isOnScreen() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001229 return mPolicyVisibility && isOnScreenIgnoringKeyguard();
1230 }
1231
1232 /**
1233 * Like isOnScreen(), but ignores any force hiding of the window due
1234 * to the keyguard.
1235 */
1236 boolean isOnScreenIgnoringKeyguard() {
1237 if (!mHasSurface || mDestroying) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001238 return false;
1239 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001240 final AppWindowToken atoken = mAppToken;
1241 if (atoken != null) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001242 return ((!mAttachedHidden && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001243 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001244 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001245 return !mAttachedHidden || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001246 }
1247
1248 /**
1249 * Like isOnScreen(), but we don't return true if the window is part
1250 * of a transition that has not yet been started.
1251 */
1252 boolean isReadyForDisplay() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001253 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001254 return false;
1255 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001256 return mHasSurface && mPolicyVisibility && !mDestroying
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001257 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE && !mRootToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001258 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001259 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001260 }
1261
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001262 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001263 * Like isReadyForDisplay(), but ignores any force hiding of the window due
1264 * to the keyguard.
1265 */
1266 boolean isReadyForDisplayIgnoringKeyguard() {
Craig Mautner164d4bb2012-11-26 13:51:23 -08001267 if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001268 return false;
1269 }
1270 final AppWindowToken atoken = mAppToken;
1271 if (atoken == null && !mPolicyVisibility) {
1272 // If this is not an app window, and the policy has asked to force
1273 // hide, then we really do want to hide.
1274 return false;
1275 }
1276 return mHasSurface && !mDestroying
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001277 && ((!mAttachedHidden && mViewVisibility == View.VISIBLE && !mRootToken.hidden)
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001278 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -07001279 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
1280 && !mWinAnimator.isDummyAnimation()));
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001281 }
1282
1283 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001284 * Like isOnScreen, but returns false if the surface hasn't yet
1285 * been drawn.
1286 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001287 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001288 public boolean isDisplayedLw() {
1289 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001290 return isDrawnLw() && mPolicyVisibility
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001291 && ((!mAttachedHidden &&
1292 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001293 || mWinAnimator.mAnimating
1294 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001295 }
1296
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001297 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001298 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001299 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001300 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001301 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001302 return mWinAnimator.mAnimation != null
1303 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001304 }
1305
Craig Mautner812d2ca2012-09-27 15:35:34 -07001306 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001307 public boolean isGoneForLayoutLw() {
1308 final AppWindowToken atoken = mAppToken;
1309 return mViewVisibility == View.GONE
1310 || !mRelayoutCalled
1311 || (atoken == null && mRootToken.hidden)
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001312 || (atoken != null && atoken.hiddenRequested)
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001313 || mAttachedHidden
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001314 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001315 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001316 }
1317
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001318 /**
1319 * Returns true if the window has a surface that it has drawn a
1320 * complete UI in to.
1321 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001322 public boolean isDrawFinishedLw() {
1323 return mHasSurface && !mDestroying &&
1324 (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING
1325 || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1326 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
1327 }
1328
1329 /**
1330 * Returns true if the window has a surface that it has drawn a
1331 * complete UI in to.
1332 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001333 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001334 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001335 return mHasSurface && !mDestroying &&
Craig Mautner749a7bb2012-04-02 13:49:53 -07001336 (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
1337 || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001338 }
1339
1340 /**
1341 * Return true if the window is opaque and fully drawn. This indicates
1342 * it may obscure windows behind it.
1343 */
1344 boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001345 // When there is keyguard, wallpaper could be placed over the secure app
1346 // window but invisible. We need to check wallpaper visibility explicitly
1347 // to determine if it's occluding apps.
1348 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1349 || (mIsWallpaper && mWallpaperVisible))
Craig Mautnera2c77052012-03-26 12:14:43 -07001350 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001351 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001352 }
1353
1354 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001355 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001356 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1357 */
Craig Mautner4557c082015-04-27 13:07:40 -07001358 boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001359 return mHasSurface && (mContentChanged || mMovedByResize)
Jorim Jaggi192086e2016-03-11 17:17:03 +01001360 && !mAnimatingExit && mService.okToDisplay()
Chong Zhangbd0d9372015-12-28 15:18:29 -08001361 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Craig Mautner4557c082015-04-27 13:07:40 -07001362 && (mAttachedWindow == null || !mAttachedWindow.hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001363 }
1364
Chong Zhang0abb20f2015-11-19 14:17:31 -08001365 boolean isObscuringFullscreen(final DisplayInfo displayInfo) {
1366 Task task = getTask();
1367 if (task != null && task.mStack != null && !task.mStack.isFullscreen()) {
1368 return false;
1369 }
1370 if (!isOpaqueDrawn() || !isFrameFullscreen(displayInfo)) {
1371 return false;
1372 }
1373 return true;
1374 }
1375
1376 boolean isFrameFullscreen(final DisplayInfo displayInfo) {
1377 return mFrame.left <= 0 && mFrame.top <= 0
1378 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001379 }
1380
Craig Mautner812d2ca2012-09-27 15:35:34 -07001381 boolean isConfigChanged() {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001382 final Task task = getTask();
Wale Ogunwale60454db2015-01-23 16:05:07 -08001383 final Configuration overrideConfig =
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001384 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001385 final Configuration serviceConfig = mService.mCurConfiguration;
1386 boolean configChanged =
1387 (mConfiguration != serviceConfig && mConfiguration.diff(serviceConfig) != 0)
1388 || (mOverrideConfig != overrideConfig && !mOverrideConfig.equals(overrideConfig));
Craig Mautnere8552142012-11-07 13:55:47 -08001389
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001390 if ((mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Craig Mautnere8552142012-11-07 13:55:47 -08001391 // Retain configuration changed status until resetConfiguration called.
1392 mConfigHasChanged |= configChanged;
1393 configChanged = mConfigHasChanged;
1394 }
1395
1396 return configChanged;
Craig Mautner812d2ca2012-09-27 15:35:34 -07001397 }
1398
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07001399 boolean isAdjustedForMinimizedDock() {
1400 return mAppToken != null && mAppToken.mTask != null
1401 && mAppToken.mTask.mStack.isAdjustedForMinimizedDock();
1402 }
1403
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001404 void removeLocked() {
1405 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001406
Robert Carr51a1b872015-12-08 14:03:13 -08001407 if (isChildWindow()) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -08001408 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001409 mAttachedWindow.mChildWindows.remove(this);
1410 }
Craig Mautner96868332012-12-04 14:29:11 -08001411 mWinAnimator.destroyDeferredSurfaceLocked();
1412 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001413 mSession.windowRemovedLocked();
1414 try {
1415 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1416 } catch (RuntimeException e) {
1417 // Ignore if it has already been removed (usually because
1418 // we are doing this as part of processing a death note.)
1419 }
1420 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001421
Wale Ogunwale60454db2015-01-23 16:05:07 -08001422 private void setConfiguration(
1423 final Configuration newConfig, final Configuration newOverrideConfig) {
Craig Mautnere8552142012-11-07 13:55:47 -08001424 mConfiguration = newConfig;
Wale Ogunwale60454db2015-01-23 16:05:07 -08001425 mOverrideConfig = newOverrideConfig;
Craig Mautnere8552142012-11-07 13:55:47 -08001426 mConfigHasChanged = false;
Robert Carrc24d8f92016-02-29 16:24:33 -08001427
1428 mMergedConfiguration.setTo(newConfig);
1429 if (newOverrideConfig != null && newOverrideConfig != Configuration.EMPTY) {
1430 mMergedConfiguration.updateFrom(newOverrideConfig);
1431 }
Craig Mautnere8552142012-11-07 13:55:47 -08001432 }
1433
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001434 void setHasSurface(boolean hasSurface) {
1435 mHasSurface = hasSurface;
1436 }
1437
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001438 int getAnimLayerAdjustment() {
1439 if (mTargetAppToken != null) {
1440 return mTargetAppToken.mAppAnimator.animLayerAdjustment;
1441 } else if (mAppToken != null) {
1442 return mAppToken.mAppAnimator.animLayerAdjustment;
1443 } else {
1444 // Nothing is animating, so there is no animation adjustment.
1445 return 0;
1446 }
1447 }
1448
1449 void scheduleAnimationIfDimming() {
1450 if (mDisplayContent == null) {
1451 return;
1452 }
1453 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1454 if (dimLayerUser != null && mDisplayContent.mDimLayerController.isDimming(
1455 dimLayerUser, mWinAnimator)) {
1456 // Force an animation pass just to update the mDimLayer layer.
1457 mService.scheduleAnimationLocked();
1458 }
1459 }
1460
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08001461 /**
1462 * Notifies this window that the corresponding task has just moved in the stack.
1463 * <p>
1464 * This is used to fix the following: If we moved in the stack, and if the last clip rect was
1465 * empty, meaning that our task was completely offscreen, we need to keep it invisible because
1466 * the actual app transition that updates the visibility is delayed by a few transactions.
1467 * Instead of messing around with the ordering and timing how transitions and transactions are
1468 * executed, we introduce this little hack which prevents this window of getting visible again
1469 * with the wrong bounds until the app transitions has started.
1470 * <p>
1471 * This method notifies the window about that we just moved in the stack so we can apply this
1472 * logic in {@link WindowStateAnimator#updateSurfaceWindowCrop}
1473 */
1474 void notifyMovedInStack() {
1475 mJustMovedInStack = true;
1476 }
1477
1478 /**
1479 * See {@link #notifyMovedInStack}.
1480 *
1481 * @return Whether we just got moved in the corresponding stack.
1482 */
1483 boolean hasJustMovedInStack() {
1484 return mJustMovedInStack;
1485 }
1486
1487 /**
1488 * Resets that we just moved in the corresponding stack. See {@link #notifyMovedInStack}.
1489 */
1490 void resetJustMovedInStack() {
1491 mJustMovedInStack = false;
1492 }
1493
Chong Zhangacf11402015-11-04 16:23:10 -08001494 private final class DeadWindowEventReceiver extends InputEventReceiver {
1495 DeadWindowEventReceiver(InputChannel inputChannel) {
1496 super(inputChannel, mService.mH.getLooper());
1497 }
1498 @Override
1499 public void onInputEvent(InputEvent event) {
1500 finishInputEvent(event, true);
1501 }
1502 }
1503 /**
1504 * Dummy event receiver for windows that died visible.
1505 */
1506 private DeadWindowEventReceiver mDeadWindowEventReceiver;
1507
Chong Zhang112eb8c2015-11-02 11:17:00 -08001508 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001509 if (mInputChannel != null) {
1510 throw new IllegalStateException("Window already has an input channel.");
1511 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001512 String name = makeInputChannelName();
1513 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1514 mInputChannel = inputChannels[0];
1515 mClientChannel = inputChannels[1];
1516 mInputWindowHandle.inputChannel = inputChannels[0];
1517 if (outInputChannel != null) {
1518 mClientChannel.transferTo(outInputChannel);
1519 mClientChannel.dispose();
1520 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08001521 } else {
1522 // If the window died visible, we setup a dummy input channel, so that taps
1523 // can still detected by input monitor channel, and we can relaunch the app.
1524 // Create dummy event receiver that simply reports all events as handled.
1525 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08001526 }
1527 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001528 }
1529
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001530 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08001531 if (mDeadWindowEventReceiver != null) {
1532 mDeadWindowEventReceiver.dispose();
1533 mDeadWindowEventReceiver = null;
1534 }
1535
1536 // unregister server channel first otherwise it complains about broken channel
1537 if (mInputChannel != null) {
1538 mService.mInputManager.unregisterInputChannel(mInputChannel);
1539 mInputChannel.dispose();
1540 mInputChannel = null;
1541 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001542 if (mClientChannel != null) {
1543 mClientChannel.dispose();
1544 mClientChannel = null;
1545 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001546 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001547 }
1548
Chong Zhang112eb8c2015-11-02 11:17:00 -08001549 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08001550 // When the app is terminated (eg. from Recents), the task might have already been
1551 // removed with the window pending removal. Don't apply dim in such cases, as there
1552 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
1553 final AppWindowToken token = mAppToken;
1554 if (token != null && token.removed) {
1555 return;
1556 }
1557
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001558 if (!mAnimatingExit && mAppDied) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001559 // If app died visible, apply a dim over the window to indicate that it's inactive
1560 mDisplayContent.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
1561 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
Robert Carr9fe459d2016-04-07 23:32:28 -07001562 && mDisplayContent != null && !mAnimatingExit && isVisibleUnchecked()) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001563 mDisplayContent.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001564 }
1565 }
1566
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001567 DimLayer.DimLayerUser getDimLayerUser() {
1568 Task task = getTask();
1569 if (task != null) {
1570 return task;
1571 }
1572 return getStack();
1573 }
1574
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001575 void maybeRemoveReplacedWindow() {
Robert Carra1eb4392015-12-10 12:43:51 -08001576 if (mAppToken == null) {
1577 return;
1578 }
1579 for (int i = mAppToken.allAppWindows.size() - 1; i >= 0; i--) {
1580 final WindowState win = mAppToken.allAppWindows.get(i);
Robert Carrdcdca582016-04-07 22:59:24 -07001581 if (win.mWillReplaceWindow && win.mReplacingWindow == this && hasDrawnLw()) {
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08001582 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + win);
Robert Carr9fe459d2016-04-07 23:32:28 -07001583 if (win.isDimming()) {
1584 win.transferDimToReplacement();
1585 }
Robert Carra1eb4392015-12-10 12:43:51 -08001586 win.mWillReplaceWindow = false;
1587 win.mAnimateReplacingWindow = false;
1588 win.mReplacingRemoveRequested = false;
1589 win.mReplacingWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -07001590 mSkipEnterAnimationForSeamlessReplacement = false;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001591 if (win.mAnimatingExit) {
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001592 mService.removeWindowInnerLocked(win);
1593 }
1594 }
1595 }
1596 }
1597
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07001598 void setDisplayLayoutNeeded() {
1599 if (mDisplayContent != null) {
1600 mDisplayContent.layoutNeeded = true;
1601 }
1602 }
1603
Filip Gruszczynski955b2fc2015-10-15 14:46:07 -07001604 boolean inDockedWorkspace() {
Chong Zhang2a88fc32016-01-11 17:14:24 -08001605 final Task task = getTask();
Chong Zhangb15758a2015-11-17 12:12:03 -08001606 return task != null && task.inDockedWorkspace();
1607 }
1608
1609 boolean isDockedInEffect() {
Chong Zhang2a88fc32016-01-11 17:14:24 -08001610 final Task task = getTask();
Chong Zhangb15758a2015-11-17 12:12:03 -08001611 return task != null && task.isDockedInEffect();
Filip Gruszczynski955b2fc2015-10-15 14:46:07 -07001612 }
1613
Chong Zhang2a88fc32016-01-11 17:14:24 -08001614 void applyScrollIfNeeded() {
1615 final Task task = getTask();
Chong Zhangf66db432016-01-13 10:39:51 -08001616 if (task != null) {
1617 task.applyScrollToWindowIfNeeded(this);
Chong Zhang2a88fc32016-01-11 17:14:24 -08001618 }
1619 }
1620
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001621 int getTouchableRegion(Region region, int flags) {
1622 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001623 if (modal && mAppToken != null) {
1624 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001625 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001626 // If this is a modal window we need to dismiss it if it's not full screen and the
1627 // touch happens outside of the frame that displays the content. This means we
1628 // need to intercept touches outside of that window. The dim layer user
1629 // associated with the window (task or stack) will give us the good bounds, as
1630 // they would be used to display the dim layer.
1631 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1632 if (dimLayerUser != null) {
1633 dimLayerUser.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001634 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001635 getVisibleBounds(mTmpRect);
1636 }
1637 if (inFreeformWorkspace()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001638 // For freeform windows we the touch region to include the whole surface for the
1639 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001640 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
1641 final int delta = WindowManagerService.dipToPixel(
1642 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
1643 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001644 }
1645 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001646 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001647 } else {
1648 // Not modal or full screen modal
1649 getTouchableRegion(region);
1650 }
1651 return flags;
1652 }
1653
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001654 void checkPolicyVisibilityChange() {
1655 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
1656 if (DEBUG_VISIBILITY) {
1657 Slog.v(TAG, "Policy visibility changing after anim in " +
1658 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
1659 }
1660 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001661 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001662 if (!mPolicyVisibility) {
1663 if (mService.mCurrentFocus == this) {
1664 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
1665 "setAnimationLocked: setting mFocusMayChange true");
1666 mService.mFocusMayChange = true;
1667 }
1668 // Window is no longer visible -- make sure if we were waiting
1669 // for it to be displayed before enabling the display, that
1670 // we allow the display to be enabled now.
1671 mService.enableScreenIfNeededLocked();
1672 }
1673 }
1674 }
1675
1676 void setRequestedSize(int requestedWidth, int requestedHeight) {
1677 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
1678 mLayoutNeeded = true;
1679 mRequestedWidth = requestedWidth;
1680 mRequestedHeight = requestedHeight;
1681 }
1682 }
1683
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001684 void prepareWindowToDisplayDuringRelayout(Configuration outConfig) {
1685 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
1686 == SOFT_INPUT_ADJUST_RESIZE) {
1687 mLayoutNeeded = true;
1688 }
1689 if (isDrawnLw() && mService.okToDisplay()) {
1690 mWinAnimator.applyEnterAnimationLocked();
1691 }
1692 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
1693 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
1694 mTurnOnScreen = true;
1695 }
1696 if (isConfigChanged()) {
Robert Carrc24d8f92016-02-29 16:24:33 -08001697 final Configuration newConfig = updateConfiguration();
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001698 if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + this + " visible with new config: "
Robert Carrc24d8f92016-02-29 16:24:33 -08001699 + newConfig);
1700 outConfig.setTo(newConfig);
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001701 }
1702 }
1703
1704 void adjustStartingWindowFlags() {
1705 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
1706 && mAppToken.startingWindow != null) {
1707 // Special handling of starting window over the base
1708 // window of the app: propagate lock screen flags to it,
1709 // to provide the correct semantics while starting.
1710 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
1711 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
1712 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
1713 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
1714 }
1715 }
1716
1717 void setWindowScale(int requestedWidth, int requestedHeight) {
1718 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
1719
1720 if (scaledWindow) {
1721 // requested{Width|Height} Surface's physical size
1722 // attrs.{width|height} Size on screen
1723 // TODO: We don't check if attrs != null here. Is it implicitly checked?
1724 mHScale = (mAttrs.width != requestedWidth) ?
1725 (mAttrs.width / (float)requestedWidth) : 1.0f;
1726 mVScale = (mAttrs.height != requestedHeight) ?
1727 (mAttrs.height / (float)requestedHeight) : 1.0f;
1728 } else {
1729 mHScale = mVScale = 1;
1730 }
1731 }
1732
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001733 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08001734 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001735 public void binderDied() {
1736 try {
1737 synchronized(mService.mWindowMap) {
1738 WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07001739 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001740 if (win != null) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001741 if (win.mAppToken != null && !win.mAppToken.clientHidden) {
1742 win.mAppToken.appDied = true;
1743 }
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001744 mService.removeWindowLocked(win);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08001745 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
1746 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08001747 // just in case they have the divider at an unstable position. Better
1748 // also reset drag resizing state, because the owner can't do it
1749 // anymore.
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08001750 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
1751 if (stack != null) {
1752 stack.resetDockedStackToMiddle();
1753 }
Jorim Jaggidcb68142016-02-09 21:51:30 -08001754 mService.setDockedStackResizing(false);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08001755 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001756 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08001757 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwalea6ab5c42015-04-24 09:00:25 -07001758 mService.removeWindowLocked(WindowState.this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001759 }
1760 }
1761 } catch (IllegalArgumentException ex) {
1762 // This will happen if the window has already been
1763 // removed.
1764 }
1765 }
1766 }
1767
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08001768 /**
1769 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
1770 * because we want to preserve its location on screen to be re-activated later when the user
1771 * interacts with it.
1772 */
1773 boolean shouldKeepVisibleDeadAppWindow() {
1774 if (!isWinVisibleLw() || mAppToken == null || !mAppToken.appDied) {
1775 // Not a visible app window or the app isn't dead.
1776 return false;
1777 }
1778
1779 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1780 // We don't keep starting windows since they were added by the window manager before
1781 // the app even launched.
1782 return false;
1783 }
1784
1785 final TaskStack stack = getStack();
1786 return stack != null && StackId.keepVisibleDeadAppWindowOnScreen(stack.mStackId);
1787 }
1788
Wale Ogunwaled045c822015-12-02 09:14:28 -08001789 /** @return true if this window desires key events. */
1790 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08001791 return isVisibleOrAdding()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001792 && (mViewVisibility == View.VISIBLE)
Wale Ogunwaled045c822015-12-02 09:14:28 -08001793 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07001794 && (mAppToken == null || mAppToken.windowsAreFocusable())
1795 && !isAdjustedForMinimizedDock();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001796 }
1797
Craig Mautner749a7bb2012-04-02 13:49:53 -07001798 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001799 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07001800 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001801 }
1802
Craig Mautner749a7bb2012-04-02 13:49:53 -07001803 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001804 public boolean showLw(boolean doAnimation) {
1805 return showLw(doAnimation, true);
1806 }
1807
1808 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07001809 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07001810 return false;
1811 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001812 if (!mAppOpVisibility) {
1813 // Being hidden due to app op request.
1814 return false;
1815 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001816 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001817 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001818 return false;
1819 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07001820 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001821 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001822 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07001823 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07001824 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001825 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07001826 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001827 // Check for the case where we are currently visible and
1828 // not animating; we do not want to do animation at such a
1829 // point to become visible when we already are.
1830 doAnimation = false;
1831 }
1832 }
1833 mPolicyVisibility = true;
1834 mPolicyVisibilityAfterAnim = true;
1835 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001836 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001837 }
1838 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001839 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001840 }
1841 return true;
1842 }
1843
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001844 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001845 public boolean hideLw(boolean doAnimation) {
1846 return hideLw(doAnimation, true);
1847 }
1848
1849 boolean hideLw(boolean doAnimation, boolean requestAnim) {
1850 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07001851 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001852 doAnimation = false;
1853 }
1854 }
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001855 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
1856 : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001857 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07001858 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001859 return false;
1860 }
1861 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07001862 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07001863 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001864 doAnimation = false;
1865 }
1866 }
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001867 if (doAnimation) {
1868 mPolicyVisibilityAfterAnim = false;
1869 } else {
Craig Mautnerd87946b2012-03-29 18:00:19 -07001870 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Filip Gruszczynski19723a42015-11-25 15:01:48 -08001871 mPolicyVisibilityAfterAnim = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001872 mPolicyVisibility = false;
1873 // Window is no longer visible -- make sure if we were waiting
1874 // for it to be displayed before enabling the display, that
1875 // we allow the display to be enabled now.
1876 mService.enableScreenIfNeededLocked();
1877 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001878 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07001879 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001880 mService.mFocusMayChange = true;
1881 }
1882 }
1883 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08001884 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001885 }
1886 return true;
1887 }
1888
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001889 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001890 if (mAppOpVisibility != state) {
1891 mAppOpVisibility = state;
1892 if (state) {
1893 // If the policy visibility had last been to hide, then this
1894 // will incorrectly show at this point since we lost that
1895 // information. Not a big deal -- for the windows that have app
1896 // ops modifies they should only be hidden by policy due to the
1897 // lock screen, and the user won't be changing this if locked.
1898 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001899 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001900 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08001901 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001902 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001903 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08001904 }
1905
Jeff Brownc2932a12014-11-20 18:04:05 -08001906 public void pokeDrawLockLw(long timeout) {
1907 if (isVisibleOrAdding()) {
1908 if (mDrawLock == null) {
1909 // We want the tag name to be somewhat stable so that it is easier to correlate
1910 // in wake lock statistics. So in particular, we don't want to include the
1911 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07001912 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08001913 mDrawLock = mService.mPowerManager.newWakeLock(
1914 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
1915 mDrawLock.setReferenceCounted(false);
1916 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
1917 }
1918 // Each call to acquire resets the timeout.
1919 if (DEBUG_POWER) {
1920 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
1921 + mAttrs.packageName);
1922 }
1923 mDrawLock.acquire(timeout);
1924 } else if (DEBUG_POWER) {
1925 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
1926 + "owned by " + mAttrs.packageName);
1927 }
1928 }
1929
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001930 @Override
1931 public boolean isAlive() {
1932 return mClient.asBinder().isBinderAlive();
1933 }
1934
Craig Mautnera987d432012-10-11 14:07:58 -07001935 boolean isClosing() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001936 return mAnimatingExit || (mService.mClosingApps.contains(mAppToken));
Craig Mautnera987d432012-10-11 14:07:58 -07001937 }
1938
Chong Zhangbef461f2015-10-27 11:38:24 -07001939 boolean isAnimatingWithSavedSurface() {
1940 return mAppToken != null && mAppToken.mAnimatingWithSavedSurface;
1941 }
1942
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001943 private boolean shouldSaveSurface() {
Chong Zhang6c71c0b2016-04-01 15:10:31 -07001944 if (mWinAnimator.mSurfaceController == null) {
1945 // Don't bother if the surface controller is gone for any reason.
1946 return false;
1947 }
1948
Wale Ogunwale945d1972016-03-23 13:16:41 -07001949 if ((mAttrs.flags & FLAG_SECURE) != 0) {
1950 // We don't save secure surfaces since their content shouldn't be shown while the app
1951 // isn't on screen and content might leak through during the transition animation with
1952 // saved surface.
1953 return false;
1954 }
1955
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001956 if (ActivityManager.isLowRamDeviceStatic()) {
1957 // Don't save surfaces on Svelte devices.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001958 return false;
1959 }
1960
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001961 Task task = getTask();
1962 if (task == null || task.inHomeStack()) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001963 // Don't save surfaces for home stack apps. These usually resume and draw
1964 // first frame very fast. Saving surfaces are mostly a waste of memory.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001965 return false;
Chong Zhangdb20b5f2015-10-23 14:01:43 -07001966 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001967
1968 final AppWindowToken taskTop = task.getTopVisibleAppToken();
1969 if (taskTop != null && taskTop != mAppToken) {
1970 // Don't save if the window is not the topmost window.
1971 return false;
1972 }
1973
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001974 if (mResizedWhileGone) {
1975 // Somebody resized our window while we were gone for layout, which means that the
1976 // client got an old size, so we have an outdated surface here.
1977 return false;
1978 }
1979
Robert Carr7098dbd2016-02-01 12:31:01 -08001980 if (DEBUG_DISABLE_SAVING_SURFACES) {
1981 return false;
1982 }
1983
Chong Zhangeb22e8e2016-01-20 19:52:22 -08001984 return mAppToken.shouldSaveSurface();
1985 }
1986
1987 void destroyOrSaveSurface() {
1988 mSurfaceSaved = shouldSaveSurface();
1989 if (mSurfaceSaved) {
1990 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
1991 Slog.v(TAG, "Saving surface: " + this);
1992 }
1993
1994 mWinAnimator.hide("saved surface");
1995 mWinAnimator.mDrawState = WindowStateAnimator.NO_SURFACE;
1996 setHasSurface(false);
Chong Zhang47e36a32016-02-29 16:44:33 -08001997 // The client should have disconnected at this point, but if it doesn't,
1998 // we need to make sure it's disconnected. Otherwise when we reuse the surface
1999 // the client can't reconnect to the buffer queue, and rendering will fail.
2000 if (mWinAnimator.mSurfaceController != null) {
2001 mWinAnimator.mSurfaceController.disconnectInTransaction();
2002 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002003 } else {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002004 mWinAnimator.destroySurfaceLocked();
2005 }
Robert Carr13f7be9e2015-12-02 18:39:45 -08002006 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002007
Robert Carr13f7be9e2015-12-02 18:39:45 -08002008 public void destroySavedSurface() {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002009 if (mSurfaceSaved) {
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002010 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2011 Slog.v(TAG, "Destroying saved surface: " + this);
2012 }
Robert Carr13f7be9e2015-12-02 18:39:45 -08002013 mWinAnimator.destroySurfaceLocked();
2014 }
2015 }
2016
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002017 public void restoreSavedSurface() {
Chong Zhang4113ffa2016-02-18 12:39:13 -08002018 if (!mSurfaceSaved) {
2019 return;
2020 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002021 mSurfaceSaved = false;
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002022 if (mWinAnimator.mSurfaceController != null) {
2023 setHasSurface(true);
2024 mWinAnimator.mDrawState = WindowStateAnimator.READY_TO_SHOW;
2025
2026 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2027 Slog.v(TAG, "Restoring saved surface: " + this);
2028 }
2029 } else {
2030 // mSurfaceController shouldn't be null if mSurfaceSaved was still true at
2031 // this point. Even if we destroyed the saved surface because of rotation
2032 // or resize, mSurfaceSaved flag should have been cleared. So this is a wtf.
2033 Slog.wtf(TAG, "Failed to restore saved surface: surface gone! " + this);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002034 }
2035 }
2036
Robert Carr13f7be9e2015-12-02 18:39:45 -08002037 public boolean hasSavedSurface() {
2038 return mSurfaceSaved;
2039 }
2040
Craig Mautner69b08182012-09-05 13:07:13 -07002041 @Override
2042 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002043 final DisplayContent displayContent = getDisplayContent();
2044 if (displayContent == null) {
2045 // Only a window that was on a non-default display can be detached from it.
2046 return false;
2047 }
Winson Chung47a3e652014-05-21 16:03:42 -07002048 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002049 }
2050
Adrian Rooscd3884d2015-02-18 17:25:23 +01002051 @Override
2052 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002053 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
2054 return dimLayerUser != null && mDisplayContent != null &&
Chong Zhang112eb8c2015-11-02 11:17:00 -08002055 mDisplayContent.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01002056 }
2057
Craig Mautner88400d32012-09-30 12:35:45 -07002058 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
2059 mShowToOwnerOnly = showToOwnerOnly;
2060 }
2061
Craig Mautner5962b122012-10-05 14:45:52 -07002062 boolean isHiddenFromUserLocked() {
Craig Mautner341220f2012-10-16 15:20:09 -07002063 // Attached windows are evaluated based on the window that they are attached to.
2064 WindowState win = this;
Robert Carr51a1b872015-12-08 14:03:13 -08002065 while (win.isChildWindow()) {
Craig Mautner341220f2012-10-16 15:20:09 -07002066 win = win.mAttachedWindow;
2067 }
2068 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -07002069 && win.mAppToken != null && win.mAppToken.showForAllUsers) {
Craig Mautner341220f2012-10-16 15:20:09 -07002070 // Save some cycles by not calling getDisplayInfo unless it is an application
2071 // window intended for all users.
Craig Mautnerdf88d732014-01-27 09:21:32 -08002072 final DisplayContent displayContent = win.getDisplayContent();
2073 if (displayContent == null) {
2074 return true;
2075 }
2076 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Craig Mautner341220f2012-10-16 15:20:09 -07002077 if (win.mFrame.left <= 0 && win.mFrame.top <= 0
2078 && win.mFrame.right >= displayInfo.appWidth
2079 && win.mFrame.bottom >= displayInfo.appHeight) {
Craig Mautner5962b122012-10-05 14:45:52 -07002080 // Is a fullscreen window, like the clock alarm. Show to everyone.
2081 return false;
2082 }
2083 }
2084
Craig Mautner341220f2012-10-16 15:20:09 -07002085 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01002086 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002087 }
2088
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002089 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2090 outRegion.set(
2091 frame.left + inset.left, frame.top + inset.top,
2092 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002093 }
2094
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002095 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002096 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002097 switch (mTouchableInsets) {
2098 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002099 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002100 outRegion.set(frame);
2101 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002102 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002103 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002104 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002105 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002106 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002107 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002108 case TOUCHABLE_INSETS_REGION: {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002109 final Region givenTouchableRegion = mGivenTouchableRegion;
2110 outRegion.set(givenTouchableRegion);
2111 outRegion.translate(frame.left, frame.top);
2112 break;
2113 }
2114 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002115 cropRegionToStackBoundsIfNeeded(outRegion);
2116 }
2117
2118 void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002119 final Task task = getTask();
2120 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002121 return;
2122 }
2123
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002124 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002125 if (stack == null) {
2126 return;
2127 }
2128
2129 stack.getDimBounds(mTmpRect);
2130 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002131 }
2132
Craig Mautner59c00972012-07-30 12:10:24 -07002133 WindowList getWindowList() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002134 final DisplayContent displayContent = getDisplayContent();
2135 return displayContent == null ? null : displayContent.getWindowList();
Craig Mautner59c00972012-07-30 12:10:24 -07002136 }
2137
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002138 /**
2139 * Report a focus change. Must be called with no locks held, and consistently
2140 * from the same serialized thread (such as dispatched from a handler).
2141 */
2142 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
2143 try {
2144 mClient.windowFocusChanged(focused, inTouchMode);
2145 } catch (RemoteException e) {
2146 }
2147 if (mFocusCallbacks != null) {
2148 final int N = mFocusCallbacks.beginBroadcast();
2149 for (int i=0; i<N; i++) {
2150 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2151 try {
2152 if (focused) {
2153 obs.focusGained(mWindowId.asBinder());
2154 } else {
2155 obs.focusLost(mWindowId.asBinder());
2156 }
2157 } catch (RemoteException e) {
2158 }
2159 }
2160 mFocusCallbacks.finishBroadcast();
2161 }
2162 }
2163
Robert Carrc24d8f92016-02-29 16:24:33 -08002164 /**
2165 * Update our current configurations, based on task configuration.
2166 *
2167 * @return A configuration suitable for sending to the client.
2168 */
2169 private Configuration updateConfiguration() {
2170 final Task task = getTask();
2171 final Configuration overrideConfig =
2172 (task != null) ? task.mOverrideConfig : Configuration.EMPTY;
2173 final boolean configChanged = isConfigChanged();
2174 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) && configChanged) {
2175 Slog.i(TAG, "Sending new config to window " + this + ": " +
2176 " / config=" + mService.mCurConfiguration + " overrideConfig=" + overrideConfig);
2177 }
2178 setConfiguration(mService.mCurConfiguration, overrideConfig);
2179 return mMergedConfiguration;
2180 }
2181
Craig Mautnerdf88d732014-01-27 09:21:32 -08002182 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002183 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08002184 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002185 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
2186 + ": " + mCompatFrame);
Robert Carrc24d8f92016-02-29 16:24:33 -08002187 final Configuration newConfig = isConfigChanged() ? updateConfiguration() : null;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002188 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING)
2189 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
2190
Craig Mautnerdf88d732014-01-27 09:21:32 -08002191 final Rect frame = mFrame;
2192 final Rect overscanInsets = mLastOverscanInsets;
2193 final Rect contentInsets = mLastContentInsets;
2194 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07002195 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002196 final Rect outsets = mLastOutsets;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002197 final boolean reportDraw = mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING;
Chet Haase8eb48d22014-09-24 07:31:29 -07002198 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
2199 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002200 // To prevent deadlock simulate one-way call if win.mClient is a local object.
2201 mService.mH.post(new Runnable() {
2202 @Override
2203 public void run() {
2204 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002205 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
2206 stableInsets, outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002207 } catch (RemoteException e) {
2208 // Not a remote call, RemoteException won't be raised.
2209 }
2210 }
2211 });
2212 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002213 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002214 outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002215 }
Svetoslav4604abc2014-06-10 18:59:30 -07002216
2217 //TODO (multidisplay): Accessibility supported only for the default display.
2218 if (mService.mAccessibilityController != null
2219 && getDisplayId() == Display.DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07002220 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07002221 }
2222
Craig Mautnerdf88d732014-01-27 09:21:32 -08002223 mOverscanInsetsChanged = false;
2224 mContentInsetsChanged = false;
2225 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07002226 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002227 mOutsetsChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08002228 mWinAnimator.mSurfaceResized = false;
2229 } catch (RemoteException e) {
2230 mOrientationChanging = false;
2231 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2232 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08002233 // We are assuming the hosting process is dead or in a zombie state.
2234 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
2235 + ", removing this window.");
2236 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002237 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002238 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002239 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002240 }
2241
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002242 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08002243 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
2244 // start even if we haven't received the relayout window, so that the client requests
2245 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
2246 // until the window to small size, otherwise the multithread renderer will shift last
2247 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
2248 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002249 boolean resizing = isDragResizing() || isDragResizeChanged();
2250 if (StackId.useWindowFrameForBackdrop(getStackId()) || !resizing) {
2251 return frame;
2252 }
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002253 DisplayInfo displayInfo = getDisplayInfo();
2254 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002255 return mTmpRect;
2256 }
2257
Jorim Jaggi86905582016-02-09 21:36:09 -08002258 @Override
2259 public int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002260 final TaskStack stack = getStack();
2261 if (stack == null) {
2262 return INVALID_STACK_ID;
2263 }
2264 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002265 }
2266
2267 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
2268 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
2269 Configuration newConfig) throws RemoteException {
Chong Zhangedaf3052016-04-22 15:04:31 -07002270 final boolean forceRelayout = isDragResizeChanged() || mResizedWhileNotDragResizing;
2271
Jorim Jaggidc249c42015-12-15 14:57:31 -08002272 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Jorim Jaggia4a58ef2016-01-27 02:10:08 -08002273 reportDraw, newConfig, getBackdropFrame(frame),
Chong Zhangedaf3052016-04-22 15:04:31 -07002274 forceRelayout, mPolicy.isNavBarForcedShownLw(this));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002275 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002276 }
2277
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002278 public void registerFocusObserver(IWindowFocusObserver observer) {
2279 synchronized(mService.mWindowMap) {
2280 if (mFocusCallbacks == null) {
2281 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
2282 }
2283 mFocusCallbacks.register(observer);
2284 }
2285 }
2286
2287 public void unregisterFocusObserver(IWindowFocusObserver observer) {
2288 synchronized(mService.mWindowMap) {
2289 if (mFocusCallbacks != null) {
2290 mFocusCallbacks.unregister(observer);
2291 }
2292 }
2293 }
2294
2295 public boolean isFocused() {
2296 synchronized(mService.mWindowMap) {
2297 return mService.mCurrentFocus == this;
2298 }
2299 }
2300
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07002301 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07002302 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07002303 return task != null && task.inFreeformWorkspace();
2304 }
2305
Wale Ogunwale9185fb02016-03-11 18:06:14 -08002306 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07002307 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08002308 final Task task = getTask();
2309 return task != null && !task.isFullscreen();
2310 }
2311
Chong Zhang3005e752015-09-18 18:46:28 -07002312 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002313 return mDragResizing != computeDragResizing();
2314 }
2315
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002316 /**
2317 * @return Whether we reported a drag resize change to the application or not already.
2318 */
2319 boolean isDragResizingChangeReported() {
2320 return mDragResizingChangeReported;
2321 }
2322
2323 /**
2324 * Resets the state whether we reported a drag resize change to the app.
2325 */
2326 void resetDragResizingChangeReported() {
2327 mDragResizingChangeReported = false;
2328 }
2329
Jorim Jaggidcf467c2015-11-05 13:59:32 +01002330 int getResizeMode() {
2331 return mResizeMode;
2332 }
2333
Jorim Jaggi192086e2016-03-11 17:17:03 +01002334 boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07002335 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002336 if (task == null) {
2337 return false;
2338 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08002339 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
2340
2341 // Floating windows never enter drag resize mode.
2342 return false;
2343 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002344 if (task.isDragResizing()) {
2345 return true;
2346 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01002347
2348 // If the bounds are currently frozen, it means that the layout size that the app sees
2349 // and the bounds we clip this window to might be different. In order to avoid holes, we
2350 // simulate that we are still resizing so the app fills the hole with the resizing
2351 // background.
2352 return (mDisplayContent.mDividerControllerLocked.isResizing()
2353 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Jorim Jaggi899327f2016-02-25 20:44:18 -05002354 !task.inFreeformWorkspace() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08002355
Chong Zhang3005e752015-09-18 18:46:28 -07002356 }
2357
2358 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002359 final boolean resizing = computeDragResizing();
2360 if (resizing == mDragResizing) {
2361 return;
2362 }
2363 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01002364 final Task task = getTask();
2365 if (task != null && task.isDragResizing()) {
2366 mResizeMode = task.getDragResizeMode();
2367 } else {
2368 mResizeMode = mDragResizing && mDisplayContent.mDividerControllerLocked.isResizing()
2369 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
2370 : DRAG_RESIZE_MODE_FREEFORM;
2371 }
Chong Zhang3005e752015-09-18 18:46:28 -07002372 }
2373
2374 boolean isDragResizing() {
2375 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07002376 }
2377
Robert Carr2487ce72016-04-07 15:18:45 -07002378 boolean isDockedResizing() {
2379 return mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
2380 }
2381
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002382 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08002383 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002384 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08002385 if (stack != null) {
2386 pw.print(" stackId="); pw.print(stack.mStackId);
2387 }
Wale Ogunwale4c5aa5172016-04-19 11:29:05 -07002388 if (mNotOnAppsDisplay) {
2389 pw.print(" mNotOnAppsDisplay="); pw.print(mNotOnAppsDisplay);
2390 }
Craig Mautner59c00972012-07-30 12:10:24 -07002391 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002392 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07002393 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08002394 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
2395 pw.print(" package="); pw.print(mAttrs.packageName);
2396 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002397 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002398 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
2399 pw.print(" h="); pw.print(mRequestedHeight);
2400 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07002401 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
2402 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
2403 pw.print(" h="); pw.println(mLastRequestedHeight);
2404 }
Robert Carr51a1b872015-12-08 14:03:13 -08002405 if (isChildWindow() || mLayoutAttached) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002406 pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
2407 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
2408 }
2409 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
2410 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
2411 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
2412 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
2413 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
2414 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002415 if (dumpAll) {
2416 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
2417 pw.print(" mSubLayer="); pw.print(mSubLayer);
2418 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautner59431632012-04-04 11:56:44 -07002419 pw.print((mTargetAppToken != null ?
2420 mTargetAppToken.mAppAnimator.animLayerAdjustment
2421 : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002422 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
2423 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08002424 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002425 if (dumpAll) {
2426 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
2427 pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
2428 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07002429 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
2430 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08002431 pw.print(isAnimatingWithSavedSurface());
Chong Zhang112eb8c2015-11-02 11:17:00 -08002432 pw.print(" mAppDied=");pw.println(mAppDied);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002433 }
2434 if (mTargetAppToken != null) {
2435 pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
2436 }
2437 pw.print(prefix); pw.print("mViewVisibility=0x");
2438 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002439 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
2440 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07002441 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
2442 pw.print(" mSystemUiVisibility=0x");
2443 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002444 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002445 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
2446 || mAttachedHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002447 pw.print(prefix); pw.print("mPolicyVisibility=");
2448 pw.print(mPolicyVisibility);
2449 pw.print(" mPolicyVisibilityAfterAnim=");
2450 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002451 pw.print(" mAppOpVisibility=");
2452 pw.print(mAppOpVisibility);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002453 pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
2454 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08002455 if (!mRelayoutCalled || mLayoutNeeded) {
2456 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
2457 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002458 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002459 if (mXOffset != 0 || mYOffset != 0) {
2460 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
2461 pw.print(" y="); pw.println(mYOffset);
2462 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002463 if (dumpAll) {
2464 pw.print(prefix); pw.print("mGivenContentInsets=");
2465 mGivenContentInsets.printShortString(pw);
2466 pw.print(" mGivenVisibleInsets=");
2467 mGivenVisibleInsets.printShortString(pw);
2468 pw.println();
2469 if (mTouchableInsets != 0 || mGivenInsetsPending) {
2470 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
2471 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07002472 Region region = new Region();
2473 getTouchableRegion(region);
2474 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002475 }
2476 pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
Wale Ogunwale7c726682015-02-06 17:34:28 -08002477 if (mOverrideConfig != Configuration.EMPTY) {
2478 pw.print(prefix); pw.print("mOverrideConfig="); pw.println(mOverrideConfig);
2479 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002480 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07002481 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07002482 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Chong Zhanga8975bd2016-01-28 17:13:47 -08002483 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08002484 pw.print(" hasSavedSurface()="); pw.print(hasSavedSurface());
2485 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002486 if (dumpAll) {
2487 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
2488 pw.print(" last="); mLastFrame.printShortString(pw);
2489 pw.println();
2490 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002491 if (mEnforceSizeCompat) {
2492 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002493 pw.println();
2494 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002495 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002496 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002497 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002498 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002499 pw.println();
2500 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
2501 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002502 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002503 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002504 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002505 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04002506 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
2507 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002508 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
2509 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002510 pw.print(prefix); pw.print("Cur insets: overscan=");
2511 mOverscanInsets.printShortString(pw);
2512 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002513 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002514 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07002515 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002516 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002517 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002518 pw.print(prefix); pw.print("Lst insets: overscan=");
2519 mLastOverscanInsets.printShortString(pw);
2520 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002521 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002522 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002523 pw.print(" physical="); mLastOutsets.printShortString(pw);
2524 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002525 pw.println();
2526 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07002527 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
2528 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002529 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
2530 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002531 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
2532 pw.print(" mDestroying="); pw.print(mDestroying);
2533 pw.print(" mRemoved="); pw.println(mRemoved);
2534 }
2535 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
2536 pw.print(prefix); pw.print("mOrientationChanging=");
2537 pw.print(mOrientationChanging);
2538 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
2539 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
2540 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07002541 if (mLastFreezeDuration != 0) {
2542 pw.print(prefix); pw.print("mLastFreezeDuration=");
2543 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
2544 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002545 if (mHScale != 1 || mVScale != 1) {
2546 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
2547 pw.print(" mVScale="); pw.println(mVScale);
2548 }
2549 if (mWallpaperX != -1 || mWallpaperY != -1) {
2550 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
2551 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
2552 }
2553 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
2554 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
2555 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
2556 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07002557 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
2558 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
2559 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
2560 pw.print(mWallpaperDisplayOffsetX);
2561 pw.print(" mWallpaperDisplayOffsetY=");
2562 pw.println(mWallpaperDisplayOffsetY);
2563 }
Jeff Brownc2932a12014-11-20 18:04:05 -08002564 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07002565 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08002566 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08002567 if (isDragResizing()) {
2568 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
2569 }
2570 if (computeDragResizing()) {
2571 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
2572 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002573 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002574
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002575 String makeInputChannelName() {
2576 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002577 + " " + getWindowTag();
2578 }
2579
Robert Carra1eb4392015-12-10 12:43:51 -08002580 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002581 CharSequence tag = mAttrs.getTitle();
2582 if (tag == null || tag.length() <= 0) {
2583 tag = mAttrs.packageName;
2584 }
2585 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002586 }
2587
2588 @Override
2589 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002590 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002591 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08002592 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002593 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002594 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn5fe7e2a2012-10-04 11:58:16 -07002595 + " u" + UserHandle.getUserId(mSession.mUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002596 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002597 }
2598 return mStringNameCache;
2599 }
Robert Carr58f29132015-10-29 14:19:05 -07002600
2601 void transformFromScreenToSurfaceSpace(Rect rect) {
2602 if (mHScale >= 0) {
Chong Zhang84389572016-01-13 10:33:27 -08002603 rect.left = (int) (rect.left / mHScale);
2604 rect.right = (int) (rect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07002605 }
2606 if (mVScale >= 0) {
Chong Zhang84389572016-01-13 10:33:27 -08002607 rect.top = (int) (rect.top / mVScale);
2608 rect.bottom = (int) (rect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07002609 }
2610 }
Robert Carr31e28482015-12-02 16:53:18 -08002611
Jorim Jaggif5834272016-04-04 20:25:41 -07002612 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
2613 final int pw = containingFrame.width();
2614 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08002615 final Task task = getTask();
Andrii Kulian933076d2016-03-29 17:04:42 -07002616 final boolean nonFullscreenTask = isInMultiWindowMode();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07002617 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
2618
2619 // We need to fit it to the display if either
2620 // a) The task is fullscreen, or we don't have a task (we assume fullscreen for the taskless
2621 // windows)
2622 // b) If it's a child window, we also need to fit it to the display unless
2623 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popup and similar windows on screen,
2624 // but SurfaceViews want to be always at a specific location so we don't fit it to the
2625 // display.
2626 final boolean fitToDisplay = (task == null || !nonFullscreenTask)
2627 || (isChildWindow() && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08002628 float x, y;
2629 int w,h;
2630
2631 if ((mAttrs.flags & FLAG_SCALED) != 0) {
2632 if (mAttrs.width < 0) {
2633 w = pw;
2634 } else if (mEnforceSizeCompat) {
2635 w = (int)(mAttrs.width * mGlobalScale + .5f);
2636 } else {
2637 w = mAttrs.width;
2638 }
2639 if (mAttrs.height < 0) {
2640 h = ph;
2641 } else if (mEnforceSizeCompat) {
2642 h = (int)(mAttrs.height * mGlobalScale + .5f);
2643 } else {
2644 h = mAttrs.height;
2645 }
2646 } else {
2647 if (mAttrs.width == MATCH_PARENT) {
2648 w = pw;
2649 } else if (mEnforceSizeCompat) {
2650 w = (int)(mRequestedWidth * mGlobalScale + .5f);
2651 } else {
2652 w = mRequestedWidth;
2653 }
2654 if (mAttrs.height == MATCH_PARENT) {
2655 h = ph;
2656 } else if (mEnforceSizeCompat) {
2657 h = (int)(mRequestedHeight * mGlobalScale + .5f);
2658 } else {
2659 h = mRequestedHeight;
2660 }
2661 }
2662
2663 if (mEnforceSizeCompat) {
2664 x = mAttrs.x * mGlobalScale;
2665 y = mAttrs.y * mGlobalScale;
2666 } else {
2667 x = mAttrs.x;
2668 y = mAttrs.y;
2669 }
2670
Robert Carr1d2bacb2016-03-30 14:29:35 -07002671 if (nonFullscreenTask && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08002672 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08002673 // required by {@link Gravity#apply} call.
2674 w = Math.min(w, pw);
2675 h = Math.min(h, ph);
2676 }
2677
2678 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07002679 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08002680 (int) (x + mAttrs.horizontalMargin * pw),
2681 (int) (y + mAttrs.verticalMargin * ph), mFrame);
2682
2683 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08002684 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07002685 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08002686 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08002687
2688 // We need to make sure we update the CompatFrame as it is used for
2689 // cropping decisions, etc, on systems where we lack a decor layer.
2690 mCompatFrame.set(mFrame);
2691 if (mEnforceSizeCompat) {
2692 // See comparable block in computeFrameLw.
2693 mCompatFrame.scale(mInvGlobalScale);
2694 }
Robert Carr31e28482015-12-02 16:53:18 -08002695 }
Robert Carr51a1b872015-12-08 14:03:13 -08002696
2697 boolean isChildWindow() {
2698 return mAttachedWindow != null;
2699 }
Robert Carra1eb4392015-12-10 12:43:51 -08002700
Robert Carrf3b72c72016-03-21 18:16:39 -07002701 boolean layoutInParentFrame() {
2702 return isChildWindow() && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
2703 }
2704
Robert Carra1eb4392015-12-10 12:43:51 -08002705 void setReplacing(boolean animate) {
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08002706 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
2707 || mAttrs.type == TYPE_APPLICATION_STARTING) {
2708 // We don't set replacing on starting windows since they are added by window manager and
2709 // not the client so won't be replaced by the client.
2710 return;
Robert Carra1eb4392015-12-10 12:43:51 -08002711 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08002712
2713 mWillReplaceWindow = true;
2714 mReplacingWindow = null;
2715 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08002716 }
Chong Zhangf596cd52016-01-05 13:42:44 -08002717
2718 void resetReplacing() {
2719 mWillReplaceWindow = false;
2720 mReplacingWindow = null;
2721 mAnimateReplacingWindow = false;
2722 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08002723
2724 float translateToWindowX(float x) {
2725 float winX = x - mFrame.left;
2726 if (mEnforceSizeCompat) {
2727 winX *= mGlobalScale;
2728 }
2729 return winX;
2730 }
2731
2732 float translateToWindowY(float y) {
2733 float winY = y - mFrame.top;
2734 if (mEnforceSizeCompat) {
2735 winY *= mGlobalScale;
2736 }
2737 return winY;
2738 }
Robert Carrd1a010f2016-04-07 22:36:22 -07002739
Robert Carr9fe459d2016-04-07 23:32:28 -07002740 void transferDimToReplacement() {
2741 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
2742 if (dimLayerUser != null && mDisplayContent != null) {
2743 mDisplayContent.mDimLayerController.applyDim(dimLayerUser,
2744 mReplacingWindow.mWinAnimator,
2745 (mAttrs.flags & FLAG_DIM_BEHIND) != 0 ? true : false);
2746 }
2747 }
2748
Robert Carrd1a010f2016-04-07 22:36:22 -07002749 // During activity relaunch due to resize, we sometimes use window replacement
2750 // for only child windows (as the main window is handled by window preservation)
2751 // and the big surface.
2752 //
2753 // Though windows of TYPE_APPLICATION (as opposed to TYPE_BASE_APPLICATION)
2754 // are not children in the sense of an attached window, we also want to replace
2755 // them at such phases, as they won't be covered by window preservation,
2756 // and in general we expect them to return following relaunch.
2757 boolean shouldBeReplacedWithChildren() {
2758 return isChildWindow() || mAttrs.type == TYPE_APPLICATION;
2759 }
satokcef37fb2011-10-24 21:49:38 +09002760}