blob: 4d69c83d7d67209735f4d950d1b4c6e5a474bb1a [file] [log] [blame]
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Jorim Jaggi02886a82016-12-06 09:10:06 -080019import static android.app.ActivityManager.ENABLE_TASK_SNAPSHOTS;
20import static android.app.ActivityManager.StackId;
Winson Chungd73e94b2017-05-31 16:25:30 -070021import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
Jorim Jaggi02886a82016-12-06 09:10:06 -080022import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
Winson Chungd73e94b2017-05-31 16:25:30 -070023import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
Jorim Jaggi02886a82016-12-06 09:10:06 -080024import static android.app.ActivityManager.isLowRamDeviceStatic;
25import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
26import static android.view.Display.DEFAULT_DISPLAY;
27import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
28import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
29import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
30import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
31import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
32import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW;
33import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
34import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
35import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
36import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
37import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
38import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
39import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
40import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
41import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
42import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
43import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
44import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Robert Carrc91d1c32017-02-15 19:37:46 -080045import static android.view.WindowManager.LayoutParams.FORMAT_CHANGED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080046import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
47import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
48import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Phil Weaverc510ecb2017-08-18 18:01:46 -070049import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Jorim Jaggi02886a82016-12-06 09:10:06 -080050import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
51import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
52import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
53import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
54import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
55import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Robert Carraf422a82017-04-10 18:34:33 -070056import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080057import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
58import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
59import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
60import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
61import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
62import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Phil Weaverc510ecb2017-08-18 18:01:46 -070063import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Jorim Jaggi02886a82016-12-06 09:10:06 -080064import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Phil Weaverc510ecb2017-08-18 18:01:46 -070065import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType;
Robert Carrc91d1c32017-02-15 19:37:46 -080066import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED;
67import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM;
68import static android.view.WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME;
69import static android.view.WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080070import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
71import static android.view.WindowManagerPolicy.TRANSIT_ENTER;
72import static android.view.WindowManagerPolicy.TRANSIT_EXIT;
73import static android.view.WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
74import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
75import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
76import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
77import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
78import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
79import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
80import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
81import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
82import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Jorim Jaggi02886a82016-12-06 09:10:06 -080083import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
84import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
85import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
86import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
87import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020088import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Jorim Jaggi02886a82016-12-06 09:10:06 -080089import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SURFACE_TRACE;
90import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080091import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
92import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
93import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
94import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
95import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
96import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
97import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
98import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
99import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
100import static com.android.server.wm.WindowManagerService.localLOGV;
101import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING;
102import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
103import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN;
104import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
105
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800106import android.app.AppOpsManager;
107import android.content.Context;
108import android.content.res.Configuration;
109import android.graphics.Matrix;
110import android.graphics.PixelFormat;
111import android.graphics.Point;
112import android.graphics.Rect;
113import android.graphics.Region;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700114import android.os.Binder;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700115import android.os.Debug;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800116import android.os.IBinder;
117import android.os.PowerManager;
118import android.os.RemoteCallbackList;
119import android.os.RemoteException;
120import android.os.SystemClock;
121import android.os.Trace;
122import android.os.UserHandle;
123import android.os.WorkSource;
Andrii Kulian44607962017-03-16 11:06:24 -0700124import android.util.MergedConfiguration;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800125import android.util.DisplayMetrics;
126import android.util.Slog;
127import android.util.TimeUtils;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800128import android.view.DisplayInfo;
129import android.view.Gravity;
130import android.view.IApplicationToken;
131import android.view.IWindow;
132import android.view.IWindowFocusObserver;
133import android.view.IWindowId;
134import android.view.InputChannel;
135import android.view.InputEvent;
136import android.view.InputEventReceiver;
137import android.view.View;
138import android.view.ViewTreeObserver;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700139import android.view.WindowInfo;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800140import android.view.WindowManager;
141import android.view.WindowManagerPolicy;
142
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800143import com.android.internal.util.ToBooleanFunction;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800144import com.android.server.input.InputWindowHandle;
145
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800146import java.io.PrintWriter;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200147import java.lang.ref.WeakReference;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800148import java.util.ArrayList;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700149import java.util.Comparator;
150import java.util.LinkedList;
Wale Ogunwaled1880962016-11-08 10:31:59 -0800151import java.util.function.Predicate;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800152
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700153/** A window in the window manager. */
154class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800155 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800156
Skuhne81c524a2015-08-12 13:34:14 -0700157 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700158 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
159 // use hard-coded min sizes for now.
160 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
161 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700162
163 // The thickness of a window resize handle outside the window bounds on the free form workspace
164 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700165 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700166
Jorim Jaggi02886a82016-12-06 09:10:06 -0800167 private static final boolean DEBUG_DISABLE_SAVING_SURFACES = false ||
168 ENABLE_TASK_SNAPSHOTS;
Robert Carr7098dbd2016-02-01 12:31:01 -0800169
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800170 final WindowManagerService mService;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700171 final WindowManagerPolicy mPolicy;
172 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800173 final Session mSession;
174 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800175 final int mAppOp;
176 // UserId and appId of the owner. Don't display windows of non-current user.
177 final int mOwnerUid;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800178 /** The owner has {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} */
179 final boolean mOwnerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200180 final WindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800181 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700182 // The same object as mToken if this is an app window and null for non-app windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800183 AppWindowToken mAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700184
185 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
186 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800187 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
188 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700189 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800190 final int mBaseLayer;
191 final int mSubLayer;
192 final boolean mLayoutAttached;
193 final boolean mIsImWindow;
194 final boolean mIsWallpaper;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700195 private final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700196 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700197 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800198 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700199 int mSystemUiVisibility;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700200 /**
201 * The visibility of the window based on policy like {@link WindowManagerPolicy}.
202 * Normally set by calling {@link #showLw} and {@link #hideLw}.
203 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800204 boolean mPolicyVisibility = true;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700205 /**
206 * What {@link #mPolicyVisibility} should be set to after a transition animation.
207 * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and
208 * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit
209 * animation is done.
210 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800211 boolean mPolicyVisibilityAfterAnim = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700212 private boolean mAppOpVisibility = true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700213 boolean mPermanentlyHidden; // the window should never be shown again
Phil Weaverc510ecb2017-08-18 18:01:46 -0700214 // This is a non-system overlay window that is currently force hidden.
215 private boolean mForceHideNonSystemOverlayWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800216 boolean mAppFreezing;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700217 boolean mHidden; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800218 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700219 private boolean mDragResizing;
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200220 private boolean mDragResizingChangeReported = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700221 private int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700222
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700223 private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800224
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700225 /**
226 * The window size that was requested by the application. These are in
227 * the application's coordinate space (without compatibility scale applied).
228 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800229 int mRequestedWidth;
230 int mRequestedHeight;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700231 private int mLastRequestedWidth;
232 private int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700233
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800234 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800235 boolean mHaveFrame;
236 boolean mObscured;
237 boolean mTurnOnScreen;
238
239 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700240
Andrii Kulian9d91ca62016-09-29 22:28:09 -0700241 /**
242 * Used to store last reported to client configuration and check if we have newer available.
243 * We'll send configuration to client only if it is different from the last applied one and
244 * client won't perform unnecessary updates.
245 */
246 private final Configuration mLastReportedConfiguration = new Configuration();
Craig Mautnera2c77052012-03-26 12:14:43 -0700247
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700248 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700249 * Actual position of the surface shown on-screen (may be modified by animation). These are
250 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700251 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700252 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800253
254 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700255 * Insets that determine the actually visible area. These are in the application's
256 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800257 */
258 final Rect mVisibleInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700259 private final Rect mLastVisibleInsets = new Rect();
260 private boolean mVisibleInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800261
262 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700263 * Insets that are covered by system windows (such as the status bar) and
264 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700265 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800266 */
267 final Rect mContentInsets = new Rect();
268 final Rect mLastContentInsets = new Rect();
Robert Carr18f622f2017-05-08 11:20:43 -0700269
270 /**
271 * The last content insets returned to the client in relayout. We use
272 * these in the bounds animation to ensure we only observe inset changes
273 * at the same time that a client resizes it's surface so that we may use
274 * the geometryAppliesWithResize synchronization mechanism to keep
275 * the contents in place.
276 */
277 final Rect mLastRelayoutContentInsets = new Rect();
278
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700279 private boolean mContentInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800280
281 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800282 * Insets that determine the area covered by the display overscan region. These are in the
283 * application's coordinate space (without compatibility scale applied).
284 */
285 final Rect mOverscanInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700286 private final Rect mLastOverscanInsets = new Rect();
287 private boolean mOverscanInsetsChanged;
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800288
289 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700290 * Insets that determine the area covered by the stable system windows. These are in the
291 * application's coordinate space (without compatibility scale applied).
292 */
293 final Rect mStableInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700294 private final Rect mLastStableInsets = new Rect();
295 private boolean mStableInsetsChanged;
Adrian Roosfa104232014-06-20 16:10:14 -0700296
297 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700298 * Outsets determine the area outside of the surface where we want to pretend that it's possible
299 * to draw anyway.
300 */
301 final Rect mOutsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700302 private final Rect mLastOutsets = new Rect();
303 private boolean mOutsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700304
305 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800306 * Set to true if we are waiting for this window to receive its
307 * given internal insets before laying out other windows based on it.
308 */
309 boolean mGivenInsetsPending;
310
311 /**
312 * These are the content insets that were given during layout for
313 * this window, to be applied to windows behind it.
314 */
315 final Rect mGivenContentInsets = new Rect();
316
317 /**
318 * These are the visible insets that were given during layout for
319 * this window, to be applied to windows behind it.
320 */
321 final Rect mGivenVisibleInsets = new Rect();
322
323 /**
324 * This is the given touchable area relative to the window frame, or null if none.
325 */
326 final Region mGivenTouchableRegion = new Region();
327
328 /**
329 * Flag indicating whether the touchable region should be adjusted by
330 * the visible insets; if false the area outside the visible insets is
331 * NOT touchable, so we must use those to adjust the frame during hit
332 * tests.
333 */
334 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
335
336 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400337 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700338 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800339 float mHScale=1, mVScale=1;
340 float mLastHScale=1, mLastVScale=1;
341 final Matrix mTmpMatrix = new Matrix();
342
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700343 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800344 final Rect mFrame = new Rect();
345 final Rect mLastFrame = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700346 private boolean mFrameSizeChanged = false;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700347 // Frame that is scaled to the application's coordinate space when in
348 // screen size compatibility mode.
349 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800350
351 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700352
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700353 private final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700354
Wale Ogunwale94596652015-02-06 19:27:34 -0800355 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
356 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700357 final Rect mDisplayFrame = new Rect();
358
359 // The region of the display frame that the display type supports displaying content on. This
360 // is mostly a special case for TV where some displays don’t have the entire display usable.
361 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
362 // window display contents to extend into the overscan region.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700363 private final Rect mOverscanFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700364
365 // The display frame minus the stable insets. This value is always constant regardless of if
366 // the status bar or navigation bar is visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700367 private final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800368
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700369 // The area not occupied by the status and navigation bars. So, if both status and navigation
370 // bars are visible, the decor frame is equal to the stable frame.
371 final Rect mDecorFrame = new Rect();
372
373 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
374 // minus the area occupied by the IME if the IME is present.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700375 private final Rect mContentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700376
377 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
378 // displays hint text.
379 final Rect mVisibleFrame = new Rect();
380
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700381 // Frame that includes dead area outside of the surface but where we want to pretend that it's
382 // possible to draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700383 private final Rect mOutsetFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700384
Jorim Jaggidc249c42015-12-15 14:57:31 -0800385 /**
386 * Usually empty. Set to the task's tempInsetFrame. See
387 *{@link android.app.IActivityManager#resizeDockedStack}.
388 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700389 private final Rect mInsetFrame = new Rect();
Jorim Jaggidc249c42015-12-15 14:57:31 -0800390
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800391 boolean mContentChanged;
392
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800393 // If a window showing a wallpaper: the requested offset for the
394 // wallpaper; if a wallpaper window: the currently applied offset.
395 float mWallpaperX = -1;
396 float mWallpaperY = -1;
397
398 // If a window showing a wallpaper: what fraction of the offset
399 // range corresponds to a full virtual screen.
400 float mWallpaperXStep = -1;
401 float mWallpaperYStep = -1;
402
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700403 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
404 // to its window; if a wallpaper window: not used.
405 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
406 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
407
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800408 // Wallpaper windows: pixels offset based on above variables.
409 int mXOffset;
410 int mYOffset;
411
Craig Mautner2268e7e2012-12-13 15:40:00 -0800412 /**
413 * This is set after IWindowSession.relayout() has been called at
414 * least once for the window. It allows us to detect the situation
415 * where we don't yet have a surface, but should have one soon, so
416 * we can give the window focus before waiting for the relayout.
417 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800418 boolean mRelayoutCalled;
419
Robert Carrfed10072016-05-26 11:48:49 -0700420 boolean mInRelayout;
421
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800422 /**
423 * If the application has called relayout() with changes that can
424 * impact its window's size, we need to perform a layout pass on it
425 * even if it is not currently visible for layout. This is set
426 * when in that case until the layout is done.
427 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800428 boolean mLayoutNeeded;
429
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800430 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800431 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800432
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800433 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800434 boolean mDestroying;
435
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800436 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800437 boolean mRemoveOnExit;
438
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800439 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800440 * Whether the app died while it was visible, if true we might need
441 * to continue to show it until it's restarted.
442 */
443 boolean mAppDied;
444
445 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800446 * Set when the orientation is changing and this window has not yet
447 * been updated for the new orientation.
448 */
Bryce Lee8c3cf382017-07-06 19:47:10 -0700449 private boolean mOrientationChanging;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800450
Dianne Hackborna57c6952013-03-29 14:46:40 -0700451 /**
Robert Carr9c1c3a02017-08-08 12:59:01 -0700452 * Sometimes in addition to the mOrientationChanging
453 * flag we report that the orientation is changing
454 * due to a mismatch in current and reported configuration.
455 *
456 * In the case of timeout we still need to make sure we
457 * leave the orientation changing state though, so we
458 * use this as a special time out escape hatch.
459 */
460 private boolean mOrientationChangeTimedOut;
461
462 /**
Robert Carr237028a2016-07-26 10:39:45 -0700463 * The orientation during the last visible call to relayout. If our
464 * current orientation is different, the window can't be ready
465 * to be shown.
466 */
467 int mLastVisibleLayoutRotation = -1;
468
469 /**
Andrii Kulianb2e37802017-01-11 00:36:44 -0800470 * Set when we need to report the orientation change to client to trigger a relayout.
471 */
472 boolean mReportOrientationChanged;
473
474 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700475 * How long we last kept the screen frozen.
476 */
477 int mLastFreezeDuration;
478
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800479 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800480 boolean mRemoved;
481
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800482 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800483 * It is save to remove the window and destroy the surface because the client requested removal
484 * or some other higher level component said so (e.g. activity manager).
485 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800486 */
Svetoslav Ganov200adfb2016-10-18 13:29:27 -0700487 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800488
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800489 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700490 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800491 InputChannel mInputChannel;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700492 private InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800493
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800494 // Used to improve performance of toString()
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700495 private String mStringNameCache;
496 private CharSequence mLastTitle;
497 private boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800498
Craig Mautnera2c77052012-03-26 12:14:43 -0700499 final WindowStateAnimator mWinAnimator;
500
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700501 boolean mHasSurface = false;
502
Craig Mautner88400d32012-09-30 12:35:45 -0700503 /** When true this window can be displayed on screens owther than mOwnerUid's */
504 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700505
Robert Carr13f7be9e2015-12-02 18:39:45 -0800506 // Whether the window has a saved surface from last pause, which can be
507 // used to start an entering animation earlier.
Chong Zhang92147042016-05-09 12:47:11 -0700508 private boolean mSurfaceSaved = false;
509
Chong Zhang8e4bda92016-05-04 15:08:18 -0700510 // Whether we're performing an entering animation with a saved surface. This flag is
511 // true during the time we're showing a window with a previously saved surface. It's
512 // cleared when surface is destroyed, saved, or re-drawn by the app.
Chong Zhang92147042016-05-09 12:47:11 -0700513 private boolean mAnimatingWithSavedSurface;
514
515 // Whether the window was visible when we set the app to invisible last time. WM uses
516 // this as a hint to restore the surface (if available) for early animation next time
517 // the app is brought visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700518 private boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800519
Robert Carra1eb4392015-12-10 12:43:51 -0800520 // This window will be replaced due to relaunch. This allows window manager
521 // to differentiate between simple removal of a window and replacement. In the latter case it
522 // will preserve the old window until the new one is drawn.
523 boolean mWillReplaceWindow = false;
524 // If true, the replaced window was already requested to be removed.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700525 private boolean mReplacingRemoveRequested = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800526 // Whether the replacement of the window should trigger app transition animation.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700527 private boolean mAnimateReplacingWindow = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800528 // If not null, the window that will be used to replace the old one. This is being set when
529 // the window is added and unset when this window reports its first draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700530 private WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700531 // For the new window in the replacement transition, if we have
532 // requested to replace without animation, then we should
533 // make sure we also don't apply an enter animation for
534 // the new window.
535 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800536 // Whether this window is being moved via the resize API
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700537 private boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800538
Jeff Brownc2932a12014-11-20 18:04:05 -0800539 /**
540 * Wake lock for drawing.
541 * Even though it's slightly more expensive to do so, we will use a separate wake lock
542 * for each app that is requesting to draw while dozing so that we can accurately track
543 * who is preventing the system from suspending.
544 * This lock is only acquired on first use.
545 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700546 private PowerManager.WakeLock mDrawLock;
Jeff Brownc2932a12014-11-20 18:04:05 -0800547
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700548 final private Rect mTmpRect = new Rect();
549
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800550 /**
551 * Whether the window was resized by us while it was gone for layout.
552 */
553 boolean mResizedWhileGone = false;
554
Andrii Kulianeb1d3222016-05-16 15:17:55 -0700555 /** @see #isResizedWhileNotDragResizing(). */
556 private boolean mResizedWhileNotDragResizing;
557
558 /** @see #isResizedWhileNotDragResizingReported(). */
559 private boolean mResizedWhileNotDragResizingReported;
Jorim Jaggif3df0aa2016-04-06 15:56:33 -0700560
Robert Carr6da3cc02016-06-16 15:17:07 -0700561 /**
562 * During seamless rotation we have two phases, first the old window contents
563 * are rotated to look as if they didn't move in the new coordinate system. Then we
564 * have to freeze updates to this layer (to preserve the transformation) until
565 * the resize actually occurs. This is true from when the transformation is set
566 * and false until the transaction to resize is sent.
567 */
568 boolean mSeamlesslyRotated = false;
569
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700570 private static final Region sEmptyRegion = new Region();
571
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700572 /**
Robert Carrc91d1c32017-02-15 19:37:46 -0800573 * Surface insets from the previous call to relayout(), used to track
574 * if we are changing the Surface insets.
575 */
576 final Rect mLastSurfaceInsets = new Rect();
577
578 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700579 * A flag set by the {@link WindowState} parent to indicate that the parent has examined this
580 * {@link WindowState} in its overall drawing context. This book-keeping allows the parent to
581 * make sure all children have been considered.
582 */
583 private boolean mDrawnStateEvaluated;
584
585 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700586 * 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 -0700587 * of z-order and 1 otherwise.
588 */
Griff Hazen51d00d82016-11-22 15:39:24 -0800589 private static final Comparator<WindowState> sWindowSubLayerComparator =
590 new Comparator<WindowState>() {
591 @Override
592 public int compare(WindowState w1, WindowState w2) {
593 final int layer1 = w1.mSubLayer;
594 final int layer2 = w2.mSubLayer;
595 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
596 // We insert the child window into the list ordered by
597 // the sub-layer. For same sub-layers, the negative one
598 // should go below others; the positive one should go
599 // above others.
600 return -1;
601 }
602 return 1;
603 };
604 };
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700605
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800606 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700607 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800608 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800609 mService = service;
610 mSession = s;
611 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800612 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800613 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700614 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700615 mOwnerUid = ownerId;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800616 mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200617 mWindowId = new WindowId(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800618 mAttrs.copyFrom(a);
619 mViewVisibility = viewVisibility;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700620 mPolicy = mService.mPolicy;
621 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800622 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700623 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700624 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700625 if (localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700626 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700627 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800628 try {
629 c.asBinder().linkToDeath(deathRecipient, 0);
630 } catch (RemoteException e) {
631 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700632 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800633 mLayoutAttached = false;
634 mIsImWindow = false;
635 mIsWallpaper = false;
636 mIsFloatingLayer = false;
637 mBaseLayer = 0;
638 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700639 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700640 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800641 return;
642 }
643 mDeathRecipient = deathRecipient;
644
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700645 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800646 // The multiplier here is to reserve space for multiple
647 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800648 mBaseLayer = mPolicy.getWindowLayerLw(parentWindow)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700649 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800650 mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700651 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900652
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700653 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow);
654 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900655
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800656 mLayoutAttached = mAttrs.type !=
657 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700658 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
659 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
660 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800661 } else {
662 // The multiplier here is to reserve space for multiple
663 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800664 mBaseLayer = mPolicy.getWindowLayerLw(this)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700665 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800666 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700667 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800668 mLayoutAttached = false;
669 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
670 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
671 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800672 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700673 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800674
Wale Ogunwale72919d22016-12-08 18:58:50 -0800675 if (mAppToken != null && mAppToken.mShowForAllUsers) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700676 // Windows for apps that can show for all users should also show when the device is
677 // locked.
678 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
Craig Mautner19ab8282014-05-07 10:35:34 -0700679 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800680
Craig Mautner322e4032012-07-13 13:35:20 -0700681 mWinAnimator = new WindowStateAnimator(this);
682 mWinAnimator.mAlpha = a.alpha;
683
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800684 mRequestedWidth = 0;
685 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700686 mLastRequestedWidth = 0;
687 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800688 mXOffset = 0;
689 mYOffset = 0;
690 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800691 mInputWindowHandle = new InputWindowHandle(
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800692 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this, c,
693 getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800694 }
695
696 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700697 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800698 mSession.windowAddedLocked(mAttrs.packageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800699 }
700
Bryce Leed390deb2017-06-22 13:14:28 -0700701 /**
702 * Returns whether this {@link WindowState} has been considered for drawing by its parent.
703 */
Bryce Lee6311c4b2017-07-06 14:09:29 -0700704 boolean getDrawnStateEvaluated() {
Bryce Leed390deb2017-06-22 13:14:28 -0700705 return mDrawnStateEvaluated;
706 }
707
708 /**
709 * Sets whether this {@link WindowState} has been considered for drawing by its parent. Should
710 * be cleared when detached from parent.
711 */
712 void setDrawnStateEvaluated(boolean evaluated) {
713 mDrawnStateEvaluated = evaluated;
714 }
715
716 @Override
717 void onParentSet() {
718 super.onParentSet();
719 setDrawnStateEvaluated(false /*evaluated*/);
720 }
721
Craig Mautnera2c77052012-03-26 12:14:43 -0700722 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800723 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800724 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800725 }
726
727 @Override
728 public String getOwningPackage() {
729 return mAttrs.packageName;
730 }
731
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800732 @Override
733 public boolean canAddInternalSystemWindow() {
734 return mOwnerCanAddInternalSystemWindow;
735 }
736
Jorim Jaggif5834272016-04-04 20:25:41 -0700737 /**
738 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
739 * from {@param frame}. In other words, it applies the insets that would result if
740 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700741 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
742 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700743 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700744 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
745 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
746 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
747 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
748 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700749 frame.inset(left, top, right, bottom);
750 }
751
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800752 @Override
Robert Carr43521762016-10-28 13:15:04 -0700753 public void computeFrameLw(Rect parentFrame, Rect displayFrame, Rect overscanFrame,
754 Rect contentFrame, Rect visibleFrame, Rect decorFrame, Rect stableFrame,
755 Rect outsetFrame) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800756 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700757 // This window is being replaced and either already got information that it's being
758 // removed or we are still waiting for some information. Because of this we don't
759 // want to apply any more changes to it, so it remains in this state until new window
760 // appears.
761 return;
762 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800763 mHaveFrame = true;
764
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700765 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700766 final boolean inFullscreenContainer = inFullscreenContainer();
Robert Carre6275582016-02-29 15:45:45 -0800767 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700768 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800769
Chong Zhangae35fef2016-03-16 15:56:55 -0700770 // If the task has temp inset bounds set, we have to make sure all its windows uses
771 // the temp inset frame. Otherwise different display frames get applied to the main
772 // window and the child window, making them misaligned.
Andrii Kulianc24f3732017-08-08 19:35:17 -0700773 if (inFullscreenContainer || isLetterboxedAppWindow()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700774 mInsetFrame.setEmpty();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700775 } else if (task != null && isInMultiWindowMode()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700776 task.getTempInsetBounds(mInsetFrame);
777 }
778
Jorim Jaggif5834272016-04-04 20:25:41 -0700779 // Denotes the actual frame used to calculate the insets and to perform the layout. When
780 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
781 // insets temporarily. By the notion of a task having a different layout frame, we can
782 // achieve that while still moving the task around.
783 final Rect layoutContainingFrame;
784 final Rect layoutDisplayFrame;
785
786 // The offset from the layout containing frame to the actual containing frame.
787 final int layoutXDiff;
788 final int layoutYDiff;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700789 if (inFullscreenContainer || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800790 // We use the parent frame as the containing frame for fullscreen and child windows
Robert Carr43521762016-10-28 13:15:04 -0700791 mContainingFrame.set(parentFrame);
792 mDisplayFrame.set(displayFrame);
793 layoutDisplayFrame = displayFrame;
794 layoutContainingFrame = parentFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700795 layoutXDiff = 0;
796 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800797 } else {
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700798 getContainerBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100799 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
800
801 // If the bounds are frozen, we still want to translate the window freely and only
802 // freeze the size.
803 Rect frozen = mAppToken.mFrozenBounds.peek();
804 mContainingFrame.right = mContainingFrame.left + frozen.width();
805 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
806 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800807 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700808 // IME is up and obscuring this window. Adjust the window position so it is visible.
809 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this) {
Winson Chungd73e94b2017-05-31 16:25:30 -0700810 final int stackId = getStackId();
811 if (stackId == FREEFORM_WORKSPACE_STACK_ID
812 && mContainingFrame.bottom > contentFrame.bottom) {
813 // In freeform we want to move the top up directly.
814 // TODO: Investigate why this is contentFrame not parentFrame.
815 mContainingFrame.top -= mContainingFrame.bottom - contentFrame.bottom;
816 } else if (stackId != PINNED_STACK_ID
817 && mContainingFrame.bottom > parentFrame.bottom) {
818 // But in docked we want to behave like fullscreen and behave as if the task
819 // were given smaller bounds for the purposes of layout. Skip adjustments for
820 // the pinned stack, they are handled separately in the PinnedStackController.
821 mContainingFrame.bottom = parentFrame.bottom;
822 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700823 }
Skuhne81c524a2015-08-12 13:34:14 -0700824
Robert Carre6275582016-02-29 15:45:45 -0800825 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700826 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
827 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800828 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700829 if (mContainingFrame.isEmpty()) {
Robert Carr43521762016-10-28 13:15:04 -0700830 mContainingFrame.set(contentFrame);
Skuhne81c524a2015-08-12 13:34:14 -0700831 }
Doris Liu06d582d2015-06-01 13:18:43 -0700832 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800833 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700834 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
835 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
836 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700837 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
Robert Carr43521762016-10-28 13:15:04 -0700838 subtractInsets(mDisplayFrame, layoutContainingFrame, displayFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700839 if (!layoutInParentFrame()) {
Robert Carr43521762016-10-28 13:15:04 -0700840 subtractInsets(mContainingFrame, layoutContainingFrame, parentFrame, mTmpRect);
841 subtractInsets(mInsetFrame, layoutContainingFrame, parentFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700842 }
Robert Carr43521762016-10-28 13:15:04 -0700843 layoutDisplayFrame = displayFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700844 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700845 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800846
Craig Mautner967212c2013-04-13 21:10:58 -0700847 final int pw = mContainingFrame.width();
848 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800849
Robert Carr43521762016-10-28 13:15:04 -0700850 if (!mParentFrame.equals(parentFrame)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800851 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Robert Carr43521762016-10-28 13:15:04 -0700852 // + " to " + parentFrame);
853 mParentFrame.set(parentFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800854 mContentChanged = true;
855 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700856 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
857 mLastRequestedWidth = mRequestedWidth;
858 mLastRequestedHeight = mRequestedHeight;
859 mContentChanged = true;
860 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800861
Robert Carr43521762016-10-28 13:15:04 -0700862 mOverscanFrame.set(overscanFrame);
863 mContentFrame.set(contentFrame);
864 mVisibleFrame.set(visibleFrame);
865 mDecorFrame.set(decorFrame);
866 mStableFrame.set(stableFrame);
867 final boolean hasOutsets = outsetFrame != null;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700868 if (hasOutsets) {
Robert Carr43521762016-10-28 13:15:04 -0700869 mOutsetFrame.set(outsetFrame);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700870 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800871
Craig Mautnereda67292013-04-28 13:50:14 -0700872 final int fw = mFrame.width();
873 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800874
Jorim Jaggif5834272016-04-04 20:25:41 -0700875 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
876
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700877 // Calculate the outsets before the content frame gets shrinked to the window frame.
878 if (hasOutsets) {
879 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
880 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
881 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
882 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
883 } else {
884 mOutsets.set(0, 0, 0, 0);
885 }
886
Craig Mautnera248eee2013-05-07 11:41:27 -0700887 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800888 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -0800889 if (windowsAreFloating && !mFrame.isEmpty()) {
Robert Carre65a1c42017-02-28 16:52:59 -0800890 // For pinned workspace the frame isn't limited in any particular
891 // way since SystemUI controls the bounds. For freeform however
892 // we want to keep things inside the content frame.
893 final Rect limitFrame = task.inPinnedWorkspace() ? mFrame : mContentFrame;
Skuhne81c524a2015-08-12 13:34:14 -0700894 // Keep the frame out of the blocked system area, limit it in size to the content area
895 // and make sure that there is always a minimum visible so that the user can drag it
896 // into a usable area..
Robert Carre65a1c42017-02-28 16:52:59 -0800897 final int height = Math.min(mFrame.height(), limitFrame.height());
898 final int width = Math.min(limitFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700899 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +0900900 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
901 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
902 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
903 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Robert Carre65a1c42017-02-28 16:52:59 -0800904 final int top = Math.max(limitFrame.top,
905 Math.min(mFrame.top, limitFrame.bottom - minVisibleHeight));
906 final int left = Math.max(limitFrame.left + minVisibleWidth - width,
907 Math.min(mFrame.left, limitFrame.right - minVisibleWidth));
Skuhne81c524a2015-08-12 13:34:14 -0700908 mFrame.set(left, top, left + width, top + height);
909 mContentFrame.set(mFrame);
910 mVisibleFrame.set(mContentFrame);
911 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700912 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700913 dc.getDockedDividerController().positionDockedStackedDivider(mFrame);
Jorim Jaggi192086e2016-03-11 17:17:03 +0100914 mContentFrame.set(mFrame);
915 if (!mFrame.equals(mLastFrame)) {
916 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800917 }
Skuhne81c524a2015-08-12 13:34:14 -0700918 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -0700919 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
920 Math.max(mContentFrame.top, mFrame.top),
921 Math.min(mContentFrame.right, mFrame.right),
922 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800923
Jorim Jaggi656f6502016-04-11 21:08:17 -0700924 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
925 Math.max(mVisibleFrame.top, mFrame.top),
926 Math.min(mVisibleFrame.right, mFrame.right),
927 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800928
Jorim Jaggi656f6502016-04-11 21:08:17 -0700929 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
930 Math.max(mStableFrame.top, mFrame.top),
931 Math.min(mStableFrame.right, mFrame.right),
932 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700933 }
Adrian Roosfa104232014-06-20 16:10:14 -0700934
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700935 if (inFullscreenContainer && !windowsAreFloating) {
Jorim Jaggi899327f2016-02-25 20:44:18 -0500936 // Windows that are not fullscreen can be positioned outside of the display frame,
937 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -0700938 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
939 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
940 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
941 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800942 }
Craig Mautnereda67292013-04-28 13:50:14 -0700943
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100944 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100945 // For the docked divider, we calculate the stable insets like a full-screen window
946 // so it can use it to calculate the snap positions.
947 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
948 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
949 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
950 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800951
952 // The divider doesn't care about insets in any case, so set it to empty so we don't
953 // trigger a relayout when moving it.
954 mContentInsets.setEmpty();
955 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100956 } else {
Andrii Kuliand9003372016-04-04 17:46:59 -0700957 getDisplayContent().getLogicalDisplayRect(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700958 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
959 // non-fullscreen mode.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700960 boolean overrideRightInset = !windowsAreFloating && !inFullscreenContainer
961 && mFrame.right > mTmpRect.right;
962 boolean overrideBottomInset = !windowsAreFloating && !inFullscreenContainer
963 && mFrame.bottom > mTmpRect.bottom;
Jorim Jaggi656f6502016-04-11 21:08:17 -0700964 mContentInsets.set(mContentFrame.left - mFrame.left,
965 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700966 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700967 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700968 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700969 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800970
Jorim Jaggi656f6502016-04-11 21:08:17 -0700971 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
972 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700973 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700974 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700975 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700976 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800977
Jorim Jaggi656f6502016-04-11 21:08:17 -0700978 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
979 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700980 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700981 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -0700982 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -0700983 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100984 }
Adrian Roosfa104232014-06-20 16:10:14 -0700985
Jorim Jaggi656f6502016-04-11 21:08:17 -0700986 // Offset the actual frame by the amount layout frame is off.
987 mFrame.offset(-layoutXDiff, -layoutYDiff);
988 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -0700989 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
990 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
991 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
992
Craig Mautnereda67292013-04-28 13:50:14 -0700993 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400994 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700995 // If there is a size compatibility scale being applied to the
996 // window, we need to apply this to its insets so that they are
997 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -0700998 mOverscanInsets.scale(mInvGlobalScale);
999 mContentInsets.scale(mInvGlobalScale);
1000 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -07001001 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001002 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001003
1004 // Also the scaled frame that we report to the app needs to be
1005 // adjusted to be in its coordinate space.
1006 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001007 }
1008
Craig Mautnereda67292013-04-28 13:50:14 -07001009 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001010 final DisplayContent displayContent = getDisplayContent();
1011 if (displayContent != null) {
1012 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwale0303c572016-10-20 10:16:29 -07001013 getDisplayContent().mWallpaperController.updateWallpaperOffset(
Wale Ogunwalee8069dc2015-08-18 09:52:01 -07001014 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001015 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001016 }
1017
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001018 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001019 "Resolving (mRequestedWidth="
1020 + mRequestedWidth + ", mRequestedheight="
1021 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
1022 + "): frame=" + mFrame.toShortString()
1023 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07001024 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -07001025 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001026 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001027 }
1028
Craig Mautnera2c77052012-03-26 12:14:43 -07001029 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001030 public Rect getFrameLw() {
1031 return mFrame;
1032 }
1033
Craig Mautnera2c77052012-03-26 12:14:43 -07001034 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001035 public Point getShownPositionLw() {
1036 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001037 }
1038
Craig Mautnera2c77052012-03-26 12:14:43 -07001039 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001040 public Rect getDisplayFrameLw() {
1041 return mDisplayFrame;
1042 }
1043
Craig Mautnera2c77052012-03-26 12:14:43 -07001044 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001045 public Rect getOverscanFrameLw() {
1046 return mOverscanFrame;
1047 }
1048
1049 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001050 public Rect getContentFrameLw() {
1051 return mContentFrame;
1052 }
1053
Craig Mautnera2c77052012-03-26 12:14:43 -07001054 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001055 public Rect getVisibleFrameLw() {
1056 return mVisibleFrame;
1057 }
1058
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001059 Rect getStableFrameLw() {
1060 return mStableFrame;
1061 }
1062
Craig Mautnera2c77052012-03-26 12:14:43 -07001063 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001064 public boolean getGivenInsetsPendingLw() {
1065 return mGivenInsetsPending;
1066 }
1067
Craig Mautnera2c77052012-03-26 12:14:43 -07001068 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001069 public Rect getGivenContentInsetsLw() {
1070 return mGivenContentInsets;
1071 }
1072
Craig Mautnera2c77052012-03-26 12:14:43 -07001073 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001074 public Rect getGivenVisibleInsetsLw() {
1075 return mGivenVisibleInsets;
1076 }
1077
Craig Mautnera2c77052012-03-26 12:14:43 -07001078 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001079 public WindowManager.LayoutParams getAttrs() {
1080 return mAttrs;
1081 }
1082
Craig Mautner812d2ca2012-09-27 15:35:34 -07001083 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001084 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001085 return getDisplayContent().getNeedsMenu(this, bottom);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001086 }
1087
Craig Mautner19d59bc2012-09-04 11:15:56 -07001088 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001089 public int getSystemUiVisibility() {
1090 return mSystemUiVisibility;
1091 }
1092
Craig Mautner19d59bc2012-09-04 11:15:56 -07001093 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001094 public int getSurfaceLayer() {
1095 return mLayer;
1096 }
1097
Craig Mautner812d2ca2012-09-27 15:35:34 -07001098 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001099 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001100 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001101 }
1102
1103 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001104 public IApplicationToken getAppToken() {
1105 return mAppToken != null ? mAppToken.appToken : null;
1106 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001107
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001108 @Override
1109 public boolean isVoiceInteraction() {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001110 return mAppToken != null && mAppToken.mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001111 }
1112
Robert Carr31aa98b2016-07-20 15:29:03 -07001113 boolean setReportResizeHints() {
Craig Mautner4c5eb222013-11-18 12:59:05 -08001114 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1115 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1116 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001117 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001118 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
Robert Carr31aa98b2016-07-20 15:29:03 -07001119 mFrameSizeChanged |= (mLastFrame.width() != mFrame.width()) ||
1120 (mLastFrame.height() != mFrame.height());
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001121 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
Robert Carr31aa98b2016-07-20 15:29:03 -07001122 || mOutsetsChanged || mFrameSizeChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001123 }
1124
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001125 /**
1126 * Adds the window to the resizing list if any of the parameters we use to track the window
1127 * dimensions or insets have changed.
1128 */
1129 void updateResizingWindowIfNeeded() {
1130 final WindowStateAnimator winAnimator = mWinAnimator;
1131 if (!mHasSurface || mService.mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
1132 return;
1133 }
1134
1135 final Task task = getTask();
1136 // In the case of stack bound animations, the window frames will update (unlike other
1137 // animations which just modify various transformation properties). We don't want to
1138 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1139 // the frame may not correspond to the surface size or the onscreen area at various
1140 // phases in the animation, and the client will become sad and confused.
Winson Chung40a5f932017-04-13 16:39:36 -07001141 if (task != null && task.mStack.isAnimatingBounds()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001142 return;
1143 }
1144
1145 setReportResizeHints();
1146 boolean configChanged = isConfigChanged();
1147 if (DEBUG_CONFIGURATION && configChanged) {
1148 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1149 }
1150
1151 final boolean dragResizingChanged = isDragResizeChanged()
1152 && !isDragResizingChangeReported();
1153
1154 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
1155 + " dragResizingChanged=" + dragResizingChanged + " last=" + mLastFrame
1156 + " frame=" + mFrame);
1157
1158 // We update mLastFrame always rather than in the conditional with the last inset
1159 // variables, because mFrameSizeChanged only tracks the width and height changing.
1160 mLastFrame.set(mFrame);
1161
1162 if (mContentInsetsChanged
1163 || mVisibleInsetsChanged
1164 || winAnimator.mSurfaceResized
1165 || mOutsetsChanged
1166 || mFrameSizeChanged
1167 || configChanged
1168 || dragResizingChanged
Andrii Kulianb2e37802017-01-11 00:36:44 -08001169 || !isResizedWhileNotDragResizingReported()
1170 || mReportOrientationChanged) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001171 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1172 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
1173 + " contentInsetsChanged=" + mContentInsetsChanged
1174 + " " + mContentInsets.toShortString()
1175 + " visibleInsetsChanged=" + mVisibleInsetsChanged
1176 + " " + mVisibleInsets.toShortString()
1177 + " stableInsetsChanged=" + mStableInsetsChanged
1178 + " " + mStableInsets.toShortString()
1179 + " outsetsChanged=" + mOutsetsChanged
1180 + " " + mOutsets.toShortString()
1181 + " surfaceResized=" + winAnimator.mSurfaceResized
1182 + " configChanged=" + configChanged
1183 + " dragResizingChanged=" + dragResizingChanged
1184 + " resizedWhileNotDragResizingReported="
Andrii Kulianb2e37802017-01-11 00:36:44 -08001185 + isResizedWhileNotDragResizingReported()
1186 + " reportOrientationChanged=" + mReportOrientationChanged);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001187 }
1188
1189 // If it's a dead window left on screen, and the configuration changed, there is nothing
1190 // we can do about it. Remove the window now.
1191 if (mAppToken != null && mAppDied) {
1192 mAppToken.removeDeadWindows();
1193 return;
1194 }
1195
Jorim Jaggidc9385a2017-05-13 02:00:31 +02001196 updateLastInsetValues();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001197 mService.makeWindowFreezingScreenIfNeededLocked(this);
1198
1199 // If the orientation is changing, or we're starting or ending a drag resizing action,
1200 // then we need to hold off on unfreezing the display until this window has been
1201 // redrawn; to do that, we need to go through the process of getting informed by the
1202 // application when it has finished drawing.
Bryce Lee8c3cf382017-07-06 19:47:10 -07001203 if (getOrientationChanging() || dragResizingChanged
1204 || isResizedWhileNotDragResizing()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001205 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
1206 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1207 + ", mDrawState=DRAW_PENDING in " + this
1208 + ", surfaceController " + winAnimator.mSurfaceController);
1209 }
1210 winAnimator.mDrawState = DRAW_PENDING;
1211 if (mAppToken != null) {
1212 mAppToken.clearAllDrawn();
1213 }
1214 }
1215 if (!mService.mResizingWindows.contains(this)) {
1216 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
1217 mService.mResizingWindows.add(this);
1218 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07001219 } else if (getOrientationChanging()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001220 if (isDrawnLw()) {
1221 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1222 + this + ", surfaceController " + winAnimator.mSurfaceController);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001223 setOrientationChanging(false);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001224 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1225 - mService.mDisplayFreezeTime);
1226 }
1227 }
1228 }
1229
Bryce Lee8c3cf382017-07-06 19:47:10 -07001230 boolean getOrientationChanging() {
1231 // In addition to the local state flag, we must also consider the difference in the last
1232 // reported configuration vs. the current state. If the client code has not been informed of
1233 // the change, logic dependent on having finished processing the orientation, such as
1234 // unfreezing, could be improperly triggered.
1235 // TODO(b/62846907): Checking against {@link mLastReportedConfiguration} could be flaky as
1236 // this is not necessarily what the client has processed yet. Find a
1237 // better indicator consistent with the client.
Robert Carr926643f2017-08-02 12:01:12 -07001238 return (mOrientationChanging || (isVisible()
1239 && getConfiguration().orientation != mLastReportedConfiguration.orientation))
Robert Carr9c1c3a02017-08-08 12:59:01 -07001240 && !mSeamlesslyRotated
1241 && !mOrientationChangeTimedOut;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001242 }
1243
1244 void setOrientationChanging(boolean changing) {
1245 mOrientationChanging = changing;
Robert Carr9c1c3a02017-08-08 12:59:01 -07001246 mOrientationChangeTimedOut = false;
1247 }
1248
1249 void orientationChangeTimedOut() {
1250 mOrientationChangeTimedOut = true;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001251 }
1252
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001253 DisplayContent getDisplayContent() {
1254 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001255 }
1256
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001257 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001258 final DisplayContent displayContent = getDisplayContent();
1259 return displayContent != null ? displayContent.getDisplayInfo() : null;
1260 }
1261
Jorim Jaggife762342016-10-13 14:33:27 +02001262 @Override
1263 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001264 final DisplayContent displayContent = getDisplayContent();
1265 if (displayContent == null) {
1266 return -1;
1267 }
1268 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001269 }
1270
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001271 Task getTask() {
Bryce Lee6d410262017-02-28 15:30:17 -08001272 return mAppToken != null ? mAppToken.getTask() : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001273 }
1274
1275 TaskStack getStack() {
1276 Task task = getTask();
1277 if (task != null) {
1278 if (task.mStack != null) {
1279 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001280 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001281 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001282 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1283 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001284 final DisplayContent dc = getDisplayContent();
1285 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001286 }
1287
Skuhnef932e562015-08-20 12:07:30 -07001288 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001289 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001290 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001291 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001292 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001293 final Task task = getTask();
1294 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001295 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001296 mTmpRect.setEmpty();
1297 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001298 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001299 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001300 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001301 } else {
1302 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001303 }
1304 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001305
Chong Zhang9184ec62015-09-24 12:32:21 -07001306 bounds.set(mVisibleFrame);
1307 if (intersectWithStackBounds) {
1308 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001309 }
1310
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001311 if (bounds.isEmpty()) {
1312 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001313 if (intersectWithStackBounds) {
1314 bounds.intersect(mTmpRect);
1315 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001316 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001317 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001318 }
1319
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001320 public long getInputDispatchingTimeoutNanos() {
1321 return mAppToken != null
Wale Ogunwale72919d22016-12-08 18:58:50 -08001322 ? mAppToken.mInputDispatchingTimeoutNanos
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001323 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1324 }
1325
Craig Mautnere8552142012-11-07 13:55:47 -08001326 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001327 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001328 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001329 }
1330
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001331 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1332 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1333 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1334 if (dtdx < -.000001f || dtdx > .000001f) return false;
1335 if (dsdy < -.000001f || dsdy > .000001f) return false;
1336 return true;
1337 }
1338
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001339 void prelayout() {
1340 if (mEnforceSizeCompat) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001341 mGlobalScale = getDisplayContent().mCompatibleScreenScale;
1342 mInvGlobalScale = 1 / mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001343 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001344 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001345 }
1346 }
1347
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001348 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001349 boolean hasContentToDisplay() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001350 // If we're animating with a saved surface, we're already visible.
1351 // Return true so that the alpha doesn't get cleared.
1352 if (!mAppFreezing && isDrawnLw()
1353 && (mViewVisibility == View.VISIBLE || isAnimatingWithSavedSurface()
1354 || (mWinAnimator.isAnimationSet() && !mService.mAppTransition.isTransitionSet()))) {
1355 return true;
1356 }
1357
Wale Ogunwale44f21802016-09-02 12:49:48 -07001358 return super.hasContentToDisplay();
1359 }
1360
1361 @Override
1362 boolean isVisible() {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001363 return wouldBeVisibleIfPolicyIgnored() && mPolicyVisibility;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001364 }
1365
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001366 /**
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001367 * @return True if the window would be visible if we'd ignore policy visibility, false
1368 * otherwise.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001369 */
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001370 boolean wouldBeVisibleIfPolicyIgnored() {
Jorim Jaggi43530c92017-05-18 01:53:56 +02001371 return mHasSurface && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001372 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001373 }
1374
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001375 @Override
1376 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001377 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001378 }
1379
1380 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001381 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1382 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001383 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001384 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1385 boolean isWinVisibleLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001386 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.mAppAnimator.animating)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001387 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001388 }
1389
1390 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001391 * The same as isVisible(), but follows the current hidden state of the associated app token,
1392 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001393 */
1394 boolean isVisibleNow() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001395 return (!mToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001396 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001397 }
1398
1399 /**
1400 * Can this window possibly be a drag/drop target? The test here is
1401 * a combination of the above "visible now" with the check that the
1402 * Input Manager uses when discarding windows from input consideration.
1403 */
1404 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001405 return isVisibleNow() && !mRemoved
1406 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001407 }
1408
1409 /**
1410 * Same as isVisible(), but we also count it as visible between the
1411 * call to IWindowSession.add() and the first relayout().
1412 */
1413 boolean isVisibleOrAdding() {
1414 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001415 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001416 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001417 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001418 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001419 }
1420
1421 /**
1422 * Is this window currently on-screen? It is on-screen either if it
1423 * is visible or it is currently running an animation before no longer
1424 * being visible.
1425 */
1426 boolean isOnScreen() {
Jorim Jaggiaf221d12016-11-15 14:59:57 -08001427 if (!mHasSurface || mDestroying || !mPolicyVisibility) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001428 return false;
1429 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001430 final AppWindowToken atoken = mAppToken;
1431 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001432 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001433 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001434 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07001435 return !isParentWindowHidden() || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001436 }
1437
1438 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001439 * Whether this window's drawn state might affect the drawn states of the app token.
1440 *
1441 * @param visibleOnly Whether we should consider only the windows that's currently
1442 * visible in layout. If true, windows that has not relayout to VISIBLE
1443 * would always return false.
1444 *
1445 * @return true if the window should be considered while evaluating allDrawn flags.
1446 */
1447 boolean mightAffectAllDrawn(boolean visibleOnly) {
Wale Ogunwale89973222017-04-23 18:39:45 -07001448 final boolean isViewVisible = (mAppToken == null || !mAppToken.isClientHidden())
Chong Zhange292eb32016-05-21 09:23:55 -07001449 && (mViewVisibility == View.VISIBLE) && !mWindowRemovalAllowed;
Jorim Jaggib0d27342016-11-01 16:10:42 -07001450 return (isOnScreen() && (!visibleOnly || isViewVisible)
Chong Zhangfea963e2016-08-15 17:14:16 -07001451 || mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1452 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION)
Chong Zhang8e4bda92016-05-04 15:08:18 -07001453 && !mAnimatingExit && !mDestroying;
1454 }
1455
1456 /**
1457 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1458 * it must be drawn before allDrawn can become true.
1459 */
1460 boolean isInteresting() {
1461 return mAppToken != null && !mAppDied
1462 && (!mAppToken.mAppAnimator.freezingScreen || !mAppFreezing);
1463 }
1464
1465 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001466 * Like isOnScreen(), but we don't return true if the window is part
1467 * of a transition that has not yet been started.
1468 */
1469 boolean isReadyForDisplay() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001470 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001471 return false;
1472 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001473 return mHasSurface && mPolicyVisibility && !mDestroying
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001474 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001475 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001476 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001477 }
1478
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001479 // TODO: Another visibility method that was added late in the release to minimize risk.
1480 @Override
1481 public boolean canAffectSystemUiFlags() {
1482 final boolean shown = mWinAnimator.getShown();
Jorim Jaggic0c93242017-08-04 16:05:02 +02001483
1484 // We only consider the app to be exiting when the animation has started. After the app
1485 // transition is executed the windows are marked exiting before the new windows have been
1486 // shown. Thus, wait considering a window to be exiting after the animation has actually
1487 // started.
1488 final boolean appAnimationStarting = mAppToken != null
1489 && mAppToken.mAppAnimator.isAnimationStarting();
1490 final boolean exitingSelf = mAnimatingExit && (!mWinAnimator.isAnimationStarting()
1491 && !appAnimationStarting);
1492 final boolean appExiting = mAppToken != null && mAppToken.hidden && !appAnimationStarting;
1493
1494 final boolean exiting = exitingSelf || mDestroying || appExiting;
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001495 final boolean translucent = mAttrs.alpha == 0.0f;
1496 return shown && !exiting && !translucent;
1497 }
1498
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001499 /**
1500 * Like isOnScreen, but returns false if the surface hasn't yet
1501 * been drawn.
1502 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001503 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001504 public boolean isDisplayedLw() {
1505 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001506 return isDrawnLw() && mPolicyVisibility
Wale Ogunwale9d147902016-07-16 11:58:55 -07001507 && ((!isParentWindowHidden() &&
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001508 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001509 || mWinAnimator.mAnimating
1510 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001511 }
1512
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001513 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001514 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001515 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001516 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001517 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001518 return mWinAnimator.mAnimation != null
1519 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001520 }
1521
Craig Mautner812d2ca2012-09-27 15:35:34 -07001522 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001523 public boolean isGoneForLayoutLw() {
1524 final AppWindowToken atoken = mAppToken;
1525 return mViewVisibility == View.GONE
1526 || !mRelayoutCalled
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001527 || (atoken == null && mToken.hidden)
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001528 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001529 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001530 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001531 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001532 }
1533
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001534 /**
1535 * Returns true if the window has a surface that it has drawn a
1536 * complete UI in to.
1537 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001538 public boolean isDrawFinishedLw() {
1539 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001540 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1541 || mWinAnimator.mDrawState == READY_TO_SHOW
1542 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001543 }
1544
1545 /**
1546 * Returns true if the window has a surface that it has drawn a
1547 * complete UI in to.
1548 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001549 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001550 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001551 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001552 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001553 }
1554
1555 /**
1556 * Return true if the window is opaque and fully drawn. This indicates
1557 * it may obscure windows behind it.
1558 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001559 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001560 // When there is keyguard, wallpaper could be placed over the secure app
1561 // window but invisible. We need to check wallpaper visibility explicitly
1562 // to determine if it's occluding apps.
1563 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1564 || (mIsWallpaper && mWallpaperVisible))
Craig Mautnera2c77052012-03-26 12:14:43 -07001565 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001566 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001567 }
1568
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001569 @Override
1570 void onMovedByResize() {
1571 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001572 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001573 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001574 }
1575
1576 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1577 boolean changed = false;
1578
1579 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001580 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001581 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1582 }
1583
1584 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1585 // Starting window that's exiting will be removed when the animation finishes.
1586 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1587 // to actually remove it.
1588 if (!visible && isVisibleNow() && mAppToken.mAppAnimator.isAnimating()) {
1589 mAnimatingExit = true;
1590 mRemoveOnExit = true;
1591 mWindowRemovalAllowed = true;
1592 }
1593 return changed;
1594 }
1595
Robert Carrd5c7dd62017-03-08 10:39:30 -08001596 // Next up we will notify the client that it's visibility has changed.
1597 // We need to prevent it from destroying child surfaces until
1598 // the animation has finished.
1599 if (!visible && isVisibleNow()) {
1600 mWinAnimator.detachChildren();
1601 }
1602
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001603 if (visible != isVisibleNow()) {
1604 if (!runningAppAnimation) {
1605 final AccessibilityController accessibilityController =
1606 mService.mAccessibilityController;
1607 final int winTransit = visible ? TRANSIT_ENTER : TRANSIT_EXIT;
1608 mWinAnimator.applyAnimationLocked(winTransit, visible);
1609 //TODO (multidisplay): Magnification is supported only for the default
1610 if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
1611 accessibilityController.onWindowTransitionLocked(this, winTransit);
1612 }
1613 }
1614 changed = true;
1615 setDisplayLayoutNeeded();
1616 }
1617
1618 return changed;
1619 }
1620
1621 boolean onSetAppExiting() {
1622 final DisplayContent displayContent = getDisplayContent();
1623 boolean changed = false;
1624
1625 if (isVisibleNow()) {
1626 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
1627 //TODO (multidisplay): Magnification is supported only for the default
1628 if (mService.mAccessibilityController != null && isDefaultDisplay()) {
1629 mService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
1630 }
1631 changed = true;
1632 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001633 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001634 }
1635 }
1636
1637 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001638 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001639 changed |= c.onSetAppExiting();
1640 }
1641
1642 return changed;
1643 }
1644
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001645 @Override
1646 void onResize() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001647 // Some windows won't go through the resizing process, if they don't have a surface, so
1648 // destroy all saved surfaces here.
1649 destroySavedSurface();
1650
1651 final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
1652 if (mHasSurface && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001653 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001654 resizingWindows.add(this);
1655
1656 // If we are not drag resizing, force recreating of a new surface so updating
1657 // the content and positioning that surface will be in sync.
1658 //
1659 // As we use this flag as a hint to freeze surface boundary updates, we'd like to only
1660 // apply this to TYPE_BASE_APPLICATION, windows of TYPE_APPLICATION like dialogs, could
1661 // appear to not be drag resizing while they resize, but we'd still like to manipulate
1662 // their frame to update crop, etc...
1663 //
1664 // Anyway we don't need to synchronize position and content updates for these
1665 // windows since they aren't at the base layer and could be moved around anyway.
1666 if (!computeDragResizing() && mAttrs.type == TYPE_BASE_APPLICATION &&
Robert Carr8f0a3ad2017-02-15 19:30:28 -08001667 !mWinAnimator.isForceScaled() && !isGoneForLayoutLw() &&
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001668 !getTask().inPinnedWorkspace()) {
1669 setResizedWhileNotDragResizing(true);
1670 }
1671 }
1672 if (isGoneForLayoutLw()) {
1673 mResizedWhileGone = true;
1674 }
1675
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001676 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001677 }
1678
1679 void onUnfreezeBounds() {
1680 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001681 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001682 c.onUnfreezeBounds();
1683 }
1684
1685 if (!mHasSurface) {
1686 return;
1687 }
1688
1689 mLayoutNeeded = true;
1690 setDisplayLayoutNeeded();
1691 if (!mService.mResizingWindows.contains(this)) {
1692 mService.mResizingWindows.add(this);
1693 }
1694 }
1695
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001696 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001697 * If the window has moved due to its containing content frame changing, then notify the
1698 * listeners and optionally animate it. Simply checking a change of position is not enough,
1699 * because being move due to dock divider is not a trigger for animation.
1700 */
1701 void handleWindowMovedIfNeeded() {
1702 if (!hasMoved()) {
1703 return;
1704 }
1705
1706 // Frame has moved, containing content frame has also moved, and we're not currently
1707 // animating... let's do something.
1708 final int left = mFrame.left;
1709 final int top = mFrame.top;
1710 final Task task = getTask();
1711 final boolean adjustedForMinimizedDockOrIme = task != null
1712 && (task.mStack.isAdjustedForMinimizedDockedStack()
1713 || task.mStack.isAdjustedForIme());
Adrian Roose94c15c2017-05-09 13:17:54 -07001714 if (mService.okToAnimate()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001715 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1716 && !isDragResizing() && !adjustedForMinimizedDockOrIme
1717 && (task == null || getTask().mStack.hasMovementAnimations())
1718 && !mWinAnimator.mLastHidden) {
1719 mWinAnimator.setMoveAnimation(left, top);
1720 }
1721
1722 //TODO (multidisplay): Accessibility supported only for the default display.
1723 if (mService.mAccessibilityController != null
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001724 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001725 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
1726 }
1727
1728 try {
1729 mClient.moved(left, top);
1730 } catch (RemoteException e) {
1731 }
1732 mMovedByResize = false;
1733 }
1734
1735 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001736 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001737 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1738 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001739 private boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001740 return mHasSurface && (mContentChanged || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001741 && !mAnimatingExit
Chong Zhangbd0d9372015-12-28 15:18:29 -08001742 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001743 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001744 }
1745
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001746 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001747 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001748 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001749 return false;
1750 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001751 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001752 }
1753
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001754 boolean fillsDisplay() {
1755 final DisplayInfo displayInfo = getDisplayInfo();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001756 return mFrame.left <= 0 && mFrame.top <= 0
1757 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001758 }
1759
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001760 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001761 boolean isConfigChanged() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001762 return !mLastReportedConfiguration.equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001763 }
1764
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001765 void onWindowReplacementTimeout() {
1766 if (mWillReplaceWindow) {
1767 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001768 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001769 // delays removal on certain conditions, which will leave the stale window in the
1770 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1771 //
1772 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001773 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001774 } else {
1775 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001776 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001777 c.onWindowReplacementTimeout();
1778 }
1779 }
1780 }
1781
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001782 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001783 void forceWindowsScaleableInTransaction(boolean force) {
1784 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1785 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1786 }
1787
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001788 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001789 }
1790
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001791 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001792 void removeImmediately() {
1793 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001794
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001795 if (mRemoved) {
1796 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001797 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1798 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001799 return;
1800 }
1801
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001802 mRemoved = true;
1803
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001804 mWillReplaceWindow = false;
1805 if (mReplacementWindow != null) {
1806 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1807 }
1808
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001809 final DisplayContent dc = getDisplayContent();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001810 if (mService.mInputMethodTarget == this) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001811 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001812 }
1813
1814 final int type = mAttrs.type;
1815 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001816 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001817 }
1818 mPolicy.removeWindowLw(this);
1819
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001820 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001821
Craig Mautner96868332012-12-04 14:29:11 -08001822 mWinAnimator.destroyDeferredSurfaceLocked();
1823 mWinAnimator.destroySurfaceLocked();
Wale Ogunwale943002b2017-02-15 19:34:01 -08001824 mSession.windowRemovedLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001825 try {
1826 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1827 } catch (RuntimeException e) {
1828 // Ignore if it has already been removed (usually because
1829 // we are doing this as part of processing a death note.)
1830 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001831
1832 mService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001833 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001834
Wale Ogunwale571771c2016-08-26 13:18:50 -07001835 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001836 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001837 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001838 removeIfPossible(false /*keepVisibleDeadWindow*/);
1839 }
1840
Wale Ogunwale571771c2016-08-26 13:18:50 -07001841 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001842 mWindowRemovalAllowed = true;
1843 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1844 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1845
1846 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1847 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1848 "Starting window removed " + this);
1849
1850 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && this == mService.mCurrentFocus)
1851 Slog.v(TAG_WM, "Remove " + this + " client="
1852 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1853 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1854 + Debug.getCallers(5));
1855
1856 final long origId = Binder.clearCallingIdentity();
1857
1858 disposeInputChannel();
1859
1860 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1861 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1862 + " mAnimatingExit=" + mAnimatingExit
1863 + " mRemoveOnExit=" + mRemoveOnExit
1864 + " mHasSurface=" + mHasSurface
1865 + " surfaceShowing=" + mWinAnimator.getShown()
1866 + " isAnimationSet=" + mWinAnimator.isAnimationSet()
1867 + " app-animation="
1868 + (mAppToken != null ? mAppToken.mAppAnimator.animation : null)
1869 + " mWillReplaceWindow=" + mWillReplaceWindow
1870 + " inPendingTransaction="
1871 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
1872 + " mDisplayFrozen=" + mService.mDisplayFrozen
1873 + " callers=" + Debug.getCallers(6));
1874
1875 // Visibility of the removed window. Will be used later to update orientation later on.
1876 boolean wasVisible = false;
1877
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001878 final int displayId = getDisplayId();
1879
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001880 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1881 // window until the animation is done. If the display is frozen, just remove immediately,
1882 // since the animation wouldn't be seen.
Adrian Roose94c15c2017-05-09 13:17:54 -07001883 if (mHasSurface && mService.okToAnimate()) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001884 if (mWillReplaceWindow) {
1885 // This window is going to be replaced. We need to keep it around until the new one
1886 // gets added, then we will get rid of this one.
1887 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1888 "Preserving " + this + " until the new one is " + "added");
1889 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1890 // been removed. We probably need another flag to indicate that window removal
1891 // should be deffered vs. overloading the flag that says we are playing an exit
1892 // animation.
1893 mAnimatingExit = true;
1894 mReplacingRemoveRequested = true;
1895 Binder.restoreCallingIdentity(origId);
1896 return;
1897 }
1898
1899 if (isAnimatingWithSavedSurface() && !mAppToken.allDrawnExcludingSaved) {
1900 // We started enter animation early with a saved surface, now the app asks to remove
1901 // this window. If we remove it now and the app is not yet drawn, we'll show a
1902 // flicker. Delay the removal now until it's really drawn.
1903 if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM,
1904 "removeWindowLocked: delay removal of " + this + " due to early animation");
1905 // Do not set mAnimatingExit to true here, it will cause the surface to be hidden
1906 // immediately after the enter animation is done. If the app is not yet drawn then
1907 // it will show up as a flicker.
1908 setupWindowForRemoveOnExit();
1909 Binder.restoreCallingIdentity(origId);
1910 return;
1911 }
1912 // If we are not currently running the exit animation, we need to see about starting one
1913 wasVisible = isWinVisibleLw();
1914
1915 if (keepVisibleDeadWindow) {
1916 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1917 "Not removing " + this + " because app died while it's visible");
1918
1919 mAppDied = true;
1920 setDisplayLayoutNeeded();
1921 mService.mWindowPlacerLocked.performSurfacePlacement();
1922
1923 // Set up a replacement input channel since the app is now dead.
1924 // We need to catch tapping on the dead window to restart the app.
1925 openInputChannel(null);
1926 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
1927
1928 Binder.restoreCallingIdentity(origId);
1929 return;
1930 }
1931
1932 if (wasVisible) {
1933 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
1934
1935 // Try starting an animation.
1936 if (mWinAnimator.applyAnimationLocked(transit, false)) {
1937 mAnimatingExit = true;
1938 }
1939 //TODO (multidisplay): Magnification is supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001940 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001941 mService.mAccessibilityController.onWindowTransitionLocked(this, transit);
1942 }
1943 }
1944 final boolean isAnimating =
1945 mWinAnimator.isAnimationSet() && !mWinAnimator.isDummyAnimation();
1946 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001947 && mAppToken.isLastWindow(this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001948 // We delay the removal of a window if it has a showing surface that can be used to run
1949 // exit animation and it is marked as exiting.
1950 // Also, If isn't the an animating starting window that is the last window in the app.
1951 // We allow the removal of the non-animating starting window now as there is no
1952 // additional window or animation that will trigger its removal.
1953 if (mWinAnimator.getShown() && mAnimatingExit
1954 && (!lastWindowIsStartingWindow || isAnimating)) {
1955 // The exit animation is running or should run... wait for it!
1956 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1957 "Not removing " + this + " due to exit animation ");
1958 setupWindowForRemoveOnExit();
1959 if (mAppToken != null) {
1960 mAppToken.updateReportedVisibilityLocked();
1961 }
1962 Binder.restoreCallingIdentity(origId);
1963 return;
1964 }
1965 }
1966
Wale Ogunwale571771c2016-08-26 13:18:50 -07001967 removeImmediately();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001968 // Removing a visible window will effect the computed orientation
1969 // So just update orientation if needed.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001970 if (wasVisible && mService.updateOrientationFromAppTokensLocked(false, displayId)) {
1971 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001972 }
1973 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
1974 Binder.restoreCallingIdentity(origId);
1975 }
1976
1977 private void setupWindowForRemoveOnExit() {
1978 mRemoveOnExit = true;
1979 setDisplayLayoutNeeded();
1980 // Request a focus update as this window's input channel is already gone. Otherwise
1981 // we could have no focused window in input manager.
1982 final boolean focusChanged = mService.updateFocusedWindowLocked(
1983 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
1984 mService.mWindowPlacerLocked.performSurfacePlacement();
1985 if (focusChanged) {
1986 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
1987 }
1988 }
1989
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001990 void setHasSurface(boolean hasSurface) {
1991 mHasSurface = hasSurface;
1992 }
1993
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08001994 int getAnimLayerAdjustment() {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -08001995 if (mIsImWindow && mService.mInputMethodTarget != null) {
Wale Ogunwale455fac52016-07-21 07:24:49 -07001996 final AppWindowToken appToken = mService.mInputMethodTarget.mAppToken;
1997 if (appToken != null) {
Robert Carrdee1b3f2017-02-27 11:33:33 -08001998 return appToken.getAnimLayerAdjustment();
Wale Ogunwale455fac52016-07-21 07:24:49 -07001999 }
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002000 }
Wale Ogunwale455fac52016-07-21 07:24:49 -07002001
Robert Carrdee1b3f2017-02-27 11:33:33 -08002002 return mToken.getAnimLayerAdjustment();
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002003 }
2004
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002005 int getSpecialWindowAnimLayerAdjustment() {
2006 int specialAdjustment = 0;
2007 if (mIsImWindow) {
2008 specialAdjustment = getDisplayContent().mInputMethodAnimLayerAdjustment;
2009 } else if (mIsWallpaper) {
Wale Ogunwale0303c572016-10-20 10:16:29 -07002010 specialAdjustment = getDisplayContent().mWallpaperController.getAnimLayerAdjustment();
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002011 }
2012
2013 return mLayer + specialAdjustment;
2014 }
2015
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002016 boolean canBeImeTarget() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002017 if (mIsImWindow) {
2018 // IME windows can't be IME targets. IME targets are required to be below the IME
2019 // windows and that wouldn't be possible if the IME window is its own target...silly.
2020 return false;
2021 }
2022
Winson Chung3d0a74a2017-07-12 12:37:19 -07002023 final boolean windowsAreFocusable = mAppToken == null || mAppToken.windowsAreFocusable();
Winson Chungb1549342017-07-11 09:59:56 -07002024 if (!windowsAreFocusable) {
2025 // This window can't be an IME target if the app's windows should not be focusable.
2026 return false;
2027 }
2028
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002029 final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002030 final int type = mAttrs.type;
2031
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002032 // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are set or
2033 // both are cleared...and not a starting window.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002034 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
2035 && type != TYPE_APPLICATION_STARTING) {
2036 return false;
2037 }
2038
2039 if (DEBUG_INPUT_METHOD) {
2040 Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding());
2041 if (!isVisibleOrAdding()) {
2042 Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController
2043 + " relayoutCalled=" + mRelayoutCalled
2044 + " viewVis=" + mViewVisibility
2045 + " policyVis=" + mPolicyVisibility
2046 + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim
2047 + " parentHidden=" + isParentWindowHidden()
2048 + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
2049 if (mAppToken != null) {
2050 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + mAppToken.hiddenRequested);
2051 }
2052 }
2053 }
2054 return isVisibleOrAdding();
2055 }
2056
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002057 void scheduleAnimationIfDimming() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002058 final DisplayContent dc = getDisplayContent();
2059 if (dc == null) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002060 return;
2061 }
Jorim Jaggi1f833082017-08-04 18:06:56 +02002062
2063 // If layout is currently deferred, we want to hold of with updating the layers.
2064 if (mService.mWindowPlacerLocked.isLayoutDeferred()) {
2065 return;
2066 }
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002067 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002068 if (dimLayerUser != null && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator)) {
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002069 // Force an animation pass just to update the mDimLayer layer.
2070 mService.scheduleAnimationLocked();
2071 }
2072 }
2073
Chong Zhangacf11402015-11-04 16:23:10 -08002074 private final class DeadWindowEventReceiver extends InputEventReceiver {
2075 DeadWindowEventReceiver(InputChannel inputChannel) {
2076 super(inputChannel, mService.mH.getLooper());
2077 }
2078 @Override
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -07002079 public void onInputEvent(InputEvent event, int displayId) {
Chong Zhangacf11402015-11-04 16:23:10 -08002080 finishInputEvent(event, true);
2081 }
2082 }
2083 /**
2084 * Dummy event receiver for windows that died visible.
2085 */
2086 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2087
Chong Zhang112eb8c2015-11-02 11:17:00 -08002088 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002089 if (mInputChannel != null) {
2090 throw new IllegalStateException("Window already has an input channel.");
2091 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002092 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002093 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2094 mInputChannel = inputChannels[0];
2095 mClientChannel = inputChannels[1];
2096 mInputWindowHandle.inputChannel = inputChannels[0];
2097 if (outInputChannel != null) {
2098 mClientChannel.transferTo(outInputChannel);
2099 mClientChannel.dispose();
2100 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002101 } else {
2102 // If the window died visible, we setup a dummy input channel, so that taps
2103 // can still detected by input monitor channel, and we can relaunch the app.
2104 // Create dummy event receiver that simply reports all events as handled.
2105 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002106 }
2107 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002108 }
2109
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002110 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002111 if (mDeadWindowEventReceiver != null) {
2112 mDeadWindowEventReceiver.dispose();
2113 mDeadWindowEventReceiver = null;
2114 }
2115
2116 // unregister server channel first otherwise it complains about broken channel
2117 if (mInputChannel != null) {
2118 mService.mInputManager.unregisterInputChannel(mInputChannel);
2119 mInputChannel.dispose();
2120 mInputChannel = null;
2121 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002122 if (mClientChannel != null) {
2123 mClientChannel.dispose();
2124 mClientChannel = null;
2125 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07002126 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002127 }
2128
Chong Zhang112eb8c2015-11-02 11:17:00 -08002129 void applyDimLayerIfNeeded() {
Chong Zhangeb917322015-11-10 14:05:40 -08002130 // When the app is terminated (eg. from Recents), the task might have already been
2131 // removed with the window pending removal. Don't apply dim in such cases, as there
2132 // will be no more updateDimLayer() calls, which leaves the dimlayer invalid.
2133 final AppWindowToken token = mAppToken;
2134 if (token != null && token.removed) {
2135 return;
2136 }
2137
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002138 final DisplayContent dc = getDisplayContent();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002139 if (!mAnimatingExit && mAppDied) {
Chong Zhang112eb8c2015-11-02 11:17:00 -08002140 // If app died visible, apply a dim over the window to indicate that it's inactive
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002141 dc.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002142 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02002143 && dc != null && !mAnimatingExit && isVisible()) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002144 dc.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
Filip Gruszczynski4501d232015-09-02 13:00:02 -07002145 }
2146 }
2147
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002148 private DimLayer.DimLayerUser getDimLayerUser() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002149 Task task = getTask();
2150 if (task != null) {
2151 return task;
2152 }
2153 return getStack();
2154 }
2155
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002156 /** Returns true if the replacement window was removed. */
2157 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2158 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2159 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2160 removeReplacedWindow();
2161 return true;
2162 }
2163
2164 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002165 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002166 if (c.removeReplacedWindowIfNeeded(replacement)) {
2167 return true;
2168 }
2169 }
2170 return false;
2171 }
2172
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002173 private void removeReplacedWindow() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002174 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
2175 if (isDimming()) {
2176 transferDimToReplacement();
Robert Carra1eb4392015-12-10 12:43:51 -08002177 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002178 mWillReplaceWindow = false;
2179 mAnimateReplacingWindow = false;
2180 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002181 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002182 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002183 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002184 }
2185 }
2186
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002187 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2188 boolean replacementSet = false;
2189
2190 if (mWillReplaceWindow && mReplacementWindow == null
2191 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2192
2193 mReplacementWindow = replacementCandidate;
2194 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2195 replacementSet = true;
2196 }
2197
2198 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002199 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002200 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2201 }
2202
2203 return replacementSet;
2204 }
2205
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002206 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002207 final DisplayContent dc = getDisplayContent();
2208 if (dc != null) {
2209 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002210 }
2211 }
2212
Robert Carrfed10072016-05-26 11:48:49 -07002213 // TODO: Strange usage of word workspace here and above.
2214 boolean inPinnedWorkspace() {
2215 final Task task = getTask();
2216 return task != null && task.inPinnedWorkspace();
2217 }
2218
Chong Zhang5117e272016-05-03 12:47:34 -07002219 void applyAdjustForImeIfNeeded() {
2220 final Task task = getTask();
2221 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2222 task.mStack.applyAdjustForImeIfNeeded(task);
2223 }
2224 }
2225
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002226 @Override
2227 void switchUser() {
2228 super.switchUser();
2229 if (isHiddenFromUserLocked()) {
2230 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2231 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
2232 hideLw(false);
2233 }
2234 }
2235
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002236 int getTouchableRegion(Region region, int flags) {
2237 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002238 if (modal && mAppToken != null) {
2239 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002240 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002241 // If this is a modal window we need to dismiss it if it's not full screen and the
2242 // touch happens outside of the frame that displays the content. This means we
2243 // need to intercept touches outside of that window. The dim layer user
2244 // associated with the window (task or stack) will give us the good bounds, as
2245 // they would be used to display the dim layer.
2246 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
2247 if (dimLayerUser != null) {
2248 dimLayerUser.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002249 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002250 getVisibleBounds(mTmpRect);
2251 }
2252 if (inFreeformWorkspace()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002253 // For freeform windows we the touch region to include the whole surface for the
2254 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002255 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2256 final int delta = WindowManagerService.dipToPixel(
2257 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2258 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002259 }
2260 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002261 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002262 } else {
2263 // Not modal or full screen modal
2264 getTouchableRegion(region);
2265 }
2266 return flags;
2267 }
2268
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002269 void checkPolicyVisibilityChange() {
2270 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2271 if (DEBUG_VISIBILITY) {
2272 Slog.v(TAG, "Policy visibility changing after anim in " +
2273 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2274 }
2275 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08002276 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002277 if (!mPolicyVisibility) {
2278 if (mService.mCurrentFocus == this) {
2279 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2280 "setAnimationLocked: setting mFocusMayChange true");
2281 mService.mFocusMayChange = true;
2282 }
2283 // Window is no longer visible -- make sure if we were waiting
2284 // for it to be displayed before enabling the display, that
2285 // we allow the display to be enabled now.
2286 mService.enableScreenIfNeededLocked();
2287 }
2288 }
2289 }
2290
2291 void setRequestedSize(int requestedWidth, int requestedHeight) {
2292 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2293 mLayoutNeeded = true;
2294 mRequestedWidth = requestedWidth;
2295 mRequestedHeight = requestedHeight;
2296 }
2297 }
2298
Bryce Leef858b572017-06-29 14:03:33 -07002299 void prepareWindowToDisplayDuringRelayout(boolean wasVisible) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002300 // We need to turn on screen regardless of visibility.
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002301 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
2302 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
2303 mTurnOnScreen = true;
2304 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002305
2306 // If we were already visible, skip rest of preparation.
2307 if (wasVisible) {
2308 if (DEBUG_VISIBILITY) Slog.v(TAG,
2309 "Already visible and does not turn on screen, skip preparing: " + this);
2310 return;
2311 }
2312
2313 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2314 == SOFT_INPUT_ADJUST_RESIZE) {
2315 mLayoutNeeded = true;
2316 }
2317
Adrian Roose94c15c2017-05-09 13:17:54 -07002318 if (isDrawnLw() && mService.okToAnimate()) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002319 mWinAnimator.applyEnterAnimationLocked();
2320 }
Bryce Leef858b572017-06-29 14:03:33 -07002321 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002322
Bryce Leef858b572017-06-29 14:03:33 -07002323 void getMergedConfiguration(MergedConfiguration outConfiguration) {
2324 final Configuration globalConfig = mService.mRoot.getConfiguration();
2325 final Configuration overrideConfig = getMergedOverrideConfiguration();
2326 outConfiguration.setConfiguration(globalConfig, overrideConfig);
2327 }
2328
2329 void setReportedConfiguration(MergedConfiguration config) {
2330 mLastReportedConfiguration.setTo(config.getMergedConfiguration());
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002331 }
2332
2333 void adjustStartingWindowFlags() {
2334 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2335 && mAppToken.startingWindow != null) {
2336 // Special handling of starting window over the base
2337 // window of the app: propagate lock screen flags to it,
2338 // to provide the correct semantics while starting.
2339 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2340 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2341 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2342 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2343 }
2344 }
2345
2346 void setWindowScale(int requestedWidth, int requestedHeight) {
2347 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2348
2349 if (scaledWindow) {
2350 // requested{Width|Height} Surface's physical size
2351 // attrs.{width|height} Size on screen
2352 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2353 mHScale = (mAttrs.width != requestedWidth) ?
2354 (mAttrs.width / (float)requestedWidth) : 1.0f;
2355 mVScale = (mAttrs.height != requestedHeight) ?
2356 (mAttrs.height / (float)requestedHeight) : 1.0f;
2357 } else {
2358 mHScale = mVScale = 1;
2359 }
2360 }
2361
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002362 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002363 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002364 public void binderDied() {
2365 try {
2366 synchronized(mService.mWindowMap) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002367 final WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002368 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002369 if (win != null) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002370 final DisplayContent dc = getDisplayContent();
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002371 if (win.mAppToken != null && win.mAppToken.findMainWindow() == win) {
2372 mService.mTaskSnapshotController.onAppDied(win.mAppToken);
2373 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002374 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002375 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2376 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002377 // just in case they have the divider at an unstable position. Better
2378 // also reset drag resizing state, because the owner can't do it
2379 // anymore.
Wale Ogunwale1666e312016-12-16 11:27:18 -08002380 final TaskStack stack = dc.getDockedStackIgnoringVisibility();
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002381 if (stack != null) {
2382 stack.resetDockedStackToMiddle();
2383 }
Jorim Jaggidcb68142016-02-09 21:51:30 -08002384 mService.setDockedStackResizing(false);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002385 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002386 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002387 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002388 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002389 }
2390 }
2391 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002392 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002393 }
2394 }
2395 }
2396
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002397 /**
2398 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2399 * because we want to preserve its location on screen to be re-activated later when the user
2400 * interacts with it.
2401 */
2402 boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwale89973222017-04-23 18:39:45 -07002403 if (!isWinVisibleLw() || mAppToken == null || mAppToken.isClientHidden()) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002404 // Not a visible app window or the app isn't dead.
2405 return false;
2406 }
2407
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002408 if (mAttrs.token != mClient.asBinder()) {
2409 // The window was add by a client using another client's app token. We don't want to
2410 // keep the dead window around for this case since this is meant for 'real' apps.
2411 return false;
2412 }
2413
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002414 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2415 // We don't keep starting windows since they were added by the window manager before
2416 // the app even launched.
2417 return false;
2418 }
2419
2420 final TaskStack stack = getStack();
2421 return stack != null && StackId.keepVisibleDeadAppWindowOnScreen(stack.mStackId);
2422 }
2423
Wale Ogunwaled045c822015-12-02 09:14:28 -08002424 /** @return true if this window desires key events. */
2425 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002426 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002427 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002428 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002429 && (mAppToken == null || mAppToken.windowsAreFocusable())
Matthew Nge15352e2016-12-20 15:36:29 -08002430 && !canReceiveTouchInput();
2431 }
2432
2433 /** @return true if this window desires touch events. */
2434 boolean canReceiveTouchInput() {
Bryce Lee6d410262017-02-28 15:30:17 -08002435 return mAppToken != null && mAppToken.getTask() != null
2436 && mAppToken.getTask().mStack.shouldIgnoreInput();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002437 }
2438
Craig Mautner749a7bb2012-04-02 13:49:53 -07002439 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002440 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002441 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002442 }
2443
Craig Mautner749a7bb2012-04-02 13:49:53 -07002444 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002445 public boolean showLw(boolean doAnimation) {
2446 return showLw(doAnimation, true);
2447 }
2448
2449 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002450 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002451 return false;
2452 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002453 if (!mAppOpVisibility) {
2454 // Being hidden due to app op request.
2455 return false;
2456 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002457 if (mPermanentlyHidden) {
2458 // Permanently hidden until the app exists as apps aren't prepared
2459 // to handle their windows being removed from under them.
2460 return false;
2461 }
Phil Weaverc510ecb2017-08-18 18:01:46 -07002462 if (mForceHideNonSystemOverlayWindow) {
2463 // This is an alert window that is currently force hidden.
2464 return false;
2465 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002466 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002467 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002468 return false;
2469 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002470 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002471 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002472 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07002473 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
Adrian Roose94c15c2017-05-09 13:17:54 -07002474 if (!mService.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002475 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07002476 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002477 // Check for the case where we are currently visible and
2478 // not animating; we do not want to do animation at such a
2479 // point to become visible when we already are.
2480 doAnimation = false;
2481 }
2482 }
2483 mPolicyVisibility = true;
2484 mPolicyVisibilityAfterAnim = true;
2485 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002486 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002487 }
2488 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002489 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002490 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002491 if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) {
2492 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2493 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002494 return true;
2495 }
2496
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002497 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002498 public boolean hideLw(boolean doAnimation) {
2499 return hideLw(doAnimation, true);
2500 }
2501
2502 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2503 if (doAnimation) {
Adrian Roose94c15c2017-05-09 13:17:54 -07002504 if (!mService.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002505 doAnimation = false;
2506 }
2507 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002508 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002509 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002510 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002511 return false;
2512 }
2513 if (doAnimation) {
Craig Mautnerc2f9be02012-03-27 17:32:29 -07002514 mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07002515 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002516 doAnimation = false;
2517 }
2518 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002519 mPolicyVisibilityAfterAnim = false;
2520 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002521 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002522 mPolicyVisibility = false;
2523 // Window is no longer visible -- make sure if we were waiting
2524 // for it to be displayed before enabling the display, that
2525 // we allow the display to be enabled now.
2526 mService.enableScreenIfNeededLocked();
2527 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002528 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002529 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002530 mService.mFocusMayChange = true;
2531 }
2532 }
2533 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002534 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002535 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002536 if (mService.mCurrentFocus == this) {
2537 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2538 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002539 return true;
2540 }
2541
Phil Weaverc510ecb2017-08-18 18:01:46 -07002542 void setForceHideNonSystemOverlayWindowIfNeeded(boolean forceHide) {
2543 if (mOwnerCanAddInternalSystemWindow
2544 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2545 return;
2546 }
2547 if (mForceHideNonSystemOverlayWindow == forceHide) {
2548 return;
2549 }
2550 mForceHideNonSystemOverlayWindow = forceHide;
2551 if (forceHide) {
2552 hideLw(true /* doAnimation */, true /* requestAnim */);
2553 } else {
2554 showLw(true /* doAnimation */, true /* requestAnim */);
2555 }
2556 }
2557
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002558 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002559 if (mAppOpVisibility != state) {
2560 mAppOpVisibility = state;
2561 if (state) {
2562 // If the policy visibility had last been to hide, then this
2563 // will incorrectly show at this point since we lost that
2564 // information. Not a big deal -- for the windows that have app
2565 // ops modifies they should only be hidden by policy due to the
2566 // lock screen, and the user won't be changing this if locked.
2567 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002568 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002569 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002570 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002571 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002572 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002573 }
2574
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002575 public void hidePermanentlyLw() {
2576 if (!mPermanentlyHidden) {
2577 mPermanentlyHidden = true;
2578 hideLw(true, true);
2579 }
2580 }
2581
Jeff Brownc2932a12014-11-20 18:04:05 -08002582 public void pokeDrawLockLw(long timeout) {
2583 if (isVisibleOrAdding()) {
2584 if (mDrawLock == null) {
2585 // We want the tag name to be somewhat stable so that it is easier to correlate
2586 // in wake lock statistics. So in particular, we don't want to include the
2587 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002588 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08002589 mDrawLock = mService.mPowerManager.newWakeLock(
2590 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
2591 mDrawLock.setReferenceCounted(false);
2592 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2593 }
2594 // Each call to acquire resets the timeout.
2595 if (DEBUG_POWER) {
2596 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2597 + mAttrs.packageName);
2598 }
2599 mDrawLock.acquire(timeout);
2600 } else if (DEBUG_POWER) {
2601 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2602 + "owned by " + mAttrs.packageName);
2603 }
2604 }
2605
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002606 @Override
2607 public boolean isAlive() {
2608 return mClient.asBinder().isBinderAlive();
2609 }
2610
Craig Mautnera987d432012-10-11 14:07:58 -07002611 boolean isClosing() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002612 return mAnimatingExit || (mService.mClosingApps.contains(mAppToken));
Craig Mautnera987d432012-10-11 14:07:58 -07002613 }
2614
Chong Zhangbef461f2015-10-27 11:38:24 -07002615 boolean isAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002616 return mAnimatingWithSavedSurface;
2617 }
2618
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002619 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002620 boolean isAnimating() {
2621 if (mWinAnimator.isAnimationSet() || mAnimatingExit) {
2622 return true;
2623 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002624 return super.isAnimating();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002625 }
2626
Chong Zhang8e4bda92016-05-04 15:08:18 -07002627 boolean isAnimatingInvisibleWithSavedSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002628 if (mAnimatingWithSavedSurface
2629 && (mViewVisibility != View.VISIBLE || mWindowRemovalAllowed)) {
2630 return true;
2631 }
2632 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002633 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002634 if (c.isAnimatingInvisibleWithSavedSurface()) {
2635 return true;
2636 }
2637 }
2638 return false;
2639 }
2640
2641 void stopUsingSavedSurface() {
2642 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002643 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002644 c.stopUsingSavedSurface();
2645 }
2646
2647 if (!isAnimatingInvisibleWithSavedSurface()) {
2648 return;
2649 }
2650
2651 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG, "stopUsingSavedSurface: " + this);
2652 clearAnimatingWithSavedSurface();
2653 mDestroying = true;
2654 mWinAnimator.hide("stopUsingSavedSurface");
Wale Ogunwale0303c572016-10-20 10:16:29 -07002655 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002656 }
2657
2658 void markSavedSurfaceExiting() {
2659 if (isAnimatingInvisibleWithSavedSurface()) {
2660 mAnimatingExit = true;
2661 mWinAnimator.mAnimating = true;
2662 }
2663 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002664 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002665 c.markSavedSurfaceExiting();
2666 }
2667 }
2668
2669 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2670 animators.add(mWinAnimator);
2671
2672 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002673 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002674 c.addWinAnimatorToList(animators);
2675 }
2676 }
2677
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002678 void sendAppVisibilityToClients() {
2679 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002680
Wale Ogunwale89973222017-04-23 18:39:45 -07002681 final boolean clientHidden = mAppToken.isClientHidden();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002682 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2683 // Don't hide the starting window.
2684 return;
2685 }
2686
Wale Ogunwale89973222017-04-23 18:39:45 -07002687 if (clientHidden) {
2688 // Once we are notifying the client that it's visibility has changed, we need to prevent
2689 // it from destroying child surfaces until the animation has finished. We do this by
2690 // detaching any surface control the client added from the client.
2691 for (int i = mChildren.size() - 1; i >= 0; --i) {
2692 final WindowState c = mChildren.get(i);
2693 c.mWinAnimator.detachChildren();
2694 }
2695
2696 mWinAnimator.detachChildren();
2697 }
2698
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002699 try {
2700 if (DEBUG_VISIBILITY) Slog.v(TAG,
2701 "Setting visibility of " + this + ": " + (!clientHidden));
2702 mClient.dispatchAppVisibility(!clientHidden);
2703 } catch (RemoteException e) {
2704 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002705 }
2706
Chong Zhang92147042016-05-09 12:47:11 -07002707 public void setVisibleBeforeClientHidden() {
2708 mWasVisibleBeforeClientHidden |=
2709 (mViewVisibility == View.VISIBLE || mAnimatingWithSavedSurface);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002710
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002711 super.setVisibleBeforeClientHidden();
Chong Zhang92147042016-05-09 12:47:11 -07002712 }
2713
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002714 public void clearWasVisibleBeforeClientHidden() {
Chong Zhang92147042016-05-09 12:47:11 -07002715 mWasVisibleBeforeClientHidden = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002716 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002717 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002718 c.clearWasVisibleBeforeClientHidden();
2719 }
Chong Zhang92147042016-05-09 12:47:11 -07002720 }
2721
2722 public boolean wasVisibleBeforeClientHidden() {
2723 return mWasVisibleBeforeClientHidden;
Chong Zhangbef461f2015-10-27 11:38:24 -07002724 }
2725
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002726 void onStartFreezingScreen() {
2727 mAppFreezing = true;
2728 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002729 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002730 c.onStartFreezingScreen();
2731 }
2732 }
2733
2734 boolean onStopFreezingScreen() {
2735 boolean unfrozeWindows = false;
2736 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002737 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002738 unfrozeWindows |= c.onStopFreezingScreen();
2739 }
2740
2741 if (!mAppFreezing) {
2742 return unfrozeWindows;
2743 }
2744
Wale Ogunwale953171d2016-09-30 09:17:30 -07002745 mAppFreezing = false;
2746
Bryce Lee8c3cf382017-07-06 19:47:10 -07002747 if (mHasSurface && !getOrientationChanging()
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002748 && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
2749 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
Bryce Lee8c3cf382017-07-06 19:47:10 -07002750 setOrientationChanging(true);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002751 mService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002752 }
2753 mLastFreezeDuration = 0;
2754 setDisplayLayoutNeeded();
2755 return true;
2756 }
2757
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002758 private boolean shouldSaveSurface() {
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002759 if (mWinAnimator.mSurfaceController == null) {
2760 // Don't bother if the surface controller is gone for any reason.
2761 return false;
2762 }
2763
Chong Zhang92147042016-05-09 12:47:11 -07002764 if (!mWasVisibleBeforeClientHidden) {
2765 return false;
2766 }
2767
Wale Ogunwale945d1972016-03-23 13:16:41 -07002768 if ((mAttrs.flags & FLAG_SECURE) != 0) {
2769 // We don't save secure surfaces since their content shouldn't be shown while the app
2770 // isn't on screen and content might leak through during the transition animation with
2771 // saved surface.
2772 return false;
2773 }
2774
Jorim Jaggi02886a82016-12-06 09:10:06 -08002775 if (isLowRamDeviceStatic()) {
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002776 // Don't save surfaces on Svelte devices.
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002777 return false;
2778 }
2779
Jorim Jaggiab7ad382016-10-26 18:22:04 -07002780 final Task task = getTask();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002781 final AppWindowToken taskTop = task.getTopVisibleAppToken();
2782 if (taskTop != null && taskTop != mAppToken) {
2783 // Don't save if the window is not the topmost window.
2784 return false;
2785 }
2786
Jorim Jaggi8fa45222016-02-19 19:54:39 -08002787 if (mResizedWhileGone) {
2788 // Somebody resized our window while we were gone for layout, which means that the
2789 // client got an old size, so we have an outdated surface here.
2790 return false;
2791 }
2792
Robert Carr7098dbd2016-02-01 12:31:01 -08002793 if (DEBUG_DISABLE_SAVING_SURFACES) {
2794 return false;
2795 }
2796
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002797 return mAppToken.shouldSaveSurface();
2798 }
2799
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002800 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2801 boolean destroyedSomething = false;
2802 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002803 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002804 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2805 }
2806
Robert Carrdb2f6e62017-03-01 20:17:58 -08002807 if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) {
2808 return destroyedSomething;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002809 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08002810
2811 if (appStopped || mWindowRemovalAllowed) {
2812 mWinAnimator.destroyPreservedSurfaceLocked();
2813 }
2814
2815 if (mDestroying) {
2816 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2817 + " destroySurfaces: appStopped=" + appStopped
2818 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2819 + " win.mRemoveOnExit=" + mRemoveOnExit);
2820 if (!cleanupOnResume || mRemoveOnExit) {
Robert Carr89a28ab2017-04-24 15:33:11 -07002821 destroyOrSaveSurfaceUnchecked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08002822 }
2823 if (mRemoveOnExit) {
2824 removeImmediately();
2825 }
2826 if (cleanupOnResume) {
2827 requestUpdateWallpaperIfNeeded();
2828 }
2829 mDestroying = false;
2830 destroyedSomething = true;
2831 }
2832
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002833 return destroyedSomething;
2834 }
Chris Craik3131bde2016-05-06 13:39:08 -07002835
Robert Carr89a28ab2017-04-24 15:33:11 -07002836 // Destroy or save the application surface without checking
2837 // various indicators of whether the client has released the surface.
2838 // This is in general unsafe, and most callers should use {@link #destroySurface}
2839 void destroyOrSaveSurfaceUnchecked() {
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002840 mSurfaceSaved = shouldSaveSurface();
2841 if (mSurfaceSaved) {
2842 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2843 Slog.v(TAG, "Saving surface: " + this);
2844 }
Chris Craik3131bde2016-05-06 13:39:08 -07002845 // Previous user of the surface may have set a transparent region signaling a portion
2846 // doesn't need to be composited, so reset to default empty state.
2847 mSession.setTransparentRegion(mClient, sEmptyRegion);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002848
2849 mWinAnimator.hide("saved surface");
2850 mWinAnimator.mDrawState = WindowStateAnimator.NO_SURFACE;
2851 setHasSurface(false);
Chong Zhang47e36a32016-02-29 16:44:33 -08002852 // The client should have disconnected at this point, but if it doesn't,
2853 // we need to make sure it's disconnected. Otherwise when we reuse the surface
2854 // the client can't reconnect to the buffer queue, and rendering will fail.
2855 if (mWinAnimator.mSurfaceController != null) {
2856 mWinAnimator.mSurfaceController.disconnectInTransaction();
2857 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002858 mAnimatingWithSavedSurface = false;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002859 } else {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002860 mWinAnimator.destroySurfaceLocked();
2861 }
Chong Zhang92147042016-05-09 12:47:11 -07002862 // Clear animating flags now, since the surface is now gone. (Note this is true even
2863 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2864 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002865 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002866
Chong Zhang92147042016-05-09 12:47:11 -07002867 void destroySavedSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002868 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002869 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002870 c.destroySavedSurface();
2871 }
2872
Robert Carr13f7be9e2015-12-02 18:39:45 -08002873 if (mSurfaceSaved) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002874 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, "Destroying saved surface: " + this);
Robert Carr13f7be9e2015-12-02 18:39:45 -08002875 mWinAnimator.destroySurfaceLocked();
Robert Carr237028a2016-07-26 10:39:45 -07002876 mSurfaceSaved = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002877 }
Chong Zhang92147042016-05-09 12:47:11 -07002878 mWasVisibleBeforeClientHidden = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002879 }
2880
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002881 /** Returns -1 if there are no interesting windows or number of interesting windows not drawn.*/
2882 int restoreSavedSurfaceForInterestingWindow() {
2883 int interestingNotDrawn = -1;
2884 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002885 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002886 final int childInterestingNotDrawn = c.restoreSavedSurfaceForInterestingWindow();
2887 if (childInterestingNotDrawn != -1) {
2888 if (interestingNotDrawn == -1) {
2889 interestingNotDrawn = childInterestingNotDrawn;
2890 } else {
2891 interestingNotDrawn += childInterestingNotDrawn;
2892 }
2893 }
Chong Zhang4113ffa2016-02-18 12:39:13 -08002894 }
Robert Carr237028a2016-07-26 10:39:45 -07002895
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002896 if (mAttrs.type == TYPE_APPLICATION_STARTING
2897 || mAppDied || !wasVisibleBeforeClientHidden()
2898 || (mAppToken.mAppAnimator.freezingScreen && mAppFreezing)) {
2899 // Window isn't interesting...
2900 return interestingNotDrawn;
2901 }
2902
2903 restoreSavedSurface();
2904
2905 if (!isDrawnLw()) {
2906 if (interestingNotDrawn == -1) {
2907 interestingNotDrawn = 1;
2908 } else {
2909 interestingNotDrawn++;
2910 }
2911 }
2912 return interestingNotDrawn;
2913 }
2914
2915 /** Returns true if the saved surface was restored. */
2916 boolean restoreSavedSurface() {
2917 if (!mSurfaceSaved) {
2918 return false;
2919 }
2920
2921 // Sometimes we save surfaces due to layout invisible directly after rotation occurs.
2922 // However this means the surface was never laid out in the new orientation.
2923 // We can only restore to the last rotation we were laid out as visible in.
Andrii Kulian8ee72852017-03-10 10:36:45 -08002924 if (mLastVisibleLayoutRotation != getDisplayContent().getRotation()) {
Robert Carr237028a2016-07-26 10:39:45 -07002925 destroySavedSurface();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002926 return false;
Robert Carr237028a2016-07-26 10:39:45 -07002927 }
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002928 mSurfaceSaved = false;
Robert Carr237028a2016-07-26 10:39:45 -07002929
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002930 if (mWinAnimator.mSurfaceController != null) {
2931 setHasSurface(true);
Wale Ogunwale9d147902016-07-16 11:58:55 -07002932 mWinAnimator.mDrawState = READY_TO_SHOW;
Chong Zhang92147042016-05-09 12:47:11 -07002933 mAnimatingWithSavedSurface = true;
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002934
Chong Zhang6e9872b2016-08-17 10:19:05 -07002935 requestUpdateWallpaperIfNeeded();
2936
Chong Zhang6c71c0b2016-04-01 15:10:31 -07002937 if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) {
2938 Slog.v(TAG, "Restoring saved surface: " + this);
2939 }
2940 } else {
2941 // mSurfaceController shouldn't be null if mSurfaceSaved was still true at
2942 // this point. Even if we destroyed the saved surface because of rotation
2943 // or resize, mSurfaceSaved flag should have been cleared. So this is a wtf.
2944 Slog.wtf(TAG, "Failed to restore saved surface: surface gone! " + this);
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002945 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002946
2947 return true;
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002948 }
2949
Chong Zhang92147042016-05-09 12:47:11 -07002950 boolean canRestoreSurface() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002951 if (mWasVisibleBeforeClientHidden && mSurfaceSaved) {
2952 return true;
2953 }
2954
2955 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002956 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002957 if (c.canRestoreSurface()) {
2958 return true;
2959 }
2960 }
2961
2962 return false;
Chong Zhang92147042016-05-09 12:47:11 -07002963 }
2964
2965 boolean hasSavedSurface() {
Robert Carr13f7be9e2015-12-02 18:39:45 -08002966 return mSurfaceSaved;
2967 }
2968
Chong Zhang92147042016-05-09 12:47:11 -07002969 void clearHasSavedSurface() {
2970 mSurfaceSaved = false;
2971 mAnimatingWithSavedSurface = false;
Chong Zhangf58631a2016-05-24 16:02:10 -07002972 if (mWasVisibleBeforeClientHidden) {
2973 mAppToken.destroySavedSurfaces();
2974 }
Chong Zhang92147042016-05-09 12:47:11 -07002975 }
2976
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002977 boolean clearAnimatingWithSavedSurface() {
Chong Zhang92147042016-05-09 12:47:11 -07002978 if (mAnimatingWithSavedSurface) {
2979 // App has drawn something to its windows, we're no longer animating with
2980 // the saved surfaces.
2981 if (DEBUG_ANIM) Slog.d(TAG,
2982 "clearAnimatingWithSavedSurface(): win=" + this);
2983 mAnimatingWithSavedSurface = false;
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002984 return true;
Chong Zhang92147042016-05-09 12:47:11 -07002985 }
Chong Zhangcbbcc0f2016-05-17 20:46:58 -07002986 return false;
Chong Zhang92147042016-05-09 12:47:11 -07002987 }
2988
Craig Mautner69b08182012-09-05 13:07:13 -07002989 @Override
2990 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002991 final DisplayContent displayContent = getDisplayContent();
2992 if (displayContent == null) {
2993 // Only a window that was on a non-default display can be detached from it.
2994 return false;
2995 }
Winson Chung47a3e652014-05-21 16:03:42 -07002996 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002997 }
2998
Adrian Rooscd3884d2015-02-18 17:25:23 +01002999 @Override
3000 public boolean isDimming() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07003001 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003002 final DisplayContent dc = getDisplayContent();
3003 return dimLayerUser != null && dc != null
3004 && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
Adrian Rooscd3884d2015-02-18 17:25:23 +01003005 }
3006
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003007 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07003008 mShowToOwnerOnly = showToOwnerOnly;
3009 }
3010
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003011 private boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003012 // Child windows are evaluated based on their parent window.
3013 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003014 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale72919d22016-12-08 18:58:50 -08003015 && win.mAppToken != null && win.mAppToken.mShowForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07003016
3017 // All window frames that are fullscreen extend above status bar, but some don't extend
3018 // below navigation bar. Thus, check for display frame for top/left and stable frame for
3019 // bottom right.
3020 if (win.mFrame.left <= win.mDisplayFrame.left
3021 && win.mFrame.top <= win.mDisplayFrame.top
3022 && win.mFrame.right >= win.mStableFrame.right
3023 && win.mFrame.bottom >= win.mStableFrame.bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07003024 // Is a fullscreen window, like the clock alarm. Show to everyone.
3025 return false;
3026 }
3027 }
3028
Craig Mautner341220f2012-10-16 15:20:09 -07003029 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01003030 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07003031 }
3032
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003033 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
3034 outRegion.set(
3035 frame.left + inset.left, frame.top + inset.top,
3036 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04003037 }
3038
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003039 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003040 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003041 switch (mTouchableInsets) {
3042 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003043 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003044 outRegion.set(frame);
3045 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003046 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003047 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003048 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003049 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003050 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003051 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003052 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003053 outRegion.set(mGivenTouchableRegion);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003054 outRegion.translate(frame.left, frame.top);
3055 break;
3056 }
3057 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003058 cropRegionToStackBoundsIfNeeded(outRegion);
3059 }
3060
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07003061 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08003062 final Task task = getTask();
3063 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003064 return;
3065 }
3066
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08003067 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08003068 if (stack == null) {
3069 return;
3070 }
3071
3072 stack.getDimBounds(mTmpRect);
3073 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003074 }
3075
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003076 /**
3077 * Report a focus change. Must be called with no locks held, and consistently
3078 * from the same serialized thread (such as dispatched from a handler).
3079 */
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07003080 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003081 try {
3082 mClient.windowFocusChanged(focused, inTouchMode);
3083 } catch (RemoteException e) {
3084 }
3085 if (mFocusCallbacks != null) {
3086 final int N = mFocusCallbacks.beginBroadcast();
3087 for (int i=0; i<N; i++) {
3088 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
3089 try {
3090 if (focused) {
3091 obs.focusGained(mWindowId.asBinder());
3092 } else {
3093 obs.focusLost(mWindowId.asBinder());
3094 }
3095 } catch (RemoteException e) {
3096 }
3097 }
3098 mFocusCallbacks.finishBroadcast();
3099 }
3100 }
3101
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003102 @Override
3103 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003104 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003105 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003106 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003107
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003108 return super.getConfiguration();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003109 }
3110
Craig Mautnerdf88d732014-01-27 09:21:32 -08003111 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003112 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08003113 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003114 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
3115 + ": " + mCompatFrame);
Bryce Leef858b572017-06-29 14:03:33 -07003116 final MergedConfiguration mergedConfiguration =
3117 new MergedConfiguration(mService.mRoot.getConfiguration(),
3118 getMergedOverrideConfiguration());
3119
3120 setReportedConfiguration(mergedConfiguration);
3121
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003122 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003123 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
3124
Craig Mautnerdf88d732014-01-27 09:21:32 -08003125 final Rect frame = mFrame;
3126 final Rect overscanInsets = mLastOverscanInsets;
3127 final Rect contentInsets = mLastContentInsets;
3128 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07003129 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003130 final Rect outsets = mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003131 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003132 final boolean reportOrientation = mReportOrientationChanged;
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003133 final int displayId = getDisplayId();
Chet Haase8eb48d22014-09-24 07:31:29 -07003134 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
3135 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08003136 // To prevent deadlock simulate one-way call if win.mClient is a local object.
3137 mService.mH.post(new Runnable() {
3138 @Override
3139 public void run() {
3140 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003141 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003142 stableInsets, outsets, reportDraw, mergedConfiguration,
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003143 reportOrientation, displayId);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003144 } catch (RemoteException e) {
3145 // Not a remote call, RemoteException won't be raised.
3146 }
3147 }
3148 });
3149 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003150 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003151 outsets, reportDraw, mergedConfiguration, reportOrientation, displayId);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003152 }
Svetoslav4604abc2014-06-10 18:59:30 -07003153
3154 //TODO (multidisplay): Accessibility supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07003155 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07003156 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07003157 }
3158
Craig Mautnerdf88d732014-01-27 09:21:32 -08003159 mOverscanInsetsChanged = false;
3160 mContentInsetsChanged = false;
3161 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07003162 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003163 mOutsetsChanged = false;
Robert Carr31aa98b2016-07-20 15:29:03 -07003164 mFrameSizeChanged = false;
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003165 mResizedWhileNotDragResizingReported = true;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003166 mWinAnimator.mSurfaceResized = false;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003167 mReportOrientationChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003168 } catch (RemoteException e) {
Bryce Lee8c3cf382017-07-06 19:47:10 -07003169 setOrientationChanging(false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003170 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
3171 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08003172 // We are assuming the hosting process is dead or in a zombie state.
3173 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
3174 + ", removing this window.");
3175 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07003176 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003177 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003178 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003179 }
3180
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003181 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08003182 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
3183 // start even if we haven't received the relayout window, so that the client requests
3184 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
3185 // until the window to small size, otherwise the multithread renderer will shift last
3186 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
3187 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003188 boolean resizing = isDragResizing() || isDragResizeChanged();
3189 if (StackId.useWindowFrameForBackdrop(getStackId()) || !resizing) {
3190 return frame;
3191 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07003192 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003193 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003194 return mTmpRect;
3195 }
3196
Jorim Jaggi86905582016-02-09 21:36:09 -08003197 @Override
3198 public int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003199 final TaskStack stack = getStack();
3200 if (stack == null) {
3201 return INVALID_STACK_ID;
3202 }
3203 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003204 }
3205
3206 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
3207 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
Andrii Kulian44607962017-03-16 11:06:24 -07003208 MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId)
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003209 throws RemoteException {
Andrii Kulianb2e37802017-01-11 00:36:44 -08003210 final boolean forceRelayout = isDragResizeChanged() || mResizedWhileNotDragResizing
3211 || reportOrientation;
Chong Zhangedaf3052016-04-22 15:04:31 -07003212
Jorim Jaggidc249c42015-12-15 14:57:31 -08003213 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003214 reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout,
3215 mPolicy.isNavBarForcedShownLw(this), displayId);
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003216 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003217 }
3218
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003219 public void registerFocusObserver(IWindowFocusObserver observer) {
3220 synchronized(mService.mWindowMap) {
3221 if (mFocusCallbacks == null) {
3222 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
3223 }
3224 mFocusCallbacks.register(observer);
3225 }
3226 }
3227
3228 public void unregisterFocusObserver(IWindowFocusObserver observer) {
3229 synchronized(mService.mWindowMap) {
3230 if (mFocusCallbacks != null) {
3231 mFocusCallbacks.unregister(observer);
3232 }
3233 }
3234 }
3235
3236 public boolean isFocused() {
3237 synchronized(mService.mWindowMap) {
3238 return mService.mCurrentFocus == this;
3239 }
3240 }
3241
Filip Gruszczynski1a1d8312015-08-26 17:00:47 -07003242 boolean inFreeformWorkspace() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003243 final Task task = getTask();
Chong Zhang09b21ef2015-09-14 10:20:21 -07003244 return task != null && task.inFreeformWorkspace();
3245 }
3246
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003247 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07003248 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003249 final Task task = getTask();
3250 return task != null && !task.isFullscreen();
3251 }
3252
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003253 /** Is this window in a container that takes up the entire screen space? */
3254 private boolean inFullscreenContainer() {
3255 if (mAppToken == null) {
3256 return true;
3257 }
3258 if (mAppToken.hasBounds()) {
3259 return false;
3260 }
3261 return !isInMultiWindowMode();
3262 }
3263
Andrii Kulian283acd22017-08-03 04:03:51 -07003264 /** @return true when the window is in fullscreen task, but has non-fullscreen bounds set. */
3265 boolean isLetterboxedAppWindow() {
3266 final Task task = getTask();
3267 final boolean taskIsFullscreen = task != null && task.isFullscreen();
3268 final boolean appWindowIsFullscreen = mAppToken != null && !mAppToken.hasBounds();
3269
3270 return taskIsFullscreen && !appWindowIsFullscreen;
3271 }
3272
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003273 /** Returns the appropriate bounds to use for computing frames. */
3274 private void getContainerBounds(Rect outBounds) {
3275 if (isInMultiWindowMode()) {
3276 getTask().getBounds(outBounds);
3277 } else if (mAppToken != null){
3278 mAppToken.getBounds(outBounds);
3279 } else {
3280 outBounds.setEmpty();
3281 }
3282 }
3283
Chong Zhang3005e752015-09-18 18:46:28 -07003284 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003285 return mDragResizing != computeDragResizing();
3286 }
3287
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003288 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003289 void setWaitingForDrawnIfResizingChanged() {
3290 if (isDragResizeChanged()) {
3291 mService.mWaitingForDrawn.add(this);
3292 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003293 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003294 }
3295
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003296 /**
3297 * @return Whether we reported a drag resize change to the application or not already.
3298 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003299 private boolean isDragResizingChangeReported() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003300 return mDragResizingChangeReported;
3301 }
3302
3303 /**
3304 * Resets the state whether we reported a drag resize change to the app.
3305 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003306 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003307 void resetDragResizingChangeReported() {
3308 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003309 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003310 }
3311
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003312 /**
3313 * Set whether we got resized but drag resizing flag was false.
3314 * @see #isResizedWhileNotDragResizing().
3315 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003316 private void setResizedWhileNotDragResizing(boolean resizedWhileNotDragResizing) {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003317 mResizedWhileNotDragResizing = resizedWhileNotDragResizing;
3318 mResizedWhileNotDragResizingReported = !resizedWhileNotDragResizing;
3319 }
3320
3321 /**
3322 * Indicates whether we got resized but drag resizing flag was false. In this case, we also
3323 * need to recreate the surface and defer surface bound updates in order to make sure the
3324 * buffer contents and the positioning/size stay in sync.
3325 */
3326 boolean isResizedWhileNotDragResizing() {
3327 return mResizedWhileNotDragResizing;
3328 }
3329
3330 /**
3331 * @return Whether we reported "resize while not drag resizing" to the application.
3332 * @see #isResizedWhileNotDragResizing()
3333 */
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003334 private boolean isResizedWhileNotDragResizingReported() {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003335 return mResizedWhileNotDragResizingReported;
3336 }
3337
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003338 int getResizeMode() {
3339 return mResizeMode;
3340 }
3341
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003342 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003343 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003344 if (task == null) {
3345 return false;
3346 }
Winson Chung2af04b32017-01-24 16:21:13 -08003347 if (!StackId.isStackAffectedByDragResizing(getStackId())) {
3348 return false;
3349 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003350 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003351 // Floating windows never enter drag resize mode.
3352 return false;
3353 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003354 if (task.isDragResizing()) {
3355 return true;
3356 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003357
3358 // If the bounds are currently frozen, it means that the layout size that the app sees
3359 // and the bounds we clip this window to might be different. In order to avoid holes, we
3360 // simulate that we are still resizing so the app fills the hole with the resizing
3361 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003362 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003363 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Jorim Jaggi899327f2016-02-25 20:44:18 -05003364 !task.inFreeformWorkspace() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003365
Chong Zhang3005e752015-09-18 18:46:28 -07003366 }
3367
3368 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003369 final boolean resizing = computeDragResizing();
3370 if (resizing == mDragResizing) {
3371 return;
3372 }
3373 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003374 final Task task = getTask();
3375 if (task != null && task.isDragResizing()) {
3376 mResizeMode = task.getDragResizeMode();
3377 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003378 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003379 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3380 : DRAG_RESIZE_MODE_FREEFORM;
3381 }
Chong Zhang3005e752015-09-18 18:46:28 -07003382 }
3383
3384 boolean isDragResizing() {
3385 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003386 }
3387
Robert Carr2487ce72016-04-07 15:18:45 -07003388 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003389 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3390 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003391 }
3392
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003393 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003394 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003395 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003396 if (stack != null) {
3397 pw.print(" stackId="); pw.print(stack.mStackId);
3398 }
Craig Mautner59c00972012-07-30 12:10:24 -07003399 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003400 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07003401 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08003402 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
3403 pw.print(" package="); pw.print(mAttrs.packageName);
3404 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003405 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003406 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
3407 pw.print(" h="); pw.print(mRequestedHeight);
3408 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003409 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
3410 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
3411 pw.print(" h="); pw.println(mLastRequestedHeight);
3412 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003413 if (mIsChildWindow || mLayoutAttached) {
3414 pw.print(prefix); pw.print("mParentWindow="); pw.print(getParentWindow());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003415 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
3416 }
3417 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
3418 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
3419 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
3420 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
3421 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
3422 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003423 if (dumpAll) {
3424 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3425 pw.print(" mSubLayer="); pw.print(mSubLayer);
3426 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Wale Ogunwale455fac52016-07-21 07:24:49 -07003427 pw.print(getAnimLayerAdjustment());
Craig Mautnerc2f9be02012-03-27 17:32:29 -07003428 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
3429 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003430 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003431 if (dumpAll) {
3432 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003433 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003434 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
3435 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Chong Zhangbfc2f8f2016-01-29 15:50:34 -08003436 pw.print(isAnimatingWithSavedSurface());
Bryce Lee6311c4b2017-07-06 14:09:29 -07003437 pw.print(" mAppDied=");pw.print(mAppDied);
3438 pw.print(prefix); pw.print("drawnStateEvaluated=");
3439 pw.print(getDrawnStateEvaluated());
3440 pw.print(prefix); pw.print("mightAffectAllDrawn=");
3441 pw.println(mightAffectAllDrawn(false /*visibleOnly*/));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003442 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003443 pw.print(prefix); pw.print("mViewVisibility=0x");
3444 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003445 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
3446 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07003447 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
3448 pw.print(" mSystemUiVisibility=0x");
3449 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003450 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003451 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
Phil Weaverc510ecb2017-08-18 18:01:46 -07003452 || isParentWindowHidden()|| mPermanentlyHidden || mForceHideNonSystemOverlayWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003453 pw.print(prefix); pw.print("mPolicyVisibility=");
3454 pw.print(mPolicyVisibility);
3455 pw.print(" mPolicyVisibilityAfterAnim=");
3456 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003457 pw.print(" mAppOpVisibility=");
3458 pw.print(mAppOpVisibility);
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003459 pw.print(" parentHidden="); pw.print(isParentWindowHidden());
Phil Weaverc510ecb2017-08-18 18:01:46 -07003460 pw.print(" mForceHideNonSystemOverlayWindow="); pw.println(
3461 mForceHideNonSystemOverlayWindow); }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003462 if (!mRelayoutCalled || mLayoutNeeded) {
3463 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
3464 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003465 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003466 if (mXOffset != 0 || mYOffset != 0) {
3467 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
3468 pw.print(" y="); pw.println(mYOffset);
3469 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003470 if (dumpAll) {
3471 pw.print(prefix); pw.print("mGivenContentInsets=");
3472 mGivenContentInsets.printShortString(pw);
3473 pw.print(" mGivenVisibleInsets=");
3474 mGivenVisibleInsets.printShortString(pw);
3475 pw.println();
3476 if (mTouchableInsets != 0 || mGivenInsetsPending) {
3477 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
3478 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003479 Region region = new Region();
3480 getTouchableRegion(region);
3481 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003482 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003483 pw.print(prefix); pw.print("mFullConfiguration="); pw.println(getConfiguration());
3484 pw.print(prefix); pw.print("mLastReportedConfiguration=");
3485 pw.println(mLastReportedConfiguration);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003486 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07003487 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07003488 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Chong Zhanga8975bd2016-01-28 17:13:47 -08003489 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08003490 pw.print(" hasSavedSurface()="); pw.print(hasSavedSurface());
3491 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003492 if (dumpAll) {
3493 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
3494 pw.print(" last="); mLastFrame.printShortString(pw);
3495 pw.println();
3496 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003497 if (mEnforceSizeCompat) {
3498 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003499 pw.println();
3500 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003501 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003502 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003503 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003504 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003505 pw.println();
3506 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
3507 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003508 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003509 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003510 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003511 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04003512 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
3513 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003514 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
3515 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003516 pw.print(prefix); pw.print("Cur insets: overscan=");
3517 mOverscanInsets.printShortString(pw);
3518 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003519 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003520 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003521 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003522 pw.print(" outsets="); mOutsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003523 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003524 pw.print(prefix); pw.print("Lst insets: overscan=");
3525 mLastOverscanInsets.printShortString(pw);
3526 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003527 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003528 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003529 pw.print(" physical="); mLastOutsets.printShortString(pw);
3530 pw.print(" outset="); mLastOutsets.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003531 pw.println();
3532 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07003533 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
3534 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003535 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
3536 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003537 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
3538 pw.print(" mDestroying="); pw.print(mDestroying);
3539 pw.print(" mRemoved="); pw.println(mRemoved);
3540 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07003541 if (getOrientationChanging() || mAppFreezing || mTurnOnScreen
Andrii Kulianb2e37802017-01-11 00:36:44 -08003542 || mReportOrientationChanged) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003543 pw.print(prefix); pw.print("mOrientationChanging=");
3544 pw.print(mOrientationChanging);
Bryce Lee8c3cf382017-07-06 19:47:10 -07003545 pw.print(" configOrientationChanging=");
3546 pw.print(mLastReportedConfiguration.orientation
3547 != getConfiguration().orientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003548 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003549 pw.print(" mTurnOnScreen="); pw.print(mTurnOnScreen);
Andrii Kulianb2e37802017-01-11 00:36:44 -08003550 pw.print(" mReportOrientationChanged="); pw.println(mReportOrientationChanged);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003551 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003552 if (mLastFreezeDuration != 0) {
3553 pw.print(prefix); pw.print("mLastFreezeDuration=");
3554 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
3555 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003556 if (mHScale != 1 || mVScale != 1) {
3557 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
3558 pw.print(" mVScale="); pw.println(mVScale);
3559 }
3560 if (mWallpaperX != -1 || mWallpaperY != -1) {
3561 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
3562 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
3563 }
3564 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
3565 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
3566 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
3567 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003568 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3569 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
3570 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
3571 pw.print(mWallpaperDisplayOffsetX);
3572 pw.print(" mWallpaperDisplayOffsetY=");
3573 pw.println(mWallpaperDisplayOffsetY);
3574 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003575 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07003576 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003577 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003578 if (isDragResizing()) {
3579 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
3580 }
3581 if (computeDragResizing()) {
3582 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
3583 }
Bryce Lee6311c4b2017-07-06 14:09:29 -07003584 pw.print(prefix); pw.println("isOnScreen=" + isOnScreen());
3585 pw.print(prefix); pw.println("isVisible=" + isVisible());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003586 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003587
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003588 @Override
3589 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003590 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003591 + " " + getWindowTag();
3592 }
3593
Robert Carra1eb4392015-12-10 12:43:51 -08003594 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003595 CharSequence tag = mAttrs.getTitle();
3596 if (tag == null || tag.length() <= 0) {
3597 tag = mAttrs.packageName;
3598 }
3599 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003600 }
3601
3602 @Override
3603 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003604 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003605 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003606 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003607 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003608 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003609 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003610 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003611 }
3612 return mStringNameCache;
3613 }
Robert Carr58f29132015-10-29 14:19:05 -07003614
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003615 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003616 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003617 clipRect.left = (int) (clipRect.left / mHScale);
3618 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003619 }
3620 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003621 clipRect.top = (int) (clipRect.top / mVScale);
3622 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003623 }
3624 }
Robert Carr31e28482015-12-02 16:53:18 -08003625
Jorim Jaggif5834272016-04-04 20:25:41 -07003626 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
3627 final int pw = containingFrame.width();
3628 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003629 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003630 final boolean inNonFullscreenContainer = !inFullscreenContainer();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003631 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3632
3633 // We need to fit it to the display if either
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003634 // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen
3635 // for the taskless windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003636 // b) If it's a secondary app window, we also need to fit it to the display unless
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003637 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on
3638 // screen, but SurfaceViews want to be always at a specific location so we don't fit it to
3639 // the display.
3640 final boolean fitToDisplay = (task == null || !inNonFullscreenContainer)
Robert Carr6f44db12016-07-21 14:54:43 -07003641 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003642 float x, y;
3643 int w,h;
3644
3645 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3646 if (mAttrs.width < 0) {
3647 w = pw;
3648 } else if (mEnforceSizeCompat) {
3649 w = (int)(mAttrs.width * mGlobalScale + .5f);
3650 } else {
3651 w = mAttrs.width;
3652 }
3653 if (mAttrs.height < 0) {
3654 h = ph;
3655 } else if (mEnforceSizeCompat) {
3656 h = (int)(mAttrs.height * mGlobalScale + .5f);
3657 } else {
3658 h = mAttrs.height;
3659 }
3660 } else {
3661 if (mAttrs.width == MATCH_PARENT) {
3662 w = pw;
3663 } else if (mEnforceSizeCompat) {
3664 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3665 } else {
3666 w = mRequestedWidth;
3667 }
3668 if (mAttrs.height == MATCH_PARENT) {
3669 h = ph;
3670 } else if (mEnforceSizeCompat) {
3671 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3672 } else {
3673 h = mRequestedHeight;
3674 }
3675 }
3676
3677 if (mEnforceSizeCompat) {
3678 x = mAttrs.x * mGlobalScale;
3679 y = mAttrs.y * mGlobalScale;
3680 } else {
3681 x = mAttrs.x;
3682 y = mAttrs.y;
3683 }
3684
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003685 if (inNonFullscreenContainer && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003686 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003687 // required by {@link Gravity#apply} call.
3688 w = Math.min(w, pw);
3689 h = Math.min(h, ph);
3690 }
3691
3692 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003693 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003694 (int) (x + mAttrs.horizontalMargin * pw),
3695 (int) (y + mAttrs.verticalMargin * ph), mFrame);
3696
3697 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003698 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003699 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003700 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003701
3702 // We need to make sure we update the CompatFrame as it is used for
3703 // cropping decisions, etc, on systems where we lack a decor layer.
3704 mCompatFrame.set(mFrame);
3705 if (mEnforceSizeCompat) {
3706 // See comparable block in computeFrameLw.
3707 mCompatFrame.scale(mInvGlobalScale);
3708 }
Robert Carr31e28482015-12-02 16:53:18 -08003709 }
Robert Carr51a1b872015-12-08 14:03:13 -08003710
3711 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003712 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003713 }
3714
Robert Carrf3b72c72016-03-21 18:16:39 -07003715 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003716 return mIsChildWindow
3717 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003718 }
3719
Phil Weaverc510ecb2017-08-18 18:01:46 -07003720 /**
3721 * Returns true if any window added by an application process that if of type
3722 * {@link android.view.WindowManager.LayoutParams#TYPE_TOAST} or that requires that requires
3723 * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when
3724 * this window is visible.
3725 */
3726 boolean hideNonSystemOverlayWindowsWhenVisible() {
3727 return (mAttrs.privateFlags & PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != 0
3728 && mSession.mCanHideNonSystemOverlayWindows;
3729 }
3730
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003731 /** Returns the parent window if this is a child of another window, else null. */
3732 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003733 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3734 // WindowContainer that isn't a WindowState.
3735 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003736 }
3737
3738 /** Returns the topmost parent window if this is a child of another window, else this. */
3739 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003740 WindowState current = this;
3741 WindowState topParent = current;
3742 while (current != null && current.mIsChildWindow) {
3743 current = current.getParentWindow();
3744 // Parent window can be null if the child is detached from it's parent already, but
3745 // someone still has a reference to access it. So, we return the top parent value we
3746 // already have instead of null.
3747 if (current != null) {
3748 topParent = current;
3749 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003750 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003751 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003752 }
3753
Wale Ogunwale9d147902016-07-16 11:58:55 -07003754 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003755 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003756 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003757 }
3758
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003759 void setWillReplaceWindow(boolean animate) {
3760 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003761 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003762 c.setWillReplaceWindow(animate);
3763 }
3764
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003765 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3766 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3767 // We don't set replacing on starting windows since they are added by window manager and
3768 // not the client so won't be replaced by the client.
3769 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003770 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003771
3772 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003773 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003774 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003775 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003776
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003777 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003778 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003779 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003780 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003781
3782 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003783 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003784 c.clearWillReplaceWindow();
3785 }
3786 }
3787
3788 boolean waitingForReplacement() {
3789 if (mWillReplaceWindow) {
3790 return true;
3791 }
3792
3793 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003794 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003795 if (c.waitingForReplacement()) {
3796 return true;
3797 }
3798 }
3799 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003800 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003801
Chong Zhang4d7369a2016-04-25 16:09:14 -07003802 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003803 final DisplayContent dc = getDisplayContent();
3804 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3805 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3806 dc.setLayoutNeeded();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003807 mService.mWindowPlacerLocked.requestTraversal();
3808 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003809
3810 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003811 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003812 c.requestUpdateWallpaperIfNeeded();
3813 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003814 }
3815
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003816 float translateToWindowX(float x) {
3817 float winX = x - mFrame.left;
3818 if (mEnforceSizeCompat) {
3819 winX *= mGlobalScale;
3820 }
3821 return winX;
3822 }
3823
3824 float translateToWindowY(float y) {
3825 float winY = y - mFrame.top;
3826 if (mEnforceSizeCompat) {
3827 winY *= mGlobalScale;
3828 }
3829 return winY;
3830 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003831
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003832 private void transferDimToReplacement() {
Robert Carr9fe459d2016-04-07 23:32:28 -07003833 final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003834 final DisplayContent dc = getDisplayContent();
3835 if (dimLayerUser != null && dc != null) {
3836 dc.mDimLayerController.applyDim(dimLayerUser,
3837 mReplacementWindow.mWinAnimator, (mAttrs.flags & FLAG_DIM_BEHIND) != 0);
Robert Carr9fe459d2016-04-07 23:32:28 -07003838 }
3839 }
3840
Robert Carrd1a010f2016-04-07 22:36:22 -07003841 // During activity relaunch due to resize, we sometimes use window replacement
3842 // for only child windows (as the main window is handled by window preservation)
3843 // and the big surface.
3844 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003845 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3846 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3847 // we also want to replace them at such phases, as they won't be covered by window
3848 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003849 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003850 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003851 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003852 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003853
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003854 void setWillReplaceChildWindows() {
3855 if (shouldBeReplacedWithChildren()) {
3856 setWillReplaceWindow(false /* animate */);
3857 }
3858 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003859 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003860 c.setWillReplaceChildWindows();
3861 }
3862 }
3863
3864 WindowState getReplacingWindow() {
3865 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3866 return this;
3867 }
3868 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003869 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003870 final WindowState replacing = c.getReplacingWindow();
3871 if (replacing != null) {
3872 return replacing;
3873 }
3874 }
3875 return null;
3876 }
3877
Jorim Jaggife762342016-10-13 14:33:27 +02003878 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07003879 public int getRotationAnimationHint() {
3880 if (mAppToken != null) {
3881 return mAppToken.mRotationAnimationHint;
3882 } else {
3883 return -1;
3884 }
3885 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003886
Jorim Jaggife762342016-10-13 14:33:27 +02003887 @Override
3888 public boolean isInputMethodWindow() {
3889 return mIsImWindow;
3890 }
3891
Wale Ogunwale9d147902016-07-16 11:58:55 -07003892 // This must be called while inside a transaction.
3893 boolean performShowLocked() {
3894 if (isHiddenFromUserLocked()) {
3895 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3896 hideLw(false);
3897 return false;
3898 }
3899
3900 logPerformShow("performShow on ");
3901
Jorim Jaggia50da602016-12-29 11:51:42 +01003902 final int drawState = mWinAnimator.mDrawState;
3903 if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW)
3904 && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3905 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3906 }
3907
Jorim Jaggib0d27342016-11-01 16:10:42 -07003908 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003909 return false;
3910 }
3911
3912 logPerformShow("Showing ");
3913
3914 mService.enableScreenIfNeededLocked();
3915 mWinAnimator.applyEnterAnimationLocked();
3916
3917 // Force the show in the next prepareSurfaceLocked() call.
3918 mWinAnimator.mLastAlpha = -1;
3919 if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) Slog.v(TAG,
3920 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3921 mWinAnimator.mDrawState = HAS_DRAWN;
3922 mService.scheduleAnimationLocked();
3923
3924 if (mHidden) {
3925 mHidden = false;
3926 final DisplayContent displayContent = getDisplayContent();
3927
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003928 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003929 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003930 if (c.mWinAnimator.mSurfaceController != null) {
3931 c.performShowLocked();
3932 // It hadn't been shown, which means layout not performed on it, so now we
3933 // want to make sure to do a layout. If called from within the transaction
3934 // loop, this will cause it to restart with a new layout.
3935 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003936 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003937 }
3938 }
3939 }
3940 }
3941
Wale Ogunwale9d147902016-07-16 11:58:55 -07003942 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003943 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003944 }
3945
3946 return true;
3947 }
3948
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003949 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003950 if (DEBUG_VISIBILITY
Jorim Jaggie4b0f282017-05-17 15:10:29 +02003951 || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003952 Slog.v(TAG, prefix + this
3953 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07003954 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003955 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3956 + " during animation: policyVis=" + mPolicyVisibility
3957 + " parentHidden=" + isParentWindowHidden()
3958 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003959 + (mAppToken != null && mAppToken.hiddenRequested)
3960 + " tok.hidden=" + (mAppToken != null && mAppToken.hidden)
Wale Ogunwale9d147902016-07-16 11:58:55 -07003961 + " animating=" + mWinAnimator.mAnimating
3962 + " tok animating="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003963 + (mWinAnimator.mAppAnimator != null && mWinAnimator.mAppAnimator.animating)
Wale Ogunwale9d147902016-07-16 11:58:55 -07003964 + " Callers=" + Debug.getCallers(4));
3965 }
3966 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003967
3968 WindowInfo getWindowInfo() {
3969 WindowInfo windowInfo = WindowInfo.obtain();
3970 windowInfo.type = mAttrs.type;
3971 windowInfo.layer = mLayer;
3972 windowInfo.token = mClient.asBinder();
3973 windowInfo.title = mAttrs.accessibilityTitle;
3974 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3975 windowInfo.focused = isFocused();
Phil Weaverf00cd142017-03-03 13:44:00 -08003976 Task task = getTask();
3977 windowInfo.inPictureInPicture = (task != null) && task.inPinnedWorkspace();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003978
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003979 if (mIsChildWindow) {
3980 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003981 }
3982
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003983 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003984 if (childCount > 0) {
3985 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003986 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003987 }
3988 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003989 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003990 windowInfo.childTokens.add(child.mClient.asBinder());
3991 }
3992 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003993 return windowInfo;
3994 }
3995
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003996 int getHighestAnimLayer() {
3997 int highest = mWinAnimator.mAnimLayer;
3998 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003999 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004000 final int childLayer = c.getHighestAnimLayer();
4001 if (childLayer > highest) {
4002 highest = childLayer;
4003 }
4004 }
4005 return highest;
4006 }
4007
Wale Ogunwale9adfe572016-09-08 20:43:58 -07004008 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004009 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004010 if (mChildren.isEmpty()) {
4011 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004012 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004013 }
4014
4015 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004016 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004017 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004018 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004019 }
4020 }
4021
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004022 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004023 // We want to consume the negative sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004024 // below the parent, then this window (the parent), and then the positive sublayer children
4025 // because they need to appear above the parent.
4026 int i = 0;
4027 final int count = mChildren.size();
4028 WindowState child = mChildren.get(i);
4029
4030 while (i < count && child.mSubLayer < 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004031 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004032 return true;
4033 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004034 i++;
4035 if (i >= count) {
4036 break;
4037 }
4038 child = mChildren.get(i);
4039 }
4040
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004041 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004042 return true;
4043 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004044
4045 while (i < count) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004046 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004047 return true;
4048 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004049 i++;
4050 if (i >= count) {
4051 break;
4052 }
4053 child = mChildren.get(i);
4054 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004055
4056 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004057 }
4058
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004059 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004060 // We want to consume the positive sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004061 // above the parent, then this window (the parent), and then the negative sublayer children
4062 // because they need to appear above the parent.
4063 int i = mChildren.size() - 1;
4064 WindowState child = mChildren.get(i);
4065
4066 while (i >= 0 && child.mSubLayer >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004067 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004068 return true;
4069 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004070 --i;
4071 if (i < 0) {
4072 break;
4073 }
4074 child = mChildren.get(i);
4075 }
4076
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004077 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004078 return true;
4079 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004080
4081 while (i >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004082 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004083 return true;
4084 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004085 --i;
4086 if (i < 0) {
4087 break;
4088 }
4089 child = mChildren.get(i);
4090 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004091
4092 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004093 }
4094
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004095 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
4096 boolean traverseTopToBottom) {
4097 if (traverseTopToBottom) {
4098 if (mService.mInputMethodTarget == this) {
4099 // This window is the current IME target, so we need to process the IME windows
4100 // directly above it.
4101 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
4102 return true;
4103 }
4104 }
4105 if (callback.apply(this)) {
4106 return true;
4107 }
4108 } else {
4109 if (callback.apply(this)) {
4110 return true;
4111 }
4112 if (mService.mInputMethodTarget == this) {
4113 // This window is the current IME target, so we need to process the IME windows
4114 // directly above it.
4115 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
4116 return true;
4117 }
4118 }
4119 }
4120
4121 return false;
4122 }
4123
Wale Ogunwaled1880962016-11-08 10:31:59 -08004124 WindowState getWindow(Predicate<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004125 if (mChildren.isEmpty()) {
4126 return callback.test(this) ? this : null;
4127 }
4128
4129 // We want to consume the positive sublayer children first because they need to appear
4130 // above the parent, then this window (the parent), and then the negative sublayer children
4131 // because they need to appear above the parent.
4132 int i = mChildren.size() - 1;
4133 WindowState child = mChildren.get(i);
4134
4135 while (i >= 0 && child.mSubLayer >= 0) {
4136 if (callback.test(child)) {
4137 return child;
4138 }
4139 --i;
4140 if (i < 0) {
4141 break;
4142 }
4143 child = mChildren.get(i);
4144 }
4145
Wale Ogunwaled1880962016-11-08 10:31:59 -08004146 if (callback.test(this)) {
4147 return this;
4148 }
Wale Ogunwale34247952017-02-19 11:57:53 -08004149
4150 while (i >= 0) {
4151 if (callback.test(child)) {
4152 return child;
4153 }
4154 --i;
4155 if (i < 0) {
4156 break;
4157 }
4158 child = mChildren.get(i);
4159 }
4160
4161 return null;
Wale Ogunwaled1880962016-11-08 10:31:59 -08004162 }
4163
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004164 boolean isWindowAnimationSet() {
4165 if (mWinAnimator.isWindowAnimationSet()) {
4166 return true;
4167 }
4168 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004169 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004170 if (c.isWindowAnimationSet()) {
4171 return true;
4172 }
4173 }
4174 return false;
4175 }
4176
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004177 void onExitAnimationDone() {
4178 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
4179 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
4180 + " windowAnimating=" + mWinAnimator.isWindowAnimationSet());
4181
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004182 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004183 // Copying to a different list as multiple children can be removed.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004184 // TODO: Not sure if we really need to copy this into a different list.
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004185 final LinkedList<WindowState> childWindows = new LinkedList(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004186 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004187 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004188 }
4189 }
4190
4191 if (mWinAnimator.mEnteringAnimation) {
4192 mWinAnimator.mEnteringAnimation = false;
4193 mService.requestTraversal();
4194 // System windows don't have an activity and an app token as a result, but need a way
4195 // to be informed about their entrance animation end.
4196 if (mAppToken == null) {
4197 try {
4198 mClient.dispatchWindowShown();
4199 } catch (RemoteException e) {
4200 }
4201 }
4202 }
4203
4204 if (!mWinAnimator.isWindowAnimationSet()) {
4205 //TODO (multidisplay): Accessibility is supported only for the default display.
4206 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
4207 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
4208 }
4209 }
4210
4211 if (!mAnimatingExit) {
4212 return;
4213 }
4214
4215 if (mWinAnimator.isWindowAnimationSet()) {
4216 return;
4217 }
4218
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07004219 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004220 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
4221
4222 mDestroying = true;
4223
4224 final boolean hasSurface = mWinAnimator.hasSurface();
4225 if (hasSurface) {
4226 mWinAnimator.hide("onExitAnimationDone");
4227 }
4228
4229 // If we have an app token, we ask it to destroy the surface for us, so that it can take
4230 // care to ensure the activity has actually stopped and the surface is not still in use.
4231 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
4232 // transaction.
4233 if (mAppToken != null) {
4234 mAppToken.destroySurfaces();
4235 } else {
4236 if (hasSurface) {
4237 mService.mDestroySurface.add(this);
4238 }
4239 if (mRemoveOnExit) {
4240 mService.mPendingRemove.add(this);
4241 mRemoveOnExit = false;
4242 }
4243 }
4244 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07004245 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004246 }
Dan Willemsen117197f2016-07-30 13:02:59 -07004247
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004248 boolean clearAnimatingFlags() {
4249 boolean didSomething = false;
4250 // We don't want to clear it out for windows that get replaced, because the
4251 // animation depends on the flag to remove the replaced window.
4252 //
4253 // We also don't clear the mAnimatingExit flag for windows which have the
4254 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4255 // by the client. We should let animation proceed and not clear this flag or
4256 // they won't eventually be removed by WindowStateAnimator#finishExit.
4257 if (!mWillReplaceWindow && !mRemoveOnExit) {
4258 // Clear mAnimating flag together with mAnimatingExit. When animation
4259 // changes from exiting to entering, we need to clear this flag until the
4260 // new animation gets applied, so that isAnimationStarting() becomes true
4261 // until then.
4262 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4263 // placement for this window during this period, one or more frame will
4264 // show up with wrong position or scale.
4265 if (mAnimatingExit) {
4266 mAnimatingExit = false;
4267 didSomething = true;
4268 }
4269 if (mWinAnimator.mAnimating) {
4270 mWinAnimator.mAnimating = false;
4271 didSomething = true;
4272 }
4273 if (mDestroying) {
4274 mDestroying = false;
4275 mService.mDestroySurface.remove(this);
4276 didSomething = true;
4277 }
4278 }
4279
4280 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004281 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004282 }
4283
4284 return didSomething;
4285 }
4286
Winson4b4ba902016-07-27 19:45:52 -07004287 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004288 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004289 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004290
4291 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004292 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004293 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004294 c.hideWallpaperWindow(wasDeferred, reason);
4295 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004296 if (!mWinAnimator.mLastHidden || wasDeferred) {
4297 mWinAnimator.hide(reason);
4298 dispatchWallpaperVisibility(false);
4299 final DisplayContent displayContent = getDisplayContent();
4300 if (displayContent != null) {
4301 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
4302 }
4303 }
4304 }
4305
4306 /**
4307 * Check wallpaper window for visibility change and notify window if so.
4308 * @param visible Current visibility.
4309 */
4310 void dispatchWallpaperVisibility(final boolean visible) {
4311 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07004312 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004313
4314 // Only send notification if the visibility actually changed and we are not trying to hide
4315 // the wallpaper when we are deferring hiding of the wallpaper.
4316 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4317 mWallpaperVisible = visible;
4318 try {
4319 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4320 "Updating vis of wallpaper " + this
4321 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4322 mClient.dispatchAppVisibility(visible);
4323 } catch (RemoteException e) {
4324 }
4325 }
4326 }
4327
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004328 boolean hasVisibleNotDrawnWallpaper() {
4329 if (mWallpaperVisible && !isDrawnLw()) {
4330 return true;
4331 }
4332 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004333 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004334 if (c.hasVisibleNotDrawnWallpaper()) {
4335 return true;
4336 }
4337 }
4338 return false;
4339 }
4340
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004341 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4342 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004343 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004344 c.updateReportedVisibility(results);
4345 }
4346
4347 if (mAppFreezing || mViewVisibility != View.VISIBLE
4348 || mAttrs.type == TYPE_APPLICATION_STARTING
4349 || mDestroying) {
4350 return;
4351 }
4352 if (DEBUG_VISIBILITY) {
4353 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
4354 + ", isAnimationSet=" + mWinAnimator.isAnimationSet());
4355 if (!isDrawnLw()) {
4356 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4357 + " pv=" + mPolicyVisibility
4358 + " mDrawState=" + mWinAnimator.mDrawState
4359 + " ph=" + isParentWindowHidden()
4360 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
4361 + " a=" + mWinAnimator.mAnimating);
4362 }
4363 }
4364
4365 results.numInteresting++;
4366 if (isDrawnLw()) {
4367 results.numDrawn++;
4368 if (!mWinAnimator.isAnimationSet()) {
4369 results.numVisible++;
4370 }
4371 results.nowGone = false;
4372 } else if (mWinAnimator.isAnimationSet()) {
4373 results.nowGone = false;
4374 }
4375 }
4376
Robert Carrfbbde852016-10-18 11:02:28 -07004377 /**
4378 * Calculate the window crop according to system decor policy. In general this is
4379 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4380 * special cases. This rectangle is in screen space.
4381 */
4382 void calculatePolicyCrop(Rect policyCrop) {
4383 final DisplayContent displayContent = getDisplayContent();
4384 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
4385
4386 if (!isDefaultDisplay()) {
4387 // On a different display there is no system decor. Crop the window
4388 // by the screen boundaries.
4389 // TODO(multi-display)
4390 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4391 policyCrop.intersect(-mCompatFrame.left, -mCompatFrame.top,
4392 displayInfo.logicalWidth - mCompatFrame.left,
4393 displayInfo.logicalHeight - mCompatFrame.top);
4394 } else if (mLayer >= mService.mSystemDecorLayer) {
4395 // Above the decor layer is easy, just use the entire window
4396 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4397 } else if (mDecorFrame.isEmpty()) {
4398 // Windows without policy decor aren't cropped.
4399 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4400 } else {
4401 // Crop to the system decor specified by policy.
4402 calculateSystemDecorRect(policyCrop);
4403 }
4404 }
4405
4406 /**
4407 * The system decor rect is the region of the window which is not covered
4408 * by system decorations.
4409 */
4410 private void calculateSystemDecorRect(Rect systemDecorRect) {
4411 final Rect decorRect = mDecorFrame;
4412 final int width = mFrame.width();
4413 final int height = mFrame.height();
4414
4415 // Compute the offset of the window in relation to the decor rect.
4416 final int left = mXOffset + mFrame.left;
4417 final int top = mYOffset + mFrame.top;
4418
4419 // Initialize the decor rect to the entire frame.
4420 if (isDockedResizing()) {
4421 // If we are resizing with the divider, the task bounds might be smaller than the
4422 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4423 // want in this case in order to avoid holes.
4424 //
4425 // We take care to not shrink the width, for surfaces which are larger than
4426 // the display region. Of course this area will not eventually be visible
4427 // but if we truncate the width now, we will calculate incorrectly
4428 // when adjusting to the stack bounds.
4429 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4430 systemDecorRect.set(0, 0,
4431 Math.max(width, displayInfo.logicalWidth),
4432 Math.max(height, displayInfo.logicalHeight));
4433 } else {
4434 systemDecorRect.set(0, 0, width, height);
4435 }
4436
4437 // If a freeform window is animating from a position where it would be cutoff, it would be
4438 // cutoff during the animation. We don't want that, so for the duration of the animation
4439 // we ignore the decor cropping and depend on layering to position windows correctly.
4440 final boolean cropToDecor = !(inFreeformWorkspace() && isAnimatingLw());
4441 if (cropToDecor) {
4442 // Intersect with the decor rect, offsetted by window position.
4443 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
4444 decorRect.right - left, decorRect.bottom - top);
4445 }
4446
4447 // If size compatibility is being applied to the window, the
4448 // surface is scaled relative to the screen. Also apply this
4449 // scaling to the crop rect. We aren't using the standard rect
4450 // scale function because we want to round things to make the crop
4451 // always round to a larger rect to ensure we don't crop too
4452 // much and hide part of the window that should be seen.
4453 if (mEnforceSizeCompat && mInvGlobalScale != 1.0f) {
4454 final float scale = mInvGlobalScale;
4455 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
4456 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
4457 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
4458 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
4459 }
4460
4461 }
4462
4463 /**
4464 * Expand the given rectangle by this windows surface insets. This
4465 * takes you from the 'window size' to the 'surface size'.
4466 * The surface insets are positive in each direction, so we inset by
4467 * the inverse.
4468 */
4469 void expandForSurfaceInsets(Rect r) {
4470 r.inset(-mAttrs.surfaceInsets.left,
4471 -mAttrs.surfaceInsets.top,
4472 -mAttrs.surfaceInsets.right,
4473 -mAttrs.surfaceInsets.bottom);
4474 }
4475
Robert Carrc91d1c32017-02-15 19:37:46 -08004476 boolean surfaceInsetsChanging() {
4477 return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets);
4478 }
4479
Bryce Leef858b572017-06-29 14:03:33 -07004480 int relayoutVisibleWindow(int result, int attrChanges, int oldVisibility) {
Robert Carrecc06b32017-04-18 14:25:10 -07004481 final boolean wasVisible = isVisibleLw();
4482
4483 result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004484 if (mAnimatingExit) {
4485 Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit="
4486 + mRemoveOnExit + ", mDestroying=" + mDestroying);
4487
4488 mWinAnimator.cancelExitAnimationForNextAnimationLocked();
4489 mAnimatingExit = false;
4490 }
4491 if (mDestroying) {
4492 mDestroying = false;
4493 mService.mDestroySurface.remove(this);
4494 }
4495 if (oldVisibility == View.GONE) {
4496 mWinAnimator.mEnterAnimationPending = true;
4497 }
4498
Andrii Kulian8ee72852017-03-10 10:36:45 -08004499 mLastVisibleLayoutRotation = getDisplayContent().getRotation();
Robert Carrc91d1c32017-02-15 19:37:46 -08004500
4501 mWinAnimator.mEnteringAnimation = true;
Bryce Leeae73ba42017-05-05 09:58:25 -07004502
Bryce Leef858b572017-06-29 14:03:33 -07004503 prepareWindowToDisplayDuringRelayout(wasVisible);
Bryce Leeae73ba42017-05-05 09:58:25 -07004504
Robert Carrc91d1c32017-02-15 19:37:46 -08004505 if ((attrChanges & FORMAT_CHANGED) != 0) {
4506 // If the format can't be changed in place, preserve the old surface until the app draws
4507 // on the new one. This prevents blinking when we change elevation of freeform and
4508 // pinned windows.
4509 if (!mWinAnimator.tryChangeFormatInPlaceLocked()) {
4510 mWinAnimator.preserveSurfaceLocked();
4511 result |= RELAYOUT_RES_SURFACE_CHANGED
4512 | RELAYOUT_RES_FIRST_TIME;
4513 }
4514 }
4515
4516 // When we change the Surface size, in scenarios which may require changing
4517 // the surface position in sync with the resize, we use a preserved surface
4518 // so we can freeze it while waiting for the client to report draw on the newly
Winson Chung8bca9e42017-04-16 15:59:43 -07004519 // sized surface. Don't preserve surfaces if the insets change while animating the pinned
4520 // stack since it can lead to issues if a new surface is created while calculating the
4521 // scale for the animation using the source hint rect
4522 // (see WindowStateAnimator#setSurfaceBoundariesLocked()).
Robert Carrc91d1c32017-02-15 19:37:46 -08004523 if (isDragResizeChanged() || isResizedWhileNotDragResizing()
Winson Chung8bca9e42017-04-16 15:59:43 -07004524 || (surfaceInsetsChanging() && !inPinnedWorkspace())) {
Robert Carrc91d1c32017-02-15 19:37:46 -08004525 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
4526
4527 setDragResizing();
4528 setResizedWhileNotDragResizing(false);
4529 // We can only change top level windows to the full-screen surface when
4530 // resizing (as we only have one full-screen surface). So there is no need
4531 // to preserve and destroy windows which are attached to another, they
4532 // will keep their surface and its size may change over time.
4533 if (mHasSurface && !isChildWindow()) {
4534 mWinAnimator.preserveSurfaceLocked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08004535 result |= RELAYOUT_RES_SURFACE_CHANGED |
4536 RELAYOUT_RES_FIRST_TIME;
Robert Carrc91d1c32017-02-15 19:37:46 -08004537 }
4538 }
4539 final boolean freeformResizing = isDragResizing()
4540 && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
4541 final boolean dockedResizing = isDragResizing()
4542 && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
4543 result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0;
4544 result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0;
4545 if (isAnimatingWithSavedSurface()) {
4546 // If we're animating with a saved surface now, request client to report draw.
4547 // We still need to know when the real thing is drawn.
4548 result |= RELAYOUT_RES_FIRST_TIME;
4549 }
4550 return result;
4551 }
4552
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004553 /**
4554 * @return True if this window has been laid out at least once; false otherwise.
4555 */
4556 boolean isLaidOut() {
4557 return mLayoutSeq != -1;
4558 }
4559
4560 /**
4561 * Updates the last inset values to the current ones.
4562 */
4563 void updateLastInsetValues() {
4564 mLastOverscanInsets.set(mOverscanInsets);
4565 mLastContentInsets.set(mContentInsets);
4566 mLastVisibleInsets.set(mVisibleInsets);
4567 mLastStableInsets.set(mStableInsets);
4568 mLastOutsets.set(mOutsets);
4569 }
4570
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004571 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4572 // access to its windows children. Need to investigate re-writing
4573 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4574 static final class UpdateReportedVisibilityResults {
4575 int numInteresting;
4576 int numVisible;
4577 int numDrawn;
4578 boolean nowGone = true;
4579
4580 void reset() {
4581 numInteresting = 0;
4582 numVisible = 0;
4583 numDrawn = 0;
4584 nowGone = true;
4585 }
4586 }
Robert Carraf422a82017-04-10 18:34:33 -07004587
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004588 private static final class WindowId extends IWindowId.Stub {
4589 private final WeakReference<WindowState> mOuter;
4590
4591 private WindowId(WindowState outer) {
4592
4593 // Use a weak reference for the outer class. This is important to prevent the following
4594 // leak: Since we send this class to the client process, binder will keep it alive as
4595 // long as the client keeps it alive. Now, if the window is removed, we need to clear
4596 // out our reference so even though this class is kept alive we don't leak WindowState,
4597 // which can keep a whole lot of classes alive.
4598 mOuter = new WeakReference<>(outer);
4599 }
4600
4601 @Override
4602 public void registerFocusObserver(IWindowFocusObserver observer) {
4603 final WindowState outer = mOuter.get();
4604 if (outer != null) {
4605 outer.registerFocusObserver(observer);
4606 }
4607 }
4608 @Override
4609 public void unregisterFocusObserver(IWindowFocusObserver observer) {
4610 final WindowState outer = mOuter.get();
4611 if (outer != null) {
4612 outer.unregisterFocusObserver(observer);
4613 }
4614 }
4615 @Override
4616 public boolean isFocused() {
4617 final WindowState outer = mOuter.get();
4618 return outer != null && outer.isFocused();
4619 }
4620 }
4621
Robert Carraf422a82017-04-10 18:34:33 -07004622 boolean usesRelativeZOrdering() {
4623 if (!isChildWindow()) {
4624 return false;
4625 } else if (mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) {
4626 return true;
4627 } else {
4628 return false;
4629 }
4630 }
satokcef37fb2011-10-24 21:49:38 +09004631}