blob: aa4d7be3c59a641d8b6f04c97fc0fe111a452e6c [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;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -070090import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
Robert Carra1eb4392015-12-10 12:43:51 -080091import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080092import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
93import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
Robert Carrd1a010f2016-04-07 22:36:22 -070094import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080095import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -080096import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
Chong Zhangfea963e2016-08-15 17:14:16 -070097import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070098import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
Wale Ogunwalef9c81492015-02-25 18:06:17 -080099import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
100import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
101import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Chong Zhang4d7369a2016-04-25 16:09:14 -0700102import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700103import static android.view.WindowManagerPolicy.TRANSIT_ENTER;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700104import static android.view.WindowManagerPolicy.TRANSIT_EXIT;
105import static android.view.WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +0100106import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
107import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800108import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
109import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
110import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
111import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -0700112import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800113import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700114import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800115import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
116import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
117import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
118import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700119import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
120import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SURFACE_TRACE;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800121import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700122import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -0700123import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700124import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800125import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
126import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700127import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700128import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
129import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700130import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
131import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700132import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700133import static com.android.server.wm.WindowManagerService.localLOGV;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700134import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -0700135import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700136import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN;
137import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800138
Craig Mautner59c00972012-07-30 12:10:24 -0700139class WindowList extends ArrayList<WindowState> {
Wale Ogunwale33fde7d2016-03-05 22:38:51 -0800140 WindowList() {}
141 WindowList(WindowList windowList) {
142 super(windowList);
143 }
Craig Mautner59c00972012-07-30 12:10:24 -0700144}
145
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700146/** A window in the window manager. */
147class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800148 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800149
Skuhne81c524a2015-08-12 13:34:14 -0700150 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700151 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
152 // use hard-coded min sizes for now.
153 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
154 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700155
156 // The thickness of a window resize handle outside the window bounds on the free form workspace
157 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700158 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700159
Robert Carr7098dbd2016-02-01 12:31:01 -0800160 static final boolean DEBUG_DISABLE_SAVING_SURFACES = false;
161
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800162 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700163 final WindowManagerPolicy mPolicy;
164 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800165 final Session mSession;
166 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800167 final int mAppOp;
168 // UserId and appId of the owner. Don't display windows of non-current user.
169 final int mOwnerUid;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800170 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800171 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700172 // The same object as mToken if this is an app window and null for non-app windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800173 AppWindowToken mAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700174
175 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
176 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800177 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
178 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700179 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800180 final int mBaseLayer;
181 final int mSubLayer;
182 final boolean mLayoutAttached;
183 final boolean mIsImWindow;
184 final boolean mIsWallpaper;
185 final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700186 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700187 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800188 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700189 int mSystemUiVisibility;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700190 /**
191 * The visibility of the window based on policy like {@link WindowManagerPolicy}.
192 * Normally set by calling {@link #showLw} and {@link #hideLw}.
193 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800194 boolean mPolicyVisibility = true;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700195 /**
196 * What {@link #mPolicyVisibility} should be set to after a transition animation.
197 * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and
198 * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit
199 * animation is done.
200 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800201 boolean mPolicyVisibilityAfterAnim = true;
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -0800202 boolean mAppOpVisibility = true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700203 boolean mPermanentlyHidden; // the window should never be shown again
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800204 boolean mAppFreezing;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700205 boolean mHidden; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800206 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Chong Zhang0275e392015-09-17 10:41:44 -0700207 boolean mDragResizing;
Jorim Jaggic662d8e2016-02-05 16:54:54 -0800208 boolean mDragResizingChangeReported;
Jorim Jaggidcf467c2015-11-05 13:59:32 +0100209 int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700210
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800211 RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
212
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700213 /**
214 * The window size that was requested by the application. These are in
215 * the application's coordinate space (without compatibility scale applied).
216 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800217 int mRequestedWidth;
218 int mRequestedHeight;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700219 int mLastRequestedWidth;
220 int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700221
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800222 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800223 boolean mHaveFrame;
224 boolean mObscured;
225 boolean mTurnOnScreen;
226
227 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700228
Jorim Jaggi26c8c422016-05-09 19:57:25 -0700229 private final Configuration mTmpConfig = new Configuration();
Robert Carrc24d8f92016-02-29 16:24:33 -0800230 // Represents the changes from our override configuration applied
231 // to the global configuration. This is the only form of configuration
232 // which is suitable for delivery to the client.
233 private Configuration mMergedConfiguration = new Configuration();
Craig Mautnere8552142012-11-07 13:55:47 -0800234 // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned.
235 // Used only on {@link #TYPE_KEYGUARD}.
236 private boolean mConfigHasChanged;
Craig Mautnera2c77052012-03-26 12:14:43 -0700237
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700238 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700239 * Actual position of the surface shown on-screen (may be modified by animation). These are
240 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700241 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700242 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800243
244 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700245 * Insets that determine the actually visible area. These are in the application's
246 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800247 */
248 final Rect mVisibleInsets = new Rect();
249 final Rect mLastVisibleInsets = new Rect();
250 boolean mVisibleInsetsChanged;
251
252 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700253 * Insets that are covered by system windows (such as the status bar) and
254 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700255 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800256 */
257 final Rect mContentInsets = new Rect();
258 final Rect mLastContentInsets = new Rect();
259 boolean mContentInsetsChanged;
260
261 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800262 * Insets that determine the area covered by the display overscan region. These are in the
263 * application's coordinate space (without compatibility scale applied).
264 */
265 final Rect mOverscanInsets = new Rect();
266 final Rect mLastOverscanInsets = new Rect();
267 boolean mOverscanInsetsChanged;
268
269 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700270 * Insets that determine the area covered by the stable system windows. These are in the
271 * application's coordinate space (without compatibility scale applied).
272 */
273 final Rect mStableInsets = new Rect();
274 final Rect mLastStableInsets = new Rect();
275 boolean mStableInsetsChanged;
276
277 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700278 * Outsets determine the area outside of the surface where we want to pretend that it's possible
279 * to draw anyway.
280 */
281 final Rect mOutsets = new Rect();
282 final Rect mLastOutsets = new Rect();
283 boolean mOutsetsChanged = false;
284
285 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800286 * Set to true if we are waiting for this window to receive its
287 * given internal insets before laying out other windows based on it.
288 */
289 boolean mGivenInsetsPending;
290
291 /**
292 * These are the content insets that were given during layout for
293 * this window, to be applied to windows behind it.
294 */
295 final Rect mGivenContentInsets = new Rect();
296
297 /**
298 * These are the visible insets that were given during layout for
299 * this window, to be applied to windows behind it.
300 */
301 final Rect mGivenVisibleInsets = new Rect();
302
303 /**
304 * This is the given touchable area relative to the window frame, or null if none.
305 */
306 final Region mGivenTouchableRegion = new Region();
307
308 /**
309 * Flag indicating whether the touchable region should be adjusted by
310 * the visible insets; if false the area outside the visible insets is
311 * NOT touchable, so we must use those to adjust the frame during hit
312 * tests.
313 */
314 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
315
316 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400317 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700318 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800319 float mHScale=1, mVScale=1;
320 float mLastHScale=1, mLastVScale=1;
321 final Matrix mTmpMatrix = new Matrix();
322
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700323 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800324 final Rect mFrame = new Rect();
325 final Rect mLastFrame = new Rect();
Robert Carr31aa98b2016-07-20 15:29:03 -0700326 boolean mFrameSizeChanged = false;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700327 // Frame that is scaled to the application's coordinate space when in
328 // screen size compatibility mode.
329 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800330
331 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700332
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800333 final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700334
Wale Ogunwale94596652015-02-06 19:27:34 -0800335 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
336 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700337 final Rect mDisplayFrame = new Rect();
338
339 // The region of the display frame that the display type supports displaying content on. This
340 // is mostly a special case for TV where some displays don’t have the entire display usable.
341 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
342 // window display contents to extend into the overscan region.
343 final Rect mOverscanFrame = new Rect();
344
345 // The display frame minus the stable insets. This value is always constant regardless of if
346 // the status bar or navigation bar is visible.
Adrian Roosfa104232014-06-20 16:10:14 -0700347 final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800348
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700349 // The area not occupied by the status and navigation bars. So, if both status and navigation
350 // bars are visible, the decor frame is equal to the stable frame.
351 final Rect mDecorFrame = new Rect();
352
353 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
354 // minus the area occupied by the IME if the IME is present.
355 final Rect mContentFrame = new Rect();
356
357 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
358 // displays hint text.
359 final Rect mVisibleFrame = new Rect();
360
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700361 // Frame that includes dead area outside of the surface but where we want to pretend that it's
362 // possible to draw.
363 final Rect mOutsetFrame = new Rect();
364
Jorim Jaggidc249c42015-12-15 14:57:31 -0800365 /**
366 * Usually empty. Set to the task's tempInsetFrame. See
367 *{@link android.app.IActivityManager#resizeDockedStack}.
368 */
369 final Rect mInsetFrame = new Rect();
370
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800371 boolean mContentChanged;
372
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800373 // If a window showing a wallpaper: the requested offset for the
374 // wallpaper; if a wallpaper window: the currently applied offset.
375 float mWallpaperX = -1;
376 float mWallpaperY = -1;
377
378 // If a window showing a wallpaper: what fraction of the offset
379 // range corresponds to a full virtual screen.
380 float mWallpaperXStep = -1;
381 float mWallpaperYStep = -1;
382
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700383 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
384 // to its window; if a wallpaper window: not used.
385 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
386 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
387
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800388 // Wallpaper windows: pixels offset based on above variables.
389 int mXOffset;
390 int mYOffset;
391
Craig Mautner2268e7e2012-12-13 15:40:00 -0800392 /**
393 * This is set after IWindowSession.relayout() has been called at
394 * least once for the window. It allows us to detect the situation
395 * where we don't yet have a surface, but should have one soon, so
396 * we can give the window focus before waiting for the relayout.
397 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800398 boolean mRelayoutCalled;
399
Robert Carrfed10072016-05-26 11:48:49 -0700400 boolean mInRelayout;
401
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800402 /**
403 * If the application has called relayout() with changes that can
404 * impact its window's size, we need to perform a layout pass on it
405 * even if it is not currently visible for layout. This is set
406 * when in that case until the layout is done.
407 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800408 boolean mLayoutNeeded;
409
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800410 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800411 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800412
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800413 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800414 boolean mDestroying;
415
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800416 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800417 boolean mRemoveOnExit;
418
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800419 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800420 * Whether the app died while it was visible, if true we might need
421 * to continue to show it until it's restarted.
422 */
423 boolean mAppDied;
424
425 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800426 * Set when the orientation is changing and this window has not yet
427 * been updated for the new orientation.
428 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800429 boolean mOrientationChanging;
430
Dianne Hackborna57c6952013-03-29 14:46:40 -0700431 /**
Robert Carr237028a2016-07-26 10:39:45 -0700432 * The orientation during the last visible call to relayout. If our
433 * current orientation is different, the window can't be ready
434 * to be shown.
435 */
436 int mLastVisibleLayoutRotation = -1;
437
438 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700439 * How long we last kept the screen frozen.
440 */
441 int mLastFreezeDuration;
442
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800443 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800444 boolean mRemoved;
445
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800446 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800447 * It is save to remove the window and destroy the surface because the client requested removal
448 * or some other higher level component said so (e.g. activity manager).
449 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800450 */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800451 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800452
453 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800454 * Temp for keeping track of windows that have been removed when
455 * rebuilding window list.
456 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800457 boolean mRebuilding;
458
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800459 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700460 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800461 InputChannel mInputChannel;
Chong Zhang112eb8c2015-11-02 11:17:00 -0800462 InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800463
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800464 // Used to improve performance of toString()
465 String mStringNameCache;
466 CharSequence mLastTitle;
Dianne Hackborn529e7442012-11-01 14:22:28 -0700467 boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800468
Craig Mautnera2c77052012-03-26 12:14:43 -0700469 final WindowStateAnimator mWinAnimator;
470
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700471 boolean mHasSurface = false;
472
Craig Mautner19ab8282014-05-07 10:35:34 -0700473 boolean mNotOnAppsDisplay = false;
Craig Mautner59c00972012-07-30 12:10:24 -0700474 DisplayContent mDisplayContent;
Craig Mautner6881a102012-07-27 13:04:51 -0700475
Craig Mautner88400d32012-09-30 12:35:45 -0700476 /** When true this window can be displayed on screens owther than mOwnerUid's */
477 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700478
Robert Carr13f7be9e2015-12-02 18:39:45 -0800479 // Whether the window has a saved surface from last pause, which can be
480 // used to start an entering animation earlier.
Chong Zhang92147042016-05-09 12:47:11 -0700481 private boolean mSurfaceSaved = false;
482
Chong Zhang8e4bda92016-05-04 15:08:18 -0700483 // Whether we're performing an entering animation with a saved surface. This flag is
484 // true during the time we're showing a window with a previously saved surface. It's
485 // cleared when surface is destroyed, saved, or re-drawn by the app.
Chong Zhang92147042016-05-09 12:47:11 -0700486 private boolean mAnimatingWithSavedSurface;
487
488 // Whether the window was visible when we set the app to invisible last time. WM uses
489 // this as a hint to restore the surface (if available) for early animation next time
490 // the app is brought visible.
491 boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800492
Robert Carra1eb4392015-12-10 12:43:51 -0800493 // This window will be replaced due to relaunch. This allows window manager
494 // to differentiate between simple removal of a window and replacement. In the latter case it
495 // will preserve the old window until the new one is drawn.
496 boolean mWillReplaceWindow = false;
497 // If true, the replaced window was already requested to be removed.
498 boolean mReplacingRemoveRequested = false;
499 // Whether the replacement of the window should trigger app transition animation.
500 boolean mAnimateReplacingWindow = false;
501 // If not null, the window that will be used to replace the old one. This is being set when
502 // the window is added and unset when this window reports its first draw.
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700503 WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700504 // For the new window in the replacement transition, if we have
505 // requested to replace without animation, then we should
506 // make sure we also don't apply an enter animation for
507 // the new window.
508 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800509 // Whether this window is being moved via the resize API
510 boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800511
Jeff Brownc2932a12014-11-20 18:04:05 -0800512 /**
513 * Wake lock for drawing.
514 * Even though it's slightly more expensive to do so, we will use a separate wake lock
515 * for each app that is requesting to draw while dozing so that we can accurately track
516 * who is preventing the system from suspending.
517 * This lock is only acquired on first use.
518 */
519 PowerManager.WakeLock mDrawLock;
520
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700521 final private Rect mTmpRect = new Rect();
522
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800523 /**
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800524 * See {@link #notifyMovedInStack}.
525 */
526 private boolean mJustMovedInStack;
527
528 /**
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800529 * Whether the window was resized by us while it was gone for layout.
530 */
531 boolean mResizedWhileGone = false;
532
Andrii Kulianeb1d3222016-05-16 15:17:55 -0700533 /** @see #isResizedWhileNotDragResizing(). */
534 private boolean mResizedWhileNotDragResizing;
535
536 /** @see #isResizedWhileNotDragResizingReported(). */
537 private boolean mResizedWhileNotDragResizingReported;
Jorim Jaggif3df0aa2016-04-06 15:56:33 -0700538
Robert Carr6da3cc02016-06-16 15:17:07 -0700539 /**
540 * During seamless rotation we have two phases, first the old window contents
541 * are rotated to look as if they didn't move in the new coordinate system. Then we
542 * have to freeze updates to this layer (to preserve the transformation) until
543 * the resize actually occurs. This is true from when the transformation is set
544 * and false until the transaction to resize is sent.
545 */
546 boolean mSeamlesslyRotated = false;
547
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700548 private static final Region sEmptyRegion = new Region();
549
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700550 /**
551 * Compares to window sub-layers and returns -1 if the first is lesser than the second in terms
552 * of z-order and 1 otherwise.
553 */
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700554 private static final Comparator<WindowState> sWindowSubLayerComparator = (w1, w2) -> {
555 final int layer1 = w1.mSubLayer;
556 final int layer2 = w2.mSubLayer;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700557 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
558 // We insert the child window into the list ordered by the sub-layer.
559 // For same sub-layers, the negative one should go below others; the positive one should
560 // go above others.
561 return -1;
562 }
563 return 1;
564 };
565
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800566 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700567 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700568 int viewVisibility, final DisplayContent displayContent, int ownerId) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800569 mService = service;
570 mSession = s;
571 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800572 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800573 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700574 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700575 mOwnerUid = ownerId;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800576 mWindowId = new IWindowId.Stub() {
577 @Override
578 public void registerFocusObserver(IWindowFocusObserver observer) {
579 WindowState.this.registerFocusObserver(observer);
580 }
581 @Override
582 public void unregisterFocusObserver(IWindowFocusObserver observer) {
583 WindowState.this.unregisterFocusObserver(observer);
584 }
585 @Override
586 public boolean isFocused() {
587 return WindowState.this.isFocused();
588 }
589 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800590 mAttrs.copyFrom(a);
591 mViewVisibility = viewVisibility;
Craig Mautner59c00972012-07-30 12:10:24 -0700592 mDisplayContent = displayContent;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700593 mPolicy = mService.mPolicy;
594 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800595 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700596 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700597 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700598 if (localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700599 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700600 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800601 try {
602 c.asBinder().linkToDeath(deathRecipient, 0);
603 } catch (RemoteException e) {
604 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700605 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800606 mLayoutAttached = false;
607 mIsImWindow = false;
608 mIsWallpaper = false;
609 mIsFloatingLayer = false;
610 mBaseLayer = 0;
611 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700612 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700613 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800614 return;
615 }
616 mDeathRecipient = deathRecipient;
617
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700618 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800619 // The multiplier here is to reserve space for multiple
620 // windows in the same type layer.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700621 mBaseLayer = mPolicy.windowTypeToLayerLw(parentWindow.mAttrs.type)
622 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700623 mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700624 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900625
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700626 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow);
627 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900628
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800629 mLayoutAttached = mAttrs.type !=
630 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700631 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
632 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
633 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800634 } else {
635 // The multiplier here is to reserve space for multiple
636 // windows in the same type layer.
Craig Mautnere7ae2502012-03-26 17:11:19 -0700637 mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700638 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800639 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700640 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800641 mLayoutAttached = false;
642 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
643 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
644 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800645 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700646 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800647
Craig Mautner19ab8282014-05-07 10:35:34 -0700648 if (mAppToken != null) {
649 final DisplayContent appDisplay = getDisplayContent();
650 mNotOnAppsDisplay = displayContent != appDisplay;
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -0700651
652 if (mAppToken.showForAllUsers) {
653 // Windows for apps that can show for all users should also show when the
654 // device is locked.
655 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
656 }
Craig Mautner19ab8282014-05-07 10:35:34 -0700657 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800658
Craig Mautner322e4032012-07-13 13:35:20 -0700659 mWinAnimator = new WindowStateAnimator(this);
660 mWinAnimator.mAlpha = a.alpha;
661
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800662 mRequestedWidth = 0;
663 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700664 mLastRequestedWidth = 0;
665 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800666 mXOffset = 0;
667 mYOffset = 0;
668 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800669 mInputWindowHandle = new InputWindowHandle(
Craig Mautner59c00972012-07-30 12:10:24 -0700670 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
671 displayContent.getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800672 }
673
674 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700675 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800676 mSession.windowAddedLocked();
677 }
678
Craig Mautnera2c77052012-03-26 12:14:43 -0700679 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800680 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800681 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800682 }
683
684 @Override
685 public String getOwningPackage() {
686 return mAttrs.packageName;
687 }
688
Jorim Jaggif5834272016-04-04 20:25:41 -0700689 /**
690 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
691 * from {@param frame}. In other words, it applies the insets that would result if
692 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700693 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
694 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700695 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700696 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
697 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
698 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
699 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
700 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700701 frame.inset(left, top, right, bottom);
702 }
703
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800704 @Override
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700705 public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf, Rect sf,
706 Rect osf) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800707 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700708 // This window is being replaced and either already got information that it's being
709 // removed or we are still waiting for some information. Because of this we don't
710 // want to apply any more changes to it, so it remains in this state until new window
711 // appears.
712 return;
713 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800714 mHaveFrame = true;
715
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700716 final Task task = getTask();
Andrii Kulian933076d2016-03-29 17:04:42 -0700717 final boolean fullscreenTask = !isInMultiWindowMode();
Robert Carre6275582016-02-29 15:45:45 -0800718 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800719
Chong Zhangae35fef2016-03-16 15:56:55 -0700720 // If the task has temp inset bounds set, we have to make sure all its windows uses
721 // the temp inset frame. Otherwise different display frames get applied to the main
722 // window and the child window, making them misaligned.
723 if (fullscreenTask) {
724 mInsetFrame.setEmpty();
725 } else {
726 task.getTempInsetBounds(mInsetFrame);
727 }
728
Jorim Jaggif5834272016-04-04 20:25:41 -0700729 // Denotes the actual frame used to calculate the insets and to perform the layout. When
730 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
731 // insets temporarily. By the notion of a task having a different layout frame, we can
732 // achieve that while still moving the task around.
733 final Rect layoutContainingFrame;
734 final Rect layoutDisplayFrame;
735
736 // The offset from the layout containing frame to the actual containing frame.
737 final int layoutXDiff;
738 final int layoutYDiff;
Wale Ogunwale7cd4b012016-05-07 12:41:22 -0700739 if (fullscreenTask || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800740 // We use the parent frame as the containing frame for fullscreen and child windows
741 mContainingFrame.set(pf);
742 mDisplayFrame.set(df);
Jorim Jaggif5834272016-04-04 20:25:41 -0700743 layoutDisplayFrame = df;
744 layoutContainingFrame = pf;
745 layoutXDiff = 0;
746 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800747 } else {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700748 task.getBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100749 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
750
751 // If the bounds are frozen, we still want to translate the window freely and only
752 // freeze the size.
753 Rect frozen = mAppToken.mFrozenBounds.peek();
754 mContainingFrame.right = mContainingFrame.left + frozen.width();
755 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
756 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800757 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700758 // IME is up and obscuring this window. Adjust the window position so it is visible.
759 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this) {
760 if (windowsAreFloating && mContainingFrame.bottom > cf.bottom) {
761 // In freeform we want to move the top up directly.
762 // TODO: Investigate why this is cf not pf.
763 mContainingFrame.top -= mContainingFrame.bottom - cf.bottom;
764 } else if (mContainingFrame.bottom > pf.bottom) {
765 // But in docked we want to behave like fullscreen
766 // and behave as if the task were given smaller bounds
767 // for the purposes of layout.
768 mContainingFrame.bottom = pf.bottom;
769 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700770 }
Skuhne81c524a2015-08-12 13:34:14 -0700771
Robert Carre6275582016-02-29 15:45:45 -0800772 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700773 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
774 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800775 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700776 if (mContainingFrame.isEmpty()) {
777 mContainingFrame.set(cf);
778 }
Doris Liu06d582d2015-06-01 13:18:43 -0700779 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800780 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700781 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
782 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
783 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Andrii Kuliandaea3572016-04-08 13:20:51 -0700784 mTmpRect.set(0, 0, mDisplayContent.getDisplayInfo().logicalWidth,
785 mDisplayContent.getDisplayInfo().logicalHeight);
786 subtractInsets(mDisplayFrame, layoutContainingFrame, df, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700787 if (!layoutInParentFrame()) {
Andrii Kuliandaea3572016-04-08 13:20:51 -0700788 subtractInsets(mContainingFrame, layoutContainingFrame, pf, mTmpRect);
789 subtractInsets(mInsetFrame, layoutContainingFrame, pf, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700790 }
Jorim Jaggif5834272016-04-04 20:25:41 -0700791 layoutDisplayFrame = df;
792 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700793 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800794
Craig Mautner967212c2013-04-13 21:10:58 -0700795 final int pw = mContainingFrame.width();
796 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800797
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800798 if (!mParentFrame.equals(pf)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800799 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800800 // + " to " + pf);
801 mParentFrame.set(pf);
802 mContentChanged = true;
803 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700804 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
805 mLastRequestedWidth = mRequestedWidth;
806 mLastRequestedHeight = mRequestedHeight;
807 mContentChanged = true;
808 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800809
Craig Mautnereda67292013-04-28 13:50:14 -0700810 mOverscanFrame.set(of);
811 mContentFrame.set(cf);
812 mVisibleFrame.set(vf);
John Spurlock46646232013-09-30 22:32:42 -0400813 mDecorFrame.set(dcf);
Adrian Roosfa104232014-06-20 16:10:14 -0700814 mStableFrame.set(sf);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700815 final boolean hasOutsets = osf != null;
816 if (hasOutsets) {
817 mOutsetFrame.set(osf);
818 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800819
Craig Mautnereda67292013-04-28 13:50:14 -0700820 final int fw = mFrame.width();
821 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800822
Jorim Jaggif5834272016-04-04 20:25:41 -0700823 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
824
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700825 // Calculate the outsets before the content frame gets shrinked to the window frame.
826 if (hasOutsets) {
827 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
828 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
829 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
830 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
831 } else {
832 mOutsets.set(0, 0, 0, 0);
833 }
834
Craig Mautnera248eee2013-05-07 11:41:27 -0700835 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800836 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -0800837 if (windowsAreFloating && !mFrame.isEmpty()) {
Skuhne81c524a2015-08-12 13:34:14 -0700838 // Keep the frame out of the blocked system area, limit it in size to the content area
839 // and make sure that there is always a minimum visible so that the user can drag it
840 // into a usable area..
841 final int height = Math.min(mFrame.height(), mContentFrame.height());
842 final int width = Math.min(mContentFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700843 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +0900844 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
845 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
846 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
847 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Skuhne81c524a2015-08-12 13:34:14 -0700848 final int top = Math.max(mContentFrame.top,
849 Math.min(mFrame.top, mContentFrame.bottom - minVisibleHeight));
850 final int left = Math.max(mContentFrame.left + minVisibleWidth - width,
851 Math.min(mFrame.left, mContentFrame.right - minVisibleWidth));
852 mFrame.set(left, top, left + width, top + height);
853 mContentFrame.set(mFrame);
854 mVisibleFrame.set(mContentFrame);
855 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700856 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi192086e2016-03-11 17:17:03 +0100857 mDisplayContent.getDockedDividerController().positionDockedStackedDivider(mFrame);
858 mContentFrame.set(mFrame);
859 if (!mFrame.equals(mLastFrame)) {
860 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800861 }
Skuhne81c524a2015-08-12 13:34:14 -0700862 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -0700863 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
864 Math.max(mContentFrame.top, mFrame.top),
865 Math.min(mContentFrame.right, mFrame.right),
866 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800867
Jorim Jaggi656f6502016-04-11 21:08:17 -0700868 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
869 Math.max(mVisibleFrame.top, mFrame.top),
870 Math.min(mVisibleFrame.right, mFrame.right),
871 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800872
Jorim Jaggi656f6502016-04-11 21:08:17 -0700873 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
874 Math.max(mStableFrame.top, mFrame.top),
875 Math.min(mStableFrame.right, mFrame.right),
876 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700877 }
Adrian Roosfa104232014-06-20 16:10:14 -0700878
Jorim Jaggi899327f2016-02-25 20:44:18 -0500879 if (fullscreenTask && !windowsAreFloating) {
880 // Windows that are not fullscreen can be positioned outside of the display frame,
881 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -0700882 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
883 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
884 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
885 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800886 }
Craig Mautnereda67292013-04-28 13:50:14 -0700887
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100888 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100889 // For the docked divider, we calculate the stable insets like a full-screen window
890 // so it can use it to calculate the snap positions.
891 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
892 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
893 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
894 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800895
896 // The divider doesn't care about insets in any case, so set it to empty so we don't
897 // trigger a relayout when moving it.
898 mContentInsets.setEmpty();
899 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100900 } else {
Andrii Kuliand9003372016-04-04 17:46:59 -0700901 getDisplayContent().getLogicalDisplayRect(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700902 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
903 // non-fullscreen mode.
Jorim Jaggi656f6502016-04-11 21:08:17 -0700904 boolean overrideRightInset = !fullscreenTask && mFrame.right > mTmpRect.right;
905 boolean overrideBottomInset = !fullscreenTask && mFrame.bottom > mTmpRect.bottom;
906 mContentInsets.set(mContentFrame.left - mFrame.left,
907 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700908 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700909 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700910 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700911 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800912
Jorim Jaggi656f6502016-04-11 21:08:17 -0700913 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
914 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700915 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700916 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700917 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700918 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800919
Jorim Jaggi656f6502016-04-11 21:08:17 -0700920 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
921 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700922 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700923 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700924 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700925 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100926 }
Adrian Roosfa104232014-06-20 16:10:14 -0700927
Jorim Jaggi656f6502016-04-11 21:08:17 -0700928 // Offset the actual frame by the amount layout frame is off.
929 mFrame.offset(-layoutXDiff, -layoutYDiff);
930 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -0700931 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
932 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
933 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
934
Craig Mautnereda67292013-04-28 13:50:14 -0700935 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400936 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700937 // If there is a size compatibility scale being applied to the
938 // window, we need to apply this to its insets so that they are
939 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700940 mOverscanInsets.scale(mInvGlobalScale);
941 mContentInsets.scale(mInvGlobalScale);
942 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700943 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700944 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700945
946 // Also the scaled frame that we report to the app needs to be
947 // adjusted to be in its coordinate space.
948 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400949 }
950
Craig Mautnereda67292013-04-28 13:50:14 -0700951 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800952 final DisplayContent displayContent = getDisplayContent();
953 if (displayContent != null) {
954 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700955 mService.mWallpaperControllerLocked.updateWallpaperOffset(
956 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800957 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800958 }
959
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700960 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700961 "Resolving (mRequestedWidth="
962 + mRequestedWidth + ", mRequestedheight="
963 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
964 + "): frame=" + mFrame.toShortString()
965 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -0700966 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700967 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700968 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800969 }
970
Craig Mautnera2c77052012-03-26 12:14:43 -0700971 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800972 public Rect getFrameLw() {
973 return mFrame;
974 }
975
Craig Mautnera2c77052012-03-26 12:14:43 -0700976 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700977 public Point getShownPositionLw() {
978 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800979 }
980
Craig Mautnera2c77052012-03-26 12:14:43 -0700981 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800982 public Rect getDisplayFrameLw() {
983 return mDisplayFrame;
984 }
985
Craig Mautnera2c77052012-03-26 12:14:43 -0700986 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800987 public Rect getOverscanFrameLw() {
988 return mOverscanFrame;
989 }
990
991 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800992 public Rect getContentFrameLw() {
993 return mContentFrame;
994 }
995
Craig Mautnera2c77052012-03-26 12:14:43 -0700996 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800997 public Rect getVisibleFrameLw() {
998 return mVisibleFrame;
999 }
1000
Craig Mautnera2c77052012-03-26 12:14:43 -07001001 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001002 public boolean getGivenInsetsPendingLw() {
1003 return mGivenInsetsPending;
1004 }
1005
Craig Mautnera2c77052012-03-26 12:14:43 -07001006 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001007 public Rect getGivenContentInsetsLw() {
1008 return mGivenContentInsets;
1009 }
1010
Craig Mautnera2c77052012-03-26 12:14:43 -07001011 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001012 public Rect getGivenVisibleInsetsLw() {
1013 return mGivenVisibleInsets;
1014 }
1015
Craig Mautnera2c77052012-03-26 12:14:43 -07001016 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001017 public WindowManager.LayoutParams getAttrs() {
1018 return mAttrs;
1019 }
1020
Craig Mautner812d2ca2012-09-27 15:35:34 -07001021 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001022 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
1023 int index = -1;
1024 WindowState ws = this;
Craig Mautner59c00972012-07-30 12:10:24 -07001025 WindowList windows = getWindowList();
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001026 while (true) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07001027 if (ws.mAttrs.needsMenuKey != WindowManager.LayoutParams.NEEDS_MENU_UNSET) {
1028 return ws.mAttrs.needsMenuKey == WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001029 }
1030 // If we reached the bottom of the range of windows we are considering,
1031 // assume no menu is needed.
1032 if (ws == bottom) {
1033 return false;
1034 }
1035 // The current window hasn't specified whether menu key is needed;
1036 // look behind it.
1037 // First, we may need to determine the starting position.
1038 if (index < 0) {
Craig Mautner59c00972012-07-30 12:10:24 -07001039 index = windows.indexOf(ws);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001040 }
1041 index--;
1042 if (index < 0) {
1043 return false;
1044 }
Craig Mautner59c00972012-07-30 12:10:24 -07001045 ws = windows.get(index);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001046 }
1047 }
1048
Craig Mautner19d59bc2012-09-04 11:15:56 -07001049 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001050 public int getSystemUiVisibility() {
1051 return mSystemUiVisibility;
1052 }
1053
Craig Mautner19d59bc2012-09-04 11:15:56 -07001054 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001055 public int getSurfaceLayer() {
1056 return mLayer;
1057 }
1058
Craig Mautner812d2ca2012-09-27 15:35:34 -07001059 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001060 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001061 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001062 }
1063
1064 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001065 public IApplicationToken getAppToken() {
1066 return mAppToken != null ? mAppToken.appToken : null;
1067 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001068
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001069 @Override
1070 public boolean isVoiceInteraction() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001071 return mAppToken != null && mAppToken.voiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001072 }
1073
Robert Carr31aa98b2016-07-20 15:29:03 -07001074 boolean setReportResizeHints() {
Craig Mautner4c5eb222013-11-18 12:59:05 -08001075 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1076 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1077 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001078 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001079 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
Robert Carr31aa98b2016-07-20 15:29:03 -07001080 mFrameSizeChanged |= (mLastFrame.width() != mFrame.width()) ||
1081 (mLastFrame.height() != mFrame.height());
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001082 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
Robert Carr31aa98b2016-07-20 15:29:03 -07001083 || mOutsetsChanged || mFrameSizeChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001084 }
1085
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001086 /**
1087 * Adds the window to the resizing list if any of the parameters we use to track the window
1088 * dimensions or insets have changed.
1089 */
1090 void updateResizingWindowIfNeeded() {
1091 final WindowStateAnimator winAnimator = mWinAnimator;
1092 if (!mHasSurface || mService.mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
1093 return;
1094 }
1095
1096 final Task task = getTask();
1097 // In the case of stack bound animations, the window frames will update (unlike other
1098 // animations which just modify various transformation properties). We don't want to
1099 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1100 // the frame may not correspond to the surface size or the onscreen area at various
1101 // phases in the animation, and the client will become sad and confused.
1102 if (task != null && task.mStack.getBoundsAnimating()) {
1103 return;
1104 }
1105
1106 setReportResizeHints();
1107 boolean configChanged = isConfigChanged();
1108 if (DEBUG_CONFIGURATION && configChanged) {
1109 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1110 }
1111
1112 final boolean dragResizingChanged = isDragResizeChanged()
1113 && !isDragResizingChangeReported();
1114
1115 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
1116 + " dragResizingChanged=" + dragResizingChanged + " last=" + mLastFrame
1117 + " frame=" + mFrame);
1118
1119 // We update mLastFrame always rather than in the conditional with the last inset
1120 // variables, because mFrameSizeChanged only tracks the width and height changing.
1121 mLastFrame.set(mFrame);
1122
1123 if (mContentInsetsChanged
1124 || mVisibleInsetsChanged
1125 || winAnimator.mSurfaceResized
1126 || mOutsetsChanged
1127 || mFrameSizeChanged
1128 || configChanged
1129 || dragResizingChanged
1130 || !isResizedWhileNotDragResizingReported()) {
1131 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1132 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
1133 + " contentInsetsChanged=" + mContentInsetsChanged
1134 + " " + mContentInsets.toShortString()
1135 + " visibleInsetsChanged=" + mVisibleInsetsChanged
1136 + " " + mVisibleInsets.toShortString()
1137 + " stableInsetsChanged=" + mStableInsetsChanged
1138 + " " + mStableInsets.toShortString()
1139 + " outsetsChanged=" + mOutsetsChanged
1140 + " " + mOutsets.toShortString()
1141 + " surfaceResized=" + winAnimator.mSurfaceResized
1142 + " configChanged=" + configChanged
1143 + " dragResizingChanged=" + dragResizingChanged
1144 + " resizedWhileNotDragResizingReported="
1145 + isResizedWhileNotDragResizingReported());
1146 }
1147
1148 // If it's a dead window left on screen, and the configuration changed, there is nothing
1149 // we can do about it. Remove the window now.
1150 if (mAppToken != null && mAppDied) {
1151 mAppToken.removeDeadWindows();
1152 return;
1153 }
1154
1155 mLastOverscanInsets.set(mOverscanInsets);
1156 mLastContentInsets.set(mContentInsets);
1157 mLastVisibleInsets.set(mVisibleInsets);
1158 mLastStableInsets.set(mStableInsets);
1159 mLastOutsets.set(mOutsets);
1160 mService.makeWindowFreezingScreenIfNeededLocked(this);
1161
1162 // If the orientation is changing, or we're starting or ending a drag resizing action,
1163 // then we need to hold off on unfreezing the display until this window has been
1164 // redrawn; to do that, we need to go through the process of getting informed by the
1165 // application when it has finished drawing.
1166 if (mOrientationChanging || dragResizingChanged || isResizedWhileNotDragResizing()) {
1167 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
1168 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1169 + ", mDrawState=DRAW_PENDING in " + this
1170 + ", surfaceController " + winAnimator.mSurfaceController);
1171 }
1172 winAnimator.mDrawState = DRAW_PENDING;
1173 if (mAppToken != null) {
1174 mAppToken.clearAllDrawn();
1175 }
1176 }
1177 if (!mService.mResizingWindows.contains(this)) {
1178 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
1179 mService.mResizingWindows.add(this);
1180 }
1181 } else if (mOrientationChanging) {
1182 if (isDrawnLw()) {
1183 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1184 + this + ", surfaceController " + winAnimator.mSurfaceController);
1185 mOrientationChanging = false;
1186 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1187 - mService.mDisplayFreezeTime);
1188 }
1189 }
1190 }
1191
Craig Mautnerdf88d732014-01-27 09:21:32 -08001192 public DisplayContent getDisplayContent() {
Chad Jonesf391ebc2014-06-12 17:45:05 -07001193 if (mAppToken == null || mNotOnAppsDisplay) {
Craig Mautnerbe634952014-06-12 13:39:24 -07001194 return mDisplayContent;
1195 }
1196 final TaskStack stack = getStack();
1197 return stack == null ? mDisplayContent : stack.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001198 }
1199
Chong Zhang09b21ef2015-09-14 10:20:21 -07001200 public DisplayInfo getDisplayInfo() {
1201 final DisplayContent displayContent = getDisplayContent();
1202 return displayContent != null ? displayContent.getDisplayInfo() : null;
1203 }
1204
Craig Mautner19d59bc2012-09-04 11:15:56 -07001205 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001206 final DisplayContent displayContent = getDisplayContent();
1207 if (displayContent == null) {
1208 return -1;
1209 }
1210 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001211 }
1212
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001213 Task getTask() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07001214 return mAppToken != null ? mAppToken.mTask : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001215 }
1216
1217 TaskStack getStack() {
1218 Task task = getTask();
1219 if (task != null) {
1220 if (task.mStack != null) {
1221 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001222 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001223 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001224 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1225 // associate them with some stack to enable dimming.
1226 return mAttrs.type >= WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1227 && mDisplayContent != null ? mDisplayContent.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001228 }
1229
Skuhnef932e562015-08-20 12:07:30 -07001230 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001231 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001232 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001233 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001234 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001235 final Task task = getTask();
1236 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001237 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001238 mTmpRect.setEmpty();
1239 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001240 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001241 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001242 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001243 } else {
1244 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001245 }
1246 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001247
Chong Zhang9184ec62015-09-24 12:32:21 -07001248 bounds.set(mVisibleFrame);
1249 if (intersectWithStackBounds) {
1250 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001251 }
1252
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001253 if (bounds.isEmpty()) {
1254 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001255 if (intersectWithStackBounds) {
1256 bounds.intersect(mTmpRect);
1257 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001258 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001259 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001260 }
1261
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001262 public long getInputDispatchingTimeoutNanos() {
1263 return mAppToken != null
1264 ? mAppToken.inputDispatchingTimeoutNanos
1265 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1266 }
1267
Craig Mautnere8552142012-11-07 13:55:47 -08001268 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001269 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001270 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001271 }
1272
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001273 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1274 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1275 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1276 if (dtdx < -.000001f || dtdx > .000001f) return false;
1277 if (dsdy < -.000001f || dsdy > .000001f) return false;
1278 return true;
1279 }
1280
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001281 void prelayout() {
1282 if (mEnforceSizeCompat) {
1283 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001284 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001285 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001286 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001287 }
1288 }
1289
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001290 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001291 boolean hasContentToDisplay() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001292 // If we're animating with a saved surface, we're already visible.
1293 // Return true so that the alpha doesn't get cleared.
1294 if (!mAppFreezing && isDrawnLw()
1295 && (mViewVisibility == View.VISIBLE || isAnimatingWithSavedSurface()
1296 || (mWinAnimator.isAnimationSet() && !mService.mAppTransition.isTransitionSet()))) {
1297 return true;
1298 }
1299
Wale Ogunwale44f21802016-09-02 12:49:48 -07001300 return super.hasContentToDisplay();
1301 }
1302
1303 @Override
1304 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -07001305 // TODO: The check for hiddenRequested is commented out below, because the window can still
1306 // be visible on screen when the flag is true. We would like the isVisible() method to
1307 // return an answer closer to if the window is truly visible (can't be an exact answer
1308 // without checking the surface state), so comment out the check for now so we can test to
1309 // see what problem it causes.
1310 // If it doesn't cause any issues, then we can remove just before we lock down the current
1311 // release (O) and also consolidate this method with #isVisibleUnchecked() and possibly
1312 // other methods like isVisibleNow().
1313 // If it does cause problems, then we can look if there are other ways to solve the problem.
1314 // If there isn't then uncomment and document here why it is needed.
1315 if (/*(mAppToken == null || !mAppToken.hiddenRequested) && */isVisibleUnchecked()
1316 // TODO: The window isn't considered visible when the token is hidden, however
1317 // uncommenting the check below breaks the visual transition from an app to the launcher
1318 // if the home buttons is pressed. Need to investigate an fix that issue before
1319 // uncommenting.
1320 /* && !mToken.hidden*/) {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001321 // Is this window visible? It is not visible if there is no surface, or we are in the
1322 // process of running an exit animation that will remove the surface, or its app token
1323 // has been hidden.
1324 return true;
1325 }
Wale Ogunwale51362492016-09-08 17:49:17 -07001326 return false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001327 }
1328
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001329 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001330 * Does the minimal check for visibility. Callers generally want to use one of the public
1331 * methods as they perform additional checks on the app token.
1332 * TODO: See if there are other places we can use this check below instead of duplicating...
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001333 */
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001334 private boolean isVisibleUnchecked() {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001335 return mHasSurface && mPolicyVisibility && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001336 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001337 }
1338
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001339 @Override
1340 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001341 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001342 }
1343
1344 /**
1345 * Like {@link #isVisibleLw}, but also counts a window that is currently "hidden" behind the
1346 * keyguard as visible. This allows us to apply things like window flags that impact the
1347 * keyguard. XXX I am starting to think we need to have ANOTHER visibility flag for this
1348 * "hidden behind keyguard" state rather than overloading mPolicyVisibility. Ungh.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001349 */
Craig Mautner88400d32012-09-30 12:35:45 -07001350 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001351 public boolean isVisibleOrBehindKeyguardLw() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001352 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07001353 return false;
1354 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001355 final AppWindowToken atoken = mAppToken;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001356 final boolean animating = atoken != null && atoken.mAppAnimator.animation != null;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001357 return mHasSurface && !mDestroying && !mAnimatingExit
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001358 && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001359 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001360 || mWinAnimator.mAnimation != null || animating);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001361 }
1362
1363 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001364 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1365 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001366 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001367 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1368 boolean isWinVisibleLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001369 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.mAppAnimator.animating)
1370 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001371 }
1372
1373 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001374 * The same as isVisible(), but follows the current hidden state of the associated app token,
1375 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001376 */
1377 boolean isVisibleNow() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001378 return (!mToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001379 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001380 }
1381
1382 /**
1383 * Can this window possibly be a drag/drop target? The test here is
1384 * a combination of the above "visible now" with the check that the
1385 * Input Manager uses when discarding windows from input consideration.
1386 */
1387 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001388 return isVisibleNow() && !mRemoved
1389 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001390 }
1391
1392 /**
1393 * Same as isVisible(), but we also count it as visible between the
1394 * call to IWindowSession.add() and the first relayout().
1395 */
1396 boolean isVisibleOrAdding() {
1397 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001398 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001399 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001400 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001401 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001402 }
1403
1404 /**
1405 * Is this window currently on-screen? It is on-screen either if it
1406 * is visible or it is currently running an animation before no longer
1407 * being visible.
1408 */
1409 boolean isOnScreen() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001410 return mPolicyVisibility && isOnScreenIgnoringKeyguard();
1411 }
1412
1413 /**
1414 * Like isOnScreen(), but ignores any force hiding of the window due
1415 * to the keyguard.
1416 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001417 private boolean isOnScreenIgnoringKeyguard() {
Jorim Jaggi44f60cc2014-11-07 20:33:51 +01001418 if (!mHasSurface || mDestroying) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001419 return false;
1420 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001421 final AppWindowToken atoken = mAppToken;
1422 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001423 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001424 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001425 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07001426 return !isParentWindowHidden() || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001427 }
1428
1429 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001430 * Whether this window's drawn state might affect the drawn states of the app token.
1431 *
1432 * @param visibleOnly Whether we should consider only the windows that's currently
1433 * visible in layout. If true, windows that has not relayout to VISIBLE
1434 * would always return false.
1435 *
1436 * @return true if the window should be considered while evaluating allDrawn flags.
1437 */
1438 boolean mightAffectAllDrawn(boolean visibleOnly) {
Chong Zhange292eb32016-05-21 09:23:55 -07001439 final boolean isViewVisible = (mAppToken == null || !mAppToken.clientHidden)
1440 && (mViewVisibility == View.VISIBLE) && !mWindowRemovalAllowed;
Chong Zhang8e4bda92016-05-04 15:08:18 -07001441 return (isOnScreenIgnoringKeyguard() && (!visibleOnly || isViewVisible)
Chong Zhangfea963e2016-08-15 17:14:16 -07001442 || mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1443 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION)
Chong Zhang8e4bda92016-05-04 15:08:18 -07001444 && !mAnimatingExit && !mDestroying;
1445 }
1446
1447 /**
1448 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1449 * it must be drawn before allDrawn can become true.
1450 */
1451 boolean isInteresting() {
1452 return mAppToken != null && !mAppDied
1453 && (!mAppToken.mAppAnimator.freezingScreen || !mAppFreezing);
1454 }
1455
1456 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001457 * Like isOnScreen(), but we don't return true if the window is part
1458 * of a transition that has not yet been started.
1459 */
1460 boolean isReadyForDisplay() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001461 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001462 return false;
1463 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001464 return mHasSurface && mPolicyVisibility && !mDestroying
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001465 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001466 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001467 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001468 }
1469
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001470 /**
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001471 * Like isReadyForDisplay(), but ignores any force hiding of the window due
1472 * to the keyguard.
1473 */
1474 boolean isReadyForDisplayIgnoringKeyguard() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001475 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001476 return false;
1477 }
1478 final AppWindowToken atoken = mAppToken;
1479 if (atoken == null && !mPolicyVisibility) {
1480 // If this is not an app window, and the policy has asked to force
1481 // hide, then we really do want to hide.
1482 return false;
1483 }
1484 return mHasSurface && !mDestroying
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001485 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden)
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001486 || mWinAnimator.mAnimation != null
Craig Mautner9c5bf3b2012-06-22 15:19:13 -07001487 || ((atoken != null) && (atoken.mAppAnimator.animation != null)
Chong Zhang83caa362016-08-14 18:47:54 -07001488 && !mWinAnimator.isDummyAnimation())
1489 || isAnimatingWithSavedSurface());
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07001490 }
1491
1492 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001493 * Like isOnScreen, but returns false if the surface hasn't yet
1494 * been drawn.
1495 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001496 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001497 public boolean isDisplayedLw() {
1498 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001499 return isDrawnLw() && mPolicyVisibility
Wale Ogunwale9d147902016-07-16 11:58:55 -07001500 && ((!isParentWindowHidden() &&
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001501 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001502 || mWinAnimator.mAnimating
1503 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001504 }
1505
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001506 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001507 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001508 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001509 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001510 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001511 return mWinAnimator.mAnimation != null
1512 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001513 }
1514
Craig Mautner812d2ca2012-09-27 15:35:34 -07001515 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001516 public boolean isGoneForLayoutLw() {
1517 final AppWindowToken atoken = mAppToken;
1518 return mViewVisibility == View.GONE
1519 || !mRelayoutCalled
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001520 || (atoken == null && mToken.hidden)
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001521 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001522 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001523 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001524 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001525 }
1526
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001527 /**
1528 * Returns true if the window has a surface that it has drawn a
1529 * complete UI in to.
1530 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001531 public boolean isDrawFinishedLw() {
1532 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001533 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1534 || mWinAnimator.mDrawState == READY_TO_SHOW
1535 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001536 }
1537
1538 /**
1539 * Returns true if the window has a surface that it has drawn a
1540 * complete UI in to.
1541 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001542 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001543 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001544 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001545 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001546 }
1547
1548 /**
1549 * Return true if the window is opaque and fully drawn. This indicates
1550 * it may obscure windows behind it.
1551 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001552 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001553 // When there is keyguard, wallpaper could be placed over the secure app
1554 // window but invisible. We need to check wallpaper visibility explicitly
1555 // to determine if it's occluding apps.
1556 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1557 || (mIsWallpaper && mWallpaperVisible))
Craig Mautnera2c77052012-03-26 12:14:43 -07001558 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001559 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001560 }
1561
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001562 @Override
1563 void onMovedByResize() {
1564 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001565 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001566 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001567 }
1568
1569 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1570 boolean changed = false;
1571
1572 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001573 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001574 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1575 }
1576
1577 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1578 // Starting window that's exiting will be removed when the animation finishes.
1579 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1580 // to actually remove it.
1581 if (!visible && isVisibleNow() && mAppToken.mAppAnimator.isAnimating()) {
1582 mAnimatingExit = true;
1583 mRemoveOnExit = true;
1584 mWindowRemovalAllowed = true;
1585 }
1586 return changed;
1587 }
1588
1589 if (visible != isVisibleNow()) {
1590 if (!runningAppAnimation) {
1591 final AccessibilityController accessibilityController =
1592 mService.mAccessibilityController;
1593 final int winTransit = visible ? TRANSIT_ENTER : TRANSIT_EXIT;
1594 mWinAnimator.applyAnimationLocked(winTransit, visible);
1595 //TODO (multidisplay): Magnification is supported only for the default
1596 if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
1597 accessibilityController.onWindowTransitionLocked(this, winTransit);
1598 }
1599 }
1600 changed = true;
1601 setDisplayLayoutNeeded();
1602 }
1603
1604 return changed;
1605 }
1606
1607 boolean onSetAppExiting() {
1608 final DisplayContent displayContent = getDisplayContent();
1609 boolean changed = false;
1610
1611 if (isVisibleNow()) {
1612 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
1613 //TODO (multidisplay): Magnification is supported only for the default
1614 if (mService.mAccessibilityController != null && isDefaultDisplay()) {
1615 mService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
1616 }
1617 changed = true;
1618 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001619 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001620 }
1621 }
1622
1623 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001624 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001625 changed |= c.onSetAppExiting();
1626 }
1627
1628 return changed;
1629 }
1630
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001631 @Override
1632 void onResize() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001633 // Some windows won't go through the resizing process, if they don't have a surface, so
1634 // destroy all saved surfaces here.
1635 destroySavedSurface();
1636
1637 final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
1638 if (mHasSurface && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001639 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001640 resizingWindows.add(this);
1641
1642 // If we are not drag resizing, force recreating of a new surface so updating
1643 // the content and positioning that surface will be in sync.
1644 //
1645 // As we use this flag as a hint to freeze surface boundary updates, we'd like to only
1646 // apply this to TYPE_BASE_APPLICATION, windows of TYPE_APPLICATION like dialogs, could
1647 // appear to not be drag resizing while they resize, but we'd still like to manipulate
1648 // their frame to update crop, etc...
1649 //
1650 // Anyway we don't need to synchronize position and content updates for these
1651 // windows since they aren't at the base layer and could be moved around anyway.
1652 if (!computeDragResizing() && mAttrs.type == TYPE_BASE_APPLICATION &&
1653 !getTask().mStack.getBoundsAnimating() && !isGoneForLayoutLw() &&
1654 !getTask().inPinnedWorkspace()) {
1655 setResizedWhileNotDragResizing(true);
1656 }
1657 }
1658 if (isGoneForLayoutLw()) {
1659 mResizedWhileGone = true;
1660 }
1661
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001662 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001663 }
1664
1665 void onUnfreezeBounds() {
1666 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001667 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001668 c.onUnfreezeBounds();
1669 }
1670
1671 if (!mHasSurface) {
1672 return;
1673 }
1674
1675 mLayoutNeeded = true;
1676 setDisplayLayoutNeeded();
1677 if (!mService.mResizingWindows.contains(this)) {
1678 mService.mResizingWindows.add(this);
1679 }
1680 }
1681
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001682 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001683 * If the window has moved due to its containing content frame changing, then notify the
1684 * listeners and optionally animate it. Simply checking a change of position is not enough,
1685 * because being move due to dock divider is not a trigger for animation.
1686 */
1687 void handleWindowMovedIfNeeded() {
1688 if (!hasMoved()) {
1689 return;
1690 }
1691
1692 // Frame has moved, containing content frame has also moved, and we're not currently
1693 // animating... let's do something.
1694 final int left = mFrame.left;
1695 final int top = mFrame.top;
1696 final Task task = getTask();
1697 final boolean adjustedForMinimizedDockOrIme = task != null
1698 && (task.mStack.isAdjustedForMinimizedDockedStack()
1699 || task.mStack.isAdjustedForIme());
1700 if (mService.okToDisplay()
1701 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1702 && !isDragResizing() && !adjustedForMinimizedDockOrIme
1703 && (task == null || getTask().mStack.hasMovementAnimations())
1704 && !mWinAnimator.mLastHidden) {
1705 mWinAnimator.setMoveAnimation(left, top);
1706 }
1707
1708 //TODO (multidisplay): Accessibility supported only for the default display.
1709 if (mService.mAccessibilityController != null
1710 && getDisplayContent().getDisplayId() == Display.DEFAULT_DISPLAY) {
1711 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
1712 }
1713
1714 try {
1715 mClient.moved(left, top);
1716 } catch (RemoteException e) {
1717 }
1718 mMovedByResize = false;
1719 }
1720
1721 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001722 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001723 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1724 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001725 private boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001726 return mHasSurface && (mContentChanged || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001727 && !mAnimatingExit
Chong Zhangbd0d9372015-12-28 15:18:29 -08001728 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001729 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001730 }
1731
Chong Zhang0abb20f2015-11-19 14:17:31 -08001732 boolean isObscuringFullscreen(final DisplayInfo displayInfo) {
1733 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001734 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001735 return false;
1736 }
1737 if (!isOpaqueDrawn() || !isFrameFullscreen(displayInfo)) {
1738 return false;
1739 }
1740 return true;
1741 }
1742
1743 boolean isFrameFullscreen(final DisplayInfo displayInfo) {
1744 return mFrame.left <= 0 && mFrame.top <= 0
1745 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001746 }
1747
Craig Mautner812d2ca2012-09-27 15:35:34 -07001748 boolean isConfigChanged() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001749 getMergedConfig(mTmpConfig);
1750
Andrii Kulian8072d112016-09-16 11:11:01 -07001751 // If the merged configuration is still empty, it means that we haven't issued the
Jorim Jaggi26c8c422016-05-09 19:57:25 -07001752 // configuration to the client yet and we need to return true so the configuration updates.
1753 boolean configChanged = mMergedConfiguration.equals(Configuration.EMPTY)
1754 || mTmpConfig.diff(mMergedConfiguration) != 0;
Craig Mautnere8552142012-11-07 13:55:47 -08001755
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001756 if ((mAttrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Craig Mautnere8552142012-11-07 13:55:47 -08001757 // Retain configuration changed status until resetConfiguration called.
1758 mConfigHasChanged |= configChanged;
1759 configChanged = mConfigHasChanged;
1760 }
1761
1762 return configChanged;
Craig Mautner812d2ca2012-09-27 15:35:34 -07001763 }
1764
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07001765 boolean isAdjustedForMinimizedDock() {
1766 return mAppToken != null && mAppToken.mTask != null
1767 && mAppToken.mTask.mStack.isAdjustedForMinimizedDock();
1768 }
1769
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001770 void onWindowReplacementTimeout() {
1771 if (mWillReplaceWindow) {
1772 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001773 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001774 // delays removal on certain conditions, which will leave the stale window in the
1775 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1776 //
1777 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001778 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001779 } else {
1780 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001781 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001782 c.onWindowReplacementTimeout();
1783 }
1784 }
1785 }
1786
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001787 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001788 void forceWindowsScaleableInTransaction(boolean force) {
1789 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1790 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1791 }
1792
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001793 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001794 }
1795
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001796 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001797 void removeImmediately() {
1798 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001799
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001800 if (mRemoved) {
1801 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001802 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1803 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001804 return;
1805 }
1806
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001807 mRemoved = true;
1808
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001809 mWillReplaceWindow = false;
1810 if (mReplacementWindow != null) {
1811 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1812 }
1813
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001814 if (mService.mInputMethodTarget == this) {
1815 mService.moveInputMethodWindowsIfNeededLocked(false);
1816 }
1817
1818 final int type = mAttrs.type;
1819 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
1820 final DisplayContent displaycontent = getDisplayContent();
1821 displaycontent.mTapExcludedWindows.remove(this);
1822 }
1823 mPolicy.removeWindowLw(this);
1824
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001825 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001826
Craig Mautner96868332012-12-04 14:29:11 -08001827 mWinAnimator.destroyDeferredSurfaceLocked();
1828 mWinAnimator.destroySurfaceLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001829 mSession.windowRemovedLocked();
1830 try {
1831 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1832 } catch (RuntimeException e) {
1833 // Ignore if it has already been removed (usually because
1834 // we are doing this as part of processing a death note.)
1835 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001836
1837 mService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001838 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001839
Wale Ogunwale571771c2016-08-26 13:18:50 -07001840 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001841 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001842 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001843 removeIfPossible(false /*keepVisibleDeadWindow*/);
1844 }
1845
Wale Ogunwale571771c2016-08-26 13:18:50 -07001846 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001847 mWindowRemovalAllowed = true;
1848 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1849 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1850
1851 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1852 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1853 "Starting window removed " + this);
1854
1855 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && this == mService.mCurrentFocus)
1856 Slog.v(TAG_WM, "Remove " + this + " client="
1857 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1858 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1859 + Debug.getCallers(5));
1860
1861 final long origId = Binder.clearCallingIdentity();
1862
1863 disposeInputChannel();
1864
1865 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1866 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1867 + " mAnimatingExit=" + mAnimatingExit
1868 + " mRemoveOnExit=" + mRemoveOnExit
1869 + " mHasSurface=" + mHasSurface
1870 + " surfaceShowing=" + mWinAnimator.getShown()
1871 + " isAnimationSet=" + mWinAnimator.isAnimationSet()
1872 + " app-animation="
1873 + (mAppToken != null ? mAppToken.mAppAnimator.animation : null)
1874 + " mWillReplaceWindow=" + mWillReplaceWindow
1875 + " inPendingTransaction="
1876 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
1877 + " mDisplayFrozen=" + mService.mDisplayFrozen
1878 + " callers=" + Debug.getCallers(6));
1879
1880 // Visibility of the removed window. Will be used later to update orientation later on.
1881 boolean wasVisible = false;
1882
1883 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1884 // window until the animation is done. If the display is frozen, just remove immediately,
1885 // since the animation wouldn't be seen.
1886 if (mHasSurface && mService.okToDisplay()) {
1887 if (mWillReplaceWindow) {
1888 // This window is going to be replaced. We need to keep it around until the new one
1889 // gets added, then we will get rid of this one.
1890 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1891 "Preserving " + this + " until the new one is " + "added");
1892 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1893 // been removed. We probably need another flag to indicate that window removal
1894 // should be deffered vs. overloading the flag that says we are playing an exit
1895 // animation.
1896 mAnimatingExit = true;
1897 mReplacingRemoveRequested = true;
1898 Binder.restoreCallingIdentity(origId);
1899 return;
1900 }
1901
1902 if (isAnimatingWithSavedSurface() && !mAppToken.allDrawnExcludingSaved) {
1903 // We started enter animation early with a saved surface, now the app asks to remove
1904 // this window. If we remove it now and the app is not yet drawn, we'll show a
1905 // flicker. Delay the removal now until it's really drawn.
1906 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
1907 "removeWindowLocked: delay removal of " + this + " due to early animation");
1908 // Do not set mAnimatingExit to true here, it will cause the surface to be hidden
1909 // immediately after the enter animation is done. If the app is not yet drawn then
1910 // it will show up as a flicker.
1911 setupWindowForRemoveOnExit();
1912 Binder.restoreCallingIdentity(origId);
1913 return;
1914 }
1915 // If we are not currently running the exit animation, we need to see about starting one
1916 wasVisible = isWinVisibleLw();
1917
1918 if (keepVisibleDeadWindow) {
1919 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1920 "Not removing " + this + " because app died while it's visible");
1921
1922 mAppDied = true;
1923 setDisplayLayoutNeeded();
1924 mService.mWindowPlacerLocked.performSurfacePlacement();
1925
1926 // Set up a replacement input channel since the app is now dead.
1927 // We need to catch tapping on the dead window to restart the app.
1928 openInputChannel(null);
1929 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
1930
1931 Binder.restoreCallingIdentity(origId);
1932 return;
1933 }
1934
1935 if (wasVisible) {
1936 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
1937
1938 // Try starting an animation.
1939 if (mWinAnimator.applyAnimationLocked(transit, false)) {
1940 mAnimatingExit = true;
1941 }
1942 //TODO (multidisplay): Magnification is supported only for the default display.
1943 if (mService.mAccessibilityController != null
1944 && getDisplayId() == Display.DEFAULT_DISPLAY) {
1945 mService.mAccessibilityController.onWindowTransitionLocked(this, transit);
1946 }
1947 }
1948 final boolean isAnimating =
1949 mWinAnimator.isAnimationSet() && !mWinAnimator.isDummyAnimation();
1950 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001951 && mAppToken.isLastWindow(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001952 // We delay the removal of a window if it has a showing surface that can be used to run
1953 // exit animation and it is marked as exiting.
1954 // Also, If isn't the an animating starting window that is the last window in the app.
1955 // We allow the removal of the non-animating starting window now as there is no
1956 // additional window or animation that will trigger its removal.
1957 if (mWinAnimator.getShown() && mAnimatingExit
1958 && (!lastWindowIsStartingWindow || isAnimating)) {
1959 // The exit animation is running or should run... wait for it!
1960 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1961 "Not removing " + this + " due to exit animation ");
1962 setupWindowForRemoveOnExit();
1963 if (mAppToken != null) {
1964 mAppToken.updateReportedVisibilityLocked();
1965 }
1966 Binder.restoreCallingIdentity(origId);
1967 return;
1968 }
1969 }
1970
Wale Ogunwale571771c2016-08-26 13:18:50 -07001971 removeImmediately();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001972 // Removing a visible window will effect the computed orientation
1973 // So just update orientation if needed.
1974 if (wasVisible && mService.updateOrientationFromAppTokensLocked(false)) {
1975 mService.mH.sendEmptyMessage(SEND_NEW_CONFIGURATION);
1976 }
1977 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
1978 Binder.restoreCallingIdentity(origId);
1979 }
1980
1981 private void setupWindowForRemoveOnExit() {
1982 mRemoveOnExit = true;
1983 setDisplayLayoutNeeded();
1984 // Request a focus update as this window's input channel is already gone. Otherwise
1985 // we could have no focused window in input manager.
1986 final boolean focusChanged = mService.updateFocusedWindowLocked(
1987 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
1988 mService.mWindowPlacerLocked.performSurfacePlacement();
1989 if (focusChanged) {
1990 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
1991 }
1992 }
1993
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001994 void setHasSurface(boolean hasSurface) {
1995 mHasSurface = hasSurface;
1996 }
1997
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001998 int getAnimLayerAdjustment() {
Wale Ogunwale455fac52016-07-21 07:24:49 -07001999 final boolean isImeType =
2000 mAttrs.type == TYPE_INPUT_METHOD || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
2001 if (isImeType && mService.mInputMethodTarget != null) {
2002 final AppWindowToken appToken = mService.mInputMethodTarget.mAppToken;
2003 if (appToken != null) {
2004 return appToken.mAppAnimator.animLayerAdjustment;
2005 }
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002006 }
Wale Ogunwale455fac52016-07-21 07:24:49 -07002007
2008 if (mAppToken != null) {
2009 return mAppToken.mAppAnimator.animLayerAdjustment;
2010 }
2011
2012 // Nothing is animating, so there is no animation adjustment.
2013 return 0;
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002014 }
2015
2016 void scheduleAnimationIfDimming() {
2017 if (mDisplayContent == null) {
2018 return;
2019 }
2020 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
2021 if (dimLayerUser != null && mDisplayContent.mDimLayerController.isDimming(
2022 dimLayerUser, mWinAnimator)) {
2023 // Force an animation pass just to update the mDimLayer layer.
2024 mService.scheduleAnimationLocked();
2025 }
2026 }
2027
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08002028 /**
2029 * Notifies this window that the corresponding task has just moved in the stack.
2030 * <p>
2031 * This is used to fix the following: If we moved in the stack, and if the last clip rect was
2032 * empty, meaning that our task was completely offscreen, we need to keep it invisible because
2033 * the actual app transition that updates the visibility is delayed by a few transactions.
2034 * Instead of messing around with the ordering and timing how transitions and transactions are
2035 * executed, we introduce this little hack which prevents this window of getting visible again
2036 * with the wrong bounds until the app transitions has started.
2037 * <p>
2038 * This method notifies the window about that we just moved in the stack so we can apply this
2039 * logic in {@link WindowStateAnimator#updateSurfaceWindowCrop}
2040 */
2041 void notifyMovedInStack() {
2042 mJustMovedInStack = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002043
2044 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002045 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002046 c.notifyMovedInStack();
2047 }
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08002048 }
2049
2050 /**
2051 * See {@link #notifyMovedInStack}.
2052 *
2053 * @return Whether we just got moved in the corresponding stack.
2054 */
2055 boolean hasJustMovedInStack() {
2056 return mJustMovedInStack;
2057 }
2058
2059 /**
2060 * Resets that we just moved in the corresponding stack. See {@link #notifyMovedInStack}.
2061 */
2062 void resetJustMovedInStack() {
2063 mJustMovedInStack = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002064
2065 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002066 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002067 c.resetJustMovedInStack();
2068 }
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08002069 }
2070
Chong Zhangacf11402015-11-04 16:23:10 -08002071 private final class DeadWindowEventReceiver extends InputEventReceiver {
2072 DeadWindowEventReceiver(InputChannel inputChannel) {
2073 super(inputChannel, mService.mH.getLooper());
2074 }
2075 @Override
2076 public void onInputEvent(InputEvent event) {
2077 finishInputEvent(event, true);
2078 }
2079 }
2080 /**
2081 * Dummy event receiver for windows that died visible.
2082 */
2083 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2084
Chong Zhang112eb8c2015-11-02 11:17:00 -08002085 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002086 if (mInputChannel != null) {
2087 throw new IllegalStateException("Window already has an input channel.");
2088 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002089 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002090 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2091 mInputChannel = inputChannels[0];
2092 mClientChannel = inputChannels[1];
2093 mInputWindowHandle.inputChannel = inputChannels[0];
2094 if (outInputChannel != null) {
2095 mClientChannel.transferTo(outInputChannel);
2096 mClientChannel.dispose();
2097 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002098 } else {
2099 // If the window died visible, we setup a dummy input channel, so that taps
2100 // can still detected by input monitor channel, and we can relaunch the app.
2101 // Create dummy event receiver that simply reports all events as handled.
2102 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002103 }
2104 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002105 }
2106
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002107 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002108 if (mDeadWindowEventReceiver != null) {
2109 mDeadWindowEventReceiver.dispose();
2110 mDeadWindowEventReceiver = null;
2111 }
2112
2113 // unregister server channel first otherwise it complains about broken channel
2114 if (mInputChannel != null) {
2115 mService.mInputManager.unregisterInputChannel(mInputChannel);
2116 mInputChannel.dispose();
2117 mInputChannel = null;
2118 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002119 if (mClientChannel != null) {
2120 mClientChannel.dispose();
2121 mClientChannel = null;
2122 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07002123 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002124 }
2125
Chong Zhang112eb8c2015-11-02 11:17:00 -08002126 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08002127 // When the app is terminated (eg. from Recents), the task might have already been
2128 // removed with the window pending removal. Don't apply dim in such cases, as there
2129 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
2130 final AppWindowToken token = mAppToken;
2131 if (token != null && token.removed) {
2132 return;
2133 }
2134
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002135 if (!mAnimatingExit && mAppDied) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08002136 // If app died visible, apply a dim over the window to indicate that it's inactive
2137 mDisplayContent.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
2138 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
Robert Carr9fe459d2016-04-07 23:32:28 -07002139 && mDisplayContent != null && !mAnimatingExit && isVisibleUnchecked()) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08002140 mDisplayContent.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07002141 }
2142 }
2143
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002144 DimLayer.DimLayerUser getDimLayerUser() {
2145 Task task = getTask();
2146 if (task != null) {
2147 return task;
2148 }
2149 return getStack();
2150 }
2151
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002152 /** Returns true if the replacement window was removed. */
2153 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2154 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2155 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2156 removeReplacedWindow();
2157 return true;
2158 }
2159
2160 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002161 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002162 if (c.removeReplacedWindowIfNeeded(replacement)) {
2163 return true;
2164 }
2165 }
2166 return false;
2167 }
2168
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002169 void removeReplacedWindow() {
2170 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
2171 if (isDimming()) {
2172 transferDimToReplacement();
Robert Carra1eb4392015-12-10 12:43:51 -08002173 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002174 mWillReplaceWindow = false;
2175 mAnimateReplacingWindow = false;
2176 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002177 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002178 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002179 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002180 }
2181 }
2182
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002183 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2184 boolean replacementSet = false;
2185
2186 if (mWillReplaceWindow && mReplacementWindow == null
2187 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2188
2189 mReplacementWindow = replacementCandidate;
2190 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2191 replacementSet = true;
2192 }
2193
2194 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002195 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002196 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2197 }
2198
2199 return replacementSet;
2200 }
2201
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002202 void setDisplayLayoutNeeded() {
2203 if (mDisplayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07002204 mDisplayContent.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002205 }
2206 }
2207
Robert Carrfed10072016-05-26 11:48:49 -07002208 // TODO: Strange usage of word workspace here and above.
2209 boolean inPinnedWorkspace() {
2210 final Task task = getTask();
2211 return task != null && task.inPinnedWorkspace();
2212 }
2213
Chong Zhang5117e272016-05-03 12:47:34 -07002214 void applyAdjustForImeIfNeeded() {
2215 final Task task = getTask();
2216 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2217 task.mStack.applyAdjustForImeIfNeeded(task);
2218 }
2219 }
2220
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002221 int getTouchableRegion(Region region, int flags) {
2222 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002223 if (modal && mAppToken != null) {
2224 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002225 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002226 // If this is a modal window we need to dismiss it if it's not full screen and the
2227 // touch happens outside of the frame that displays the content. This means we
2228 // need to intercept touches outside of that window. The dim layer user
2229 // associated with the window (task or stack) will give us the good bounds, as
2230 // they would be used to display the dim layer.
2231 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
2232 if (dimLayerUser != null) {
2233 dimLayerUser.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002234 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002235 getVisibleBounds(mTmpRect);
2236 }
2237 if (inFreeformWorkspace()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002238 // For freeform windows we the touch region to include the whole surface for the
2239 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002240 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2241 final int delta = WindowManagerService.dipToPixel(
2242 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2243 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002244 }
2245 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002246 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002247 } else {
2248 // Not modal or full screen modal
2249 getTouchableRegion(region);
2250 }
2251 return flags;
2252 }
2253
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002254 void checkPolicyVisibilityChange() {
2255 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2256 if (DEBUG_VISIBILITY) {
2257 Slog.v(TAG, "Policy visibility changing after anim in " +
2258 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2259 }
2260 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08002261 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002262 if (!mPolicyVisibility) {
2263 if (mService.mCurrentFocus == this) {
2264 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2265 "setAnimationLocked: setting mFocusMayChange true");
2266 mService.mFocusMayChange = true;
2267 }
2268 // Window is no longer visible -- make sure if we were waiting
2269 // for it to be displayed before enabling the display, that
2270 // we allow the display to be enabled now.
2271 mService.enableScreenIfNeededLocked();
2272 }
2273 }
2274 }
2275
2276 void setRequestedSize(int requestedWidth, int requestedHeight) {
2277 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2278 mLayoutNeeded = true;
2279 mRequestedWidth = requestedWidth;
2280 mRequestedHeight = requestedHeight;
2281 }
2282 }
2283
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002284 void prepareWindowToDisplayDuringRelayout(Configuration outConfig) {
2285 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2286 == SOFT_INPUT_ADJUST_RESIZE) {
2287 mLayoutNeeded = true;
2288 }
2289 if (isDrawnLw() && mService.okToDisplay()) {
2290 mWinAnimator.applyEnterAnimationLocked();
2291 }
2292 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
2293 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
2294 mTurnOnScreen = true;
2295 }
2296 if (isConfigChanged()) {
Robert Carrc24d8f92016-02-29 16:24:33 -08002297 final Configuration newConfig = updateConfiguration();
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002298 if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + this + " visible with new config: "
Robert Carrc24d8f92016-02-29 16:24:33 -08002299 + newConfig);
2300 outConfig.setTo(newConfig);
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002301 }
2302 }
2303
2304 void adjustStartingWindowFlags() {
2305 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2306 && mAppToken.startingWindow != null) {
2307 // Special handling of starting window over the base
2308 // window of the app: propagate lock screen flags to it,
2309 // to provide the correct semantics while starting.
2310 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2311 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2312 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2313 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2314 }
2315 }
2316
2317 void setWindowScale(int requestedWidth, int requestedHeight) {
2318 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2319
2320 if (scaledWindow) {
2321 // requested{Width|Height} Surface's physical size
2322 // attrs.{width|height} Size on screen
2323 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2324 mHScale = (mAttrs.width != requestedWidth) ?
2325 (mAttrs.width / (float)requestedWidth) : 1.0f;
2326 mVScale = (mAttrs.height != requestedHeight) ?
2327 (mAttrs.height / (float)requestedHeight) : 1.0f;
2328 } else {
2329 mHScale = mVScale = 1;
2330 }
2331 }
2332
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002333 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002334 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002335 public void binderDied() {
2336 try {
2337 synchronized(mService.mWindowMap) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002338 final WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002339 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002340 if (win != null) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002341 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002342 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2343 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002344 // just in case they have the divider at an unstable position. Better
2345 // also reset drag resizing state, because the owner can't do it
2346 // anymore.
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002347 final TaskStack stack = mService.mStackIdToStack.get(DOCKED_STACK_ID);
2348 if (stack != null) {
2349 stack.resetDockedStackToMiddle();
2350 }
Jorim Jaggidcb68142016-02-09 21:51:30 -08002351 mService.setDockedStackResizing(false);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002352 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002353 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002354 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002355 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002356 }
2357 }
2358 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002359 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002360 }
2361 }
2362 }
2363
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002364 /**
2365 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2366 * because we want to preserve its location on screen to be re-activated later when the user
2367 * interacts with it.
2368 */
2369 boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002370 if (!isWinVisibleLw() || mAppToken == null || mAppToken.clientHidden) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002371 // Not a visible app window or the app isn't dead.
2372 return false;
2373 }
2374
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002375 if (mAttrs.token != mClient.asBinder()) {
2376 // The window was add by a client using another client's app token. We don't want to
2377 // keep the dead window around for this case since this is meant for 'real' apps.
2378 return false;
2379 }
2380
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002381 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2382 // We don't keep starting windows since they were added by the window manager before
2383 // the app even launched.
2384 return false;
2385 }
2386
2387 final TaskStack stack = getStack();
2388 return stack != null && StackId.keepVisibleDeadAppWindowOnScreen(stack.mStackId);
2389 }
2390
Wale Ogunwaled045c822015-12-02 09:14:28 -08002391 /** @return true if this window desires key events. */
2392 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002393 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002394 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002395 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002396 && (mAppToken == null || mAppToken.windowsAreFocusable())
2397 && !isAdjustedForMinimizedDock();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002398 }
2399
Craig Mautner749a7bb2012-04-02 13:49:53 -07002400 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002401 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002402 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002403 }
2404
Craig Mautner749a7bb2012-04-02 13:49:53 -07002405 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002406 public boolean showLw(boolean doAnimation) {
2407 return showLw(doAnimation, true);
2408 }
2409
2410 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002411 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002412 return false;
2413 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002414 if (!mAppOpVisibility) {
2415 // Being hidden due to app op request.
2416 return false;
2417 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002418 if (mPermanentlyHidden) {
2419 // Permanently hidden until the app exists as apps aren't prepared
2420 // to handle their windows being removed from under them.
2421 return false;
2422 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002423 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002424 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002425 return false;
2426 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002427 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002428 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002429 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07002430 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07002431 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002432 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07002433 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002434 // Check for the case where we are currently visible and
2435 // not animating; we do not want to do animation at such a
2436 // point to become visible when we already are.
2437 doAnimation = false;
2438 }
2439 }
2440 mPolicyVisibility = true;
2441 mPolicyVisibilityAfterAnim = true;
2442 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002443 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002444 }
2445 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002446 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002447 }
2448 return true;
2449 }
2450
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002451 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002452 public boolean hideLw(boolean doAnimation) {
2453 return hideLw(doAnimation, true);
2454 }
2455
2456 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2457 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07002458 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002459 doAnimation = false;
2460 }
2461 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002462 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002463 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002464 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002465 return false;
2466 }
2467 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002468 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07002469 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002470 doAnimation = false;
2471 }
2472 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002473 mPolicyVisibilityAfterAnim = false;
2474 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002475 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002476 mPolicyVisibility = false;
2477 // Window is no longer visible -- make sure if we were waiting
2478 // for it to be displayed before enabling the display, that
2479 // we allow the display to be enabled now.
2480 mService.enableScreenIfNeededLocked();
2481 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002482 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002483 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002484 mService.mFocusMayChange = true;
2485 }
2486 }
2487 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002488 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002489 }
2490 return true;
2491 }
2492
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002493 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002494 if (mAppOpVisibility != state) {
2495 mAppOpVisibility = state;
2496 if (state) {
2497 // If the policy visibility had last been to hide, then this
2498 // will incorrectly show at this point since we lost that
2499 // information. Not a big deal -- for the windows that have app
2500 // ops modifies they should only be hidden by policy due to the
2501 // lock screen, and the user won't be changing this if locked.
2502 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002503 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002504 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002505 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002506 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002507 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002508 }
2509
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002510 public void hidePermanentlyLw() {
2511 if (!mPermanentlyHidden) {
2512 mPermanentlyHidden = true;
2513 hideLw(true, true);
2514 }
2515 }
2516
Jeff Brownc2932a12014-11-20 18:04:05 -08002517 public void pokeDrawLockLw(long timeout) {
2518 if (isVisibleOrAdding()) {
2519 if (mDrawLock == null) {
2520 // We want the tag name to be somewhat stable so that it is easier to correlate
2521 // in wake lock statistics. So in particular, we don't want to include the
2522 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002523 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08002524 mDrawLock = mService.mPowerManager.newWakeLock(
2525 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
2526 mDrawLock.setReferenceCounted(false);
2527 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2528 }
2529 // Each call to acquire resets the timeout.
2530 if (DEBUG_POWER) {
2531 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2532 + mAttrs.packageName);
2533 }
2534 mDrawLock.acquire(timeout);
2535 } else if (DEBUG_POWER) {
2536 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2537 + "owned by " + mAttrs.packageName);
2538 }
2539 }
2540
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002541 @Override
2542 public boolean isAlive() {
2543 return mClient.asBinder().isBinderAlive();
2544 }
2545
Craig Mautnera987d432012-10-11 14:07:58 -07002546 boolean isClosing() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002547 return mAnimatingExit || (mService.mClosingApps.contains(mAppToken));
Craig Mautnera987d432012-10-11 14:07:58 -07002548 }
2549
Chong Zhangbef461f2015-10-27 11:38:24 -07002550 boolean isAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002551 return mAnimatingWithSavedSurface;
2552 }
2553
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002554 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002555 boolean isAnimating() {
2556 if (mWinAnimator.isAnimationSet() || mAnimatingExit) {
2557 return true;
2558 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002559 return super.isAnimating();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002560 }
2561
Chong Zhang8e4bda92016-05-04 15:08:18 -07002562 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002563 if (mAnimatingWithSavedSurface
2564 && (mViewVisibility != View.VISIBLE || mWindowRemovalAllowed)) {
2565 return true;
2566 }
2567 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002568 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002569 if (c.isAnimatingInvisibleWithSavedSurface()) {
2570 return true;
2571 }
2572 }
2573 return false;
2574 }
2575
2576 void stopUsingSavedSurface() {
2577 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002578 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002579 c.stopUsingSavedSurface();
2580 }
2581
2582 if (!isAnimatingInvisibleWithSavedSurface()) {
2583 return;
2584 }
2585
2586 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG, "stopUsingSavedSurface: " + this);
2587 clearAnimatingWithSavedSurface();
2588 mDestroying = true;
2589 mWinAnimator.hide("stopUsingSavedSurface");
2590 mService.mWallpaperControllerLocked.hideWallpapers(this);
2591 }
2592
2593 void markSavedSurfaceExiting() {
2594 if (isAnimatingInvisibleWithSavedSurface()) {
2595 mAnimatingExit = true;
2596 mWinAnimator.mAnimating = true;
2597 }
2598 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002599 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002600 c.markSavedSurfaceExiting();
2601 }
2602 }
2603
2604 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2605 animators.add(mWinAnimator);
2606
2607 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002608 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002609 c.addWinAnimatorToList(animators);
2610 }
2611 }
2612
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002613 void sendAppVisibilityToClients() {
2614 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002615
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002616 final boolean clientHidden = mAppToken.clientHidden;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002617 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2618 // Don't hide the starting window.
2619 return;
2620 }
2621
2622 try {
2623 if (DEBUG_VISIBILITY) Slog.v(TAG,
2624 "Setting visibility of " + this + ": " + (!clientHidden));
2625 mClient.dispatchAppVisibility(!clientHidden);
2626 } catch (RemoteException e) {
2627 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002628 }
2629
Chong Zhang92147042016-05-09 12:47:11 -07002630 public void setVisibleBeforeClientHidden() {
2631 mWasVisibleBeforeClientHidden |=
2632 (mViewVisibility == View.VISIBLE || mAnimatingWithSavedSurface);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002633
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002634 super.setVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -07002635 }
2636
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002637 public void clearWasVisibleBeforeClientHidden() {
Chong Zhang92147042016-05-09 12:47:11 -07002638 mWasVisibleBeforeClientHidden = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002639 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002640 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002641 c.clearWasVisibleBeforeClientHidden();
2642 }
Chong Zhang92147042016-05-09 12:47:11 -07002643 }
2644
2645 public boolean wasVisibleBeforeClientHidden() {
2646 return mWasVisibleBeforeClientHidden;
Chong Zhangbef461f2015-10-27 11:38:24 -07002647 }
2648
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002649 void onStartFreezingScreen() {
2650 mAppFreezing = true;
2651 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002652 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002653 c.onStartFreezingScreen();
2654 }
2655 }
2656
2657 boolean onStopFreezingScreen() {
2658 boolean unfrozeWindows = false;
2659 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002660 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002661 unfrozeWindows |= c.onStopFreezingScreen();
2662 }
2663
2664 if (!mAppFreezing) {
2665 return unfrozeWindows;
2666 }
2667
Wale Ogunwale953171d2016-09-30 09:17:30 -07002668 mAppFreezing = false;
2669
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002670 if (mHasSurface && !mOrientationChanging
2671 && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
2672 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
2673 mOrientationChanging = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002674 mService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002675 }
2676 mLastFreezeDuration = 0;
2677 setDisplayLayoutNeeded();
2678 return true;
2679 }
2680
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002681 private boolean shouldSaveSurface() {
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002682 if (mWinAnimator.mSurfaceController == null) {
2683 // Don't bother if the surface controller is gone for any reason.
2684 return false;
2685 }
2686
Chong Zhang92147042016-05-09 12:47:11 -07002687 if (!mWasVisibleBeforeClientHidden) {
2688 return false;
2689 }
2690
Wale Ogunwale945d1972016-03-23 13:16:41 -07002691 if ((mAttrs.flags & FLAG_SECURE) != 0) {
2692 // We don't save secure surfaces since their content shouldn't be shown while the app
2693 // isn't on screen and content might leak through during the transition animation with
2694 // saved surface.
2695 return false;
2696 }
2697
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002698 if (ActivityManager.isLowRamDeviceStatic()) {
2699 // Don't save surfaces on Svelte devices.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002700 return false;
2701 }
2702
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002703 Task task = getTask();
2704 if (task == null || task.inHomeStack()) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002705 // Don't save surfaces for home stack apps. These usually resume and draw
2706 // first frame very fast. Saving surfaces are mostly a waste of memory.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002707 return false;
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002708 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002709
2710 final AppWindowToken taskTop = task.getTopVisibleAppToken();
2711 if (taskTop != null && taskTop != mAppToken) {
2712 // Don't save if the window is not the topmost window.
2713 return false;
2714 }
2715
Jorim Jaggi8fa45222016-02-19 19:54:39 -08002716 if (mResizedWhileGone) {
2717 // Somebody resized our window while we were gone for layout, which means that the
2718 // client got an old size, so we have an outdated surface here.
2719 return false;
2720 }
2721
Robert Carr7098dbd2016-02-01 12:31:01 -08002722 if (DEBUG_DISABLE_SAVING_SURFACES) {
2723 return false;
2724 }
2725
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002726 return mAppToken.shouldSaveSurface();
2727 }
2728
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002729 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2730 boolean destroyedSomething = false;
2731 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002732 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002733 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2734 }
2735
2736 if (appStopped || mWindowRemovalAllowed || cleanupOnResume) {
2737
2738 mWinAnimator.destroyPreservedSurfaceLocked();
2739
2740 if (mDestroying) {
2741 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2742 + " destroySurfaces: appStopped=" + appStopped
2743 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2744 + " win.mRemoveOnExit=" + mRemoveOnExit);
2745
2746 if (!cleanupOnResume || mRemoveOnExit) {
2747 destroyOrSaveSurface();
2748 }
2749 if (mRemoveOnExit) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002750 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002751 }
2752 if (cleanupOnResume) {
2753 requestUpdateWallpaperIfNeeded();
2754 }
2755 mDestroying = false;
2756 destroyedSomething = true;
2757 }
2758 }
2759 return destroyedSomething;
2760 }
Chris Craik3131bde2016-05-06 13:39:08 -07002761
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002762 void destroyOrSaveSurface() {
2763 mSurfaceSaved = shouldSaveSurface();
2764 if (mSurfaceSaved) {
2765 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2766 Slog.v(TAG, "Saving surface: " + this);
2767 }
Chris Craik3131bde2016-05-06 13:39:08 -07002768 // Previous user of the surface may have set a transparent region signaling a portion
2769 // doesn't need to be composited, so reset to default empty state.
2770 mSession.setTransparentRegion(mClient, sEmptyRegion);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002771
2772 mWinAnimator.hide("saved surface");
2773 mWinAnimator.mDrawState = WindowStateAnimator.NO_SURFACE;
2774 setHasSurface(false);
Chong Zhang47e36a32016-02-29 16:44:33 -08002775 // The client should have disconnected at this point, but if it doesn't,
2776 // we need to make sure it's disconnected. Otherwise when we reuse the surface
2777 // the client can't reconnect to the buffer queue, and rendering will fail.
2778 if (mWinAnimator.mSurfaceController != null) {
2779 mWinAnimator.mSurfaceController.disconnectInTransaction();
2780 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002781 mAnimatingWithSavedSurface = false;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002782 } else {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002783 mWinAnimator.destroySurfaceLocked();
2784 }
Chong Zhang92147042016-05-09 12:47:11 -07002785 // Clear animating flags now, since the surface is now gone. (Note this is true even
2786 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2787 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002788 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002789
Chong Zhang92147042016-05-09 12:47:11 -07002790 void destroySavedSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002791 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002792 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002793 c.destroySavedSurface();
2794 }
2795
Robert Carr13f7be9e2015-12-02 18:39:45 -08002796 if (mSurfaceSaved) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002797 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, "Destroying saved surface: " + this);
Robert Carr13f7be9e2015-12-02 18:39:45 -08002798 mWinAnimator.destroySurfaceLocked();
Robert Carr237028a2016-07-26 10:39:45 -07002799 mSurfaceSaved = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002800 }
Chong Zhang92147042016-05-09 12:47:11 -07002801 mWasVisibleBeforeClientHidden = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002802 }
2803
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002804 /** Returns -1 if there are no interesting windows or number of interesting windows not drawn.*/
2805 int restoreSavedSurfaceForInterestingWindow() {
2806 int interestingNotDrawn = -1;
2807 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002808 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002809 final int childInterestingNotDrawn = c.restoreSavedSurfaceForInterestingWindow();
2810 if (childInterestingNotDrawn != -1) {
2811 if (interestingNotDrawn == -1) {
2812 interestingNotDrawn = childInterestingNotDrawn;
2813 } else {
2814 interestingNotDrawn += childInterestingNotDrawn;
2815 }
2816 }
Chong Zhang4113ffa2016-02-18 12:39:13 -08002817 }
Robert Carr237028a2016-07-26 10:39:45 -07002818
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002819 if (mAttrs.type == TYPE_APPLICATION_STARTING
2820 || mAppDied || !wasVisibleBeforeClientHidden()
2821 || (mAppToken.mAppAnimator.freezingScreen && mAppFreezing)) {
2822 // Window isn't interesting...
2823 return interestingNotDrawn;
2824 }
2825
2826 restoreSavedSurface();
2827
2828 if (!isDrawnLw()) {
2829 if (interestingNotDrawn == -1) {
2830 interestingNotDrawn = 1;
2831 } else {
2832 interestingNotDrawn++;
2833 }
2834 }
2835 return interestingNotDrawn;
2836 }
2837
2838 /** Returns true if the saved surface was restored. */
2839 boolean restoreSavedSurface() {
2840 if (!mSurfaceSaved) {
2841 return false;
2842 }
2843
2844 // Sometimes we save surfaces due to layout invisible directly after rotation occurs.
2845 // However this means the surface was never laid out in the new orientation.
2846 // We can only restore to the last rotation we were laid out as visible in.
Robert Carr237028a2016-07-26 10:39:45 -07002847 if (mLastVisibleLayoutRotation != mService.mRotation) {
2848 destroySavedSurface();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002849 return false;
Robert Carr237028a2016-07-26 10:39:45 -07002850 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002851 mSurfaceSaved = false;
Robert Carr237028a2016-07-26 10:39:45 -07002852
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002853 if (mWinAnimator.mSurfaceController != null) {
2854 setHasSurface(true);
Wale Ogunwale9d147902016-07-16 11:58:55 -07002855 mWinAnimator.mDrawState = READY_TO_SHOW;
Chong Zhang92147042016-05-09 12:47:11 -07002856 mAnimatingWithSavedSurface = true;
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002857
Chong Zhang6e9872b2016-08-17 10:19:05 -07002858 requestUpdateWallpaperIfNeeded();
2859
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002860 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2861 Slog.v(TAG, "Restoring saved surface: " + this);
2862 }
2863 } else {
2864 // mSurfaceController shouldn't be null if mSurfaceSaved was still true at
2865 // this point. Even if we destroyed the saved surface because of rotation
2866 // or resize, mSurfaceSaved flag should have been cleared. So this is a wtf.
2867 Slog.wtf(TAG, "Failed to restore saved surface: surface gone! " + this);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002868 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002869
2870 return true;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002871 }
2872
Chong Zhang92147042016-05-09 12:47:11 -07002873 boolean canRestoreSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002874 if (mWasVisibleBeforeClientHidden && mSurfaceSaved) {
2875 return true;
2876 }
2877
2878 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002879 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002880 if (c.canRestoreSurface()) {
2881 return true;
2882 }
2883 }
2884
2885 return false;
Chong Zhang92147042016-05-09 12:47:11 -07002886 }
2887
2888 boolean hasSavedSurface() {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002889 return mSurfaceSaved;
2890 }
2891
Chong Zhang92147042016-05-09 12:47:11 -07002892 void clearHasSavedSurface() {
2893 mSurfaceSaved = false;
2894 mAnimatingWithSavedSurface = false;
Chong Zhangf58631a2016-05-24 16:02:10 -07002895 if (mWasVisibleBeforeClientHidden) {
2896 mAppToken.destroySavedSurfaces();
2897 }
Chong Zhang92147042016-05-09 12:47:11 -07002898 }
2899
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002900 boolean clearAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002901 if (mAnimatingWithSavedSurface) {
2902 // App has drawn something to its windows, we're no longer animating with
2903 // the saved surfaces.
2904 if (DEBUG_ANIM) Slog.d(TAG,
2905 "clearAnimatingWithSavedSurface(): win=" + this);
2906 mAnimatingWithSavedSurface = false;
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002907 return true;
Chong Zhang92147042016-05-09 12:47:11 -07002908 }
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002909 return false;
Chong Zhang92147042016-05-09 12:47:11 -07002910 }
2911
Craig Mautner69b08182012-09-05 13:07:13 -07002912 @Override
2913 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002914 final DisplayContent displayContent = getDisplayContent();
2915 if (displayContent == null) {
2916 // Only a window that was on a non-default display can be detached from it.
2917 return false;
2918 }
Winson Chung47a3e652014-05-21 16:03:42 -07002919 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002920 }
2921
Adrian Rooscd3884d2015-02-18 17:25:23 +01002922 @Override
2923 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002924 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
2925 return dimLayerUser != null && mDisplayContent != null &&
Chong Zhang112eb8c2015-11-02 11:17:00 -08002926 mDisplayContent.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01002927 }
2928
Craig Mautner88400d32012-09-30 12:35:45 -07002929 public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
2930 mShowToOwnerOnly = showToOwnerOnly;
2931 }
2932
Craig Mautner5962b122012-10-05 14:45:52 -07002933 boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002934 // Child windows are evaluated based on their parent window.
2935 final WindowState win = getTopParentWindow();
Craig Mautner341220f2012-10-16 15:20:09 -07002936 if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
Wale Ogunwale6dfdfd62015-04-15 12:01:38 -07002937 && win.mAppToken != null && win.mAppToken.showForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002938
2939 // All window frames that are fullscreen extend above status bar, but some don't extend
2940 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2941 // bottom right.
2942 if (win.mFrame.left <= win.mDisplayFrame.left
2943 && win.mFrame.top <= win.mDisplayFrame.top
2944 && win.mFrame.right >= win.mStableFrame.right
2945 && win.mFrame.bottom >= win.mStableFrame.bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002946 // Is a fullscreen window, like the clock alarm. Show to everyone.
2947 return false;
2948 }
2949 }
2950
Craig Mautner341220f2012-10-16 15:20:09 -07002951 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01002952 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002953 }
2954
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002955 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2956 outRegion.set(
2957 frame.left + inset.left, frame.top + inset.top,
2958 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002959 }
2960
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002961 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002962 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002963 switch (mTouchableInsets) {
2964 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002965 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002966 outRegion.set(frame);
2967 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002968 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002969 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002970 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002971 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002972 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002973 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002974 case TOUCHABLE_INSETS_REGION: {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002975 final Region givenTouchableRegion = mGivenTouchableRegion;
2976 outRegion.set(givenTouchableRegion);
2977 outRegion.translate(frame.left, frame.top);
2978 break;
2979 }
2980 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002981 cropRegionToStackBoundsIfNeeded(outRegion);
2982 }
2983
2984 void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002985 final Task task = getTask();
2986 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002987 return;
2988 }
2989
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002990 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002991 if (stack == null) {
2992 return;
2993 }
2994
2995 stack.getDimBounds(mTmpRect);
2996 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002997 }
2998
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002999 // TODO: This is one reason why WindowList are bad...prime candidate for removal once we
3000 // figure-out a good way to replace WindowList with WindowContainer hierarchy.
Craig Mautner59c00972012-07-30 12:10:24 -07003001 WindowList getWindowList() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08003002 final DisplayContent displayContent = getDisplayContent();
3003 return displayContent == null ? null : displayContent.getWindowList();
Craig Mautner59c00972012-07-30 12:10:24 -07003004 }
3005
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003006 /**
3007 * Report a focus change. Must be called with no locks held, and consistently
3008 * from the same serialized thread (such as dispatched from a handler).
3009 */
3010 public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
3011 try {
3012 mClient.windowFocusChanged(focused, inTouchMode);
3013 } catch (RemoteException e) {
3014 }
3015 if (mFocusCallbacks != null) {
3016 final int N = mFocusCallbacks.beginBroadcast();
3017 for (int i=0; i<N; i++) {
3018 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
3019 try {
3020 if (focused) {
3021 obs.focusGained(mWindowId.asBinder());
3022 } else {
3023 obs.focusLost(mWindowId.asBinder());
3024 }
3025 } catch (RemoteException e) {
3026 }
3027 }
3028 mFocusCallbacks.finishBroadcast();
3029 }
3030 }
3031
Robert Carrc24d8f92016-02-29 16:24:33 -08003032 /**
3033 * Update our current configurations, based on task configuration.
3034 *
3035 * @return A configuration suitable for sending to the client.
3036 */
3037 private Configuration updateConfiguration() {
Robert Carrc24d8f92016-02-29 16:24:33 -08003038 final boolean configChanged = isConfigChanged();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003039 getMergedConfig(mMergedConfiguration);
3040 mConfigHasChanged = false;
Robert Carrc24d8f92016-02-29 16:24:33 -08003041 if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) && configChanged) {
3042 Slog.i(TAG, "Sending new config to window " + this + ": " +
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003043 " / mergedConfig=" + mMergedConfiguration);
Robert Carrc24d8f92016-02-29 16:24:33 -08003044 }
Robert Carrc24d8f92016-02-29 16:24:33 -08003045 return mMergedConfiguration;
3046 }
3047
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003048 private void getMergedConfig(Configuration outConfig) {
3049 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
3050 outConfig.setTo(mAppToken.mFrozenMergedConfig.peek());
3051 return;
3052 }
Andrii Kulian441e4492016-09-29 15:25:00 -07003053 outConfig.setTo(
3054 mAppToken != null ? getConfiguration() : mDisplayContent.getConfiguration());
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003055 }
3056
Craig Mautnerdf88d732014-01-27 09:21:32 -08003057 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003058 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08003059 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003060 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
3061 + ": " + mCompatFrame);
Robert Carrc24d8f92016-02-29 16:24:33 -08003062 final Configuration newConfig = isConfigChanged() ? updateConfiguration() : null;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003063 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING)
3064 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
3065
Craig Mautnerdf88d732014-01-27 09:21:32 -08003066 final Rect frame = mFrame;
3067 final Rect overscanInsets = mLastOverscanInsets;
3068 final Rect contentInsets = mLastContentInsets;
3069 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07003070 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003071 final Rect outsets = mLastOutsets;
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003072 final boolean reportDraw = mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING;
Chet Haase8eb48d22014-09-24 07:31:29 -07003073 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
3074 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08003075 // To prevent deadlock simulate one-way call if win.mClient is a local object.
3076 mService.mH.post(new Runnable() {
3077 @Override
3078 public void run() {
3079 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003080 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
3081 stableInsets, outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003082 } catch (RemoteException e) {
3083 // Not a remote call, RemoteException won't be raised.
3084 }
3085 }
3086 });
3087 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003088 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003089 outsets, reportDraw, newConfig);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003090 }
Svetoslav4604abc2014-06-10 18:59:30 -07003091
3092 //TODO (multidisplay): Accessibility supported only for the default display.
3093 if (mService.mAccessibilityController != null
3094 && getDisplayId() == Display.DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07003095 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07003096 }
3097
Craig Mautnerdf88d732014-01-27 09:21:32 -08003098 mOverscanInsetsChanged = false;
3099 mContentInsetsChanged = false;
3100 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07003101 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003102 mOutsetsChanged = false;
Robert Carr31aa98b2016-07-20 15:29:03 -07003103 mFrameSizeChanged = false;
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003104 mResizedWhileNotDragResizingReported = true;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003105 mWinAnimator.mSurfaceResized = false;
3106 } catch (RemoteException e) {
3107 mOrientationChanging = false;
3108 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
3109 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08003110 // We are assuming the hosting process is dead or in a zombie state.
3111 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
3112 + ", removing this window.");
3113 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07003114 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003115 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003116 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003117 }
3118
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003119 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08003120 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
3121 // start even if we haven't received the relayout window, so that the client requests
3122 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
3123 // until the window to small size, otherwise the multithread renderer will shift last
3124 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
3125 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003126 boolean resizing = isDragResizing() || isDragResizeChanged();
3127 if (StackId.useWindowFrameForBackdrop(getStackId()) || !resizing) {
3128 return frame;
3129 }
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003130 DisplayInfo displayInfo = getDisplayInfo();
3131 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003132 return mTmpRect;
3133 }
3134
Jorim Jaggi86905582016-02-09 21:36:09 -08003135 @Override
3136 public int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003137 final TaskStack stack = getStack();
3138 if (stack == null) {
3139 return INVALID_STACK_ID;
3140 }
3141 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003142 }
3143
3144 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
3145 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
3146 Configuration newConfig) throws RemoteException {
Chong Zhangedaf3052016-04-22 15:04:31 -07003147 final boolean forceRelayout = isDragResizeChanged() || mResizedWhileNotDragResizing;
3148
Jorim Jaggidc249c42015-12-15 14:57:31 -08003149 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Jorim Jaggia4a58ef2016-01-27 02:10:08 -08003150 reportDraw, newConfig, getBackdropFrame(frame),
Chong Zhangedaf3052016-04-22 15:04:31 -07003151 forceRelayout, mPolicy.isNavBarForcedShownLw(this));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003152 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003153 }
3154
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003155 public void registerFocusObserver(IWindowFocusObserver observer) {
3156 synchronized(mService.mWindowMap) {
3157 if (mFocusCallbacks == null) {
3158 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
3159 }
3160 mFocusCallbacks.register(observer);
3161 }
3162 }
3163
3164 public void unregisterFocusObserver(IWindowFocusObserver observer) {
3165 synchronized(mService.mWindowMap) {
3166 if (mFocusCallbacks != null) {
3167 mFocusCallbacks.unregister(observer);
3168 }
3169 }
3170 }
3171
3172 public boolean isFocused() {
3173 synchronized(mService.mWindowMap) {
3174 return mService.mCurrentFocus == this;
3175 }
3176 }
3177
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07003178 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003179 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07003180 return task != null && task.inFreeformWorkspace();
3181 }
3182
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003183 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07003184 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003185 final Task task = getTask();
3186 return task != null && !task.isFullscreen();
3187 }
3188
Chong Zhang3005e752015-09-18 18:46:28 -07003189 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003190 return mDragResizing != computeDragResizing();
3191 }
3192
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003193 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003194 void setWaitingForDrawnIfResizingChanged() {
3195 if (isDragResizeChanged()) {
3196 mService.mWaitingForDrawn.add(this);
3197 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003198 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003199 }
3200
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003201 /**
3202 * @return Whether we reported a drag resize change to the application or not already.
3203 */
3204 boolean isDragResizingChangeReported() {
3205 return mDragResizingChangeReported;
3206 }
3207
3208 /**
3209 * Resets the state whether we reported a drag resize change to the app.
3210 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003211 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003212 void resetDragResizingChangeReported() {
3213 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003214 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003215 }
3216
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003217 /**
3218 * Set whether we got resized but drag resizing flag was false.
3219 * @see #isResizedWhileNotDragResizing().
3220 */
3221 void setResizedWhileNotDragResizing(boolean resizedWhileNotDragResizing) {
3222 mResizedWhileNotDragResizing = resizedWhileNotDragResizing;
3223 mResizedWhileNotDragResizingReported = !resizedWhileNotDragResizing;
3224 }
3225
3226 /**
3227 * Indicates whether we got resized but drag resizing flag was false. In this case, we also
3228 * need to recreate the surface and defer surface bound updates in order to make sure the
3229 * buffer contents and the positioning/size stay in sync.
3230 */
3231 boolean isResizedWhileNotDragResizing() {
3232 return mResizedWhileNotDragResizing;
3233 }
3234
3235 /**
3236 * @return Whether we reported "resize while not drag resizing" to the application.
3237 * @see #isResizedWhileNotDragResizing()
3238 */
3239 boolean isResizedWhileNotDragResizingReported() {
3240 return mResizedWhileNotDragResizingReported;
3241 }
3242
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003243 int getResizeMode() {
3244 return mResizeMode;
3245 }
3246
Jorim Jaggi192086e2016-03-11 17:17:03 +01003247 boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003248 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003249 if (task == null) {
3250 return false;
3251 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003252 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
3253
3254 // Floating windows never enter drag resize mode.
3255 return false;
3256 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003257 if (task.isDragResizing()) {
3258 return true;
3259 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003260
3261 // If the bounds are currently frozen, it means that the layout size that the app sees
3262 // and the bounds we clip this window to might be different. In order to avoid holes, we
3263 // simulate that we are still resizing so the app fills the hole with the resizing
3264 // background.
3265 return (mDisplayContent.mDividerControllerLocked.isResizing()
3266 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Jorim Jaggi899327f2016-02-25 20:44:18 -05003267 !task.inFreeformWorkspace() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003268
Chong Zhang3005e752015-09-18 18:46:28 -07003269 }
3270
3271 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003272 final boolean resizing = computeDragResizing();
3273 if (resizing == mDragResizing) {
3274 return;
3275 }
3276 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003277 final Task task = getTask();
3278 if (task != null && task.isDragResizing()) {
3279 mResizeMode = task.getDragResizeMode();
3280 } else {
3281 mResizeMode = mDragResizing && mDisplayContent.mDividerControllerLocked.isResizing()
3282 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3283 : DRAG_RESIZE_MODE_FREEFORM;
3284 }
Chong Zhang3005e752015-09-18 18:46:28 -07003285 }
3286
3287 boolean isDragResizing() {
3288 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003289 }
3290
Robert Carr2487ce72016-04-07 15:18:45 -07003291 boolean isDockedResizing() {
3292 return mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
3293 }
3294
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003295 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003296 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003297 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003298 if (stack != null) {
3299 pw.print(" stackId="); pw.print(stack.mStackId);
3300 }
Wale Ogunwale4c5aa5172016-04-19 11:29:05 -07003301 if (mNotOnAppsDisplay) {
3302 pw.print(" mNotOnAppsDisplay="); pw.print(mNotOnAppsDisplay);
3303 }
Craig Mautner59c00972012-07-30 12:10:24 -07003304 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003305 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07003306 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08003307 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
3308 pw.print(" package="); pw.print(mAttrs.packageName);
3309 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003310 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003311 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
3312 pw.print(" h="); pw.print(mRequestedHeight);
3313 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003314 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
3315 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
3316 pw.print(" h="); pw.println(mLastRequestedHeight);
3317 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003318 if (mIsChildWindow || mLayoutAttached) {
3319 pw.print(prefix); pw.print("mParentWindow="); pw.print(getParentWindow());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003320 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
3321 }
3322 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
3323 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
3324 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
3325 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
3326 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
3327 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003328 if (dumpAll) {
3329 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3330 pw.print(" mSubLayer="); pw.print(mSubLayer);
3331 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Wale Ogunwale455fac52016-07-21 07:24:49 -07003332 pw.print(getAnimLayerAdjustment());
Craig Mautnerc2f9be02012-03-27 17:32:29 -07003333 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
3334 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003335 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003336 if (dumpAll) {
3337 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003338 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003339 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
3340 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08003341 pw.print(isAnimatingWithSavedSurface());
Chong Zhang112eb8c2015-11-02 11:17:00 -08003342 pw.print(" mAppDied=");pw.println(mAppDied);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003343 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003344 pw.print(prefix); pw.print("mViewVisibility=0x");
3345 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003346 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
3347 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07003348 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
3349 pw.print(" mSystemUiVisibility=0x");
3350 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003351 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003352 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
Svetoslav Ganov71c51022016-09-02 17:54:37 -07003353 || isParentWindowHidden()|| mPermanentlyHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003354 pw.print(prefix); pw.print("mPolicyVisibility=");
3355 pw.print(mPolicyVisibility);
3356 pw.print(" mPolicyVisibilityAfterAnim=");
3357 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003358 pw.print(" mAppOpVisibility=");
3359 pw.print(mAppOpVisibility);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003360 pw.print(" parentHidden="); pw.println(isParentWindowHidden());
Svetoslav Ganovaa076532016-08-01 19:16:43 -07003361 pw.print(" mPermanentlyHidden="); pw.println(mPermanentlyHidden);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003362 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003363 if (!mRelayoutCalled || mLayoutNeeded) {
3364 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
3365 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003366 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003367 if (mXOffset != 0 || mYOffset != 0) {
3368 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
3369 pw.print(" y="); pw.println(mYOffset);
3370 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003371 if (dumpAll) {
3372 pw.print(prefix); pw.print("mGivenContentInsets=");
3373 mGivenContentInsets.printShortString(pw);
3374 pw.print(" mGivenVisibleInsets=");
3375 mGivenVisibleInsets.printShortString(pw);
3376 pw.println();
3377 if (mTouchableInsets != 0 || mGivenInsetsPending) {
3378 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
3379 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003380 Region region = new Region();
3381 getTouchableRegion(region);
3382 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003383 }
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003384 pw.print(prefix); pw.print("mMergedConfiguration="); pw.println(mMergedConfiguration);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003385 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07003386 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07003387 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Chong Zhanga8975bd2016-01-28 17:13:47 -08003388 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08003389 pw.print(" hasSavedSurface()="); pw.print(hasSavedSurface());
3390 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003391 if (dumpAll) {
3392 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
3393 pw.print(" last="); mLastFrame.printShortString(pw);
3394 pw.println();
3395 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003396 if (mEnforceSizeCompat) {
3397 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003398 pw.println();
3399 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003400 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003401 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003402 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003403 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003404 pw.println();
3405 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
3406 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003407 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003408 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003409 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003410 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04003411 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
3412 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003413 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
3414 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003415 pw.print(prefix); pw.print("Cur insets: overscan=");
3416 mOverscanInsets.printShortString(pw);
3417 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003418 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003419 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003420 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003421 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003422 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003423 pw.print(prefix); pw.print("Lst insets: overscan=");
3424 mLastOverscanInsets.printShortString(pw);
3425 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003426 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003427 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003428 pw.print(" physical="); mLastOutsets.printShortString(pw);
3429 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003430 pw.println();
3431 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07003432 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
3433 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003434 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
3435 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003436 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
3437 pw.print(" mDestroying="); pw.print(mDestroying);
3438 pw.print(" mRemoved="); pw.println(mRemoved);
3439 }
3440 if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
3441 pw.print(prefix); pw.print("mOrientationChanging=");
3442 pw.print(mOrientationChanging);
3443 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
3444 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
3445 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003446 if (mLastFreezeDuration != 0) {
3447 pw.print(prefix); pw.print("mLastFreezeDuration=");
3448 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
3449 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003450 if (mHScale != 1 || mVScale != 1) {
3451 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
3452 pw.print(" mVScale="); pw.println(mVScale);
3453 }
3454 if (mWallpaperX != -1 || mWallpaperY != -1) {
3455 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
3456 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
3457 }
3458 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
3459 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
3460 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
3461 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003462 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3463 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
3464 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
3465 pw.print(mWallpaperDisplayOffsetX);
3466 pw.print(" mWallpaperDisplayOffsetY=");
3467 pw.println(mWallpaperDisplayOffsetY);
3468 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003469 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07003470 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003471 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003472 if (isDragResizing()) {
3473 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
3474 }
3475 if (computeDragResizing()) {
3476 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
3477 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003478 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003479
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003480 @Override
3481 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003482 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003483 + " " + getWindowTag();
3484 }
3485
Robert Carra1eb4392015-12-10 12:43:51 -08003486 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003487 CharSequence tag = mAttrs.getTitle();
3488 if (tag == null || tag.length() <= 0) {
3489 tag = mAttrs.packageName;
3490 }
3491 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003492 }
3493
3494 @Override
3495 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003496 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003497 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003498 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003499 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003500 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003501 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003502 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003503 }
3504 return mStringNameCache;
3505 }
Robert Carr58f29132015-10-29 14:19:05 -07003506
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003507 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003508 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003509 clipRect.left = (int) (clipRect.left / mHScale);
3510 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003511 }
3512 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003513 clipRect.top = (int) (clipRect.top / mVScale);
3514 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003515 }
3516 }
Robert Carr31e28482015-12-02 16:53:18 -08003517
Jorim Jaggif5834272016-04-04 20:25:41 -07003518 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
3519 final int pw = containingFrame.width();
3520 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003521 final Task task = getTask();
Andrii Kulian933076d2016-03-29 17:04:42 -07003522 final boolean nonFullscreenTask = isInMultiWindowMode();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003523 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3524
3525 // We need to fit it to the display if either
3526 // a) The task is fullscreen, or we don't have a task (we assume fullscreen for the taskless
3527 // windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003528 // b) If it's a secondary app window, we also need to fit it to the display unless
3529 // 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 -07003530 // but SurfaceViews want to be always at a specific location so we don't fit it to the
3531 // display.
3532 final boolean fitToDisplay = (task == null || !nonFullscreenTask)
Robert Carr6f44db12016-07-21 14:54:43 -07003533 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003534 float x, y;
3535 int w,h;
3536
3537 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3538 if (mAttrs.width < 0) {
3539 w = pw;
3540 } else if (mEnforceSizeCompat) {
3541 w = (int)(mAttrs.width * mGlobalScale + .5f);
3542 } else {
3543 w = mAttrs.width;
3544 }
3545 if (mAttrs.height < 0) {
3546 h = ph;
3547 } else if (mEnforceSizeCompat) {
3548 h = (int)(mAttrs.height * mGlobalScale + .5f);
3549 } else {
3550 h = mAttrs.height;
3551 }
3552 } else {
3553 if (mAttrs.width == MATCH_PARENT) {
3554 w = pw;
3555 } else if (mEnforceSizeCompat) {
3556 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3557 } else {
3558 w = mRequestedWidth;
3559 }
3560 if (mAttrs.height == MATCH_PARENT) {
3561 h = ph;
3562 } else if (mEnforceSizeCompat) {
3563 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3564 } else {
3565 h = mRequestedHeight;
3566 }
3567 }
3568
3569 if (mEnforceSizeCompat) {
3570 x = mAttrs.x * mGlobalScale;
3571 y = mAttrs.y * mGlobalScale;
3572 } else {
3573 x = mAttrs.x;
3574 y = mAttrs.y;
3575 }
3576
Robert Carr1d2bacb2016-03-30 14:29:35 -07003577 if (nonFullscreenTask && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003578 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003579 // required by {@link Gravity#apply} call.
3580 w = Math.min(w, pw);
3581 h = Math.min(h, ph);
3582 }
3583
3584 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003585 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003586 (int) (x + mAttrs.horizontalMargin * pw),
3587 (int) (y + mAttrs.verticalMargin * ph), mFrame);
3588
3589 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003590 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003591 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003592 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003593
3594 // We need to make sure we update the CompatFrame as it is used for
3595 // cropping decisions, etc, on systems where we lack a decor layer.
3596 mCompatFrame.set(mFrame);
3597 if (mEnforceSizeCompat) {
3598 // See comparable block in computeFrameLw.
3599 mCompatFrame.scale(mInvGlobalScale);
3600 }
Robert Carr31e28482015-12-02 16:53:18 -08003601 }
Robert Carr51a1b872015-12-08 14:03:13 -08003602
3603 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003604 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003605 }
3606
3607 /**
3608 * Returns the bottom child window in regards to z-order of this window or null if no children.
3609 */
3610 WindowState getBottomChild() {
3611 // Child windows are z-ordered based on sub-layer using {@link #sWindowSubLayerComparator}
3612 // and the child with the lowest z-order will be at the head of the list.
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003613 WindowState c = mChildren.peekFirst();
3614 return c == null ? null : c;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003615 }
3616
Robert Carrf3b72c72016-03-21 18:16:39 -07003617 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003618 return mIsChildWindow
3619 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003620 }
3621
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003622 /** Returns the parent window if this is a child of another window, else null. */
3623 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003624 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3625 // WindowContainer that isn't a WindowState.
3626 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003627 }
3628
3629 /** Returns the topmost parent window if this is a child of another window, else this. */
3630 WindowState getTopParentWindow() {
3631 WindowState w = this;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07003632 while (w != null && w.mIsChildWindow) {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003633 w = w.getParentWindow();
3634 }
3635 return w;
3636 }
3637
Wale Ogunwale9d147902016-07-16 11:58:55 -07003638 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003639 final WindowState parent = getParentWindow();
3640 return (parent == null) ? false : parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003641 }
3642
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003643 void setWillReplaceWindow(boolean animate) {
3644 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003645 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003646 c.setWillReplaceWindow(animate);
3647 }
3648
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003649 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3650 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3651 // We don't set replacing on starting windows since they are added by window manager and
3652 // not the client so won't be replaced by the client.
3653 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003654 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003655
3656 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003657 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003658 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003659 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003660
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003661 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003662 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003663 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003664 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003665
3666 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003667 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003668 c.clearWillReplaceWindow();
3669 }
3670 }
3671
3672 boolean waitingForReplacement() {
3673 if (mWillReplaceWindow) {
3674 return true;
3675 }
3676
3677 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003678 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003679 if (c.waitingForReplacement()) {
3680 return true;
3681 }
3682 }
3683 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003684 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003685
Chong Zhang4d7369a2016-04-25 16:09:14 -07003686 void requestUpdateWallpaperIfNeeded() {
3687 if (mDisplayContent != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3688 mDisplayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003689 mDisplayContent.setLayoutNeeded();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003690 mService.mWindowPlacerLocked.requestTraversal();
3691 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003692
3693 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003694 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003695 c.requestUpdateWallpaperIfNeeded();
3696 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003697 }
3698
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003699 float translateToWindowX(float x) {
3700 float winX = x - mFrame.left;
3701 if (mEnforceSizeCompat) {
3702 winX *= mGlobalScale;
3703 }
3704 return winX;
3705 }
3706
3707 float translateToWindowY(float y) {
3708 float winY = y - mFrame.top;
3709 if (mEnforceSizeCompat) {
3710 winY *= mGlobalScale;
3711 }
3712 return winY;
3713 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003714
Robert Carr9fe459d2016-04-07 23:32:28 -07003715 void transferDimToReplacement() {
3716 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
3717 if (dimLayerUser != null && mDisplayContent != null) {
3718 mDisplayContent.mDimLayerController.applyDim(dimLayerUser,
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003719 mReplacementWindow.mWinAnimator,
Robert Carr9fe459d2016-04-07 23:32:28 -07003720 (mAttrs.flags & FLAG_DIM_BEHIND) != 0 ? true : false);
3721 }
3722 }
3723
Robert Carrd1a010f2016-04-07 22:36:22 -07003724 // During activity relaunch due to resize, we sometimes use window replacement
3725 // for only child windows (as the main window is handled by window preservation)
3726 // and the big surface.
3727 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003728 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3729 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3730 // we also want to replace them at such phases, as they won't be covered by window
3731 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003732 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003733 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003734 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003735 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003736
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003737 void setWillReplaceChildWindows() {
3738 if (shouldBeReplacedWithChildren()) {
3739 setWillReplaceWindow(false /* animate */);
3740 }
3741 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003742 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003743 c.setWillReplaceChildWindows();
3744 }
3745 }
3746
3747 WindowState getReplacingWindow() {
3748 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3749 return this;
3750 }
3751 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003752 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003753 final WindowState replacing = c.getReplacingWindow();
3754 if (replacing != null) {
3755 return replacing;
3756 }
3757 }
3758 return null;
3759 }
3760
Robert Carrfd10cd12016-06-29 16:41:50 -07003761 public int getRotationAnimationHint() {
3762 if (mAppToken != null) {
3763 return mAppToken.mRotationAnimationHint;
3764 } else {
3765 return -1;
3766 }
3767 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003768
3769 // This must be called while inside a transaction.
3770 boolean performShowLocked() {
3771 if (isHiddenFromUserLocked()) {
3772 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3773 hideLw(false);
3774 return false;
3775 }
3776
3777 logPerformShow("performShow on ");
3778
3779 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplayIgnoringKeyguard()) {
3780 return false;
3781 }
3782
3783 logPerformShow("Showing ");
3784
3785 mService.enableScreenIfNeededLocked();
3786 mWinAnimator.applyEnterAnimationLocked();
3787
3788 // Force the show in the next prepareSurfaceLocked() call.
3789 mWinAnimator.mLastAlpha = -1;
3790 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) Slog.v(TAG,
3791 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3792 mWinAnimator.mDrawState = HAS_DRAWN;
3793 mService.scheduleAnimationLocked();
3794
3795 if (mHidden) {
3796 mHidden = false;
3797 final DisplayContent displayContent = getDisplayContent();
3798
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003799 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003800 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003801 if (c.mWinAnimator.mSurfaceController != null) {
3802 c.performShowLocked();
3803 // It hadn't been shown, which means layout not performed on it, so now we
3804 // want to make sure to do a layout. If called from within the transaction
3805 // loop, this will cause it to restart with a new layout.
3806 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003807 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003808 }
3809 }
3810 }
3811 }
3812
3813 if (mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3814 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3815 }
3816
3817 if (mAttrs.type == TYPE_INPUT_METHOD) {
3818 mDisplayContent.mDividerControllerLocked.resetImeHideRequested();
3819 }
3820
3821 return true;
3822 }
3823
3824 void logPerformShow(String prefix) {
3825 if (DEBUG_VISIBILITY
3826 || (DEBUG_STARTING_WINDOW && mAttrs.type == TYPE_APPLICATION_STARTING)) {
3827 Slog.v(TAG, prefix + this
3828 + ": mDrawState=" + mWinAnimator.drawStateToString()
3829 + " readyForDisplay=" + isReadyForDisplayIgnoringKeyguard()
3830 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3831 + " during animation: policyVis=" + mPolicyVisibility
3832 + " parentHidden=" + isParentWindowHidden()
3833 + " tok.hiddenRequested="
3834 + (mAppToken != null ? mAppToken.hiddenRequested : false)
3835 + " tok.hidden=" + (mAppToken != null ? mAppToken.hidden : false)
3836 + " animating=" + mWinAnimator.mAnimating
3837 + " tok animating="
3838 + (mWinAnimator.mAppAnimator != null ? mWinAnimator.mAppAnimator.animating : false)
3839 + " Callers=" + Debug.getCallers(4));
3840 }
3841 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003842
3843 WindowInfo getWindowInfo() {
3844 WindowInfo windowInfo = WindowInfo.obtain();
3845 windowInfo.type = mAttrs.type;
3846 windowInfo.layer = mLayer;
3847 windowInfo.token = mClient.asBinder();
3848 windowInfo.title = mAttrs.accessibilityTitle;
3849 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3850 windowInfo.focused = isFocused();
3851
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003852 if (mIsChildWindow) {
3853 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003854 }
3855
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003856 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003857 if (childCount > 0) {
3858 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003859 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003860 }
3861 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003862 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003863 windowInfo.childTokens.add(child.mClient.asBinder());
3864 }
3865 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003866 return windowInfo;
3867 }
3868
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003869 int getHighestAnimLayer() {
3870 int highest = mWinAnimator.mAnimLayer;
3871 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003872 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003873 final int childLayer = c.getHighestAnimLayer();
3874 if (childLayer > highest) {
3875 highest = childLayer;
3876 }
3877 }
3878 return highest;
3879 }
3880
3881 int adjustAnimLayer(int adj) {
3882 int highestAnimLayer = mWinAnimator.mAnimLayer = mLayer + adj;
3883 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG_WM,
3884 "adjustAnimLayer win=" + this + " anim layer: " + mWinAnimator.mAnimLayer);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003885 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003886 final WindowState childWindow = mChildren.get(i);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003887 childWindow.adjustAnimLayer(adj);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003888 if (childWindow.mWinAnimator.mAnimLayer > highestAnimLayer) {
3889 highestAnimLayer = childWindow.mWinAnimator.mAnimLayer;
3890 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003891 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003892 return highestAnimLayer;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003893 }
3894
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003895 @Override
3896 int rebuildWindowList(DisplayContent dc, int addIndex) {
3897 final DisplayContent winDisplayContent = getDisplayContent();
3898 if (winDisplayContent == dc || winDisplayContent == null) {
3899 mDisplayContent = dc;
3900 return reAddWindow(addIndex);
3901 }
3902 return addIndex;
3903 }
3904
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003905 // TODO: come-up with a better name for this method that represents what it does.
3906 // Or, it is probably not going to matter anyways if we are successful in getting rid of
3907 // the WindowList concept.
Wale Ogunwale92fc3722016-08-05 12:19:08 -07003908 int reAddWindow(int index) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003909 final WindowList windows = getWindowList();
3910 // Adding child windows relies on child windows being ordered by mSubLayer using
3911 // {@link #sWindowSubLayerComparator}.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003912 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003913 boolean winAdded = false;
3914 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003915 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003916 if (!winAdded && child.mSubLayer >= 0) {
3917 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM,
3918 "Re-adding child window at " + index + ": " + child);
3919 mRebuilding = false;
3920 windows.add(index, this);
3921 index++;
3922 winAdded = true;
3923 }
3924 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Re-adding window at " + index + ": " + child);
3925 child.mRebuilding = false;
3926 windows.add(index, child);
3927 index++;
3928 }
3929 if (!winAdded) {
3930 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Re-adding window at " + index + ": " + this);
3931 mRebuilding = false;
3932 windows.add(index, this);
3933 index++;
3934 }
3935 mService.mWindowsChanged = true;
3936 return index;
3937 }
3938
3939 int removeFromWindowList(int interestingPos) {
3940 final WindowList windows = getWindowList();
3941 int wpos = windows.indexOf(this);
3942 if (wpos < 0) {
3943 return interestingPos;
3944 }
3945
3946 if (wpos < interestingPos) interestingPos--;
3947 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "Temp removing at " + wpos + ": " + this);
3948 windows.remove(wpos);
3949 mService.mWindowsChanged = true;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003950 int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003951 while (childCount > 0) {
3952 childCount--;
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003953 final WindowState cw = mChildren.get(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003954 int cpos = windows.indexOf(cw);
3955 if (cpos >= 0) {
3956 if (cpos < interestingPos) interestingPos--;
3957 if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM,
3958 "Temp removing child at " + cpos + ": " + cw);
3959 windows.remove(cpos);
3960 }
3961 }
3962 return interestingPos;
3963 }
3964
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003965 boolean isWindowAnimationSet() {
3966 if (mWinAnimator.isWindowAnimationSet()) {
3967 return true;
3968 }
3969 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003970 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003971 if (c.isWindowAnimationSet()) {
3972 return true;
3973 }
3974 }
3975 return false;
3976 }
3977
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003978 void onExitAnimationDone() {
3979 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
3980 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
3981 + " windowAnimating=" + mWinAnimator.isWindowAnimationSet());
3982
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003983 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003984 // Copying to a different list as multiple children can be removed.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003985 // TODO: Not sure if we really need to copy this into a different list.
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003986 final LinkedList<WindowState> childWindows = new LinkedList(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003987 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003988 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003989 }
3990 }
3991
3992 if (mWinAnimator.mEnteringAnimation) {
3993 mWinAnimator.mEnteringAnimation = false;
3994 mService.requestTraversal();
3995 // System windows don't have an activity and an app token as a result, but need a way
3996 // to be informed about their entrance animation end.
3997 if (mAppToken == null) {
3998 try {
3999 mClient.dispatchWindowShown();
4000 } catch (RemoteException e) {
4001 }
4002 }
4003 }
4004
4005 if (!mWinAnimator.isWindowAnimationSet()) {
4006 //TODO (multidisplay): Accessibility is supported only for the default display.
4007 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
4008 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
4009 }
4010 }
4011
4012 if (!mAnimatingExit) {
4013 return;
4014 }
4015
4016 if (mWinAnimator.isWindowAnimationSet()) {
4017 return;
4018 }
4019
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07004020 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004021 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
4022
4023 mDestroying = true;
4024
4025 final boolean hasSurface = mWinAnimator.hasSurface();
4026 if (hasSurface) {
4027 mWinAnimator.hide("onExitAnimationDone");
4028 }
4029
4030 // If we have an app token, we ask it to destroy the surface for us, so that it can take
4031 // care to ensure the activity has actually stopped and the surface is not still in use.
4032 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
4033 // transaction.
4034 if (mAppToken != null) {
4035 mAppToken.destroySurfaces();
4036 } else {
4037 if (hasSurface) {
4038 mService.mDestroySurface.add(this);
4039 }
4040 if (mRemoveOnExit) {
4041 mService.mPendingRemove.add(this);
4042 mRemoveOnExit = false;
4043 }
4044 }
4045 mAnimatingExit = false;
4046 mService.mWallpaperControllerLocked.hideWallpapers(this);
4047 }
Dan Willemsen117197f2016-07-30 13:02:59 -07004048
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004049 boolean clearAnimatingFlags() {
4050 boolean didSomething = false;
4051 // We don't want to clear it out for windows that get replaced, because the
4052 // animation depends on the flag to remove the replaced window.
4053 //
4054 // We also don't clear the mAnimatingExit flag for windows which have the
4055 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4056 // by the client. We should let animation proceed and not clear this flag or
4057 // they won't eventually be removed by WindowStateAnimator#finishExit.
4058 if (!mWillReplaceWindow && !mRemoveOnExit) {
4059 // Clear mAnimating flag together with mAnimatingExit. When animation
4060 // changes from exiting to entering, we need to clear this flag until the
4061 // new animation gets applied, so that isAnimationStarting() becomes true
4062 // until then.
4063 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4064 // placement for this window during this period, one or more frame will
4065 // show up with wrong position or scale.
4066 if (mAnimatingExit) {
4067 mAnimatingExit = false;
4068 didSomething = true;
4069 }
4070 if (mWinAnimator.mAnimating) {
4071 mWinAnimator.mAnimating = false;
4072 didSomething = true;
4073 }
4074 if (mDestroying) {
4075 mDestroying = false;
4076 mService.mDestroySurface.remove(this);
4077 didSomething = true;
4078 }
4079 }
4080
4081 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004082 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004083 }
4084
4085 return didSomething;
4086 }
4087
Winson4b4ba902016-07-27 19:45:52 -07004088 public boolean isRtl() {
4089 return mMergedConfiguration.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
4090 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004091
4092 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004093 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004094 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004095 c.hideWallpaperWindow(wasDeferred, reason);
4096 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004097 if (!mWinAnimator.mLastHidden || wasDeferred) {
4098 mWinAnimator.hide(reason);
4099 dispatchWallpaperVisibility(false);
4100 final DisplayContent displayContent = getDisplayContent();
4101 if (displayContent != null) {
4102 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
4103 }
4104 }
4105 }
4106
4107 /**
4108 * Check wallpaper window for visibility change and notify window if so.
4109 * @param visible Current visibility.
4110 */
4111 void dispatchWallpaperVisibility(final boolean visible) {
4112 final boolean hideAllowed =
4113 mService.mWallpaperControllerLocked.mDeferredHideWallpaper == null;
4114
4115 // Only send notification if the visibility actually changed and we are not trying to hide
4116 // the wallpaper when we are deferring hiding of the wallpaper.
4117 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4118 mWallpaperVisible = visible;
4119 try {
4120 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4121 "Updating vis of wallpaper " + this
4122 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4123 mClient.dispatchAppVisibility(visible);
4124 } catch (RemoteException e) {
4125 }
4126 }
4127 }
4128
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004129 boolean hasVisibleNotDrawnWallpaper() {
4130 if (mWallpaperVisible && !isDrawnLw()) {
4131 return true;
4132 }
4133 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004134 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004135 if (c.hasVisibleNotDrawnWallpaper()) {
4136 return true;
4137 }
4138 }
4139 return false;
4140 }
4141
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004142 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4143 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004144 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004145 c.updateReportedVisibility(results);
4146 }
4147
4148 if (mAppFreezing || mViewVisibility != View.VISIBLE
4149 || mAttrs.type == TYPE_APPLICATION_STARTING
4150 || mDestroying) {
4151 return;
4152 }
4153 if (DEBUG_VISIBILITY) {
4154 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
4155 + ", isAnimationSet=" + mWinAnimator.isAnimationSet());
4156 if (!isDrawnLw()) {
4157 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4158 + " pv=" + mPolicyVisibility
4159 + " mDrawState=" + mWinAnimator.mDrawState
4160 + " ph=" + isParentWindowHidden()
4161 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
4162 + " a=" + mWinAnimator.mAnimating);
4163 }
4164 }
4165
4166 results.numInteresting++;
4167 if (isDrawnLw()) {
4168 results.numDrawn++;
4169 if (!mWinAnimator.isAnimationSet()) {
4170 results.numVisible++;
4171 }
4172 results.nowGone = false;
4173 } else if (mWinAnimator.isAnimationSet()) {
4174 results.nowGone = false;
4175 }
4176 }
4177
4178 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4179 // access to its windows children. Need to investigate re-writing
4180 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4181 static final class UpdateReportedVisibilityResults {
4182 int numInteresting;
4183 int numVisible;
4184 int numDrawn;
4185 boolean nowGone = true;
4186
4187 void reset() {
4188 numInteresting = 0;
4189 numVisible = 0;
4190 numDrawn = 0;
4191 nowGone = true;
4192 }
4193 }
satokcef37fb2011-10-24 21:49:38 +09004194}