blob: 5d324432409e56764d9522b7bed3be2fca93160d [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
Jorim Jaggi02886a82016-12-06 09:10:06 -080019import static android.app.ActivityManager.ENABLE_TASK_SNAPSHOTS;
20import static android.app.ActivityManager.StackId;
Winson Chungd73e94b2017-05-31 16:25:30 -070021import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
Jorim Jaggi02886a82016-12-06 09:10:06 -080022import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
Winson Chungd73e94b2017-05-31 16:25:30 -070023import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Jorim Jaggi02886a82016-12-06 09:10:06 -080024import static android.app.ActivityManager.isLowRamDeviceStatic;
25import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
26import static android.view.Display.DEFAULT_DISPLAY;
27import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
28import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
29import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
30import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
31import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
32import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW;
33import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
34import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
35import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
36import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
37import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
38import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
39import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
40import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
41import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
42import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
43import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
44import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Robert Carrc91d1c32017-02-15 19:37:46 -080045import static android.view.WindowManager.LayoutParams.FORMAT_CHANGED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080046import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
47import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
48import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
49import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
50import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
51import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
52import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
53import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
54import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Robert Carraf422a82017-04-10 18:34:33 -070055import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080056import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
57import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
58import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
59import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
60import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
61import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
62import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Robert Carrc91d1c32017-02-15 19:37:46 -080063import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED;
64import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM;
65import static android.view.WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME;
66import static android.view.WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080067import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
68import static android.view.WindowManagerPolicy.TRANSIT_ENTER;
69import static android.view.WindowManagerPolicy.TRANSIT_EXIT;
70import static android.view.WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
71import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
72import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
73import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
74import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
75import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
76import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
77import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
78import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
79import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Jorim Jaggi02886a82016-12-06 09:10:06 -080080import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
81import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
82import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
83import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
84import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020085import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Jorim Jaggi02886a82016-12-06 09:10:06 -080086import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SURFACE_TRACE;
87import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080088import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
89import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
90import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
91import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
92import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
93import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
94import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
95import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
96import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
97import static com.android.server.wm.WindowManagerService.localLOGV;
98import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING;
99import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
100import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN;
101import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
102
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800103import android.app.AppOpsManager;
104import android.content.Context;
105import android.content.res.Configuration;
106import android.graphics.Matrix;
107import android.graphics.PixelFormat;
108import android.graphics.Point;
109import android.graphics.Rect;
110import android.graphics.Region;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700111import android.os.Binder;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700112import android.os.Debug;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800113import android.os.IBinder;
114import android.os.PowerManager;
115import android.os.RemoteCallbackList;
116import android.os.RemoteException;
117import android.os.SystemClock;
118import android.os.Trace;
119import android.os.UserHandle;
120import android.os.WorkSource;
Andrii Kulian44607962017-03-16 11:06:24 -0700121import android.util.MergedConfiguration;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800122import android.util.DisplayMetrics;
123import android.util.Slog;
124import android.util.TimeUtils;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800125import android.view.DisplayInfo;
126import android.view.Gravity;
127import android.view.IApplicationToken;
128import android.view.IWindow;
129import android.view.IWindowFocusObserver;
130import android.view.IWindowId;
131import android.view.InputChannel;
132import android.view.InputEvent;
133import android.view.InputEventReceiver;
134import android.view.View;
135import android.view.ViewTreeObserver;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700136import android.view.WindowInfo;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800137import android.view.WindowManager;
138import android.view.WindowManagerPolicy;
139
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800140import com.android.internal.util.ToBooleanFunction;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800141import com.android.server.input.InputWindowHandle;
142
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800143import java.io.PrintWriter;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200144import java.lang.ref.WeakReference;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800145import java.util.ArrayList;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700146import java.util.Comparator;
147import java.util.LinkedList;
Wale Ogunwaled1880962016-11-08 10:31:59 -0800148import java.util.function.Predicate;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800149
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700150/** A window in the window manager. */
151class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800152 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800153
Skuhne81c524a2015-08-12 13:34:14 -0700154 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700155 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
156 // use hard-coded min sizes for now.
157 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
158 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700159
160 // The thickness of a window resize handle outside the window bounds on the free form workspace
161 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700162 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700163
Jorim Jaggi02886a82016-12-06 09:10:06 -0800164 private static final boolean DEBUG_DISABLE_SAVING_SURFACES = false ||
165 ENABLE_TASK_SNAPSHOTS;
Robert Carr7098dbd2016-02-01 12:31:01 -0800166
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800167 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700168 final WindowManagerPolicy mPolicy;
169 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800170 final Session mSession;
171 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800172 final int mAppOp;
173 // UserId and appId of the owner. Don't display windows of non-current user.
174 final int mOwnerUid;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800175 /** The owner has {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} */
176 final boolean mOwnerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200177 final WindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800178 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700179 // The same object as mToken if this is an app window and null for non-app windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800180 AppWindowToken mAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700181
182 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
183 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800184 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
185 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700186 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800187 final int mBaseLayer;
188 final int mSubLayer;
189 final boolean mLayoutAttached;
190 final boolean mIsImWindow;
191 final boolean mIsWallpaper;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700192 private final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700193 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700194 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800195 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700196 int mSystemUiVisibility;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700197 /**
198 * The visibility of the window based on policy like {@link WindowManagerPolicy}.
199 * Normally set by calling {@link #showLw} and {@link #hideLw}.
200 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800201 boolean mPolicyVisibility = true;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700202 /**
203 * What {@link #mPolicyVisibility} should be set to after a transition animation.
204 * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and
205 * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit
206 * animation is done.
207 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800208 boolean mPolicyVisibilityAfterAnim = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700209 private boolean mAppOpVisibility = true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700210 boolean mPermanentlyHidden; // the window should never be shown again
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800211 boolean mAppFreezing;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700212 boolean mHidden; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800213 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700214 private boolean mDragResizing;
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200215 private boolean mDragResizingChangeReported = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700216 private int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700217
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700218 private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800219
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700220 /**
221 * The window size that was requested by the application. These are in
222 * the application's coordinate space (without compatibility scale applied).
223 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800224 int mRequestedWidth;
225 int mRequestedHeight;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700226 private int mLastRequestedWidth;
227 private int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700228
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800229 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800230 boolean mHaveFrame;
231 boolean mObscured;
232 boolean mTurnOnScreen;
233
234 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700235
Andrii Kulian9d91ca62016-09-29 22:28:09 -0700236 /**
237 * Used to store last reported to client configuration and check if we have newer available.
238 * We'll send configuration to client only if it is different from the last applied one and
239 * client won't perform unnecessary updates.
240 */
241 private final Configuration mLastReportedConfiguration = new Configuration();
Craig Mautnera2c77052012-03-26 12:14:43 -0700242
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700243 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700244 * Actual position of the surface shown on-screen (may be modified by animation). These are
245 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700246 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700247 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800248
249 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700250 * Insets that determine the actually visible area. These are in the application's
251 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800252 */
253 final Rect mVisibleInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700254 private final Rect mLastVisibleInsets = new Rect();
255 private boolean mVisibleInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800256
257 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700258 * Insets that are covered by system windows (such as the status bar) and
259 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700260 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800261 */
262 final Rect mContentInsets = new Rect();
263 final Rect mLastContentInsets = new Rect();
Robert Carr18f622f2017-05-08 11:20:43 -0700264
265 /**
266 * The last content insets returned to the client in relayout. We use
267 * these in the bounds animation to ensure we only observe inset changes
268 * at the same time that a client resizes it's surface so that we may use
269 * the geometryAppliesWithResize synchronization mechanism to keep
270 * the contents in place.
271 */
272 final Rect mLastRelayoutContentInsets = new Rect();
273
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700274 private boolean mContentInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800275
276 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800277 * Insets that determine the area covered by the display overscan region. These are in the
278 * application's coordinate space (without compatibility scale applied).
279 */
280 final Rect mOverscanInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700281 private final Rect mLastOverscanInsets = new Rect();
282 private boolean mOverscanInsetsChanged;
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800283
284 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700285 * Insets that determine the area covered by the stable system windows. These are in the
286 * application's coordinate space (without compatibility scale applied).
287 */
288 final Rect mStableInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700289 private final Rect mLastStableInsets = new Rect();
290 private boolean mStableInsetsChanged;
Adrian Roosfa104232014-06-20 16:10:14 -0700291
292 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700293 * Outsets determine the area outside of the surface where we want to pretend that it's possible
294 * to draw anyway.
295 */
296 final Rect mOutsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700297 private final Rect mLastOutsets = new Rect();
298 private boolean mOutsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700299
300 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800301 * Set to true if we are waiting for this window to receive its
302 * given internal insets before laying out other windows based on it.
303 */
304 boolean mGivenInsetsPending;
305
306 /**
307 * These are the content insets that were given during layout for
308 * this window, to be applied to windows behind it.
309 */
310 final Rect mGivenContentInsets = new Rect();
311
312 /**
313 * These are the visible insets that were given during layout for
314 * this window, to be applied to windows behind it.
315 */
316 final Rect mGivenVisibleInsets = new Rect();
317
318 /**
319 * This is the given touchable area relative to the window frame, or null if none.
320 */
321 final Region mGivenTouchableRegion = new Region();
322
323 /**
324 * Flag indicating whether the touchable region should be adjusted by
325 * the visible insets; if false the area outside the visible insets is
326 * NOT touchable, so we must use those to adjust the frame during hit
327 * tests.
328 */
329 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
330
331 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400332 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700333 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800334 float mHScale=1, mVScale=1;
335 float mLastHScale=1, mLastVScale=1;
336 final Matrix mTmpMatrix = new Matrix();
337
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700338 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800339 final Rect mFrame = new Rect();
340 final Rect mLastFrame = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700341 private boolean mFrameSizeChanged = false;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700342 // Frame that is scaled to the application's coordinate space when in
343 // screen size compatibility mode.
344 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800345
346 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700347
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700348 private final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700349
Wale Ogunwale94596652015-02-06 19:27:34 -0800350 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
351 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700352 final Rect mDisplayFrame = new Rect();
353
354 // The region of the display frame that the display type supports displaying content on. This
355 // is mostly a special case for TV where some displays don’t have the entire display usable.
356 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
357 // window display contents to extend into the overscan region.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700358 private final Rect mOverscanFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700359
360 // The display frame minus the stable insets. This value is always constant regardless of if
361 // the status bar or navigation bar is visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700362 private final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800363
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700364 // The area not occupied by the status and navigation bars. So, if both status and navigation
365 // bars are visible, the decor frame is equal to the stable frame.
366 final Rect mDecorFrame = new Rect();
367
368 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
369 // minus the area occupied by the IME if the IME is present.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700370 private final Rect mContentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700371
372 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
373 // displays hint text.
374 final Rect mVisibleFrame = new Rect();
375
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700376 // Frame that includes dead area outside of the surface but where we want to pretend that it's
377 // possible to draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700378 private final Rect mOutsetFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700379
Jorim Jaggidc249c42015-12-15 14:57:31 -0800380 /**
381 * Usually empty. Set to the task's tempInsetFrame. See
382 *{@link android.app.IActivityManager#resizeDockedStack}.
383 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700384 private final Rect mInsetFrame = new Rect();
Jorim Jaggidc249c42015-12-15 14:57:31 -0800385
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800386 boolean mContentChanged;
387
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800388 // If a window showing a wallpaper: the requested offset for the
389 // wallpaper; if a wallpaper window: the currently applied offset.
390 float mWallpaperX = -1;
391 float mWallpaperY = -1;
392
393 // If a window showing a wallpaper: what fraction of the offset
394 // range corresponds to a full virtual screen.
395 float mWallpaperXStep = -1;
396 float mWallpaperYStep = -1;
397
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700398 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
399 // to its window; if a wallpaper window: not used.
400 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
401 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
402
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800403 // Wallpaper windows: pixels offset based on above variables.
404 int mXOffset;
405 int mYOffset;
406
Craig Mautner2268e7e2012-12-13 15:40:00 -0800407 /**
408 * This is set after IWindowSession.relayout() has been called at
409 * least once for the window. It allows us to detect the situation
410 * where we don't yet have a surface, but should have one soon, so
411 * we can give the window focus before waiting for the relayout.
412 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800413 boolean mRelayoutCalled;
414
Robert Carrfed10072016-05-26 11:48:49 -0700415 boolean mInRelayout;
416
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800417 /**
418 * If the application has called relayout() with changes that can
419 * impact its window's size, we need to perform a layout pass on it
420 * even if it is not currently visible for layout. This is set
421 * when in that case until the layout is done.
422 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800423 boolean mLayoutNeeded;
424
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800425 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800426 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800427
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800428 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800429 boolean mDestroying;
430
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800431 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800432 boolean mRemoveOnExit;
433
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800434 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800435 * Whether the app died while it was visible, if true we might need
436 * to continue to show it until it's restarted.
437 */
438 boolean mAppDied;
439
440 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800441 * Set when the orientation is changing and this window has not yet
442 * been updated for the new orientation.
443 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800444 boolean mOrientationChanging;
445
Dianne Hackborna57c6952013-03-29 14:46:40 -0700446 /**
Robert Carr237028a2016-07-26 10:39:45 -0700447 * The orientation during the last visible call to relayout. If our
448 * current orientation is different, the window can't be ready
449 * to be shown.
450 */
451 int mLastVisibleLayoutRotation = -1;
452
453 /**
Andrii Kulianb2e37802017-01-11 00:36:44 -0800454 * Set when we need to report the orientation change to client to trigger a relayout.
455 */
456 boolean mReportOrientationChanged;
457
458 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700459 * How long we last kept the screen frozen.
460 */
461 int mLastFreezeDuration;
462
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800463 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800464 boolean mRemoved;
465
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800466 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800467 * It is save to remove the window and destroy the surface because the client requested removal
468 * or some other higher level component said so (e.g. activity manager).
469 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800470 */
Svetoslav Ganov200adfb2016-10-18 13:29:27 -0700471 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800472
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800473 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700474 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800475 InputChannel mInputChannel;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700476 private InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800477
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800478 // Used to improve performance of toString()
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700479 private String mStringNameCache;
480 private CharSequence mLastTitle;
481 private boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800482
Craig Mautnera2c77052012-03-26 12:14:43 -0700483 final WindowStateAnimator mWinAnimator;
484
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700485 boolean mHasSurface = false;
486
Craig Mautner88400d32012-09-30 12:35:45 -0700487 /** When true this window can be displayed on screens owther than mOwnerUid's */
488 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700489
Robert Carr13f7be9e2015-12-02 18:39:45 -0800490 // Whether the window has a saved surface from last pause, which can be
491 // used to start an entering animation earlier.
Chong Zhang92147042016-05-09 12:47:11 -0700492 private boolean mSurfaceSaved = false;
493
Chong Zhang8e4bda92016-05-04 15:08:18 -0700494 // Whether we're performing an entering animation with a saved surface. This flag is
495 // true during the time we're showing a window with a previously saved surface. It's
496 // cleared when surface is destroyed, saved, or re-drawn by the app.
Chong Zhang92147042016-05-09 12:47:11 -0700497 private boolean mAnimatingWithSavedSurface;
498
499 // Whether the window was visible when we set the app to invisible last time. WM uses
500 // this as a hint to restore the surface (if available) for early animation next time
501 // the app is brought visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700502 private boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800503
Robert Carra1eb4392015-12-10 12:43:51 -0800504 // This window will be replaced due to relaunch. This allows window manager
505 // to differentiate between simple removal of a window and replacement. In the latter case it
506 // will preserve the old window until the new one is drawn.
507 boolean mWillReplaceWindow = false;
508 // If true, the replaced window was already requested to be removed.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700509 private boolean mReplacingRemoveRequested = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800510 // Whether the replacement of the window should trigger app transition animation.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700511 private boolean mAnimateReplacingWindow = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800512 // If not null, the window that will be used to replace the old one. This is being set when
513 // the window is added and unset when this window reports its first draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700514 private WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700515 // For the new window in the replacement transition, if we have
516 // requested to replace without animation, then we should
517 // make sure we also don't apply an enter animation for
518 // the new window.
519 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800520 // Whether this window is being moved via the resize API
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700521 private boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800522
Jeff Brownc2932a12014-11-20 18:04:05 -0800523 /**
524 * Wake lock for drawing.
525 * Even though it's slightly more expensive to do so, we will use a separate wake lock
526 * for each app that is requesting to draw while dozing so that we can accurately track
527 * who is preventing the system from suspending.
528 * This lock is only acquired on first use.
529 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700530 private PowerManager.WakeLock mDrawLock;
Jeff Brownc2932a12014-11-20 18:04:05 -0800531
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700532 final private Rect mTmpRect = new Rect();
533
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800534 /**
535 * Whether the window was resized by us while it was gone for layout.
536 */
537 boolean mResizedWhileGone = false;
538
Andrii Kulianeb1d3222016-05-16 15:17:55 -0700539 /** @see #isResizedWhileNotDragResizing(). */
540 private boolean mResizedWhileNotDragResizing;
541
542 /** @see #isResizedWhileNotDragResizingReported(). */
543 private boolean mResizedWhileNotDragResizingReported;
Jorim Jaggif3df0aa2016-04-06 15:56:33 -0700544
Robert Carr6da3cc02016-06-16 15:17:07 -0700545 /**
546 * During seamless rotation we have two phases, first the old window contents
547 * are rotated to look as if they didn't move in the new coordinate system. Then we
548 * have to freeze updates to this layer (to preserve the transformation) until
549 * the resize actually occurs. This is true from when the transformation is set
550 * and false until the transaction to resize is sent.
551 */
552 boolean mSeamlesslyRotated = false;
553
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700554 private static final Region sEmptyRegion = new Region();
555
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700556 /**
Robert Carrc91d1c32017-02-15 19:37:46 -0800557 * Surface insets from the previous call to relayout(), used to track
558 * if we are changing the Surface insets.
559 */
560 final Rect mLastSurfaceInsets = new Rect();
561
562 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700563 * Compares two window sub-layers and returns -1 if the first is lesser than the second in terms
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700564 * of z-order and 1 otherwise.
565 */
Griff Hazen51d00d82016-11-22 15:39:24 -0800566 private static final Comparator<WindowState> sWindowSubLayerComparator =
567 new Comparator<WindowState>() {
568 @Override
569 public int compare(WindowState w1, WindowState w2) {
570 final int layer1 = w1.mSubLayer;
571 final int layer2 = w2.mSubLayer;
572 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
573 // We insert the child window into the list ordered by
574 // the sub-layer. For same sub-layers, the negative one
575 // should go below others; the positive one should go
576 // above others.
577 return -1;
578 }
579 return 1;
580 };
581 };
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700582
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800583 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700584 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800585 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800586 mService = service;
587 mSession = s;
588 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800589 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800590 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700591 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700592 mOwnerUid = ownerId;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800593 mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200594 mWindowId = new WindowId(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800595 mAttrs.copyFrom(a);
596 mViewVisibility = viewVisibility;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700597 mPolicy = mService.mPolicy;
598 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800599 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700600 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700601 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700602 if (localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700603 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700604 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800605 try {
606 c.asBinder().linkToDeath(deathRecipient, 0);
607 } catch (RemoteException e) {
608 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700609 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800610 mLayoutAttached = false;
611 mIsImWindow = false;
612 mIsWallpaper = false;
613 mIsFloatingLayer = false;
614 mBaseLayer = 0;
615 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700616 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700617 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800618 return;
619 }
620 mDeathRecipient = deathRecipient;
621
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700622 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800623 // The multiplier here is to reserve space for multiple
624 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800625 mBaseLayer = mPolicy.getWindowLayerLw(parentWindow)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700626 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800627 mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700628 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900629
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700630 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow);
631 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900632
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800633 mLayoutAttached = mAttrs.type !=
634 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700635 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
636 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
637 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800638 } else {
639 // The multiplier here is to reserve space for multiple
640 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800641 mBaseLayer = mPolicy.getWindowLayerLw(this)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700642 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800643 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700644 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800645 mLayoutAttached = false;
646 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
647 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
648 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800649 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700650 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800651
Wale Ogunwale72919d22016-12-08 18:58:50 -0800652 if (mAppToken != null && mAppToken.mShowForAllUsers) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700653 // Windows for apps that can show for all users should also show when the device is
654 // locked.
655 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
Craig Mautner19ab8282014-05-07 10:35:34 -0700656 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800657
Craig Mautner322e4032012-07-13 13:35:20 -0700658 mWinAnimator = new WindowStateAnimator(this);
659 mWinAnimator.mAlpha = a.alpha;
660
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800661 mRequestedWidth = 0;
662 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700663 mLastRequestedWidth = 0;
664 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800665 mXOffset = 0;
666 mYOffset = 0;
667 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800668 mInputWindowHandle = new InputWindowHandle(
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800669 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this, c,
670 getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800671 }
672
673 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700674 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800675 mSession.windowAddedLocked(mAttrs.packageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800676 }
677
Craig Mautnera2c77052012-03-26 12:14:43 -0700678 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800679 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800680 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800681 }
682
683 @Override
684 public String getOwningPackage() {
685 return mAttrs.packageName;
686 }
687
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800688 @Override
689 public boolean canAddInternalSystemWindow() {
690 return mOwnerCanAddInternalSystemWindow;
691 }
692
Jorim Jaggif5834272016-04-04 20:25:41 -0700693 /**
694 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
695 * from {@param frame}. In other words, it applies the insets that would result if
696 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700697 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
698 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700699 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700700 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
701 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
702 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
703 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
704 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700705 frame.inset(left, top, right, bottom);
706 }
707
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800708 @Override
Robert Carr43521762016-10-28 13:15:04 -0700709 public void computeFrameLw(Rect parentFrame, Rect displayFrame, Rect overscanFrame,
710 Rect contentFrame, Rect visibleFrame, Rect decorFrame, Rect stableFrame,
711 Rect outsetFrame) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800712 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700713 // This window is being replaced and either already got information that it's being
714 // removed or we are still waiting for some information. Because of this we don't
715 // want to apply any more changes to it, so it remains in this state until new window
716 // appears.
717 return;
718 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800719 mHaveFrame = true;
720
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700721 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700722 final boolean inFullscreenContainer = inFullscreenContainer();
Robert Carre6275582016-02-29 15:45:45 -0800723 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700724 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800725
Chong Zhangae35fef2016-03-16 15:56:55 -0700726 // If the task has temp inset bounds set, we have to make sure all its windows uses
727 // the temp inset frame. Otherwise different display frames get applied to the main
728 // window and the child window, making them misaligned.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700729 if (inFullscreenContainer) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700730 mInsetFrame.setEmpty();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700731 } else if (task != null && isInMultiWindowMode()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700732 task.getTempInsetBounds(mInsetFrame);
733 }
734
Jorim Jaggif5834272016-04-04 20:25:41 -0700735 // Denotes the actual frame used to calculate the insets and to perform the layout. When
736 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
737 // insets temporarily. By the notion of a task having a different layout frame, we can
738 // achieve that while still moving the task around.
739 final Rect layoutContainingFrame;
740 final Rect layoutDisplayFrame;
741
742 // The offset from the layout containing frame to the actual containing frame.
743 final int layoutXDiff;
744 final int layoutYDiff;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700745 if (inFullscreenContainer || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800746 // We use the parent frame as the containing frame for fullscreen and child windows
Robert Carr43521762016-10-28 13:15:04 -0700747 mContainingFrame.set(parentFrame);
748 mDisplayFrame.set(displayFrame);
749 layoutDisplayFrame = displayFrame;
750 layoutContainingFrame = parentFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700751 layoutXDiff = 0;
752 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800753 } else {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700754 getContainerBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100755 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
756
757 // If the bounds are frozen, we still want to translate the window freely and only
758 // freeze the size.
759 Rect frozen = mAppToken.mFrozenBounds.peek();
760 mContainingFrame.right = mContainingFrame.left + frozen.width();
761 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
762 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800763 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700764 // IME is up and obscuring this window. Adjust the window position so it is visible.
765 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this) {
Winson Chungd73e94b2017-05-31 16:25:30 -0700766 final int stackId = getStackId();
767 if (stackId == FREEFORM_WORKSPACE_STACK_ID
768 && mContainingFrame.bottom > contentFrame.bottom) {
769 // In freeform we want to move the top up directly.
770 // TODO: Investigate why this is contentFrame not parentFrame.
771 mContainingFrame.top -= mContainingFrame.bottom - contentFrame.bottom;
772 } else if (stackId != PINNED_STACK_ID
773 && mContainingFrame.bottom > parentFrame.bottom) {
774 // But in docked we want to behave like fullscreen and behave as if the task
775 // were given smaller bounds for the purposes of layout. Skip adjustments for
776 // the pinned stack, they are handled separately in the PinnedStackController.
777 mContainingFrame.bottom = parentFrame.bottom;
778 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700779 }
Skuhne81c524a2015-08-12 13:34:14 -0700780
Robert Carre6275582016-02-29 15:45:45 -0800781 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700782 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
783 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800784 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700785 if (mContainingFrame.isEmpty()) {
Robert Carr43521762016-10-28 13:15:04 -0700786 mContainingFrame.set(contentFrame);
Skuhne81c524a2015-08-12 13:34:14 -0700787 }
Doris Liu06d582d2015-06-01 13:18:43 -0700788 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800789 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700790 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
791 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
792 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700793 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
Robert Carr43521762016-10-28 13:15:04 -0700794 subtractInsets(mDisplayFrame, layoutContainingFrame, displayFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700795 if (!layoutInParentFrame()) {
Robert Carr43521762016-10-28 13:15:04 -0700796 subtractInsets(mContainingFrame, layoutContainingFrame, parentFrame, mTmpRect);
797 subtractInsets(mInsetFrame, layoutContainingFrame, parentFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700798 }
Robert Carr43521762016-10-28 13:15:04 -0700799 layoutDisplayFrame = displayFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700800 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700801 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800802
Craig Mautner967212c2013-04-13 21:10:58 -0700803 final int pw = mContainingFrame.width();
804 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800805
Robert Carr43521762016-10-28 13:15:04 -0700806 if (!mParentFrame.equals(parentFrame)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800807 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Robert Carr43521762016-10-28 13:15:04 -0700808 // + " to " + parentFrame);
809 mParentFrame.set(parentFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800810 mContentChanged = true;
811 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700812 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
813 mLastRequestedWidth = mRequestedWidth;
814 mLastRequestedHeight = mRequestedHeight;
815 mContentChanged = true;
816 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800817
Robert Carr43521762016-10-28 13:15:04 -0700818 mOverscanFrame.set(overscanFrame);
819 mContentFrame.set(contentFrame);
820 mVisibleFrame.set(visibleFrame);
821 mDecorFrame.set(decorFrame);
822 mStableFrame.set(stableFrame);
823 final boolean hasOutsets = outsetFrame != null;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700824 if (hasOutsets) {
Robert Carr43521762016-10-28 13:15:04 -0700825 mOutsetFrame.set(outsetFrame);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700826 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800827
Craig Mautnereda67292013-04-28 13:50:14 -0700828 final int fw = mFrame.width();
829 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800830
Jorim Jaggif5834272016-04-04 20:25:41 -0700831 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
832
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700833 // Calculate the outsets before the content frame gets shrinked to the window frame.
834 if (hasOutsets) {
835 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
836 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
837 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
838 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
839 } else {
840 mOutsets.set(0, 0, 0, 0);
841 }
842
Craig Mautnera248eee2013-05-07 11:41:27 -0700843 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800844 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -0800845 if (windowsAreFloating && !mFrame.isEmpty()) {
Robert Carre65a1c42017-02-28 16:52:59 -0800846 // For pinned workspace the frame isn't limited in any particular
847 // way since SystemUI controls the bounds. For freeform however
848 // we want to keep things inside the content frame.
849 final Rect limitFrame = task.inPinnedWorkspace() ? mFrame : mContentFrame;
Skuhne81c524a2015-08-12 13:34:14 -0700850 // Keep the frame out of the blocked system area, limit it in size to the content area
851 // and make sure that there is always a minimum visible so that the user can drag it
852 // into a usable area..
Robert Carre65a1c42017-02-28 16:52:59 -0800853 final int height = Math.min(mFrame.height(), limitFrame.height());
854 final int width = Math.min(limitFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700855 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +0900856 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
857 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
858 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
859 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Robert Carre65a1c42017-02-28 16:52:59 -0800860 final int top = Math.max(limitFrame.top,
861 Math.min(mFrame.top, limitFrame.bottom - minVisibleHeight));
862 final int left = Math.max(limitFrame.left + minVisibleWidth - width,
863 Math.min(mFrame.left, limitFrame.right - minVisibleWidth));
Skuhne81c524a2015-08-12 13:34:14 -0700864 mFrame.set(left, top, left + width, top + height);
865 mContentFrame.set(mFrame);
866 mVisibleFrame.set(mContentFrame);
867 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700868 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700869 dc.getDockedDividerController().positionDockedStackedDivider(mFrame);
Jorim Jaggi192086e2016-03-11 17:17:03 +0100870 mContentFrame.set(mFrame);
871 if (!mFrame.equals(mLastFrame)) {
872 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800873 }
Skuhne81c524a2015-08-12 13:34:14 -0700874 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -0700875 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
876 Math.max(mContentFrame.top, mFrame.top),
877 Math.min(mContentFrame.right, mFrame.right),
878 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800879
Jorim Jaggi656f6502016-04-11 21:08:17 -0700880 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
881 Math.max(mVisibleFrame.top, mFrame.top),
882 Math.min(mVisibleFrame.right, mFrame.right),
883 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800884
Jorim Jaggi656f6502016-04-11 21:08:17 -0700885 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
886 Math.max(mStableFrame.top, mFrame.top),
887 Math.min(mStableFrame.right, mFrame.right),
888 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700889 }
Adrian Roosfa104232014-06-20 16:10:14 -0700890
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700891 if (inFullscreenContainer && !windowsAreFloating) {
Jorim Jaggi899327f2016-02-25 20:44:18 -0500892 // Windows that are not fullscreen can be positioned outside of the display frame,
893 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -0700894 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
895 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
896 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
897 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800898 }
Craig Mautnereda67292013-04-28 13:50:14 -0700899
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100900 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100901 // For the docked divider, we calculate the stable insets like a full-screen window
902 // so it can use it to calculate the snap positions.
903 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
904 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
905 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
906 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800907
908 // The divider doesn't care about insets in any case, so set it to empty so we don't
909 // trigger a relayout when moving it.
910 mContentInsets.setEmpty();
911 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100912 } else {
Andrii Kuliand9003372016-04-04 17:46:59 -0700913 getDisplayContent().getLogicalDisplayRect(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700914 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
915 // non-fullscreen mode.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700916 boolean overrideRightInset = !windowsAreFloating && !inFullscreenContainer
917 && mFrame.right > mTmpRect.right;
918 boolean overrideBottomInset = !windowsAreFloating && !inFullscreenContainer
919 && mFrame.bottom > mTmpRect.bottom;
Jorim Jaggi656f6502016-04-11 21:08:17 -0700920 mContentInsets.set(mContentFrame.left - mFrame.left,
921 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700922 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700923 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700924 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700925 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800926
Jorim Jaggi656f6502016-04-11 21:08:17 -0700927 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
928 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700929 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700930 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700931 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700932 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800933
Jorim Jaggi656f6502016-04-11 21:08:17 -0700934 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
935 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700936 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700937 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700938 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700939 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100940 }
Adrian Roosfa104232014-06-20 16:10:14 -0700941
Jorim Jaggi656f6502016-04-11 21:08:17 -0700942 // Offset the actual frame by the amount layout frame is off.
943 mFrame.offset(-layoutXDiff, -layoutYDiff);
944 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -0700945 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
946 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
947 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
948
Craig Mautnereda67292013-04-28 13:50:14 -0700949 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400950 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700951 // If there is a size compatibility scale being applied to the
952 // window, we need to apply this to its insets so that they are
953 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700954 mOverscanInsets.scale(mInvGlobalScale);
955 mContentInsets.scale(mInvGlobalScale);
956 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700957 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700958 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700959
960 // Also the scaled frame that we report to the app needs to be
961 // adjusted to be in its coordinate space.
962 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400963 }
964
Craig Mautnereda67292013-04-28 13:50:14 -0700965 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800966 final DisplayContent displayContent = getDisplayContent();
967 if (displayContent != null) {
968 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwale0303c572016-10-20 10:16:29 -0700969 getDisplayContent().mWallpaperController.updateWallpaperOffset(
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700970 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800971 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800972 }
973
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700974 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700975 "Resolving (mRequestedWidth="
976 + mRequestedWidth + ", mRequestedheight="
977 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
978 + "): frame=" + mFrame.toShortString()
979 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -0700980 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700981 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700982 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800983 }
984
Craig Mautnera2c77052012-03-26 12:14:43 -0700985 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800986 public Rect getFrameLw() {
987 return mFrame;
988 }
989
Craig Mautnera2c77052012-03-26 12:14:43 -0700990 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700991 public Point getShownPositionLw() {
992 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800993 }
994
Craig Mautnera2c77052012-03-26 12:14:43 -0700995 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800996 public Rect getDisplayFrameLw() {
997 return mDisplayFrame;
998 }
999
Craig Mautnera2c77052012-03-26 12:14:43 -07001000 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001001 public Rect getOverscanFrameLw() {
1002 return mOverscanFrame;
1003 }
1004
1005 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001006 public Rect getContentFrameLw() {
1007 return mContentFrame;
1008 }
1009
Craig Mautnera2c77052012-03-26 12:14:43 -07001010 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001011 public Rect getVisibleFrameLw() {
1012 return mVisibleFrame;
1013 }
1014
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001015 Rect getStableFrameLw() {
1016 return mStableFrame;
1017 }
1018
Craig Mautnera2c77052012-03-26 12:14:43 -07001019 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001020 public boolean getGivenInsetsPendingLw() {
1021 return mGivenInsetsPending;
1022 }
1023
Craig Mautnera2c77052012-03-26 12:14:43 -07001024 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001025 public Rect getGivenContentInsetsLw() {
1026 return mGivenContentInsets;
1027 }
1028
Craig Mautnera2c77052012-03-26 12:14:43 -07001029 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001030 public Rect getGivenVisibleInsetsLw() {
1031 return mGivenVisibleInsets;
1032 }
1033
Craig Mautnera2c77052012-03-26 12:14:43 -07001034 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001035 public WindowManager.LayoutParams getAttrs() {
1036 return mAttrs;
1037 }
1038
Craig Mautner812d2ca2012-09-27 15:35:34 -07001039 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001040 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001041 return getDisplayContent().getNeedsMenu(this, bottom);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001042 }
1043
Craig Mautner19d59bc2012-09-04 11:15:56 -07001044 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001045 public int getSystemUiVisibility() {
1046 return mSystemUiVisibility;
1047 }
1048
Craig Mautner19d59bc2012-09-04 11:15:56 -07001049 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001050 public int getSurfaceLayer() {
1051 return mLayer;
1052 }
1053
Craig Mautner812d2ca2012-09-27 15:35:34 -07001054 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001055 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001056 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001057 }
1058
1059 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001060 public IApplicationToken getAppToken() {
1061 return mAppToken != null ? mAppToken.appToken : null;
1062 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001063
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001064 @Override
1065 public boolean isVoiceInteraction() {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001066 return mAppToken != null && mAppToken.mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001067 }
1068
Robert Carr31aa98b2016-07-20 15:29:03 -07001069 boolean setReportResizeHints() {
Craig Mautner4c5eb222013-11-18 12:59:05 -08001070 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1071 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1072 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001073 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001074 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
Robert Carr31aa98b2016-07-20 15:29:03 -07001075 mFrameSizeChanged |= (mLastFrame.width() != mFrame.width()) ||
1076 (mLastFrame.height() != mFrame.height());
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001077 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
Robert Carr31aa98b2016-07-20 15:29:03 -07001078 || mOutsetsChanged || mFrameSizeChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001079 }
1080
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001081 /**
1082 * Adds the window to the resizing list if any of the parameters we use to track the window
1083 * dimensions or insets have changed.
1084 */
1085 void updateResizingWindowIfNeeded() {
1086 final WindowStateAnimator winAnimator = mWinAnimator;
1087 if (!mHasSurface || mService.mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
1088 return;
1089 }
1090
1091 final Task task = getTask();
1092 // In the case of stack bound animations, the window frames will update (unlike other
1093 // animations which just modify various transformation properties). We don't want to
1094 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1095 // the frame may not correspond to the surface size or the onscreen area at various
1096 // phases in the animation, and the client will become sad and confused.
Winson Chung40a5f932017-04-13 16:39:36 -07001097 if (task != null && task.mStack.isAnimatingBounds()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001098 return;
1099 }
1100
1101 setReportResizeHints();
1102 boolean configChanged = isConfigChanged();
1103 if (DEBUG_CONFIGURATION && configChanged) {
1104 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1105 }
1106
1107 final boolean dragResizingChanged = isDragResizeChanged()
1108 && !isDragResizingChangeReported();
1109
1110 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
1111 + " dragResizingChanged=" + dragResizingChanged + " last=" + mLastFrame
1112 + " frame=" + mFrame);
1113
1114 // We update mLastFrame always rather than in the conditional with the last inset
1115 // variables, because mFrameSizeChanged only tracks the width and height changing.
1116 mLastFrame.set(mFrame);
1117
1118 if (mContentInsetsChanged
1119 || mVisibleInsetsChanged
1120 || winAnimator.mSurfaceResized
1121 || mOutsetsChanged
1122 || mFrameSizeChanged
1123 || configChanged
1124 || dragResizingChanged
Andrii Kulianb2e37802017-01-11 00:36:44 -08001125 || !isResizedWhileNotDragResizingReported()
1126 || mReportOrientationChanged) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001127 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1128 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
1129 + " contentInsetsChanged=" + mContentInsetsChanged
1130 + " " + mContentInsets.toShortString()
1131 + " visibleInsetsChanged=" + mVisibleInsetsChanged
1132 + " " + mVisibleInsets.toShortString()
1133 + " stableInsetsChanged=" + mStableInsetsChanged
1134 + " " + mStableInsets.toShortString()
1135 + " outsetsChanged=" + mOutsetsChanged
1136 + " " + mOutsets.toShortString()
1137 + " surfaceResized=" + winAnimator.mSurfaceResized
1138 + " configChanged=" + configChanged
1139 + " dragResizingChanged=" + dragResizingChanged
1140 + " resizedWhileNotDragResizingReported="
Andrii Kulianb2e37802017-01-11 00:36:44 -08001141 + isResizedWhileNotDragResizingReported()
1142 + " reportOrientationChanged=" + mReportOrientationChanged);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001143 }
1144
1145 // If it's a dead window left on screen, and the configuration changed, there is nothing
1146 // we can do about it. Remove the window now.
1147 if (mAppToken != null && mAppDied) {
1148 mAppToken.removeDeadWindows();
1149 return;
1150 }
1151
Jorim Jaggidc9385a2017-05-13 02:00:31 +02001152 updateLastInsetValues();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001153 mService.makeWindowFreezingScreenIfNeededLocked(this);
1154
1155 // If the orientation is changing, or we're starting or ending a drag resizing action,
1156 // then we need to hold off on unfreezing the display until this window has been
1157 // redrawn; to do that, we need to go through the process of getting informed by the
1158 // application when it has finished drawing.
1159 if (mOrientationChanging || dragResizingChanged || isResizedWhileNotDragResizing()) {
1160 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
1161 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1162 + ", mDrawState=DRAW_PENDING in " + this
1163 + ", surfaceController " + winAnimator.mSurfaceController);
1164 }
1165 winAnimator.mDrawState = DRAW_PENDING;
1166 if (mAppToken != null) {
1167 mAppToken.clearAllDrawn();
1168 }
1169 }
1170 if (!mService.mResizingWindows.contains(this)) {
1171 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
1172 mService.mResizingWindows.add(this);
1173 }
1174 } else if (mOrientationChanging) {
1175 if (isDrawnLw()) {
1176 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1177 + this + ", surfaceController " + winAnimator.mSurfaceController);
1178 mOrientationChanging = false;
1179 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1180 - mService.mDisplayFreezeTime);
1181 }
1182 }
1183 }
1184
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001185 DisplayContent getDisplayContent() {
1186 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001187 }
1188
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001189 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001190 final DisplayContent displayContent = getDisplayContent();
1191 return displayContent != null ? displayContent.getDisplayInfo() : null;
1192 }
1193
Jorim Jaggife762342016-10-13 14:33:27 +02001194 @Override
1195 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001196 final DisplayContent displayContent = getDisplayContent();
1197 if (displayContent == null) {
1198 return -1;
1199 }
1200 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001201 }
1202
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001203 Task getTask() {
Bryce Lee6d410262017-02-28 15:30:17 -08001204 return mAppToken != null ? mAppToken.getTask() : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001205 }
1206
1207 TaskStack getStack() {
1208 Task task = getTask();
1209 if (task != null) {
1210 if (task.mStack != null) {
1211 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001212 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001213 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001214 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1215 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001216 final DisplayContent dc = getDisplayContent();
1217 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001218 }
1219
Skuhnef932e562015-08-20 12:07:30 -07001220 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001221 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001222 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001223 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001224 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001225 final Task task = getTask();
1226 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001227 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001228 mTmpRect.setEmpty();
1229 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001230 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001231 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001232 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001233 } else {
1234 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001235 }
1236 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001237
Chong Zhang9184ec62015-09-24 12:32:21 -07001238 bounds.set(mVisibleFrame);
1239 if (intersectWithStackBounds) {
1240 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001241 }
1242
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001243 if (bounds.isEmpty()) {
1244 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001245 if (intersectWithStackBounds) {
1246 bounds.intersect(mTmpRect);
1247 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001248 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001249 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001250 }
1251
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001252 public long getInputDispatchingTimeoutNanos() {
1253 return mAppToken != null
Wale Ogunwale72919d22016-12-08 18:58:50 -08001254 ? mAppToken.mInputDispatchingTimeoutNanos
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001255 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1256 }
1257
Craig Mautnere8552142012-11-07 13:55:47 -08001258 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001259 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001260 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001261 }
1262
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001263 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1264 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1265 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1266 if (dtdx < -.000001f || dtdx > .000001f) return false;
1267 if (dsdy < -.000001f || dsdy > .000001f) return false;
1268 return true;
1269 }
1270
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001271 void prelayout() {
1272 if (mEnforceSizeCompat) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001273 mGlobalScale = getDisplayContent().mCompatibleScreenScale;
1274 mInvGlobalScale = 1 / mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001275 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001276 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001277 }
1278 }
1279
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001280 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001281 boolean hasContentToDisplay() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001282 // If we're animating with a saved surface, we're already visible.
1283 // Return true so that the alpha doesn't get cleared.
1284 if (!mAppFreezing && isDrawnLw()
1285 && (mViewVisibility == View.VISIBLE || isAnimatingWithSavedSurface()
1286 || (mWinAnimator.isAnimationSet() && !mService.mAppTransition.isTransitionSet()))) {
1287 return true;
1288 }
1289
Wale Ogunwale44f21802016-09-02 12:49:48 -07001290 return super.hasContentToDisplay();
1291 }
1292
1293 @Override
1294 boolean isVisible() {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001295 return wouldBeVisibleIfPolicyIgnored() && mPolicyVisibility;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001296 }
1297
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001298 /**
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001299 * @return True if the window would be visible if we'd ignore policy visibility, false
1300 * otherwise.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001301 */
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001302 boolean wouldBeVisibleIfPolicyIgnored() {
Jorim Jaggi43530c92017-05-18 01:53:56 +02001303 return mHasSurface && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001304 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001305 }
1306
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001307 @Override
1308 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001309 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001310 }
1311
1312 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001313 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1314 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001315 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001316 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1317 boolean isWinVisibleLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001318 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.mAppAnimator.animating)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001319 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001320 }
1321
1322 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001323 * The same as isVisible(), but follows the current hidden state of the associated app token,
1324 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001325 */
1326 boolean isVisibleNow() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001327 return (!mToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001328 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001329 }
1330
1331 /**
1332 * Can this window possibly be a drag/drop target? The test here is
1333 * a combination of the above "visible now" with the check that the
1334 * Input Manager uses when discarding windows from input consideration.
1335 */
1336 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001337 return isVisibleNow() && !mRemoved
1338 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001339 }
1340
1341 /**
1342 * Same as isVisible(), but we also count it as visible between the
1343 * call to IWindowSession.add() and the first relayout().
1344 */
1345 boolean isVisibleOrAdding() {
1346 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001347 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001348 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001349 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001350 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001351 }
1352
1353 /**
1354 * Is this window currently on-screen? It is on-screen either if it
1355 * is visible or it is currently running an animation before no longer
1356 * being visible.
1357 */
1358 boolean isOnScreen() {
Jorim Jaggiaf221d12016-11-15 14:59:57 -08001359 if (!mHasSurface || mDestroying || !mPolicyVisibility) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001360 return false;
1361 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001362 final AppWindowToken atoken = mAppToken;
1363 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001364 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001365 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001366 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07001367 return !isParentWindowHidden() || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001368 }
1369
1370 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001371 * Whether this window's drawn state might affect the drawn states of the app token.
1372 *
1373 * @param visibleOnly Whether we should consider only the windows that's currently
1374 * visible in layout. If true, windows that has not relayout to VISIBLE
1375 * would always return false.
1376 *
1377 * @return true if the window should be considered while evaluating allDrawn flags.
1378 */
1379 boolean mightAffectAllDrawn(boolean visibleOnly) {
Wale Ogunwale89973222017-04-23 18:39:45 -07001380 final boolean isViewVisible = (mAppToken == null || !mAppToken.isClientHidden())
Chong Zhange292eb32016-05-21 09:23:55 -07001381 && (mViewVisibility == View.VISIBLE) && !mWindowRemovalAllowed;
Jorim Jaggib0d27342016-11-01 16:10:42 -07001382 return (isOnScreen() && (!visibleOnly || isViewVisible)
Chong Zhangfea963e2016-08-15 17:14:16 -07001383 || mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1384 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION)
Chong Zhang8e4bda92016-05-04 15:08:18 -07001385 && !mAnimatingExit && !mDestroying;
1386 }
1387
1388 /**
1389 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1390 * it must be drawn before allDrawn can become true.
1391 */
1392 boolean isInteresting() {
1393 return mAppToken != null && !mAppDied
1394 && (!mAppToken.mAppAnimator.freezingScreen || !mAppFreezing);
1395 }
1396
1397 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001398 * Like isOnScreen(), but we don't return true if the window is part
1399 * of a transition that has not yet been started.
1400 */
1401 boolean isReadyForDisplay() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001402 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001403 return false;
1404 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001405 return mHasSurface && mPolicyVisibility && !mDestroying
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001406 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001407 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001408 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001409 }
1410
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001411 // TODO: Another visibility method that was added late in the release to minimize risk.
1412 @Override
1413 public boolean canAffectSystemUiFlags() {
1414 final boolean shown = mWinAnimator.getShown();
1415 final boolean exiting = mAnimatingExit || mDestroying
1416 || mAppToken != null && mAppToken.hidden;
1417 final boolean translucent = mAttrs.alpha == 0.0f;
1418 return shown && !exiting && !translucent;
1419 }
1420
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001421 /**
1422 * Like isOnScreen, but returns false if the surface hasn't yet
1423 * been drawn.
1424 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001425 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001426 public boolean isDisplayedLw() {
1427 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001428 return isDrawnLw() && mPolicyVisibility
Wale Ogunwale9d147902016-07-16 11:58:55 -07001429 && ((!isParentWindowHidden() &&
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001430 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001431 || mWinAnimator.mAnimating
1432 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001433 }
1434
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001435 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001436 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001437 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001438 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001439 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001440 return mWinAnimator.mAnimation != null
1441 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001442 }
1443
Craig Mautner812d2ca2012-09-27 15:35:34 -07001444 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001445 public boolean isGoneForLayoutLw() {
1446 final AppWindowToken atoken = mAppToken;
1447 return mViewVisibility == View.GONE
1448 || !mRelayoutCalled
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001449 || (atoken == null && mToken.hidden)
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001450 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001451 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001452 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001453 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001454 }
1455
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001456 /**
1457 * Returns true if the window has a surface that it has drawn a
1458 * complete UI in to.
1459 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001460 public boolean isDrawFinishedLw() {
1461 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001462 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1463 || mWinAnimator.mDrawState == READY_TO_SHOW
1464 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001465 }
1466
1467 /**
1468 * Returns true if the window has a surface that it has drawn a
1469 * complete UI in to.
1470 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001471 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001472 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001473 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001474 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001475 }
1476
1477 /**
1478 * Return true if the window is opaque and fully drawn. This indicates
1479 * it may obscure windows behind it.
1480 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001481 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001482 // When there is keyguard, wallpaper could be placed over the secure app
1483 // window but invisible. We need to check wallpaper visibility explicitly
1484 // to determine if it's occluding apps.
1485 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1486 || (mIsWallpaper && mWallpaperVisible))
Craig Mautnera2c77052012-03-26 12:14:43 -07001487 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001488 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001489 }
1490
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001491 @Override
1492 void onMovedByResize() {
1493 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001494 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001495 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001496 }
1497
1498 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1499 boolean changed = false;
1500
1501 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001502 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001503 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1504 }
1505
1506 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1507 // Starting window that's exiting will be removed when the animation finishes.
1508 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1509 // to actually remove it.
1510 if (!visible && isVisibleNow() && mAppToken.mAppAnimator.isAnimating()) {
1511 mAnimatingExit = true;
1512 mRemoveOnExit = true;
1513 mWindowRemovalAllowed = true;
1514 }
1515 return changed;
1516 }
1517
Robert Carrd5c7dd62017-03-08 10:39:30 -08001518 // Next up we will notify the client that it's visibility has changed.
1519 // We need to prevent it from destroying child surfaces until
1520 // the animation has finished.
1521 if (!visible && isVisibleNow()) {
1522 mWinAnimator.detachChildren();
1523 }
1524
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001525 if (visible != isVisibleNow()) {
1526 if (!runningAppAnimation) {
1527 final AccessibilityController accessibilityController =
1528 mService.mAccessibilityController;
1529 final int winTransit = visible ? TRANSIT_ENTER : TRANSIT_EXIT;
1530 mWinAnimator.applyAnimationLocked(winTransit, visible);
1531 //TODO (multidisplay): Magnification is supported only for the default
1532 if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
1533 accessibilityController.onWindowTransitionLocked(this, winTransit);
1534 }
1535 }
1536 changed = true;
1537 setDisplayLayoutNeeded();
1538 }
1539
1540 return changed;
1541 }
1542
1543 boolean onSetAppExiting() {
1544 final DisplayContent displayContent = getDisplayContent();
1545 boolean changed = false;
1546
1547 if (isVisibleNow()) {
1548 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
1549 //TODO (multidisplay): Magnification is supported only for the default
1550 if (mService.mAccessibilityController != null && isDefaultDisplay()) {
1551 mService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
1552 }
1553 changed = true;
1554 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001555 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001556 }
1557 }
1558
1559 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001560 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001561 changed |= c.onSetAppExiting();
1562 }
1563
1564 return changed;
1565 }
1566
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001567 @Override
1568 void onResize() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001569 // Some windows won't go through the resizing process, if they don't have a surface, so
1570 // destroy all saved surfaces here.
1571 destroySavedSurface();
1572
1573 final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
1574 if (mHasSurface && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001575 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001576 resizingWindows.add(this);
1577
1578 // If we are not drag resizing, force recreating of a new surface so updating
1579 // the content and positioning that surface will be in sync.
1580 //
1581 // As we use this flag as a hint to freeze surface boundary updates, we'd like to only
1582 // apply this to TYPE_BASE_APPLICATION, windows of TYPE_APPLICATION like dialogs, could
1583 // appear to not be drag resizing while they resize, but we'd still like to manipulate
1584 // their frame to update crop, etc...
1585 //
1586 // Anyway we don't need to synchronize position and content updates for these
1587 // windows since they aren't at the base layer and could be moved around anyway.
1588 if (!computeDragResizing() && mAttrs.type == TYPE_BASE_APPLICATION &&
Robert Carr8f0a3ad2017-02-15 19:30:28 -08001589 !mWinAnimator.isForceScaled() && !isGoneForLayoutLw() &&
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001590 !getTask().inPinnedWorkspace()) {
1591 setResizedWhileNotDragResizing(true);
1592 }
1593 }
1594 if (isGoneForLayoutLw()) {
1595 mResizedWhileGone = true;
1596 }
1597
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001598 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001599 }
1600
1601 void onUnfreezeBounds() {
1602 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001603 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001604 c.onUnfreezeBounds();
1605 }
1606
1607 if (!mHasSurface) {
1608 return;
1609 }
1610
1611 mLayoutNeeded = true;
1612 setDisplayLayoutNeeded();
1613 if (!mService.mResizingWindows.contains(this)) {
1614 mService.mResizingWindows.add(this);
1615 }
1616 }
1617
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001618 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001619 * If the window has moved due to its containing content frame changing, then notify the
1620 * listeners and optionally animate it. Simply checking a change of position is not enough,
1621 * because being move due to dock divider is not a trigger for animation.
1622 */
1623 void handleWindowMovedIfNeeded() {
1624 if (!hasMoved()) {
1625 return;
1626 }
1627
1628 // Frame has moved, containing content frame has also moved, and we're not currently
1629 // animating... let's do something.
1630 final int left = mFrame.left;
1631 final int top = mFrame.top;
1632 final Task task = getTask();
1633 final boolean adjustedForMinimizedDockOrIme = task != null
1634 && (task.mStack.isAdjustedForMinimizedDockedStack()
1635 || task.mStack.isAdjustedForIme());
Adrian Roose94c15c2017-05-09 13:17:54 -07001636 if (mService.okToAnimate()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001637 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1638 && !isDragResizing() && !adjustedForMinimizedDockOrIme
1639 && (task == null || getTask().mStack.hasMovementAnimations())
1640 && !mWinAnimator.mLastHidden) {
1641 mWinAnimator.setMoveAnimation(left, top);
1642 }
1643
1644 //TODO (multidisplay): Accessibility supported only for the default display.
1645 if (mService.mAccessibilityController != null
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001646 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001647 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
1648 }
1649
1650 try {
1651 mClient.moved(left, top);
1652 } catch (RemoteException e) {
1653 }
1654 mMovedByResize = false;
1655 }
1656
1657 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001658 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001659 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1660 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001661 private boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001662 return mHasSurface && (mContentChanged || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001663 && !mAnimatingExit
Chong Zhangbd0d9372015-12-28 15:18:29 -08001664 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001665 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001666 }
1667
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001668 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001669 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001670 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001671 return false;
1672 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001673 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001674 }
1675
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001676 boolean fillsDisplay() {
1677 final DisplayInfo displayInfo = getDisplayInfo();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001678 return mFrame.left <= 0 && mFrame.top <= 0
1679 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001680 }
1681
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001682 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001683 boolean isConfigChanged() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001684 return !mLastReportedConfiguration.equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001685 }
1686
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001687 void onWindowReplacementTimeout() {
1688 if (mWillReplaceWindow) {
1689 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001690 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001691 // delays removal on certain conditions, which will leave the stale window in the
1692 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1693 //
1694 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001695 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001696 } else {
1697 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001698 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001699 c.onWindowReplacementTimeout();
1700 }
1701 }
1702 }
1703
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001704 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001705 void forceWindowsScaleableInTransaction(boolean force) {
1706 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1707 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1708 }
1709
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001710 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001711 }
1712
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001713 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001714 void removeImmediately() {
1715 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001716
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001717 if (mRemoved) {
1718 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001719 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1720 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001721 return;
1722 }
1723
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001724 mRemoved = true;
1725
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001726 mWillReplaceWindow = false;
1727 if (mReplacementWindow != null) {
1728 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1729 }
1730
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001731 final DisplayContent dc = getDisplayContent();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001732 if (mService.mInputMethodTarget == this) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001733 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001734 }
1735
1736 final int type = mAttrs.type;
1737 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001738 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001739 }
1740 mPolicy.removeWindowLw(this);
1741
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001742 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001743
Craig Mautner96868332012-12-04 14:29:11 -08001744 mWinAnimator.destroyDeferredSurfaceLocked();
1745 mWinAnimator.destroySurfaceLocked();
Wale Ogunwale943002b2017-02-15 19:34:01 -08001746 mSession.windowRemovedLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001747 try {
1748 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1749 } catch (RuntimeException e) {
1750 // Ignore if it has already been removed (usually because
1751 // we are doing this as part of processing a death note.)
1752 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001753
1754 mService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001755 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001756
Wale Ogunwale571771c2016-08-26 13:18:50 -07001757 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001758 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001759 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001760 removeIfPossible(false /*keepVisibleDeadWindow*/);
1761 }
1762
Wale Ogunwale571771c2016-08-26 13:18:50 -07001763 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001764 mWindowRemovalAllowed = true;
1765 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1766 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1767
1768 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1769 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1770 "Starting window removed " + this);
1771
1772 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && this == mService.mCurrentFocus)
1773 Slog.v(TAG_WM, "Remove " + this + " client="
1774 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1775 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1776 + Debug.getCallers(5));
1777
1778 final long origId = Binder.clearCallingIdentity();
1779
1780 disposeInputChannel();
1781
1782 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1783 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1784 + " mAnimatingExit=" + mAnimatingExit
1785 + " mRemoveOnExit=" + mRemoveOnExit
1786 + " mHasSurface=" + mHasSurface
1787 + " surfaceShowing=" + mWinAnimator.getShown()
1788 + " isAnimationSet=" + mWinAnimator.isAnimationSet()
1789 + " app-animation="
1790 + (mAppToken != null ? mAppToken.mAppAnimator.animation : null)
1791 + " mWillReplaceWindow=" + mWillReplaceWindow
1792 + " inPendingTransaction="
1793 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
1794 + " mDisplayFrozen=" + mService.mDisplayFrozen
1795 + " callers=" + Debug.getCallers(6));
1796
1797 // Visibility of the removed window. Will be used later to update orientation later on.
1798 boolean wasVisible = false;
1799
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001800 final int displayId = getDisplayId();
1801
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001802 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1803 // window until the animation is done. If the display is frozen, just remove immediately,
1804 // since the animation wouldn't be seen.
Adrian Roose94c15c2017-05-09 13:17:54 -07001805 if (mHasSurface && mService.okToAnimate()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001806 if (mWillReplaceWindow) {
1807 // This window is going to be replaced. We need to keep it around until the new one
1808 // gets added, then we will get rid of this one.
1809 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1810 "Preserving " + this + " until the new one is " + "added");
1811 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1812 // been removed. We probably need another flag to indicate that window removal
1813 // should be deffered vs. overloading the flag that says we are playing an exit
1814 // animation.
1815 mAnimatingExit = true;
1816 mReplacingRemoveRequested = true;
1817 Binder.restoreCallingIdentity(origId);
1818 return;
1819 }
1820
1821 if (isAnimatingWithSavedSurface() && !mAppToken.allDrawnExcludingSaved) {
1822 // We started enter animation early with a saved surface, now the app asks to remove
1823 // this window. If we remove it now and the app is not yet drawn, we'll show a
1824 // flicker. Delay the removal now until it's really drawn.
1825 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
1826 "removeWindowLocked: delay removal of " + this + " due to early animation");
1827 // Do not set mAnimatingExit to true here, it will cause the surface to be hidden
1828 // immediately after the enter animation is done. If the app is not yet drawn then
1829 // it will show up as a flicker.
1830 setupWindowForRemoveOnExit();
1831 Binder.restoreCallingIdentity(origId);
1832 return;
1833 }
1834 // If we are not currently running the exit animation, we need to see about starting one
1835 wasVisible = isWinVisibleLw();
1836
1837 if (keepVisibleDeadWindow) {
1838 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1839 "Not removing " + this + " because app died while it's visible");
1840
1841 mAppDied = true;
1842 setDisplayLayoutNeeded();
1843 mService.mWindowPlacerLocked.performSurfacePlacement();
1844
1845 // Set up a replacement input channel since the app is now dead.
1846 // We need to catch tapping on the dead window to restart the app.
1847 openInputChannel(null);
1848 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
1849
1850 Binder.restoreCallingIdentity(origId);
1851 return;
1852 }
1853
1854 if (wasVisible) {
1855 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
1856
1857 // Try starting an animation.
1858 if (mWinAnimator.applyAnimationLocked(transit, false)) {
1859 mAnimatingExit = true;
1860 }
1861 //TODO (multidisplay): Magnification is supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001862 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001863 mService.mAccessibilityController.onWindowTransitionLocked(this, transit);
1864 }
1865 }
1866 final boolean isAnimating =
1867 mWinAnimator.isAnimationSet() && !mWinAnimator.isDummyAnimation();
1868 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001869 && mAppToken.isLastWindow(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001870 // We delay the removal of a window if it has a showing surface that can be used to run
1871 // exit animation and it is marked as exiting.
1872 // Also, If isn't the an animating starting window that is the last window in the app.
1873 // We allow the removal of the non-animating starting window now as there is no
1874 // additional window or animation that will trigger its removal.
1875 if (mWinAnimator.getShown() && mAnimatingExit
1876 && (!lastWindowIsStartingWindow || isAnimating)) {
1877 // The exit animation is running or should run... wait for it!
1878 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1879 "Not removing " + this + " due to exit animation ");
1880 setupWindowForRemoveOnExit();
1881 if (mAppToken != null) {
1882 mAppToken.updateReportedVisibilityLocked();
1883 }
1884 Binder.restoreCallingIdentity(origId);
1885 return;
1886 }
1887 }
1888
Wale Ogunwale571771c2016-08-26 13:18:50 -07001889 removeImmediately();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001890 // Removing a visible window will effect the computed orientation
1891 // So just update orientation if needed.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001892 if (wasVisible && mService.updateOrientationFromAppTokensLocked(false, displayId)) {
1893 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001894 }
1895 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
1896 Binder.restoreCallingIdentity(origId);
1897 }
1898
1899 private void setupWindowForRemoveOnExit() {
1900 mRemoveOnExit = true;
1901 setDisplayLayoutNeeded();
1902 // Request a focus update as this window's input channel is already gone. Otherwise
1903 // we could have no focused window in input manager.
1904 final boolean focusChanged = mService.updateFocusedWindowLocked(
1905 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
1906 mService.mWindowPlacerLocked.performSurfacePlacement();
1907 if (focusChanged) {
1908 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
1909 }
1910 }
1911
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001912 void setHasSurface(boolean hasSurface) {
1913 mHasSurface = hasSurface;
1914 }
1915
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001916 int getAnimLayerAdjustment() {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -08001917 if (mIsImWindow && mService.mInputMethodTarget != null) {
Wale Ogunwale455fac52016-07-21 07:24:49 -07001918 final AppWindowToken appToken = mService.mInputMethodTarget.mAppToken;
1919 if (appToken != null) {
Robert Carrdee1b3f2017-02-27 11:33:33 -08001920 return appToken.getAnimLayerAdjustment();
Wale Ogunwale455fac52016-07-21 07:24:49 -07001921 }
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001922 }
Wale Ogunwale455fac52016-07-21 07:24:49 -07001923
Robert Carrdee1b3f2017-02-27 11:33:33 -08001924 return mToken.getAnimLayerAdjustment();
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001925 }
1926
Wale Ogunwalec69694a2016-10-18 13:51:15 -07001927 int getSpecialWindowAnimLayerAdjustment() {
1928 int specialAdjustment = 0;
1929 if (mIsImWindow) {
1930 specialAdjustment = getDisplayContent().mInputMethodAnimLayerAdjustment;
1931 } else if (mIsWallpaper) {
Wale Ogunwale0303c572016-10-20 10:16:29 -07001932 specialAdjustment = getDisplayContent().mWallpaperController.getAnimLayerAdjustment();
Wale Ogunwalec69694a2016-10-18 13:51:15 -07001933 }
1934
1935 return mLayer + specialAdjustment;
1936 }
1937
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001938 boolean canBeImeTarget() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08001939 if (mIsImWindow) {
1940 // IME windows can't be IME targets. IME targets are required to be below the IME
1941 // windows and that wouldn't be possible if the IME window is its own target...silly.
1942 return false;
1943 }
1944
1945 final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001946 final int type = mAttrs.type;
1947
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08001948 // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are set or
1949 // both are cleared...and not a starting window.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001950 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
1951 && type != TYPE_APPLICATION_STARTING) {
1952 return false;
1953 }
1954
1955 if (DEBUG_INPUT_METHOD) {
1956 Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding());
1957 if (!isVisibleOrAdding()) {
1958 Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController
1959 + " relayoutCalled=" + mRelayoutCalled
1960 + " viewVis=" + mViewVisibility
1961 + " policyVis=" + mPolicyVisibility
1962 + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim
1963 + " parentHidden=" + isParentWindowHidden()
1964 + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
1965 if (mAppToken != null) {
1966 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + mAppToken.hiddenRequested);
1967 }
1968 }
1969 }
1970 return isVisibleOrAdding();
1971 }
1972
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001973 void scheduleAnimationIfDimming() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001974 final DisplayContent dc = getDisplayContent();
1975 if (dc == null) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001976 return;
1977 }
1978 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001979 if (dimLayerUser != null && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator)) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001980 // Force an animation pass just to update the mDimLayer layer.
1981 mService.scheduleAnimationLocked();
1982 }
1983 }
1984
Chong Zhangacf11402015-11-04 16:23:10 -08001985 private final class DeadWindowEventReceiver extends InputEventReceiver {
1986 DeadWindowEventReceiver(InputChannel inputChannel) {
1987 super(inputChannel, mService.mH.getLooper());
1988 }
1989 @Override
1990 public void onInputEvent(InputEvent event) {
1991 finishInputEvent(event, true);
1992 }
1993 }
1994 /**
1995 * Dummy event receiver for windows that died visible.
1996 */
1997 private DeadWindowEventReceiver mDeadWindowEventReceiver;
1998
Chong Zhang112eb8c2015-11-02 11:17:00 -08001999 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002000 if (mInputChannel != null) {
2001 throw new IllegalStateException("Window already has an input channel.");
2002 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002003 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002004 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2005 mInputChannel = inputChannels[0];
2006 mClientChannel = inputChannels[1];
2007 mInputWindowHandle.inputChannel = inputChannels[0];
2008 if (outInputChannel != null) {
2009 mClientChannel.transferTo(outInputChannel);
2010 mClientChannel.dispose();
2011 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002012 } else {
2013 // If the window died visible, we setup a dummy input channel, so that taps
2014 // can still detected by input monitor channel, and we can relaunch the app.
2015 // Create dummy event receiver that simply reports all events as handled.
2016 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002017 }
2018 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002019 }
2020
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002021 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002022 if (mDeadWindowEventReceiver != null) {
2023 mDeadWindowEventReceiver.dispose();
2024 mDeadWindowEventReceiver = null;
2025 }
2026
2027 // unregister server channel first otherwise it complains about broken channel
2028 if (mInputChannel != null) {
2029 mService.mInputManager.unregisterInputChannel(mInputChannel);
2030 mInputChannel.dispose();
2031 mInputChannel = null;
2032 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002033 if (mClientChannel != null) {
2034 mClientChannel.dispose();
2035 mClientChannel = null;
2036 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07002037 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002038 }
2039
Chong Zhang112eb8c2015-11-02 11:17:00 -08002040 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08002041 // When the app is terminated (eg. from Recents), the task might have already been
2042 // removed with the window pending removal. Don't apply dim in such cases, as there
2043 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
2044 final AppWindowToken token = mAppToken;
2045 if (token != null && token.removed) {
2046 return;
2047 }
2048
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002049 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002050 if (!mAnimatingExit && mAppDied) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08002051 // If app died visible, apply a dim over the window to indicate that it's inactive
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002052 dc.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002053 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02002054 && dc != null && !mAnimatingExit && isVisible()) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002055 dc.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07002056 }
2057 }
2058
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002059 private DimLayer.DimLayerUser getDimLayerUser() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002060 Task task = getTask();
2061 if (task != null) {
2062 return task;
2063 }
2064 return getStack();
2065 }
2066
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002067 /** Returns true if the replacement window was removed. */
2068 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2069 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2070 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2071 removeReplacedWindow();
2072 return true;
2073 }
2074
2075 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002076 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002077 if (c.removeReplacedWindowIfNeeded(replacement)) {
2078 return true;
2079 }
2080 }
2081 return false;
2082 }
2083
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002084 private void removeReplacedWindow() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002085 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
2086 if (isDimming()) {
2087 transferDimToReplacement();
Robert Carra1eb4392015-12-10 12:43:51 -08002088 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002089 mWillReplaceWindow = false;
2090 mAnimateReplacingWindow = false;
2091 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002092 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002093 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002094 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002095 }
2096 }
2097
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002098 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2099 boolean replacementSet = false;
2100
2101 if (mWillReplaceWindow && mReplacementWindow == null
2102 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2103
2104 mReplacementWindow = replacementCandidate;
2105 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2106 replacementSet = true;
2107 }
2108
2109 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002110 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002111 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2112 }
2113
2114 return replacementSet;
2115 }
2116
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002117 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002118 final DisplayContent dc = getDisplayContent();
2119 if (dc != null) {
2120 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002121 }
2122 }
2123
Robert Carrfed10072016-05-26 11:48:49 -07002124 // TODO: Strange usage of word workspace here and above.
2125 boolean inPinnedWorkspace() {
2126 final Task task = getTask();
2127 return task != null && task.inPinnedWorkspace();
2128 }
2129
Chong Zhang5117e272016-05-03 12:47:34 -07002130 void applyAdjustForImeIfNeeded() {
2131 final Task task = getTask();
2132 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2133 task.mStack.applyAdjustForImeIfNeeded(task);
2134 }
2135 }
2136
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002137 @Override
2138 void switchUser() {
2139 super.switchUser();
2140 if (isHiddenFromUserLocked()) {
2141 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2142 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
2143 hideLw(false);
2144 }
2145 }
2146
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002147 int getTouchableRegion(Region region, int flags) {
2148 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002149 if (modal && mAppToken != null) {
2150 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002151 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002152 // If this is a modal window we need to dismiss it if it's not full screen and the
2153 // touch happens outside of the frame that displays the content. This means we
2154 // need to intercept touches outside of that window. The dim layer user
2155 // associated with the window (task or stack) will give us the good bounds, as
2156 // they would be used to display the dim layer.
2157 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
2158 if (dimLayerUser != null) {
2159 dimLayerUser.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002160 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002161 getVisibleBounds(mTmpRect);
2162 }
2163 if (inFreeformWorkspace()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002164 // For freeform windows we the touch region to include the whole surface for the
2165 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002166 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2167 final int delta = WindowManagerService.dipToPixel(
2168 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2169 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002170 }
2171 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002172 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002173 } else {
2174 // Not modal or full screen modal
2175 getTouchableRegion(region);
2176 }
2177 return flags;
2178 }
2179
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002180 void checkPolicyVisibilityChange() {
2181 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2182 if (DEBUG_VISIBILITY) {
2183 Slog.v(TAG, "Policy visibility changing after anim in " +
2184 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2185 }
2186 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08002187 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002188 if (!mPolicyVisibility) {
2189 if (mService.mCurrentFocus == this) {
2190 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2191 "setAnimationLocked: setting mFocusMayChange true");
2192 mService.mFocusMayChange = true;
2193 }
2194 // Window is no longer visible -- make sure if we were waiting
2195 // for it to be displayed before enabling the display, that
2196 // we allow the display to be enabled now.
2197 mService.enableScreenIfNeededLocked();
2198 }
2199 }
2200 }
2201
2202 void setRequestedSize(int requestedWidth, int requestedHeight) {
2203 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2204 mLayoutNeeded = true;
2205 mRequestedWidth = requestedWidth;
2206 mRequestedHeight = requestedHeight;
2207 }
2208 }
2209
Bryce Leef858b572017-06-29 14:03:33 -07002210 void prepareWindowToDisplayDuringRelayout(boolean wasVisible) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002211 // We need to turn on screen regardless of visibility.
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002212 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
2213 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
2214 mTurnOnScreen = true;
2215 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002216
2217 // If we were already visible, skip rest of preparation.
2218 if (wasVisible) {
2219 if (DEBUG_VISIBILITY) Slog.v(TAG,
2220 "Already visible and does not turn on screen, skip preparing: " + this);
2221 return;
2222 }
2223
2224 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2225 == SOFT_INPUT_ADJUST_RESIZE) {
2226 mLayoutNeeded = true;
2227 }
2228
Adrian Roose94c15c2017-05-09 13:17:54 -07002229 if (isDrawnLw() && mService.okToAnimate()) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002230 mWinAnimator.applyEnterAnimationLocked();
2231 }
Bryce Leef858b572017-06-29 14:03:33 -07002232 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002233
Bryce Leef858b572017-06-29 14:03:33 -07002234 void getMergedConfiguration(MergedConfiguration outConfiguration) {
2235 final Configuration globalConfig = mService.mRoot.getConfiguration();
2236 final Configuration overrideConfig = getMergedOverrideConfiguration();
2237 outConfiguration.setConfiguration(globalConfig, overrideConfig);
2238 }
2239
2240 void setReportedConfiguration(MergedConfiguration config) {
2241 mLastReportedConfiguration.setTo(config.getMergedConfiguration());
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002242 }
2243
2244 void adjustStartingWindowFlags() {
2245 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2246 && mAppToken.startingWindow != null) {
2247 // Special handling of starting window over the base
2248 // window of the app: propagate lock screen flags to it,
2249 // to provide the correct semantics while starting.
2250 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2251 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2252 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2253 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2254 }
2255 }
2256
2257 void setWindowScale(int requestedWidth, int requestedHeight) {
2258 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2259
2260 if (scaledWindow) {
2261 // requested{Width|Height} Surface's physical size
2262 // attrs.{width|height} Size on screen
2263 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2264 mHScale = (mAttrs.width != requestedWidth) ?
2265 (mAttrs.width / (float)requestedWidth) : 1.0f;
2266 mVScale = (mAttrs.height != requestedHeight) ?
2267 (mAttrs.height / (float)requestedHeight) : 1.0f;
2268 } else {
2269 mHScale = mVScale = 1;
2270 }
2271 }
2272
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002273 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002274 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002275 public void binderDied() {
2276 try {
2277 synchronized(mService.mWindowMap) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002278 final WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002279 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002280 if (win != null) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002281 final DisplayContent dc = getDisplayContent();
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002282 if (win.mAppToken != null && win.mAppToken.findMainWindow() == win) {
2283 mService.mTaskSnapshotController.onAppDied(win.mAppToken);
2284 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002285 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002286 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2287 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002288 // just in case they have the divider at an unstable position. Better
2289 // also reset drag resizing state, because the owner can't do it
2290 // anymore.
Wale Ogunwale1666e312016-12-16 11:27:18 -08002291 final TaskStack stack = dc.getDockedStackIgnoringVisibility();
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002292 if (stack != null) {
2293 stack.resetDockedStackToMiddle();
2294 }
Jorim Jaggidcb68142016-02-09 21:51:30 -08002295 mService.setDockedStackResizing(false);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002296 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002297 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002298 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002299 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002300 }
2301 }
2302 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002303 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002304 }
2305 }
2306 }
2307
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002308 /**
2309 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2310 * because we want to preserve its location on screen to be re-activated later when the user
2311 * interacts with it.
2312 */
2313 boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwale89973222017-04-23 18:39:45 -07002314 if (!isWinVisibleLw() || mAppToken == null || mAppToken.isClientHidden()) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002315 // Not a visible app window or the app isn't dead.
2316 return false;
2317 }
2318
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002319 if (mAttrs.token != mClient.asBinder()) {
2320 // The window was add by a client using another client's app token. We don't want to
2321 // keep the dead window around for this case since this is meant for 'real' apps.
2322 return false;
2323 }
2324
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002325 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2326 // We don't keep starting windows since they were added by the window manager before
2327 // the app even launched.
2328 return false;
2329 }
2330
2331 final TaskStack stack = getStack();
2332 return stack != null && StackId.keepVisibleDeadAppWindowOnScreen(stack.mStackId);
2333 }
2334
Wale Ogunwaled045c822015-12-02 09:14:28 -08002335 /** @return true if this window desires key events. */
2336 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002337 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002338 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002339 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002340 && (mAppToken == null || mAppToken.windowsAreFocusable())
Matthew Nge15352e2016-12-20 15:36:29 -08002341 && !canReceiveTouchInput();
2342 }
2343
2344 /** @return true if this window desires touch events. */
2345 boolean canReceiveTouchInput() {
Bryce Lee6d410262017-02-28 15:30:17 -08002346 return mAppToken != null && mAppToken.getTask() != null
2347 && mAppToken.getTask().mStack.shouldIgnoreInput();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002348 }
2349
Craig Mautner749a7bb2012-04-02 13:49:53 -07002350 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002351 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002352 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002353 }
2354
Craig Mautner749a7bb2012-04-02 13:49:53 -07002355 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002356 public boolean showLw(boolean doAnimation) {
2357 return showLw(doAnimation, true);
2358 }
2359
2360 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002361 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002362 return false;
2363 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002364 if (!mAppOpVisibility) {
2365 // Being hidden due to app op request.
2366 return false;
2367 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002368 if (mPermanentlyHidden) {
2369 // Permanently hidden until the app exists as apps aren't prepared
2370 // to handle their windows being removed from under them.
2371 return false;
2372 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002373 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002374 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002375 return false;
2376 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002377 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002378 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002379 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07002380 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Adrian Roose94c15c2017-05-09 13:17:54 -07002381 if (!mService.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002382 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07002383 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002384 // Check for the case where we are currently visible and
2385 // not animating; we do not want to do animation at such a
2386 // point to become visible when we already are.
2387 doAnimation = false;
2388 }
2389 }
2390 mPolicyVisibility = true;
2391 mPolicyVisibilityAfterAnim = true;
2392 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002393 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002394 }
2395 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002396 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002397 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002398 if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) {
2399 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2400 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002401 return true;
2402 }
2403
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002404 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002405 public boolean hideLw(boolean doAnimation) {
2406 return hideLw(doAnimation, true);
2407 }
2408
2409 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2410 if (doAnimation) {
Adrian Roose94c15c2017-05-09 13:17:54 -07002411 if (!mService.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002412 doAnimation = false;
2413 }
2414 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002415 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002416 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002417 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002418 return false;
2419 }
2420 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002421 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07002422 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002423 doAnimation = false;
2424 }
2425 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002426 mPolicyVisibilityAfterAnim = false;
2427 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002428 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002429 mPolicyVisibility = false;
2430 // Window is no longer visible -- make sure if we were waiting
2431 // for it to be displayed before enabling the display, that
2432 // we allow the display to be enabled now.
2433 mService.enableScreenIfNeededLocked();
2434 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002435 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002436 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002437 mService.mFocusMayChange = true;
2438 }
2439 }
2440 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002441 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002442 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002443 if (mService.mCurrentFocus == this) {
2444 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2445 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002446 return true;
2447 }
2448
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002449 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002450 if (mAppOpVisibility != state) {
2451 mAppOpVisibility = state;
2452 if (state) {
2453 // If the policy visibility had last been to hide, then this
2454 // will incorrectly show at this point since we lost that
2455 // information. Not a big deal -- for the windows that have app
2456 // ops modifies they should only be hidden by policy due to the
2457 // lock screen, and the user won't be changing this if locked.
2458 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002459 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002460 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002461 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002462 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002463 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002464 }
2465
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002466 public void hidePermanentlyLw() {
2467 if (!mPermanentlyHidden) {
2468 mPermanentlyHidden = true;
2469 hideLw(true, true);
2470 }
2471 }
2472
Jeff Brownc2932a12014-11-20 18:04:05 -08002473 public void pokeDrawLockLw(long timeout) {
2474 if (isVisibleOrAdding()) {
2475 if (mDrawLock == null) {
2476 // We want the tag name to be somewhat stable so that it is easier to correlate
2477 // in wake lock statistics. So in particular, we don't want to include the
2478 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002479 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08002480 mDrawLock = mService.mPowerManager.newWakeLock(
2481 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
2482 mDrawLock.setReferenceCounted(false);
2483 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2484 }
2485 // Each call to acquire resets the timeout.
2486 if (DEBUG_POWER) {
2487 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2488 + mAttrs.packageName);
2489 }
2490 mDrawLock.acquire(timeout);
2491 } else if (DEBUG_POWER) {
2492 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2493 + "owned by " + mAttrs.packageName);
2494 }
2495 }
2496
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002497 @Override
2498 public boolean isAlive() {
2499 return mClient.asBinder().isBinderAlive();
2500 }
2501
Craig Mautnera987d432012-10-11 14:07:58 -07002502 boolean isClosing() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002503 return mAnimatingExit || (mService.mClosingApps.contains(mAppToken));
Craig Mautnera987d432012-10-11 14:07:58 -07002504 }
2505
Chong Zhangbef461f2015-10-27 11:38:24 -07002506 boolean isAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002507 return mAnimatingWithSavedSurface;
2508 }
2509
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002510 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002511 boolean isAnimating() {
2512 if (mWinAnimator.isAnimationSet() || mAnimatingExit) {
2513 return true;
2514 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002515 return super.isAnimating();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002516 }
2517
Chong Zhang8e4bda92016-05-04 15:08:18 -07002518 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002519 if (mAnimatingWithSavedSurface
2520 && (mViewVisibility != View.VISIBLE || mWindowRemovalAllowed)) {
2521 return true;
2522 }
2523 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002524 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002525 if (c.isAnimatingInvisibleWithSavedSurface()) {
2526 return true;
2527 }
2528 }
2529 return false;
2530 }
2531
2532 void stopUsingSavedSurface() {
2533 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002534 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002535 c.stopUsingSavedSurface();
2536 }
2537
2538 if (!isAnimatingInvisibleWithSavedSurface()) {
2539 return;
2540 }
2541
2542 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG, "stopUsingSavedSurface: " + this);
2543 clearAnimatingWithSavedSurface();
2544 mDestroying = true;
2545 mWinAnimator.hide("stopUsingSavedSurface");
Wale Ogunwale0303c572016-10-20 10:16:29 -07002546 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002547 }
2548
2549 void markSavedSurfaceExiting() {
2550 if (isAnimatingInvisibleWithSavedSurface()) {
2551 mAnimatingExit = true;
2552 mWinAnimator.mAnimating = true;
2553 }
2554 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002555 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002556 c.markSavedSurfaceExiting();
2557 }
2558 }
2559
2560 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2561 animators.add(mWinAnimator);
2562
2563 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002564 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002565 c.addWinAnimatorToList(animators);
2566 }
2567 }
2568
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002569 void sendAppVisibilityToClients() {
2570 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002571
Wale Ogunwale89973222017-04-23 18:39:45 -07002572 final boolean clientHidden = mAppToken.isClientHidden();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002573 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2574 // Don't hide the starting window.
2575 return;
2576 }
2577
Wale Ogunwale89973222017-04-23 18:39:45 -07002578 if (clientHidden) {
2579 // Once we are notifying the client that it's visibility has changed, we need to prevent
2580 // it from destroying child surfaces until the animation has finished. We do this by
2581 // detaching any surface control the client added from the client.
2582 for (int i = mChildren.size() - 1; i >= 0; --i) {
2583 final WindowState c = mChildren.get(i);
2584 c.mWinAnimator.detachChildren();
2585 }
2586
2587 mWinAnimator.detachChildren();
2588 }
2589
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002590 try {
2591 if (DEBUG_VISIBILITY) Slog.v(TAG,
2592 "Setting visibility of " + this + ": " + (!clientHidden));
2593 mClient.dispatchAppVisibility(!clientHidden);
2594 } catch (RemoteException e) {
2595 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002596 }
2597
Chong Zhang92147042016-05-09 12:47:11 -07002598 public void setVisibleBeforeClientHidden() {
2599 mWasVisibleBeforeClientHidden |=
2600 (mViewVisibility == View.VISIBLE || mAnimatingWithSavedSurface);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002601
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002602 super.setVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -07002603 }
2604
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002605 public void clearWasVisibleBeforeClientHidden() {
Chong Zhang92147042016-05-09 12:47:11 -07002606 mWasVisibleBeforeClientHidden = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002607 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.clearWasVisibleBeforeClientHidden();
2610 }
Chong Zhang92147042016-05-09 12:47:11 -07002611 }
2612
2613 public boolean wasVisibleBeforeClientHidden() {
2614 return mWasVisibleBeforeClientHidden;
Chong Zhangbef461f2015-10-27 11:38:24 -07002615 }
2616
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002617 void onStartFreezingScreen() {
2618 mAppFreezing = true;
2619 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002620 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002621 c.onStartFreezingScreen();
2622 }
2623 }
2624
2625 boolean onStopFreezingScreen() {
2626 boolean unfrozeWindows = false;
2627 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002628 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002629 unfrozeWindows |= c.onStopFreezingScreen();
2630 }
2631
2632 if (!mAppFreezing) {
2633 return unfrozeWindows;
2634 }
2635
Wale Ogunwale953171d2016-09-30 09:17:30 -07002636 mAppFreezing = false;
2637
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002638 if (mHasSurface && !mOrientationChanging
2639 && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
2640 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
2641 mOrientationChanging = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002642 mService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002643 }
2644 mLastFreezeDuration = 0;
2645 setDisplayLayoutNeeded();
2646 return true;
2647 }
2648
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002649 private boolean shouldSaveSurface() {
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002650 if (mWinAnimator.mSurfaceController == null) {
2651 // Don't bother if the surface controller is gone for any reason.
2652 return false;
2653 }
2654
Chong Zhang92147042016-05-09 12:47:11 -07002655 if (!mWasVisibleBeforeClientHidden) {
2656 return false;
2657 }
2658
Wale Ogunwale945d1972016-03-23 13:16:41 -07002659 if ((mAttrs.flags & FLAG_SECURE) != 0) {
2660 // We don't save secure surfaces since their content shouldn't be shown while the app
2661 // isn't on screen and content might leak through during the transition animation with
2662 // saved surface.
2663 return false;
2664 }
2665
Jorim Jaggi02886a82016-12-06 09:10:06 -08002666 if (isLowRamDeviceStatic()) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002667 // Don't save surfaces on Svelte devices.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002668 return false;
2669 }
2670
Jorim Jaggiab7ad382016-10-26 18:22:04 -07002671 final Task task = getTask();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002672 final AppWindowToken taskTop = task.getTopVisibleAppToken();
2673 if (taskTop != null && taskTop != mAppToken) {
2674 // Don't save if the window is not the topmost window.
2675 return false;
2676 }
2677
Jorim Jaggi8fa45222016-02-19 19:54:39 -08002678 if (mResizedWhileGone) {
2679 // Somebody resized our window while we were gone for layout, which means that the
2680 // client got an old size, so we have an outdated surface here.
2681 return false;
2682 }
2683
Robert Carr7098dbd2016-02-01 12:31:01 -08002684 if (DEBUG_DISABLE_SAVING_SURFACES) {
2685 return false;
2686 }
2687
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002688 return mAppToken.shouldSaveSurface();
2689 }
2690
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002691 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2692 boolean destroyedSomething = false;
2693 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002694 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002695 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2696 }
2697
Robert Carrdb2f6e62017-03-01 20:17:58 -08002698 if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) {
2699 return destroyedSomething;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002700 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08002701
2702 if (appStopped || mWindowRemovalAllowed) {
2703 mWinAnimator.destroyPreservedSurfaceLocked();
2704 }
2705
2706 if (mDestroying) {
2707 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2708 + " destroySurfaces: appStopped=" + appStopped
2709 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2710 + " win.mRemoveOnExit=" + mRemoveOnExit);
2711 if (!cleanupOnResume || mRemoveOnExit) {
Robert Carr89a28ab2017-04-24 15:33:11 -07002712 destroyOrSaveSurfaceUnchecked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08002713 }
2714 if (mRemoveOnExit) {
2715 removeImmediately();
2716 }
2717 if (cleanupOnResume) {
2718 requestUpdateWallpaperIfNeeded();
2719 }
2720 mDestroying = false;
2721 destroyedSomething = true;
2722 }
2723
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002724 return destroyedSomething;
2725 }
Chris Craik3131bde2016-05-06 13:39:08 -07002726
Robert Carr89a28ab2017-04-24 15:33:11 -07002727 // Destroy or save the application surface without checking
2728 // various indicators of whether the client has released the surface.
2729 // This is in general unsafe, and most callers should use {@link #destroySurface}
2730 void destroyOrSaveSurfaceUnchecked() {
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002731 mSurfaceSaved = shouldSaveSurface();
2732 if (mSurfaceSaved) {
2733 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2734 Slog.v(TAG, "Saving surface: " + this);
2735 }
Chris Craik3131bde2016-05-06 13:39:08 -07002736 // Previous user of the surface may have set a transparent region signaling a portion
2737 // doesn't need to be composited, so reset to default empty state.
2738 mSession.setTransparentRegion(mClient, sEmptyRegion);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002739
2740 mWinAnimator.hide("saved surface");
2741 mWinAnimator.mDrawState = WindowStateAnimator.NO_SURFACE;
2742 setHasSurface(false);
Chong Zhang47e36a32016-02-29 16:44:33 -08002743 // The client should have disconnected at this point, but if it doesn't,
2744 // we need to make sure it's disconnected. Otherwise when we reuse the surface
2745 // the client can't reconnect to the buffer queue, and rendering will fail.
2746 if (mWinAnimator.mSurfaceController != null) {
2747 mWinAnimator.mSurfaceController.disconnectInTransaction();
2748 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002749 mAnimatingWithSavedSurface = false;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002750 } else {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002751 mWinAnimator.destroySurfaceLocked();
2752 }
Chong Zhang92147042016-05-09 12:47:11 -07002753 // Clear animating flags now, since the surface is now gone. (Note this is true even
2754 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2755 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002756 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002757
Chong Zhang92147042016-05-09 12:47:11 -07002758 void destroySavedSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002759 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002760 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002761 c.destroySavedSurface();
2762 }
2763
Robert Carr13f7be9e2015-12-02 18:39:45 -08002764 if (mSurfaceSaved) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002765 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, "Destroying saved surface: " + this);
Robert Carr13f7be9e2015-12-02 18:39:45 -08002766 mWinAnimator.destroySurfaceLocked();
Robert Carr237028a2016-07-26 10:39:45 -07002767 mSurfaceSaved = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002768 }
Chong Zhang92147042016-05-09 12:47:11 -07002769 mWasVisibleBeforeClientHidden = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002770 }
2771
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002772 /** Returns -1 if there are no interesting windows or number of interesting windows not drawn.*/
2773 int restoreSavedSurfaceForInterestingWindow() {
2774 int interestingNotDrawn = -1;
2775 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002776 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002777 final int childInterestingNotDrawn = c.restoreSavedSurfaceForInterestingWindow();
2778 if (childInterestingNotDrawn != -1) {
2779 if (interestingNotDrawn == -1) {
2780 interestingNotDrawn = childInterestingNotDrawn;
2781 } else {
2782 interestingNotDrawn += childInterestingNotDrawn;
2783 }
2784 }
Chong Zhang4113ffa2016-02-18 12:39:13 -08002785 }
Robert Carr237028a2016-07-26 10:39:45 -07002786
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002787 if (mAttrs.type == TYPE_APPLICATION_STARTING
2788 || mAppDied || !wasVisibleBeforeClientHidden()
2789 || (mAppToken.mAppAnimator.freezingScreen && mAppFreezing)) {
2790 // Window isn't interesting...
2791 return interestingNotDrawn;
2792 }
2793
2794 restoreSavedSurface();
2795
2796 if (!isDrawnLw()) {
2797 if (interestingNotDrawn == -1) {
2798 interestingNotDrawn = 1;
2799 } else {
2800 interestingNotDrawn++;
2801 }
2802 }
2803 return interestingNotDrawn;
2804 }
2805
2806 /** Returns true if the saved surface was restored. */
2807 boolean restoreSavedSurface() {
2808 if (!mSurfaceSaved) {
2809 return false;
2810 }
2811
2812 // Sometimes we save surfaces due to layout invisible directly after rotation occurs.
2813 // However this means the surface was never laid out in the new orientation.
2814 // We can only restore to the last rotation we were laid out as visible in.
Andrii Kulian8ee72852017-03-10 10:36:45 -08002815 if (mLastVisibleLayoutRotation != getDisplayContent().getRotation()) {
Robert Carr237028a2016-07-26 10:39:45 -07002816 destroySavedSurface();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002817 return false;
Robert Carr237028a2016-07-26 10:39:45 -07002818 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002819 mSurfaceSaved = false;
Robert Carr237028a2016-07-26 10:39:45 -07002820
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002821 if (mWinAnimator.mSurfaceController != null) {
2822 setHasSurface(true);
Wale Ogunwale9d147902016-07-16 11:58:55 -07002823 mWinAnimator.mDrawState = READY_TO_SHOW;
Chong Zhang92147042016-05-09 12:47:11 -07002824 mAnimatingWithSavedSurface = true;
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002825
Chong Zhang6e9872b2016-08-17 10:19:05 -07002826 requestUpdateWallpaperIfNeeded();
2827
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002828 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2829 Slog.v(TAG, "Restoring saved surface: " + this);
2830 }
2831 } else {
2832 // mSurfaceController shouldn't be null if mSurfaceSaved was still true at
2833 // this point. Even if we destroyed the saved surface because of rotation
2834 // or resize, mSurfaceSaved flag should have been cleared. So this is a wtf.
2835 Slog.wtf(TAG, "Failed to restore saved surface: surface gone! " + this);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002836 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002837
2838 return true;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002839 }
2840
Chong Zhang92147042016-05-09 12:47:11 -07002841 boolean canRestoreSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002842 if (mWasVisibleBeforeClientHidden && mSurfaceSaved) {
2843 return true;
2844 }
2845
2846 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002847 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002848 if (c.canRestoreSurface()) {
2849 return true;
2850 }
2851 }
2852
2853 return false;
Chong Zhang92147042016-05-09 12:47:11 -07002854 }
2855
2856 boolean hasSavedSurface() {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002857 return mSurfaceSaved;
2858 }
2859
Chong Zhang92147042016-05-09 12:47:11 -07002860 void clearHasSavedSurface() {
2861 mSurfaceSaved = false;
2862 mAnimatingWithSavedSurface = false;
Chong Zhangf58631a2016-05-24 16:02:10 -07002863 if (mWasVisibleBeforeClientHidden) {
2864 mAppToken.destroySavedSurfaces();
2865 }
Chong Zhang92147042016-05-09 12:47:11 -07002866 }
2867
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002868 boolean clearAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002869 if (mAnimatingWithSavedSurface) {
2870 // App has drawn something to its windows, we're no longer animating with
2871 // the saved surfaces.
2872 if (DEBUG_ANIM) Slog.d(TAG,
2873 "clearAnimatingWithSavedSurface(): win=" + this);
2874 mAnimatingWithSavedSurface = false;
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002875 return true;
Chong Zhang92147042016-05-09 12:47:11 -07002876 }
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002877 return false;
Chong Zhang92147042016-05-09 12:47:11 -07002878 }
2879
Craig Mautner69b08182012-09-05 13:07:13 -07002880 @Override
2881 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002882 final DisplayContent displayContent = getDisplayContent();
2883 if (displayContent == null) {
2884 // Only a window that was on a non-default display can be detached from it.
2885 return false;
2886 }
Winson Chung47a3e652014-05-21 16:03:42 -07002887 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002888 }
2889
Adrian Rooscd3884d2015-02-18 17:25:23 +01002890 @Override
2891 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002892 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002893 final DisplayContent dc = getDisplayContent();
2894 return dimLayerUser != null && dc != null
2895 && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01002896 }
2897
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002898 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07002899 mShowToOwnerOnly = showToOwnerOnly;
2900 }
2901
Wale Ogunwaleea92d972016-12-08 07:33:13 -08002902 private boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002903 // Child windows are evaluated based on their parent window.
2904 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002905 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale72919d22016-12-08 18:58:50 -08002906 && win.mAppToken != null && win.mAppToken.mShowForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002907
2908 // All window frames that are fullscreen extend above status bar, but some don't extend
2909 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2910 // bottom right.
2911 if (win.mFrame.left <= win.mDisplayFrame.left
2912 && win.mFrame.top <= win.mDisplayFrame.top
2913 && win.mFrame.right >= win.mStableFrame.right
2914 && win.mFrame.bottom >= win.mStableFrame.bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002915 // Is a fullscreen window, like the clock alarm. Show to everyone.
2916 return false;
2917 }
2918 }
2919
Craig Mautner341220f2012-10-16 15:20:09 -07002920 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01002921 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002922 }
2923
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002924 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2925 outRegion.set(
2926 frame.left + inset.left, frame.top + inset.top,
2927 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002928 }
2929
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002930 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002931 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002932 switch (mTouchableInsets) {
2933 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002934 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002935 outRegion.set(frame);
2936 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002937 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002938 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002939 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002940 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002941 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002942 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002943 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002944 outRegion.set(mGivenTouchableRegion);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002945 outRegion.translate(frame.left, frame.top);
2946 break;
2947 }
2948 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002949 cropRegionToStackBoundsIfNeeded(outRegion);
2950 }
2951
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002952 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002953 final Task task = getTask();
2954 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002955 return;
2956 }
2957
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002958 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002959 if (stack == null) {
2960 return;
2961 }
2962
2963 stack.getDimBounds(mTmpRect);
2964 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002965 }
2966
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002967 /**
2968 * Report a focus change. Must be called with no locks held, and consistently
2969 * from the same serialized thread (such as dispatched from a handler).
2970 */
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07002971 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002972 try {
2973 mClient.windowFocusChanged(focused, inTouchMode);
2974 } catch (RemoteException e) {
2975 }
2976 if (mFocusCallbacks != null) {
2977 final int N = mFocusCallbacks.beginBroadcast();
2978 for (int i=0; i<N; i++) {
2979 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2980 try {
2981 if (focused) {
2982 obs.focusGained(mWindowId.asBinder());
2983 } else {
2984 obs.focusLost(mWindowId.asBinder());
2985 }
2986 } catch (RemoteException e) {
2987 }
2988 }
2989 mFocusCallbacks.finishBroadcast();
2990 }
2991 }
2992
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002993 @Override
2994 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002995 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002996 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002997 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002998
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002999 return super.getConfiguration();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003000 }
3001
Craig Mautnerdf88d732014-01-27 09:21:32 -08003002 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003003 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08003004 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003005 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
3006 + ": " + mCompatFrame);
Bryce Leef858b572017-06-29 14:03:33 -07003007 final MergedConfiguration mergedConfiguration =
3008 new MergedConfiguration(mService.mRoot.getConfiguration(),
3009 getMergedOverrideConfiguration());
3010
3011 setReportedConfiguration(mergedConfiguration);
3012
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003013 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003014 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
3015
Craig Mautnerdf88d732014-01-27 09:21:32 -08003016 final Rect frame = mFrame;
3017 final Rect overscanInsets = mLastOverscanInsets;
3018 final Rect contentInsets = mLastContentInsets;
3019 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07003020 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003021 final Rect outsets = mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003022 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003023 final boolean reportOrientation = mReportOrientationChanged;
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003024 final int displayId = getDisplayId();
Chet Haase8eb48d22014-09-24 07:31:29 -07003025 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
3026 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08003027 // To prevent deadlock simulate one-way call if win.mClient is a local object.
3028 mService.mH.post(new Runnable() {
3029 @Override
3030 public void run() {
3031 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003032 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003033 stableInsets, outsets, reportDraw, mergedConfiguration,
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003034 reportOrientation, displayId);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003035 } catch (RemoteException e) {
3036 // Not a remote call, RemoteException won't be raised.
3037 }
3038 }
3039 });
3040 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003041 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003042 outsets, reportDraw, mergedConfiguration, reportOrientation, displayId);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003043 }
Svetoslav4604abc2014-06-10 18:59:30 -07003044
3045 //TODO (multidisplay): Accessibility supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07003046 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07003047 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07003048 }
3049
Craig Mautnerdf88d732014-01-27 09:21:32 -08003050 mOverscanInsetsChanged = false;
3051 mContentInsetsChanged = false;
3052 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07003053 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003054 mOutsetsChanged = false;
Robert Carr31aa98b2016-07-20 15:29:03 -07003055 mFrameSizeChanged = false;
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003056 mResizedWhileNotDragResizingReported = true;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003057 mWinAnimator.mSurfaceResized = false;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003058 mReportOrientationChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003059 } catch (RemoteException e) {
3060 mOrientationChanging = false;
3061 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
3062 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08003063 // We are assuming the hosting process is dead or in a zombie state.
3064 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
3065 + ", removing this window.");
3066 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07003067 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003068 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003069 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003070 }
3071
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003072 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08003073 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
3074 // start even if we haven't received the relayout window, so that the client requests
3075 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
3076 // until the window to small size, otherwise the multithread renderer will shift last
3077 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
3078 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003079 boolean resizing = isDragResizing() || isDragResizeChanged();
3080 if (StackId.useWindowFrameForBackdrop(getStackId()) || !resizing) {
3081 return frame;
3082 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07003083 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003084 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003085 return mTmpRect;
3086 }
3087
Jorim Jaggi86905582016-02-09 21:36:09 -08003088 @Override
3089 public int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003090 final TaskStack stack = getStack();
3091 if (stack == null) {
3092 return INVALID_STACK_ID;
3093 }
3094 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003095 }
3096
3097 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
3098 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
Andrii Kulian44607962017-03-16 11:06:24 -07003099 MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId)
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003100 throws RemoteException {
Andrii Kulianb2e37802017-01-11 00:36:44 -08003101 final boolean forceRelayout = isDragResizeChanged() || mResizedWhileNotDragResizing
3102 || reportOrientation;
Chong Zhangedaf3052016-04-22 15:04:31 -07003103
Jorim Jaggidc249c42015-12-15 14:57:31 -08003104 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003105 reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout,
3106 mPolicy.isNavBarForcedShownLw(this), displayId);
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003107 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003108 }
3109
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003110 public void registerFocusObserver(IWindowFocusObserver observer) {
3111 synchronized(mService.mWindowMap) {
3112 if (mFocusCallbacks == null) {
3113 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
3114 }
3115 mFocusCallbacks.register(observer);
3116 }
3117 }
3118
3119 public void unregisterFocusObserver(IWindowFocusObserver observer) {
3120 synchronized(mService.mWindowMap) {
3121 if (mFocusCallbacks != null) {
3122 mFocusCallbacks.unregister(observer);
3123 }
3124 }
3125 }
3126
3127 public boolean isFocused() {
3128 synchronized(mService.mWindowMap) {
3129 return mService.mCurrentFocus == this;
3130 }
3131 }
3132
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07003133 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003134 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07003135 return task != null && task.inFreeformWorkspace();
3136 }
3137
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003138 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07003139 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003140 final Task task = getTask();
3141 return task != null && !task.isFullscreen();
3142 }
3143
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003144 /** Is this window in a container that takes up the entire screen space? */
3145 private boolean inFullscreenContainer() {
3146 if (mAppToken == null) {
3147 return true;
3148 }
3149 if (mAppToken.hasBounds()) {
3150 return false;
3151 }
3152 return !isInMultiWindowMode();
3153 }
3154
3155 /** Returns the appropriate bounds to use for computing frames. */
3156 private void getContainerBounds(Rect outBounds) {
3157 if (isInMultiWindowMode()) {
3158 getTask().getBounds(outBounds);
3159 } else if (mAppToken != null){
3160 mAppToken.getBounds(outBounds);
3161 } else {
3162 outBounds.setEmpty();
3163 }
3164 }
3165
Chong Zhang3005e752015-09-18 18:46:28 -07003166 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003167 return mDragResizing != computeDragResizing();
3168 }
3169
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003170 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003171 void setWaitingForDrawnIfResizingChanged() {
3172 if (isDragResizeChanged()) {
3173 mService.mWaitingForDrawn.add(this);
3174 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003175 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003176 }
3177
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003178 /**
3179 * @return Whether we reported a drag resize change to the application or not already.
3180 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003181 private boolean isDragResizingChangeReported() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003182 return mDragResizingChangeReported;
3183 }
3184
3185 /**
3186 * Resets the state whether we reported a drag resize change to the app.
3187 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003188 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003189 void resetDragResizingChangeReported() {
3190 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003191 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003192 }
3193
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003194 /**
3195 * Set whether we got resized but drag resizing flag was false.
3196 * @see #isResizedWhileNotDragResizing().
3197 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003198 private void setResizedWhileNotDragResizing(boolean resizedWhileNotDragResizing) {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003199 mResizedWhileNotDragResizing = resizedWhileNotDragResizing;
3200 mResizedWhileNotDragResizingReported = !resizedWhileNotDragResizing;
3201 }
3202
3203 /**
3204 * Indicates whether we got resized but drag resizing flag was false. In this case, we also
3205 * need to recreate the surface and defer surface bound updates in order to make sure the
3206 * buffer contents and the positioning/size stay in sync.
3207 */
3208 boolean isResizedWhileNotDragResizing() {
3209 return mResizedWhileNotDragResizing;
3210 }
3211
3212 /**
3213 * @return Whether we reported "resize while not drag resizing" to the application.
3214 * @see #isResizedWhileNotDragResizing()
3215 */
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003216 private boolean isResizedWhileNotDragResizingReported() {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003217 return mResizedWhileNotDragResizingReported;
3218 }
3219
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003220 int getResizeMode() {
3221 return mResizeMode;
3222 }
3223
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003224 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003225 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003226 if (task == null) {
3227 return false;
3228 }
Winson Chung2af04b32017-01-24 16:21:13 -08003229 if (!StackId.isStackAffectedByDragResizing(getStackId())) {
3230 return false;
3231 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003232 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003233 // Floating windows never enter drag resize mode.
3234 return false;
3235 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003236 if (task.isDragResizing()) {
3237 return true;
3238 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003239
3240 // If the bounds are currently frozen, it means that the layout size that the app sees
3241 // and the bounds we clip this window to might be different. In order to avoid holes, we
3242 // simulate that we are still resizing so the app fills the hole with the resizing
3243 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003244 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003245 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Jorim Jaggi899327f2016-02-25 20:44:18 -05003246 !task.inFreeformWorkspace() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003247
Chong Zhang3005e752015-09-18 18:46:28 -07003248 }
3249
3250 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003251 final boolean resizing = computeDragResizing();
3252 if (resizing == mDragResizing) {
3253 return;
3254 }
3255 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003256 final Task task = getTask();
3257 if (task != null && task.isDragResizing()) {
3258 mResizeMode = task.getDragResizeMode();
3259 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003260 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003261 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3262 : DRAG_RESIZE_MODE_FREEFORM;
3263 }
Chong Zhang3005e752015-09-18 18:46:28 -07003264 }
3265
3266 boolean isDragResizing() {
3267 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003268 }
3269
Robert Carr2487ce72016-04-07 15:18:45 -07003270 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003271 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3272 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003273 }
3274
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003275 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003276 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003277 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003278 if (stack != null) {
3279 pw.print(" stackId="); pw.print(stack.mStackId);
3280 }
Craig Mautner59c00972012-07-30 12:10:24 -07003281 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003282 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07003283 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08003284 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
3285 pw.print(" package="); pw.print(mAttrs.packageName);
3286 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003287 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003288 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
3289 pw.print(" h="); pw.print(mRequestedHeight);
3290 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003291 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
3292 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
3293 pw.print(" h="); pw.println(mLastRequestedHeight);
3294 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003295 if (mIsChildWindow || mLayoutAttached) {
3296 pw.print(prefix); pw.print("mParentWindow="); pw.print(getParentWindow());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003297 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
3298 }
3299 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
3300 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
3301 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
3302 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
3303 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
3304 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003305 if (dumpAll) {
3306 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3307 pw.print(" mSubLayer="); pw.print(mSubLayer);
3308 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Wale Ogunwale455fac52016-07-21 07:24:49 -07003309 pw.print(getAnimLayerAdjustment());
Craig Mautnerc2f9be02012-03-27 17:32:29 -07003310 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
3311 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003312 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003313 if (dumpAll) {
3314 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003315 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003316 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
3317 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08003318 pw.print(isAnimatingWithSavedSurface());
Chong Zhang112eb8c2015-11-02 11:17:00 -08003319 pw.print(" mAppDied=");pw.println(mAppDied);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003320 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003321 pw.print(prefix); pw.print("mViewVisibility=0x");
3322 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003323 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
3324 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07003325 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
3326 pw.print(" mSystemUiVisibility=0x");
3327 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003328 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003329 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
Svetoslav Ganov71c51022016-09-02 17:54:37 -07003330 || isParentWindowHidden()|| mPermanentlyHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003331 pw.print(prefix); pw.print("mPolicyVisibility=");
3332 pw.print(mPolicyVisibility);
3333 pw.print(" mPolicyVisibilityAfterAnim=");
3334 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003335 pw.print(" mAppOpVisibility=");
3336 pw.print(mAppOpVisibility);
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003337 pw.print(" parentHidden="); pw.print(isParentWindowHidden());
Svetoslav Ganovaa076532016-08-01 19:16:43 -07003338 pw.print(" mPermanentlyHidden="); pw.println(mPermanentlyHidden);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003339 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003340 if (!mRelayoutCalled || mLayoutNeeded) {
3341 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
3342 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003343 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003344 if (mXOffset != 0 || mYOffset != 0) {
3345 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
3346 pw.print(" y="); pw.println(mYOffset);
3347 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003348 if (dumpAll) {
3349 pw.print(prefix); pw.print("mGivenContentInsets=");
3350 mGivenContentInsets.printShortString(pw);
3351 pw.print(" mGivenVisibleInsets=");
3352 mGivenVisibleInsets.printShortString(pw);
3353 pw.println();
3354 if (mTouchableInsets != 0 || mGivenInsetsPending) {
3355 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
3356 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003357 Region region = new Region();
3358 getTouchableRegion(region);
3359 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003360 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003361 pw.print(prefix); pw.print("mFullConfiguration="); pw.println(getConfiguration());
3362 pw.print(prefix); pw.print("mLastReportedConfiguration=");
3363 pw.println(mLastReportedConfiguration);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003364 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07003365 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07003366 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Chong Zhanga8975bd2016-01-28 17:13:47 -08003367 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08003368 pw.print(" hasSavedSurface()="); pw.print(hasSavedSurface());
3369 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003370 if (dumpAll) {
3371 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
3372 pw.print(" last="); mLastFrame.printShortString(pw);
3373 pw.println();
3374 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003375 if (mEnforceSizeCompat) {
3376 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003377 pw.println();
3378 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003379 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003380 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003381 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003382 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003383 pw.println();
3384 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
3385 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003386 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003387 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003388 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003389 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04003390 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
3391 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003392 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
3393 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003394 pw.print(prefix); pw.print("Cur insets: overscan=");
3395 mOverscanInsets.printShortString(pw);
3396 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003397 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003398 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003399 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003400 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003401 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003402 pw.print(prefix); pw.print("Lst insets: overscan=");
3403 mLastOverscanInsets.printShortString(pw);
3404 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003405 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003406 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003407 pw.print(" physical="); mLastOutsets.printShortString(pw);
3408 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003409 pw.println();
3410 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07003411 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
3412 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003413 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
3414 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003415 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
3416 pw.print(" mDestroying="); pw.print(mDestroying);
3417 pw.print(" mRemoved="); pw.println(mRemoved);
3418 }
Andrii Kulianb2e37802017-01-11 00:36:44 -08003419 if (mOrientationChanging || mAppFreezing || mTurnOnScreen
3420 || mReportOrientationChanged) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003421 pw.print(prefix); pw.print("mOrientationChanging=");
3422 pw.print(mOrientationChanging);
3423 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003424 pw.print(" mTurnOnScreen="); pw.print(mTurnOnScreen);
Andrii Kulianb2e37802017-01-11 00:36:44 -08003425 pw.print(" mReportOrientationChanged="); pw.println(mReportOrientationChanged);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003426 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003427 if (mLastFreezeDuration != 0) {
3428 pw.print(prefix); pw.print("mLastFreezeDuration=");
3429 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
3430 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003431 if (mHScale != 1 || mVScale != 1) {
3432 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
3433 pw.print(" mVScale="); pw.println(mVScale);
3434 }
3435 if (mWallpaperX != -1 || mWallpaperY != -1) {
3436 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
3437 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
3438 }
3439 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
3440 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
3441 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
3442 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003443 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3444 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
3445 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
3446 pw.print(mWallpaperDisplayOffsetX);
3447 pw.print(" mWallpaperDisplayOffsetY=");
3448 pw.println(mWallpaperDisplayOffsetY);
3449 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003450 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07003451 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003452 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003453 if (isDragResizing()) {
3454 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
3455 }
3456 if (computeDragResizing()) {
3457 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
3458 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003459 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003460
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003461 @Override
3462 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003463 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003464 + " " + getWindowTag();
3465 }
3466
Robert Carra1eb4392015-12-10 12:43:51 -08003467 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003468 CharSequence tag = mAttrs.getTitle();
3469 if (tag == null || tag.length() <= 0) {
3470 tag = mAttrs.packageName;
3471 }
3472 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003473 }
3474
3475 @Override
3476 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003477 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003478 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003479 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003480 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003481 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003482 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003483 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003484 }
3485 return mStringNameCache;
3486 }
Robert Carr58f29132015-10-29 14:19:05 -07003487
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003488 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003489 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003490 clipRect.left = (int) (clipRect.left / mHScale);
3491 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003492 }
3493 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003494 clipRect.top = (int) (clipRect.top / mVScale);
3495 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003496 }
3497 }
Robert Carr31e28482015-12-02 16:53:18 -08003498
Jorim Jaggif5834272016-04-04 20:25:41 -07003499 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
3500 final int pw = containingFrame.width();
3501 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003502 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003503 final boolean inNonFullscreenContainer = !inFullscreenContainer();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003504 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3505
3506 // We need to fit it to the display if either
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003507 // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen
3508 // for the taskless windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003509 // b) If it's a secondary app window, we also need to fit it to the display unless
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003510 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on
3511 // screen, but SurfaceViews want to be always at a specific location so we don't fit it to
3512 // the display.
3513 final boolean fitToDisplay = (task == null || !inNonFullscreenContainer)
Robert Carr6f44db12016-07-21 14:54:43 -07003514 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003515 float x, y;
3516 int w,h;
3517
3518 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3519 if (mAttrs.width < 0) {
3520 w = pw;
3521 } else if (mEnforceSizeCompat) {
3522 w = (int)(mAttrs.width * mGlobalScale + .5f);
3523 } else {
3524 w = mAttrs.width;
3525 }
3526 if (mAttrs.height < 0) {
3527 h = ph;
3528 } else if (mEnforceSizeCompat) {
3529 h = (int)(mAttrs.height * mGlobalScale + .5f);
3530 } else {
3531 h = mAttrs.height;
3532 }
3533 } else {
3534 if (mAttrs.width == MATCH_PARENT) {
3535 w = pw;
3536 } else if (mEnforceSizeCompat) {
3537 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3538 } else {
3539 w = mRequestedWidth;
3540 }
3541 if (mAttrs.height == MATCH_PARENT) {
3542 h = ph;
3543 } else if (mEnforceSizeCompat) {
3544 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3545 } else {
3546 h = mRequestedHeight;
3547 }
3548 }
3549
3550 if (mEnforceSizeCompat) {
3551 x = mAttrs.x * mGlobalScale;
3552 y = mAttrs.y * mGlobalScale;
3553 } else {
3554 x = mAttrs.x;
3555 y = mAttrs.y;
3556 }
3557
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003558 if (inNonFullscreenContainer && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003559 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003560 // required by {@link Gravity#apply} call.
3561 w = Math.min(w, pw);
3562 h = Math.min(h, ph);
3563 }
3564
3565 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003566 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003567 (int) (x + mAttrs.horizontalMargin * pw),
3568 (int) (y + mAttrs.verticalMargin * ph), mFrame);
3569
3570 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003571 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003572 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003573 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003574
3575 // We need to make sure we update the CompatFrame as it is used for
3576 // cropping decisions, etc, on systems where we lack a decor layer.
3577 mCompatFrame.set(mFrame);
3578 if (mEnforceSizeCompat) {
3579 // See comparable block in computeFrameLw.
3580 mCompatFrame.scale(mInvGlobalScale);
3581 }
Robert Carr31e28482015-12-02 16:53:18 -08003582 }
Robert Carr51a1b872015-12-08 14:03:13 -08003583
3584 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003585 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003586 }
3587
Robert Carrf3b72c72016-03-21 18:16:39 -07003588 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003589 return mIsChildWindow
3590 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003591 }
3592
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003593 /** Returns the parent window if this is a child of another window, else null. */
3594 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003595 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3596 // WindowContainer that isn't a WindowState.
3597 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003598 }
3599
3600 /** Returns the topmost parent window if this is a child of another window, else this. */
3601 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003602 WindowState current = this;
3603 WindowState topParent = current;
3604 while (current != null && current.mIsChildWindow) {
3605 current = current.getParentWindow();
3606 // Parent window can be null if the child is detached from it's parent already, but
3607 // someone still has a reference to access it. So, we return the top parent value we
3608 // already have instead of null.
3609 if (current != null) {
3610 topParent = current;
3611 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003612 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003613 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003614 }
3615
Wale Ogunwale9d147902016-07-16 11:58:55 -07003616 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003617 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003618 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003619 }
3620
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003621 void setWillReplaceWindow(boolean animate) {
3622 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003623 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003624 c.setWillReplaceWindow(animate);
3625 }
3626
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003627 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3628 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3629 // We don't set replacing on starting windows since they are added by window manager and
3630 // not the client so won't be replaced by the client.
3631 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003632 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003633
3634 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003635 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003636 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003637 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003638
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003639 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003640 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003641 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003642 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003643
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.clearWillReplaceWindow();
3647 }
3648 }
3649
3650 boolean waitingForReplacement() {
3651 if (mWillReplaceWindow) {
3652 return true;
3653 }
3654
3655 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003656 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003657 if (c.waitingForReplacement()) {
3658 return true;
3659 }
3660 }
3661 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003662 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003663
Chong Zhang4d7369a2016-04-25 16:09:14 -07003664 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003665 final DisplayContent dc = getDisplayContent();
3666 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3667 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3668 dc.setLayoutNeeded();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003669 mService.mWindowPlacerLocked.requestTraversal();
3670 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003671
3672 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003673 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003674 c.requestUpdateWallpaperIfNeeded();
3675 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003676 }
3677
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003678 float translateToWindowX(float x) {
3679 float winX = x - mFrame.left;
3680 if (mEnforceSizeCompat) {
3681 winX *= mGlobalScale;
3682 }
3683 return winX;
3684 }
3685
3686 float translateToWindowY(float y) {
3687 float winY = y - mFrame.top;
3688 if (mEnforceSizeCompat) {
3689 winY *= mGlobalScale;
3690 }
3691 return winY;
3692 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003693
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003694 private void transferDimToReplacement() {
Robert Carr9fe459d2016-04-07 23:32:28 -07003695 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003696 final DisplayContent dc = getDisplayContent();
3697 if (dimLayerUser != null && dc != null) {
3698 dc.mDimLayerController.applyDim(dimLayerUser,
3699 mReplacementWindow.mWinAnimator, (mAttrs.flags & FLAG_DIM_BEHIND) != 0);
Robert Carr9fe459d2016-04-07 23:32:28 -07003700 }
3701 }
3702
Robert Carrd1a010f2016-04-07 22:36:22 -07003703 // During activity relaunch due to resize, we sometimes use window replacement
3704 // for only child windows (as the main window is handled by window preservation)
3705 // and the big surface.
3706 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003707 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3708 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3709 // we also want to replace them at such phases, as they won't be covered by window
3710 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003711 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003712 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003713 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003714 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003715
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003716 void setWillReplaceChildWindows() {
3717 if (shouldBeReplacedWithChildren()) {
3718 setWillReplaceWindow(false /* animate */);
3719 }
3720 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003721 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003722 c.setWillReplaceChildWindows();
3723 }
3724 }
3725
3726 WindowState getReplacingWindow() {
3727 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3728 return this;
3729 }
3730 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003731 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003732 final WindowState replacing = c.getReplacingWindow();
3733 if (replacing != null) {
3734 return replacing;
3735 }
3736 }
3737 return null;
3738 }
3739
Jorim Jaggife762342016-10-13 14:33:27 +02003740 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07003741 public int getRotationAnimationHint() {
3742 if (mAppToken != null) {
3743 return mAppToken.mRotationAnimationHint;
3744 } else {
3745 return -1;
3746 }
3747 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003748
Jorim Jaggife762342016-10-13 14:33:27 +02003749 @Override
3750 public boolean isInputMethodWindow() {
3751 return mIsImWindow;
3752 }
3753
Wale Ogunwale9d147902016-07-16 11:58:55 -07003754 // This must be called while inside a transaction.
3755 boolean performShowLocked() {
3756 if (isHiddenFromUserLocked()) {
3757 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3758 hideLw(false);
3759 return false;
3760 }
3761
3762 logPerformShow("performShow on ");
3763
Jorim Jaggia50da602016-12-29 11:51:42 +01003764 final int drawState = mWinAnimator.mDrawState;
3765 if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW)
3766 && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3767 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3768 }
3769
Jorim Jaggib0d27342016-11-01 16:10:42 -07003770 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003771 return false;
3772 }
3773
3774 logPerformShow("Showing ");
3775
3776 mService.enableScreenIfNeededLocked();
3777 mWinAnimator.applyEnterAnimationLocked();
3778
3779 // Force the show in the next prepareSurfaceLocked() call.
3780 mWinAnimator.mLastAlpha = -1;
3781 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) Slog.v(TAG,
3782 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3783 mWinAnimator.mDrawState = HAS_DRAWN;
3784 mService.scheduleAnimationLocked();
3785
3786 if (mHidden) {
3787 mHidden = false;
3788 final DisplayContent displayContent = getDisplayContent();
3789
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003790 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003791 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003792 if (c.mWinAnimator.mSurfaceController != null) {
3793 c.performShowLocked();
3794 // It hadn't been shown, which means layout not performed on it, so now we
3795 // want to make sure to do a layout. If called from within the transaction
3796 // loop, this will cause it to restart with a new layout.
3797 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003798 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003799 }
3800 }
3801 }
3802 }
3803
Wale Ogunwale9d147902016-07-16 11:58:55 -07003804 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003805 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003806 }
3807
3808 return true;
3809 }
3810
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003811 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003812 if (DEBUG_VISIBILITY
Jorim Jaggie4b0f282017-05-17 15:10:29 +02003813 || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003814 Slog.v(TAG, prefix + this
3815 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07003816 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003817 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3818 + " during animation: policyVis=" + mPolicyVisibility
3819 + " parentHidden=" + isParentWindowHidden()
3820 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003821 + (mAppToken != null && mAppToken.hiddenRequested)
3822 + " tok.hidden=" + (mAppToken != null && mAppToken.hidden)
Wale Ogunwale9d147902016-07-16 11:58:55 -07003823 + " animating=" + mWinAnimator.mAnimating
3824 + " tok animating="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003825 + (mWinAnimator.mAppAnimator != null && mWinAnimator.mAppAnimator.animating)
Wale Ogunwale9d147902016-07-16 11:58:55 -07003826 + " Callers=" + Debug.getCallers(4));
3827 }
3828 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003829
3830 WindowInfo getWindowInfo() {
3831 WindowInfo windowInfo = WindowInfo.obtain();
3832 windowInfo.type = mAttrs.type;
3833 windowInfo.layer = mLayer;
3834 windowInfo.token = mClient.asBinder();
3835 windowInfo.title = mAttrs.accessibilityTitle;
3836 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3837 windowInfo.focused = isFocused();
Phil Weaverf00cd142017-03-03 13:44:00 -08003838 Task task = getTask();
3839 windowInfo.inPictureInPicture = (task != null) && task.inPinnedWorkspace();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003840
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003841 if (mIsChildWindow) {
3842 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003843 }
3844
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003845 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003846 if (childCount > 0) {
3847 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003848 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003849 }
3850 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003851 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003852 windowInfo.childTokens.add(child.mClient.asBinder());
3853 }
3854 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003855 return windowInfo;
3856 }
3857
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003858 int getHighestAnimLayer() {
3859 int highest = mWinAnimator.mAnimLayer;
3860 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003861 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003862 final int childLayer = c.getHighestAnimLayer();
3863 if (childLayer > highest) {
3864 highest = childLayer;
3865 }
3866 }
3867 return highest;
3868 }
3869
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003870 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003871 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003872 if (mChildren.isEmpty()) {
3873 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003874 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003875 }
3876
3877 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003878 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003879 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003880 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003881 }
3882 }
3883
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003884 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003885 // We want to consume the negative sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003886 // below the parent, then this window (the parent), and then the positive sublayer children
3887 // because they need to appear above the parent.
3888 int i = 0;
3889 final int count = mChildren.size();
3890 WindowState child = mChildren.get(i);
3891
3892 while (i < count && child.mSubLayer < 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003893 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003894 return true;
3895 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003896 i++;
3897 if (i >= count) {
3898 break;
3899 }
3900 child = mChildren.get(i);
3901 }
3902
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003903 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003904 return true;
3905 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003906
3907 while (i < count) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003908 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003909 return true;
3910 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003911 i++;
3912 if (i >= count) {
3913 break;
3914 }
3915 child = mChildren.get(i);
3916 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003917
3918 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003919 }
3920
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003921 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003922 // We want to consume the positive sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003923 // above the parent, then this window (the parent), and then the negative sublayer children
3924 // because they need to appear above the parent.
3925 int i = mChildren.size() - 1;
3926 WindowState child = mChildren.get(i);
3927
3928 while (i >= 0 && child.mSubLayer >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003929 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003930 return true;
3931 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003932 --i;
3933 if (i < 0) {
3934 break;
3935 }
3936 child = mChildren.get(i);
3937 }
3938
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003939 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003940 return true;
3941 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003942
3943 while (i >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003944 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003945 return true;
3946 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003947 --i;
3948 if (i < 0) {
3949 break;
3950 }
3951 child = mChildren.get(i);
3952 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003953
3954 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003955 }
3956
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003957 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
3958 boolean traverseTopToBottom) {
3959 if (traverseTopToBottom) {
3960 if (mService.mInputMethodTarget == this) {
3961 // This window is the current IME target, so we need to process the IME windows
3962 // directly above it.
3963 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
3964 return true;
3965 }
3966 }
3967 if (callback.apply(this)) {
3968 return true;
3969 }
3970 } else {
3971 if (callback.apply(this)) {
3972 return true;
3973 }
3974 if (mService.mInputMethodTarget == this) {
3975 // This window is the current IME target, so we need to process the IME windows
3976 // directly above it.
3977 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
3978 return true;
3979 }
3980 }
3981 }
3982
3983 return false;
3984 }
3985
Wale Ogunwaled1880962016-11-08 10:31:59 -08003986 WindowState getWindow(Predicate<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003987 if (mChildren.isEmpty()) {
3988 return callback.test(this) ? this : null;
3989 }
3990
3991 // We want to consume the positive sublayer children first because they need to appear
3992 // above the parent, then this window (the parent), and then the negative sublayer children
3993 // because they need to appear above the parent.
3994 int i = mChildren.size() - 1;
3995 WindowState child = mChildren.get(i);
3996
3997 while (i >= 0 && child.mSubLayer >= 0) {
3998 if (callback.test(child)) {
3999 return child;
4000 }
4001 --i;
4002 if (i < 0) {
4003 break;
4004 }
4005 child = mChildren.get(i);
4006 }
4007
Wale Ogunwaled1880962016-11-08 10:31:59 -08004008 if (callback.test(this)) {
4009 return this;
4010 }
Wale Ogunwale34247952017-02-19 11:57:53 -08004011
4012 while (i >= 0) {
4013 if (callback.test(child)) {
4014 return child;
4015 }
4016 --i;
4017 if (i < 0) {
4018 break;
4019 }
4020 child = mChildren.get(i);
4021 }
4022
4023 return null;
Wale Ogunwaled1880962016-11-08 10:31:59 -08004024 }
4025
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004026 boolean isWindowAnimationSet() {
4027 if (mWinAnimator.isWindowAnimationSet()) {
4028 return true;
4029 }
4030 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004031 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004032 if (c.isWindowAnimationSet()) {
4033 return true;
4034 }
4035 }
4036 return false;
4037 }
4038
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004039 void onExitAnimationDone() {
4040 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
4041 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
4042 + " windowAnimating=" + mWinAnimator.isWindowAnimationSet());
4043
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004044 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004045 // Copying to a different list as multiple children can be removed.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004046 // TODO: Not sure if we really need to copy this into a different list.
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004047 final LinkedList<WindowState> childWindows = new LinkedList(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004048 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004049 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004050 }
4051 }
4052
4053 if (mWinAnimator.mEnteringAnimation) {
4054 mWinAnimator.mEnteringAnimation = false;
4055 mService.requestTraversal();
4056 // System windows don't have an activity and an app token as a result, but need a way
4057 // to be informed about their entrance animation end.
4058 if (mAppToken == null) {
4059 try {
4060 mClient.dispatchWindowShown();
4061 } catch (RemoteException e) {
4062 }
4063 }
4064 }
4065
4066 if (!mWinAnimator.isWindowAnimationSet()) {
4067 //TODO (multidisplay): Accessibility is supported only for the default display.
4068 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
4069 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
4070 }
4071 }
4072
4073 if (!mAnimatingExit) {
4074 return;
4075 }
4076
4077 if (mWinAnimator.isWindowAnimationSet()) {
4078 return;
4079 }
4080
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07004081 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004082 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
4083
4084 mDestroying = true;
4085
4086 final boolean hasSurface = mWinAnimator.hasSurface();
4087 if (hasSurface) {
4088 mWinAnimator.hide("onExitAnimationDone");
4089 }
4090
4091 // If we have an app token, we ask it to destroy the surface for us, so that it can take
4092 // care to ensure the activity has actually stopped and the surface is not still in use.
4093 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
4094 // transaction.
4095 if (mAppToken != null) {
4096 mAppToken.destroySurfaces();
4097 } else {
4098 if (hasSurface) {
4099 mService.mDestroySurface.add(this);
4100 }
4101 if (mRemoveOnExit) {
4102 mService.mPendingRemove.add(this);
4103 mRemoveOnExit = false;
4104 }
4105 }
4106 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07004107 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004108 }
Dan Willemsen117197f2016-07-30 13:02:59 -07004109
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004110 boolean clearAnimatingFlags() {
4111 boolean didSomething = false;
4112 // We don't want to clear it out for windows that get replaced, because the
4113 // animation depends on the flag to remove the replaced window.
4114 //
4115 // We also don't clear the mAnimatingExit flag for windows which have the
4116 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4117 // by the client. We should let animation proceed and not clear this flag or
4118 // they won't eventually be removed by WindowStateAnimator#finishExit.
4119 if (!mWillReplaceWindow && !mRemoveOnExit) {
4120 // Clear mAnimating flag together with mAnimatingExit. When animation
4121 // changes from exiting to entering, we need to clear this flag until the
4122 // new animation gets applied, so that isAnimationStarting() becomes true
4123 // until then.
4124 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4125 // placement for this window during this period, one or more frame will
4126 // show up with wrong position or scale.
4127 if (mAnimatingExit) {
4128 mAnimatingExit = false;
4129 didSomething = true;
4130 }
4131 if (mWinAnimator.mAnimating) {
4132 mWinAnimator.mAnimating = false;
4133 didSomething = true;
4134 }
4135 if (mDestroying) {
4136 mDestroying = false;
4137 mService.mDestroySurface.remove(this);
4138 didSomething = true;
4139 }
4140 }
4141
4142 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004143 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004144 }
4145
4146 return didSomething;
4147 }
4148
Winson4b4ba902016-07-27 19:45:52 -07004149 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004150 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004151 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004152
4153 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004154 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004155 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004156 c.hideWallpaperWindow(wasDeferred, reason);
4157 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004158 if (!mWinAnimator.mLastHidden || wasDeferred) {
4159 mWinAnimator.hide(reason);
4160 dispatchWallpaperVisibility(false);
4161 final DisplayContent displayContent = getDisplayContent();
4162 if (displayContent != null) {
4163 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
4164 }
4165 }
4166 }
4167
4168 /**
4169 * Check wallpaper window for visibility change and notify window if so.
4170 * @param visible Current visibility.
4171 */
4172 void dispatchWallpaperVisibility(final boolean visible) {
4173 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07004174 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004175
4176 // Only send notification if the visibility actually changed and we are not trying to hide
4177 // the wallpaper when we are deferring hiding of the wallpaper.
4178 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4179 mWallpaperVisible = visible;
4180 try {
4181 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4182 "Updating vis of wallpaper " + this
4183 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4184 mClient.dispatchAppVisibility(visible);
4185 } catch (RemoteException e) {
4186 }
4187 }
4188 }
4189
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004190 boolean hasVisibleNotDrawnWallpaper() {
4191 if (mWallpaperVisible && !isDrawnLw()) {
4192 return true;
4193 }
4194 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004195 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004196 if (c.hasVisibleNotDrawnWallpaper()) {
4197 return true;
4198 }
4199 }
4200 return false;
4201 }
4202
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004203 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4204 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004205 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004206 c.updateReportedVisibility(results);
4207 }
4208
4209 if (mAppFreezing || mViewVisibility != View.VISIBLE
4210 || mAttrs.type == TYPE_APPLICATION_STARTING
4211 || mDestroying) {
4212 return;
4213 }
4214 if (DEBUG_VISIBILITY) {
4215 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
4216 + ", isAnimationSet=" + mWinAnimator.isAnimationSet());
4217 if (!isDrawnLw()) {
4218 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4219 + " pv=" + mPolicyVisibility
4220 + " mDrawState=" + mWinAnimator.mDrawState
4221 + " ph=" + isParentWindowHidden()
4222 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
4223 + " a=" + mWinAnimator.mAnimating);
4224 }
4225 }
4226
4227 results.numInteresting++;
4228 if (isDrawnLw()) {
4229 results.numDrawn++;
4230 if (!mWinAnimator.isAnimationSet()) {
4231 results.numVisible++;
4232 }
4233 results.nowGone = false;
4234 } else if (mWinAnimator.isAnimationSet()) {
4235 results.nowGone = false;
4236 }
4237 }
4238
Robert Carrfbbde852016-10-18 11:02:28 -07004239 /**
4240 * Calculate the window crop according to system decor policy. In general this is
4241 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4242 * special cases. This rectangle is in screen space.
4243 */
4244 void calculatePolicyCrop(Rect policyCrop) {
4245 final DisplayContent displayContent = getDisplayContent();
4246 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
4247
4248 if (!isDefaultDisplay()) {
4249 // On a different display there is no system decor. Crop the window
4250 // by the screen boundaries.
4251 // TODO(multi-display)
4252 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4253 policyCrop.intersect(-mCompatFrame.left, -mCompatFrame.top,
4254 displayInfo.logicalWidth - mCompatFrame.left,
4255 displayInfo.logicalHeight - mCompatFrame.top);
4256 } else if (mLayer >= mService.mSystemDecorLayer) {
4257 // Above the decor layer is easy, just use the entire window
4258 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4259 } else if (mDecorFrame.isEmpty()) {
4260 // Windows without policy decor aren't cropped.
4261 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4262 } else {
4263 // Crop to the system decor specified by policy.
4264 calculateSystemDecorRect(policyCrop);
4265 }
4266 }
4267
4268 /**
4269 * The system decor rect is the region of the window which is not covered
4270 * by system decorations.
4271 */
4272 private void calculateSystemDecorRect(Rect systemDecorRect) {
4273 final Rect decorRect = mDecorFrame;
4274 final int width = mFrame.width();
4275 final int height = mFrame.height();
4276
4277 // Compute the offset of the window in relation to the decor rect.
4278 final int left = mXOffset + mFrame.left;
4279 final int top = mYOffset + mFrame.top;
4280
4281 // Initialize the decor rect to the entire frame.
4282 if (isDockedResizing()) {
4283 // If we are resizing with the divider, the task bounds might be smaller than the
4284 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4285 // want in this case in order to avoid holes.
4286 //
4287 // We take care to not shrink the width, for surfaces which are larger than
4288 // the display region. Of course this area will not eventually be visible
4289 // but if we truncate the width now, we will calculate incorrectly
4290 // when adjusting to the stack bounds.
4291 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4292 systemDecorRect.set(0, 0,
4293 Math.max(width, displayInfo.logicalWidth),
4294 Math.max(height, displayInfo.logicalHeight));
4295 } else {
4296 systemDecorRect.set(0, 0, width, height);
4297 }
4298
4299 // If a freeform window is animating from a position where it would be cutoff, it would be
4300 // cutoff during the animation. We don't want that, so for the duration of the animation
4301 // we ignore the decor cropping and depend on layering to position windows correctly.
4302 final boolean cropToDecor = !(inFreeformWorkspace() && isAnimatingLw());
4303 if (cropToDecor) {
4304 // Intersect with the decor rect, offsetted by window position.
4305 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
4306 decorRect.right - left, decorRect.bottom - top);
4307 }
4308
4309 // If size compatibility is being applied to the window, the
4310 // surface is scaled relative to the screen. Also apply this
4311 // scaling to the crop rect. We aren't using the standard rect
4312 // scale function because we want to round things to make the crop
4313 // always round to a larger rect to ensure we don't crop too
4314 // much and hide part of the window that should be seen.
4315 if (mEnforceSizeCompat && mInvGlobalScale != 1.0f) {
4316 final float scale = mInvGlobalScale;
4317 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
4318 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
4319 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
4320 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
4321 }
4322
4323 }
4324
4325 /**
4326 * Expand the given rectangle by this windows surface insets. This
4327 * takes you from the 'window size' to the 'surface size'.
4328 * The surface insets are positive in each direction, so we inset by
4329 * the inverse.
4330 */
4331 void expandForSurfaceInsets(Rect r) {
4332 r.inset(-mAttrs.surfaceInsets.left,
4333 -mAttrs.surfaceInsets.top,
4334 -mAttrs.surfaceInsets.right,
4335 -mAttrs.surfaceInsets.bottom);
4336 }
4337
Robert Carrc91d1c32017-02-15 19:37:46 -08004338 boolean surfaceInsetsChanging() {
4339 return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets);
4340 }
4341
Bryce Leef858b572017-06-29 14:03:33 -07004342 int relayoutVisibleWindow(int result, int attrChanges, int oldVisibility) {
Robert Carrecc06b32017-04-18 14:25:10 -07004343 final boolean wasVisible = isVisibleLw();
4344
4345 result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004346 if (mAnimatingExit) {
4347 Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit="
4348 + mRemoveOnExit + ", mDestroying=" + mDestroying);
4349
4350 mWinAnimator.cancelExitAnimationForNextAnimationLocked();
4351 mAnimatingExit = false;
4352 }
4353 if (mDestroying) {
4354 mDestroying = false;
4355 mService.mDestroySurface.remove(this);
4356 }
4357 if (oldVisibility == View.GONE) {
4358 mWinAnimator.mEnterAnimationPending = true;
4359 }
4360
Andrii Kulian8ee72852017-03-10 10:36:45 -08004361 mLastVisibleLayoutRotation = getDisplayContent().getRotation();
Robert Carrc91d1c32017-02-15 19:37:46 -08004362
4363 mWinAnimator.mEnteringAnimation = true;
Bryce Leeae73ba42017-05-05 09:58:25 -07004364
Bryce Leef858b572017-06-29 14:03:33 -07004365 prepareWindowToDisplayDuringRelayout(wasVisible);
Bryce Leeae73ba42017-05-05 09:58:25 -07004366
Robert Carrc91d1c32017-02-15 19:37:46 -08004367 if ((attrChanges & FORMAT_CHANGED) != 0) {
4368 // If the format can't be changed in place, preserve the old surface until the app draws
4369 // on the new one. This prevents blinking when we change elevation of freeform and
4370 // pinned windows.
4371 if (!mWinAnimator.tryChangeFormatInPlaceLocked()) {
4372 mWinAnimator.preserveSurfaceLocked();
4373 result |= RELAYOUT_RES_SURFACE_CHANGED
4374 | RELAYOUT_RES_FIRST_TIME;
4375 }
4376 }
4377
4378 // When we change the Surface size, in scenarios which may require changing
4379 // the surface position in sync with the resize, we use a preserved surface
4380 // so we can freeze it while waiting for the client to report draw on the newly
Winson Chung8bca9e42017-04-16 15:59:43 -07004381 // sized surface. Don't preserve surfaces if the insets change while animating the pinned
4382 // stack since it can lead to issues if a new surface is created while calculating the
4383 // scale for the animation using the source hint rect
4384 // (see WindowStateAnimator#setSurfaceBoundariesLocked()).
Robert Carrc91d1c32017-02-15 19:37:46 -08004385 if (isDragResizeChanged() || isResizedWhileNotDragResizing()
Winson Chung8bca9e42017-04-16 15:59:43 -07004386 || (surfaceInsetsChanging() && !inPinnedWorkspace())) {
Robert Carrc91d1c32017-02-15 19:37:46 -08004387 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
4388
4389 setDragResizing();
4390 setResizedWhileNotDragResizing(false);
4391 // We can only change top level windows to the full-screen surface when
4392 // resizing (as we only have one full-screen surface). So there is no need
4393 // to preserve and destroy windows which are attached to another, they
4394 // will keep their surface and its size may change over time.
4395 if (mHasSurface && !isChildWindow()) {
4396 mWinAnimator.preserveSurfaceLocked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08004397 result |= RELAYOUT_RES_SURFACE_CHANGED |
4398 RELAYOUT_RES_FIRST_TIME;
Robert Carrc91d1c32017-02-15 19:37:46 -08004399 }
4400 }
4401 final boolean freeformResizing = isDragResizing()
4402 && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
4403 final boolean dockedResizing = isDragResizing()
4404 && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
4405 result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0;
4406 result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0;
4407 if (isAnimatingWithSavedSurface()) {
4408 // If we're animating with a saved surface now, request client to report draw.
4409 // We still need to know when the real thing is drawn.
4410 result |= RELAYOUT_RES_FIRST_TIME;
4411 }
4412 return result;
4413 }
4414
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004415 /**
4416 * @return True if this window has been laid out at least once; false otherwise.
4417 */
4418 boolean isLaidOut() {
4419 return mLayoutSeq != -1;
4420 }
4421
4422 /**
4423 * Updates the last inset values to the current ones.
4424 */
4425 void updateLastInsetValues() {
4426 mLastOverscanInsets.set(mOverscanInsets);
4427 mLastContentInsets.set(mContentInsets);
4428 mLastVisibleInsets.set(mVisibleInsets);
4429 mLastStableInsets.set(mStableInsets);
4430 mLastOutsets.set(mOutsets);
4431 }
4432
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004433 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4434 // access to its windows children. Need to investigate re-writing
4435 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4436 static final class UpdateReportedVisibilityResults {
4437 int numInteresting;
4438 int numVisible;
4439 int numDrawn;
4440 boolean nowGone = true;
4441
4442 void reset() {
4443 numInteresting = 0;
4444 numVisible = 0;
4445 numDrawn = 0;
4446 nowGone = true;
4447 }
4448 }
Robert Carraf422a82017-04-10 18:34:33 -07004449
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004450 private static final class WindowId extends IWindowId.Stub {
4451 private final WeakReference<WindowState> mOuter;
4452
4453 private WindowId(WindowState outer) {
4454
4455 // Use a weak reference for the outer class. This is important to prevent the following
4456 // leak: Since we send this class to the client process, binder will keep it alive as
4457 // long as the client keeps it alive. Now, if the window is removed, we need to clear
4458 // out our reference so even though this class is kept alive we don't leak WindowState,
4459 // which can keep a whole lot of classes alive.
4460 mOuter = new WeakReference<>(outer);
4461 }
4462
4463 @Override
4464 public void registerFocusObserver(IWindowFocusObserver observer) {
4465 final WindowState outer = mOuter.get();
4466 if (outer != null) {
4467 outer.registerFocusObserver(observer);
4468 }
4469 }
4470 @Override
4471 public void unregisterFocusObserver(IWindowFocusObserver observer) {
4472 final WindowState outer = mOuter.get();
4473 if (outer != null) {
4474 outer.unregisterFocusObserver(observer);
4475 }
4476 }
4477 @Override
4478 public boolean isFocused() {
4479 final WindowState outer = mOuter.get();
4480 return outer != null && outer.isFocused();
4481 }
4482 }
4483
Robert Carraf422a82017-04-10 18:34:33 -07004484 boolean usesRelativeZOrdering() {
4485 if (!isChildWindow()) {
4486 return false;
4487 } else if (mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) {
4488 return true;
4489 } else {
4490 return false;
4491 }
4492 }
satokcef37fb2011-10-24 21:49:38 +09004493}