blob: 970e62f980c05a728851a9802455a6899c48bdfa [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;
Jorim Jaggi02886a82016-12-06 09:10:06 -080021import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
22import static android.app.ActivityManager.isLowRamDeviceStatic;
23import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
24import static android.view.Display.DEFAULT_DISPLAY;
25import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
26import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
27import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
28import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
29import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
30import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW;
31import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
32import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
33import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
34import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
35import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
36import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
37import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
38import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
39import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
40import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
41import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
42import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
43import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
44import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
45import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
46import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
47import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
48import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
49import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
50import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
51import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
52import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
53import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
54import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
55import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
56import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
57import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
58import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
59import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
60import static android.view.WindowManagerPolicy.TRANSIT_ENTER;
61import static android.view.WindowManagerPolicy.TRANSIT_EXIT;
62import static android.view.WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
63import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
64import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
65import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
66import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
67import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
68import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
69import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
70import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
71import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
72import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS;
73import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
74import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
75import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
76import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
77import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
78import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SURFACE_TRACE;
79import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
80import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER;
81import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
82import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
83import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
84import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
85import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
86import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
87import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
88import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
89import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
90import static com.android.server.wm.WindowManagerService.localLOGV;
91import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING;
92import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
93import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN;
94import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
95
Wale Ogunwale053c8e42015-11-16 14:27:21 -080096import android.app.AppOpsManager;
97import android.content.Context;
98import android.content.res.Configuration;
99import android.graphics.Matrix;
100import android.graphics.PixelFormat;
101import android.graphics.Point;
102import android.graphics.Rect;
103import android.graphics.Region;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700104import android.os.Binder;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700105import android.os.Debug;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800106import android.os.IBinder;
107import android.os.PowerManager;
108import android.os.RemoteCallbackList;
109import android.os.RemoteException;
110import android.os.SystemClock;
111import android.os.Trace;
112import android.os.UserHandle;
113import android.os.WorkSource;
114import android.util.DisplayMetrics;
115import android.util.Slog;
116import android.util.TimeUtils;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800117import android.view.DisplayInfo;
118import android.view.Gravity;
119import android.view.IApplicationToken;
120import android.view.IWindow;
121import android.view.IWindowFocusObserver;
122import android.view.IWindowId;
123import android.view.InputChannel;
124import android.view.InputEvent;
125import android.view.InputEventReceiver;
126import android.view.View;
127import android.view.ViewTreeObserver;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700128import android.view.WindowInfo;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800129import android.view.WindowManager;
130import android.view.WindowManagerPolicy;
131
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800132import com.android.internal.util.ToBooleanFunction;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800133import com.android.server.input.InputWindowHandle;
134
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800135import java.io.PrintWriter;
136import java.util.ArrayList;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700137import java.util.Comparator;
138import java.util.LinkedList;
Wale Ogunwaled1880962016-11-08 10:31:59 -0800139import java.util.function.Predicate;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800140
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700141/** A window in the window manager. */
142class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800143 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800144
Skuhne81c524a2015-08-12 13:34:14 -0700145 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700146 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
147 // use hard-coded min sizes for now.
148 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
149 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700150
151 // The thickness of a window resize handle outside the window bounds on the free form workspace
152 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700153 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700154
Jorim Jaggi02886a82016-12-06 09:10:06 -0800155 private static final boolean DEBUG_DISABLE_SAVING_SURFACES = false ||
156 ENABLE_TASK_SNAPSHOTS;
Robert Carr7098dbd2016-02-01 12:31:01 -0800157
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800158 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700159 final WindowManagerPolicy mPolicy;
160 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800161 final Session mSession;
162 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800163 final int mAppOp;
164 // UserId and appId of the owner. Don't display windows of non-current user.
165 final int mOwnerUid;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800166 /** The owner has {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} */
167 final boolean mOwnerCanAddInternalSystemWindow;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800168 final IWindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800169 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700170 // The same object as mToken if this is an app window and null for non-app windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800171 AppWindowToken mAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700172
173 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
174 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800175 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
176 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700177 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800178 final int mBaseLayer;
179 final int mSubLayer;
180 final boolean mLayoutAttached;
181 final boolean mIsImWindow;
182 final boolean mIsWallpaper;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700183 private final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700184 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700185 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800186 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700187 int mSystemUiVisibility;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700188 /**
189 * The visibility of the window based on policy like {@link WindowManagerPolicy}.
190 * Normally set by calling {@link #showLw} and {@link #hideLw}.
191 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800192 boolean mPolicyVisibility = true;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700193 /**
194 * What {@link #mPolicyVisibility} should be set to after a transition animation.
195 * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and
196 * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit
197 * animation is done.
198 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800199 boolean mPolicyVisibilityAfterAnim = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700200 private boolean mAppOpVisibility = true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700201 boolean mPermanentlyHidden; // the window should never be shown again
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800202 boolean mAppFreezing;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700203 boolean mHidden; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800204 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700205 private boolean mDragResizing;
206 private boolean mDragResizingChangeReported;
207 private int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700208
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700209 private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800210
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700211 /**
212 * The window size that was requested by the application. These are in
213 * the application's coordinate space (without compatibility scale applied).
214 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800215 int mRequestedWidth;
216 int mRequestedHeight;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700217 private int mLastRequestedWidth;
218 private int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700219
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800220 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800221 boolean mHaveFrame;
222 boolean mObscured;
223 boolean mTurnOnScreen;
224
225 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700226
Andrii Kulian9d91ca62016-09-29 22:28:09 -0700227 /**
228 * Used to store last reported to client configuration and check if we have newer available.
229 * We'll send configuration to client only if it is different from the last applied one and
230 * client won't perform unnecessary updates.
231 */
232 private final Configuration mLastReportedConfiguration = new Configuration();
Craig Mautnera2c77052012-03-26 12:14:43 -0700233
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700234 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700235 * Actual position of the surface shown on-screen (may be modified by animation). These are
236 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700237 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700238 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800239
240 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700241 * Insets that determine the actually visible area. These are in the application's
242 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800243 */
244 final Rect mVisibleInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700245 private final Rect mLastVisibleInsets = new Rect();
246 private boolean mVisibleInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800247
248 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700249 * Insets that are covered by system windows (such as the status bar) and
250 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700251 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800252 */
253 final Rect mContentInsets = new Rect();
254 final Rect mLastContentInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700255 private boolean mContentInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800256
257 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800258 * Insets that determine the area covered by the display overscan region. These are in the
259 * application's coordinate space (without compatibility scale applied).
260 */
261 final Rect mOverscanInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700262 private final Rect mLastOverscanInsets = new Rect();
263 private boolean mOverscanInsetsChanged;
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800264
265 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700266 * Insets that determine the area covered by the stable system windows. These are in the
267 * application's coordinate space (without compatibility scale applied).
268 */
269 final Rect mStableInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700270 private final Rect mLastStableInsets = new Rect();
271 private boolean mStableInsetsChanged;
Adrian Roosfa104232014-06-20 16:10:14 -0700272
273 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700274 * Outsets determine the area outside of the surface where we want to pretend that it's possible
275 * to draw anyway.
276 */
277 final Rect mOutsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700278 private final Rect mLastOutsets = new Rect();
279 private boolean mOutsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700280
281 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800282 * Set to true if we are waiting for this window to receive its
283 * given internal insets before laying out other windows based on it.
284 */
285 boolean mGivenInsetsPending;
286
287 /**
288 * These are the content insets that were given during layout for
289 * this window, to be applied to windows behind it.
290 */
291 final Rect mGivenContentInsets = new Rect();
292
293 /**
294 * These are the visible insets that were given during layout for
295 * this window, to be applied to windows behind it.
296 */
297 final Rect mGivenVisibleInsets = new Rect();
298
299 /**
300 * This is the given touchable area relative to the window frame, or null if none.
301 */
302 final Region mGivenTouchableRegion = new Region();
303
304 /**
305 * Flag indicating whether the touchable region should be adjusted by
306 * the visible insets; if false the area outside the visible insets is
307 * NOT touchable, so we must use those to adjust the frame during hit
308 * tests.
309 */
310 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
311
312 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400313 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700314 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800315 float mHScale=1, mVScale=1;
316 float mLastHScale=1, mLastVScale=1;
317 final Matrix mTmpMatrix = new Matrix();
318
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700319 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800320 final Rect mFrame = new Rect();
321 final Rect mLastFrame = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700322 private boolean mFrameSizeChanged = false;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700323 // Frame that is scaled to the application's coordinate space when in
324 // screen size compatibility mode.
325 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800326
327 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700328
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700329 private final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700330
Wale Ogunwale94596652015-02-06 19:27:34 -0800331 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
332 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700333 final Rect mDisplayFrame = new Rect();
334
335 // The region of the display frame that the display type supports displaying content on. This
336 // is mostly a special case for TV where some displays don’t have the entire display usable.
337 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
338 // window display contents to extend into the overscan region.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700339 private final Rect mOverscanFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700340
341 // The display frame minus the stable insets. This value is always constant regardless of if
342 // the status bar or navigation bar is visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700343 private final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800344
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700345 // The area not occupied by the status and navigation bars. So, if both status and navigation
346 // bars are visible, the decor frame is equal to the stable frame.
347 final Rect mDecorFrame = new Rect();
348
349 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
350 // minus the area occupied by the IME if the IME is present.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700351 private final Rect mContentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700352
353 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
354 // displays hint text.
355 final Rect mVisibleFrame = new Rect();
356
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700357 // Frame that includes dead area outside of the surface but where we want to pretend that it's
358 // possible to draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700359 private final Rect mOutsetFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700360
Jorim Jaggidc249c42015-12-15 14:57:31 -0800361 /**
362 * Usually empty. Set to the task's tempInsetFrame. See
363 *{@link android.app.IActivityManager#resizeDockedStack}.
364 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700365 private final Rect mInsetFrame = new Rect();
Jorim Jaggidc249c42015-12-15 14:57:31 -0800366
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800367 boolean mContentChanged;
368
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800369 // If a window showing a wallpaper: the requested offset for the
370 // wallpaper; if a wallpaper window: the currently applied offset.
371 float mWallpaperX = -1;
372 float mWallpaperY = -1;
373
374 // If a window showing a wallpaper: what fraction of the offset
375 // range corresponds to a full virtual screen.
376 float mWallpaperXStep = -1;
377 float mWallpaperYStep = -1;
378
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700379 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
380 // to its window; if a wallpaper window: not used.
381 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
382 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
383
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800384 // Wallpaper windows: pixels offset based on above variables.
385 int mXOffset;
386 int mYOffset;
387
Craig Mautner2268e7e2012-12-13 15:40:00 -0800388 /**
389 * This is set after IWindowSession.relayout() has been called at
390 * least once for the window. It allows us to detect the situation
391 * where we don't yet have a surface, but should have one soon, so
392 * we can give the window focus before waiting for the relayout.
393 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800394 boolean mRelayoutCalled;
395
Robert Carrfed10072016-05-26 11:48:49 -0700396 boolean mInRelayout;
397
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800398 /**
399 * If the application has called relayout() with changes that can
400 * impact its window's size, we need to perform a layout pass on it
401 * even if it is not currently visible for layout. This is set
402 * when in that case until the layout is done.
403 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800404 boolean mLayoutNeeded;
405
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800406 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800407 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800408
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800409 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800410 boolean mDestroying;
411
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800412 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800413 boolean mRemoveOnExit;
414
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800415 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800416 * Whether the app died while it was visible, if true we might need
417 * to continue to show it until it's restarted.
418 */
419 boolean mAppDied;
420
421 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800422 * Set when the orientation is changing and this window has not yet
423 * been updated for the new orientation.
424 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800425 boolean mOrientationChanging;
426
Dianne Hackborna57c6952013-03-29 14:46:40 -0700427 /**
Robert Carr237028a2016-07-26 10:39:45 -0700428 * The orientation during the last visible call to relayout. If our
429 * current orientation is different, the window can't be ready
430 * to be shown.
431 */
432 int mLastVisibleLayoutRotation = -1;
433
434 /**
Andrii Kulianb2e37802017-01-11 00:36:44 -0800435 * Set when we need to report the orientation change to client to trigger a relayout.
436 */
437 boolean mReportOrientationChanged;
438
439 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700440 * How long we last kept the screen frozen.
441 */
442 int mLastFreezeDuration;
443
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800444 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800445 boolean mRemoved;
446
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800447 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800448 * It is save to remove the window and destroy the surface because the client requested removal
449 * or some other higher level component said so (e.g. activity manager).
450 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800451 */
Svetoslav Ganov200adfb2016-10-18 13:29:27 -0700452 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800453
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800454 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700455 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800456 InputChannel mInputChannel;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700457 private InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800458
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800459 // Used to improve performance of toString()
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700460 private String mStringNameCache;
461 private CharSequence mLastTitle;
462 private boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800463
Craig Mautnera2c77052012-03-26 12:14:43 -0700464 final WindowStateAnimator mWinAnimator;
465
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700466 boolean mHasSurface = false;
467
Craig Mautner88400d32012-09-30 12:35:45 -0700468 /** When true this window can be displayed on screens owther than mOwnerUid's */
469 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700470
Robert Carr13f7be9e2015-12-02 18:39:45 -0800471 // Whether the window has a saved surface from last pause, which can be
472 // used to start an entering animation earlier.
Chong Zhang92147042016-05-09 12:47:11 -0700473 private boolean mSurfaceSaved = false;
474
Chong Zhang8e4bda92016-05-04 15:08:18 -0700475 // Whether we're performing an entering animation with a saved surface. This flag is
476 // true during the time we're showing a window with a previously saved surface. It's
477 // cleared when surface is destroyed, saved, or re-drawn by the app.
Chong Zhang92147042016-05-09 12:47:11 -0700478 private boolean mAnimatingWithSavedSurface;
479
480 // Whether the window was visible when we set the app to invisible last time. WM uses
481 // this as a hint to restore the surface (if available) for early animation next time
482 // the app is brought visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700483 private boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800484
Robert Carra1eb4392015-12-10 12:43:51 -0800485 // This window will be replaced due to relaunch. This allows window manager
486 // to differentiate between simple removal of a window and replacement. In the latter case it
487 // will preserve the old window until the new one is drawn.
488 boolean mWillReplaceWindow = false;
489 // If true, the replaced window was already requested to be removed.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700490 private boolean mReplacingRemoveRequested = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800491 // Whether the replacement of the window should trigger app transition animation.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700492 private boolean mAnimateReplacingWindow = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800493 // If not null, the window that will be used to replace the old one. This is being set when
494 // the window is added and unset when this window reports its first draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700495 private WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700496 // For the new window in the replacement transition, if we have
497 // requested to replace without animation, then we should
498 // make sure we also don't apply an enter animation for
499 // the new window.
500 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800501 // Whether this window is being moved via the resize API
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700502 private boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800503
Jeff Brownc2932a12014-11-20 18:04:05 -0800504 /**
505 * Wake lock for drawing.
506 * Even though it's slightly more expensive to do so, we will use a separate wake lock
507 * for each app that is requesting to draw while dozing so that we can accurately track
508 * who is preventing the system from suspending.
509 * This lock is only acquired on first use.
510 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700511 private PowerManager.WakeLock mDrawLock;
Jeff Brownc2932a12014-11-20 18:04:05 -0800512
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700513 final private Rect mTmpRect = new Rect();
514
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800515 /**
Jorim Jaggi5e6968d2016-02-19 18:02:13 -0800516 * See {@link #notifyMovedInStack}.
517 */
518 private boolean mJustMovedInStack;
519
520 /**
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800521 * Whether the window was resized by us while it was gone for layout.
522 */
523 boolean mResizedWhileGone = false;
524
Andrii Kulianeb1d3222016-05-16 15:17:55 -0700525 /** @see #isResizedWhileNotDragResizing(). */
526 private boolean mResizedWhileNotDragResizing;
527
528 /** @see #isResizedWhileNotDragResizingReported(). */
529 private boolean mResizedWhileNotDragResizingReported;
Jorim Jaggif3df0aa2016-04-06 15:56:33 -0700530
Robert Carr6da3cc02016-06-16 15:17:07 -0700531 /**
532 * During seamless rotation we have two phases, first the old window contents
533 * are rotated to look as if they didn't move in the new coordinate system. Then we
534 * have to freeze updates to this layer (to preserve the transformation) until
535 * the resize actually occurs. This is true from when the transformation is set
536 * and false until the transaction to resize is sent.
537 */
538 boolean mSeamlesslyRotated = false;
539
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700540 private static final Region sEmptyRegion = new Region();
541
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700542 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700543 * 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 -0700544 * of z-order and 1 otherwise.
545 */
Griff Hazen51d00d82016-11-22 15:39:24 -0800546 private static final Comparator<WindowState> sWindowSubLayerComparator =
547 new Comparator<WindowState>() {
548 @Override
549 public int compare(WindowState w1, WindowState w2) {
550 final int layer1 = w1.mSubLayer;
551 final int layer2 = w2.mSubLayer;
552 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
553 // We insert the child window into the list ordered by
554 // the sub-layer. For same sub-layers, the negative one
555 // should go below others; the positive one should go
556 // above others.
557 return -1;
558 }
559 return 1;
560 };
561 };
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700562
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800563 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700564 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800565 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800566 mService = service;
567 mSession = s;
568 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800569 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800570 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700571 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700572 mOwnerUid = ownerId;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800573 mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800574 mWindowId = new IWindowId.Stub() {
575 @Override
576 public void registerFocusObserver(IWindowFocusObserver observer) {
577 WindowState.this.registerFocusObserver(observer);
578 }
579 @Override
580 public void unregisterFocusObserver(IWindowFocusObserver observer) {
581 WindowState.this.unregisterFocusObserver(observer);
582 }
583 @Override
584 public boolean isFocused() {
585 return WindowState.this.isFocused();
586 }
587 };
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800588 mAttrs.copyFrom(a);
589 mViewVisibility = viewVisibility;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700590 mPolicy = mService.mPolicy;
591 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800592 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700593 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700594 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700595 if (localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700596 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700597 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800598 try {
599 c.asBinder().linkToDeath(deathRecipient, 0);
600 } catch (RemoteException e) {
601 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700602 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800603 mLayoutAttached = false;
604 mIsImWindow = false;
605 mIsWallpaper = false;
606 mIsFloatingLayer = false;
607 mBaseLayer = 0;
608 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700609 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700610 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800611 return;
612 }
613 mDeathRecipient = deathRecipient;
614
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700615 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800616 // The multiplier here is to reserve space for multiple
617 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800618 mBaseLayer = mPolicy.getWindowLayerLw(parentWindow)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700619 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800620 mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700621 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900622
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700623 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow);
624 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900625
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800626 mLayoutAttached = mAttrs.type !=
627 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700628 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
629 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
630 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800631 } else {
632 // The multiplier here is to reserve space for multiple
633 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800634 mBaseLayer = mPolicy.getWindowLayerLw(this)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700635 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800636 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700637 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800638 mLayoutAttached = false;
639 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
640 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
641 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800642 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700643 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800644
Wale Ogunwale72919d22016-12-08 18:58:50 -0800645 if (mAppToken != null && mAppToken.mShowForAllUsers) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700646 // Windows for apps that can show for all users should also show when the device is
647 // locked.
648 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
Craig Mautner19ab8282014-05-07 10:35:34 -0700649 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800650
Craig Mautner322e4032012-07-13 13:35:20 -0700651 mWinAnimator = new WindowStateAnimator(this);
652 mWinAnimator.mAlpha = a.alpha;
653
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800654 mRequestedWidth = 0;
655 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700656 mLastRequestedWidth = 0;
657 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800658 mXOffset = 0;
659 mYOffset = 0;
660 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800661 mInputWindowHandle = new InputWindowHandle(
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800662 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this, c,
663 getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800664 }
665
666 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700667 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Wale Ogunwaled993a572017-02-05 13:52:09 -0800668 mSession.windowAddedLocked(mAttrs.type);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800669 }
670
Craig Mautnera2c77052012-03-26 12:14:43 -0700671 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800672 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800673 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800674 }
675
676 @Override
677 public String getOwningPackage() {
678 return mAttrs.packageName;
679 }
680
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800681 @Override
682 public boolean canAddInternalSystemWindow() {
683 return mOwnerCanAddInternalSystemWindow;
684 }
685
Jorim Jaggif5834272016-04-04 20:25:41 -0700686 /**
687 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
688 * from {@param frame}. In other words, it applies the insets that would result if
689 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700690 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
691 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700692 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700693 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
694 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
695 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
696 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
697 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700698 frame.inset(left, top, right, bottom);
699 }
700
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800701 @Override
Robert Carr43521762016-10-28 13:15:04 -0700702 public void computeFrameLw(Rect parentFrame, Rect displayFrame, Rect overscanFrame,
703 Rect contentFrame, Rect visibleFrame, Rect decorFrame, Rect stableFrame,
704 Rect outsetFrame) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800705 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700706 // This window is being replaced and either already got information that it's being
707 // removed or we are still waiting for some information. Because of this we don't
708 // want to apply any more changes to it, so it remains in this state until new window
709 // appears.
710 return;
711 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800712 mHaveFrame = true;
713
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700714 final Task task = getTask();
Andrii Kulian933076d2016-03-29 17:04:42 -0700715 final boolean fullscreenTask = !isInMultiWindowMode();
Robert Carre6275582016-02-29 15:45:45 -0800716 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700717 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800718
Chong Zhangae35fef2016-03-16 15:56:55 -0700719 // If the task has temp inset bounds set, we have to make sure all its windows uses
720 // the temp inset frame. Otherwise different display frames get applied to the main
721 // window and the child window, making them misaligned.
722 if (fullscreenTask) {
723 mInsetFrame.setEmpty();
724 } else {
725 task.getTempInsetBounds(mInsetFrame);
726 }
727
Jorim Jaggif5834272016-04-04 20:25:41 -0700728 // Denotes the actual frame used to calculate the insets and to perform the layout. When
729 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
730 // insets temporarily. By the notion of a task having a different layout frame, we can
731 // achieve that while still moving the task around.
732 final Rect layoutContainingFrame;
733 final Rect layoutDisplayFrame;
734
735 // The offset from the layout containing frame to the actual containing frame.
736 final int layoutXDiff;
737 final int layoutYDiff;
Wale Ogunwale7cd4b012016-05-07 12:41:22 -0700738 if (fullscreenTask || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800739 // We use the parent frame as the containing frame for fullscreen and child windows
Robert Carr43521762016-10-28 13:15:04 -0700740 mContainingFrame.set(parentFrame);
741 mDisplayFrame.set(displayFrame);
742 layoutDisplayFrame = displayFrame;
743 layoutContainingFrame = parentFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700744 layoutXDiff = 0;
745 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800746 } else {
Wale Ogunwalee4a0c572015-06-30 08:40:31 -0700747 task.getBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100748 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
749
750 // If the bounds are frozen, we still want to translate the window freely and only
751 // freeze the size.
752 Rect frozen = mAppToken.mFrozenBounds.peek();
753 mContainingFrame.right = mContainingFrame.left + frozen.width();
754 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
755 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800756 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700757 // IME is up and obscuring this window. Adjust the window position so it is visible.
758 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this) {
Robert Carr43521762016-10-28 13:15:04 -0700759 if (windowsAreFloating && mContainingFrame.bottom > contentFrame.bottom) {
Robert Carrfc03b2b2016-03-31 15:22:02 -0700760 // In freeform we want to move the top up directly.
Robert Carr43521762016-10-28 13:15:04 -0700761 // TODO: Investigate why this is contentFrame not parentFrame.
762 mContainingFrame.top -= mContainingFrame.bottom - contentFrame.bottom;
763 } else if (mContainingFrame.bottom > parentFrame.bottom) {
Robert Carrfc03b2b2016-03-31 15:22:02 -0700764 // But in docked we want to behave like fullscreen
765 // and behave as if the task were given smaller bounds
766 // for the purposes of layout.
Robert Carr43521762016-10-28 13:15:04 -0700767 mContainingFrame.bottom = parentFrame.bottom;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700768 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700769 }
Skuhne81c524a2015-08-12 13:34:14 -0700770
Robert Carre6275582016-02-29 15:45:45 -0800771 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700772 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
773 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800774 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700775 if (mContainingFrame.isEmpty()) {
Robert Carr43521762016-10-28 13:15:04 -0700776 mContainingFrame.set(contentFrame);
Skuhne81c524a2015-08-12 13:34:14 -0700777 }
Doris Liu06d582d2015-06-01 13:18:43 -0700778 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800779 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700780 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
781 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
782 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700783 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
Robert Carr43521762016-10-28 13:15:04 -0700784 subtractInsets(mDisplayFrame, layoutContainingFrame, displayFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700785 if (!layoutInParentFrame()) {
Robert Carr43521762016-10-28 13:15:04 -0700786 subtractInsets(mContainingFrame, layoutContainingFrame, parentFrame, mTmpRect);
787 subtractInsets(mInsetFrame, layoutContainingFrame, parentFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700788 }
Robert Carr43521762016-10-28 13:15:04 -0700789 layoutDisplayFrame = displayFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700790 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700791 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800792
Craig Mautner967212c2013-04-13 21:10:58 -0700793 final int pw = mContainingFrame.width();
794 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800795
Robert Carr43521762016-10-28 13:15:04 -0700796 if (!mParentFrame.equals(parentFrame)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800797 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Robert Carr43521762016-10-28 13:15:04 -0700798 // + " to " + parentFrame);
799 mParentFrame.set(parentFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800800 mContentChanged = true;
801 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700802 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
803 mLastRequestedWidth = mRequestedWidth;
804 mLastRequestedHeight = mRequestedHeight;
805 mContentChanged = true;
806 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800807
Robert Carr43521762016-10-28 13:15:04 -0700808 mOverscanFrame.set(overscanFrame);
809 mContentFrame.set(contentFrame);
810 mVisibleFrame.set(visibleFrame);
811 mDecorFrame.set(decorFrame);
812 mStableFrame.set(stableFrame);
813 final boolean hasOutsets = outsetFrame != null;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700814 if (hasOutsets) {
Robert Carr43521762016-10-28 13:15:04 -0700815 mOutsetFrame.set(outsetFrame);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700816 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800817
Craig Mautnereda67292013-04-28 13:50:14 -0700818 final int fw = mFrame.width();
819 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800820
Jorim Jaggif5834272016-04-04 20:25:41 -0700821 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
822
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700823 // Calculate the outsets before the content frame gets shrinked to the window frame.
824 if (hasOutsets) {
825 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
826 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
827 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
828 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
829 } else {
830 mOutsets.set(0, 0, 0, 0);
831 }
832
Craig Mautnera248eee2013-05-07 11:41:27 -0700833 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800834 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -0800835 if (windowsAreFloating && !mFrame.isEmpty()) {
Skuhne81c524a2015-08-12 13:34:14 -0700836 // Keep the frame out of the blocked system area, limit it in size to the content area
837 // and make sure that there is always a minimum visible so that the user can drag it
838 // into a usable area..
839 final int height = Math.min(mFrame.height(), mContentFrame.height());
840 final int width = Math.min(mContentFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700841 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +0900842 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
843 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
844 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
845 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Skuhne81c524a2015-08-12 13:34:14 -0700846 final int top = Math.max(mContentFrame.top,
847 Math.min(mFrame.top, mContentFrame.bottom - minVisibleHeight));
848 final int left = Math.max(mContentFrame.left + minVisibleWidth - width,
849 Math.min(mFrame.left, mContentFrame.right - minVisibleWidth));
850 mFrame.set(left, top, left + width, top + height);
851 mContentFrame.set(mFrame);
852 mVisibleFrame.set(mContentFrame);
853 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700854 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700855 dc.getDockedDividerController().positionDockedStackedDivider(mFrame);
Jorim Jaggi192086e2016-03-11 17:17:03 +0100856 mContentFrame.set(mFrame);
857 if (!mFrame.equals(mLastFrame)) {
858 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800859 }
Skuhne81c524a2015-08-12 13:34:14 -0700860 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -0700861 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
862 Math.max(mContentFrame.top, mFrame.top),
863 Math.min(mContentFrame.right, mFrame.right),
864 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800865
Jorim Jaggi656f6502016-04-11 21:08:17 -0700866 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
867 Math.max(mVisibleFrame.top, mFrame.top),
868 Math.min(mVisibleFrame.right, mFrame.right),
869 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800870
Jorim Jaggi656f6502016-04-11 21:08:17 -0700871 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
872 Math.max(mStableFrame.top, mFrame.top),
873 Math.min(mStableFrame.right, mFrame.right),
874 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700875 }
Adrian Roosfa104232014-06-20 16:10:14 -0700876
Jorim Jaggi899327f2016-02-25 20:44:18 -0500877 if (fullscreenTask && !windowsAreFloating) {
878 // Windows that are not fullscreen can be positioned outside of the display frame,
879 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -0700880 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
881 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
882 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
883 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800884 }
Craig Mautnereda67292013-04-28 13:50:14 -0700885
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100886 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100887 // For the docked divider, we calculate the stable insets like a full-screen window
888 // so it can use it to calculate the snap positions.
889 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
890 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
891 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
892 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800893
894 // The divider doesn't care about insets in any case, so set it to empty so we don't
895 // trigger a relayout when moving it.
896 mContentInsets.setEmpty();
897 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100898 } else {
Andrii Kuliand9003372016-04-04 17:46:59 -0700899 getDisplayContent().getLogicalDisplayRect(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700900 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
901 // non-fullscreen mode.
Winsonbf1ed3d2016-10-19 17:30:26 -0700902 boolean overrideRightInset = !windowsAreFloating && !fullscreenTask &&
903 mFrame.right > mTmpRect.right;
904 boolean overrideBottomInset = !windowsAreFloating && !fullscreenTask &&
905 mFrame.bottom > mTmpRect.bottom;
Jorim Jaggi656f6502016-04-11 21:08:17 -0700906 mContentInsets.set(mContentFrame.left - mFrame.left,
907 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700908 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700909 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700910 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700911 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800912
Jorim Jaggi656f6502016-04-11 21:08:17 -0700913 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
914 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700915 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700916 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700917 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700918 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800919
Jorim Jaggi656f6502016-04-11 21:08:17 -0700920 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
921 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700922 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700923 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700924 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700925 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100926 }
Adrian Roosfa104232014-06-20 16:10:14 -0700927
Jorim Jaggi656f6502016-04-11 21:08:17 -0700928 // Offset the actual frame by the amount layout frame is off.
929 mFrame.offset(-layoutXDiff, -layoutYDiff);
930 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -0700931 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
932 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
933 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
934
Craig Mautnereda67292013-04-28 13:50:14 -0700935 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400936 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700937 // If there is a size compatibility scale being applied to the
938 // window, we need to apply this to its insets so that they are
939 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700940 mOverscanInsets.scale(mInvGlobalScale);
941 mContentInsets.scale(mInvGlobalScale);
942 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -0700943 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700944 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700945
946 // Also the scaled frame that we report to the app needs to be
947 // adjusted to be in its coordinate space.
948 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400949 }
950
Craig Mautnereda67292013-04-28 13:50:14 -0700951 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -0800952 final DisplayContent displayContent = getDisplayContent();
953 if (displayContent != null) {
954 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwale0303c572016-10-20 10:16:29 -0700955 getDisplayContent().mWallpaperController.updateWallpaperOffset(
Wale Ogunwalee8069dc2015-08-18 09:52:01 -0700956 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -0800957 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800958 }
959
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700960 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -0700961 "Resolving (mRequestedWidth="
962 + mRequestedWidth + ", mRequestedheight="
963 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
964 + "): frame=" + mFrame.toShortString()
965 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -0700966 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700967 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700968 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800969 }
970
Craig Mautnera2c77052012-03-26 12:14:43 -0700971 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800972 public Rect getFrameLw() {
973 return mFrame;
974 }
975
Craig Mautnera2c77052012-03-26 12:14:43 -0700976 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700977 public Point getShownPositionLw() {
978 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800979 }
980
Craig Mautnera2c77052012-03-26 12:14:43 -0700981 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800982 public Rect getDisplayFrameLw() {
983 return mDisplayFrame;
984 }
985
Craig Mautnera2c77052012-03-26 12:14:43 -0700986 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800987 public Rect getOverscanFrameLw() {
988 return mOverscanFrame;
989 }
990
991 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800992 public Rect getContentFrameLw() {
993 return mContentFrame;
994 }
995
Craig Mautnera2c77052012-03-26 12:14:43 -0700996 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800997 public Rect getVisibleFrameLw() {
998 return mVisibleFrame;
999 }
1000
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001001 Rect getStableFrameLw() {
1002 return mStableFrame;
1003 }
1004
Craig Mautnera2c77052012-03-26 12:14:43 -07001005 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001006 public boolean getGivenInsetsPendingLw() {
1007 return mGivenInsetsPending;
1008 }
1009
Craig Mautnera2c77052012-03-26 12:14:43 -07001010 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001011 public Rect getGivenContentInsetsLw() {
1012 return mGivenContentInsets;
1013 }
1014
Craig Mautnera2c77052012-03-26 12:14:43 -07001015 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001016 public Rect getGivenVisibleInsetsLw() {
1017 return mGivenVisibleInsets;
1018 }
1019
Craig Mautnera2c77052012-03-26 12:14:43 -07001020 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001021 public WindowManager.LayoutParams getAttrs() {
1022 return mAttrs;
1023 }
1024
Craig Mautner812d2ca2012-09-27 15:35:34 -07001025 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001026 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001027 return getDisplayContent().getNeedsMenu(this, bottom);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001028 }
1029
Craig Mautner19d59bc2012-09-04 11:15:56 -07001030 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001031 public int getSystemUiVisibility() {
1032 return mSystemUiVisibility;
1033 }
1034
Craig Mautner19d59bc2012-09-04 11:15:56 -07001035 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001036 public int getSurfaceLayer() {
1037 return mLayer;
1038 }
1039
Craig Mautner812d2ca2012-09-27 15:35:34 -07001040 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001041 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001042 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001043 }
1044
1045 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001046 public IApplicationToken getAppToken() {
1047 return mAppToken != null ? mAppToken.appToken : null;
1048 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001049
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001050 @Override
1051 public boolean isVoiceInteraction() {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001052 return mAppToken != null && mAppToken.mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001053 }
1054
Robert Carr31aa98b2016-07-20 15:29:03 -07001055 boolean setReportResizeHints() {
Craig Mautner4c5eb222013-11-18 12:59:05 -08001056 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1057 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1058 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001059 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001060 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
Robert Carr31aa98b2016-07-20 15:29:03 -07001061 mFrameSizeChanged |= (mLastFrame.width() != mFrame.width()) ||
1062 (mLastFrame.height() != mFrame.height());
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001063 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
Robert Carr31aa98b2016-07-20 15:29:03 -07001064 || mOutsetsChanged || mFrameSizeChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001065 }
1066
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001067 /**
1068 * Adds the window to the resizing list if any of the parameters we use to track the window
1069 * dimensions or insets have changed.
1070 */
1071 void updateResizingWindowIfNeeded() {
1072 final WindowStateAnimator winAnimator = mWinAnimator;
1073 if (!mHasSurface || mService.mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
1074 return;
1075 }
1076
1077 final Task task = getTask();
1078 // In the case of stack bound animations, the window frames will update (unlike other
1079 // animations which just modify various transformation properties). We don't want to
1080 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1081 // the frame may not correspond to the surface size or the onscreen area at various
1082 // phases in the animation, and the client will become sad and confused.
1083 if (task != null && task.mStack.getBoundsAnimating()) {
1084 return;
1085 }
1086
1087 setReportResizeHints();
1088 boolean configChanged = isConfigChanged();
1089 if (DEBUG_CONFIGURATION && configChanged) {
1090 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1091 }
1092
1093 final boolean dragResizingChanged = isDragResizeChanged()
1094 && !isDragResizingChangeReported();
1095
1096 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
1097 + " dragResizingChanged=" + dragResizingChanged + " last=" + mLastFrame
1098 + " frame=" + mFrame);
1099
1100 // We update mLastFrame always rather than in the conditional with the last inset
1101 // variables, because mFrameSizeChanged only tracks the width and height changing.
1102 mLastFrame.set(mFrame);
1103
1104 if (mContentInsetsChanged
1105 || mVisibleInsetsChanged
1106 || winAnimator.mSurfaceResized
1107 || mOutsetsChanged
1108 || mFrameSizeChanged
1109 || configChanged
1110 || dragResizingChanged
Andrii Kulianb2e37802017-01-11 00:36:44 -08001111 || !isResizedWhileNotDragResizingReported()
1112 || mReportOrientationChanged) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001113 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1114 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
1115 + " contentInsetsChanged=" + mContentInsetsChanged
1116 + " " + mContentInsets.toShortString()
1117 + " visibleInsetsChanged=" + mVisibleInsetsChanged
1118 + " " + mVisibleInsets.toShortString()
1119 + " stableInsetsChanged=" + mStableInsetsChanged
1120 + " " + mStableInsets.toShortString()
1121 + " outsetsChanged=" + mOutsetsChanged
1122 + " " + mOutsets.toShortString()
1123 + " surfaceResized=" + winAnimator.mSurfaceResized
1124 + " configChanged=" + configChanged
1125 + " dragResizingChanged=" + dragResizingChanged
1126 + " resizedWhileNotDragResizingReported="
Andrii Kulianb2e37802017-01-11 00:36:44 -08001127 + isResizedWhileNotDragResizingReported()
1128 + " reportOrientationChanged=" + mReportOrientationChanged);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001129 }
1130
1131 // If it's a dead window left on screen, and the configuration changed, there is nothing
1132 // we can do about it. Remove the window now.
1133 if (mAppToken != null && mAppDied) {
1134 mAppToken.removeDeadWindows();
1135 return;
1136 }
1137
1138 mLastOverscanInsets.set(mOverscanInsets);
1139 mLastContentInsets.set(mContentInsets);
1140 mLastVisibleInsets.set(mVisibleInsets);
1141 mLastStableInsets.set(mStableInsets);
1142 mLastOutsets.set(mOutsets);
1143 mService.makeWindowFreezingScreenIfNeededLocked(this);
1144
1145 // If the orientation is changing, or we're starting or ending a drag resizing action,
1146 // then we need to hold off on unfreezing the display until this window has been
1147 // redrawn; to do that, we need to go through the process of getting informed by the
1148 // application when it has finished drawing.
1149 if (mOrientationChanging || dragResizingChanged || isResizedWhileNotDragResizing()) {
1150 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
1151 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1152 + ", mDrawState=DRAW_PENDING in " + this
1153 + ", surfaceController " + winAnimator.mSurfaceController);
1154 }
1155 winAnimator.mDrawState = DRAW_PENDING;
1156 if (mAppToken != null) {
1157 mAppToken.clearAllDrawn();
1158 }
1159 }
1160 if (!mService.mResizingWindows.contains(this)) {
1161 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
1162 mService.mResizingWindows.add(this);
1163 }
1164 } else if (mOrientationChanging) {
1165 if (isDrawnLw()) {
1166 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1167 + this + ", surfaceController " + winAnimator.mSurfaceController);
1168 mOrientationChanging = false;
1169 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1170 - mService.mDisplayFreezeTime);
1171 }
1172 }
1173 }
1174
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001175 DisplayContent getDisplayContent() {
1176 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001177 }
1178
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001179 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001180 final DisplayContent displayContent = getDisplayContent();
1181 return displayContent != null ? displayContent.getDisplayInfo() : null;
1182 }
1183
Jorim Jaggife762342016-10-13 14:33:27 +02001184 @Override
1185 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001186 final DisplayContent displayContent = getDisplayContent();
1187 if (displayContent == null) {
1188 return -1;
1189 }
1190 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001191 }
1192
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001193 Task getTask() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07001194 return mAppToken != null ? mAppToken.mTask : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001195 }
1196
1197 TaskStack getStack() {
1198 Task task = getTask();
1199 if (task != null) {
1200 if (task.mStack != null) {
1201 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001202 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001203 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001204 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1205 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001206 final DisplayContent dc = getDisplayContent();
1207 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001208 }
1209
Skuhnef932e562015-08-20 12:07:30 -07001210 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001211 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001212 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001213 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001214 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001215 final Task task = getTask();
1216 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001217 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001218 mTmpRect.setEmpty();
1219 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001220 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001221 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001222 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001223 } else {
1224 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001225 }
1226 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001227
Chong Zhang9184ec62015-09-24 12:32:21 -07001228 bounds.set(mVisibleFrame);
1229 if (intersectWithStackBounds) {
1230 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001231 }
1232
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001233 if (bounds.isEmpty()) {
1234 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001235 if (intersectWithStackBounds) {
1236 bounds.intersect(mTmpRect);
1237 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001238 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001239 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001240 }
1241
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001242 public long getInputDispatchingTimeoutNanos() {
1243 return mAppToken != null
Wale Ogunwale72919d22016-12-08 18:58:50 -08001244 ? mAppToken.mInputDispatchingTimeoutNanos
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001245 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1246 }
1247
Craig Mautnere8552142012-11-07 13:55:47 -08001248 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001249 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001250 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001251 }
1252
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001253 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1254 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1255 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1256 if (dtdx < -.000001f || dtdx > .000001f) return false;
1257 if (dsdy < -.000001f || dsdy > .000001f) return false;
1258 return true;
1259 }
1260
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001261 void prelayout() {
1262 if (mEnforceSizeCompat) {
1263 mGlobalScale = mService.mCompatibleScreenScale;
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001264 mInvGlobalScale = 1/mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001265 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001266 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001267 }
1268 }
1269
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001270 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001271 boolean hasContentToDisplay() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001272 // If we're animating with a saved surface, we're already visible.
1273 // Return true so that the alpha doesn't get cleared.
1274 if (!mAppFreezing && isDrawnLw()
1275 && (mViewVisibility == View.VISIBLE || isAnimatingWithSavedSurface()
1276 || (mWinAnimator.isAnimationSet() && !mService.mAppTransition.isTransitionSet()))) {
1277 return true;
1278 }
1279
Wale Ogunwale44f21802016-09-02 12:49:48 -07001280 return super.hasContentToDisplay();
1281 }
1282
1283 @Override
1284 boolean isVisible() {
Wale Ogunwalee471be62016-10-03 07:53:55 -07001285 // TODO: The check for hiddenRequested is commented out below, because the window can still
1286 // be visible on screen when the flag is true. We would like the isVisible() method to
1287 // return an answer closer to if the window is truly visible (can't be an exact answer
1288 // without checking the surface state), so comment out the check for now so we can test to
1289 // see what problem it causes.
1290 // If it doesn't cause any issues, then we can remove just before we lock down the current
1291 // release (O) and also consolidate this method with #isVisibleUnchecked() and possibly
1292 // other methods like isVisibleNow().
1293 // If it does cause problems, then we can look if there are other ways to solve the problem.
1294 // If there isn't then uncomment and document here why it is needed.
1295 if (/*(mAppToken == null || !mAppToken.hiddenRequested) && */isVisibleUnchecked()
1296 // TODO: The window isn't considered visible when the token is hidden, however
1297 // uncommenting the check below breaks the visual transition from an app to the launcher
1298 // if the home buttons is pressed. Need to investigate an fix that issue before
1299 // uncommenting.
1300 /* && !mToken.hidden*/) {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001301 // Is this window visible? It is not visible if there is no surface, or we are in the
1302 // process of running an exit animation that will remove the surface, or its app token
1303 // has been hidden.
1304 return true;
1305 }
Wale Ogunwale51362492016-09-08 17:49:17 -07001306 return false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001307 }
1308
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001309 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001310 * Does the minimal check for visibility. Callers generally want to use one of the public
1311 * methods as they perform additional checks on the app token.
1312 * TODO: See if there are other places we can use this check below instead of duplicating...
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001313 */
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001314 private boolean isVisibleUnchecked() {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001315 return mHasSurface && mPolicyVisibility && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001316 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001317 }
1318
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001319 @Override
1320 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001321 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001322 }
1323
1324 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001325 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1326 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001327 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001328 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1329 boolean isWinVisibleLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001330 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.mAppAnimator.animating)
1331 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001332 }
1333
1334 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001335 * The same as isVisible(), but follows the current hidden state of the associated app token,
1336 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001337 */
1338 boolean isVisibleNow() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001339 return (!mToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001340 && isVisibleUnchecked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001341 }
1342
1343 /**
1344 * Can this window possibly be a drag/drop target? The test here is
1345 * a combination of the above "visible now" with the check that the
1346 * Input Manager uses when discarding windows from input consideration.
1347 */
1348 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001349 return isVisibleNow() && !mRemoved
1350 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001351 }
1352
1353 /**
1354 * Same as isVisible(), but we also count it as visible between the
1355 * call to IWindowSession.add() and the first relayout().
1356 */
1357 boolean isVisibleOrAdding() {
1358 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001359 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001360 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001361 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001362 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001363 }
1364
1365 /**
1366 * Is this window currently on-screen? It is on-screen either if it
1367 * is visible or it is currently running an animation before no longer
1368 * being visible.
1369 */
1370 boolean isOnScreen() {
Jorim Jaggiaf221d12016-11-15 14:59:57 -08001371 if (!mHasSurface || mDestroying || !mPolicyVisibility) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001372 return false;
1373 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001374 final AppWindowToken atoken = mAppToken;
1375 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001376 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001377 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001378 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07001379 return !isParentWindowHidden() || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001380 }
1381
1382 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001383 * Whether this window's drawn state might affect the drawn states of the app token.
1384 *
1385 * @param visibleOnly Whether we should consider only the windows that's currently
1386 * visible in layout. If true, windows that has not relayout to VISIBLE
1387 * would always return false.
1388 *
1389 * @return true if the window should be considered while evaluating allDrawn flags.
1390 */
1391 boolean mightAffectAllDrawn(boolean visibleOnly) {
Chong Zhange292eb32016-05-21 09:23:55 -07001392 final boolean isViewVisible = (mAppToken == null || !mAppToken.clientHidden)
1393 && (mViewVisibility == View.VISIBLE) && !mWindowRemovalAllowed;
Jorim Jaggib0d27342016-11-01 16:10:42 -07001394 return (isOnScreen() && (!visibleOnly || isViewVisible)
Chong Zhangfea963e2016-08-15 17:14:16 -07001395 || mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1396 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION)
Chong Zhang8e4bda92016-05-04 15:08:18 -07001397 && !mAnimatingExit && !mDestroying;
1398 }
1399
1400 /**
1401 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1402 * it must be drawn before allDrawn can become true.
1403 */
1404 boolean isInteresting() {
1405 return mAppToken != null && !mAppDied
1406 && (!mAppToken.mAppAnimator.freezingScreen || !mAppFreezing);
1407 }
1408
1409 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001410 * Like isOnScreen(), but we don't return true if the window is part
1411 * of a transition that has not yet been started.
1412 */
1413 boolean isReadyForDisplay() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001414 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001415 return false;
1416 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001417 return mHasSurface && mPolicyVisibility && !mDestroying
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001418 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001419 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001420 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001421 }
1422
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001423 /**
1424 * Like isOnScreen, but returns false if the surface hasn't yet
1425 * been drawn.
1426 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001427 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001428 public boolean isDisplayedLw() {
1429 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001430 return isDrawnLw() && mPolicyVisibility
Wale Ogunwale9d147902016-07-16 11:58:55 -07001431 && ((!isParentWindowHidden() &&
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001432 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001433 || mWinAnimator.mAnimating
1434 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001435 }
1436
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001437 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001438 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001439 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001440 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001441 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001442 return mWinAnimator.mAnimation != null
1443 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001444 }
1445
Craig Mautner812d2ca2012-09-27 15:35:34 -07001446 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001447 public boolean isGoneForLayoutLw() {
1448 final AppWindowToken atoken = mAppToken;
1449 return mViewVisibility == View.GONE
1450 || !mRelayoutCalled
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001451 || (atoken == null && mToken.hidden)
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001452 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001453 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001454 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001455 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001456 }
1457
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001458 /**
1459 * Returns true if the window has a surface that it has drawn a
1460 * complete UI in to.
1461 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001462 public boolean isDrawFinishedLw() {
1463 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001464 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1465 || mWinAnimator.mDrawState == READY_TO_SHOW
1466 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001467 }
1468
1469 /**
1470 * Returns true if the window has a surface that it has drawn a
1471 * complete UI in to.
1472 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001473 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001474 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001475 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001476 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001477 }
1478
1479 /**
1480 * Return true if the window is opaque and fully drawn. This indicates
1481 * it may obscure windows behind it.
1482 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001483 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001484 // When there is keyguard, wallpaper could be placed over the secure app
1485 // window but invisible. We need to check wallpaper visibility explicitly
1486 // to determine if it's occluding apps.
1487 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1488 || (mIsWallpaper && mWallpaperVisible))
Craig Mautnera2c77052012-03-26 12:14:43 -07001489 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001490 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001491 }
1492
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001493 @Override
1494 void onMovedByResize() {
1495 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001496 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001497 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001498 }
1499
1500 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1501 boolean changed = false;
1502
1503 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001504 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001505 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1506 }
1507
1508 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1509 // Starting window that's exiting will be removed when the animation finishes.
1510 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1511 // to actually remove it.
1512 if (!visible && isVisibleNow() && mAppToken.mAppAnimator.isAnimating()) {
1513 mAnimatingExit = true;
1514 mRemoveOnExit = true;
1515 mWindowRemovalAllowed = true;
1516 }
1517 return changed;
1518 }
1519
1520 if (visible != isVisibleNow()) {
1521 if (!runningAppAnimation) {
1522 final AccessibilityController accessibilityController =
1523 mService.mAccessibilityController;
1524 final int winTransit = visible ? TRANSIT_ENTER : TRANSIT_EXIT;
1525 mWinAnimator.applyAnimationLocked(winTransit, visible);
1526 //TODO (multidisplay): Magnification is supported only for the default
1527 if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
1528 accessibilityController.onWindowTransitionLocked(this, winTransit);
1529 }
1530 }
1531 changed = true;
1532 setDisplayLayoutNeeded();
1533 }
1534
1535 return changed;
1536 }
1537
1538 boolean onSetAppExiting() {
1539 final DisplayContent displayContent = getDisplayContent();
1540 boolean changed = false;
1541
1542 if (isVisibleNow()) {
1543 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
1544 //TODO (multidisplay): Magnification is supported only for the default
1545 if (mService.mAccessibilityController != null && isDefaultDisplay()) {
1546 mService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
1547 }
1548 changed = true;
1549 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001550 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001551 }
1552 }
1553
1554 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001555 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001556 changed |= c.onSetAppExiting();
1557 }
1558
1559 return changed;
1560 }
1561
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001562 @Override
1563 void onResize() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001564 // Some windows won't go through the resizing process, if they don't have a surface, so
1565 // destroy all saved surfaces here.
1566 destroySavedSurface();
1567
1568 final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
1569 if (mHasSurface && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001570 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001571 resizingWindows.add(this);
1572
1573 // If we are not drag resizing, force recreating of a new surface so updating
1574 // the content and positioning that surface will be in sync.
1575 //
1576 // As we use this flag as a hint to freeze surface boundary updates, we'd like to only
1577 // apply this to TYPE_BASE_APPLICATION, windows of TYPE_APPLICATION like dialogs, could
1578 // appear to not be drag resizing while they resize, but we'd still like to manipulate
1579 // their frame to update crop, etc...
1580 //
1581 // Anyway we don't need to synchronize position and content updates for these
1582 // windows since they aren't at the base layer and could be moved around anyway.
1583 if (!computeDragResizing() && mAttrs.type == TYPE_BASE_APPLICATION &&
Robert Carr8f0a3ad2017-02-15 19:30:28 -08001584 !mWinAnimator.isForceScaled() && !isGoneForLayoutLw() &&
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001585 !getTask().inPinnedWorkspace()) {
1586 setResizedWhileNotDragResizing(true);
1587 }
1588 }
1589 if (isGoneForLayoutLw()) {
1590 mResizedWhileGone = true;
1591 }
1592
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001593 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001594 }
1595
1596 void onUnfreezeBounds() {
1597 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001598 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001599 c.onUnfreezeBounds();
1600 }
1601
1602 if (!mHasSurface) {
1603 return;
1604 }
1605
1606 mLayoutNeeded = true;
1607 setDisplayLayoutNeeded();
1608 if (!mService.mResizingWindows.contains(this)) {
1609 mService.mResizingWindows.add(this);
1610 }
1611 }
1612
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001613 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001614 * If the window has moved due to its containing content frame changing, then notify the
1615 * listeners and optionally animate it. Simply checking a change of position is not enough,
1616 * because being move due to dock divider is not a trigger for animation.
1617 */
1618 void handleWindowMovedIfNeeded() {
1619 if (!hasMoved()) {
1620 return;
1621 }
1622
1623 // Frame has moved, containing content frame has also moved, and we're not currently
1624 // animating... let's do something.
1625 final int left = mFrame.left;
1626 final int top = mFrame.top;
1627 final Task task = getTask();
1628 final boolean adjustedForMinimizedDockOrIme = task != null
1629 && (task.mStack.isAdjustedForMinimizedDockedStack()
1630 || task.mStack.isAdjustedForIme());
1631 if (mService.okToDisplay()
1632 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1633 && !isDragResizing() && !adjustedForMinimizedDockOrIme
1634 && (task == null || getTask().mStack.hasMovementAnimations())
1635 && !mWinAnimator.mLastHidden) {
1636 mWinAnimator.setMoveAnimation(left, top);
1637 }
1638
1639 //TODO (multidisplay): Accessibility supported only for the default display.
1640 if (mService.mAccessibilityController != null
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001641 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001642 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
1643 }
1644
1645 try {
1646 mClient.moved(left, top);
1647 } catch (RemoteException e) {
1648 }
1649 mMovedByResize = false;
1650 }
1651
1652 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001653 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001654 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1655 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001656 private boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001657 return mHasSurface && (mContentChanged || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001658 && !mAnimatingExit
Chong Zhangbd0d9372015-12-28 15:18:29 -08001659 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001660 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001661 }
1662
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001663 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001664 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001665 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001666 return false;
1667 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001668 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001669 }
1670
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001671 boolean fillsDisplay() {
1672 final DisplayInfo displayInfo = getDisplayInfo();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001673 return mFrame.left <= 0 && mFrame.top <= 0
1674 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001675 }
1676
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001677 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001678 boolean isConfigChanged() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001679 return !mLastReportedConfiguration.equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001680 }
1681
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001682 void onWindowReplacementTimeout() {
1683 if (mWillReplaceWindow) {
1684 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001685 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001686 // delays removal on certain conditions, which will leave the stale window in the
1687 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1688 //
1689 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001690 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001691 } else {
1692 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001693 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001694 c.onWindowReplacementTimeout();
1695 }
1696 }
1697 }
1698
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001699 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001700 void forceWindowsScaleableInTransaction(boolean force) {
1701 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1702 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1703 }
1704
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001705 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001706 }
1707
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001708 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001709 void removeImmediately() {
1710 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001711
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001712 if (mRemoved) {
1713 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001714 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1715 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001716 return;
1717 }
1718
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001719 mRemoved = true;
1720
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001721 mWillReplaceWindow = false;
1722 if (mReplacementWindow != null) {
1723 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1724 }
1725
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001726 final DisplayContent dc = getDisplayContent();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001727 if (mService.mInputMethodTarget == this) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001728 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001729 }
1730
1731 final int type = mAttrs.type;
1732 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001733 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001734 }
1735 mPolicy.removeWindowLw(this);
1736
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001737 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001738
Craig Mautner96868332012-12-04 14:29:11 -08001739 mWinAnimator.destroyDeferredSurfaceLocked();
1740 mWinAnimator.destroySurfaceLocked();
Wale Ogunwaled993a572017-02-05 13:52:09 -08001741 mSession.windowRemovedLocked(mAttrs.type);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001742 try {
1743 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1744 } catch (RuntimeException e) {
1745 // Ignore if it has already been removed (usually because
1746 // we are doing this as part of processing a death note.)
1747 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001748
1749 mService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001750 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001751
Wale Ogunwale571771c2016-08-26 13:18:50 -07001752 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001753 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001754 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001755 removeIfPossible(false /*keepVisibleDeadWindow*/);
1756 }
1757
Wale Ogunwale571771c2016-08-26 13:18:50 -07001758 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001759 mWindowRemovalAllowed = true;
1760 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1761 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1762
1763 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1764 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1765 "Starting window removed " + this);
1766
1767 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && this == mService.mCurrentFocus)
1768 Slog.v(TAG_WM, "Remove " + this + " client="
1769 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1770 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1771 + Debug.getCallers(5));
1772
1773 final long origId = Binder.clearCallingIdentity();
1774
1775 disposeInputChannel();
1776
1777 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1778 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1779 + " mAnimatingExit=" + mAnimatingExit
1780 + " mRemoveOnExit=" + mRemoveOnExit
1781 + " mHasSurface=" + mHasSurface
1782 + " surfaceShowing=" + mWinAnimator.getShown()
1783 + " isAnimationSet=" + mWinAnimator.isAnimationSet()
1784 + " app-animation="
1785 + (mAppToken != null ? mAppToken.mAppAnimator.animation : null)
1786 + " mWillReplaceWindow=" + mWillReplaceWindow
1787 + " inPendingTransaction="
1788 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
1789 + " mDisplayFrozen=" + mService.mDisplayFrozen
1790 + " callers=" + Debug.getCallers(6));
1791
1792 // Visibility of the removed window. Will be used later to update orientation later on.
1793 boolean wasVisible = false;
1794
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001795 final int displayId = getDisplayId();
1796
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001797 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1798 // window until the animation is done. If the display is frozen, just remove immediately,
1799 // since the animation wouldn't be seen.
1800 if (mHasSurface && mService.okToDisplay()) {
1801 if (mWillReplaceWindow) {
1802 // This window is going to be replaced. We need to keep it around until the new one
1803 // gets added, then we will get rid of this one.
1804 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1805 "Preserving " + this + " until the new one is " + "added");
1806 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1807 // been removed. We probably need another flag to indicate that window removal
1808 // should be deffered vs. overloading the flag that says we are playing an exit
1809 // animation.
1810 mAnimatingExit = true;
1811 mReplacingRemoveRequested = true;
1812 Binder.restoreCallingIdentity(origId);
1813 return;
1814 }
1815
1816 if (isAnimatingWithSavedSurface() && !mAppToken.allDrawnExcludingSaved) {
1817 // We started enter animation early with a saved surface, now the app asks to remove
1818 // this window. If we remove it now and the app is not yet drawn, we'll show a
1819 // flicker. Delay the removal now until it's really drawn.
1820 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
1821 "removeWindowLocked: delay removal of " + this + " due to early animation");
1822 // Do not set mAnimatingExit to true here, it will cause the surface to be hidden
1823 // immediately after the enter animation is done. If the app is not yet drawn then
1824 // it will show up as a flicker.
1825 setupWindowForRemoveOnExit();
1826 Binder.restoreCallingIdentity(origId);
1827 return;
1828 }
1829 // If we are not currently running the exit animation, we need to see about starting one
1830 wasVisible = isWinVisibleLw();
1831
1832 if (keepVisibleDeadWindow) {
1833 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1834 "Not removing " + this + " because app died while it's visible");
1835
1836 mAppDied = true;
1837 setDisplayLayoutNeeded();
1838 mService.mWindowPlacerLocked.performSurfacePlacement();
1839
1840 // Set up a replacement input channel since the app is now dead.
1841 // We need to catch tapping on the dead window to restart the app.
1842 openInputChannel(null);
1843 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
1844
1845 Binder.restoreCallingIdentity(origId);
1846 return;
1847 }
1848
1849 if (wasVisible) {
1850 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
1851
1852 // Try starting an animation.
1853 if (mWinAnimator.applyAnimationLocked(transit, false)) {
1854 mAnimatingExit = true;
1855 }
1856 //TODO (multidisplay): Magnification is supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001857 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001858 mService.mAccessibilityController.onWindowTransitionLocked(this, transit);
1859 }
1860 }
1861 final boolean isAnimating =
1862 mWinAnimator.isAnimationSet() && !mWinAnimator.isDummyAnimation();
1863 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001864 && mAppToken.isLastWindow(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001865 // We delay the removal of a window if it has a showing surface that can be used to run
1866 // exit animation and it is marked as exiting.
1867 // Also, If isn't the an animating starting window that is the last window in the app.
1868 // We allow the removal of the non-animating starting window now as there is no
1869 // additional window or animation that will trigger its removal.
1870 if (mWinAnimator.getShown() && mAnimatingExit
1871 && (!lastWindowIsStartingWindow || isAnimating)) {
1872 // The exit animation is running or should run... wait for it!
1873 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1874 "Not removing " + this + " due to exit animation ");
1875 setupWindowForRemoveOnExit();
1876 if (mAppToken != null) {
1877 mAppToken.updateReportedVisibilityLocked();
1878 }
1879 Binder.restoreCallingIdentity(origId);
1880 return;
1881 }
1882 }
1883
Wale Ogunwale571771c2016-08-26 13:18:50 -07001884 removeImmediately();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001885 // Removing a visible window will effect the computed orientation
1886 // So just update orientation if needed.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001887 if (wasVisible && mService.updateOrientationFromAppTokensLocked(false, displayId)) {
1888 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001889 }
1890 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
1891 Binder.restoreCallingIdentity(origId);
1892 }
1893
1894 private void setupWindowForRemoveOnExit() {
1895 mRemoveOnExit = true;
1896 setDisplayLayoutNeeded();
1897 // Request a focus update as this window's input channel is already gone. Otherwise
1898 // we could have no focused window in input manager.
1899 final boolean focusChanged = mService.updateFocusedWindowLocked(
1900 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
1901 mService.mWindowPlacerLocked.performSurfacePlacement();
1902 if (focusChanged) {
1903 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
1904 }
1905 }
1906
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001907 void setHasSurface(boolean hasSurface) {
1908 mHasSurface = hasSurface;
1909 }
1910
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001911 int getAnimLayerAdjustment() {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -08001912 if (mIsImWindow && mService.mInputMethodTarget != null) {
Wale Ogunwale455fac52016-07-21 07:24:49 -07001913 final AppWindowToken appToken = mService.mInputMethodTarget.mAppToken;
1914 if (appToken != null) {
1915 return appToken.mAppAnimator.animLayerAdjustment;
1916 }
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001917 }
Wale Ogunwale455fac52016-07-21 07:24:49 -07001918
1919 if (mAppToken != null) {
1920 return mAppToken.mAppAnimator.animLayerAdjustment;
1921 }
1922
1923 // Nothing is animating, so there is no animation adjustment.
1924 return 0;
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
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08001985 /**
1986 * Notifies this window that the corresponding task has just moved in the stack.
1987 * <p>
1988 * This is used to fix the following: If we moved in the stack, and if the last clip rect was
1989 * empty, meaning that our task was completely offscreen, we need to keep it invisible because
1990 * the actual app transition that updates the visibility is delayed by a few transactions.
1991 * Instead of messing around with the ordering and timing how transitions and transactions are
1992 * executed, we introduce this little hack which prevents this window of getting visible again
1993 * with the wrong bounds until the app transitions has started.
1994 * <p>
1995 * This method notifies the window about that we just moved in the stack so we can apply this
1996 * logic in {@link WindowStateAnimator#updateSurfaceWindowCrop}
1997 */
1998 void notifyMovedInStack() {
1999 mJustMovedInStack = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002000
2001 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002002 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002003 c.notifyMovedInStack();
2004 }
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08002005 }
2006
2007 /**
2008 * See {@link #notifyMovedInStack}.
2009 *
2010 * @return Whether we just got moved in the corresponding stack.
2011 */
2012 boolean hasJustMovedInStack() {
2013 return mJustMovedInStack;
2014 }
2015
2016 /**
2017 * Resets that we just moved in the corresponding stack. See {@link #notifyMovedInStack}.
2018 */
2019 void resetJustMovedInStack() {
2020 mJustMovedInStack = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002021
2022 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002023 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002024 c.resetJustMovedInStack();
2025 }
Jorim Jaggi5e6968d2016-02-19 18:02:13 -08002026 }
2027
Chong Zhangacf11402015-11-04 16:23:10 -08002028 private final class DeadWindowEventReceiver extends InputEventReceiver {
2029 DeadWindowEventReceiver(InputChannel inputChannel) {
2030 super(inputChannel, mService.mH.getLooper());
2031 }
2032 @Override
2033 public void onInputEvent(InputEvent event) {
2034 finishInputEvent(event, true);
2035 }
2036 }
2037 /**
2038 * Dummy event receiver for windows that died visible.
2039 */
2040 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2041
Chong Zhang112eb8c2015-11-02 11:17:00 -08002042 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002043 if (mInputChannel != null) {
2044 throw new IllegalStateException("Window already has an input channel.");
2045 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002046 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002047 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2048 mInputChannel = inputChannels[0];
2049 mClientChannel = inputChannels[1];
2050 mInputWindowHandle.inputChannel = inputChannels[0];
2051 if (outInputChannel != null) {
2052 mClientChannel.transferTo(outInputChannel);
2053 mClientChannel.dispose();
2054 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002055 } else {
2056 // If the window died visible, we setup a dummy input channel, so that taps
2057 // can still detected by input monitor channel, and we can relaunch the app.
2058 // Create dummy event receiver that simply reports all events as handled.
2059 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002060 }
2061 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002062 }
2063
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002064 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002065 if (mDeadWindowEventReceiver != null) {
2066 mDeadWindowEventReceiver.dispose();
2067 mDeadWindowEventReceiver = null;
2068 }
2069
2070 // unregister server channel first otherwise it complains about broken channel
2071 if (mInputChannel != null) {
2072 mService.mInputManager.unregisterInputChannel(mInputChannel);
2073 mInputChannel.dispose();
2074 mInputChannel = null;
2075 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002076 if (mClientChannel != null) {
2077 mClientChannel.dispose();
2078 mClientChannel = null;
2079 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07002080 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002081 }
2082
Chong Zhang112eb8c2015-11-02 11:17:00 -08002083 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08002084 // When the app is terminated (eg. from Recents), the task might have already been
2085 // removed with the window pending removal. Don't apply dim in such cases, as there
2086 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
2087 final AppWindowToken token = mAppToken;
2088 if (token != null && token.removed) {
2089 return;
2090 }
2091
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002092 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002093 if (!mAnimatingExit && mAppDied) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08002094 // If app died visible, apply a dim over the window to indicate that it's inactive
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002095 dc.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002096 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002097 && dc != null && !mAnimatingExit && isVisibleUnchecked()) {
2098 dc.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07002099 }
2100 }
2101
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002102 private DimLayer.DimLayerUser getDimLayerUser() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002103 Task task = getTask();
2104 if (task != null) {
2105 return task;
2106 }
2107 return getStack();
2108 }
2109
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002110 /** Returns true if the replacement window was removed. */
2111 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2112 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2113 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2114 removeReplacedWindow();
2115 return true;
2116 }
2117
2118 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002119 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002120 if (c.removeReplacedWindowIfNeeded(replacement)) {
2121 return true;
2122 }
2123 }
2124 return false;
2125 }
2126
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002127 private void removeReplacedWindow() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002128 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
2129 if (isDimming()) {
2130 transferDimToReplacement();
Robert Carra1eb4392015-12-10 12:43:51 -08002131 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002132 mWillReplaceWindow = false;
2133 mAnimateReplacingWindow = false;
2134 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002135 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002136 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002137 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002138 }
2139 }
2140
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002141 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2142 boolean replacementSet = false;
2143
2144 if (mWillReplaceWindow && mReplacementWindow == null
2145 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2146
2147 mReplacementWindow = replacementCandidate;
2148 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2149 replacementSet = true;
2150 }
2151
2152 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002153 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002154 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2155 }
2156
2157 return replacementSet;
2158 }
2159
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002160 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002161 final DisplayContent dc = getDisplayContent();
2162 if (dc != null) {
2163 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002164 }
2165 }
2166
Robert Carrfed10072016-05-26 11:48:49 -07002167 // TODO: Strange usage of word workspace here and above.
2168 boolean inPinnedWorkspace() {
2169 final Task task = getTask();
2170 return task != null && task.inPinnedWorkspace();
2171 }
2172
Chong Zhang5117e272016-05-03 12:47:34 -07002173 void applyAdjustForImeIfNeeded() {
2174 final Task task = getTask();
2175 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2176 task.mStack.applyAdjustForImeIfNeeded(task);
2177 }
2178 }
2179
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002180 @Override
2181 void switchUser() {
2182 super.switchUser();
2183 if (isHiddenFromUserLocked()) {
2184 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2185 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
2186 hideLw(false);
2187 }
2188 }
2189
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002190 int getTouchableRegion(Region region, int flags) {
2191 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002192 if (modal && mAppToken != null) {
2193 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002194 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002195 // If this is a modal window we need to dismiss it if it's not full screen and the
2196 // touch happens outside of the frame that displays the content. This means we
2197 // need to intercept touches outside of that window. The dim layer user
2198 // associated with the window (task or stack) will give us the good bounds, as
2199 // they would be used to display the dim layer.
2200 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
2201 if (dimLayerUser != null) {
2202 dimLayerUser.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002203 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002204 getVisibleBounds(mTmpRect);
2205 }
2206 if (inFreeformWorkspace()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002207 // For freeform windows we the touch region to include the whole surface for the
2208 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002209 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2210 final int delta = WindowManagerService.dipToPixel(
2211 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2212 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002213 }
2214 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002215 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002216 } else {
2217 // Not modal or full screen modal
2218 getTouchableRegion(region);
2219 }
2220 return flags;
2221 }
2222
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002223 void checkPolicyVisibilityChange() {
2224 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2225 if (DEBUG_VISIBILITY) {
2226 Slog.v(TAG, "Policy visibility changing after anim in " +
2227 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2228 }
2229 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08002230 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002231 if (!mPolicyVisibility) {
2232 if (mService.mCurrentFocus == this) {
2233 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2234 "setAnimationLocked: setting mFocusMayChange true");
2235 mService.mFocusMayChange = true;
2236 }
2237 // Window is no longer visible -- make sure if we were waiting
2238 // for it to be displayed before enabling the display, that
2239 // we allow the display to be enabled now.
2240 mService.enableScreenIfNeededLocked();
2241 }
2242 }
2243 }
2244
2245 void setRequestedSize(int requestedWidth, int requestedHeight) {
2246 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2247 mLayoutNeeded = true;
2248 mRequestedWidth = requestedWidth;
2249 mRequestedHeight = requestedHeight;
2250 }
2251 }
2252
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002253 void prepareWindowToDisplayDuringRelayout(Configuration outConfig) {
2254 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2255 == SOFT_INPUT_ADJUST_RESIZE) {
2256 mLayoutNeeded = true;
2257 }
2258 if (isDrawnLw() && mService.okToDisplay()) {
2259 mWinAnimator.applyEnterAnimationLocked();
2260 }
2261 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
2262 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
2263 mTurnOnScreen = true;
2264 }
2265 if (isConfigChanged()) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002266 outConfig.setTo(getConfiguration());
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002267 if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + this + " visible with new config: "
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002268 + outConfig);
2269 mLastReportedConfiguration.setTo(outConfig);
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002270 }
2271 }
2272
2273 void adjustStartingWindowFlags() {
2274 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2275 && mAppToken.startingWindow != null) {
2276 // Special handling of starting window over the base
2277 // window of the app: propagate lock screen flags to it,
2278 // to provide the correct semantics while starting.
2279 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2280 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2281 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2282 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2283 }
2284 }
2285
2286 void setWindowScale(int requestedWidth, int requestedHeight) {
2287 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2288
2289 if (scaledWindow) {
2290 // requested{Width|Height} Surface's physical size
2291 // attrs.{width|height} Size on screen
2292 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2293 mHScale = (mAttrs.width != requestedWidth) ?
2294 (mAttrs.width / (float)requestedWidth) : 1.0f;
2295 mVScale = (mAttrs.height != requestedHeight) ?
2296 (mAttrs.height / (float)requestedHeight) : 1.0f;
2297 } else {
2298 mHScale = mVScale = 1;
2299 }
2300 }
2301
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002302 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002303 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002304 public void binderDied() {
2305 try {
2306 synchronized(mService.mWindowMap) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002307 final WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002308 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002309 if (win != null) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002310 final DisplayContent dc = getDisplayContent();
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002311 if (win.mAppToken != null && win.mAppToken.findMainWindow() == win) {
2312 mService.mTaskSnapshotController.onAppDied(win.mAppToken);
2313 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002314 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002315 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2316 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002317 // just in case they have the divider at an unstable position. Better
2318 // also reset drag resizing state, because the owner can't do it
2319 // anymore.
Wale Ogunwale1666e312016-12-16 11:27:18 -08002320 final TaskStack stack = dc.getDockedStackIgnoringVisibility();
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002321 if (stack != null) {
2322 stack.resetDockedStackToMiddle();
2323 }
Jorim Jaggidcb68142016-02-09 21:51:30 -08002324 mService.setDockedStackResizing(false);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002325 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002326 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002327 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002328 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002329 }
2330 }
2331 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002332 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002333 }
2334 }
2335 }
2336
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002337 /**
2338 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2339 * because we want to preserve its location on screen to be re-activated later when the user
2340 * interacts with it.
2341 */
2342 boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002343 if (!isWinVisibleLw() || mAppToken == null || mAppToken.clientHidden) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002344 // Not a visible app window or the app isn't dead.
2345 return false;
2346 }
2347
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002348 if (mAttrs.token != mClient.asBinder()) {
2349 // The window was add by a client using another client's app token. We don't want to
2350 // keep the dead window around for this case since this is meant for 'real' apps.
2351 return false;
2352 }
2353
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002354 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2355 // We don't keep starting windows since they were added by the window manager before
2356 // the app even launched.
2357 return false;
2358 }
2359
2360 final TaskStack stack = getStack();
2361 return stack != null && StackId.keepVisibleDeadAppWindowOnScreen(stack.mStackId);
2362 }
2363
Wale Ogunwaled045c822015-12-02 09:14:28 -08002364 /** @return true if this window desires key events. */
2365 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002366 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002367 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002368 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002369 && (mAppToken == null || mAppToken.windowsAreFocusable())
Matthew Nge15352e2016-12-20 15:36:29 -08002370 && !canReceiveTouchInput();
2371 }
2372
2373 /** @return true if this window desires touch events. */
2374 boolean canReceiveTouchInput() {
2375 return mAppToken != null && mAppToken.mTask != null
2376 && mAppToken.mTask.mStack.shouldIgnoreInput();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002377 }
2378
Craig Mautner749a7bb2012-04-02 13:49:53 -07002379 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002380 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002381 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002382 }
2383
Craig Mautner749a7bb2012-04-02 13:49:53 -07002384 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002385 public boolean showLw(boolean doAnimation) {
2386 return showLw(doAnimation, true);
2387 }
2388
2389 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002390 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002391 return false;
2392 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002393 if (!mAppOpVisibility) {
2394 // Being hidden due to app op request.
2395 return false;
2396 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002397 if (mPermanentlyHidden) {
2398 // Permanently hidden until the app exists as apps aren't prepared
2399 // to handle their windows being removed from under them.
2400 return false;
2401 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002402 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002403 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002404 return false;
2405 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002406 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002407 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002408 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07002409 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Craig Mautner2fb98b12012-03-20 17:24:00 -07002410 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002411 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07002412 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002413 // Check for the case where we are currently visible and
2414 // not animating; we do not want to do animation at such a
2415 // point to become visible when we already are.
2416 doAnimation = false;
2417 }
2418 }
2419 mPolicyVisibility = true;
2420 mPolicyVisibilityAfterAnim = true;
2421 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002422 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002423 }
2424 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002425 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002426 }
2427 return true;
2428 }
2429
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002430 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002431 public boolean hideLw(boolean doAnimation) {
2432 return hideLw(doAnimation, true);
2433 }
2434
2435 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2436 if (doAnimation) {
Craig Mautner2fb98b12012-03-20 17:24:00 -07002437 if (!mService.okToDisplay()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002438 doAnimation = false;
2439 }
2440 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002441 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002442 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002443 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002444 return false;
2445 }
2446 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002447 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07002448 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002449 doAnimation = false;
2450 }
2451 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002452 mPolicyVisibilityAfterAnim = false;
2453 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002454 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002455 mPolicyVisibility = false;
2456 // Window is no longer visible -- make sure if we were waiting
2457 // for it to be displayed before enabling the display, that
2458 // we allow the display to be enabled now.
2459 mService.enableScreenIfNeededLocked();
2460 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002461 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002462 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002463 mService.mFocusMayChange = true;
2464 }
2465 }
2466 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002467 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002468 }
2469 return true;
2470 }
2471
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002472 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002473 if (mAppOpVisibility != state) {
2474 mAppOpVisibility = state;
2475 if (state) {
2476 // If the policy visibility had last been to hide, then this
2477 // will incorrectly show at this point since we lost that
2478 // information. Not a big deal -- for the windows that have app
2479 // ops modifies they should only be hidden by policy due to the
2480 // lock screen, and the user won't be changing this if locked.
2481 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002482 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002483 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002484 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002485 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002486 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002487 }
2488
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002489 public void hidePermanentlyLw() {
2490 if (!mPermanentlyHidden) {
2491 mPermanentlyHidden = true;
2492 hideLw(true, true);
2493 }
2494 }
2495
Jeff Brownc2932a12014-11-20 18:04:05 -08002496 public void pokeDrawLockLw(long timeout) {
2497 if (isVisibleOrAdding()) {
2498 if (mDrawLock == null) {
2499 // We want the tag name to be somewhat stable so that it is easier to correlate
2500 // in wake lock statistics. So in particular, we don't want to include the
2501 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002502 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08002503 mDrawLock = mService.mPowerManager.newWakeLock(
2504 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
2505 mDrawLock.setReferenceCounted(false);
2506 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2507 }
2508 // Each call to acquire resets the timeout.
2509 if (DEBUG_POWER) {
2510 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2511 + mAttrs.packageName);
2512 }
2513 mDrawLock.acquire(timeout);
2514 } else if (DEBUG_POWER) {
2515 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2516 + "owned by " + mAttrs.packageName);
2517 }
2518 }
2519
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002520 @Override
2521 public boolean isAlive() {
2522 return mClient.asBinder().isBinderAlive();
2523 }
2524
Craig Mautnera987d432012-10-11 14:07:58 -07002525 boolean isClosing() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002526 return mAnimatingExit || (mService.mClosingApps.contains(mAppToken));
Craig Mautnera987d432012-10-11 14:07:58 -07002527 }
2528
Chong Zhangbef461f2015-10-27 11:38:24 -07002529 boolean isAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002530 return mAnimatingWithSavedSurface;
2531 }
2532
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002533 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002534 boolean isAnimating() {
2535 if (mWinAnimator.isAnimationSet() || mAnimatingExit) {
2536 return true;
2537 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002538 return super.isAnimating();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002539 }
2540
Chong Zhang8e4bda92016-05-04 15:08:18 -07002541 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002542 if (mAnimatingWithSavedSurface
2543 && (mViewVisibility != View.VISIBLE || mWindowRemovalAllowed)) {
2544 return true;
2545 }
2546 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002547 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002548 if (c.isAnimatingInvisibleWithSavedSurface()) {
2549 return true;
2550 }
2551 }
2552 return false;
2553 }
2554
2555 void stopUsingSavedSurface() {
2556 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002557 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002558 c.stopUsingSavedSurface();
2559 }
2560
2561 if (!isAnimatingInvisibleWithSavedSurface()) {
2562 return;
2563 }
2564
2565 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG, "stopUsingSavedSurface: " + this);
2566 clearAnimatingWithSavedSurface();
2567 mDestroying = true;
2568 mWinAnimator.hide("stopUsingSavedSurface");
Wale Ogunwale0303c572016-10-20 10:16:29 -07002569 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002570 }
2571
2572 void markSavedSurfaceExiting() {
2573 if (isAnimatingInvisibleWithSavedSurface()) {
2574 mAnimatingExit = true;
2575 mWinAnimator.mAnimating = true;
2576 }
2577 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002578 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002579 c.markSavedSurfaceExiting();
2580 }
2581 }
2582
2583 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2584 animators.add(mWinAnimator);
2585
2586 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002587 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002588 c.addWinAnimatorToList(animators);
2589 }
2590 }
2591
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002592 void sendAppVisibilityToClients() {
2593 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002594
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002595 final boolean clientHidden = mAppToken.clientHidden;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002596 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2597 // Don't hide the starting window.
2598 return;
2599 }
2600
2601 try {
2602 if (DEBUG_VISIBILITY) Slog.v(TAG,
2603 "Setting visibility of " + this + ": " + (!clientHidden));
2604 mClient.dispatchAppVisibility(!clientHidden);
2605 } catch (RemoteException e) {
2606 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002607 }
2608
Chong Zhang92147042016-05-09 12:47:11 -07002609 public void setVisibleBeforeClientHidden() {
2610 mWasVisibleBeforeClientHidden |=
2611 (mViewVisibility == View.VISIBLE || mAnimatingWithSavedSurface);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002612
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002613 super.setVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -07002614 }
2615
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002616 public void clearWasVisibleBeforeClientHidden() {
Chong Zhang92147042016-05-09 12:47:11 -07002617 mWasVisibleBeforeClientHidden = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002618 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002619 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002620 c.clearWasVisibleBeforeClientHidden();
2621 }
Chong Zhang92147042016-05-09 12:47:11 -07002622 }
2623
2624 public boolean wasVisibleBeforeClientHidden() {
2625 return mWasVisibleBeforeClientHidden;
Chong Zhangbef461f2015-10-27 11:38:24 -07002626 }
2627
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002628 void onStartFreezingScreen() {
2629 mAppFreezing = true;
2630 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002631 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002632 c.onStartFreezingScreen();
2633 }
2634 }
2635
2636 boolean onStopFreezingScreen() {
2637 boolean unfrozeWindows = false;
2638 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002639 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002640 unfrozeWindows |= c.onStopFreezingScreen();
2641 }
2642
2643 if (!mAppFreezing) {
2644 return unfrozeWindows;
2645 }
2646
Wale Ogunwale953171d2016-09-30 09:17:30 -07002647 mAppFreezing = false;
2648
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002649 if (mHasSurface && !mOrientationChanging
2650 && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
2651 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
2652 mOrientationChanging = true;
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002653 mService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002654 }
2655 mLastFreezeDuration = 0;
2656 setDisplayLayoutNeeded();
2657 return true;
2658 }
2659
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002660 private boolean shouldSaveSurface() {
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002661 if (mWinAnimator.mSurfaceController == null) {
2662 // Don't bother if the surface controller is gone for any reason.
2663 return false;
2664 }
2665
Chong Zhang92147042016-05-09 12:47:11 -07002666 if (!mWasVisibleBeforeClientHidden) {
2667 return false;
2668 }
2669
Wale Ogunwale945d1972016-03-23 13:16:41 -07002670 if ((mAttrs.flags & FLAG_SECURE) != 0) {
2671 // We don't save secure surfaces since their content shouldn't be shown while the app
2672 // isn't on screen and content might leak through during the transition animation with
2673 // saved surface.
2674 return false;
2675 }
2676
Jorim Jaggi02886a82016-12-06 09:10:06 -08002677 if (isLowRamDeviceStatic()) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002678 // Don't save surfaces on Svelte devices.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002679 return false;
2680 }
2681
Jorim Jaggiab7ad382016-10-26 18:22:04 -07002682 final Task task = getTask();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002683 final AppWindowToken taskTop = task.getTopVisibleAppToken();
2684 if (taskTop != null && taskTop != mAppToken) {
2685 // Don't save if the window is not the topmost window.
2686 return false;
2687 }
2688
Jorim Jaggi8fa45222016-02-19 19:54:39 -08002689 if (mResizedWhileGone) {
2690 // Somebody resized our window while we were gone for layout, which means that the
2691 // client got an old size, so we have an outdated surface here.
2692 return false;
2693 }
2694
Robert Carr7098dbd2016-02-01 12:31:01 -08002695 if (DEBUG_DISABLE_SAVING_SURFACES) {
2696 return false;
2697 }
2698
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002699 return mAppToken.shouldSaveSurface();
2700 }
2701
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002702 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2703 boolean destroyedSomething = false;
2704 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002705 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002706 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2707 }
2708
2709 if (appStopped || mWindowRemovalAllowed || cleanupOnResume) {
2710
2711 mWinAnimator.destroyPreservedSurfaceLocked();
2712
2713 if (mDestroying) {
2714 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2715 + " destroySurfaces: appStopped=" + appStopped
2716 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2717 + " win.mRemoveOnExit=" + mRemoveOnExit);
2718
2719 if (!cleanupOnResume || mRemoveOnExit) {
2720 destroyOrSaveSurface();
2721 }
2722 if (mRemoveOnExit) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002723 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002724 }
2725 if (cleanupOnResume) {
2726 requestUpdateWallpaperIfNeeded();
2727 }
2728 mDestroying = false;
2729 destroyedSomething = true;
2730 }
2731 }
2732 return destroyedSomething;
2733 }
Chris Craik3131bde2016-05-06 13:39:08 -07002734
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002735 void destroyOrSaveSurface() {
2736 mSurfaceSaved = shouldSaveSurface();
2737 if (mSurfaceSaved) {
2738 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2739 Slog.v(TAG, "Saving surface: " + this);
2740 }
Chris Craik3131bde2016-05-06 13:39:08 -07002741 // Previous user of the surface may have set a transparent region signaling a portion
2742 // doesn't need to be composited, so reset to default empty state.
2743 mSession.setTransparentRegion(mClient, sEmptyRegion);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002744
2745 mWinAnimator.hide("saved surface");
2746 mWinAnimator.mDrawState = WindowStateAnimator.NO_SURFACE;
2747 setHasSurface(false);
Chong Zhang47e36a32016-02-29 16:44:33 -08002748 // The client should have disconnected at this point, but if it doesn't,
2749 // we need to make sure it's disconnected. Otherwise when we reuse the surface
2750 // the client can't reconnect to the buffer queue, and rendering will fail.
2751 if (mWinAnimator.mSurfaceController != null) {
2752 mWinAnimator.mSurfaceController.disconnectInTransaction();
2753 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002754 mAnimatingWithSavedSurface = false;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002755 } else {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002756 mWinAnimator.destroySurfaceLocked();
2757 }
Chong Zhang92147042016-05-09 12:47:11 -07002758 // Clear animating flags now, since the surface is now gone. (Note this is true even
2759 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2760 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002761 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002762
Chong Zhang92147042016-05-09 12:47:11 -07002763 void destroySavedSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002764 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002765 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002766 c.destroySavedSurface();
2767 }
2768
Robert Carr13f7be9e2015-12-02 18:39:45 -08002769 if (mSurfaceSaved) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002770 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, "Destroying saved surface: " + this);
Robert Carr13f7be9e2015-12-02 18:39:45 -08002771 mWinAnimator.destroySurfaceLocked();
Robert Carr237028a2016-07-26 10:39:45 -07002772 mSurfaceSaved = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002773 }
Chong Zhang92147042016-05-09 12:47:11 -07002774 mWasVisibleBeforeClientHidden = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002775 }
2776
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002777 /** Returns -1 if there are no interesting windows or number of interesting windows not drawn.*/
2778 int restoreSavedSurfaceForInterestingWindow() {
2779 int interestingNotDrawn = -1;
2780 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002781 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002782 final int childInterestingNotDrawn = c.restoreSavedSurfaceForInterestingWindow();
2783 if (childInterestingNotDrawn != -1) {
2784 if (interestingNotDrawn == -1) {
2785 interestingNotDrawn = childInterestingNotDrawn;
2786 } else {
2787 interestingNotDrawn += childInterestingNotDrawn;
2788 }
2789 }
Chong Zhang4113ffa2016-02-18 12:39:13 -08002790 }
Robert Carr237028a2016-07-26 10:39:45 -07002791
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002792 if (mAttrs.type == TYPE_APPLICATION_STARTING
2793 || mAppDied || !wasVisibleBeforeClientHidden()
2794 || (mAppToken.mAppAnimator.freezingScreen && mAppFreezing)) {
2795 // Window isn't interesting...
2796 return interestingNotDrawn;
2797 }
2798
2799 restoreSavedSurface();
2800
2801 if (!isDrawnLw()) {
2802 if (interestingNotDrawn == -1) {
2803 interestingNotDrawn = 1;
2804 } else {
2805 interestingNotDrawn++;
2806 }
2807 }
2808 return interestingNotDrawn;
2809 }
2810
2811 /** Returns true if the saved surface was restored. */
2812 boolean restoreSavedSurface() {
2813 if (!mSurfaceSaved) {
2814 return false;
2815 }
2816
2817 // Sometimes we save surfaces due to layout invisible directly after rotation occurs.
2818 // However this means the surface was never laid out in the new orientation.
2819 // We can only restore to the last rotation we were laid out as visible in.
Robert Carr237028a2016-07-26 10:39:45 -07002820 if (mLastVisibleLayoutRotation != mService.mRotation) {
2821 destroySavedSurface();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002822 return false;
Robert Carr237028a2016-07-26 10:39:45 -07002823 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002824 mSurfaceSaved = false;
Robert Carr237028a2016-07-26 10:39:45 -07002825
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002826 if (mWinAnimator.mSurfaceController != null) {
2827 setHasSurface(true);
Wale Ogunwale9d147902016-07-16 11:58:55 -07002828 mWinAnimator.mDrawState = READY_TO_SHOW;
Chong Zhang92147042016-05-09 12:47:11 -07002829 mAnimatingWithSavedSurface = true;
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002830
Chong Zhang6e9872b2016-08-17 10:19:05 -07002831 requestUpdateWallpaperIfNeeded();
2832
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002833 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2834 Slog.v(TAG, "Restoring saved surface: " + this);
2835 }
2836 } else {
2837 // mSurfaceController shouldn't be null if mSurfaceSaved was still true at
2838 // this point. Even if we destroyed the saved surface because of rotation
2839 // or resize, mSurfaceSaved flag should have been cleared. So this is a wtf.
2840 Slog.wtf(TAG, "Failed to restore saved surface: surface gone! " + this);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002841 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002842
2843 return true;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002844 }
2845
Chong Zhang92147042016-05-09 12:47:11 -07002846 boolean canRestoreSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002847 if (mWasVisibleBeforeClientHidden && mSurfaceSaved) {
2848 return true;
2849 }
2850
2851 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002852 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002853 if (c.canRestoreSurface()) {
2854 return true;
2855 }
2856 }
2857
2858 return false;
Chong Zhang92147042016-05-09 12:47:11 -07002859 }
2860
2861 boolean hasSavedSurface() {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002862 return mSurfaceSaved;
2863 }
2864
Chong Zhang92147042016-05-09 12:47:11 -07002865 void clearHasSavedSurface() {
2866 mSurfaceSaved = false;
2867 mAnimatingWithSavedSurface = false;
Chong Zhangf58631a2016-05-24 16:02:10 -07002868 if (mWasVisibleBeforeClientHidden) {
2869 mAppToken.destroySavedSurfaces();
2870 }
Chong Zhang92147042016-05-09 12:47:11 -07002871 }
2872
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002873 boolean clearAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002874 if (mAnimatingWithSavedSurface) {
2875 // App has drawn something to its windows, we're no longer animating with
2876 // the saved surfaces.
2877 if (DEBUG_ANIM) Slog.d(TAG,
2878 "clearAnimatingWithSavedSurface(): win=" + this);
2879 mAnimatingWithSavedSurface = false;
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002880 return true;
Chong Zhang92147042016-05-09 12:47:11 -07002881 }
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002882 return false;
Chong Zhang92147042016-05-09 12:47:11 -07002883 }
2884
Craig Mautner69b08182012-09-05 13:07:13 -07002885 @Override
2886 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002887 final DisplayContent displayContent = getDisplayContent();
2888 if (displayContent == null) {
2889 // Only a window that was on a non-default display can be detached from it.
2890 return false;
2891 }
Winson Chung47a3e652014-05-21 16:03:42 -07002892 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002893 }
2894
Adrian Rooscd3884d2015-02-18 17:25:23 +01002895 @Override
2896 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002897 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002898 final DisplayContent dc = getDisplayContent();
2899 return dimLayerUser != null && dc != null
2900 && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01002901 }
2902
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002903 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07002904 mShowToOwnerOnly = showToOwnerOnly;
2905 }
2906
Wale Ogunwaleea92d972016-12-08 07:33:13 -08002907 private boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002908 // Child windows are evaluated based on their parent window.
2909 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002910 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale72919d22016-12-08 18:58:50 -08002911 && win.mAppToken != null && win.mAppToken.mShowForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002912
2913 // All window frames that are fullscreen extend above status bar, but some don't extend
2914 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2915 // bottom right.
2916 if (win.mFrame.left <= win.mDisplayFrame.left
2917 && win.mFrame.top <= win.mDisplayFrame.top
2918 && win.mFrame.right >= win.mStableFrame.right
2919 && win.mFrame.bottom >= win.mStableFrame.bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002920 // Is a fullscreen window, like the clock alarm. Show to everyone.
2921 return false;
2922 }
2923 }
2924
Craig Mautner341220f2012-10-16 15:20:09 -07002925 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01002926 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002927 }
2928
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002929 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2930 outRegion.set(
2931 frame.left + inset.left, frame.top + inset.top,
2932 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002933 }
2934
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002935 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002936 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002937 switch (mTouchableInsets) {
2938 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002939 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002940 outRegion.set(frame);
2941 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002942 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002943 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002944 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002945 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002946 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002947 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002948 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002949 outRegion.set(mGivenTouchableRegion);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002950 outRegion.translate(frame.left, frame.top);
2951 break;
2952 }
2953 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002954 cropRegionToStackBoundsIfNeeded(outRegion);
2955 }
2956
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002957 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002958 final Task task = getTask();
2959 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002960 return;
2961 }
2962
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002963 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002964 if (stack == null) {
2965 return;
2966 }
2967
2968 stack.getDimBounds(mTmpRect);
2969 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002970 }
2971
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002972 /**
2973 * Report a focus change. Must be called with no locks held, and consistently
2974 * from the same serialized thread (such as dispatched from a handler).
2975 */
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07002976 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002977 try {
2978 mClient.windowFocusChanged(focused, inTouchMode);
2979 } catch (RemoteException e) {
2980 }
2981 if (mFocusCallbacks != null) {
2982 final int N = mFocusCallbacks.beginBroadcast();
2983 for (int i=0; i<N; i++) {
2984 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2985 try {
2986 if (focused) {
2987 obs.focusGained(mWindowId.asBinder());
2988 } else {
2989 obs.focusLost(mWindowId.asBinder());
2990 }
2991 } catch (RemoteException e) {
2992 }
2993 }
2994 mFocusCallbacks.finishBroadcast();
2995 }
2996 }
2997
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002998 @Override
2999 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003000 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003001 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003002 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003003
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003004 return super.getConfiguration();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003005 }
3006
Craig Mautnerdf88d732014-01-27 09:21:32 -08003007 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003008 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08003009 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003010 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
3011 + ": " + mCompatFrame);
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003012 final Configuration newConfig;
3013 if (isConfigChanged()) {
3014 newConfig = new Configuration(getConfiguration());
3015 mLastReportedConfiguration.setTo(newConfig);
3016 } else {
3017 newConfig = null;
3018 }
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003019 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003020 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
3021
Craig Mautnerdf88d732014-01-27 09:21:32 -08003022 final Rect frame = mFrame;
3023 final Rect overscanInsets = mLastOverscanInsets;
3024 final Rect contentInsets = mLastContentInsets;
3025 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07003026 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003027 final Rect outsets = mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003028 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003029 final boolean reportOrientation = mReportOrientationChanged;
Chet Haase8eb48d22014-09-24 07:31:29 -07003030 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
3031 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08003032 // To prevent deadlock simulate one-way call if win.mClient is a local object.
3033 mService.mH.post(new Runnable() {
3034 @Override
3035 public void run() {
3036 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003037 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
Andrii Kulianb2e37802017-01-11 00:36:44 -08003038 stableInsets, outsets, reportDraw, newConfig,
3039 reportOrientation);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003040 } catch (RemoteException e) {
3041 // Not a remote call, RemoteException won't be raised.
3042 }
3043 }
3044 });
3045 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003046 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Andrii Kulianb2e37802017-01-11 00:36:44 -08003047 outsets, reportDraw, newConfig, reportOrientation);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003048 }
Svetoslav4604abc2014-06-10 18:59:30 -07003049
3050 //TODO (multidisplay): Accessibility supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07003051 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07003052 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07003053 }
3054
Craig Mautnerdf88d732014-01-27 09:21:32 -08003055 mOverscanInsetsChanged = false;
3056 mContentInsetsChanged = false;
3057 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07003058 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003059 mOutsetsChanged = false;
Robert Carr31aa98b2016-07-20 15:29:03 -07003060 mFrameSizeChanged = false;
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003061 mResizedWhileNotDragResizingReported = true;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003062 mWinAnimator.mSurfaceResized = false;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003063 mReportOrientationChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003064 } catch (RemoteException e) {
3065 mOrientationChanging = false;
3066 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
3067 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08003068 // We are assuming the hosting process is dead or in a zombie state.
3069 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
3070 + ", removing this window.");
3071 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07003072 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003073 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003074 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003075 }
3076
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003077 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08003078 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
3079 // start even if we haven't received the relayout window, so that the client requests
3080 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
3081 // until the window to small size, otherwise the multithread renderer will shift last
3082 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
3083 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003084 boolean resizing = isDragResizing() || isDragResizeChanged();
3085 if (StackId.useWindowFrameForBackdrop(getStackId()) || !resizing) {
3086 return frame;
3087 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07003088 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003089 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003090 return mTmpRect;
3091 }
3092
Jorim Jaggi86905582016-02-09 21:36:09 -08003093 @Override
3094 public int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003095 final TaskStack stack = getStack();
3096 if (stack == null) {
3097 return INVALID_STACK_ID;
3098 }
3099 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003100 }
3101
3102 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
3103 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
Andrii Kulianb2e37802017-01-11 00:36:44 -08003104 Configuration newConfig, boolean reportOrientation) throws RemoteException {
3105 final boolean forceRelayout = isDragResizeChanged() || mResizedWhileNotDragResizing
3106 || reportOrientation;
Chong Zhangedaf3052016-04-22 15:04:31 -07003107
Jorim Jaggidc249c42015-12-15 14:57:31 -08003108 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Jorim Jaggia4a58ef2016-01-27 02:10:08 -08003109 reportDraw, newConfig, getBackdropFrame(frame),
Chong Zhangedaf3052016-04-22 15:04:31 -07003110 forceRelayout, mPolicy.isNavBarForcedShownLw(this));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003111 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003112 }
3113
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003114 public void registerFocusObserver(IWindowFocusObserver observer) {
3115 synchronized(mService.mWindowMap) {
3116 if (mFocusCallbacks == null) {
3117 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
3118 }
3119 mFocusCallbacks.register(observer);
3120 }
3121 }
3122
3123 public void unregisterFocusObserver(IWindowFocusObserver observer) {
3124 synchronized(mService.mWindowMap) {
3125 if (mFocusCallbacks != null) {
3126 mFocusCallbacks.unregister(observer);
3127 }
3128 }
3129 }
3130
3131 public boolean isFocused() {
3132 synchronized(mService.mWindowMap) {
3133 return mService.mCurrentFocus == this;
3134 }
3135 }
3136
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07003137 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003138 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07003139 return task != null && task.inFreeformWorkspace();
3140 }
3141
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003142 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07003143 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003144 final Task task = getTask();
3145 return task != null && !task.isFullscreen();
3146 }
3147
Chong Zhang3005e752015-09-18 18:46:28 -07003148 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003149 return mDragResizing != computeDragResizing();
3150 }
3151
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003152 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003153 void setWaitingForDrawnIfResizingChanged() {
3154 if (isDragResizeChanged()) {
3155 mService.mWaitingForDrawn.add(this);
3156 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003157 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003158 }
3159
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003160 /**
3161 * @return Whether we reported a drag resize change to the application or not already.
3162 */
3163 boolean isDragResizingChangeReported() {
3164 return mDragResizingChangeReported;
3165 }
3166
3167 /**
3168 * Resets the state whether we reported a drag resize change to the app.
3169 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003170 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003171 void resetDragResizingChangeReported() {
3172 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003173 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003174 }
3175
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003176 /**
3177 * Set whether we got resized but drag resizing flag was false.
3178 * @see #isResizedWhileNotDragResizing().
3179 */
3180 void setResizedWhileNotDragResizing(boolean resizedWhileNotDragResizing) {
3181 mResizedWhileNotDragResizing = resizedWhileNotDragResizing;
3182 mResizedWhileNotDragResizingReported = !resizedWhileNotDragResizing;
3183 }
3184
3185 /**
3186 * Indicates whether we got resized but drag resizing flag was false. In this case, we also
3187 * need to recreate the surface and defer surface bound updates in order to make sure the
3188 * buffer contents and the positioning/size stay in sync.
3189 */
3190 boolean isResizedWhileNotDragResizing() {
3191 return mResizedWhileNotDragResizing;
3192 }
3193
3194 /**
3195 * @return Whether we reported "resize while not drag resizing" to the application.
3196 * @see #isResizedWhileNotDragResizing()
3197 */
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003198 private boolean isResizedWhileNotDragResizingReported() {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003199 return mResizedWhileNotDragResizingReported;
3200 }
3201
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003202 int getResizeMode() {
3203 return mResizeMode;
3204 }
3205
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003206 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003207 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003208 if (task == null) {
3209 return false;
3210 }
Winson Chung2af04b32017-01-24 16:21:13 -08003211 if (!StackId.isStackAffectedByDragResizing(getStackId())) {
3212 return false;
3213 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003214 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003215 // Floating windows never enter drag resize mode.
3216 return false;
3217 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003218 if (task.isDragResizing()) {
3219 return true;
3220 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003221
3222 // If the bounds are currently frozen, it means that the layout size that the app sees
3223 // and the bounds we clip this window to might be different. In order to avoid holes, we
3224 // simulate that we are still resizing so the app fills the hole with the resizing
3225 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003226 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003227 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Jorim Jaggi899327f2016-02-25 20:44:18 -05003228 !task.inFreeformWorkspace() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003229
Chong Zhang3005e752015-09-18 18:46:28 -07003230 }
3231
3232 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003233 final boolean resizing = computeDragResizing();
3234 if (resizing == mDragResizing) {
3235 return;
3236 }
3237 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003238 final Task task = getTask();
3239 if (task != null && task.isDragResizing()) {
3240 mResizeMode = task.getDragResizeMode();
3241 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003242 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003243 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3244 : DRAG_RESIZE_MODE_FREEFORM;
3245 }
Chong Zhang3005e752015-09-18 18:46:28 -07003246 }
3247
3248 boolean isDragResizing() {
3249 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003250 }
3251
Robert Carr2487ce72016-04-07 15:18:45 -07003252 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003253 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3254 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003255 }
3256
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003257 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003258 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003259 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003260 if (stack != null) {
3261 pw.print(" stackId="); pw.print(stack.mStackId);
3262 }
Craig Mautner59c00972012-07-30 12:10:24 -07003263 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003264 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07003265 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08003266 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
3267 pw.print(" package="); pw.print(mAttrs.packageName);
3268 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003269 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003270 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
3271 pw.print(" h="); pw.print(mRequestedHeight);
3272 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003273 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
3274 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
3275 pw.print(" h="); pw.println(mLastRequestedHeight);
3276 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003277 if (mIsChildWindow || mLayoutAttached) {
3278 pw.print(prefix); pw.print("mParentWindow="); pw.print(getParentWindow());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003279 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
3280 }
3281 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
3282 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
3283 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
3284 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
3285 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
3286 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003287 if (dumpAll) {
3288 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3289 pw.print(" mSubLayer="); pw.print(mSubLayer);
3290 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Wale Ogunwale455fac52016-07-21 07:24:49 -07003291 pw.print(getAnimLayerAdjustment());
Craig Mautnerc2f9be02012-03-27 17:32:29 -07003292 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
3293 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003294 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003295 if (dumpAll) {
3296 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003297 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003298 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
3299 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08003300 pw.print(isAnimatingWithSavedSurface());
Chong Zhang112eb8c2015-11-02 11:17:00 -08003301 pw.print(" mAppDied=");pw.println(mAppDied);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003302 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003303 pw.print(prefix); pw.print("mViewVisibility=0x");
3304 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003305 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
3306 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07003307 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
3308 pw.print(" mSystemUiVisibility=0x");
3309 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003310 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003311 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
Svetoslav Ganov71c51022016-09-02 17:54:37 -07003312 || isParentWindowHidden()|| mPermanentlyHidden) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003313 pw.print(prefix); pw.print("mPolicyVisibility=");
3314 pw.print(mPolicyVisibility);
3315 pw.print(" mPolicyVisibilityAfterAnim=");
3316 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003317 pw.print(" mAppOpVisibility=");
3318 pw.print(mAppOpVisibility);
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003319 pw.print(" parentHidden="); pw.print(isParentWindowHidden());
Svetoslav Ganovaa076532016-08-01 19:16:43 -07003320 pw.print(" mPermanentlyHidden="); pw.println(mPermanentlyHidden);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003321 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003322 if (!mRelayoutCalled || mLayoutNeeded) {
3323 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
3324 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003325 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003326 if (mXOffset != 0 || mYOffset != 0) {
3327 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
3328 pw.print(" y="); pw.println(mYOffset);
3329 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003330 if (dumpAll) {
3331 pw.print(prefix); pw.print("mGivenContentInsets=");
3332 mGivenContentInsets.printShortString(pw);
3333 pw.print(" mGivenVisibleInsets=");
3334 mGivenVisibleInsets.printShortString(pw);
3335 pw.println();
3336 if (mTouchableInsets != 0 || mGivenInsetsPending) {
3337 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
3338 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003339 Region region = new Region();
3340 getTouchableRegion(region);
3341 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003342 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003343 pw.print(prefix); pw.print("mFullConfiguration="); pw.println(getConfiguration());
3344 pw.print(prefix); pw.print("mLastReportedConfiguration=");
3345 pw.println(mLastReportedConfiguration);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003346 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07003347 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07003348 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Chong Zhanga8975bd2016-01-28 17:13:47 -08003349 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08003350 pw.print(" hasSavedSurface()="); pw.print(hasSavedSurface());
3351 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003352 if (dumpAll) {
3353 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
3354 pw.print(" last="); mLastFrame.printShortString(pw);
3355 pw.println();
3356 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003357 if (mEnforceSizeCompat) {
3358 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003359 pw.println();
3360 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003361 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003362 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003363 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003364 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003365 pw.println();
3366 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
3367 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003368 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003369 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003370 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003371 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04003372 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
3373 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003374 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
3375 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003376 pw.print(prefix); pw.print("Cur insets: overscan=");
3377 mOverscanInsets.printShortString(pw);
3378 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003379 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003380 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003381 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003382 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003383 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003384 pw.print(prefix); pw.print("Lst insets: overscan=");
3385 mLastOverscanInsets.printShortString(pw);
3386 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003387 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003388 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003389 pw.print(" physical="); mLastOutsets.printShortString(pw);
3390 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003391 pw.println();
3392 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07003393 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
3394 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003395 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
3396 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003397 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
3398 pw.print(" mDestroying="); pw.print(mDestroying);
3399 pw.print(" mRemoved="); pw.println(mRemoved);
3400 }
Andrii Kulianb2e37802017-01-11 00:36:44 -08003401 if (mOrientationChanging || mAppFreezing || mTurnOnScreen
3402 || mReportOrientationChanged) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003403 pw.print(prefix); pw.print("mOrientationChanging=");
3404 pw.print(mOrientationChanging);
3405 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
3406 pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
Andrii Kulianb2e37802017-01-11 00:36:44 -08003407 pw.print(" mReportOrientationChanged="); pw.println(mReportOrientationChanged);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003408 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003409 if (mLastFreezeDuration != 0) {
3410 pw.print(prefix); pw.print("mLastFreezeDuration=");
3411 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
3412 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003413 if (mHScale != 1 || mVScale != 1) {
3414 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
3415 pw.print(" mVScale="); pw.println(mVScale);
3416 }
3417 if (mWallpaperX != -1 || mWallpaperY != -1) {
3418 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
3419 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
3420 }
3421 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
3422 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
3423 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
3424 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003425 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3426 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
3427 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
3428 pw.print(mWallpaperDisplayOffsetX);
3429 pw.print(" mWallpaperDisplayOffsetY=");
3430 pw.println(mWallpaperDisplayOffsetY);
3431 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003432 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07003433 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003434 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003435 if (isDragResizing()) {
3436 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
3437 }
3438 if (computeDragResizing()) {
3439 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
3440 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003441 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003442
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003443 @Override
3444 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003445 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003446 + " " + getWindowTag();
3447 }
3448
Robert Carra1eb4392015-12-10 12:43:51 -08003449 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003450 CharSequence tag = mAttrs.getTitle();
3451 if (tag == null || tag.length() <= 0) {
3452 tag = mAttrs.packageName;
3453 }
3454 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003455 }
3456
3457 @Override
3458 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003459 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003460 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003461 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003462 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003463 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003464 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003465 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003466 }
3467 return mStringNameCache;
3468 }
Robert Carr58f29132015-10-29 14:19:05 -07003469
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003470 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003471 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003472 clipRect.left = (int) (clipRect.left / mHScale);
3473 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003474 }
3475 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003476 clipRect.top = (int) (clipRect.top / mVScale);
3477 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003478 }
3479 }
Robert Carr31e28482015-12-02 16:53:18 -08003480
Jorim Jaggif5834272016-04-04 20:25:41 -07003481 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
3482 final int pw = containingFrame.width();
3483 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003484 final Task task = getTask();
Andrii Kulian933076d2016-03-29 17:04:42 -07003485 final boolean nonFullscreenTask = isInMultiWindowMode();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003486 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3487
3488 // We need to fit it to the display if either
3489 // a) The task is fullscreen, or we don't have a task (we assume fullscreen for the taskless
3490 // windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003491 // b) If it's a secondary app window, we also need to fit it to the display unless
3492 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on screen,
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003493 // but SurfaceViews want to be always at a specific location so we don't fit it to the
3494 // display.
3495 final boolean fitToDisplay = (task == null || !nonFullscreenTask)
Robert Carr6f44db12016-07-21 14:54:43 -07003496 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003497 float x, y;
3498 int w,h;
3499
3500 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3501 if (mAttrs.width < 0) {
3502 w = pw;
3503 } else if (mEnforceSizeCompat) {
3504 w = (int)(mAttrs.width * mGlobalScale + .5f);
3505 } else {
3506 w = mAttrs.width;
3507 }
3508 if (mAttrs.height < 0) {
3509 h = ph;
3510 } else if (mEnforceSizeCompat) {
3511 h = (int)(mAttrs.height * mGlobalScale + .5f);
3512 } else {
3513 h = mAttrs.height;
3514 }
3515 } else {
3516 if (mAttrs.width == MATCH_PARENT) {
3517 w = pw;
3518 } else if (mEnforceSizeCompat) {
3519 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3520 } else {
3521 w = mRequestedWidth;
3522 }
3523 if (mAttrs.height == MATCH_PARENT) {
3524 h = ph;
3525 } else if (mEnforceSizeCompat) {
3526 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3527 } else {
3528 h = mRequestedHeight;
3529 }
3530 }
3531
3532 if (mEnforceSizeCompat) {
3533 x = mAttrs.x * mGlobalScale;
3534 y = mAttrs.y * mGlobalScale;
3535 } else {
3536 x = mAttrs.x;
3537 y = mAttrs.y;
3538 }
3539
Robert Carr1d2bacb2016-03-30 14:29:35 -07003540 if (nonFullscreenTask && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003541 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003542 // required by {@link Gravity#apply} call.
3543 w = Math.min(w, pw);
3544 h = Math.min(h, ph);
3545 }
3546
3547 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003548 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003549 (int) (x + mAttrs.horizontalMargin * pw),
3550 (int) (y + mAttrs.verticalMargin * ph), mFrame);
3551
3552 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003553 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003554 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003555 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003556
3557 // We need to make sure we update the CompatFrame as it is used for
3558 // cropping decisions, etc, on systems where we lack a decor layer.
3559 mCompatFrame.set(mFrame);
3560 if (mEnforceSizeCompat) {
3561 // See comparable block in computeFrameLw.
3562 mCompatFrame.scale(mInvGlobalScale);
3563 }
Robert Carr31e28482015-12-02 16:53:18 -08003564 }
Robert Carr51a1b872015-12-08 14:03:13 -08003565
3566 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003567 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003568 }
3569
Robert Carrf3b72c72016-03-21 18:16:39 -07003570 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003571 return mIsChildWindow
3572 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003573 }
3574
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003575 /** Returns the parent window if this is a child of another window, else null. */
3576 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003577 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3578 // WindowContainer that isn't a WindowState.
3579 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003580 }
3581
3582 /** Returns the topmost parent window if this is a child of another window, else this. */
3583 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003584 WindowState current = this;
3585 WindowState topParent = current;
3586 while (current != null && current.mIsChildWindow) {
3587 current = current.getParentWindow();
3588 // Parent window can be null if the child is detached from it's parent already, but
3589 // someone still has a reference to access it. So, we return the top parent value we
3590 // already have instead of null.
3591 if (current != null) {
3592 topParent = current;
3593 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003594 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003595 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003596 }
3597
Wale Ogunwale9d147902016-07-16 11:58:55 -07003598 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003599 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003600 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003601 }
3602
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003603 void setWillReplaceWindow(boolean animate) {
3604 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003605 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003606 c.setWillReplaceWindow(animate);
3607 }
3608
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003609 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3610 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3611 // We don't set replacing on starting windows since they are added by window manager and
3612 // not the client so won't be replaced by the client.
3613 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003614 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003615
3616 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003617 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003618 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003619 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003620
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003621 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003622 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003623 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003624 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003625
3626 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003627 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003628 c.clearWillReplaceWindow();
3629 }
3630 }
3631
3632 boolean waitingForReplacement() {
3633 if (mWillReplaceWindow) {
3634 return true;
3635 }
3636
3637 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003638 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003639 if (c.waitingForReplacement()) {
3640 return true;
3641 }
3642 }
3643 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003644 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003645
Chong Zhang4d7369a2016-04-25 16:09:14 -07003646 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003647 final DisplayContent dc = getDisplayContent();
3648 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3649 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3650 dc.setLayoutNeeded();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003651 mService.mWindowPlacerLocked.requestTraversal();
3652 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003653
3654 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003655 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003656 c.requestUpdateWallpaperIfNeeded();
3657 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003658 }
3659
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003660 float translateToWindowX(float x) {
3661 float winX = x - mFrame.left;
3662 if (mEnforceSizeCompat) {
3663 winX *= mGlobalScale;
3664 }
3665 return winX;
3666 }
3667
3668 float translateToWindowY(float y) {
3669 float winY = y - mFrame.top;
3670 if (mEnforceSizeCompat) {
3671 winY *= mGlobalScale;
3672 }
3673 return winY;
3674 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003675
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003676 private void transferDimToReplacement() {
Robert Carr9fe459d2016-04-07 23:32:28 -07003677 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003678 final DisplayContent dc = getDisplayContent();
3679 if (dimLayerUser != null && dc != null) {
3680 dc.mDimLayerController.applyDim(dimLayerUser,
3681 mReplacementWindow.mWinAnimator, (mAttrs.flags & FLAG_DIM_BEHIND) != 0);
Robert Carr9fe459d2016-04-07 23:32:28 -07003682 }
3683 }
3684
Robert Carrd1a010f2016-04-07 22:36:22 -07003685 // During activity relaunch due to resize, we sometimes use window replacement
3686 // for only child windows (as the main window is handled by window preservation)
3687 // and the big surface.
3688 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003689 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3690 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3691 // we also want to replace them at such phases, as they won't be covered by window
3692 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003693 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003694 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003695 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003696 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003697
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003698 void setWillReplaceChildWindows() {
3699 if (shouldBeReplacedWithChildren()) {
3700 setWillReplaceWindow(false /* animate */);
3701 }
3702 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003703 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003704 c.setWillReplaceChildWindows();
3705 }
3706 }
3707
3708 WindowState getReplacingWindow() {
3709 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3710 return this;
3711 }
3712 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003713 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003714 final WindowState replacing = c.getReplacingWindow();
3715 if (replacing != null) {
3716 return replacing;
3717 }
3718 }
3719 return null;
3720 }
3721
Jorim Jaggife762342016-10-13 14:33:27 +02003722 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07003723 public int getRotationAnimationHint() {
3724 if (mAppToken != null) {
3725 return mAppToken.mRotationAnimationHint;
3726 } else {
3727 return -1;
3728 }
3729 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003730
Jorim Jaggife762342016-10-13 14:33:27 +02003731 @Override
3732 public boolean isInputMethodWindow() {
3733 return mIsImWindow;
3734 }
3735
Wale Ogunwale9d147902016-07-16 11:58:55 -07003736 // This must be called while inside a transaction.
3737 boolean performShowLocked() {
3738 if (isHiddenFromUserLocked()) {
3739 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3740 hideLw(false);
3741 return false;
3742 }
3743
3744 logPerformShow("performShow on ");
3745
Jorim Jaggia50da602016-12-29 11:51:42 +01003746 final int drawState = mWinAnimator.mDrawState;
3747 if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW)
3748 && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3749 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3750 }
3751
Jorim Jaggib0d27342016-11-01 16:10:42 -07003752 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003753 return false;
3754 }
3755
3756 logPerformShow("Showing ");
3757
3758 mService.enableScreenIfNeededLocked();
3759 mWinAnimator.applyEnterAnimationLocked();
3760
3761 // Force the show in the next prepareSurfaceLocked() call.
3762 mWinAnimator.mLastAlpha = -1;
3763 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) Slog.v(TAG,
3764 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3765 mWinAnimator.mDrawState = HAS_DRAWN;
3766 mService.scheduleAnimationLocked();
3767
3768 if (mHidden) {
3769 mHidden = false;
3770 final DisplayContent displayContent = getDisplayContent();
3771
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003772 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003773 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003774 if (c.mWinAnimator.mSurfaceController != null) {
3775 c.performShowLocked();
3776 // It hadn't been shown, which means layout not performed on it, so now we
3777 // want to make sure to do a layout. If called from within the transaction
3778 // loop, this will cause it to restart with a new layout.
3779 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003780 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003781 }
3782 }
3783 }
3784 }
3785
Wale Ogunwale9d147902016-07-16 11:58:55 -07003786 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003787 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003788 }
3789
3790 return true;
3791 }
3792
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003793 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003794 if (DEBUG_VISIBILITY
3795 || (DEBUG_STARTING_WINDOW && mAttrs.type == TYPE_APPLICATION_STARTING)) {
3796 Slog.v(TAG, prefix + this
3797 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07003798 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003799 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3800 + " during animation: policyVis=" + mPolicyVisibility
3801 + " parentHidden=" + isParentWindowHidden()
3802 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003803 + (mAppToken != null && mAppToken.hiddenRequested)
3804 + " tok.hidden=" + (mAppToken != null && mAppToken.hidden)
Wale Ogunwale9d147902016-07-16 11:58:55 -07003805 + " animating=" + mWinAnimator.mAnimating
3806 + " tok animating="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003807 + (mWinAnimator.mAppAnimator != null && mWinAnimator.mAppAnimator.animating)
Wale Ogunwale9d147902016-07-16 11:58:55 -07003808 + " Callers=" + Debug.getCallers(4));
3809 }
3810 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003811
3812 WindowInfo getWindowInfo() {
3813 WindowInfo windowInfo = WindowInfo.obtain();
3814 windowInfo.type = mAttrs.type;
3815 windowInfo.layer = mLayer;
3816 windowInfo.token = mClient.asBinder();
3817 windowInfo.title = mAttrs.accessibilityTitle;
3818 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3819 windowInfo.focused = isFocused();
3820
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003821 if (mIsChildWindow) {
3822 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003823 }
3824
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003825 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003826 if (childCount > 0) {
3827 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003828 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003829 }
3830 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003831 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003832 windowInfo.childTokens.add(child.mClient.asBinder());
3833 }
3834 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003835 return windowInfo;
3836 }
3837
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003838 int getHighestAnimLayer() {
3839 int highest = mWinAnimator.mAnimLayer;
3840 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003841 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003842 final int childLayer = c.getHighestAnimLayer();
3843 if (childLayer > highest) {
3844 highest = childLayer;
3845 }
3846 }
3847 return highest;
3848 }
3849
3850 int adjustAnimLayer(int adj) {
3851 int highestAnimLayer = mWinAnimator.mAnimLayer = mLayer + adj;
3852 if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG_WM,
3853 "adjustAnimLayer win=" + this + " anim layer: " + mWinAnimator.mAnimLayer);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003854 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003855 final WindowState childWindow = mChildren.get(i);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003856 childWindow.adjustAnimLayer(adj);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003857 if (childWindow.mWinAnimator.mAnimLayer > highestAnimLayer) {
3858 highestAnimLayer = childWindow.mWinAnimator.mAnimLayer;
3859 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003860 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003861 return highestAnimLayer;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003862 }
3863
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003864 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003865 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003866 if (mChildren.isEmpty()) {
3867 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003868 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003869 }
3870
3871 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003872 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003873 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003874 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003875 }
3876 }
3877
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003878 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003879 // We want to consumer the negative sublayer children first because they need to appear
3880 // below the parent, then this window (the parent), and then the positive sublayer children
3881 // because they need to appear above the parent.
3882 int i = 0;
3883 final int count = mChildren.size();
3884 WindowState child = mChildren.get(i);
3885
3886 while (i < count && child.mSubLayer < 0) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003887 if (callback.apply(child)) {
3888 return true;
3889 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003890 i++;
3891 if (i >= count) {
3892 break;
3893 }
3894 child = mChildren.get(i);
3895 }
3896
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003897 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003898 return true;
3899 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003900
3901 while (i < count) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003902 if (callback.apply(child)) {
3903 return true;
3904 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003905 i++;
3906 if (i >= count) {
3907 break;
3908 }
3909 child = mChildren.get(i);
3910 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003911
3912 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003913 }
3914
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003915 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003916 // We want to consumer the positive sublayer children first because they need to appear
3917 // above the parent, then this window (the parent), and then the negative sublayer children
3918 // because they need to appear above the parent.
3919 int i = mChildren.size() - 1;
3920 WindowState child = mChildren.get(i);
3921
3922 while (i >= 0 && child.mSubLayer >= 0) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003923 if (callback.apply(child)) {
3924 return true;
3925 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003926 --i;
3927 if (i < 0) {
3928 break;
3929 }
3930 child = mChildren.get(i);
3931 }
3932
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003933 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003934 return true;
3935 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003936
3937 while (i >= 0) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003938 if (callback.apply(child)) {
3939 return true;
3940 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003941 --i;
3942 if (i < 0) {
3943 break;
3944 }
3945 child = mChildren.get(i);
3946 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003947
3948 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003949 }
3950
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003951 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
3952 boolean traverseTopToBottom) {
3953 if (traverseTopToBottom) {
3954 if (mService.mInputMethodTarget == this) {
3955 // This window is the current IME target, so we need to process the IME windows
3956 // directly above it.
3957 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
3958 return true;
3959 }
3960 }
3961 if (callback.apply(this)) {
3962 return true;
3963 }
3964 } else {
3965 if (callback.apply(this)) {
3966 return true;
3967 }
3968 if (mService.mInputMethodTarget == this) {
3969 // This window is the current IME target, so we need to process the IME windows
3970 // directly above it.
3971 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
3972 return true;
3973 }
3974 }
3975 }
3976
3977 return false;
3978 }
3979
Wale Ogunwaled1880962016-11-08 10:31:59 -08003980 WindowState getWindow(Predicate<WindowState> callback) {
3981 if (callback.test(this)) {
3982 return this;
3983 }
3984 return super.getWindow(callback);
3985 }
3986
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003987 boolean isWindowAnimationSet() {
3988 if (mWinAnimator.isWindowAnimationSet()) {
3989 return true;
3990 }
3991 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003992 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003993 if (c.isWindowAnimationSet()) {
3994 return true;
3995 }
3996 }
3997 return false;
3998 }
3999
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004000 void onExitAnimationDone() {
4001 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
4002 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
4003 + " windowAnimating=" + mWinAnimator.isWindowAnimationSet());
4004
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004005 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004006 // Copying to a different list as multiple children can be removed.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004007 // TODO: Not sure if we really need to copy this into a different list.
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004008 final LinkedList<WindowState> childWindows = new LinkedList(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004009 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004010 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004011 }
4012 }
4013
4014 if (mWinAnimator.mEnteringAnimation) {
4015 mWinAnimator.mEnteringAnimation = false;
4016 mService.requestTraversal();
4017 // System windows don't have an activity and an app token as a result, but need a way
4018 // to be informed about their entrance animation end.
4019 if (mAppToken == null) {
4020 try {
4021 mClient.dispatchWindowShown();
4022 } catch (RemoteException e) {
4023 }
4024 }
4025 }
4026
4027 if (!mWinAnimator.isWindowAnimationSet()) {
4028 //TODO (multidisplay): Accessibility is supported only for the default display.
4029 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
4030 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
4031 }
4032 }
4033
4034 if (!mAnimatingExit) {
4035 return;
4036 }
4037
4038 if (mWinAnimator.isWindowAnimationSet()) {
4039 return;
4040 }
4041
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07004042 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004043 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
4044
4045 mDestroying = true;
4046
4047 final boolean hasSurface = mWinAnimator.hasSurface();
4048 if (hasSurface) {
4049 mWinAnimator.hide("onExitAnimationDone");
4050 }
4051
4052 // If we have an app token, we ask it to destroy the surface for us, so that it can take
4053 // care to ensure the activity has actually stopped and the surface is not still in use.
4054 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
4055 // transaction.
4056 if (mAppToken != null) {
4057 mAppToken.destroySurfaces();
4058 } else {
4059 if (hasSurface) {
4060 mService.mDestroySurface.add(this);
4061 }
4062 if (mRemoveOnExit) {
4063 mService.mPendingRemove.add(this);
4064 mRemoveOnExit = false;
4065 }
4066 }
4067 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07004068 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004069 }
Dan Willemsen117197f2016-07-30 13:02:59 -07004070
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004071 boolean clearAnimatingFlags() {
4072 boolean didSomething = false;
4073 // We don't want to clear it out for windows that get replaced, because the
4074 // animation depends on the flag to remove the replaced window.
4075 //
4076 // We also don't clear the mAnimatingExit flag for windows which have the
4077 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4078 // by the client. We should let animation proceed and not clear this flag or
4079 // they won't eventually be removed by WindowStateAnimator#finishExit.
4080 if (!mWillReplaceWindow && !mRemoveOnExit) {
4081 // Clear mAnimating flag together with mAnimatingExit. When animation
4082 // changes from exiting to entering, we need to clear this flag until the
4083 // new animation gets applied, so that isAnimationStarting() becomes true
4084 // until then.
4085 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4086 // placement for this window during this period, one or more frame will
4087 // show up with wrong position or scale.
4088 if (mAnimatingExit) {
4089 mAnimatingExit = false;
4090 didSomething = true;
4091 }
4092 if (mWinAnimator.mAnimating) {
4093 mWinAnimator.mAnimating = false;
4094 didSomething = true;
4095 }
4096 if (mDestroying) {
4097 mDestroying = false;
4098 mService.mDestroySurface.remove(this);
4099 didSomething = true;
4100 }
4101 }
4102
4103 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004104 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004105 }
4106
4107 return didSomething;
4108 }
4109
Winson4b4ba902016-07-27 19:45:52 -07004110 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004111 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004112 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004113
4114 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004115 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004116 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004117 c.hideWallpaperWindow(wasDeferred, reason);
4118 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004119 if (!mWinAnimator.mLastHidden || wasDeferred) {
4120 mWinAnimator.hide(reason);
4121 dispatchWallpaperVisibility(false);
4122 final DisplayContent displayContent = getDisplayContent();
4123 if (displayContent != null) {
4124 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
4125 }
4126 }
4127 }
4128
4129 /**
4130 * Check wallpaper window for visibility change and notify window if so.
4131 * @param visible Current visibility.
4132 */
4133 void dispatchWallpaperVisibility(final boolean visible) {
4134 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07004135 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004136
4137 // Only send notification if the visibility actually changed and we are not trying to hide
4138 // the wallpaper when we are deferring hiding of the wallpaper.
4139 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4140 mWallpaperVisible = visible;
4141 try {
4142 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4143 "Updating vis of wallpaper " + this
4144 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4145 mClient.dispatchAppVisibility(visible);
4146 } catch (RemoteException e) {
4147 }
4148 }
4149 }
4150
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004151 boolean hasVisibleNotDrawnWallpaper() {
4152 if (mWallpaperVisible && !isDrawnLw()) {
4153 return true;
4154 }
4155 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004156 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004157 if (c.hasVisibleNotDrawnWallpaper()) {
4158 return true;
4159 }
4160 }
4161 return false;
4162 }
4163
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004164 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4165 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004166 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004167 c.updateReportedVisibility(results);
4168 }
4169
4170 if (mAppFreezing || mViewVisibility != View.VISIBLE
4171 || mAttrs.type == TYPE_APPLICATION_STARTING
4172 || mDestroying) {
4173 return;
4174 }
4175 if (DEBUG_VISIBILITY) {
4176 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
4177 + ", isAnimationSet=" + mWinAnimator.isAnimationSet());
4178 if (!isDrawnLw()) {
4179 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4180 + " pv=" + mPolicyVisibility
4181 + " mDrawState=" + mWinAnimator.mDrawState
4182 + " ph=" + isParentWindowHidden()
4183 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
4184 + " a=" + mWinAnimator.mAnimating);
4185 }
4186 }
4187
4188 results.numInteresting++;
4189 if (isDrawnLw()) {
4190 results.numDrawn++;
4191 if (!mWinAnimator.isAnimationSet()) {
4192 results.numVisible++;
4193 }
4194 results.nowGone = false;
4195 } else if (mWinAnimator.isAnimationSet()) {
4196 results.nowGone = false;
4197 }
4198 }
4199
Robert Carrfbbde852016-10-18 11:02:28 -07004200 /**
4201 * Calculate the window crop according to system decor policy. In general this is
4202 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4203 * special cases. This rectangle is in screen space.
4204 */
4205 void calculatePolicyCrop(Rect policyCrop) {
4206 final DisplayContent displayContent = getDisplayContent();
4207 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
4208
4209 if (!isDefaultDisplay()) {
4210 // On a different display there is no system decor. Crop the window
4211 // by the screen boundaries.
4212 // TODO(multi-display)
4213 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4214 policyCrop.intersect(-mCompatFrame.left, -mCompatFrame.top,
4215 displayInfo.logicalWidth - mCompatFrame.left,
4216 displayInfo.logicalHeight - mCompatFrame.top);
4217 } else if (mLayer >= mService.mSystemDecorLayer) {
4218 // Above the decor layer is easy, just use the entire window
4219 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4220 } else if (mDecorFrame.isEmpty()) {
4221 // Windows without policy decor aren't cropped.
4222 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4223 } else {
4224 // Crop to the system decor specified by policy.
4225 calculateSystemDecorRect(policyCrop);
4226 }
4227 }
4228
4229 /**
4230 * The system decor rect is the region of the window which is not covered
4231 * by system decorations.
4232 */
4233 private void calculateSystemDecorRect(Rect systemDecorRect) {
4234 final Rect decorRect = mDecorFrame;
4235 final int width = mFrame.width();
4236 final int height = mFrame.height();
4237
4238 // Compute the offset of the window in relation to the decor rect.
4239 final int left = mXOffset + mFrame.left;
4240 final int top = mYOffset + mFrame.top;
4241
4242 // Initialize the decor rect to the entire frame.
4243 if (isDockedResizing()) {
4244 // If we are resizing with the divider, the task bounds might be smaller than the
4245 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4246 // want in this case in order to avoid holes.
4247 //
4248 // We take care to not shrink the width, for surfaces which are larger than
4249 // the display region. Of course this area will not eventually be visible
4250 // but if we truncate the width now, we will calculate incorrectly
4251 // when adjusting to the stack bounds.
4252 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4253 systemDecorRect.set(0, 0,
4254 Math.max(width, displayInfo.logicalWidth),
4255 Math.max(height, displayInfo.logicalHeight));
4256 } else {
4257 systemDecorRect.set(0, 0, width, height);
4258 }
4259
4260 // If a freeform window is animating from a position where it would be cutoff, it would be
4261 // cutoff during the animation. We don't want that, so for the duration of the animation
4262 // we ignore the decor cropping and depend on layering to position windows correctly.
4263 final boolean cropToDecor = !(inFreeformWorkspace() && isAnimatingLw());
4264 if (cropToDecor) {
4265 // Intersect with the decor rect, offsetted by window position.
4266 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
4267 decorRect.right - left, decorRect.bottom - top);
4268 }
4269
4270 // If size compatibility is being applied to the window, the
4271 // surface is scaled relative to the screen. Also apply this
4272 // scaling to the crop rect. We aren't using the standard rect
4273 // scale function because we want to round things to make the crop
4274 // always round to a larger rect to ensure we don't crop too
4275 // much and hide part of the window that should be seen.
4276 if (mEnforceSizeCompat && mInvGlobalScale != 1.0f) {
4277 final float scale = mInvGlobalScale;
4278 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
4279 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
4280 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
4281 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
4282 }
4283
4284 }
4285
4286 /**
4287 * Expand the given rectangle by this windows surface insets. This
4288 * takes you from the 'window size' to the 'surface size'.
4289 * The surface insets are positive in each direction, so we inset by
4290 * the inverse.
4291 */
4292 void expandForSurfaceInsets(Rect r) {
4293 r.inset(-mAttrs.surfaceInsets.left,
4294 -mAttrs.surfaceInsets.top,
4295 -mAttrs.surfaceInsets.right,
4296 -mAttrs.surfaceInsets.bottom);
4297 }
4298
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004299 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4300 // access to its windows children. Need to investigate re-writing
4301 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4302 static final class UpdateReportedVisibilityResults {
4303 int numInteresting;
4304 int numVisible;
4305 int numDrawn;
4306 boolean nowGone = true;
4307
4308 void reset() {
4309 numInteresting = 0;
4310 numVisible = 0;
4311 numDrawn = 0;
4312 nowGone = true;
4313 }
4314 }
satokcef37fb2011-10-24 21:49:38 +09004315}