blob: 746ae0ff3fcfeeaa5e3c46a1f1dbe66b4f7f33ea [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;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -070028import android.os.Binder;
Wale Ogunwale9d147902016-07-16 11:58:55 -070029import android.os.Debug;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080030import android.os.IBinder;
31import android.os.PowerManager;
32import android.os.RemoteCallbackList;
33import android.os.RemoteException;
34import android.os.SystemClock;
35import android.os.Trace;
36import android.os.UserHandle;
37import android.os.WorkSource;
38import android.util.DisplayMetrics;
39import android.util.Slog;
40import android.util.TimeUtils;
41import android.view.Display;
42import android.view.DisplayInfo;
43import android.view.Gravity;
44import android.view.IApplicationToken;
45import android.view.IWindow;
46import android.view.IWindowFocusObserver;
47import android.view.IWindowId;
48import android.view.InputChannel;
49import android.view.InputEvent;
50import android.view.InputEventReceiver;
51import android.view.View;
52import android.view.ViewTreeObserver;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -070053import android.view.WindowInfo;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080054import android.view.WindowManager;
55import android.view.WindowManagerPolicy;
56
Jorim Jaggi9511b0f2016-01-29 19:12:44 -080057import com.android.server.input.InputWindowHandle;
58
Wale Ogunwale053c8e42015-11-16 14:27:21 -080059import java.io.PrintWriter;
60import java.util.ArrayList;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -070061import java.util.Comparator;
62import java.util.LinkedList;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080063
Wale Ogunwaled045c822015-12-02 09:14:28 -080064import static android.app.ActivityManager.StackId;
Wale Ogunwalea9f9b372016-02-04 18:04:39 -080065import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
Filip Gruszczynski84fa3352016-01-25 16:28:49 -080066import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
Wale Ogunwalecad05a02015-09-25 10:41:44 -070067import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -070068import static android.view.Display.DEFAULT_DISPLAY;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080069import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
70import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
71import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
72import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080073import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080074import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Filip Gruszczynski4501d232015-09-02 13:00:02 -070075import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080076import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Jorim Jaggi5f23a572016-04-22 15:05:50 -070077import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
Wale Ogunwale053c8e42015-11-16 14:27:21 -080078import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
79import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080080import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Wale Ogunwale945d1972016-03-23 13:16:41 -070081import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
Chong Zhang4d7369a2016-04-25 16:09:14 -070082import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -070083import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080084import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080085import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
Robert Carr31e28482015-12-02 16:53:18 -080086import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080087import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080088import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -080089import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
Robert Carra1eb4392015-12-10 12:43:51 -080090import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080091import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
92import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
Robert Carrd1a010f2016-04-07 22:36:22 -070093import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080094import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080095import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070096import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080097import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
98import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
99import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Chong Zhang4d7369a2016-04-25 16:09:14 -0700100import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700101import static android.view.WindowManagerPolicy.TRANSIT_EXIT;
102import static android.view.WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100103import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
104import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800105import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
106import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
107import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
108import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -0700109import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800110import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700111import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800112import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
113import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
114import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
115import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700116import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
117import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SURFACE_TRACE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800118import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -0700119import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700120import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800121import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
122import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700123import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700124import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
125import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700126import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
127import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
128import static com.android.server.wm.WindowManagerService.localLOGV;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700129import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING;
130import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN;
131import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800132
Craig Mautner59c00972012-07-30 12:10:24 -0700133class WindowList extends ArrayList<WindowState> {
Wale Ogunwale33fde7d2016-03-05 22:38:51 -0800134 WindowList() {}
135 WindowList(WindowList windowList) {
136 super(windowList);
137 }
Craig Mautner59c00972012-07-30 12:10:24 -0700138}
139
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800140/**
141 * A window in the window manager.
142 */
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700143class WindowState extends WindowContainer implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800144 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800145
Skuhne81c524a2015-08-12 13:34:14 -0700146 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700147 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
148 // use hard-coded min sizes for now.
149 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
150 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700151
152 // The thickness of a window resize handle outside the window bounds on the free form workspace
153 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700154 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700155
Robert Carr7098dbd2016-02-01 12:31:01 -0800156 static final boolean DEBUG_DISABLE_SAVING_SURFACES = false;
157
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800158 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700159 final WindowManagerPolicy mPolicy;
160 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800161 final Session mSession;
162 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800163 final int mAppOp;
164 // UserId and appId of the owner. Don't display windows of non-current user.
165 final int mOwnerUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800166 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800167 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700168 // The same object as mToken if this is an app window and null for non-app windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800169 AppWindowToken mAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700170
171 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
172 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800173 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
174 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700175 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800176 final int mBaseLayer;
177 final int mSubLayer;
178 final boolean mLayoutAttached;
179 final boolean mIsImWindow;
180 final boolean mIsWallpaper;
181 final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700182 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700183 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800184 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700185 int mSystemUiVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800186 boolean mPolicyVisibility = true;
187 boolean mPolicyVisibilityAfterAnim = true;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -0800188 boolean mAppOpVisibility = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800189 boolean mAppFreezing;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700190 boolean mHidden; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800191 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Chong Zhang0275e392015-09-17 10:41:44 -0700192 boolean mDragResizing;
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800193 boolean mDragResizingChangeReported;
Jorim Jaggidcf467c2015-11-05 13:59:32 +0100194 int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700195
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800196 RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
197
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700198 /**
199 * The window size that was requested by the application. These are in
200 * the application's coordinate space (without compatibility scale applied).
201 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800202 int mRequestedWidth;
203 int mRequestedHeight;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700204 int mLastRequestedWidth;
205 int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700206
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800207 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800208 boolean mHaveFrame;
209 boolean mObscured;
210 boolean mTurnOnScreen;
211
212 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700213
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700214 private final Configuration mTmpConfig = new Configuration();
Robert Carrc24d8f92016-02-29 16:24:33 -0800215 // Represents the changes from our override configuration applied
216 // to the global configuration. This is the only form of configuration
217 // which is suitable for delivery to the client.
218 private Configuration mMergedConfiguration = new Configuration();
Craig Mautnere8552142012-11-07 13:55:47 -0800219 // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned.
220 // Used only on {@link #TYPE_KEYGUARD}.
221 private boolean mConfigHasChanged;
Craig Mautnera2c77052012-03-26 12:14:43 -0700222
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700223 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700224 * Actual position of the surface shown on-screen (may be modified by animation). These are
225 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700226 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700227 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800228
229 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700230 * Insets that determine the actually visible area. These are in the application's
231 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800232 */
233 final Rect mVisibleInsets = new Rect();
234 final Rect mLastVisibleInsets = new Rect();
235 boolean mVisibleInsetsChanged;
236
237 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700238 * Insets that are covered by system windows (such as the status bar) and
239 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700240 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800241 */
242 final Rect mContentInsets = new Rect();
243 final Rect mLastContentInsets = new Rect();
244 boolean mContentInsetsChanged;
245
246 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800247 * Insets that determine the area covered by the display overscan region. These are in the
248 * application's coordinate space (without compatibility scale applied).
249 */
250 final Rect mOverscanInsets = new Rect();
251 final Rect mLastOverscanInsets = new Rect();
252 boolean mOverscanInsetsChanged;
253
254 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700255 * Insets that determine the area covered by the stable system windows. These are in the
256 * application's coordinate space (without compatibility scale applied).
257 */
258 final Rect mStableInsets = new Rect();
259 final Rect mLastStableInsets = new Rect();
260 boolean mStableInsetsChanged;
261
262 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700263 * Outsets determine the area outside of the surface where we want to pretend that it's possible
264 * to draw anyway.
265 */
266 final Rect mOutsets = new Rect();
267 final Rect mLastOutsets = new Rect();
268 boolean mOutsetsChanged = false;
269
270 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800271 * Set to true if we are waiting for this window to receive its
272 * given internal insets before laying out other windows based on it.
273 */
274 boolean mGivenInsetsPending;
275
276 /**
277 * These are the content insets that were given during layout for
278 * this window, to be applied to windows behind it.
279 */
280 final Rect mGivenContentInsets = new Rect();
281
282 /**
283 * These are the visible insets that were given during layout for
284 * this window, to be applied to windows behind it.
285 */
286 final Rect mGivenVisibleInsets = new Rect();
287
288 /**
289 * This is the given touchable area relative to the window frame, or null if none.
290 */
291 final Region mGivenTouchableRegion = new Region();
292
293 /**
294 * Flag indicating whether the touchable region should be adjusted by
295 * the visible insets; if false the area outside the visible insets is
296 * NOT touchable, so we must use those to adjust the frame during hit
297 * tests.
298 */
299 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
300
301 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400302 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700303 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800304 float mHScale=1, mVScale=1;
305 float mLastHScale=1, mLastVScale=1;
306 final Matrix mTmpMatrix = new Matrix();
307
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700308 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800309 final Rect mFrame = new Rect();
310 final Rect mLastFrame = new Rect();
Robert Carr31aa98b2016-07-20 15:29:03 -0700311 boolean mFrameSizeChanged = false;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700312 // Frame that is scaled to the application's coordinate space when in
313 // screen size compatibility mode.
314 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800315
316 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700317
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800318 final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700319
Wale Ogunwale94596652015-02-06 19:27:34 -0800320 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
321 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700322 final Rect mDisplayFrame = new Rect();
323
324 // The region of the display frame that the display type supports displaying content on. This
325 // is mostly a special case for TV where some displays don’t have the entire display usable.
326 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
327 // window display contents to extend into the overscan region.
328 final Rect mOverscanFrame = new Rect();
329
330 // The display frame minus the stable insets. This value is always constant regardless of if
331 // the status bar or navigation bar is visible.
Adrian Roosfa104232014-06-20 16:10:14 -0700332 final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800333
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700334 // The area not occupied by the status and navigation bars. So, if both status and navigation
335 // bars are visible, the decor frame is equal to the stable frame.
336 final Rect mDecorFrame = new Rect();
337
338 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
339 // minus the area occupied by the IME if the IME is present.
340 final Rect mContentFrame = new Rect();
341
342 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
343 // displays hint text.
344 final Rect mVisibleFrame = new Rect();
345
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700346 // Frame that includes dead area outside of the surface but where we want to pretend that it's
347 // possible to draw.
348 final Rect mOutsetFrame = new Rect();
349
Jorim Jaggidc249c42015-12-15 14:57:31 -0800350 /**
351 * Usually empty. Set to the task's tempInsetFrame. See
352 *{@link android.app.IActivityManager#resizeDockedStack}.
353 */
354 final Rect mInsetFrame = new Rect();
355
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800356 boolean mContentChanged;
357
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800358 // If a window showing a wallpaper: the requested offset for the
359 // wallpaper; if a wallpaper window: the currently applied offset.
360 float mWallpaperX = -1;
361 float mWallpaperY = -1;
362
363 // If a window showing a wallpaper: what fraction of the offset
364 // range corresponds to a full virtual screen.
365 float mWallpaperXStep = -1;
366 float mWallpaperYStep = -1;
367
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700368 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
369 // to its window; if a wallpaper window: not used.
370 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
371 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
372
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800373 // Wallpaper windows: pixels offset based on above variables.
374 int mXOffset;
375 int mYOffset;
376
Craig Mautner2268e7e2012-12-13 15:40:00 -0800377 /**
378 * This is set after IWindowSession.relayout() has been called at
379 * least once for the window. It allows us to detect the situation
380 * where we don't yet have a surface, but should have one soon, so
381 * we can give the window focus before waiting for the relayout.
382 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800383 boolean mRelayoutCalled;
384
Robert Carrfed10072016-05-26 11:48:49 -0700385 boolean mInRelayout;
386
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800387 /**
388 * If the application has called relayout() with changes that can
389 * impact its window's size, we need to perform a layout pass on it
390 * even if it is not currently visible for layout. This is set
391 * when in that case until the layout is done.
392 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800393 boolean mLayoutNeeded;
394
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800395 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800396 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800397
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800398 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800399 boolean mDestroying;
400
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800401 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800402 boolean mRemoveOnExit;
403
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800404 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800405 * Whether the app died while it was visible, if true we might need
406 * to continue to show it until it's restarted.
407 */
408 boolean mAppDied;
409
410 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800411 * Set when the orientation is changing and this window has not yet
412 * been updated for the new orientation.
413 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800414 boolean mOrientationChanging;
415
Dianne Hackborna57c6952013-03-29 14:46:40 -0700416 /**
Robert Carr237028a2016-07-26 10:39:45 -0700417 * The orientation during the last visible call to relayout. If our
418 * current orientation is different, the window can't be ready
419 * to be shown.
420 */
421 int mLastVisibleLayoutRotation = -1;
422
423 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700424 * How long we last kept the screen frozen.
425 */
426 int mLastFreezeDuration;
427
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800428 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800429 boolean mRemoved;
430
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800431 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800432 * It is save to remove the window and destroy the surface because the client requested removal
433 * or some other higher level component said so (e.g. activity manager).
434 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800435 */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800436 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800437
438 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800439 * Temp for keeping track of windows that have been removed when
440 * rebuilding window list.
441 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800442 boolean mRebuilding;
443
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800444 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700445 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800446 InputChannel mInputChannel;
Chong Zhang112eb8c2015-11-02 11:17:00 -0800447 InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800448
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800449 // Used to improve performance of toString()
450 String mStringNameCache;
451 CharSequence mLastTitle;
Dianne Hackborn529e7442012-11-01 14:22:28 -0700452 boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800453
Craig Mautnera2c77052012-03-26 12:14:43 -0700454 final WindowStateAnimator mWinAnimator;
455
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700456 boolean mHasSurface = false;
457
Craig Mautner19ab8282014-05-07 10:35:34 -0700458 boolean mNotOnAppsDisplay = false;
Craig Mautner59c00972012-07-30 12:10:24 -0700459 DisplayContent mDisplayContent;
Craig Mautner6881a102012-07-27 13:04:51 -0700460
Craig Mautner88400d32012-09-30 12:35:45 -0700461 /** When true this window can be displayed on screens owther than mOwnerUid's */
462 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700463
Robert Carr13f7be9e2015-12-02 18:39:45 -0800464 // Whether the window has a saved surface from last pause, which can be
465 // used to start an entering animation earlier.
Chong Zhang92147042016-05-09 12:47:11 -0700466 private boolean mSurfaceSaved = false;
467
Chong Zhang8e4bda92016-05-04 15:08:18 -0700468 // Whether we're performing an entering animation with a saved surface. This flag is
469 // true during the time we're showing a window with a previously saved surface. It's
470 // cleared when surface is destroyed, saved, or re-drawn by the app.
Chong Zhang92147042016-05-09 12:47:11 -0700471 private boolean mAnimatingWithSavedSurface;
472
473 // Whether the window was visible when we set the app to invisible last time. WM uses
474 // this as a hint to restore the surface (if available) for early animation next time
475 // the app is brought visible.
476 boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800477
Robert Carra1eb4392015-12-10 12:43:51 -0800478 // This window will be replaced due to relaunch. This allows window manager
479 // to differentiate between simple removal of a window and replacement. In the latter case it
480 // will preserve the old window until the new one is drawn.
481 boolean mWillReplaceWindow = false;
482 // If true, the replaced window was already requested to be removed.
483 boolean mReplacingRemoveRequested = false;
484 // Whether the replacement of the window should trigger app transition animation.
485 boolean mAnimateReplacingWindow = false;
486 // If not null, the window that will be used to replace the old one. This is being set when
487 // the window is added and unset when this window reports its first draw.
488 WindowState mReplacingWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700489 // For the new window in the replacement transition, if we have
490 // requested to replace without animation, then we should
491 // make sure we also don't apply an enter animation for
492 // the new window.
493 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800494 // Whether this window is being moved via the resize API
495 boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800496
Jeff Brownc2932a12014-11-20 18:04:05 -0800497 /**
498 * Wake lock for drawing.
499 * Even though it's slightly more expensive to do so, we will use a separate wake lock
500 * for each app that is requesting to draw while dozing so that we can accurately track
501 * who is preventing the system from suspending.
502 * This lock is only acquired on first use.
503 */
504 PowerManager.WakeLock mDrawLock;
505
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700506 final private Rect mTmpRect = new Rect();
507
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800508 /**
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800509 * See {@link #notifyMovedInStack}.
510 */
511 private boolean mJustMovedInStack;
512
513 /**
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800514 * Whether the window was resized by us while it was gone for layout.
515 */
516 boolean mResizedWhileGone = false;
517
Andrii Kulianeb1d3222016-05-16 15:17:55 -0700518 /** @see #isResizedWhileNotDragResizing(). */
519 private boolean mResizedWhileNotDragResizing;
520
521 /** @see #isResizedWhileNotDragResizingReported(). */
522 private boolean mResizedWhileNotDragResizingReported;
Jorim Jaggif3df0aa2016-04-06 15:56:33 -0700523
Robert Carr6da3cc02016-06-16 15:17:07 -0700524 /**
525 * During seamless rotation we have two phases, first the old window contents
526 * are rotated to look as if they didn't move in the new coordinate system. Then we
527 * have to freeze updates to this layer (to preserve the transformation) until
528 * the resize actually occurs. This is true from when the transformation is set
529 * and false until the transaction to resize is sent.
530 */
531 boolean mSeamlesslyRotated = false;
532
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700533 /**
534 * Compares to window sub-layers and returns -1 if the first is lesser than the second in terms
535 * of z-order and 1 otherwise.
536 */
537 private static final Comparator<WindowContainer> sWindowSubLayerComparator = (w1, w2) -> {
538 final int layer1 = ((WindowState)w1).mSubLayer;
539 final int layer2 = ((WindowState)w2).mSubLayer;
540 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
541 // We insert the child window into the list ordered by the sub-layer.
542 // For same sub-layers, the negative one should go below others; the positive one should
543 // go above others.
544 return -1;
545 }
546 return 1;
547 };
548
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800549 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700550 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700551 int viewVisibility, final DisplayContent displayContent, int ownerId) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800552 mService = service;
553 mSession = s;
554 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800555 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800556 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700557 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700558 mOwnerUid = ownerId;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800559 mWindowId = new IWindowId.Stub() {
560 @Override
561 public void registerFocusObserver(IWindowFocusObserver observer) {
562 WindowState.this.registerFocusObserver(observer);
563 }
564 @Override
565 public void unregisterFocusObserver(IWindowFocusObserver observer) {
566 WindowState.this.unregisterFocusObserver(observer);
567 }
568 @Override
569 public boolean isFocused() {
570 return WindowState.this.isFocused();
571 }
572 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800573 mAttrs.copyFrom(a);
574 mViewVisibility = viewVisibility;
Craig Mautner59c00972012-07-30 12:10:24 -0700575 mDisplayContent = displayContent;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700576 mPolicy = mService.mPolicy;
577 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800578 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700579 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700580 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700581 if (localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700582 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700583 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800584 try {
585 c.asBinder().linkToDeath(deathRecipient, 0);
586 } catch (RemoteException e) {
587 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700588 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800589 mLayoutAttached = false;
590 mIsImWindow = false;
591 mIsWallpaper = false;
592 mIsFloatingLayer = false;
593 mBaseLayer = 0;
594 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700595 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700596 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800597 return;
598 }
599 mDeathRecipient = deathRecipient;
600
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700601 if ((mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW)) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800602 // The multiplier here is to reserve space for multiple
603 // windows in the same type layer.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700604 mBaseLayer = mPolicy.windowTypeToLayerLw(parentWindow.mAttrs.type)
605 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700606 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700607 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900608
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700609 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow);
610 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900611
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800612 mLayoutAttached = mAttrs.type !=
613 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700614 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
615 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
616 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800617 } else {
618 // The multiplier here is to reserve space for multiple
619 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700620 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700621 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800622 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700623 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800624 mLayoutAttached = false;
625 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
626 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
627 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800628 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700629 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800630
Craig Mautner19ab8282014-05-07 10:35:34 -0700631 if (mAppToken != null) {
632 final DisplayContent appDisplay = getDisplayContent();
633 mNotOnAppsDisplay = displayContent != appDisplay;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700634
635 if (mAppToken.showForAllUsers) {
636 // Windows for apps that can show for all users should also show when the
637 // device is locked.
638 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
639 }
Craig Mautner19ab8282014-05-07 10:35:34 -0700640 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800641
Craig Mautner322e4032012-07-13 13:35:20 -0700642 mWinAnimator = new WindowStateAnimator(this);
643 mWinAnimator.mAlpha = a.alpha;
644
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800645 mRequestedWidth = 0;
646 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700647 mLastRequestedWidth = 0;
648 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800649 mXOffset = 0;
650 mYOffset = 0;
651 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800652 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700653 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
654 displayContent.getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800655 }
656
657 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700658 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800659 mSession.windowAddedLocked();
660 }
661
Craig Mautnera2c77052012-03-26 12:14:43 -0700662 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800663 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800664 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800665 }
666
667 @Override
668 public String getOwningPackage() {
669 return mAttrs.packageName;
670 }
671
Jorim Jaggif5834272016-04-04 20:25:41 -0700672 /**
673 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
674 * from {@param frame}. In other words, it applies the insets that would result if
675 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700676 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
677 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700678 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700679 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
680 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
681 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
682 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
683 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700684 frame.inset(left, top, right, bottom);
685 }
686
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800687 @Override
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700688 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf, Rect sf,
689 Rect osf) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800690 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700691 // This window is being replaced and either already got information that it's being
692 // removed or we are still waiting for some information. Because of this we don't
693 // want to apply any more changes to it, so it remains in this state until new window
694 // appears.
695 return;
696 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800697 mHaveFrame = true;
698
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700699 final Task task = getTask();
Andrii Kulian933076d2016-03-29 17:04:42 -0700700 final boolean fullscreenTask = !isInMultiWindowMode();
Robert Carre6275582016-02-29 15:45:45 -0800701 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800702
Chong Zhangae35fef2016-03-16 15:56:55 -0700703 // If the task has temp inset bounds set, we have to make sure all its windows uses
704 // the temp inset frame. Otherwise different display frames get applied to the main
705 // window and the child window, making them misaligned.
706 if (fullscreenTask) {
707 mInsetFrame.setEmpty();
708 } else {
709 task.getTempInsetBounds(mInsetFrame);
710 }
711
Jorim Jaggif5834272016-04-04 20:25:41 -0700712 // Denotes the actual frame used to calculate the insets and to perform the layout. When
713 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
714 // insets temporarily. By the notion of a task having a different layout frame, we can
715 // achieve that while still moving the task around.
716 final Rect layoutContainingFrame;
717 final Rect layoutDisplayFrame;
718
719 // The offset from the layout containing frame to the actual containing frame.
720 final int layoutXDiff;
721 final int layoutYDiff;
Wale Ogunwale7cd4b012016-05-07 12:41:22 -0700722 if (fullscreenTask || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800723 // We use the parent frame as the containing frame for fullscreen and child windows
724 mContainingFrame.set(pf);
725 mDisplayFrame.set(df);
Jorim Jaggif5834272016-04-04 20:25:41 -0700726 layoutDisplayFrame = df;
727 layoutContainingFrame = pf;
728 layoutXDiff = 0;
729 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800730 } else {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700731 task.getBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100732 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
733
734 // If the bounds are frozen, we still want to translate the window freely and only
735 // freeze the size.
736 Rect frozen = mAppToken.mFrozenBounds.peek();
737 mContainingFrame.right = mContainingFrame.left + frozen.width();
738 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
739 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800740 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700741 // IME is up and obscuring this window. Adjust the window position so it is visible.
742 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this) {
743 if (windowsAreFloating && mContainingFrame.bottom > cf.bottom) {
744 // In freeform we want to move the top up directly.
745 // TODO: Investigate why this is cf not pf.
746 mContainingFrame.top -= mContainingFrame.bottom - cf.bottom;
747 } else if (mContainingFrame.bottom > pf.bottom) {
748 // But in docked we want to behave like fullscreen
749 // and behave as if the task were given smaller bounds
750 // for the purposes of layout.
751 mContainingFrame.bottom = pf.bottom;
752 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700753 }
Skuhne81c524a2015-08-12 13:34:14 -0700754
Robert Carre6275582016-02-29 15:45:45 -0800755 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700756 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
757 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800758 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700759 if (mContainingFrame.isEmpty()) {
760 mContainingFrame.set(cf);
761 }
Doris Liu06d582d2015-06-01 13:18:43 -0700762 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800763 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700764 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
765 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
766 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Andrii Kuliandaea3572016-04-08 13:20:51 -0700767 mTmpRect.set(0, 0, mDisplayContent.getDisplayInfo().logicalWidth,
768 mDisplayContent.getDisplayInfo().logicalHeight);
769 subtractInsets(mDisplayFrame, layoutContainingFrame, df, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700770 if (!layoutInParentFrame()) {
Andrii Kuliandaea3572016-04-08 13:20:51 -0700771 subtractInsets(mContainingFrame, layoutContainingFrame, pf, mTmpRect);
772 subtractInsets(mInsetFrame, layoutContainingFrame, pf, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700773 }
Jorim Jaggif5834272016-04-04 20:25:41 -0700774 layoutDisplayFrame = df;
775 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700776 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800777
Craig Mautner967212c2013-04-13 21:10:58 -0700778 final int pw = mContainingFrame.width();
779 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800780
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800781 if (!mParentFrame.equals(pf)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800782 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800783 // + " to " + pf);
784 mParentFrame.set(pf);
785 mContentChanged = true;
786 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700787 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
788 mLastRequestedWidth = mRequestedWidth;
789 mLastRequestedHeight = mRequestedHeight;
790 mContentChanged = true;
791 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800792
Craig Mautnereda67292013-04-28 13:50:14 -0700793 mOverscanFrame.set(of);
794 mContentFrame.set(cf);
795 mVisibleFrame.set(vf);
John Spurlock46646232013-09-30 22:32:42 -0400796 mDecorFrame.set(dcf);
Adrian Roosfa104232014-06-20 16:10:14 -0700797 mStableFrame.set(sf);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700798 final boolean hasOutsets = osf != null;
799 if (hasOutsets) {
800 mOutsetFrame.set(osf);
801 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800802
Craig Mautnereda67292013-04-28 13:50:14 -0700803 final int fw = mFrame.width();
804 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800805
Jorim Jaggif5834272016-04-04 20:25:41 -0700806 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
807
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700808 // Calculate the outsets before the content frame gets shrinked to the window frame.
809 if (hasOutsets) {
810 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
811 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
812 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
813 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
814 } else {
815 mOutsets.set(0, 0, 0, 0);
816 }
817
Craig Mautnera248eee2013-05-07 11:41:27 -0700818 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800819 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -0800820 if (windowsAreFloating && !mFrame.isEmpty()) {
Skuhne81c524a2015-08-12 13:34:14 -0700821 // Keep the frame out of the blocked system area, limit it in size to the content area
822 // and make sure that there is always a minimum visible so that the user can drag it
823 // into a usable area..
824 final int height = Math.min(mFrame.height(), mContentFrame.height());
825 final int width = Math.min(mContentFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700826 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +0900827 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
828 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
829 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
830 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Skuhne81c524a2015-08-12 13:34:14 -0700831 final int top = Math.max(mContentFrame.top,
832 Math.min(mFrame.top, mContentFrame.bottom - minVisibleHeight));
833 final int left = Math.max(mContentFrame.left + minVisibleWidth - width,
834 Math.min(mFrame.left, mContentFrame.right - minVisibleWidth));
835 mFrame.set(left, top, left + width, top + height);
836 mContentFrame.set(mFrame);
837 mVisibleFrame.set(mContentFrame);
838 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700839 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi192086e2016-03-11 17:17:03 +0100840 mDisplayContent.getDockedDividerController().positionDockedStackedDivider(mFrame);
841 mContentFrame.set(mFrame);
842 if (!mFrame.equals(mLastFrame)) {
843 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800844 }
Skuhne81c524a2015-08-12 13:34:14 -0700845 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -0700846 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
847 Math.max(mContentFrame.top, mFrame.top),
848 Math.min(mContentFrame.right, mFrame.right),
849 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800850
Jorim Jaggi656f6502016-04-11 21:08:17 -0700851 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
852 Math.max(mVisibleFrame.top, mFrame.top),
853 Math.min(mVisibleFrame.right, mFrame.right),
854 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800855
Jorim Jaggi656f6502016-04-11 21:08:17 -0700856 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
857 Math.max(mStableFrame.top, mFrame.top),
858 Math.min(mStableFrame.right, mFrame.right),
859 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700860 }
Adrian Roosfa104232014-06-20 16:10:14 -0700861
Jorim Jaggi899327f2016-02-25 20:44:18 -0500862 if (fullscreenTask && !windowsAreFloating) {
863 // Windows that are not fullscreen can be positioned outside of the display frame,
864 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -0700865 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
866 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
867 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
868 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800869 }
Craig Mautnereda67292013-04-28 13:50:14 -0700870
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100871 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100872 // For the docked divider, we calculate the stable insets like a full-screen window
873 // so it can use it to calculate the snap positions.
874 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
875 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
876 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
877 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800878
879 // The divider doesn't care about insets in any case, so set it to empty so we don't
880 // trigger a relayout when moving it.
881 mContentInsets.setEmpty();
882 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100883 } else {
Andrii Kuliand9003372016-04-04 17:46:59 -0700884 getDisplayContent().getLogicalDisplayRect(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700885 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
886 // non-fullscreen mode.
Jorim Jaggi656f6502016-04-11 21:08:17 -0700887 boolean overrideRightInset = !fullscreenTask && mFrame.right > mTmpRect.right;
888 boolean overrideBottomInset = !fullscreenTask && mFrame.bottom > mTmpRect.bottom;
889 mContentInsets.set(mContentFrame.left - mFrame.left,
890 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700891 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700892 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700893 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700894 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800895
Jorim Jaggi656f6502016-04-11 21:08:17 -0700896 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
897 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700898 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700899 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700900 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700901 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800902
Jorim Jaggi656f6502016-04-11 21:08:17 -0700903 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
904 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700905 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700906 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700907 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700908 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100909 }
Adrian Roosfa104232014-06-20 16:10:14 -0700910
Jorim Jaggi656f6502016-04-11 21:08:17 -0700911 // Offset the actual frame by the amount layout frame is off.
912 mFrame.offset(-layoutXDiff, -layoutYDiff);
913 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -0700914 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
915 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
916 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
917
Craig Mautnereda67292013-04-28 13:50:14 -0700918 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400919 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700920 // If there is a size compatibility scale being applied to the
921 // window, we need to apply this to its insets so that they are
922 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700923 mOverscanInsets.scale(mInvGlobalScale);
924 mContentInsets.scale(mInvGlobalScale);
925 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700926 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700927 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700928
929 // Also the scaled frame that we report to the app needs to be
930 // adjusted to be in its coordinate space.
931 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400932 }
933
Craig Mautnereda67292013-04-28 13:50:14 -0700934 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800935 final DisplayContent displayContent = getDisplayContent();
936 if (displayContent != null) {
937 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700938 mService.mWallpaperControllerLocked.updateWallpaperOffset(
939 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800940 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800941 }
942
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700943 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700944 "Resolving (mRequestedWidth="
945 + mRequestedWidth + ", mRequestedheight="
946 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
947 + "): frame=" + mFrame.toShortString()
948 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -0700949 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700950 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700951 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800952 }
953
Craig Mautnera2c77052012-03-26 12:14:43 -0700954 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800955 public Rect getFrameLw() {
956 return mFrame;
957 }
958
Craig Mautnera2c77052012-03-26 12:14:43 -0700959 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700960 public Point getShownPositionLw() {
961 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800962 }
963
Craig Mautnera2c77052012-03-26 12:14:43 -0700964 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800965 public Rect getDisplayFrameLw() {
966 return mDisplayFrame;
967 }
968
Craig Mautnera2c77052012-03-26 12:14:43 -0700969 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800970 public Rect getOverscanFrameLw() {
971 return mOverscanFrame;
972 }
973
974 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800975 public Rect getContentFrameLw() {
976 return mContentFrame;
977 }
978
Craig Mautnera2c77052012-03-26 12:14:43 -0700979 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800980 public Rect getVisibleFrameLw() {
981 return mVisibleFrame;
982 }
983
Craig Mautnera2c77052012-03-26 12:14:43 -0700984 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800985 public boolean getGivenInsetsPendingLw() {
986 return mGivenInsetsPending;
987 }
988
Craig Mautnera2c77052012-03-26 12:14:43 -0700989 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800990 public Rect getGivenContentInsetsLw() {
991 return mGivenContentInsets;
992 }
993
Craig Mautnera2c77052012-03-26 12:14:43 -0700994 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800995 public Rect getGivenVisibleInsetsLw() {
996 return mGivenVisibleInsets;
997 }
998
Craig Mautnera2c77052012-03-26 12:14:43 -0700999 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001000 public WindowManager.LayoutParams getAttrs() {
1001 return mAttrs;
1002 }
1003
Craig Mautner812d2ca2012-09-27 15:35:34 -07001004 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001005 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
1006 int index = -1;
1007 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -07001008 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001009 while (true) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07001010 if (ws.mAttrs.needsMenuKey != WindowManager.LayoutParams.NEEDS_MENU_UNSET) {
1011 return ws.mAttrs.needsMenuKey == WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001012 }
1013 // If we reached the bottom of the range of windows we are considering,
1014 // assume no menu is needed.
1015 if (ws == bottom) {
1016 return false;
1017 }
1018 // The current window hasn't specified whether menu key is needed;
1019 // look behind it.
1020 // First, we may need to determine the starting position.
1021 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -07001022 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001023 }
1024 index--;
1025 if (index < 0) {
1026 return false;
1027 }
Craig Mautner59c00972012-07-30 12:10:24 -07001028 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001029 }
1030 }
1031
Craig Mautner19d59bc2012-09-04 11:15:56 -07001032 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001033 public int getSystemUiVisibility() {
1034 return mSystemUiVisibility;
1035 }
1036
Craig Mautner19d59bc2012-09-04 11:15:56 -07001037 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001038 public int getSurfaceLayer() {
1039 return mLayer;
1040 }
1041
Craig Mautner812d2ca2012-09-27 15:35:34 -07001042 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001043 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001044 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001045 }
1046
1047 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001048 public IApplicationToken getAppToken() {
1049 return mAppToken != null ? mAppToken.appToken : null;
1050 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001051
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001052 @Override
1053 public boolean isVoiceInteraction() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001054 return mAppToken != null && mAppToken.voiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001055 }
1056
Robert Carr31aa98b2016-07-20 15:29:03 -07001057 boolean setReportResizeHints() {
Craig Mautner4c5eb222013-11-18 12:59:05 -08001058 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1059 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1060 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001061 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001062 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
Robert Carr31aa98b2016-07-20 15:29:03 -07001063 mFrameSizeChanged |= (mLastFrame.width() != mFrame.width()) ||
1064 (mLastFrame.height() != mFrame.height());
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001065 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
Robert Carr31aa98b2016-07-20 15:29:03 -07001066 || mOutsetsChanged || mFrameSizeChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001067 }
1068
Craig Mautnerdf88d732014-01-27 09:21:32 -08001069 public DisplayContent getDisplayContent() {
Chad Jonesf391ebc2014-06-12 17:45:05 -07001070 if (mAppToken == null || mNotOnAppsDisplay) {
Craig Mautnerbe634952014-06-12 13:39:24 -07001071 return mDisplayContent;
1072 }
1073 final TaskStack stack = getStack();
1074 return stack == null ? mDisplayContent : stack.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001075 }
1076
Chong Zhang09b21ef2015-09-14 10:20:21 -07001077 public DisplayInfo getDisplayInfo() {
1078 final DisplayContent displayContent = getDisplayContent();
1079 return displayContent != null ? displayContent.getDisplayInfo() : null;
1080 }
1081
Craig Mautner19d59bc2012-09-04 11:15:56 -07001082 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001083 final DisplayContent displayContent = getDisplayContent();
1084 if (displayContent == null) {
1085 return -1;
1086 }
1087 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001088 }
1089
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001090 Task getTask() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07001091 return mAppToken != null ? mAppToken.mTask : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001092 }
1093
1094 TaskStack getStack() {
1095 Task task = getTask();
1096 if (task != null) {
1097 if (task.mStack != null) {
1098 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001099 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001100 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001101 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1102 // associate them with some stack to enable dimming.
1103 return mAttrs.type >= WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1104 && mDisplayContent != null ? mDisplayContent.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001105 }
1106
Skuhnef932e562015-08-20 12:07:30 -07001107 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001108 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001109 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001110 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001111 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001112 final Task task = getTask();
1113 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001114 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001115 mTmpRect.setEmpty();
1116 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001117 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001118 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001119 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001120 } else {
1121 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001122 }
1123 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001124
Chong Zhang9184ec62015-09-24 12:32:21 -07001125 bounds.set(mVisibleFrame);
1126 if (intersectWithStackBounds) {
1127 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001128 }
1129
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001130 if (bounds.isEmpty()) {
1131 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001132 if (intersectWithStackBounds) {
1133 bounds.intersect(mTmpRect);
1134 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001135 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001136 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001137 }
1138
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001139 public long getInputDispatchingTimeoutNanos() {
1140 return mAppToken != null
1141 ? mAppToken.inputDispatchingTimeoutNanos
1142 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1143 }
1144
Craig Mautnere8552142012-11-07 13:55:47 -08001145 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001146 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001147 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001148 }
1149
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001150 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1151 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1152 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1153 if (dtdx < -.000001f || dtdx > .000001f) return false;
1154 if (dsdy < -.000001f || dsdy > .000001f) return false;
1155 return true;
1156 }
1157
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001158 void prelayout() {
1159 if (mEnforceSizeCompat) {
1160 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001161 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001162 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001163 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001164 }
1165 }
1166
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001167 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001168 * Does the minimal check for visibility. Callers generally want to use one of the public
1169 * methods as they perform additional checks on the app token.
1170 * TODO: See if there are other places we can use this check below instead of duplicating...
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001171 */
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001172 private boolean isVisibleUnchecked() {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001173 return mHasSurface && mPolicyVisibility && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001174 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001175 }
1176
1177 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001178 * Is this window visible? It is not visible if there is no surface, or we are in the process
1179 * of running an exit animation that will remove the surface, or its app token has been hidden.
1180 */
1181 @Override
1182 public boolean isVisibleLw() {
1183 return (mAppToken == null || !mAppToken.hiddenRequested) && isVisibleUnchecked();
1184 }
1185
1186 /**
1187 * Like {@link #isVisibleLw}, but also counts a window that is currently "hidden" behind the
1188 * keyguard as visible. This allows us to apply things like window flags that impact the
1189 * keyguard. XXX I am starting to think we need to have ANOTHER visibility flag for this
1190 * "hidden behind keyguard" state rather than overloading mPolicyVisibility. Ungh.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001191 */
Craig Mautner88400d32012-09-30 12:35:45 -07001192 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001193 public boolean isVisibleOrBehindKeyguardLw() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001194 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001195 return false;
1196 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001197 final AppWindowToken atoken = mAppToken;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001198 final boolean animating = atoken != null && atoken.mAppAnimator.animation != null;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001199 return mHasSurface && !mDestroying && !mAnimatingExit
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001200 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001201 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001202 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001203 }
1204
1205 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001206 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1207 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001208 */
1209 public boolean isWinVisibleLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001210 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.mAppAnimator.animating)
1211 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001212 }
1213
1214 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001215 * The same as isVisible(), but follows the current hidden state of the associated app token,
1216 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001217 */
1218 boolean isVisibleNow() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001219 return (!mToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001220 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001221 }
1222
1223 /**
1224 * Can this window possibly be a drag/drop target? The test here is
1225 * a combination of the above "visible now" with the check that the
1226 * Input Manager uses when discarding windows from input consideration.
1227 */
1228 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001229 return isVisibleNow() && !mRemoved
1230 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001231 }
1232
1233 /**
1234 * Same as isVisible(), but we also count it as visible between the
1235 * call to IWindowSession.add() and the first relayout().
1236 */
1237 boolean isVisibleOrAdding() {
1238 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001239 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001240 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001241 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001242 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001243 }
1244
1245 /**
1246 * Is this window currently on-screen? It is on-screen either if it
1247 * is visible or it is currently running an animation before no longer
1248 * being visible.
1249 */
1250 boolean isOnScreen() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001251 return mPolicyVisibility && isOnScreenIgnoringKeyguard();
1252 }
1253
1254 /**
1255 * Like isOnScreen(), but ignores any force hiding of the window due
1256 * to the keyguard.
1257 */
1258 boolean isOnScreenIgnoringKeyguard() {
1259 if (!mHasSurface || mDestroying) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001260 return false;
1261 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001262 final AppWindowToken atoken = mAppToken;
1263 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001264 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001265 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001266 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07001267 return !isParentWindowHidden() || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001268 }
1269
1270 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001271 * Whether this window's drawn state might affect the drawn states of the app token.
1272 *
1273 * @param visibleOnly Whether we should consider only the windows that's currently
1274 * visible in layout. If true, windows that has not relayout to VISIBLE
1275 * would always return false.
1276 *
1277 * @return true if the window should be considered while evaluating allDrawn flags.
1278 */
1279 boolean mightAffectAllDrawn(boolean visibleOnly) {
Chong Zhange292eb32016-05-21 09:23:55 -07001280 final boolean isViewVisible = (mAppToken == null || !mAppToken.clientHidden)
1281 && (mViewVisibility == View.VISIBLE) && !mWindowRemovalAllowed;
Chong Zhang8e4bda92016-05-04 15:08:18 -07001282 return (isOnScreenIgnoringKeyguard() && (!visibleOnly || isViewVisible)
1283 || mWinAnimator.mAttrType == TYPE_BASE_APPLICATION)
1284 && !mAnimatingExit && !mDestroying;
1285 }
1286
1287 /**
1288 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1289 * it must be drawn before allDrawn can become true.
1290 */
1291 boolean isInteresting() {
1292 return mAppToken != null && !mAppDied
1293 && (!mAppToken.mAppAnimator.freezingScreen || !mAppFreezing);
1294 }
1295
1296 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001297 * Like isOnScreen(), but we don't return true if the window is part
1298 * of a transition that has not yet been started.
1299 */
1300 boolean isReadyForDisplay() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001301 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001302 return false;
1303 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001304 return mHasSurface && mPolicyVisibility && !mDestroying
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001305 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001306 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001307 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001308 }
1309
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001310 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001311 * Like isReadyForDisplay(), but ignores any force hiding of the window due
1312 * to the keyguard.
1313 */
1314 boolean isReadyForDisplayIgnoringKeyguard() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001315 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001316 return false;
1317 }
1318 final AppWindowToken atoken = mAppToken;
1319 if (atoken == null && !mPolicyVisibility) {
1320 // If this is not an app window, and the policy has asked to force
1321 // hide, then we really do want to hide.
1322 return false;
1323 }
1324 return mHasSurface && !mDestroying
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001325 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden)
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001326 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -07001327 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
Chong Zhang83caa362016-08-14 18:47:54 -07001328 && !mWinAnimator.isDummyAnimation())
1329 || isAnimatingWithSavedSurface());
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001330 }
1331
1332 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001333 * Like isOnScreen, but returns false if the surface hasn't yet
1334 * been drawn.
1335 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001336 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001337 public boolean isDisplayedLw() {
1338 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001339 return isDrawnLw() && mPolicyVisibility
Wale Ogunwale9d147902016-07-16 11:58:55 -07001340 && ((!isParentWindowHidden() &&
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001341 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001342 || mWinAnimator.mAnimating
1343 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001344 }
1345
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001346 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001347 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001348 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001349 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001350 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001351 return mWinAnimator.mAnimation != null
1352 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001353 }
1354
Craig Mautner812d2ca2012-09-27 15:35:34 -07001355 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001356 public boolean isGoneForLayoutLw() {
1357 final AppWindowToken atoken = mAppToken;
1358 return mViewVisibility == View.GONE
1359 || !mRelayoutCalled
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001360 || (atoken == null && mToken.hidden)
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001361 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001362 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001363 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001364 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001365 }
1366
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001367 /**
1368 * Returns true if the window has a surface that it has drawn a
1369 * complete UI in to.
1370 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001371 public boolean isDrawFinishedLw() {
1372 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001373 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1374 || mWinAnimator.mDrawState == READY_TO_SHOW
1375 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001376 }
1377
1378 /**
1379 * Returns true if the window has a surface that it has drawn a
1380 * complete UI in to.
1381 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001382 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001383 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001384 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001385 (mWinAnimator.mDrawState == READY_TO_SHOW
1386 || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001387 }
1388
1389 /**
1390 * Return true if the window is opaque and fully drawn. This indicates
1391 * it may obscure windows behind it.
1392 */
1393 boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001394 // When there is keyguard, wallpaper could be placed over the secure app
1395 // window but invisible. We need to check wallpaper visibility explicitly
1396 // to determine if it's occluding apps.
1397 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1398 || (mIsWallpaper && mWallpaperVisible))
Craig Mautnera2c77052012-03-26 12:14:43 -07001399 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001400 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001401 }
1402
1403 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001404 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001405 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1406 */
Craig Mautner4557c082015-04-27 13:07:40 -07001407 boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001408 return mHasSurface && (mContentChanged || mMovedByResize)
Jorim Jaggi192086e2016-03-11 17:17:03 +01001409 && !mAnimatingExit && mService.okToDisplay()
Chong Zhangbd0d9372015-12-28 15:18:29 -08001410 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001411 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001412 }
1413
Chong Zhang0abb20f2015-11-19 14:17:31 -08001414 boolean isObscuringFullscreen(final DisplayInfo displayInfo) {
1415 Task task = getTask();
1416 if (task != null && task.mStack != null && !task.mStack.isFullscreen()) {
1417 return false;
1418 }
1419 if (!isOpaqueDrawn() || !isFrameFullscreen(displayInfo)) {
1420 return false;
1421 }
1422 return true;
1423 }
1424
1425 boolean isFrameFullscreen(final DisplayInfo displayInfo) {
1426 return mFrame.left <= 0 && mFrame.top <= 0
1427 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001428 }
1429
Craig Mautner812d2ca2012-09-27 15:35:34 -07001430 boolean isConfigChanged() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001431 getMergedConfig(mTmpConfig);
1432
1433 // If the merged configuration is still empty, it means that we haven't issues the
1434 // configuration to the client yet and we need to return true so the configuration updates.
1435 boolean configChanged = mMergedConfiguration.equals(Configuration.EMPTY)
1436 || mTmpConfig.diff(mMergedConfiguration) != 0;
Craig Mautnere8552142012-11-07 13:55:47 -08001437
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001438 if ((mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Craig Mautnere8552142012-11-07 13:55:47 -08001439 // Retain configuration changed status until resetConfiguration called.
1440 mConfigHasChanged |= configChanged;
1441 configChanged = mConfigHasChanged;
1442 }
1443
1444 return configChanged;
Craig Mautner812d2ca2012-09-27 15:35:34 -07001445 }
1446
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07001447 boolean isAdjustedForMinimizedDock() {
1448 return mAppToken != null && mAppToken.mTask != null
1449 && mAppToken.mTask.mStack.isAdjustedForMinimizedDock();
1450 }
1451
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001452 @Override
1453 void remove() {
1454 super.remove();
1455
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001456 if (mRemoved) {
1457 // Nothing to do.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001458 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM, "WS.remove: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001459 return;
1460 }
1461
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001462 mRemoved = true;
1463
1464 if (mService.mInputMethodTarget == this) {
1465 mService.moveInputMethodWindowsIfNeededLocked(false);
1466 }
1467
1468 final int type = mAttrs.type;
1469 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
1470 final DisplayContent displaycontent = getDisplayContent();
1471 displaycontent.mTapExcludedWindows.remove(this);
1472 }
1473 mPolicy.removeWindowLw(this);
1474
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001475 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001476
Craig Mautner96868332012-12-04 14:29:11 -08001477 mWinAnimator.destroyDeferredSurfaceLocked();
1478 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001479 mSession.windowRemovedLocked();
1480 try {
1481 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1482 } catch (RuntimeException e) {
1483 // Ignore if it has already been removed (usually because
1484 // we are doing this as part of processing a death note.)
1485 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001486
1487 mService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001488 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001489
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001490 void removeIfPossible() {
1491 removeIfPossible(false /*keepVisibleDeadWindow*/);
1492 }
1493
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001494 void removeIfPossible(boolean keepVisibleDeadWindow) {
1495 mWindowRemovalAllowed = true;
1496 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1497 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1498
1499 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1500 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1501 "Starting window removed " + this);
1502
1503 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && this == mService.mCurrentFocus)
1504 Slog.v(TAG_WM, "Remove " + this + " client="
1505 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1506 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1507 + Debug.getCallers(5));
1508
1509 final long origId = Binder.clearCallingIdentity();
1510
1511 disposeInputChannel();
1512
1513 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1514 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1515 + " mAnimatingExit=" + mAnimatingExit
1516 + " mRemoveOnExit=" + mRemoveOnExit
1517 + " mHasSurface=" + mHasSurface
1518 + " surfaceShowing=" + mWinAnimator.getShown()
1519 + " isAnimationSet=" + mWinAnimator.isAnimationSet()
1520 + " app-animation="
1521 + (mAppToken != null ? mAppToken.mAppAnimator.animation : null)
1522 + " mWillReplaceWindow=" + mWillReplaceWindow
1523 + " inPendingTransaction="
1524 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
1525 + " mDisplayFrozen=" + mService.mDisplayFrozen
1526 + " callers=" + Debug.getCallers(6));
1527
1528 // Visibility of the removed window. Will be used later to update orientation later on.
1529 boolean wasVisible = false;
1530
1531 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1532 // window until the animation is done. If the display is frozen, just remove immediately,
1533 // since the animation wouldn't be seen.
1534 if (mHasSurface && mService.okToDisplay()) {
1535 if (mWillReplaceWindow) {
1536 // This window is going to be replaced. We need to keep it around until the new one
1537 // gets added, then we will get rid of this one.
1538 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1539 "Preserving " + this + " until the new one is " + "added");
1540 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1541 // been removed. We probably need another flag to indicate that window removal
1542 // should be deffered vs. overloading the flag that says we are playing an exit
1543 // animation.
1544 mAnimatingExit = true;
1545 mReplacingRemoveRequested = true;
1546 Binder.restoreCallingIdentity(origId);
1547 return;
1548 }
1549
1550 if (isAnimatingWithSavedSurface() && !mAppToken.allDrawnExcludingSaved) {
1551 // We started enter animation early with a saved surface, now the app asks to remove
1552 // this window. If we remove it now and the app is not yet drawn, we'll show a
1553 // flicker. Delay the removal now until it's really drawn.
1554 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
1555 "removeWindowLocked: delay removal of " + this + " due to early animation");
1556 // Do not set mAnimatingExit to true here, it will cause the surface to be hidden
1557 // immediately after the enter animation is done. If the app is not yet drawn then
1558 // it will show up as a flicker.
1559 setupWindowForRemoveOnExit();
1560 Binder.restoreCallingIdentity(origId);
1561 return;
1562 }
1563 // If we are not currently running the exit animation, we need to see about starting one
1564 wasVisible = isWinVisibleLw();
1565
1566 if (keepVisibleDeadWindow) {
1567 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1568 "Not removing " + this + " because app died while it's visible");
1569
1570 mAppDied = true;
1571 setDisplayLayoutNeeded();
1572 mService.mWindowPlacerLocked.performSurfacePlacement();
1573
1574 // Set up a replacement input channel since the app is now dead.
1575 // We need to catch tapping on the dead window to restart the app.
1576 openInputChannel(null);
1577 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
1578
1579 Binder.restoreCallingIdentity(origId);
1580 return;
1581 }
1582
1583 if (wasVisible) {
1584 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
1585
1586 // Try starting an animation.
1587 if (mWinAnimator.applyAnimationLocked(transit, false)) {
1588 mAnimatingExit = true;
1589 }
1590 //TODO (multidisplay): Magnification is supported only for the default display.
1591 if (mService.mAccessibilityController != null
1592 && getDisplayId() == Display.DEFAULT_DISPLAY) {
1593 mService.mAccessibilityController.onWindowTransitionLocked(this, transit);
1594 }
1595 }
1596 final boolean isAnimating =
1597 mWinAnimator.isAnimationSet() && !mWinAnimator.isDummyAnimation();
1598 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
1599 && mAppToken.getWindowsCount() == 1;
1600 // We delay the removal of a window if it has a showing surface that can be used to run
1601 // exit animation and it is marked as exiting.
1602 // Also, If isn't the an animating starting window that is the last window in the app.
1603 // We allow the removal of the non-animating starting window now as there is no
1604 // additional window or animation that will trigger its removal.
1605 if (mWinAnimator.getShown() && mAnimatingExit
1606 && (!lastWindowIsStartingWindow || isAnimating)) {
1607 // The exit animation is running or should run... wait for it!
1608 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1609 "Not removing " + this + " due to exit animation ");
1610 setupWindowForRemoveOnExit();
1611 if (mAppToken != null) {
1612 mAppToken.updateReportedVisibilityLocked();
1613 }
1614 Binder.restoreCallingIdentity(origId);
1615 return;
1616 }
1617 }
1618
1619 remove();
1620 // Removing a visible window will effect the computed orientation
1621 // So just update orientation if needed.
1622 if (wasVisible && mService.updateOrientationFromAppTokensLocked(false)) {
1623 mService.mH.sendEmptyMessage(SEND_NEW_CONFIGURATION);
1624 }
1625 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
1626 Binder.restoreCallingIdentity(origId);
1627 }
1628
1629 private void setupWindowForRemoveOnExit() {
1630 mRemoveOnExit = true;
1631 setDisplayLayoutNeeded();
1632 // Request a focus update as this window's input channel is already gone. Otherwise
1633 // we could have no focused window in input manager.
1634 final boolean focusChanged = mService.updateFocusedWindowLocked(
1635 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
1636 mService.mWindowPlacerLocked.performSurfacePlacement();
1637 if (focusChanged) {
1638 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
1639 }
1640 }
1641
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001642 void setHasSurface(boolean hasSurface) {
1643 mHasSurface = hasSurface;
1644 }
1645
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001646 int getAnimLayerAdjustment() {
Wale Ogunwale455fac52016-07-21 07:24:49 -07001647 final boolean isImeType =
1648 mAttrs.type == TYPE_INPUT_METHOD || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
1649 if (isImeType && mService.mInputMethodTarget != null) {
1650 final AppWindowToken appToken = mService.mInputMethodTarget.mAppToken;
1651 if (appToken != null) {
1652 return appToken.mAppAnimator.animLayerAdjustment;
1653 }
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001654 }
Wale Ogunwale455fac52016-07-21 07:24:49 -07001655
1656 if (mAppToken != null) {
1657 return mAppToken.mAppAnimator.animLayerAdjustment;
1658 }
1659
1660 // Nothing is animating, so there is no animation adjustment.
1661 return 0;
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001662 }
1663
1664 void scheduleAnimationIfDimming() {
1665 if (mDisplayContent == null) {
1666 return;
1667 }
1668 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1669 if (dimLayerUser != null && mDisplayContent.mDimLayerController.isDimming(
1670 dimLayerUser, mWinAnimator)) {
1671 // Force an animation pass just to update the mDimLayer layer.
1672 mService.scheduleAnimationLocked();
1673 }
1674 }
1675
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08001676 /**
1677 * Notifies this window that the corresponding task has just moved in the stack.
1678 * <p>
1679 * This is used to fix the following: If we moved in the stack, and if the last clip rect was
1680 * empty, meaning that our task was completely offscreen, we need to keep it invisible because
1681 * the actual app transition that updates the visibility is delayed by a few transactions.
1682 * Instead of messing around with the ordering and timing how transitions and transactions are
1683 * executed, we introduce this little hack which prevents this window of getting visible again
1684 * with the wrong bounds until the app transitions has started.
1685 * <p>
1686 * This method notifies the window about that we just moved in the stack so we can apply this
1687 * logic in {@link WindowStateAnimator#updateSurfaceWindowCrop}
1688 */
1689 void notifyMovedInStack() {
1690 mJustMovedInStack = true;
1691 }
1692
1693 /**
1694 * See {@link #notifyMovedInStack}.
1695 *
1696 * @return Whether we just got moved in the corresponding stack.
1697 */
1698 boolean hasJustMovedInStack() {
1699 return mJustMovedInStack;
1700 }
1701
1702 /**
1703 * Resets that we just moved in the corresponding stack. See {@link #notifyMovedInStack}.
1704 */
1705 void resetJustMovedInStack() {
1706 mJustMovedInStack = false;
1707 }
1708
Chong Zhangacf11402015-11-04 16:23:10 -08001709 private final class DeadWindowEventReceiver extends InputEventReceiver {
1710 DeadWindowEventReceiver(InputChannel inputChannel) {
1711 super(inputChannel, mService.mH.getLooper());
1712 }
1713 @Override
1714 public void onInputEvent(InputEvent event) {
1715 finishInputEvent(event, true);
1716 }
1717 }
1718 /**
1719 * Dummy event receiver for windows that died visible.
1720 */
1721 private DeadWindowEventReceiver mDeadWindowEventReceiver;
1722
Chong Zhang112eb8c2015-11-02 11:17:00 -08001723 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001724 if (mInputChannel != null) {
1725 throw new IllegalStateException("Window already has an input channel.");
1726 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001727 String name = makeInputChannelName();
1728 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
1729 mInputChannel = inputChannels[0];
1730 mClientChannel = inputChannels[1];
1731 mInputWindowHandle.inputChannel = inputChannels[0];
1732 if (outInputChannel != null) {
1733 mClientChannel.transferTo(outInputChannel);
1734 mClientChannel.dispose();
1735 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08001736 } else {
1737 // If the window died visible, we setup a dummy input channel, so that taps
1738 // can still detected by input monitor channel, and we can relaunch the app.
1739 // Create dummy event receiver that simply reports all events as handled.
1740 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08001741 }
1742 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001743 }
1744
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001745 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08001746 if (mDeadWindowEventReceiver != null) {
1747 mDeadWindowEventReceiver.dispose();
1748 mDeadWindowEventReceiver = null;
1749 }
1750
1751 // unregister server channel first otherwise it complains about broken channel
1752 if (mInputChannel != null) {
1753 mService.mInputManager.unregisterInputChannel(mInputChannel);
1754 mInputChannel.dispose();
1755 mInputChannel = null;
1756 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08001757 if (mClientChannel != null) {
1758 mClientChannel.dispose();
1759 mClientChannel = null;
1760 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001761 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001762 }
1763
Chong Zhang112eb8c2015-11-02 11:17:00 -08001764 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08001765 // When the app is terminated (eg. from Recents), the task might have already been
1766 // removed with the window pending removal. Don't apply dim in such cases, as there
1767 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
1768 final AppWindowToken token = mAppToken;
1769 if (token != null && token.removed) {
1770 return;
1771 }
1772
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001773 if (!mAnimatingExit && mAppDied) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001774 // If app died visible, apply a dim over the window to indicate that it's inactive
1775 mDisplayContent.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
1776 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
Robert Carr9fe459d2016-04-07 23:32:28 -07001777 && mDisplayContent != null && !mAnimatingExit && isVisibleUnchecked()) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08001778 mDisplayContent.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07001779 }
1780 }
1781
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001782 DimLayer.DimLayerUser getDimLayerUser() {
1783 Task task = getTask();
1784 if (task != null) {
1785 return task;
1786 }
1787 return getStack();
1788 }
1789
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001790 void removeReplacedWindow() {
1791 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
1792 if (isDimming()) {
1793 transferDimToReplacement();
Robert Carra1eb4392015-12-10 12:43:51 -08001794 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001795 mWillReplaceWindow = false;
1796 mAnimateReplacingWindow = false;
1797 mReplacingRemoveRequested = false;
1798 mReplacingWindow = null;
1799 if (mAnimatingExit || !mAnimateReplacingWindow) {
1800 remove();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07001801 }
1802 }
1803
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07001804 void setDisplayLayoutNeeded() {
1805 if (mDisplayContent != null) {
1806 mDisplayContent.layoutNeeded = true;
1807 }
1808 }
1809
Robert Carrfed10072016-05-26 11:48:49 -07001810 // TODO: Strange usage of word workspace here and above.
1811 boolean inPinnedWorkspace() {
1812 final Task task = getTask();
1813 return task != null && task.inPinnedWorkspace();
1814 }
1815
Chong Zhang5117e272016-05-03 12:47:34 -07001816 void applyAdjustForImeIfNeeded() {
1817 final Task task = getTask();
1818 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
1819 task.mStack.applyAdjustForImeIfNeeded(task);
1820 }
1821 }
1822
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001823 int getTouchableRegion(Region region, int flags) {
1824 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001825 if (modal && mAppToken != null) {
1826 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001827 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001828 // If this is a modal window we need to dismiss it if it's not full screen and the
1829 // touch happens outside of the frame that displays the content. This means we
1830 // need to intercept touches outside of that window. The dim layer user
1831 // associated with the window (task or stack) will give us the good bounds, as
1832 // they would be used to display the dim layer.
1833 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
1834 if (dimLayerUser != null) {
1835 dimLayerUser.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001836 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001837 getVisibleBounds(mTmpRect);
1838 }
1839 if (inFreeformWorkspace()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001840 // For freeform windows we the touch region to include the whole surface for the
1841 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001842 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
1843 final int delta = WindowManagerService.dipToPixel(
1844 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
1845 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001846 }
1847 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08001848 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07001849 } else {
1850 // Not modal or full screen modal
1851 getTouchableRegion(region);
1852 }
1853 return flags;
1854 }
1855
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001856 void checkPolicyVisibilityChange() {
1857 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
1858 if (DEBUG_VISIBILITY) {
1859 Slog.v(TAG, "Policy visibility changing after anim in " +
1860 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
1861 }
1862 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08001863 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08001864 if (!mPolicyVisibility) {
1865 if (mService.mCurrentFocus == this) {
1866 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
1867 "setAnimationLocked: setting mFocusMayChange true");
1868 mService.mFocusMayChange = true;
1869 }
1870 // Window is no longer visible -- make sure if we were waiting
1871 // for it to be displayed before enabling the display, that
1872 // we allow the display to be enabled now.
1873 mService.enableScreenIfNeededLocked();
1874 }
1875 }
1876 }
1877
1878 void setRequestedSize(int requestedWidth, int requestedHeight) {
1879 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
1880 mLayoutNeeded = true;
1881 mRequestedWidth = requestedWidth;
1882 mRequestedHeight = requestedHeight;
1883 }
1884 }
1885
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001886 void prepareWindowToDisplayDuringRelayout(Configuration outConfig) {
1887 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
1888 == SOFT_INPUT_ADJUST_RESIZE) {
1889 mLayoutNeeded = true;
1890 }
1891 if (isDrawnLw() && mService.okToDisplay()) {
1892 mWinAnimator.applyEnterAnimationLocked();
1893 }
1894 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
1895 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
1896 mTurnOnScreen = true;
1897 }
1898 if (isConfigChanged()) {
Robert Carrc24d8f92016-02-29 16:24:33 -08001899 final Configuration newConfig = updateConfiguration();
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001900 if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + this + " visible with new config: "
Robert Carrc24d8f92016-02-29 16:24:33 -08001901 + newConfig);
1902 outConfig.setTo(newConfig);
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08001903 }
1904 }
1905
1906 void adjustStartingWindowFlags() {
1907 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
1908 && mAppToken.startingWindow != null) {
1909 // Special handling of starting window over the base
1910 // window of the app: propagate lock screen flags to it,
1911 // to provide the correct semantics while starting.
1912 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
1913 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
1914 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
1915 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
1916 }
1917 }
1918
1919 void setWindowScale(int requestedWidth, int requestedHeight) {
1920 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
1921
1922 if (scaledWindow) {
1923 // requested{Width|Height} Surface's physical size
1924 // attrs.{width|height} Size on screen
1925 // TODO: We don't check if attrs != null here. Is it implicitly checked?
1926 mHScale = (mAttrs.width != requestedWidth) ?
1927 (mAttrs.width / (float)requestedWidth) : 1.0f;
1928 mVScale = (mAttrs.height != requestedHeight) ?
1929 (mAttrs.height / (float)requestedHeight) : 1.0f;
1930 } else {
1931 mHScale = mVScale = 1;
1932 }
1933 }
1934
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001935 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08001936 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001937 public void binderDied() {
1938 try {
1939 synchronized(mService.mWindowMap) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001940 final WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07001941 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001942 if (win != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001943 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08001944 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
1945 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08001946 // just in case they have the divider at an unstable position. Better
1947 // also reset drag resizing state, because the owner can't do it
1948 // anymore.
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08001949 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
1950 if (stack != null) {
1951 stack.resetDockedStackToMiddle();
1952 }
Jorim Jaggidcb68142016-02-09 21:51:30 -08001953 mService.setDockedStackResizing(false);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08001954 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001955 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08001956 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001957 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001958 }
1959 }
1960 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07001961 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001962 }
1963 }
1964 }
1965
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08001966 /**
1967 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
1968 * because we want to preserve its location on screen to be re-activated later when the user
1969 * interacts with it.
1970 */
1971 boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07001972 if (!isWinVisibleLw() || mAppToken == null || mAppToken.clientHidden) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08001973 // Not a visible app window or the app isn't dead.
1974 return false;
1975 }
1976
Wale Ogunwale51d1d912016-05-04 13:27:18 -07001977 if (mAttrs.token != mClient.asBinder()) {
1978 // The window was add by a client using another client's app token. We don't want to
1979 // keep the dead window around for this case since this is meant for 'real' apps.
1980 return false;
1981 }
1982
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08001983 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1984 // We don't keep starting windows since they were added by the window manager before
1985 // the app even launched.
1986 return false;
1987 }
1988
1989 final TaskStack stack = getStack();
1990 return stack != null && StackId.keepVisibleDeadAppWindowOnScreen(stack.mStackId);
1991 }
1992
Wale Ogunwaled045c822015-12-02 09:14:28 -08001993 /** @return true if this window desires key events. */
1994 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08001995 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07001996 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08001997 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07001998 && (mAppToken == null || mAppToken.windowsAreFocusable())
1999 && !isAdjustedForMinimizedDock();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002000 }
2001
Craig Mautner749a7bb2012-04-02 13:49:53 -07002002 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002003 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002004 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002005 }
2006
Craig Mautner749a7bb2012-04-02 13:49:53 -07002007 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002008 public boolean showLw(boolean doAnimation) {
2009 return showLw(doAnimation, true);
2010 }
2011
2012 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002013 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002014 return false;
2015 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002016 if (!mAppOpVisibility) {
2017 // Being hidden due to app op request.
2018 return false;
2019 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002020 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002021 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002022 return false;
2023 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002024 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002025 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002026 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07002027 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07002028 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002029 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07002030 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002031 // Check for the case where we are currently visible and
2032 // not animating; we do not want to do animation at such a
2033 // point to become visible when we already are.
2034 doAnimation = false;
2035 }
2036 }
2037 mPolicyVisibility = true;
2038 mPolicyVisibilityAfterAnim = true;
2039 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002040 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002041 }
2042 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002043 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002044 }
2045 return true;
2046 }
2047
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002048 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002049 public boolean hideLw(boolean doAnimation) {
2050 return hideLw(doAnimation, true);
2051 }
2052
2053 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2054 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07002055 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002056 doAnimation = false;
2057 }
2058 }
Filip Gruszczynski19723a42015-11-25 15:01:48 -08002059 boolean current = doAnimation ? mPolicyVisibilityAfterAnim
2060 : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002061 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002062 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002063 return false;
2064 }
2065 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002066 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07002067 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002068 doAnimation = false;
2069 }
2070 }
Filip Gruszczynski19723a42015-11-25 15:01:48 -08002071 if (doAnimation) {
2072 mPolicyVisibilityAfterAnim = false;
2073 } else {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002074 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Filip Gruszczynski19723a42015-11-25 15:01:48 -08002075 mPolicyVisibilityAfterAnim = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002076 mPolicyVisibility = false;
2077 // Window is no longer visible -- make sure if we were waiting
2078 // for it to be displayed before enabling the display, that
2079 // we allow the display to be enabled now.
2080 mService.enableScreenIfNeededLocked();
2081 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002082 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002083 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002084 mService.mFocusMayChange = true;
2085 }
2086 }
2087 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002088 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002089 }
2090 return true;
2091 }
2092
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002093 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002094 if (mAppOpVisibility != state) {
2095 mAppOpVisibility = state;
2096 if (state) {
2097 // If the policy visibility had last been to hide, then this
2098 // will incorrectly show at this point since we lost that
2099 // information. Not a big deal -- for the windows that have app
2100 // ops modifies they should only be hidden by policy due to the
2101 // lock screen, and the user won't be changing this if locked.
2102 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002103 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002104 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002105 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002106 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002107 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002108 }
2109
Jeff Brownc2932a12014-11-20 18:04:05 -08002110 public void pokeDrawLockLw(long timeout) {
2111 if (isVisibleOrAdding()) {
2112 if (mDrawLock == null) {
2113 // We want the tag name to be somewhat stable so that it is easier to correlate
2114 // in wake lock statistics. So in particular, we don't want to include the
2115 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002116 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08002117 mDrawLock = mService.mPowerManager.newWakeLock(
2118 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
2119 mDrawLock.setReferenceCounted(false);
2120 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2121 }
2122 // Each call to acquire resets the timeout.
2123 if (DEBUG_POWER) {
2124 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2125 + mAttrs.packageName);
2126 }
2127 mDrawLock.acquire(timeout);
2128 } else if (DEBUG_POWER) {
2129 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2130 + "owned by " + mAttrs.packageName);
2131 }
2132 }
2133
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002134 @Override
2135 public boolean isAlive() {
2136 return mClient.asBinder().isBinderAlive();
2137 }
2138
Craig Mautnera987d432012-10-11 14:07:58 -07002139 boolean isClosing() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002140 return mAnimatingExit || (mService.mClosingApps.contains(mAppToken));
Craig Mautnera987d432012-10-11 14:07:58 -07002141 }
2142
Chong Zhangbef461f2015-10-27 11:38:24 -07002143 boolean isAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002144 return mAnimatingWithSavedSurface;
2145 }
2146
Chong Zhang8e4bda92016-05-04 15:08:18 -07002147 boolean isAnimatingInvisibleWithSavedSurface() {
2148 return mAnimatingWithSavedSurface
2149 && (mViewVisibility != View.VISIBLE || mWindowRemovalAllowed);
2150 }
2151
Chong Zhang92147042016-05-09 12:47:11 -07002152 public void setVisibleBeforeClientHidden() {
2153 mWasVisibleBeforeClientHidden |=
2154 (mViewVisibility == View.VISIBLE || mAnimatingWithSavedSurface);
2155 }
2156
2157 public void clearVisibleBeforeClientHidden() {
2158 mWasVisibleBeforeClientHidden = false;
2159 }
2160
2161 public boolean wasVisibleBeforeClientHidden() {
2162 return mWasVisibleBeforeClientHidden;
Chong Zhangbef461f2015-10-27 11:38:24 -07002163 }
2164
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002165 private boolean shouldSaveSurface() {
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002166 if (mWinAnimator.mSurfaceController == null) {
2167 // Don't bother if the surface controller is gone for any reason.
2168 return false;
2169 }
2170
Chong Zhang92147042016-05-09 12:47:11 -07002171 if (!mWasVisibleBeforeClientHidden) {
2172 return false;
2173 }
2174
Wale Ogunwale945d1972016-03-23 13:16:41 -07002175 if ((mAttrs.flags & FLAG_SECURE) != 0) {
2176 // We don't save secure surfaces since their content shouldn't be shown while the app
2177 // isn't on screen and content might leak through during the transition animation with
2178 // saved surface.
2179 return false;
2180 }
2181
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002182 if (ActivityManager.isLowRamDeviceStatic()) {
2183 // Don't save surfaces on Svelte devices.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002184 return false;
2185 }
2186
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002187 Task task = getTask();
2188 if (task == null || task.inHomeStack()) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002189 // Don't save surfaces for home stack apps. These usually resume and draw
2190 // first frame very fast. Saving surfaces are mostly a waste of memory.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002191 return false;
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002192 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002193
2194 final AppWindowToken taskTop = task.getTopVisibleAppToken();
2195 if (taskTop != null && taskTop != mAppToken) {
2196 // Don't save if the window is not the topmost window.
2197 return false;
2198 }
2199
Jorim Jaggi8fa45222016-02-19 19:54:39 -08002200 if (mResizedWhileGone) {
2201 // Somebody resized our window while we were gone for layout, which means that the
2202 // client got an old size, so we have an outdated surface here.
2203 return false;
2204 }
2205
Robert Carr7098dbd2016-02-01 12:31:01 -08002206 if (DEBUG_DISABLE_SAVING_SURFACES) {
2207 return false;
2208 }
2209
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002210 return mAppToken.shouldSaveSurface();
2211 }
2212
Chris Craik3131bde2016-05-06 13:39:08 -07002213 static final Region sEmptyRegion = new Region();
2214
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002215 void destroyOrSaveSurface() {
2216 mSurfaceSaved = shouldSaveSurface();
2217 if (mSurfaceSaved) {
2218 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2219 Slog.v(TAG, "Saving surface: " + this);
2220 }
Chris Craik3131bde2016-05-06 13:39:08 -07002221 // Previous user of the surface may have set a transparent region signaling a portion
2222 // doesn't need to be composited, so reset to default empty state.
2223 mSession.setTransparentRegion(mClient, sEmptyRegion);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002224
2225 mWinAnimator.hide("saved surface");
2226 mWinAnimator.mDrawState = WindowStateAnimator.NO_SURFACE;
2227 setHasSurface(false);
Chong Zhang47e36a32016-02-29 16:44:33 -08002228 // The client should have disconnected at this point, but if it doesn't,
2229 // we need to make sure it's disconnected. Otherwise when we reuse the surface
2230 // the client can't reconnect to the buffer queue, and rendering will fail.
2231 if (mWinAnimator.mSurfaceController != null) {
2232 mWinAnimator.mSurfaceController.disconnectInTransaction();
2233 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002234 mAnimatingWithSavedSurface = false;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002235 } else {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002236 mWinAnimator.destroySurfaceLocked();
2237 }
Chong Zhang92147042016-05-09 12:47:11 -07002238 // Clear animating flags now, since the surface is now gone. (Note this is true even
2239 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2240 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002241 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002242
Chong Zhang92147042016-05-09 12:47:11 -07002243 void destroySavedSurface() {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002244 if (mSurfaceSaved) {
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002245 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2246 Slog.v(TAG, "Destroying saved surface: " + this);
2247 }
Robert Carr13f7be9e2015-12-02 18:39:45 -08002248 mWinAnimator.destroySurfaceLocked();
Robert Carr237028a2016-07-26 10:39:45 -07002249 mSurfaceSaved = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002250 }
Chong Zhang92147042016-05-09 12:47:11 -07002251 mWasVisibleBeforeClientHidden = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002252 }
2253
Chong Zhang92147042016-05-09 12:47:11 -07002254 void restoreSavedSurface() {
Chong Zhang4113ffa2016-02-18 12:39:13 -08002255 if (!mSurfaceSaved) {
2256 return;
2257 }
Robert Carr237028a2016-07-26 10:39:45 -07002258
2259 // Sometimes we save surfaces due to layout invisible
2260 // directly after rotation occurs. However this means
2261 // the surface was never laid out in the new orientation.
2262 // We can only restore to the last rotation we were
2263 // laid out as visible in.
2264 if (mLastVisibleLayoutRotation != mService.mRotation) {
2265 destroySavedSurface();
2266 return;
2267 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002268 mSurfaceSaved = false;
Robert Carr237028a2016-07-26 10:39:45 -07002269
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002270 if (mWinAnimator.mSurfaceController != null) {
2271 setHasSurface(true);
Wale Ogunwale9d147902016-07-16 11:58:55 -07002272 mWinAnimator.mDrawState = READY_TO_SHOW;
Chong Zhang92147042016-05-09 12:47:11 -07002273 mAnimatingWithSavedSurface = true;
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002274
Chong Zhang6e9872b2016-08-17 10:19:05 -07002275 requestUpdateWallpaperIfNeeded();
2276
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002277 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2278 Slog.v(TAG, "Restoring saved surface: " + this);
2279 }
2280 } else {
2281 // mSurfaceController shouldn't be null if mSurfaceSaved was still true at
2282 // this point. Even if we destroyed the saved surface because of rotation
2283 // or resize, mSurfaceSaved flag should have been cleared. So this is a wtf.
2284 Slog.wtf(TAG, "Failed to restore saved surface: surface gone! " + this);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002285 }
2286 }
2287
Chong Zhang92147042016-05-09 12:47:11 -07002288 boolean canRestoreSurface() {
2289 return mWasVisibleBeforeClientHidden && mSurfaceSaved;
2290 }
2291
2292 boolean hasSavedSurface() {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002293 return mSurfaceSaved;
2294 }
2295
Chong Zhang92147042016-05-09 12:47:11 -07002296 void clearHasSavedSurface() {
2297 mSurfaceSaved = false;
2298 mAnimatingWithSavedSurface = false;
Chong Zhangf58631a2016-05-24 16:02:10 -07002299 if (mWasVisibleBeforeClientHidden) {
2300 mAppToken.destroySavedSurfaces();
2301 }
Chong Zhang92147042016-05-09 12:47:11 -07002302 }
2303
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002304 boolean clearAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002305 if (mAnimatingWithSavedSurface) {
2306 // App has drawn something to its windows, we're no longer animating with
2307 // the saved surfaces.
2308 if (DEBUG_ANIM) Slog.d(TAG,
2309 "clearAnimatingWithSavedSurface(): win=" + this);
2310 mAnimatingWithSavedSurface = false;
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002311 return true;
Chong Zhang92147042016-05-09 12:47:11 -07002312 }
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002313 return false;
Chong Zhang92147042016-05-09 12:47:11 -07002314 }
2315
Craig Mautner69b08182012-09-05 13:07:13 -07002316 @Override
2317 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002318 final DisplayContent displayContent = getDisplayContent();
2319 if (displayContent == null) {
2320 // Only a window that was on a non-default display can be detached from it.
2321 return false;
2322 }
Winson Chung47a3e652014-05-21 16:03:42 -07002323 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002324 }
2325
Adrian Rooscd3884d2015-02-18 17:25:23 +01002326 @Override
2327 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002328 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
2329 return dimLayerUser != null && mDisplayContent != null &&
Chong Zhang112eb8c2015-11-02 11:17:00 -08002330 mDisplayContent.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01002331 }
2332
Craig Mautner88400d32012-09-30 12:35:45 -07002333 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
2334 mShowToOwnerOnly = showToOwnerOnly;
2335 }
2336
Craig Mautner5962b122012-10-05 14:45:52 -07002337 boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002338 // Child windows are evaluated based on their parent window.
2339 final WindowState win = getTopParentWindow();
Craig Mautner341220f2012-10-16 15:20:09 -07002340 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -07002341 && win.mAppToken != null && win.mAppToken.showForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002342
2343 // All window frames that are fullscreen extend above status bar, but some don't extend
2344 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2345 // bottom right.
2346 if (win.mFrame.left <= win.mDisplayFrame.left
2347 && win.mFrame.top <= win.mDisplayFrame.top
2348 && win.mFrame.right >= win.mStableFrame.right
2349 && win.mFrame.bottom >= win.mStableFrame.bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002350 // Is a fullscreen window, like the clock alarm. Show to everyone.
2351 return false;
2352 }
2353 }
2354
Craig Mautner341220f2012-10-16 15:20:09 -07002355 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01002356 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002357 }
2358
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002359 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2360 outRegion.set(
2361 frame.left + inset.left, frame.top + inset.top,
2362 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002363 }
2364
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002365 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002366 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002367 switch (mTouchableInsets) {
2368 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002369 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002370 outRegion.set(frame);
2371 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002372 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002373 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002374 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002375 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002376 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002377 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002378 case TOUCHABLE_INSETS_REGION: {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002379 final Region givenTouchableRegion = mGivenTouchableRegion;
2380 outRegion.set(givenTouchableRegion);
2381 outRegion.translate(frame.left, frame.top);
2382 break;
2383 }
2384 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002385 cropRegionToStackBoundsIfNeeded(outRegion);
2386 }
2387
2388 void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002389 final Task task = getTask();
2390 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002391 return;
2392 }
2393
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002394 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002395 if (stack == null) {
2396 return;
2397 }
2398
2399 stack.getDimBounds(mTmpRect);
2400 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002401 }
2402
Craig Mautner59c00972012-07-30 12:10:24 -07002403 WindowList getWindowList() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002404 final DisplayContent displayContent = getDisplayContent();
2405 return displayContent == null ? null : displayContent.getWindowList();
Craig Mautner59c00972012-07-30 12:10:24 -07002406 }
2407
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002408 /**
2409 * Report a focus change. Must be called with no locks held, and consistently
2410 * from the same serialized thread (such as dispatched from a handler).
2411 */
2412 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
2413 try {
2414 mClient.windowFocusChanged(focused, inTouchMode);
2415 } catch (RemoteException e) {
2416 }
2417 if (mFocusCallbacks != null) {
2418 final int N = mFocusCallbacks.beginBroadcast();
2419 for (int i=0; i<N; i++) {
2420 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2421 try {
2422 if (focused) {
2423 obs.focusGained(mWindowId.asBinder());
2424 } else {
2425 obs.focusLost(mWindowId.asBinder());
2426 }
2427 } catch (RemoteException e) {
2428 }
2429 }
2430 mFocusCallbacks.finishBroadcast();
2431 }
2432 }
2433
Robert Carrc24d8f92016-02-29 16:24:33 -08002434 /**
2435 * Update our current configurations, based on task configuration.
2436 *
2437 * @return A configuration suitable for sending to the client.
2438 */
2439 private Configuration updateConfiguration() {
Robert Carrc24d8f92016-02-29 16:24:33 -08002440 final boolean configChanged = isConfigChanged();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002441 getMergedConfig(mMergedConfiguration);
2442 mConfigHasChanged = false;
Robert Carrc24d8f92016-02-29 16:24:33 -08002443 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) && configChanged) {
2444 Slog.i(TAG, "Sending new config to window " + this + ": " +
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002445 " / mergedConfig=" + mMergedConfiguration);
Robert Carrc24d8f92016-02-29 16:24:33 -08002446 }
Robert Carrc24d8f92016-02-29 16:24:33 -08002447 return mMergedConfiguration;
2448 }
2449
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002450 private void getMergedConfig(Configuration outConfig) {
2451 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
2452 outConfig.setTo(mAppToken.mFrozenMergedConfig.peek());
2453 return;
2454 }
2455 final Task task = getTask();
2456 final Configuration overrideConfig = task != null
2457 ? task.mOverrideConfig
2458 : Configuration.EMPTY;
2459 final Configuration serviceConfig = mService.mCurConfiguration;
2460 outConfig.setTo(serviceConfig);
2461 if (overrideConfig != Configuration.EMPTY) {
2462 outConfig.updateFrom(overrideConfig);
2463 }
2464 }
2465
Craig Mautnerdf88d732014-01-27 09:21:32 -08002466 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002467 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08002468 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002469 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
2470 + ": " + mCompatFrame);
Robert Carrc24d8f92016-02-29 16:24:33 -08002471 final Configuration newConfig = isConfigChanged() ? updateConfiguration() : null;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002472 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING)
2473 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
2474
Craig Mautnerdf88d732014-01-27 09:21:32 -08002475 final Rect frame = mFrame;
2476 final Rect overscanInsets = mLastOverscanInsets;
2477 final Rect contentInsets = mLastContentInsets;
2478 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07002479 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002480 final Rect outsets = mLastOutsets;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002481 final boolean reportDraw = mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING;
Chet Haase8eb48d22014-09-24 07:31:29 -07002482 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
2483 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002484 // To prevent deadlock simulate one-way call if win.mClient is a local object.
2485 mService.mH.post(new Runnable() {
2486 @Override
2487 public void run() {
2488 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002489 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
2490 stableInsets, outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002491 } catch (RemoteException e) {
2492 // Not a remote call, RemoteException won't be raised.
2493 }
2494 }
2495 });
2496 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002497 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002498 outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002499 }
Svetoslav4604abc2014-06-10 18:59:30 -07002500
2501 //TODO (multidisplay): Accessibility supported only for the default display.
2502 if (mService.mAccessibilityController != null
2503 && getDisplayId() == Display.DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07002504 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07002505 }
2506
Craig Mautnerdf88d732014-01-27 09:21:32 -08002507 mOverscanInsetsChanged = false;
2508 mContentInsetsChanged = false;
2509 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07002510 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002511 mOutsetsChanged = false;
Robert Carr31aa98b2016-07-20 15:29:03 -07002512 mFrameSizeChanged = false;
Andrii Kulianeb1d3222016-05-16 15:17:55 -07002513 mResizedWhileNotDragResizingReported = true;
Craig Mautnerdf88d732014-01-27 09:21:32 -08002514 mWinAnimator.mSurfaceResized = false;
2515 } catch (RemoteException e) {
2516 mOrientationChanging = false;
2517 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2518 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08002519 // We are assuming the hosting process is dead or in a zombie state.
2520 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
2521 + ", removing this window.");
2522 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002523 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002524 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002525 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002526 }
2527
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002528 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08002529 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
2530 // start even if we haven't received the relayout window, so that the client requests
2531 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
2532 // until the window to small size, otherwise the multithread renderer will shift last
2533 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
2534 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002535 boolean resizing = isDragResizing() || isDragResizeChanged();
2536 if (StackId.useWindowFrameForBackdrop(getStackId()) || !resizing) {
2537 return frame;
2538 }
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002539 DisplayInfo displayInfo = getDisplayInfo();
2540 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002541 return mTmpRect;
2542 }
2543
Jorim Jaggi86905582016-02-09 21:36:09 -08002544 @Override
2545 public int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002546 final TaskStack stack = getStack();
2547 if (stack == null) {
2548 return INVALID_STACK_ID;
2549 }
2550 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002551 }
2552
2553 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
2554 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
2555 Configuration newConfig) throws RemoteException {
Chong Zhangedaf3052016-04-22 15:04:31 -07002556 final boolean forceRelayout = isDragResizeChanged() || mResizedWhileNotDragResizing;
2557
Jorim Jaggidc249c42015-12-15 14:57:31 -08002558 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Jorim Jaggia4a58ef2016-01-27 02:10:08 -08002559 reportDraw, newConfig, getBackdropFrame(frame),
Chong Zhangedaf3052016-04-22 15:04:31 -07002560 forceRelayout, mPolicy.isNavBarForcedShownLw(this));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002561 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002562 }
2563
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002564 public void registerFocusObserver(IWindowFocusObserver observer) {
2565 synchronized(mService.mWindowMap) {
2566 if (mFocusCallbacks == null) {
2567 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
2568 }
2569 mFocusCallbacks.register(observer);
2570 }
2571 }
2572
2573 public void unregisterFocusObserver(IWindowFocusObserver observer) {
2574 synchronized(mService.mWindowMap) {
2575 if (mFocusCallbacks != null) {
2576 mFocusCallbacks.unregister(observer);
2577 }
2578 }
2579 }
2580
2581 public boolean isFocused() {
2582 synchronized(mService.mWindowMap) {
2583 return mService.mCurrentFocus == this;
2584 }
2585 }
2586
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07002587 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07002588 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07002589 return task != null && task.inFreeformWorkspace();
2590 }
2591
Wale Ogunwale9185fb02016-03-11 18:06:14 -08002592 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07002593 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08002594 final Task task = getTask();
2595 return task != null && !task.isFullscreen();
2596 }
2597
Chong Zhang3005e752015-09-18 18:46:28 -07002598 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002599 return mDragResizing != computeDragResizing();
2600 }
2601
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002602 /**
2603 * @return Whether we reported a drag resize change to the application or not already.
2604 */
2605 boolean isDragResizingChangeReported() {
2606 return mDragResizingChangeReported;
2607 }
2608
2609 /**
2610 * Resets the state whether we reported a drag resize change to the app.
2611 */
2612 void resetDragResizingChangeReported() {
2613 mDragResizingChangeReported = false;
2614 }
2615
Andrii Kulianeb1d3222016-05-16 15:17:55 -07002616 /**
2617 * Set whether we got resized but drag resizing flag was false.
2618 * @see #isResizedWhileNotDragResizing().
2619 */
2620 void setResizedWhileNotDragResizing(boolean resizedWhileNotDragResizing) {
2621 mResizedWhileNotDragResizing = resizedWhileNotDragResizing;
2622 mResizedWhileNotDragResizingReported = !resizedWhileNotDragResizing;
2623 }
2624
2625 /**
2626 * Indicates whether we got resized but drag resizing flag was false. In this case, we also
2627 * need to recreate the surface and defer surface bound updates in order to make sure the
2628 * buffer contents and the positioning/size stay in sync.
2629 */
2630 boolean isResizedWhileNotDragResizing() {
2631 return mResizedWhileNotDragResizing;
2632 }
2633
2634 /**
2635 * @return Whether we reported "resize while not drag resizing" to the application.
2636 * @see #isResizedWhileNotDragResizing()
2637 */
2638 boolean isResizedWhileNotDragResizingReported() {
2639 return mResizedWhileNotDragResizingReported;
2640 }
2641
Jorim Jaggidcf467c2015-11-05 13:59:32 +01002642 int getResizeMode() {
2643 return mResizeMode;
2644 }
2645
Jorim Jaggi192086e2016-03-11 17:17:03 +01002646 boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07002647 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002648 if (task == null) {
2649 return false;
2650 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08002651 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
2652
2653 // Floating windows never enter drag resize mode.
2654 return false;
2655 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002656 if (task.isDragResizing()) {
2657 return true;
2658 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01002659
2660 // If the bounds are currently frozen, it means that the layout size that the app sees
2661 // and the bounds we clip this window to might be different. In order to avoid holes, we
2662 // simulate that we are still resizing so the app fills the hole with the resizing
2663 // background.
2664 return (mDisplayContent.mDividerControllerLocked.isResizing()
2665 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Jorim Jaggi899327f2016-02-25 20:44:18 -05002666 !task.inFreeformWorkspace() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08002667
Chong Zhang3005e752015-09-18 18:46:28 -07002668 }
2669
2670 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002671 final boolean resizing = computeDragResizing();
2672 if (resizing == mDragResizing) {
2673 return;
2674 }
2675 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01002676 final Task task = getTask();
2677 if (task != null && task.isDragResizing()) {
2678 mResizeMode = task.getDragResizeMode();
2679 } else {
2680 mResizeMode = mDragResizing && mDisplayContent.mDividerControllerLocked.isResizing()
2681 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
2682 : DRAG_RESIZE_MODE_FREEFORM;
2683 }
Chong Zhang3005e752015-09-18 18:46:28 -07002684 }
2685
2686 boolean isDragResizing() {
2687 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07002688 }
2689
Robert Carr2487ce72016-04-07 15:18:45 -07002690 boolean isDockedResizing() {
2691 return mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
2692 }
2693
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002694 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08002695 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002696 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08002697 if (stack != null) {
2698 pw.print(" stackId="); pw.print(stack.mStackId);
2699 }
Wale Ogunwale4c5aa5172016-04-19 11:29:05 -07002700 if (mNotOnAppsDisplay) {
2701 pw.print(" mNotOnAppsDisplay="); pw.print(mNotOnAppsDisplay);
2702 }
Craig Mautner59c00972012-07-30 12:10:24 -07002703 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002704 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07002705 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08002706 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
2707 pw.print(" package="); pw.print(mAttrs.packageName);
2708 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002709 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002710 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
2711 pw.print(" h="); pw.print(mRequestedHeight);
2712 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07002713 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
2714 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
2715 pw.print(" h="); pw.println(mLastRequestedHeight);
2716 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07002717 if (mIsChildWindow || mLayoutAttached) {
2718 pw.print(prefix); pw.print("mParentWindow="); pw.print(getParentWindow());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002719 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
2720 }
2721 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
2722 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
2723 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
2724 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
2725 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
2726 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002727 if (dumpAll) {
2728 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
2729 pw.print(" mSubLayer="); pw.print(mSubLayer);
2730 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Wale Ogunwale455fac52016-07-21 07:24:49 -07002731 pw.print(getAnimLayerAdjustment());
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002732 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
2733 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08002734 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002735 if (dumpAll) {
2736 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002737 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07002738 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
2739 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08002740 pw.print(isAnimatingWithSavedSurface());
Chong Zhang112eb8c2015-11-02 11:17:00 -08002741 pw.print(" mAppDied=");pw.println(mAppDied);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002742 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002743 pw.print(prefix); pw.print("mViewVisibility=0x");
2744 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002745 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
2746 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07002747 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
2748 pw.print(" mSystemUiVisibility=0x");
2749 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002750 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002751 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
Wale Ogunwale9d147902016-07-16 11:58:55 -07002752 || isParentWindowHidden()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002753 pw.print(prefix); pw.print("mPolicyVisibility=");
2754 pw.print(mPolicyVisibility);
2755 pw.print(" mPolicyVisibilityAfterAnim=");
2756 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002757 pw.print(" mAppOpVisibility=");
2758 pw.print(mAppOpVisibility);
Wale Ogunwale9d147902016-07-16 11:58:55 -07002759 pw.print(" parentHidden="); pw.println(isParentWindowHidden());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002760 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08002761 if (!mRelayoutCalled || mLayoutNeeded) {
2762 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
2763 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002764 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002765 if (mXOffset != 0 || mYOffset != 0) {
2766 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
2767 pw.print(" y="); pw.println(mYOffset);
2768 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002769 if (dumpAll) {
2770 pw.print(prefix); pw.print("mGivenContentInsets=");
2771 mGivenContentInsets.printShortString(pw);
2772 pw.print(" mGivenVisibleInsets=");
2773 mGivenVisibleInsets.printShortString(pw);
2774 pw.println();
2775 if (mTouchableInsets != 0 || mGivenInsetsPending) {
2776 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
2777 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07002778 Region region = new Region();
2779 getTouchableRegion(region);
2780 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002781 }
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002782 pw.print(prefix); pw.print("mMergedConfiguration="); pw.println(mMergedConfiguration);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002783 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07002784 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07002785 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Chong Zhanga8975bd2016-01-28 17:13:47 -08002786 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08002787 pw.print(" hasSavedSurface()="); pw.print(hasSavedSurface());
2788 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002789 if (dumpAll) {
2790 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
2791 pw.print(" last="); mLastFrame.printShortString(pw);
2792 pw.println();
2793 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002794 if (mEnforceSizeCompat) {
2795 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002796 pw.println();
2797 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002798 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002799 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002800 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002801 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002802 pw.println();
2803 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
2804 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002805 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002806 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002807 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002808 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04002809 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
2810 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002811 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
2812 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002813 pw.print(prefix); pw.print("Cur insets: overscan=");
2814 mOverscanInsets.printShortString(pw);
2815 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002816 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002817 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07002818 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002819 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002820 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002821 pw.print(prefix); pw.print("Lst insets: overscan=");
2822 mLastOverscanInsets.printShortString(pw);
2823 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002824 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07002825 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002826 pw.print(" physical="); mLastOutsets.printShortString(pw);
2827 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07002828 pw.println();
2829 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07002830 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
2831 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002832 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
2833 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002834 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
2835 pw.print(" mDestroying="); pw.print(mDestroying);
2836 pw.print(" mRemoved="); pw.println(mRemoved);
2837 }
2838 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
2839 pw.print(prefix); pw.print("mOrientationChanging=");
2840 pw.print(mOrientationChanging);
2841 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
2842 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
2843 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07002844 if (mLastFreezeDuration != 0) {
2845 pw.print(prefix); pw.print("mLastFreezeDuration=");
2846 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
2847 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002848 if (mHScale != 1 || mVScale != 1) {
2849 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
2850 pw.print(" mVScale="); pw.println(mVScale);
2851 }
2852 if (mWallpaperX != -1 || mWallpaperY != -1) {
2853 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
2854 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
2855 }
2856 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
2857 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
2858 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
2859 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07002860 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
2861 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
2862 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
2863 pw.print(mWallpaperDisplayOffsetX);
2864 pw.print(" mWallpaperDisplayOffsetY=");
2865 pw.println(mWallpaperDisplayOffsetY);
2866 }
Jeff Brownc2932a12014-11-20 18:04:05 -08002867 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07002868 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08002869 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08002870 if (isDragResizing()) {
2871 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
2872 }
2873 if (computeDragResizing()) {
2874 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
2875 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002876 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08002877
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002878 String makeInputChannelName() {
2879 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002880 + " " + getWindowTag();
2881 }
2882
Robert Carra1eb4392015-12-10 12:43:51 -08002883 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002884 CharSequence tag = mAttrs.getTitle();
2885 if (tag == null || tag.length() <= 0) {
2886 tag = mAttrs.packageName;
2887 }
2888 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002889 }
2890
2891 @Override
2892 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002893 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002894 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08002895 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002896 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002897 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07002898 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002899 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002900 }
2901 return mStringNameCache;
2902 }
Robert Carr58f29132015-10-29 14:19:05 -07002903
Chia-I Wue6bcaf12016-05-27 10:58:48 +08002904 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07002905 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08002906 clipRect.left = (int) (clipRect.left / mHScale);
2907 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07002908 }
2909 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08002910 clipRect.top = (int) (clipRect.top / mVScale);
2911 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07002912 }
2913 }
Robert Carr31e28482015-12-02 16:53:18 -08002914
Jorim Jaggif5834272016-04-04 20:25:41 -07002915 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
2916 final int pw = containingFrame.width();
2917 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08002918 final Task task = getTask();
Andrii Kulian933076d2016-03-29 17:04:42 -07002919 final boolean nonFullscreenTask = isInMultiWindowMode();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07002920 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
2921
2922 // We need to fit it to the display if either
2923 // a) The task is fullscreen, or we don't have a task (we assume fullscreen for the taskless
2924 // windows)
Robert Carr6f44db12016-07-21 14:54:43 -07002925 // b) If it's a secondary app window, we also need to fit it to the display unless
2926 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on screen,
Jorim Jaggi5f23a572016-04-22 15:05:50 -07002927 // but SurfaceViews want to be always at a specific location so we don't fit it to the
2928 // display.
2929 final boolean fitToDisplay = (task == null || !nonFullscreenTask)
Robert Carr6f44db12016-07-21 14:54:43 -07002930 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08002931 float x, y;
2932 int w,h;
2933
2934 if ((mAttrs.flags & FLAG_SCALED) != 0) {
2935 if (mAttrs.width < 0) {
2936 w = pw;
2937 } else if (mEnforceSizeCompat) {
2938 w = (int)(mAttrs.width * mGlobalScale + .5f);
2939 } else {
2940 w = mAttrs.width;
2941 }
2942 if (mAttrs.height < 0) {
2943 h = ph;
2944 } else if (mEnforceSizeCompat) {
2945 h = (int)(mAttrs.height * mGlobalScale + .5f);
2946 } else {
2947 h = mAttrs.height;
2948 }
2949 } else {
2950 if (mAttrs.width == MATCH_PARENT) {
2951 w = pw;
2952 } else if (mEnforceSizeCompat) {
2953 w = (int)(mRequestedWidth * mGlobalScale + .5f);
2954 } else {
2955 w = mRequestedWidth;
2956 }
2957 if (mAttrs.height == MATCH_PARENT) {
2958 h = ph;
2959 } else if (mEnforceSizeCompat) {
2960 h = (int)(mRequestedHeight * mGlobalScale + .5f);
2961 } else {
2962 h = mRequestedHeight;
2963 }
2964 }
2965
2966 if (mEnforceSizeCompat) {
2967 x = mAttrs.x * mGlobalScale;
2968 y = mAttrs.y * mGlobalScale;
2969 } else {
2970 x = mAttrs.x;
2971 y = mAttrs.y;
2972 }
2973
Robert Carr1d2bacb2016-03-30 14:29:35 -07002974 if (nonFullscreenTask && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08002975 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08002976 // required by {@link Gravity#apply} call.
2977 w = Math.min(w, pw);
2978 h = Math.min(h, ph);
2979 }
2980
2981 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07002982 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08002983 (int) (x + mAttrs.horizontalMargin * pw),
2984 (int) (y + mAttrs.verticalMargin * ph), mFrame);
2985
2986 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08002987 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07002988 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08002989 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08002990
2991 // We need to make sure we update the CompatFrame as it is used for
2992 // cropping decisions, etc, on systems where we lack a decor layer.
2993 mCompatFrame.set(mFrame);
2994 if (mEnforceSizeCompat) {
2995 // See comparable block in computeFrameLw.
2996 mCompatFrame.scale(mInvGlobalScale);
2997 }
Robert Carr31e28482015-12-02 16:53:18 -08002998 }
Robert Carr51a1b872015-12-08 14:03:13 -08002999
3000 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003001 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003002 }
3003
3004 /**
3005 * Returns the bottom child window in regards to z-order of this window or null if no children.
3006 */
3007 WindowState getBottomChild() {
3008 // Child windows are z-ordered based on sub-layer using {@link #sWindowSubLayerComparator}
3009 // and the child with the lowest z-order will be at the head of the list.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003010 return (WindowState) mChildren.peekFirst();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003011 }
3012
Robert Carrf3b72c72016-03-21 18:16:39 -07003013 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003014 return mIsChildWindow
3015 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003016 }
3017
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003018 /** Returns the parent window if this is a child of another window, else null. */
3019 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003020 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3021 // WindowContainer that isn't a WindowState.
3022 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003023 }
3024
3025 /** Returns the topmost parent window if this is a child of another window, else this. */
3026 WindowState getTopParentWindow() {
3027 WindowState w = this;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07003028 while (w != null && w.mIsChildWindow) {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003029 w = w.getParentWindow();
3030 }
3031 return w;
3032 }
3033
Wale Ogunwale9d147902016-07-16 11:58:55 -07003034 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003035 final WindowState parent = getParentWindow();
3036 return (parent == null) ? false : parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003037 }
3038
Robert Carra1eb4392015-12-10 12:43:51 -08003039 void setReplacing(boolean animate) {
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003040 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3041 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3042 // We don't set replacing on starting windows since they are added by window manager and
3043 // not the client so won't be replaced by the client.
3044 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003045 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003046
3047 mWillReplaceWindow = true;
3048 mReplacingWindow = null;
3049 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003050 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003051
3052 void resetReplacing() {
3053 mWillReplaceWindow = false;
3054 mReplacingWindow = null;
3055 mAnimateReplacingWindow = false;
3056 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003057
Chong Zhang4d7369a2016-04-25 16:09:14 -07003058 void requestUpdateWallpaperIfNeeded() {
3059 if (mDisplayContent != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3060 mDisplayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3061 mDisplayContent.layoutNeeded = true;
3062 mService.mWindowPlacerLocked.requestTraversal();
3063 }
3064 }
3065
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003066 float translateToWindowX(float x) {
3067 float winX = x - mFrame.left;
3068 if (mEnforceSizeCompat) {
3069 winX *= mGlobalScale;
3070 }
3071 return winX;
3072 }
3073
3074 float translateToWindowY(float y) {
3075 float winY = y - mFrame.top;
3076 if (mEnforceSizeCompat) {
3077 winY *= mGlobalScale;
3078 }
3079 return winY;
3080 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003081
Robert Carr9fe459d2016-04-07 23:32:28 -07003082 void transferDimToReplacement() {
3083 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
3084 if (dimLayerUser != null && mDisplayContent != null) {
3085 mDisplayContent.mDimLayerController.applyDim(dimLayerUser,
3086 mReplacingWindow.mWinAnimator,
3087 (mAttrs.flags & FLAG_DIM_BEHIND) != 0 ? true : false);
3088 }
3089 }
3090
Robert Carrd1a010f2016-04-07 22:36:22 -07003091 // During activity relaunch due to resize, we sometimes use window replacement
3092 // for only child windows (as the main window is handled by window preservation)
3093 // and the big surface.
3094 //
3095 // Though windows of TYPE_APPLICATION (as opposed to TYPE_BASE_APPLICATION)
3096 // are not children in the sense of an attached window, we also want to replace
3097 // them at such phases, as they won't be covered by window preservation,
3098 // and in general we expect them to return following relaunch.
3099 boolean shouldBeReplacedWithChildren() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003100 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003101 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003102
3103 public int getRotationAnimationHint() {
3104 if (mAppToken != null) {
3105 return mAppToken.mRotationAnimationHint;
3106 } else {
3107 return -1;
3108 }
3109 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003110
3111 // This must be called while inside a transaction.
3112 boolean performShowLocked() {
3113 if (isHiddenFromUserLocked()) {
3114 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3115 hideLw(false);
3116 return false;
3117 }
3118
3119 logPerformShow("performShow on ");
3120
3121 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplayIgnoringKeyguard()) {
3122 return false;
3123 }
3124
3125 logPerformShow("Showing ");
3126
3127 mService.enableScreenIfNeededLocked();
3128 mWinAnimator.applyEnterAnimationLocked();
3129
3130 // Force the show in the next prepareSurfaceLocked() call.
3131 mWinAnimator.mLastAlpha = -1;
3132 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) Slog.v(TAG,
3133 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3134 mWinAnimator.mDrawState = HAS_DRAWN;
3135 mService.scheduleAnimationLocked();
3136
3137 if (mHidden) {
3138 mHidden = false;
3139 final DisplayContent displayContent = getDisplayContent();
3140
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003141 for (int i = mChildren.size() - 1; i >= 0; --i) {
3142 final WindowState c = (WindowState) mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003143 if (c.mWinAnimator.mSurfaceController != null) {
3144 c.performShowLocked();
3145 // It hadn't been shown, which means layout not performed on it, so now we
3146 // want to make sure to do a layout. If called from within the transaction
3147 // loop, this will cause it to restart with a new layout.
3148 if (displayContent != null) {
3149 displayContent.layoutNeeded = true;
3150 }
3151 }
3152 }
3153 }
3154
3155 if (mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3156 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3157 }
3158
3159 if (mAttrs.type == TYPE_INPUT_METHOD) {
3160 mDisplayContent.mDividerControllerLocked.resetImeHideRequested();
3161 }
3162
3163 return true;
3164 }
3165
3166 void logPerformShow(String prefix) {
3167 if (DEBUG_VISIBILITY
3168 || (DEBUG_STARTING_WINDOW && mAttrs.type == TYPE_APPLICATION_STARTING)) {
3169 Slog.v(TAG, prefix + this
3170 + ": mDrawState=" + mWinAnimator.drawStateToString()
3171 + " readyForDisplay=" + isReadyForDisplayIgnoringKeyguard()
3172 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3173 + " during animation: policyVis=" + mPolicyVisibility
3174 + " parentHidden=" + isParentWindowHidden()
3175 + " tok.hiddenRequested="
3176 + (mAppToken != null ? mAppToken.hiddenRequested : false)
3177 + " tok.hidden=" + (mAppToken != null ? mAppToken.hidden : false)
3178 + " animating=" + mWinAnimator.mAnimating
3179 + " tok animating="
3180 + (mWinAnimator.mAppAnimator != null ? mWinAnimator.mAppAnimator.animating : false)
3181 + " Callers=" + Debug.getCallers(4));
3182 }
3183 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003184
3185 WindowInfo getWindowInfo() {
3186 WindowInfo windowInfo = WindowInfo.obtain();
3187 windowInfo.type = mAttrs.type;
3188 windowInfo.layer = mLayer;
3189 windowInfo.token = mClient.asBinder();
3190 windowInfo.title = mAttrs.accessibilityTitle;
3191 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3192 windowInfo.focused = isFocused();
3193
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003194 if (mIsChildWindow) {
3195 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003196 }
3197
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003198 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003199 if (childCount > 0) {
3200 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003201 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003202 }
3203 for (int j = 0; j < childCount; j++) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003204 final WindowState child = (WindowState) mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003205 windowInfo.childTokens.add(child.mClient.asBinder());
3206 }
3207 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003208 return windowInfo;
3209 }
3210
3211 void adjustAnimLayer(int adj) {
3212 mWinAnimator.mAnimLayer = mLayer + adj;
3213 if (DEBUG_LAYERS) Slog.v(TAG_WM, "win=" + this + " anim layer: " + mWinAnimator.mAnimLayer);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003214 for (int i = mChildren.size() - 1; i >= 0; i--) {
3215 final WindowState childWindow = (WindowState) mChildren.get(i);
3216 childWindow.adjustAnimLayer(adj);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003217 }
3218 }
3219
3220 // TODO: come-up with a better name for this method that represents what it does.
3221 // Or, it is probably not going to matter anyways if we are successful in getting rid of
3222 // the WindowList concept.
Wale Ogunwale92fc3722016-08-05 12:19:08 -07003223 int reAddWindow(int index) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003224 final WindowList windows = getWindowList();
3225 // Adding child windows relies on child windows being ordered by mSubLayer using
3226 // {@link #sWindowSubLayerComparator}.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003227 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003228 boolean winAdded = false;
3229 for (int j = 0; j < childCount; j++) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003230 final WindowState child = (WindowState) mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003231 if (!winAdded && child.mSubLayer >= 0) {
3232 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM,
3233 "Re-adding child window at " + index + ": " + child);
3234 mRebuilding = false;
3235 windows.add(index, this);
3236 index++;
3237 winAdded = true;
3238 }
3239 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Re-adding window at " + index + ": " + child);
3240 child.mRebuilding = false;
3241 windows.add(index, child);
3242 index++;
3243 }
3244 if (!winAdded) {
3245 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Re-adding window at " + index + ": " + this);
3246 mRebuilding = false;
3247 windows.add(index, this);
3248 index++;
3249 }
3250 mService.mWindowsChanged = true;
3251 return index;
3252 }
3253
3254 int removeFromWindowList(int interestingPos) {
3255 final WindowList windows = getWindowList();
3256 int wpos = windows.indexOf(this);
3257 if (wpos < 0) {
3258 return interestingPos;
3259 }
3260
3261 if (wpos < interestingPos) interestingPos--;
3262 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Temp removing at " + wpos + ": " + this);
3263 windows.remove(wpos);
3264 mService.mWindowsChanged = true;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003265 int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003266 while (childCount > 0) {
3267 childCount--;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003268 final WindowState cw = (WindowState) mChildren.get(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003269 int cpos = windows.indexOf(cw);
3270 if (cpos >= 0) {
3271 if (cpos < interestingPos) interestingPos--;
3272 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM,
3273 "Temp removing child at " + cpos + ": " + cw);
3274 windows.remove(cpos);
3275 }
3276 }
3277 return interestingPos;
3278 }
3279
3280 void onExitAnimationDone() {
3281 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
3282 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
3283 + " windowAnimating=" + mWinAnimator.isWindowAnimationSet());
3284
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003285 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003286 // Copying to a different list as multiple children can be removed.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003287 // TODO: Not sure if we really need to copy this into a different list.
3288 final LinkedList childWindows = new LinkedList(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003289 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003290 ((WindowState)childWindows.get(i)).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003291 }
3292 }
3293
3294 if (mWinAnimator.mEnteringAnimation) {
3295 mWinAnimator.mEnteringAnimation = false;
3296 mService.requestTraversal();
3297 // System windows don't have an activity and an app token as a result, but need a way
3298 // to be informed about their entrance animation end.
3299 if (mAppToken == null) {
3300 try {
3301 mClient.dispatchWindowShown();
3302 } catch (RemoteException e) {
3303 }
3304 }
3305 }
3306
3307 if (!mWinAnimator.isWindowAnimationSet()) {
3308 //TODO (multidisplay): Accessibility is supported only for the default display.
3309 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
3310 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
3311 }
3312 }
3313
3314 if (!mAnimatingExit) {
3315 return;
3316 }
3317
3318 if (mWinAnimator.isWindowAnimationSet()) {
3319 return;
3320 }
3321
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07003322 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003323 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
3324
3325 mDestroying = true;
3326
3327 final boolean hasSurface = mWinAnimator.hasSurface();
3328 if (hasSurface) {
3329 mWinAnimator.hide("onExitAnimationDone");
3330 }
3331
3332 // If we have an app token, we ask it to destroy the surface for us, so that it can take
3333 // care to ensure the activity has actually stopped and the surface is not still in use.
3334 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
3335 // transaction.
3336 if (mAppToken != null) {
3337 mAppToken.destroySurfaces();
3338 } else {
3339 if (hasSurface) {
3340 mService.mDestroySurface.add(this);
3341 }
3342 if (mRemoveOnExit) {
3343 mService.mPendingRemove.add(this);
3344 mRemoveOnExit = false;
3345 }
3346 }
3347 mAnimatingExit = false;
3348 mService.mWallpaperControllerLocked.hideWallpapers(this);
3349 }
Dan Willemsen117197f2016-07-30 13:02:59 -07003350
Winson4b4ba902016-07-27 19:45:52 -07003351 public boolean isRtl() {
3352 return mMergedConfiguration.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
3353 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07003354
3355 void hideWallpaperWindow(boolean wasDeferred, String reason) {
3356 if (!mWinAnimator.mLastHidden || wasDeferred) {
3357 mWinAnimator.hide(reason);
3358 dispatchWallpaperVisibility(false);
3359 final DisplayContent displayContent = getDisplayContent();
3360 if (displayContent != null) {
3361 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3362 }
3363 }
3364 }
3365
3366 /**
3367 * Check wallpaper window for visibility change and notify window if so.
3368 * @param visible Current visibility.
3369 */
3370 void dispatchWallpaperVisibility(final boolean visible) {
3371 final boolean hideAllowed =
3372 mService.mWallpaperControllerLocked.mDeferredHideWallpaper == null;
3373
3374 // Only send notification if the visibility actually changed and we are not trying to hide
3375 // the wallpaper when we are deferring hiding of the wallpaper.
3376 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
3377 mWallpaperVisible = visible;
3378 try {
3379 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
3380 "Updating vis of wallpaper " + this
3381 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
3382 mClient.dispatchAppVisibility(visible);
3383 } catch (RemoteException e) {
3384 }
3385 }
3386 }
3387
3388 /** Places this window after the input window in the window list. */
3389 void addWindowToListAfter(WindowState pos) {
3390 final WindowList windows = pos.getWindowList();
3391 final int i = windows.indexOf(pos);
3392 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
3393 "Adding window " + this + " at " + (i+1) + " of " + windows.size()
3394 + " (after " + pos + ")");
3395 windows.add(i+1, this);
3396 mService.mWindowsChanged = true;
3397 }
3398
3399 /** Places this window before the input window in the window list. */
3400 void addWindowToListBefore(WindowState pos) {
3401 final WindowList windows = pos.getWindowList();
3402 int i = windows.indexOf(pos);
3403 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
3404 "Adding window " + this + " at " + i + " of " + windows.size()
3405 + " (before " + pos + ")");
3406 if (i < 0) {
3407 Slog.w(TAG_WM, "addWindowToListBefore: Unable to find " + pos + " in " + windows);
3408 i = 0;
3409 }
3410 windows.add(i, this);
3411 mService.mWindowsChanged = true;
3412 }
3413
3414 /** Adds this non-app window to the window list. */
3415 void addNonAppWindowToList() {
3416 final WindowList windows = getWindowList();
3417
3418 // Figure out where window should go, based on layer.
3419 int i;
3420 for (i = windows.size() - 1; i >= 0; i--) {
3421 final WindowState otherWin = windows.get(i);
3422 if (otherWin.getBaseType() != TYPE_WALLPAPER && otherWin.mBaseLayer <= mBaseLayer) {
3423 // Wallpaper wanders through the window list, for example to position itself
3424 // directly behind keyguard. Because of this it will break the ordering based on
3425 // WindowState.mBaseLayer. There might windows with higher mBaseLayer behind it and
3426 // we don't want the new window to appear above them. An example of this is adding
3427 // of the docked stack divider. Consider a scenario with the following ordering (top
3428 // to bottom): keyguard, wallpaper, assist preview, apps. We want the dock divider
3429 // to land below the assist preview, so the dock divider must ignore the wallpaper,
3430 // with which it shares the base layer.
3431 break;
3432 }
3433 }
3434
3435 i++;
3436 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
3437 "Free window: Adding window " + this + " at " + i + " of " + windows.size());
3438 windows.add(i, this);
3439 mService.mWindowsChanged = true;
3440 }
satokcef37fb2011-10-24 21:49:38 +09003441}