blob: e38605d33f26b59b5a32af35b5fb93f997c24b33 [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.StackId.INVALID_STACK_ID;
Jorim Jaggi02886a82016-12-06 09:10:06 -080020import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
21import static android.view.Display.DEFAULT_DISPLAY;
22import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
23import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
24import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
25import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
Robert Carrb1579c82017-09-05 14:54:47 -070026import static android.view.SurfaceControl.Transaction;
Jorim Jaggi02886a82016-12-06 09:10:06 -080027import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
28import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW;
29import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
30import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
31import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
32import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
33import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
34import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
35import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
36import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080037import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
38import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
39import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Robert Carrc91d1c32017-02-15 19:37:46 -080040import static android.view.WindowManager.LayoutParams.FORMAT_CHANGED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080041import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
42import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
43import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070044import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Jorim Jaggi02886a82016-12-06 09:10:06 -080045import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
46import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
47import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
48import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
49import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
50import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Robert Carraf422a82017-04-10 18:34:33 -070051import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
Robert Carr0eff1872017-12-01 14:27:04 -080052import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;
Jorim Jaggi02886a82016-12-06 09:10:06 -080053import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
54import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
55import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
56import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
57import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
58import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Robert Carrb1579c82017-09-05 14:54:47 -070059import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY;
60import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
Robert Carree4d4b92017-11-22 12:21:46 -080061import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;
Robert Carrb1579c82017-09-05 14:54:47 -070062import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070063import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Jorim Jaggi02886a82016-12-06 09:10:06 -080064import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Wale Ogunwale01ad4342017-06-30 07:07:01 -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;
Adrian Roose99bc052017-11-20 17:55:31 +010070import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
71import static com.android.server.policy.WindowManagerPolicy.TRANSIT_ENTER;
72import static com.android.server.policy.WindowManagerPolicy.TRANSIT_EXIT;
73import static com.android.server.policy.WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
Jorim Jaggi02886a82016-12-06 09:10:06 -080074import 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_VISIBILITY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080090import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
91import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
92import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
93import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
94import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
95import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
96import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
97import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
98import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
99import static com.android.server.wm.WindowManagerService.localLOGV;
100import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING;
101import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
102import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN;
103import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700104import static com.android.server.wm.proto.IdentifierProto.HASH_CODE;
105import static com.android.server.wm.proto.IdentifierProto.TITLE;
106import static com.android.server.wm.proto.IdentifierProto.USER_ID;
107import static com.android.server.wm.proto.WindowStateProto.ANIMATING_EXIT;
108import static com.android.server.wm.proto.WindowStateProto.ANIMATOR;
109import static com.android.server.wm.proto.WindowStateProto.ATTRIBUTES;
110import static com.android.server.wm.proto.WindowStateProto.CHILD_WINDOWS;
111import static com.android.server.wm.proto.WindowStateProto.CONTAINING_FRAME;
112import static com.android.server.wm.proto.WindowStateProto.CONTENT_FRAME;
113import static com.android.server.wm.proto.WindowStateProto.CONTENT_INSETS;
114import static com.android.server.wm.proto.WindowStateProto.DISPLAY_ID;
115import static com.android.server.wm.proto.WindowStateProto.FRAME;
116import static com.android.server.wm.proto.WindowStateProto.GIVEN_CONTENT_INSETS;
117import static com.android.server.wm.proto.WindowStateProto.IDENTIFIER;
118import static com.android.server.wm.proto.WindowStateProto.PARENT_FRAME;
119import static com.android.server.wm.proto.WindowStateProto.STACK_ID;
120import static com.android.server.wm.proto.WindowStateProto.SURFACE_INSETS;
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700121import static com.android.server.wm.proto.WindowStateProto.WINDOW_CONTAINER;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800122
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700123import android.annotation.CallSuper;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800124import android.app.AppOpsManager;
125import android.content.Context;
126import android.content.res.Configuration;
127import android.graphics.Matrix;
128import android.graphics.PixelFormat;
129import android.graphics.Point;
130import android.graphics.Rect;
131import android.graphics.Region;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700132import android.os.Binder;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700133import android.os.Debug;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800134import android.os.IBinder;
135import android.os.PowerManager;
136import android.os.RemoteCallbackList;
137import android.os.RemoteException;
138import android.os.SystemClock;
139import android.os.Trace;
140import android.os.UserHandle;
141import android.os.WorkSource;
142import android.util.DisplayMetrics;
Jorim Jaggie7d2b852017-08-28 17:55:15 +0200143import android.util.MergedConfiguration;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800144import android.util.Slog;
145import android.util.TimeUtils;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700146import android.util.proto.ProtoOutputStream;
Adrian Roos5c6b6222017-11-07 17:36:10 +0100147import android.view.DisplayCutout;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800148import android.view.DisplayInfo;
149import android.view.Gravity;
150import android.view.IApplicationToken;
151import android.view.IWindow;
152import android.view.IWindowFocusObserver;
153import android.view.IWindowId;
154import android.view.InputChannel;
155import android.view.InputEvent;
156import android.view.InputEventReceiver;
Robert Carrb1579c82017-09-05 14:54:47 -0700157import android.view.SurfaceControl;
158import android.view.SurfaceSession;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800159import android.view.View;
160import android.view.ViewTreeObserver;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700161import android.view.WindowInfo;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800162import android.view.WindowManager;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800163
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800164import com.android.internal.util.ToBooleanFunction;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800165import com.android.server.input.InputWindowHandle;
Adrian Roose99bc052017-11-20 17:55:31 +0100166import com.android.server.policy.WindowManagerPolicy;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800167
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800168import java.io.PrintWriter;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200169import java.lang.ref.WeakReference;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800170import java.util.ArrayList;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700171import java.util.Comparator;
172import java.util.LinkedList;
Wale Ogunwaled1880962016-11-08 10:31:59 -0800173import java.util.function.Predicate;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800174
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700175/** A window in the window manager. */
176class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800177 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800178
Skuhne81c524a2015-08-12 13:34:14 -0700179 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700180 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
181 // use hard-coded min sizes for now.
182 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
183 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700184
185 // The thickness of a window resize handle outside the window bounds on the free form workspace
186 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700187 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700188
Craig Mautnere7ae2502012-03-26 17:11:19 -0700189 final WindowManagerPolicy mPolicy;
190 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800191 final Session mSession;
192 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800193 final int mAppOp;
194 // UserId and appId of the owner. Don't display windows of non-current user.
195 final int mOwnerUid;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800196 /** The owner has {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} */
197 final boolean mOwnerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200198 final WindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800199 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700200 // The same object as mToken if this is an app window and null for non-app windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800201 AppWindowToken mAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700202
203 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
204 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800205 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
206 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700207 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800208 final int mBaseLayer;
209 final int mSubLayer;
210 final boolean mLayoutAttached;
211 final boolean mIsImWindow;
212 final boolean mIsWallpaper;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700213 private final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700214 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700215 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800216 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700217 int mSystemUiVisibility;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700218 /**
219 * The visibility of the window based on policy like {@link WindowManagerPolicy}.
220 * Normally set by calling {@link #showLw} and {@link #hideLw}.
221 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800222 boolean mPolicyVisibility = true;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700223 /**
224 * What {@link #mPolicyVisibility} should be set to after a transition animation.
225 * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and
226 * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit
227 * animation is done.
228 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800229 boolean mPolicyVisibilityAfterAnim = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700230 private boolean mAppOpVisibility = true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700231 boolean mPermanentlyHidden; // the window should never be shown again
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700232 // This is a non-system overlay window that is currently force hidden.
233 private boolean mForceHideNonSystemOverlayWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800234 boolean mAppFreezing;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700235 boolean mHidden; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800236 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700237 private boolean mDragResizing;
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200238 private boolean mDragResizingChangeReported = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700239 private int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700240
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700241 private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800242
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700243 /**
244 * The window size that was requested by the application. These are in
245 * the application's coordinate space (without compatibility scale applied).
246 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800247 int mRequestedWidth;
248 int mRequestedHeight;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700249 private int mLastRequestedWidth;
250 private int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700251
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800252 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800253 boolean mHaveFrame;
254 boolean mObscured;
255 boolean mTurnOnScreen;
256
257 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700258
Andrii Kulian9d91ca62016-09-29 22:28:09 -0700259 /**
260 * Used to store last reported to client configuration and check if we have newer available.
261 * We'll send configuration to client only if it is different from the last applied one and
262 * client won't perform unnecessary updates.
263 */
Bryce Lee2b17afd2017-09-21 10:38:20 -0700264 private final MergedConfiguration mLastReportedConfiguration = new MergedConfiguration();
Craig Mautnera2c77052012-03-26 12:14:43 -0700265
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700266 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700267 * Actual position of the surface shown on-screen (may be modified by animation). These are
268 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700269 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700270 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800271
272 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700273 * Insets that determine the actually visible area. These are in the application's
274 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800275 */
276 final Rect mVisibleInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700277 private final Rect mLastVisibleInsets = new Rect();
278 private boolean mVisibleInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800279
280 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700281 * Insets that are covered by system windows (such as the status bar) and
282 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700283 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800284 */
285 final Rect mContentInsets = new Rect();
286 final Rect mLastContentInsets = new Rect();
Robert Carr18f622f2017-05-08 11:20:43 -0700287
288 /**
289 * The last content insets returned to the client in relayout. We use
290 * these in the bounds animation to ensure we only observe inset changes
291 * at the same time that a client resizes it's surface so that we may use
292 * the geometryAppliesWithResize synchronization mechanism to keep
293 * the contents in place.
294 */
295 final Rect mLastRelayoutContentInsets = new Rect();
296
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700297 private boolean mContentInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800298
299 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800300 * Insets that determine the area covered by the display overscan region. These are in the
301 * application's coordinate space (without compatibility scale applied).
302 */
303 final Rect mOverscanInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700304 private final Rect mLastOverscanInsets = new Rect();
305 private boolean mOverscanInsetsChanged;
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800306
307 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700308 * Insets that determine the area covered by the stable system windows. These are in the
309 * application's coordinate space (without compatibility scale applied).
310 */
311 final Rect mStableInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700312 private final Rect mLastStableInsets = new Rect();
313 private boolean mStableInsetsChanged;
Adrian Roosfa104232014-06-20 16:10:14 -0700314
315 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700316 * Outsets determine the area outside of the surface where we want to pretend that it's possible
317 * to draw anyway.
318 */
319 final Rect mOutsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700320 private final Rect mLastOutsets = new Rect();
321 private boolean mOutsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700322
Adrian Roos5c6b6222017-11-07 17:36:10 +0100323 /** Part of the display that has been cut away. See {@link DisplayCutout}. */
324 DisplayCutout mDisplayCutout = DisplayCutout.NO_CUTOUT;
325 private DisplayCutout mLastDisplayCutout = DisplayCutout.NO_CUTOUT;
326 private boolean mDisplayCutoutChanged;
327
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700328 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800329 * Set to true if we are waiting for this window to receive its
330 * given internal insets before laying out other windows based on it.
331 */
332 boolean mGivenInsetsPending;
333
334 /**
335 * These are the content insets that were given during layout for
336 * this window, to be applied to windows behind it.
337 */
338 final Rect mGivenContentInsets = new Rect();
339
340 /**
341 * These are the visible insets that were given during layout for
342 * this window, to be applied to windows behind it.
343 */
344 final Rect mGivenVisibleInsets = new Rect();
345
346 /**
347 * This is the given touchable area relative to the window frame, or null if none.
348 */
349 final Region mGivenTouchableRegion = new Region();
350
351 /**
352 * Flag indicating whether the touchable region should be adjusted by
353 * the visible insets; if false the area outside the visible insets is
354 * NOT touchable, so we must use those to adjust the frame during hit
355 * tests.
356 */
357 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
358
359 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400360 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700361 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800362 float mHScale=1, mVScale=1;
363 float mLastHScale=1, mLastVScale=1;
364 final Matrix mTmpMatrix = new Matrix();
365
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700366 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800367 final Rect mFrame = new Rect();
368 final Rect mLastFrame = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700369 private boolean mFrameSizeChanged = false;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700370 // Frame that is scaled to the application's coordinate space when in
371 // screen size compatibility mode.
372 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800373
374 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700375
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700376 private final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700377
Wale Ogunwale94596652015-02-06 19:27:34 -0800378 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
379 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700380 final Rect mDisplayFrame = new Rect();
381
382 // The region of the display frame that the display type supports displaying content on. This
383 // is mostly a special case for TV where some displays don’t have the entire display usable.
384 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
385 // window display contents to extend into the overscan region.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700386 private final Rect mOverscanFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700387
388 // The display frame minus the stable insets. This value is always constant regardless of if
389 // the status bar or navigation bar is visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700390 private final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800391
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700392 // The area not occupied by the status and navigation bars. So, if both status and navigation
393 // bars are visible, the decor frame is equal to the stable frame.
394 final Rect mDecorFrame = new Rect();
395
396 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
397 // minus the area occupied by the IME if the IME is present.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700398 private final Rect mContentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700399
400 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
401 // displays hint text.
402 final Rect mVisibleFrame = new Rect();
403
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700404 // Frame that includes dead area outside of the surface but where we want to pretend that it's
405 // possible to draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700406 private final Rect mOutsetFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700407
Jorim Jaggidc249c42015-12-15 14:57:31 -0800408 /**
409 * Usually empty. Set to the task's tempInsetFrame. See
410 *{@link android.app.IActivityManager#resizeDockedStack}.
411 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700412 private final Rect mInsetFrame = new Rect();
Jorim Jaggidc249c42015-12-15 14:57:31 -0800413
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800414 boolean mContentChanged;
415
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800416 // If a window showing a wallpaper: the requested offset for the
417 // wallpaper; if a wallpaper window: the currently applied offset.
418 float mWallpaperX = -1;
419 float mWallpaperY = -1;
420
421 // If a window showing a wallpaper: what fraction of the offset
422 // range corresponds to a full virtual screen.
423 float mWallpaperXStep = -1;
424 float mWallpaperYStep = -1;
425
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700426 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
427 // to its window; if a wallpaper window: not used.
428 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
429 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
430
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800431 // Wallpaper windows: pixels offset based on above variables.
432 int mXOffset;
433 int mYOffset;
434
Craig Mautner2268e7e2012-12-13 15:40:00 -0800435 /**
436 * This is set after IWindowSession.relayout() has been called at
437 * least once for the window. It allows us to detect the situation
438 * where we don't yet have a surface, but should have one soon, so
439 * we can give the window focus before waiting for the relayout.
440 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800441 boolean mRelayoutCalled;
442
Robert Carrfed10072016-05-26 11:48:49 -0700443 boolean mInRelayout;
444
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800445 /**
446 * If the application has called relayout() with changes that can
447 * impact its window's size, we need to perform a layout pass on it
448 * even if it is not currently visible for layout. This is set
449 * when in that case until the layout is done.
450 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800451 boolean mLayoutNeeded;
452
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800453 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800454 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800455
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800456 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800457 boolean mDestroying;
458
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800459 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800460 boolean mRemoveOnExit;
461
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800462 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800463 * Whether the app died while it was visible, if true we might need
464 * to continue to show it until it's restarted.
465 */
466 boolean mAppDied;
467
468 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800469 * Set when the orientation is changing and this window has not yet
470 * been updated for the new orientation.
471 */
Bryce Lee8c3cf382017-07-06 19:47:10 -0700472 private boolean mOrientationChanging;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800473
Dianne Hackborna57c6952013-03-29 14:46:40 -0700474 /**
Robert Carr9c1c3a02017-08-08 12:59:01 -0700475 * Sometimes in addition to the mOrientationChanging
476 * flag we report that the orientation is changing
477 * due to a mismatch in current and reported configuration.
478 *
479 * In the case of timeout we still need to make sure we
480 * leave the orientation changing state though, so we
481 * use this as a special time out escape hatch.
482 */
483 private boolean mOrientationChangeTimedOut;
484
485 /**
Robert Carr237028a2016-07-26 10:39:45 -0700486 * The orientation during the last visible call to relayout. If our
487 * current orientation is different, the window can't be ready
488 * to be shown.
489 */
490 int mLastVisibleLayoutRotation = -1;
491
492 /**
Andrii Kulianb2e37802017-01-11 00:36:44 -0800493 * Set when we need to report the orientation change to client to trigger a relayout.
494 */
495 boolean mReportOrientationChanged;
496
497 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700498 * How long we last kept the screen frozen.
499 */
500 int mLastFreezeDuration;
501
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800502 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800503 boolean mRemoved;
504
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800505 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800506 * It is save to remove the window and destroy the surface because the client requested removal
507 * or some other higher level component said so (e.g. activity manager).
508 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800509 */
Svetoslav Ganov200adfb2016-10-18 13:29:27 -0700510 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800511
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800512 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700513 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800514 InputChannel mInputChannel;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700515 private InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800516
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800517 // Used to improve performance of toString()
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700518 private String mStringNameCache;
519 private CharSequence mLastTitle;
520 private boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800521
Craig Mautnera2c77052012-03-26 12:14:43 -0700522 final WindowStateAnimator mWinAnimator;
523
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700524 boolean mHasSurface = false;
525
Craig Mautner88400d32012-09-30 12:35:45 -0700526 /** When true this window can be displayed on screens owther than mOwnerUid's */
527 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700528
Chong Zhang92147042016-05-09 12:47:11 -0700529 // Whether the window was visible when we set the app to invisible last time. WM uses
530 // this as a hint to restore the surface (if available) for early animation next time
531 // the app is brought visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700532 private boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800533
Robert Carra1eb4392015-12-10 12:43:51 -0800534 // This window will be replaced due to relaunch. This allows window manager
535 // to differentiate between simple removal of a window and replacement. In the latter case it
536 // will preserve the old window until the new one is drawn.
537 boolean mWillReplaceWindow = false;
538 // If true, the replaced window was already requested to be removed.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700539 private boolean mReplacingRemoveRequested = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800540 // Whether the replacement of the window should trigger app transition animation.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700541 private boolean mAnimateReplacingWindow = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800542 // If not null, the window that will be used to replace the old one. This is being set when
543 // the window is added and unset when this window reports its first draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700544 private WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700545 // For the new window in the replacement transition, if we have
546 // requested to replace without animation, then we should
547 // make sure we also don't apply an enter animation for
548 // the new window.
549 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800550 // Whether this window is being moved via the resize API
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700551 private boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800552
Jeff Brownc2932a12014-11-20 18:04:05 -0800553 /**
554 * Wake lock for drawing.
555 * Even though it's slightly more expensive to do so, we will use a separate wake lock
556 * for each app that is requesting to draw while dozing so that we can accurately track
557 * who is preventing the system from suspending.
558 * This lock is only acquired on first use.
559 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700560 private PowerManager.WakeLock mDrawLock;
Jeff Brownc2932a12014-11-20 18:04:05 -0800561
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700562 final private Rect mTmpRect = new Rect();
563
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800564 /**
565 * Whether the window was resized by us while it was gone for layout.
566 */
567 boolean mResizedWhileGone = false;
568
Andrii Kulianeb1d3222016-05-16 15:17:55 -0700569 /** @see #isResizedWhileNotDragResizing(). */
570 private boolean mResizedWhileNotDragResizing;
571
572 /** @see #isResizedWhileNotDragResizingReported(). */
573 private boolean mResizedWhileNotDragResizingReported;
Jorim Jaggif3df0aa2016-04-06 15:56:33 -0700574
Robert Carr6da3cc02016-06-16 15:17:07 -0700575 /**
576 * During seamless rotation we have two phases, first the old window contents
577 * are rotated to look as if they didn't move in the new coordinate system. Then we
578 * have to freeze updates to this layer (to preserve the transformation) until
579 * the resize actually occurs. This is true from when the transformation is set
580 * and false until the transaction to resize is sent.
581 */
582 boolean mSeamlesslyRotated = false;
583
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700584 /**
Robert Carrc91d1c32017-02-15 19:37:46 -0800585 * Surface insets from the previous call to relayout(), used to track
586 * if we are changing the Surface insets.
587 */
588 final Rect mLastSurfaceInsets = new Rect();
589
590 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700591 * A flag set by the {@link WindowState} parent to indicate that the parent has examined this
592 * {@link WindowState} in its overall drawing context. This book-keeping allows the parent to
593 * make sure all children have been considered.
594 */
595 private boolean mDrawnStateEvaluated;
596
597 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700598 * 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 -0700599 * of z-order and 1 otherwise.
600 */
Griff Hazen51d00d82016-11-22 15:39:24 -0800601 private static final Comparator<WindowState> sWindowSubLayerComparator =
602 new Comparator<WindowState>() {
603 @Override
604 public int compare(WindowState w1, WindowState w2) {
605 final int layer1 = w1.mSubLayer;
606 final int layer2 = w2.mSubLayer;
607 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
608 // We insert the child window into the list ordered by
609 // the sub-layer. For same sub-layers, the negative one
610 // should go below others; the positive one should go
611 // above others.
612 return -1;
613 }
614 return 1;
615 };
616 };
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700617
Robert Carrf59b8dd2017-10-02 18:58:36 -0700618 /**
619 * Indicates whether we have requested a Dim (in the sense of {@link Dimmer}) from our host
620 * container.
621 */
622 private boolean mIsDimming = false;
623
624 private static final float DEFAULT_DIM_AMOUNT_DEAD_WINDOW = 0.5f;
625
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800626 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700627 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800628 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100629 super(service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800630 mSession = s;
631 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800632 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800633 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700634 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700635 mOwnerUid = ownerId;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800636 mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200637 mWindowId = new WindowId(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800638 mAttrs.copyFrom(a);
639 mViewVisibility = viewVisibility;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700640 mPolicy = mService.mPolicy;
641 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800642 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700643 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700644 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700645 if (localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700646 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700647 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800648 try {
649 c.asBinder().linkToDeath(deathRecipient, 0);
650 } catch (RemoteException e) {
651 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700652 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800653 mLayoutAttached = false;
654 mIsImWindow = false;
655 mIsWallpaper = false;
656 mIsFloatingLayer = false;
657 mBaseLayer = 0;
658 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700659 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700660 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800661 return;
662 }
663 mDeathRecipient = deathRecipient;
664
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700665 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800666 // The multiplier here is to reserve space for multiple
667 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800668 mBaseLayer = mPolicy.getWindowLayerLw(parentWindow)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700669 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800670 mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700671 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900672
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700673 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow);
674 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900675
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800676 mLayoutAttached = mAttrs.type !=
677 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700678 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
679 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
680 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800681 } else {
682 // The multiplier here is to reserve space for multiple
683 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800684 mBaseLayer = mPolicy.getWindowLayerLw(this)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700685 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800686 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700687 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800688 mLayoutAttached = false;
689 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
690 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
691 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800692 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700693 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800694
Wale Ogunwale72919d22016-12-08 18:58:50 -0800695 if (mAppToken != null && mAppToken.mShowForAllUsers) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700696 // Windows for apps that can show for all users should also show when the device is
697 // locked.
698 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
Craig Mautner19ab8282014-05-07 10:35:34 -0700699 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800700
Craig Mautner322e4032012-07-13 13:35:20 -0700701 mWinAnimator = new WindowStateAnimator(this);
702 mWinAnimator.mAlpha = a.alpha;
703
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800704 mRequestedWidth = 0;
705 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700706 mLastRequestedWidth = 0;
707 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800708 mXOffset = 0;
709 mYOffset = 0;
710 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800711 mInputWindowHandle = new InputWindowHandle(
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800712 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this, c,
713 getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800714 }
715
716 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700717 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800718 mSession.windowAddedLocked(mAttrs.packageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800719 }
720
Bryce Leed390deb2017-06-22 13:14:28 -0700721 /**
722 * Returns whether this {@link WindowState} has been considered for drawing by its parent.
723 */
Bryce Lee6311c4b2017-07-06 14:09:29 -0700724 boolean getDrawnStateEvaluated() {
Bryce Leed390deb2017-06-22 13:14:28 -0700725 return mDrawnStateEvaluated;
726 }
727
728 /**
729 * Sets whether this {@link WindowState} has been considered for drawing by its parent. Should
730 * be cleared when detached from parent.
731 */
732 void setDrawnStateEvaluated(boolean evaluated) {
733 mDrawnStateEvaluated = evaluated;
734 }
735
736 @Override
737 void onParentSet() {
738 super.onParentSet();
739 setDrawnStateEvaluated(false /*evaluated*/);
740 }
741
Craig Mautnera2c77052012-03-26 12:14:43 -0700742 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800743 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800744 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800745 }
746
747 @Override
748 public String getOwningPackage() {
749 return mAttrs.packageName;
750 }
751
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800752 @Override
753 public boolean canAddInternalSystemWindow() {
754 return mOwnerCanAddInternalSystemWindow;
755 }
756
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200757 @Override
758 public boolean canAcquireSleepToken() {
759 return mSession.mCanAcquireSleepToken;
760 }
761
Jorim Jaggif5834272016-04-04 20:25:41 -0700762 /**
763 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
764 * from {@param frame}. In other words, it applies the insets that would result if
765 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700766 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
767 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700768 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700769 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
770 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
771 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
772 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
773 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700774 frame.inset(left, top, right, bottom);
775 }
776
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800777 @Override
Robert Carr43521762016-10-28 13:15:04 -0700778 public void computeFrameLw(Rect parentFrame, Rect displayFrame, Rect overscanFrame,
779 Rect contentFrame, Rect visibleFrame, Rect decorFrame, Rect stableFrame,
Adrian Roos5c6b6222017-11-07 17:36:10 +0100780 Rect outsetFrame, DisplayCutout displayCutout) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800781 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700782 // This window is being replaced and either already got information that it's being
783 // removed or we are still waiting for some information. Because of this we don't
784 // want to apply any more changes to it, so it remains in this state until new window
785 // appears.
786 return;
787 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800788 mHaveFrame = true;
789
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700790 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700791 final boolean inFullscreenContainer = inFullscreenContainer();
Robert Carre6275582016-02-29 15:45:45 -0800792 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700793 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800794
Chong Zhangae35fef2016-03-16 15:56:55 -0700795 // If the task has temp inset bounds set, we have to make sure all its windows uses
796 // the temp inset frame. Otherwise different display frames get applied to the main
797 // window and the child window, making them misaligned.
Andrii Kulianc24f3732017-08-08 19:35:17 -0700798 if (inFullscreenContainer || isLetterboxedAppWindow()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700799 mInsetFrame.setEmpty();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700800 } else if (task != null && isInMultiWindowMode()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700801 task.getTempInsetBounds(mInsetFrame);
802 }
803
Jorim Jaggif5834272016-04-04 20:25:41 -0700804 // Denotes the actual frame used to calculate the insets and to perform the layout. When
805 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
806 // insets temporarily. By the notion of a task having a different layout frame, we can
807 // achieve that while still moving the task around.
808 final Rect layoutContainingFrame;
809 final Rect layoutDisplayFrame;
810
811 // The offset from the layout containing frame to the actual containing frame.
812 final int layoutXDiff;
813 final int layoutYDiff;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700814 if (inFullscreenContainer || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800815 // We use the parent frame as the containing frame for fullscreen and child windows
Robert Carr43521762016-10-28 13:15:04 -0700816 mContainingFrame.set(parentFrame);
817 mDisplayFrame.set(displayFrame);
818 layoutDisplayFrame = displayFrame;
819 layoutContainingFrame = parentFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700820 layoutXDiff = 0;
821 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800822 } else {
Bryce Leef3c6a472017-11-14 14:53:06 -0800823 getBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100824 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
825
826 // If the bounds are frozen, we still want to translate the window freely and only
827 // freeze the size.
828 Rect frozen = mAppToken.mFrozenBounds.peek();
829 mContainingFrame.right = mContainingFrame.left + frozen.width();
830 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
831 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800832 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700833 // IME is up and obscuring this window. Adjust the window position so it is visible.
834 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this) {
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700835 if (inFreeformWindowingMode()
Winson Chungd73e94b2017-05-31 16:25:30 -0700836 && mContainingFrame.bottom > contentFrame.bottom) {
837 // In freeform we want to move the top up directly.
838 // TODO: Investigate why this is contentFrame not parentFrame.
839 mContainingFrame.top -= mContainingFrame.bottom - contentFrame.bottom;
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700840 } else if (!inPinnedWindowingMode()
Winson Chungd73e94b2017-05-31 16:25:30 -0700841 && mContainingFrame.bottom > parentFrame.bottom) {
842 // But in docked we want to behave like fullscreen and behave as if the task
843 // were given smaller bounds for the purposes of layout. Skip adjustments for
844 // the pinned stack, they are handled separately in the PinnedStackController.
845 mContainingFrame.bottom = parentFrame.bottom;
846 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700847 }
Skuhne81c524a2015-08-12 13:34:14 -0700848
Robert Carre6275582016-02-29 15:45:45 -0800849 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700850 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
851 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800852 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700853 if (mContainingFrame.isEmpty()) {
Robert Carr43521762016-10-28 13:15:04 -0700854 mContainingFrame.set(contentFrame);
Skuhne81c524a2015-08-12 13:34:14 -0700855 }
Doris Liu06d582d2015-06-01 13:18:43 -0700856 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800857 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700858 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
859 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
860 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700861 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
Robert Carr43521762016-10-28 13:15:04 -0700862 subtractInsets(mDisplayFrame, layoutContainingFrame, displayFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700863 if (!layoutInParentFrame()) {
Robert Carr43521762016-10-28 13:15:04 -0700864 subtractInsets(mContainingFrame, layoutContainingFrame, parentFrame, mTmpRect);
865 subtractInsets(mInsetFrame, layoutContainingFrame, parentFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700866 }
Robert Carr43521762016-10-28 13:15:04 -0700867 layoutDisplayFrame = displayFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700868 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700869 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800870
Craig Mautner967212c2013-04-13 21:10:58 -0700871 final int pw = mContainingFrame.width();
872 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800873
Robert Carr43521762016-10-28 13:15:04 -0700874 if (!mParentFrame.equals(parentFrame)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800875 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Robert Carr43521762016-10-28 13:15:04 -0700876 // + " to " + parentFrame);
877 mParentFrame.set(parentFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800878 mContentChanged = true;
879 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700880 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
881 mLastRequestedWidth = mRequestedWidth;
882 mLastRequestedHeight = mRequestedHeight;
883 mContentChanged = true;
884 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800885
Robert Carr43521762016-10-28 13:15:04 -0700886 mOverscanFrame.set(overscanFrame);
887 mContentFrame.set(contentFrame);
888 mVisibleFrame.set(visibleFrame);
889 mDecorFrame.set(decorFrame);
890 mStableFrame.set(stableFrame);
891 final boolean hasOutsets = outsetFrame != null;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700892 if (hasOutsets) {
Robert Carr43521762016-10-28 13:15:04 -0700893 mOutsetFrame.set(outsetFrame);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700894 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800895
Craig Mautnereda67292013-04-28 13:50:14 -0700896 final int fw = mFrame.width();
897 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800898
Jorim Jaggif5834272016-04-04 20:25:41 -0700899 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
900
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700901 // Calculate the outsets before the content frame gets shrinked to the window frame.
902 if (hasOutsets) {
903 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
904 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
905 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
906 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
907 } else {
908 mOutsets.set(0, 0, 0, 0);
909 }
910
Craig Mautnera248eee2013-05-07 11:41:27 -0700911 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800912 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -0800913 if (windowsAreFloating && !mFrame.isEmpty()) {
Robert Carre65a1c42017-02-28 16:52:59 -0800914 // For pinned workspace the frame isn't limited in any particular
915 // way since SystemUI controls the bounds. For freeform however
916 // we want to keep things inside the content frame.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700917 final Rect limitFrame = task.inPinnedWindowingMode() ? mFrame : mContentFrame;
Skuhne81c524a2015-08-12 13:34:14 -0700918 // Keep the frame out of the blocked system area, limit it in size to the content area
919 // and make sure that there is always a minimum visible so that the user can drag it
920 // into a usable area..
Robert Carre65a1c42017-02-28 16:52:59 -0800921 final int height = Math.min(mFrame.height(), limitFrame.height());
922 final int width = Math.min(limitFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700923 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +0900924 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
925 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
926 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
927 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Robert Carre65a1c42017-02-28 16:52:59 -0800928 final int top = Math.max(limitFrame.top,
929 Math.min(mFrame.top, limitFrame.bottom - minVisibleHeight));
930 final int left = Math.max(limitFrame.left + minVisibleWidth - width,
931 Math.min(mFrame.left, limitFrame.right - minVisibleWidth));
Skuhne81c524a2015-08-12 13:34:14 -0700932 mFrame.set(left, top, left + width, top + height);
933 mContentFrame.set(mFrame);
934 mVisibleFrame.set(mContentFrame);
935 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700936 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700937 dc.getDockedDividerController().positionDockedStackedDivider(mFrame);
Jorim Jaggi192086e2016-03-11 17:17:03 +0100938 mContentFrame.set(mFrame);
939 if (!mFrame.equals(mLastFrame)) {
940 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800941 }
Skuhne81c524a2015-08-12 13:34:14 -0700942 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -0700943 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
944 Math.max(mContentFrame.top, mFrame.top),
945 Math.min(mContentFrame.right, mFrame.right),
946 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800947
Jorim Jaggi656f6502016-04-11 21:08:17 -0700948 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
949 Math.max(mVisibleFrame.top, mFrame.top),
950 Math.min(mVisibleFrame.right, mFrame.right),
951 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800952
Jorim Jaggi656f6502016-04-11 21:08:17 -0700953 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
954 Math.max(mStableFrame.top, mFrame.top),
955 Math.min(mStableFrame.right, mFrame.right),
956 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700957 }
Adrian Roosfa104232014-06-20 16:10:14 -0700958
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700959 if (inFullscreenContainer && !windowsAreFloating) {
Jorim Jaggi899327f2016-02-25 20:44:18 -0500960 // Windows that are not fullscreen can be positioned outside of the display frame,
961 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -0700962 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
963 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
964 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
965 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800966 }
Craig Mautnereda67292013-04-28 13:50:14 -0700967
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100968 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100969 // For the docked divider, we calculate the stable insets like a full-screen window
970 // so it can use it to calculate the snap positions.
971 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
972 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
973 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
974 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800975
976 // The divider doesn't care about insets in any case, so set it to empty so we don't
977 // trigger a relayout when moving it.
978 mContentInsets.setEmpty();
979 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100980 } else {
Bryce Leef3c6a472017-11-14 14:53:06 -0800981 getDisplayContent().getBounds(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -0700982 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
983 // non-fullscreen mode.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700984 boolean overrideRightInset = !windowsAreFloating && !inFullscreenContainer
985 && mFrame.right > mTmpRect.right;
986 boolean overrideBottomInset = !windowsAreFloating && !inFullscreenContainer
987 && mFrame.bottom > mTmpRect.bottom;
Jorim Jaggi656f6502016-04-11 21:08:17 -0700988 mContentInsets.set(mContentFrame.left - mFrame.left,
989 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700990 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700991 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700992 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -0700993 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -0800994
Jorim Jaggi656f6502016-04-11 21:08:17 -0700995 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
996 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -0700997 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -0700998 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -0700999 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -07001000 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -08001001
Jorim Jaggi656f6502016-04-11 21:08:17 -07001002 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
1003 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -07001004 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -07001005 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -07001006 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -07001007 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001008 }
Adrian Roosfa104232014-06-20 16:10:14 -07001009
Jorim Jaggi656f6502016-04-11 21:08:17 -07001010 // Offset the actual frame by the amount layout frame is off.
1011 mFrame.offset(-layoutXDiff, -layoutYDiff);
1012 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -07001013 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
1014 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
1015 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
1016
Adrian Roos5c6b6222017-11-07 17:36:10 +01001017 // TODO(roosa): Figure out what frame exactly this needs to be calculated with.
1018 mDisplayCutout = displayCutout.calculateRelativeTo(mFrame);
1019
1020
Craig Mautnereda67292013-04-28 13:50:14 -07001021 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001022 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001023 // If there is a size compatibility scale being applied to the
1024 // window, we need to apply this to its insets so that they are
1025 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -07001026 mOverscanInsets.scale(mInvGlobalScale);
1027 mContentInsets.scale(mInvGlobalScale);
1028 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -07001029 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001030 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001031
1032 // Also the scaled frame that we report to the app needs to be
1033 // adjusted to be in its coordinate space.
1034 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001035 }
1036
Craig Mautnereda67292013-04-28 13:50:14 -07001037 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001038 final DisplayContent displayContent = getDisplayContent();
1039 if (displayContent != null) {
1040 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwale0303c572016-10-20 10:16:29 -07001041 getDisplayContent().mWallpaperController.updateWallpaperOffset(
Wale Ogunwalee8069dc2015-08-18 09:52:01 -07001042 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001043 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001044 }
1045
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001046 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001047 "Resolving (mRequestedWidth="
1048 + mRequestedWidth + ", mRequestedheight="
1049 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
1050 + "): frame=" + mFrame.toShortString()
1051 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07001052 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -07001053 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001054 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001055 }
1056
Bryce Leef3c6a472017-11-14 14:53:06 -08001057 // TODO: Look into whether this override is still necessary.
1058 @Override
1059 public Rect getBounds() {
1060 if (isInMultiWindowMode()) {
1061 return getTask().getBounds();
1062 } else if (mAppToken != null){
1063 return mAppToken.getBounds();
1064 } else {
1065 return super.getBounds();
1066 }
1067 }
1068
Craig Mautnera2c77052012-03-26 12:14:43 -07001069 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001070 public Rect getFrameLw() {
1071 return mFrame;
1072 }
1073
Craig Mautnera2c77052012-03-26 12:14:43 -07001074 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001075 public Point getShownPositionLw() {
1076 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001077 }
1078
Craig Mautnera2c77052012-03-26 12:14:43 -07001079 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001080 public Rect getDisplayFrameLw() {
1081 return mDisplayFrame;
1082 }
1083
Craig Mautnera2c77052012-03-26 12:14:43 -07001084 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001085 public Rect getOverscanFrameLw() {
1086 return mOverscanFrame;
1087 }
1088
1089 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001090 public Rect getContentFrameLw() {
1091 return mContentFrame;
1092 }
1093
Craig Mautnera2c77052012-03-26 12:14:43 -07001094 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001095 public Rect getVisibleFrameLw() {
1096 return mVisibleFrame;
1097 }
1098
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001099 Rect getStableFrameLw() {
1100 return mStableFrame;
1101 }
1102
Craig Mautnera2c77052012-03-26 12:14:43 -07001103 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001104 public boolean getGivenInsetsPendingLw() {
1105 return mGivenInsetsPending;
1106 }
1107
Craig Mautnera2c77052012-03-26 12:14:43 -07001108 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001109 public Rect getGivenContentInsetsLw() {
1110 return mGivenContentInsets;
1111 }
1112
Craig Mautnera2c77052012-03-26 12:14:43 -07001113 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001114 public Rect getGivenVisibleInsetsLw() {
1115 return mGivenVisibleInsets;
1116 }
1117
Craig Mautnera2c77052012-03-26 12:14:43 -07001118 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001119 public WindowManager.LayoutParams getAttrs() {
1120 return mAttrs;
1121 }
1122
Craig Mautner812d2ca2012-09-27 15:35:34 -07001123 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001124 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001125 return getDisplayContent().getNeedsMenu(this, bottom);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001126 }
1127
Craig Mautner19d59bc2012-09-04 11:15:56 -07001128 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001129 public int getSystemUiVisibility() {
1130 return mSystemUiVisibility;
1131 }
1132
Craig Mautner19d59bc2012-09-04 11:15:56 -07001133 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001134 public int getSurfaceLayer() {
1135 return mLayer;
1136 }
1137
Craig Mautner812d2ca2012-09-27 15:35:34 -07001138 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001139 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001140 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001141 }
1142
1143 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001144 public IApplicationToken getAppToken() {
1145 return mAppToken != null ? mAppToken.appToken : null;
1146 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001147
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001148 @Override
1149 public boolean isVoiceInteraction() {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001150 return mAppToken != null && mAppToken.mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001151 }
1152
Robert Carr31aa98b2016-07-20 15:29:03 -07001153 boolean setReportResizeHints() {
Craig Mautner4c5eb222013-11-18 12:59:05 -08001154 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1155 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1156 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001157 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001158 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
Robert Carr31aa98b2016-07-20 15:29:03 -07001159 mFrameSizeChanged |= (mLastFrame.width() != mFrame.width()) ||
1160 (mLastFrame.height() != mFrame.height());
Adrian Roos5c6b6222017-11-07 17:36:10 +01001161 mDisplayCutoutChanged |= !mLastDisplayCutout.equals(mDisplayCutout);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001162 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
Adrian Roos5c6b6222017-11-07 17:36:10 +01001163 || mOutsetsChanged || mFrameSizeChanged || mDisplayCutoutChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001164 }
1165
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001166 /**
1167 * Adds the window to the resizing list if any of the parameters we use to track the window
1168 * dimensions or insets have changed.
1169 */
1170 void updateResizingWindowIfNeeded() {
1171 final WindowStateAnimator winAnimator = mWinAnimator;
1172 if (!mHasSurface || mService.mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
1173 return;
1174 }
1175
1176 final Task task = getTask();
1177 // In the case of stack bound animations, the window frames will update (unlike other
1178 // animations which just modify various transformation properties). We don't want to
1179 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1180 // the frame may not correspond to the surface size or the onscreen area at various
1181 // phases in the animation, and the client will become sad and confused.
Winson Chung40a5f932017-04-13 16:39:36 -07001182 if (task != null && task.mStack.isAnimatingBounds()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001183 return;
1184 }
1185
1186 setReportResizeHints();
1187 boolean configChanged = isConfigChanged();
1188 if (DEBUG_CONFIGURATION && configChanged) {
1189 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1190 }
1191
1192 final boolean dragResizingChanged = isDragResizeChanged()
1193 && !isDragResizingChangeReported();
1194
1195 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
1196 + " dragResizingChanged=" + dragResizingChanged + " last=" + mLastFrame
1197 + " frame=" + mFrame);
1198
1199 // We update mLastFrame always rather than in the conditional with the last inset
1200 // variables, because mFrameSizeChanged only tracks the width and height changing.
1201 mLastFrame.set(mFrame);
1202
1203 if (mContentInsetsChanged
1204 || mVisibleInsetsChanged
1205 || winAnimator.mSurfaceResized
1206 || mOutsetsChanged
1207 || mFrameSizeChanged
Adrian Roos5c6b6222017-11-07 17:36:10 +01001208 || mDisplayCutoutChanged
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001209 || configChanged
1210 || dragResizingChanged
Andrii Kulianb2e37802017-01-11 00:36:44 -08001211 || !isResizedWhileNotDragResizingReported()
1212 || mReportOrientationChanged) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001213 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1214 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
1215 + " contentInsetsChanged=" + mContentInsetsChanged
1216 + " " + mContentInsets.toShortString()
1217 + " visibleInsetsChanged=" + mVisibleInsetsChanged
1218 + " " + mVisibleInsets.toShortString()
1219 + " stableInsetsChanged=" + mStableInsetsChanged
1220 + " " + mStableInsets.toShortString()
1221 + " outsetsChanged=" + mOutsetsChanged
1222 + " " + mOutsets.toShortString()
1223 + " surfaceResized=" + winAnimator.mSurfaceResized
1224 + " configChanged=" + configChanged
1225 + " dragResizingChanged=" + dragResizingChanged
1226 + " resizedWhileNotDragResizingReported="
Andrii Kulianb2e37802017-01-11 00:36:44 -08001227 + isResizedWhileNotDragResizingReported()
Adrian Roos5c6b6222017-11-07 17:36:10 +01001228 + " reportOrientationChanged=" + mReportOrientationChanged
1229 + " displayCutoutChanged=" + mDisplayCutoutChanged);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001230 }
1231
1232 // If it's a dead window left on screen, and the configuration changed, there is nothing
1233 // we can do about it. Remove the window now.
1234 if (mAppToken != null && mAppDied) {
1235 mAppToken.removeDeadWindows();
1236 return;
1237 }
1238
Jorim Jaggidc9385a2017-05-13 02:00:31 +02001239 updateLastInsetValues();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001240 mService.makeWindowFreezingScreenIfNeededLocked(this);
1241
1242 // If the orientation is changing, or we're starting or ending a drag resizing action,
1243 // then we need to hold off on unfreezing the display until this window has been
1244 // redrawn; to do that, we need to go through the process of getting informed by the
1245 // application when it has finished drawing.
Bryce Lee8c3cf382017-07-06 19:47:10 -07001246 if (getOrientationChanging() || dragResizingChanged
1247 || isResizedWhileNotDragResizing()) {
Robert Carre13b58e2017-08-31 14:50:44 -07001248 if (DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001249 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1250 + ", mDrawState=DRAW_PENDING in " + this
1251 + ", surfaceController " + winAnimator.mSurfaceController);
1252 }
1253 winAnimator.mDrawState = DRAW_PENDING;
1254 if (mAppToken != null) {
1255 mAppToken.clearAllDrawn();
1256 }
1257 }
1258 if (!mService.mResizingWindows.contains(this)) {
1259 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
1260 mService.mResizingWindows.add(this);
1261 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07001262 } else if (getOrientationChanging()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001263 if (isDrawnLw()) {
1264 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1265 + this + ", surfaceController " + winAnimator.mSurfaceController);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001266 setOrientationChanging(false);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001267 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1268 - mService.mDisplayFreezeTime);
1269 }
1270 }
1271 }
1272
Bryce Lee8c3cf382017-07-06 19:47:10 -07001273 boolean getOrientationChanging() {
1274 // In addition to the local state flag, we must also consider the difference in the last
1275 // reported configuration vs. the current state. If the client code has not been informed of
1276 // the change, logic dependent on having finished processing the orientation, such as
1277 // unfreezing, could be improperly triggered.
1278 // TODO(b/62846907): Checking against {@link mLastReportedConfiguration} could be flaky as
1279 // this is not necessarily what the client has processed yet. Find a
1280 // better indicator consistent with the client.
Robert Carr926643f2017-08-02 12:01:12 -07001281 return (mOrientationChanging || (isVisible()
Bryce Lee2b17afd2017-09-21 10:38:20 -07001282 && getConfiguration().orientation != getLastReportedConfiguration().orientation))
Robert Carr9c1c3a02017-08-08 12:59:01 -07001283 && !mSeamlesslyRotated
1284 && !mOrientationChangeTimedOut;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001285 }
1286
1287 void setOrientationChanging(boolean changing) {
1288 mOrientationChanging = changing;
Robert Carr9c1c3a02017-08-08 12:59:01 -07001289 mOrientationChangeTimedOut = false;
1290 }
1291
1292 void orientationChangeTimedOut() {
1293 mOrientationChangeTimedOut = true;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001294 }
1295
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001296 DisplayContent getDisplayContent() {
1297 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001298 }
1299
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001300 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001301 final DisplayContent displayContent = getDisplayContent();
1302 return displayContent != null ? displayContent.getDisplayInfo() : null;
1303 }
1304
Jorim Jaggife762342016-10-13 14:33:27 +02001305 @Override
1306 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001307 final DisplayContent displayContent = getDisplayContent();
1308 if (displayContent == null) {
1309 return -1;
1310 }
1311 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001312 }
1313
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001314 Task getTask() {
Bryce Lee6d410262017-02-28 15:30:17 -08001315 return mAppToken != null ? mAppToken.getTask() : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001316 }
1317
1318 TaskStack getStack() {
1319 Task task = getTask();
1320 if (task != null) {
1321 if (task.mStack != null) {
1322 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001323 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001324 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001325 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1326 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001327 final DisplayContent dc = getDisplayContent();
1328 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001329 }
1330
Skuhnef932e562015-08-20 12:07:30 -07001331 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001332 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001333 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001334 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001335 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001336 final Task task = getTask();
1337 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001338 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001339 mTmpRect.setEmpty();
1340 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001341 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001342 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001343 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001344 } else {
1345 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001346 }
1347 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001348
Chong Zhang9184ec62015-09-24 12:32:21 -07001349 bounds.set(mVisibleFrame);
1350 if (intersectWithStackBounds) {
1351 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001352 }
1353
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001354 if (bounds.isEmpty()) {
1355 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001356 if (intersectWithStackBounds) {
1357 bounds.intersect(mTmpRect);
1358 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001359 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001360 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001361 }
1362
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001363 public long getInputDispatchingTimeoutNanos() {
1364 return mAppToken != null
Wale Ogunwale72919d22016-12-08 18:58:50 -08001365 ? mAppToken.mInputDispatchingTimeoutNanos
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001366 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1367 }
1368
Craig Mautnere8552142012-11-07 13:55:47 -08001369 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001370 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001371 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001372 }
1373
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001374 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1375 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1376 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1377 if (dtdx < -.000001f || dtdx > .000001f) return false;
1378 if (dsdy < -.000001f || dsdy > .000001f) return false;
1379 return true;
1380 }
1381
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001382 void prelayout() {
1383 if (mEnforceSizeCompat) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001384 mGlobalScale = getDisplayContent().mCompatibleScreenScale;
1385 mInvGlobalScale = 1 / mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001386 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001387 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001388 }
1389 }
1390
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001391 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001392 boolean hasContentToDisplay() {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001393 if (!mAppFreezing && isDrawnLw() && (mViewVisibility == View.VISIBLE
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001394 || (mWinAnimator.isAnimationSet() && !mService.mAppTransition.isTransitionSet()))) {
1395 return true;
1396 }
1397
Wale Ogunwale44f21802016-09-02 12:49:48 -07001398 return super.hasContentToDisplay();
1399 }
1400
1401 @Override
1402 boolean isVisible() {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001403 return wouldBeVisibleIfPolicyIgnored() && mPolicyVisibility;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001404 }
1405
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001406 /**
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001407 * @return True if the window would be visible if we'd ignore policy visibility, false
1408 * otherwise.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001409 */
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001410 boolean wouldBeVisibleIfPolicyIgnored() {
Jorim Jaggi43530c92017-05-18 01:53:56 +02001411 return mHasSurface && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001412 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001413 }
1414
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001415 @Override
1416 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001417 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001418 }
1419
1420 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001421 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1422 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001423 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001424 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1425 boolean isWinVisibleLw() {
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001426 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.mAppAnimator.animating)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001427 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001428 }
1429
1430 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001431 * The same as isVisible(), but follows the current hidden state of the associated app token,
1432 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001433 */
1434 boolean isVisibleNow() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001435 return (!mToken.hidden || mAttrs.type == TYPE_APPLICATION_STARTING)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001436 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001437 }
1438
1439 /**
1440 * Can this window possibly be a drag/drop target? The test here is
1441 * a combination of the above "visible now" with the check that the
1442 * Input Manager uses when discarding windows from input consideration.
1443 */
1444 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001445 return isVisibleNow() && !mRemoved
1446 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001447 }
1448
1449 /**
1450 * Same as isVisible(), but we also count it as visible between the
1451 * call to IWindowSession.add() and the first relayout().
1452 */
1453 boolean isVisibleOrAdding() {
1454 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001455 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001456 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001457 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001458 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001459 }
1460
1461 /**
1462 * Is this window currently on-screen? It is on-screen either if it
1463 * is visible or it is currently running an animation before no longer
1464 * being visible.
1465 */
1466 boolean isOnScreen() {
Jorim Jaggiaf221d12016-11-15 14:59:57 -08001467 if (!mHasSurface || mDestroying || !mPolicyVisibility) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001468 return false;
1469 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001470 final AppWindowToken atoken = mAppToken;
1471 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001472 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001473 || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001474 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07001475 return !isParentWindowHidden() || mWinAnimator.mAnimation != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001476 }
1477
1478 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001479 * Whether this window's drawn state might affect the drawn states of the app token.
1480 *
Chong Zhang8e4bda92016-05-04 15:08:18 -07001481 * @return true if the window should be considered while evaluating allDrawn flags.
1482 */
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001483 boolean mightAffectAllDrawn() {
1484 final boolean isAppType = mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1485 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION;
1486 return (isOnScreen() || isAppType) && !mAnimatingExit && !mDestroying;
Chong Zhang8e4bda92016-05-04 15:08:18 -07001487 }
1488
1489 /**
1490 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1491 * it must be drawn before allDrawn can become true.
1492 */
1493 boolean isInteresting() {
1494 return mAppToken != null && !mAppDied
1495 && (!mAppToken.mAppAnimator.freezingScreen || !mAppFreezing);
1496 }
1497
1498 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001499 * Like isOnScreen(), but we don't return true if the window is part
1500 * of a transition that has not yet been started.
1501 */
1502 boolean isReadyForDisplay() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001503 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001504 return false;
1505 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001506 return mHasSurface && mPolicyVisibility && !mDestroying
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001507 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.hidden)
Craig Mautnera2c77052012-03-26 12:14:43 -07001508 || mWinAnimator.mAnimation != null
Craig Mautner59431632012-04-04 11:56:44 -07001509 || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001510 }
1511
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001512 // TODO: Another visibility method that was added late in the release to minimize risk.
1513 @Override
1514 public boolean canAffectSystemUiFlags() {
Jorim Jaggib7202a82017-09-11 16:58:53 +02001515 final boolean shown = mWinAnimator.getShown();
Jorim Jaggic0c93242017-08-04 16:05:02 +02001516
1517 // We only consider the app to be exiting when the animation has started. After the app
1518 // transition is executed the windows are marked exiting before the new windows have been
1519 // shown. Thus, wait considering a window to be exiting after the animation has actually
1520 // started.
1521 final boolean appAnimationStarting = mAppToken != null
1522 && mAppToken.mAppAnimator.isAnimationStarting();
1523 final boolean exitingSelf = mAnimatingExit && (!mWinAnimator.isAnimationStarting()
1524 && !appAnimationStarting);
1525 final boolean appExiting = mAppToken != null && mAppToken.hidden && !appAnimationStarting;
1526
1527 final boolean exiting = exitingSelf || mDestroying || appExiting;
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001528 final boolean translucent = mAttrs.alpha == 0.0f;
Jorim Jaggib7202a82017-09-11 16:58:53 +02001529
1530 // If we are entering with a dummy animation, avoid affecting SystemUI flags until the
1531 // transition is starting.
1532 final boolean enteringWithDummyAnimation =
1533 mWinAnimator.isDummyAnimation() && mWinAnimator.mShownAlpha == 0f;
1534 return shown && !exiting && !translucent && !enteringWithDummyAnimation;
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001535 }
1536
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001537 /**
1538 * Like isOnScreen, but returns false if the surface hasn't yet
1539 * been drawn.
1540 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001541 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001542 public boolean isDisplayedLw() {
1543 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001544 return isDrawnLw() && mPolicyVisibility
Wale Ogunwale9d147902016-07-16 11:58:55 -07001545 && ((!isParentWindowHidden() &&
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001546 (atoken == null || !atoken.hiddenRequested))
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001547 || mWinAnimator.mAnimating
1548 || (atoken != null && atoken.mAppAnimator.animation != null));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001549 }
1550
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001551 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001552 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001553 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001554 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001555 public boolean isAnimatingLw() {
Craig Mautnerae446592012-12-06 19:05:05 -08001556 return mWinAnimator.mAnimation != null
1557 || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001558 }
1559
Craig Mautner812d2ca2012-09-27 15:35:34 -07001560 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001561 public boolean isGoneForLayoutLw() {
1562 final AppWindowToken atoken = mAppToken;
1563 return mViewVisibility == View.GONE
1564 || !mRelayoutCalled
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001565 || (atoken == null && mToken.hidden)
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001566 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001567 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001568 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001569 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001570 }
1571
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001572 /**
1573 * Returns true if the window has a surface that it has drawn a
1574 * complete UI in to.
1575 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001576 public boolean isDrawFinishedLw() {
1577 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001578 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1579 || mWinAnimator.mDrawState == READY_TO_SHOW
1580 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001581 }
1582
1583 /**
1584 * Returns true if the window has a surface that it has drawn a
1585 * complete UI in to.
1586 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001587 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001588 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001589 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001590 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001591 }
1592
1593 /**
1594 * Return true if the window is opaque and fully drawn. This indicates
1595 * it may obscure windows behind it.
1596 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001597 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001598 // When there is keyguard, wallpaper could be placed over the secure app
1599 // window but invisible. We need to check wallpaper visibility explicitly
1600 // to determine if it's occluding apps.
1601 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1602 || (mIsWallpaper && mWallpaperVisible))
Craig Mautnera2c77052012-03-26 12:14:43 -07001603 && isDrawnLw() && mWinAnimator.mAnimation == null
Craig Mautner59431632012-04-04 11:56:44 -07001604 && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001605 }
1606
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001607 @Override
1608 void onMovedByResize() {
1609 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001610 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001611 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001612 }
1613
1614 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1615 boolean changed = false;
1616
1617 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001618 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001619 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1620 }
1621
1622 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1623 // Starting window that's exiting will be removed when the animation finishes.
1624 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1625 // to actually remove it.
1626 if (!visible && isVisibleNow() && mAppToken.mAppAnimator.isAnimating()) {
1627 mAnimatingExit = true;
1628 mRemoveOnExit = true;
1629 mWindowRemovalAllowed = true;
1630 }
1631 return changed;
1632 }
1633
Robert Carrd5c7dd62017-03-08 10:39:30 -08001634 // Next up we will notify the client that it's visibility has changed.
1635 // We need to prevent it from destroying child surfaces until
1636 // the animation has finished.
1637 if (!visible && isVisibleNow()) {
1638 mWinAnimator.detachChildren();
1639 }
1640
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001641 if (visible != isVisibleNow()) {
1642 if (!runningAppAnimation) {
1643 final AccessibilityController accessibilityController =
1644 mService.mAccessibilityController;
1645 final int winTransit = visible ? TRANSIT_ENTER : TRANSIT_EXIT;
1646 mWinAnimator.applyAnimationLocked(winTransit, visible);
1647 //TODO (multidisplay): Magnification is supported only for the default
1648 if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
1649 accessibilityController.onWindowTransitionLocked(this, winTransit);
1650 }
1651 }
1652 changed = true;
1653 setDisplayLayoutNeeded();
1654 }
1655
1656 return changed;
1657 }
1658
1659 boolean onSetAppExiting() {
1660 final DisplayContent displayContent = getDisplayContent();
1661 boolean changed = false;
1662
1663 if (isVisibleNow()) {
1664 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
1665 //TODO (multidisplay): Magnification is supported only for the default
1666 if (mService.mAccessibilityController != null && isDefaultDisplay()) {
1667 mService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
1668 }
1669 changed = true;
1670 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001671 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001672 }
1673 }
1674
1675 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001676 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001677 changed |= c.onSetAppExiting();
1678 }
1679
1680 return changed;
1681 }
1682
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001683 @Override
1684 void onResize() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001685 final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
1686 if (mHasSurface && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001687 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001688 resizingWindows.add(this);
1689
1690 // If we are not drag resizing, force recreating of a new surface so updating
1691 // the content and positioning that surface will be in sync.
1692 //
1693 // As we use this flag as a hint to freeze surface boundary updates, we'd like to only
1694 // apply this to TYPE_BASE_APPLICATION, windows of TYPE_APPLICATION like dialogs, could
1695 // appear to not be drag resizing while they resize, but we'd still like to manipulate
1696 // their frame to update crop, etc...
1697 //
1698 // Anyway we don't need to synchronize position and content updates for these
1699 // windows since they aren't at the base layer and could be moved around anyway.
Wale Ogunwale44f036f2017-09-29 05:09:09 -07001700 if (!computeDragResizing() && mAttrs.type == TYPE_BASE_APPLICATION
1701 && !mWinAnimator.isForceScaled() && !isGoneForLayoutLw()
1702 && !getTask().inPinnedWindowingMode()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001703 setResizedWhileNotDragResizing(true);
1704 }
1705 }
1706 if (isGoneForLayoutLw()) {
1707 mResizedWhileGone = true;
1708 }
1709
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001710 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001711 }
1712
1713 void onUnfreezeBounds() {
1714 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001715 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001716 c.onUnfreezeBounds();
1717 }
1718
1719 if (!mHasSurface) {
1720 return;
1721 }
1722
1723 mLayoutNeeded = true;
1724 setDisplayLayoutNeeded();
1725 if (!mService.mResizingWindows.contains(this)) {
1726 mService.mResizingWindows.add(this);
1727 }
1728 }
1729
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001730 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001731 * If the window has moved due to its containing content frame changing, then notify the
1732 * listeners and optionally animate it. Simply checking a change of position is not enough,
1733 * because being move due to dock divider is not a trigger for animation.
1734 */
1735 void handleWindowMovedIfNeeded() {
1736 if (!hasMoved()) {
1737 return;
1738 }
1739
1740 // Frame has moved, containing content frame has also moved, and we're not currently
1741 // animating... let's do something.
1742 final int left = mFrame.left;
1743 final int top = mFrame.top;
1744 final Task task = getTask();
1745 final boolean adjustedForMinimizedDockOrIme = task != null
1746 && (task.mStack.isAdjustedForMinimizedDockedStack()
1747 || task.mStack.isAdjustedForIme());
David Stevens9440dc82017-03-16 19:00:20 -07001748 if (mToken.okToAnimate()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001749 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1750 && !isDragResizing() && !adjustedForMinimizedDockOrIme
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001751 && getWindowConfiguration().hasMovementAnimations()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001752 && !mWinAnimator.mLastHidden) {
1753 mWinAnimator.setMoveAnimation(left, top);
1754 }
1755
1756 //TODO (multidisplay): Accessibility supported only for the default display.
1757 if (mService.mAccessibilityController != null
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001758 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001759 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
1760 }
1761
1762 try {
1763 mClient.moved(left, top);
1764 } catch (RemoteException e) {
1765 }
1766 mMovedByResize = false;
1767 }
1768
1769 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001770 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001771 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1772 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001773 private boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001774 return mHasSurface && (mContentChanged || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001775 && !mAnimatingExit
Chong Zhangbd0d9372015-12-28 15:18:29 -08001776 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001777 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001778 }
1779
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001780 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001781 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001782 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001783 return false;
1784 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001785 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001786 }
1787
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001788 boolean fillsDisplay() {
1789 final DisplayInfo displayInfo = getDisplayInfo();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001790 return mFrame.left <= 0 && mFrame.top <= 0
1791 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001792 }
1793
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001794 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001795 boolean isConfigChanged() {
Bryce Lee2b17afd2017-09-21 10:38:20 -07001796 return !getLastReportedConfiguration().equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001797 }
1798
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001799 void onWindowReplacementTimeout() {
1800 if (mWillReplaceWindow) {
1801 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001802 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001803 // delays removal on certain conditions, which will leave the stale window in the
1804 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1805 //
1806 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001807 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001808 } else {
1809 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001810 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001811 c.onWindowReplacementTimeout();
1812 }
1813 }
1814 }
1815
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001816 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001817 void forceWindowsScaleableInTransaction(boolean force) {
1818 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1819 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1820 }
1821
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001822 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001823 }
1824
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001825 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001826 void removeImmediately() {
1827 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001828
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001829 if (mRemoved) {
1830 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001831 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1832 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001833 return;
1834 }
1835
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001836 mRemoved = true;
1837
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001838 mWillReplaceWindow = false;
1839 if (mReplacementWindow != null) {
1840 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1841 }
1842
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001843 final DisplayContent dc = getDisplayContent();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001844 if (mService.mInputMethodTarget == this) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001845 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001846 }
1847
1848 final int type = mAttrs.type;
1849 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001850 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001851 }
1852 mPolicy.removeWindowLw(this);
1853
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001854 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001855
Craig Mautner96868332012-12-04 14:29:11 -08001856 mWinAnimator.destroyDeferredSurfaceLocked();
1857 mWinAnimator.destroySurfaceLocked();
Wale Ogunwale943002b2017-02-15 19:34:01 -08001858 mSession.windowRemovedLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001859 try {
1860 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1861 } catch (RuntimeException e) {
1862 // Ignore if it has already been removed (usually because
1863 // we are doing this as part of processing a death note.)
1864 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001865
1866 mService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001867 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001868
Wale Ogunwale571771c2016-08-26 13:18:50 -07001869 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001870 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001871 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001872 removeIfPossible(false /*keepVisibleDeadWindow*/);
1873 }
1874
Wale Ogunwale571771c2016-08-26 13:18:50 -07001875 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001876 mWindowRemovalAllowed = true;
1877 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1878 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1879
1880 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1881 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1882 "Starting window removed " + this);
1883
1884 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && this == mService.mCurrentFocus)
1885 Slog.v(TAG_WM, "Remove " + this + " client="
1886 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1887 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1888 + Debug.getCallers(5));
1889
1890 final long origId = Binder.clearCallingIdentity();
1891
Peter Visontay3556a3b2017-11-01 17:23:17 +00001892 try {
1893 disposeInputChannel();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001894
Peter Visontay3556a3b2017-11-01 17:23:17 +00001895 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1896 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1897 + " mAnimatingExit=" + mAnimatingExit
1898 + " mRemoveOnExit=" + mRemoveOnExit
1899 + " mHasSurface=" + mHasSurface
1900 + " surfaceShowing=" + mWinAnimator.getShown()
1901 + " isAnimationSet=" + mWinAnimator.isAnimationSet()
1902 + " app-animation="
1903 + (mAppToken != null ? mAppToken.mAppAnimator.animation : null)
1904 + " mWillReplaceWindow=" + mWillReplaceWindow
1905 + " inPendingTransaction="
1906 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
1907 + " mDisplayFrozen=" + mService.mDisplayFrozen
1908 + " callers=" + Debug.getCallers(6));
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001909
Peter Visontay3556a3b2017-11-01 17:23:17 +00001910 // Visibility of the removed window. Will be used later to update orientation later on.
1911 boolean wasVisible = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001912
Peter Visontay3556a3b2017-11-01 17:23:17 +00001913 final int displayId = getDisplayId();
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001914
Peter Visontay3556a3b2017-11-01 17:23:17 +00001915 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1916 // window until the animation is done. If the display is frozen, just remove immediately,
1917 // since the animation wouldn't be seen.
1918 if (mHasSurface && mToken.okToAnimate()) {
1919 if (mWillReplaceWindow) {
1920 // This window is going to be replaced. We need to keep it around until the new one
1921 // gets added, then we will get rid of this one.
1922 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1923 "Preserving " + this + " until the new one is " + "added");
1924 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1925 // been removed. We probably need another flag to indicate that window removal
1926 // should be deffered vs. overloading the flag that says we are playing an exit
1927 // animation.
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001928 mAnimatingExit = true;
Peter Visontay3556a3b2017-11-01 17:23:17 +00001929 mReplacingRemoveRequested = true;
1930 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001931 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001932
Peter Visontay3556a3b2017-11-01 17:23:17 +00001933 // If we are not currently running the exit animation, we need to see about starting one
1934 wasVisible = isWinVisibleLw();
1935
1936 if (keepVisibleDeadWindow) {
1937 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1938 "Not removing " + this + " because app died while it's visible");
1939
1940 mAppDied = true;
1941 setDisplayLayoutNeeded();
1942 mService.mWindowPlacerLocked.performSurfacePlacement();
1943
1944 // Set up a replacement input channel since the app is now dead.
1945 // We need to catch tapping on the dead window to restart the app.
1946 openInputChannel(null);
1947 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
1948 return;
1949 }
1950
1951 if (wasVisible) {
1952 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
1953
1954 // Try starting an animation.
1955 if (mWinAnimator.applyAnimationLocked(transit, false)) {
1956 mAnimatingExit = true;
1957 }
1958 //TODO (multidisplay): Magnification is supported only for the default display.
1959 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
1960 mService.mAccessibilityController.onWindowTransitionLocked(this, transit);
1961 }
1962 }
1963 final boolean isAnimating =
1964 mWinAnimator.isAnimationSet() && !mWinAnimator.isDummyAnimation();
1965 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
1966 && mAppToken.isLastWindow(this);
1967 // We delay the removal of a window if it has a showing surface that can be used to run
1968 // exit animation and it is marked as exiting.
1969 // Also, If isn't the an animating starting window that is the last window in the app.
1970 // We allow the removal of the non-animating starting window now as there is no
1971 // additional window or animation that will trigger its removal.
1972 if (mWinAnimator.getShown() && mAnimatingExit
1973 && (!lastWindowIsStartingWindow || isAnimating)) {
1974 // The exit animation is running or should run... wait for it!
1975 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1976 "Not removing " + this + " due to exit animation ");
1977 setupWindowForRemoveOnExit();
1978 if (mAppToken != null) {
1979 mAppToken.updateReportedVisibilityLocked();
1980 }
1981 return;
1982 }
1983 }
1984
1985 removeImmediately();
1986 // Removing a visible window will effect the computed orientation
1987 // So just update orientation if needed.
1988 if (wasVisible && mService.updateOrientationFromAppTokensLocked(false, displayId)) {
1989 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
1990 }
1991 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
1992 } finally {
1993 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001994 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001995 }
1996
1997 private void setupWindowForRemoveOnExit() {
1998 mRemoveOnExit = true;
1999 setDisplayLayoutNeeded();
2000 // Request a focus update as this window's input channel is already gone. Otherwise
2001 // we could have no focused window in input manager.
2002 final boolean focusChanged = mService.updateFocusedWindowLocked(
2003 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
2004 mService.mWindowPlacerLocked.performSurfacePlacement();
2005 if (focusChanged) {
2006 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2007 }
2008 }
2009
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08002010 void setHasSurface(boolean hasSurface) {
2011 mHasSurface = hasSurface;
2012 }
2013
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002014 int getAnimLayerAdjustment() {
Wale Ogunwale44fbdf52016-11-16 10:18:45 -08002015 if (mIsImWindow && mService.mInputMethodTarget != null) {
Wale Ogunwale455fac52016-07-21 07:24:49 -07002016 final AppWindowToken appToken = mService.mInputMethodTarget.mAppToken;
2017 if (appToken != null) {
Robert Carrdee1b3f2017-02-27 11:33:33 -08002018 return appToken.getAnimLayerAdjustment();
Wale Ogunwale455fac52016-07-21 07:24:49 -07002019 }
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002020 }
Wale Ogunwale455fac52016-07-21 07:24:49 -07002021
Robert Carrdee1b3f2017-02-27 11:33:33 -08002022 return mToken.getAnimLayerAdjustment();
Filip Gruszczynski92e432c2015-12-15 19:17:09 -08002023 }
2024
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002025 int getSpecialWindowAnimLayerAdjustment() {
2026 int specialAdjustment = 0;
2027 if (mIsImWindow) {
2028 specialAdjustment = getDisplayContent().mInputMethodAnimLayerAdjustment;
2029 } else if (mIsWallpaper) {
Wale Ogunwale0303c572016-10-20 10:16:29 -07002030 specialAdjustment = getDisplayContent().mWallpaperController.getAnimLayerAdjustment();
Wale Ogunwalec69694a2016-10-18 13:51:15 -07002031 }
2032
2033 return mLayer + specialAdjustment;
2034 }
2035
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002036 boolean canBeImeTarget() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002037 if (mIsImWindow) {
2038 // IME windows can't be IME targets. IME targets are required to be below the IME
2039 // windows and that wouldn't be possible if the IME window is its own target...silly.
2040 return false;
2041 }
2042
Winson Chung3d0a74a2017-07-12 12:37:19 -07002043 final boolean windowsAreFocusable = mAppToken == null || mAppToken.windowsAreFocusable();
Winson Chungb1549342017-07-11 09:59:56 -07002044 if (!windowsAreFocusable) {
2045 // This window can't be an IME target if the app's windows should not be focusable.
2046 return false;
2047 }
2048
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002049 final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002050 final int type = mAttrs.type;
2051
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002052 // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are set or
2053 // both are cleared...and not a starting window.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002054 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
2055 && type != TYPE_APPLICATION_STARTING) {
2056 return false;
2057 }
2058
2059 if (DEBUG_INPUT_METHOD) {
2060 Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding());
2061 if (!isVisibleOrAdding()) {
2062 Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController
2063 + " relayoutCalled=" + mRelayoutCalled
2064 + " viewVis=" + mViewVisibility
2065 + " policyVis=" + mPolicyVisibility
2066 + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim
2067 + " parentHidden=" + isParentWindowHidden()
2068 + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
2069 if (mAppToken != null) {
2070 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + mAppToken.hiddenRequested);
2071 }
2072 }
2073 }
2074 return isVisibleOrAdding();
2075 }
2076
Chong Zhangacf11402015-11-04 16:23:10 -08002077 private final class DeadWindowEventReceiver extends InputEventReceiver {
2078 DeadWindowEventReceiver(InputChannel inputChannel) {
2079 super(inputChannel, mService.mH.getLooper());
2080 }
2081 @Override
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -07002082 public void onInputEvent(InputEvent event, int displayId) {
Chong Zhangacf11402015-11-04 16:23:10 -08002083 finishInputEvent(event, true);
2084 }
2085 }
2086 /**
2087 * Dummy event receiver for windows that died visible.
2088 */
2089 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2090
Chong Zhang112eb8c2015-11-02 11:17:00 -08002091 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002092 if (mInputChannel != null) {
2093 throw new IllegalStateException("Window already has an input channel.");
2094 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002095 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002096 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2097 mInputChannel = inputChannels[0];
2098 mClientChannel = inputChannels[1];
2099 mInputWindowHandle.inputChannel = inputChannels[0];
2100 if (outInputChannel != null) {
2101 mClientChannel.transferTo(outInputChannel);
2102 mClientChannel.dispose();
2103 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002104 } else {
2105 // If the window died visible, we setup a dummy input channel, so that taps
2106 // can still detected by input monitor channel, and we can relaunch the app.
2107 // Create dummy event receiver that simply reports all events as handled.
2108 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002109 }
2110 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002111 }
2112
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002113 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002114 if (mDeadWindowEventReceiver != null) {
2115 mDeadWindowEventReceiver.dispose();
2116 mDeadWindowEventReceiver = null;
2117 }
2118
2119 // unregister server channel first otherwise it complains about broken channel
2120 if (mInputChannel != null) {
2121 mService.mInputManager.unregisterInputChannel(mInputChannel);
2122 mInputChannel.dispose();
2123 mInputChannel = null;
2124 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002125 if (mClientChannel != null) {
2126 mClientChannel.dispose();
2127 mClientChannel = null;
2128 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07002129 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002130 }
2131
Robert Carrf59b8dd2017-10-02 18:58:36 -07002132 private Dimmer getDimmer() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002133 Task task = getTask();
2134 if (task != null) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07002135 return task.getDimmer();
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002136 }
Robert Carrf07ef9e2017-11-21 12:12:49 -08002137 TaskStack taskStack = getStack();
2138 if (taskStack != null) {
2139 return taskStack.getDimmer();
2140 }
2141 return null;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002142 }
2143
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002144 /** Returns true if the replacement window was removed. */
2145 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2146 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2147 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2148 removeReplacedWindow();
2149 return true;
2150 }
2151
2152 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002153 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002154 if (c.removeReplacedWindowIfNeeded(replacement)) {
2155 return true;
2156 }
2157 }
2158 return false;
2159 }
2160
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002161 private void removeReplacedWindow() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002162 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002163 mWillReplaceWindow = false;
2164 mAnimateReplacingWindow = false;
2165 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002166 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002167 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002168 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002169 }
2170 }
2171
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002172 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2173 boolean replacementSet = false;
2174
2175 if (mWillReplaceWindow && mReplacementWindow == null
2176 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2177
2178 mReplacementWindow = replacementCandidate;
2179 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2180 replacementSet = true;
2181 }
2182
2183 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002184 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002185 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2186 }
2187
2188 return replacementSet;
2189 }
2190
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002191 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002192 final DisplayContent dc = getDisplayContent();
2193 if (dc != null) {
2194 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002195 }
2196 }
2197
Chong Zhang5117e272016-05-03 12:47:34 -07002198 void applyAdjustForImeIfNeeded() {
2199 final Task task = getTask();
2200 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2201 task.mStack.applyAdjustForImeIfNeeded(task);
2202 }
2203 }
2204
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002205 @Override
2206 void switchUser() {
2207 super.switchUser();
2208 if (isHiddenFromUserLocked()) {
2209 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2210 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
2211 hideLw(false);
2212 }
2213 }
2214
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002215 int getTouchableRegion(Region region, int flags) {
2216 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002217 if (modal && mAppToken != null) {
2218 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002219 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002220 // If this is a modal window we need to dismiss it if it's not full screen and the
2221 // touch happens outside of the frame that displays the content. This means we
2222 // need to intercept touches outside of that window. The dim layer user
2223 // associated with the window (task or stack) will give us the good bounds, as
2224 // they would be used to display the dim layer.
Robert Carrf59b8dd2017-10-02 18:58:36 -07002225 final Task task = getTask();
2226 if (task != null) {
2227 task.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002228 } else {
Robert Carrf59b8dd2017-10-02 18:58:36 -07002229 getStack().getDimBounds(mTmpRect);
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002230 }
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002231 if (inFreeformWindowingMode()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002232 // For freeform windows we the touch region to include the whole surface for the
2233 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002234 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2235 final int delta = WindowManagerService.dipToPixel(
2236 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2237 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002238 }
2239 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002240 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002241 } else {
2242 // Not modal or full screen modal
2243 getTouchableRegion(region);
2244 }
2245 return flags;
2246 }
2247
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002248 void checkPolicyVisibilityChange() {
2249 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2250 if (DEBUG_VISIBILITY) {
2251 Slog.v(TAG, "Policy visibility changing after anim in " +
2252 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2253 }
2254 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski63a35e22015-11-05 15:38:59 -08002255 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002256 if (!mPolicyVisibility) {
2257 if (mService.mCurrentFocus == this) {
2258 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2259 "setAnimationLocked: setting mFocusMayChange true");
2260 mService.mFocusMayChange = true;
2261 }
2262 // Window is no longer visible -- make sure if we were waiting
2263 // for it to be displayed before enabling the display, that
2264 // we allow the display to be enabled now.
2265 mService.enableScreenIfNeededLocked();
2266 }
2267 }
2268 }
2269
2270 void setRequestedSize(int requestedWidth, int requestedHeight) {
2271 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2272 mLayoutNeeded = true;
2273 mRequestedWidth = requestedWidth;
2274 mRequestedHeight = requestedHeight;
2275 }
2276 }
2277
Bryce Leef858b572017-06-29 14:03:33 -07002278 void prepareWindowToDisplayDuringRelayout(boolean wasVisible) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002279 // We need to turn on screen regardless of visibility.
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002280 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
2281 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
2282 mTurnOnScreen = true;
2283 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002284
2285 // If we were already visible, skip rest of preparation.
2286 if (wasVisible) {
2287 if (DEBUG_VISIBILITY) Slog.v(TAG,
2288 "Already visible and does not turn on screen, skip preparing: " + this);
2289 return;
2290 }
2291
2292 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2293 == SOFT_INPUT_ADJUST_RESIZE) {
2294 mLayoutNeeded = true;
2295 }
2296
David Stevens9440dc82017-03-16 19:00:20 -07002297 if (isDrawnLw() && mToken.okToAnimate()) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002298 mWinAnimator.applyEnterAnimationLocked();
2299 }
Bryce Leef858b572017-06-29 14:03:33 -07002300 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002301
Bryce Leef858b572017-06-29 14:03:33 -07002302 void getMergedConfiguration(MergedConfiguration outConfiguration) {
2303 final Configuration globalConfig = mService.mRoot.getConfiguration();
2304 final Configuration overrideConfig = getMergedOverrideConfiguration();
2305 outConfiguration.setConfiguration(globalConfig, overrideConfig);
2306 }
2307
Bryce Lee2b17afd2017-09-21 10:38:20 -07002308 void setLastReportedMergedConfiguration(MergedConfiguration config) {
2309 mLastReportedConfiguration.setTo(config);
2310 }
2311
2312 void getLastReportedMergedConfiguration(MergedConfiguration config) {
2313 config.setTo(mLastReportedConfiguration);
2314 }
2315
2316 private Configuration getLastReportedConfiguration() {
2317 return mLastReportedConfiguration.getMergedConfiguration();
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002318 }
2319
2320 void adjustStartingWindowFlags() {
2321 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2322 && mAppToken.startingWindow != null) {
2323 // Special handling of starting window over the base
2324 // window of the app: propagate lock screen flags to it,
2325 // to provide the correct semantics while starting.
2326 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2327 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2328 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2329 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2330 }
2331 }
2332
2333 void setWindowScale(int requestedWidth, int requestedHeight) {
2334 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2335
2336 if (scaledWindow) {
2337 // requested{Width|Height} Surface's physical size
2338 // attrs.{width|height} Size on screen
2339 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2340 mHScale = (mAttrs.width != requestedWidth) ?
2341 (mAttrs.width / (float)requestedWidth) : 1.0f;
2342 mVScale = (mAttrs.height != requestedHeight) ?
2343 (mAttrs.height / (float)requestedHeight) : 1.0f;
2344 } else {
2345 mHScale = mVScale = 1;
2346 }
2347 }
2348
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002349 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002350 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002351 public void binderDied() {
2352 try {
2353 synchronized(mService.mWindowMap) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002354 final WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002355 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002356 if (win != null) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002357 final DisplayContent dc = getDisplayContent();
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002358 if (win.mAppToken != null && win.mAppToken.findMainWindow() == win) {
2359 mService.mTaskSnapshotController.onAppDied(win.mAppToken);
2360 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002361 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002362 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2363 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002364 // just in case they have the divider at an unstable position. Better
2365 // also reset drag resizing state, because the owner can't do it
2366 // anymore.
Wale Ogunwale61911492017-10-11 08:50:50 -07002367 final TaskStack stack =
Matthew Ng64e77cf2017-10-31 14:01:31 -07002368 dc.getSplitScreenPrimaryStackIgnoringVisibility();
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002369 if (stack != null) {
2370 stack.resetDockedStackToMiddle();
2371 }
Jorim Jaggidcb68142016-02-09 21:51:30 -08002372 mService.setDockedStackResizing(false);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002373 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002374 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002375 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002376 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002377 }
2378 }
2379 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002380 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002381 }
2382 }
2383 }
2384
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002385 /**
2386 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2387 * because we want to preserve its location on screen to be re-activated later when the user
2388 * interacts with it.
2389 */
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002390 private boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwale89973222017-04-23 18:39:45 -07002391 if (!isWinVisibleLw() || mAppToken == null || mAppToken.isClientHidden()) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002392 // Not a visible app window or the app isn't dead.
2393 return false;
2394 }
2395
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002396 if (mAttrs.token != mClient.asBinder()) {
2397 // The window was add by a client using another client's app token. We don't want to
2398 // keep the dead window around for this case since this is meant for 'real' apps.
2399 return false;
2400 }
2401
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002402 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2403 // We don't keep starting windows since they were added by the window manager before
2404 // the app even launched.
2405 return false;
2406 }
2407
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002408 return getWindowConfiguration().keepVisibleDeadAppWindowOnScreen();
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002409 }
2410
Wale Ogunwaled045c822015-12-02 09:14:28 -08002411 /** @return true if this window desires key events. */
2412 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002413 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002414 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002415 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002416 && (mAppToken == null || mAppToken.windowsAreFocusable())
Matthew Nge15352e2016-12-20 15:36:29 -08002417 && !canReceiveTouchInput();
2418 }
2419
2420 /** @return true if this window desires touch events. */
2421 boolean canReceiveTouchInput() {
Bryce Lee6d410262017-02-28 15:30:17 -08002422 return mAppToken != null && mAppToken.getTask() != null
2423 && mAppToken.getTask().mStack.shouldIgnoreInput();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002424 }
2425
Craig Mautner749a7bb2012-04-02 13:49:53 -07002426 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002427 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002428 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002429 }
2430
Craig Mautner749a7bb2012-04-02 13:49:53 -07002431 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002432 public boolean showLw(boolean doAnimation) {
2433 return showLw(doAnimation, true);
2434 }
2435
2436 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002437 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002438 return false;
2439 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002440 if (!mAppOpVisibility) {
2441 // Being hidden due to app op request.
2442 return false;
2443 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002444 if (mPermanentlyHidden) {
2445 // Permanently hidden until the app exists as apps aren't prepared
2446 // to handle their windows being removed from under them.
2447 return false;
2448 }
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002449 if (mForceHideNonSystemOverlayWindow) {
2450 // This is an alert window that is currently force hidden.
2451 return false;
2452 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002453 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002454 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002455 return false;
2456 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002457 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002458 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002459 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Craig Mautnera2c77052012-03-26 12:14:43 -07002460 + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
David Stevens9440dc82017-03-16 19:00:20 -07002461 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002462 doAnimation = false;
Craig Mautnera2c77052012-03-26 12:14:43 -07002463 } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002464 // Check for the case where we are currently visible and
2465 // not animating; we do not want to do animation at such a
2466 // point to become visible when we already are.
2467 doAnimation = false;
2468 }
2469 }
2470 mPolicyVisibility = true;
2471 mPolicyVisibilityAfterAnim = true;
2472 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002473 mWinAnimator.applyAnimationLocked(TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002474 }
2475 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002476 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002477 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002478 if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) {
2479 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2480 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002481 return true;
2482 }
2483
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002484 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002485 public boolean hideLw(boolean doAnimation) {
2486 return hideLw(doAnimation, true);
2487 }
2488
2489 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2490 if (doAnimation) {
David Stevens9440dc82017-03-16 19:00:20 -07002491 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002492 doAnimation = false;
2493 }
2494 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002495 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002496 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002497 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002498 return false;
2499 }
2500 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002501 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
Craig Mautnera2c77052012-03-26 12:14:43 -07002502 if (mWinAnimator.mAnimation == null) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002503 doAnimation = false;
2504 }
2505 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002506 mPolicyVisibilityAfterAnim = false;
2507 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002508 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002509 mPolicyVisibility = false;
2510 // Window is no longer visible -- make sure if we were waiting
2511 // for it to be displayed before enabling the display, that
2512 // we allow the display to be enabled now.
2513 mService.enableScreenIfNeededLocked();
2514 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002515 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002516 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002517 mService.mFocusMayChange = true;
2518 }
2519 }
2520 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002521 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002522 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002523 if (mService.mCurrentFocus == this) {
2524 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2525 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002526 return true;
2527 }
2528
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002529 void setForceHideNonSystemOverlayWindowIfNeeded(boolean forceHide) {
2530 if (mOwnerCanAddInternalSystemWindow
2531 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2532 return;
2533 }
2534 if (mForceHideNonSystemOverlayWindow == forceHide) {
2535 return;
2536 }
2537 mForceHideNonSystemOverlayWindow = forceHide;
2538 if (forceHide) {
2539 hideLw(true /* doAnimation */, true /* requestAnim */);
2540 } else {
2541 showLw(true /* doAnimation */, true /* requestAnim */);
2542 }
2543 }
2544
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002545 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002546 if (mAppOpVisibility != state) {
2547 mAppOpVisibility = state;
2548 if (state) {
2549 // If the policy visibility had last been to hide, then this
2550 // will incorrectly show at this point since we lost that
2551 // information. Not a big deal -- for the windows that have app
2552 // ops modifies they should only be hidden by policy due to the
2553 // lock screen, and the user won't be changing this if locked.
2554 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002555 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002556 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002557 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002558 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002559 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002560 }
2561
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002562 public void hidePermanentlyLw() {
2563 if (!mPermanentlyHidden) {
2564 mPermanentlyHidden = true;
2565 hideLw(true, true);
2566 }
2567 }
2568
Jeff Brownc2932a12014-11-20 18:04:05 -08002569 public void pokeDrawLockLw(long timeout) {
2570 if (isVisibleOrAdding()) {
2571 if (mDrawLock == null) {
2572 // We want the tag name to be somewhat stable so that it is easier to correlate
2573 // in wake lock statistics. So in particular, we don't want to include the
2574 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002575 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08002576 mDrawLock = mService.mPowerManager.newWakeLock(
2577 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
2578 mDrawLock.setReferenceCounted(false);
2579 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2580 }
2581 // Each call to acquire resets the timeout.
2582 if (DEBUG_POWER) {
2583 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2584 + mAttrs.packageName);
2585 }
2586 mDrawLock.acquire(timeout);
2587 } else if (DEBUG_POWER) {
2588 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2589 + "owned by " + mAttrs.packageName);
2590 }
2591 }
2592
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002593 @Override
2594 public boolean isAlive() {
2595 return mClient.asBinder().isBinderAlive();
2596 }
2597
Craig Mautnera987d432012-10-11 14:07:58 -07002598 boolean isClosing() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002599 return mAnimatingExit || (mService.mClosingApps.contains(mAppToken));
Craig Mautnera987d432012-10-11 14:07:58 -07002600 }
2601
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002602 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002603 boolean isAnimating() {
2604 if (mWinAnimator.isAnimationSet() || mAnimatingExit) {
2605 return true;
2606 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002607 return super.isAnimating();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002608 }
2609
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002610 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2611 animators.add(mWinAnimator);
2612
2613 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002614 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002615 c.addWinAnimatorToList(animators);
2616 }
2617 }
2618
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002619 void sendAppVisibilityToClients() {
2620 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002621
Wale Ogunwale89973222017-04-23 18:39:45 -07002622 final boolean clientHidden = mAppToken.isClientHidden();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002623 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2624 // Don't hide the starting window.
2625 return;
2626 }
2627
Wale Ogunwale89973222017-04-23 18:39:45 -07002628 if (clientHidden) {
2629 // Once we are notifying the client that it's visibility has changed, we need to prevent
2630 // it from destroying child surfaces until the animation has finished. We do this by
2631 // detaching any surface control the client added from the client.
2632 for (int i = mChildren.size() - 1; i >= 0; --i) {
2633 final WindowState c = mChildren.get(i);
2634 c.mWinAnimator.detachChildren();
2635 }
2636
2637 mWinAnimator.detachChildren();
2638 }
2639
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002640 try {
2641 if (DEBUG_VISIBILITY) Slog.v(TAG,
2642 "Setting visibility of " + this + ": " + (!clientHidden));
2643 mClient.dispatchAppVisibility(!clientHidden);
2644 } catch (RemoteException e) {
2645 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002646 }
2647
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002648 void onStartFreezingScreen() {
2649 mAppFreezing = true;
2650 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002651 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002652 c.onStartFreezingScreen();
2653 }
2654 }
2655
2656 boolean onStopFreezingScreen() {
2657 boolean unfrozeWindows = false;
2658 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002659 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002660 unfrozeWindows |= c.onStopFreezingScreen();
2661 }
2662
2663 if (!mAppFreezing) {
2664 return unfrozeWindows;
2665 }
2666
Wale Ogunwale953171d2016-09-30 09:17:30 -07002667 mAppFreezing = false;
2668
Bryce Lee8c3cf382017-07-06 19:47:10 -07002669 if (mHasSurface && !getOrientationChanging()
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002670 && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
2671 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
Bryce Lee8c3cf382017-07-06 19:47:10 -07002672 setOrientationChanging(true);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002673 mService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002674 }
2675 mLastFreezeDuration = 0;
2676 setDisplayLayoutNeeded();
2677 return true;
2678 }
2679
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002680 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2681 boolean destroyedSomething = false;
2682 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002683 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002684 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2685 }
2686
Robert Carrdb2f6e62017-03-01 20:17:58 -08002687 if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) {
2688 return destroyedSomething;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002689 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08002690
2691 if (appStopped || mWindowRemovalAllowed) {
2692 mWinAnimator.destroyPreservedSurfaceLocked();
2693 }
2694
2695 if (mDestroying) {
2696 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2697 + " destroySurfaces: appStopped=" + appStopped
2698 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2699 + " win.mRemoveOnExit=" + mRemoveOnExit);
2700 if (!cleanupOnResume || mRemoveOnExit) {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002701 destroySurfaceUnchecked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08002702 }
2703 if (mRemoveOnExit) {
2704 removeImmediately();
2705 }
2706 if (cleanupOnResume) {
2707 requestUpdateWallpaperIfNeeded();
2708 }
2709 mDestroying = false;
2710 destroyedSomething = true;
2711 }
2712
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002713 return destroyedSomething;
2714 }
Chris Craik3131bde2016-05-06 13:39:08 -07002715
Robert Carr89a28ab2017-04-24 15:33:11 -07002716 // Destroy or save the application surface without checking
2717 // various indicators of whether the client has released the surface.
2718 // This is in general unsafe, and most callers should use {@link #destroySurface}
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002719 void destroySurfaceUnchecked() {
2720 mWinAnimator.destroySurfaceLocked();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002721
Chong Zhang92147042016-05-09 12:47:11 -07002722 // Clear animating flags now, since the surface is now gone. (Note this is true even
2723 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2724 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002725 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002726
Craig Mautner69b08182012-09-05 13:07:13 -07002727 @Override
2728 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002729 final DisplayContent displayContent = getDisplayContent();
2730 if (displayContent == null) {
2731 // Only a window that was on a non-default display can be detached from it.
2732 return false;
2733 }
Winson Chung47a3e652014-05-21 16:03:42 -07002734 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002735 }
2736
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002737 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07002738 mShowToOwnerOnly = showToOwnerOnly;
2739 }
2740
Wale Ogunwaleea92d972016-12-08 07:33:13 -08002741 private boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002742 // Child windows are evaluated based on their parent window.
2743 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002744 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale72919d22016-12-08 18:58:50 -08002745 && win.mAppToken != null && win.mAppToken.mShowForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002746
2747 // All window frames that are fullscreen extend above status bar, but some don't extend
2748 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2749 // bottom right.
2750 if (win.mFrame.left <= win.mDisplayFrame.left
2751 && win.mFrame.top <= win.mDisplayFrame.top
2752 && win.mFrame.right >= win.mStableFrame.right
2753 && win.mFrame.bottom >= win.mStableFrame.bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002754 // Is a fullscreen window, like the clock alarm. Show to everyone.
2755 return false;
2756 }
2757 }
2758
Craig Mautner341220f2012-10-16 15:20:09 -07002759 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01002760 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002761 }
2762
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002763 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2764 outRegion.set(
2765 frame.left + inset.left, frame.top + inset.top,
2766 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002767 }
2768
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002769 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002770 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002771 switch (mTouchableInsets) {
2772 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002773 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002774 outRegion.set(frame);
2775 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002776 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002777 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002778 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002779 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002780 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002781 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002782 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002783 outRegion.set(mGivenTouchableRegion);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002784 outRegion.translate(frame.left, frame.top);
2785 break;
2786 }
2787 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002788 cropRegionToStackBoundsIfNeeded(outRegion);
2789 }
2790
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002791 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002792 final Task task = getTask();
2793 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002794 return;
2795 }
2796
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002797 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002798 if (stack == null) {
2799 return;
2800 }
2801
2802 stack.getDimBounds(mTmpRect);
2803 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002804 }
2805
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002806 /**
2807 * Report a focus change. Must be called with no locks held, and consistently
2808 * from the same serialized thread (such as dispatched from a handler).
2809 */
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07002810 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002811 try {
2812 mClient.windowFocusChanged(focused, inTouchMode);
2813 } catch (RemoteException e) {
2814 }
2815 if (mFocusCallbacks != null) {
2816 final int N = mFocusCallbacks.beginBroadcast();
2817 for (int i=0; i<N; i++) {
2818 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2819 try {
2820 if (focused) {
2821 obs.focusGained(mWindowId.asBinder());
2822 } else {
2823 obs.focusLost(mWindowId.asBinder());
2824 }
2825 } catch (RemoteException e) {
2826 }
2827 }
2828 mFocusCallbacks.finishBroadcast();
2829 }
2830 }
2831
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002832 @Override
2833 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002834 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002835 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002836 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002837
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002838 return super.getConfiguration();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002839 }
2840
Craig Mautnerdf88d732014-01-27 09:21:32 -08002841 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002842 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08002843 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002844 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
2845 + ": " + mCompatFrame);
Bryce Leef858b572017-06-29 14:03:33 -07002846 final MergedConfiguration mergedConfiguration =
2847 new MergedConfiguration(mService.mRoot.getConfiguration(),
2848 getMergedOverrideConfiguration());
2849
Bryce Lee2b17afd2017-09-21 10:38:20 -07002850 setLastReportedMergedConfiguration(mergedConfiguration);
Bryce Leef858b572017-06-29 14:03:33 -07002851
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002852 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002853 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
2854
Craig Mautnerdf88d732014-01-27 09:21:32 -08002855 final Rect frame = mFrame;
2856 final Rect overscanInsets = mLastOverscanInsets;
2857 final Rect contentInsets = mLastContentInsets;
2858 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07002859 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002860 final Rect outsets = mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002861 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Andrii Kulianb2e37802017-01-11 00:36:44 -08002862 final boolean reportOrientation = mReportOrientationChanged;
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002863 final int displayId = getDisplayId();
Adrian Roos5c6b6222017-11-07 17:36:10 +01002864 final DisplayCutout displayCutout = mDisplayCutout;
Chet Haase8eb48d22014-09-24 07:31:29 -07002865 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
2866 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002867 // To prevent deadlock simulate one-way call if win.mClient is a local object.
2868 mService.mH.post(new Runnable() {
2869 @Override
2870 public void run() {
2871 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002872 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07002873 stableInsets, outsets, reportDraw, mergedConfiguration,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002874 reportOrientation, displayId, displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002875 } catch (RemoteException e) {
2876 // Not a remote call, RemoteException won't be raised.
2877 }
2878 }
2879 });
2880 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002881 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002882 outsets, reportDraw, mergedConfiguration, reportOrientation, displayId,
2883 displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002884 }
Svetoslav4604abc2014-06-10 18:59:30 -07002885
2886 //TODO (multidisplay): Accessibility supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002887 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07002888 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07002889 }
2890
Craig Mautnerdf88d732014-01-27 09:21:32 -08002891 mOverscanInsetsChanged = false;
2892 mContentInsetsChanged = false;
2893 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07002894 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002895 mOutsetsChanged = false;
Robert Carr31aa98b2016-07-20 15:29:03 -07002896 mFrameSizeChanged = false;
Adrian Roos5c6b6222017-11-07 17:36:10 +01002897 mDisplayCutoutChanged = false;
Andrii Kulianeb1d3222016-05-16 15:17:55 -07002898 mResizedWhileNotDragResizingReported = true;
Craig Mautnerdf88d732014-01-27 09:21:32 -08002899 mWinAnimator.mSurfaceResized = false;
Andrii Kulianb2e37802017-01-11 00:36:44 -08002900 mReportOrientationChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08002901 } catch (RemoteException e) {
Bryce Lee8c3cf382017-07-06 19:47:10 -07002902 setOrientationChanging(false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002903 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2904 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08002905 // We are assuming the hosting process is dead or in a zombie state.
2906 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
2907 + ", removing this window.");
2908 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002909 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002910 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002911 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002912 }
2913
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002914 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08002915 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
2916 // start even if we haven't received the relayout window, so that the client requests
2917 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
2918 // until the window to small size, otherwise the multithread renderer will shift last
2919 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
2920 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002921 boolean resizing = isDragResizing() || isDragResizeChanged();
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002922 if (getWindowConfiguration().useWindowFrameForBackdrop() || !resizing) {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002923 return frame;
2924 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07002925 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002926 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002927 return mTmpRect;
2928 }
2929
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002930 private int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002931 final TaskStack stack = getStack();
2932 if (stack == null) {
2933 return INVALID_STACK_ID;
2934 }
2935 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002936 }
2937
2938 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
2939 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002940 MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId,
2941 DisplayCutout displayCutout)
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002942 throws RemoteException {
Andrii Kulianb2e37802017-01-11 00:36:44 -08002943 final boolean forceRelayout = isDragResizeChanged() || mResizedWhileNotDragResizing
2944 || reportOrientation;
Chong Zhangedaf3052016-04-22 15:04:31 -07002945
Jorim Jaggidc249c42015-12-15 14:57:31 -08002946 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Andrii Kulian44607962017-03-16 11:06:24 -07002947 reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002948 mPolicy.isNavBarForcedShownLw(this), displayId,
2949 new DisplayCutout.ParcelableWrapper(displayCutout));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002950 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002951 }
2952
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002953 public void registerFocusObserver(IWindowFocusObserver observer) {
2954 synchronized(mService.mWindowMap) {
2955 if (mFocusCallbacks == null) {
2956 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
2957 }
2958 mFocusCallbacks.register(observer);
2959 }
2960 }
2961
2962 public void unregisterFocusObserver(IWindowFocusObserver observer) {
2963 synchronized(mService.mWindowMap) {
2964 if (mFocusCallbacks != null) {
2965 mFocusCallbacks.unregister(observer);
2966 }
2967 }
2968 }
2969
2970 public boolean isFocused() {
2971 synchronized(mService.mWindowMap) {
2972 return mService.mCurrentFocus == this;
2973 }
2974 }
2975
Wale Ogunwale9185fb02016-03-11 18:06:14 -08002976 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07002977 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08002978 final Task task = getTask();
2979 return task != null && !task.isFullscreen();
2980 }
2981
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002982 /** Is this window in a container that takes up the entire screen space? */
2983 private boolean inFullscreenContainer() {
Bryce Leef3c6a472017-11-14 14:53:06 -08002984 return mAppToken == null || (mAppToken.matchParentBounds() && !isInMultiWindowMode());
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002985 }
2986
Andrii Kulian283acd22017-08-03 04:03:51 -07002987 /** @return true when the window is in fullscreen task, but has non-fullscreen bounds set. */
2988 boolean isLetterboxedAppWindow() {
Bryce Leef3c6a472017-11-14 14:53:06 -08002989 return !isInMultiWindowMode() && mAppToken != null && !mAppToken.matchParentBounds();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002990 }
2991
Chong Zhang3005e752015-09-18 18:46:28 -07002992 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002993 return mDragResizing != computeDragResizing();
2994 }
2995
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002996 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002997 void setWaitingForDrawnIfResizingChanged() {
2998 if (isDragResizeChanged()) {
2999 mService.mWaitingForDrawn.add(this);
3000 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003001 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003002 }
3003
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003004 /**
3005 * @return Whether we reported a drag resize change to the application or not already.
3006 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003007 private boolean isDragResizingChangeReported() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003008 return mDragResizingChangeReported;
3009 }
3010
3011 /**
3012 * Resets the state whether we reported a drag resize change to the app.
3013 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003014 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003015 void resetDragResizingChangeReported() {
3016 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003017 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003018 }
3019
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003020 /**
3021 * Set whether we got resized but drag resizing flag was false.
3022 * @see #isResizedWhileNotDragResizing().
3023 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003024 private void setResizedWhileNotDragResizing(boolean resizedWhileNotDragResizing) {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003025 mResizedWhileNotDragResizing = resizedWhileNotDragResizing;
3026 mResizedWhileNotDragResizingReported = !resizedWhileNotDragResizing;
3027 }
3028
3029 /**
3030 * Indicates whether we got resized but drag resizing flag was false. In this case, we also
3031 * need to recreate the surface and defer surface bound updates in order to make sure the
3032 * buffer contents and the positioning/size stay in sync.
3033 */
3034 boolean isResizedWhileNotDragResizing() {
3035 return mResizedWhileNotDragResizing;
3036 }
3037
3038 /**
3039 * @return Whether we reported "resize while not drag resizing" to the application.
3040 * @see #isResizedWhileNotDragResizing()
3041 */
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003042 private boolean isResizedWhileNotDragResizingReported() {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003043 return mResizedWhileNotDragResizingReported;
3044 }
3045
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003046 int getResizeMode() {
3047 return mResizeMode;
3048 }
3049
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003050 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003051 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003052 if (task == null) {
3053 return false;
3054 }
Tomasz Mikolajewskiaf20b8d2017-11-20 16:11:33 +09003055 if (!inSplitScreenWindowingMode() && !inFreeformWindowingMode()) {
Winson Chung2af04b32017-01-24 16:21:13 -08003056 return false;
3057 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003058 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003059 // Floating windows never enter drag resize mode.
3060 return false;
3061 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003062 if (task.isDragResizing()) {
3063 return true;
3064 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003065
3066 // If the bounds are currently frozen, it means that the layout size that the app sees
3067 // and the bounds we clip this window to might be different. In order to avoid holes, we
3068 // simulate that we are still resizing so the app fills the hole with the resizing
3069 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003070 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003071 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003072 !task.inFreeformWindowingMode() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003073
Chong Zhang3005e752015-09-18 18:46:28 -07003074 }
3075
3076 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003077 final boolean resizing = computeDragResizing();
3078 if (resizing == mDragResizing) {
3079 return;
3080 }
3081 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003082 final Task task = getTask();
3083 if (task != null && task.isDragResizing()) {
3084 mResizeMode = task.getDragResizeMode();
3085 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003086 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003087 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3088 : DRAG_RESIZE_MODE_FREEFORM;
3089 }
Chong Zhang3005e752015-09-18 18:46:28 -07003090 }
3091
3092 boolean isDragResizing() {
3093 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003094 }
3095
Robert Carr2487ce72016-04-07 15:18:45 -07003096 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003097 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3098 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003099 }
3100
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07003101 @CallSuper
3102 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02003103 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003104 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02003105 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003106 writeIdentifierToProto(proto, IDENTIFIER);
3107 proto.write(DISPLAY_ID, getDisplayId());
3108 proto.write(STACK_ID, getStackId());
3109 mAttrs.writeToProto(proto, ATTRIBUTES);
3110 mGivenContentInsets.writeToProto(proto, GIVEN_CONTENT_INSETS);
3111 mFrame.writeToProto(proto, FRAME);
3112 mContainingFrame.writeToProto(proto, CONTAINING_FRAME);
3113 mParentFrame.writeToProto(proto, PARENT_FRAME);
3114 mContentFrame.writeToProto(proto, CONTENT_FRAME);
3115 mContentInsets.writeToProto(proto, CONTENT_INSETS);
3116 mAttrs.surfaceInsets.writeToProto(proto, SURFACE_INSETS);
3117 mWinAnimator.writeToProto(proto, ANIMATOR);
3118 proto.write(ANIMATING_EXIT, mAnimatingExit);
3119 for (int i = 0; i < mChildren.size(); i++) {
Adrian Roos4921ccf2017-09-28 16:54:06 +02003120 mChildren.get(i).writeToProto(proto, CHILD_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003121 }
3122 proto.end(token);
3123 }
3124
3125 void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) {
3126 final long token = proto.start(fieldId);
3127 proto.write(HASH_CODE, System.identityHashCode(this));
3128 proto.write(USER_ID, UserHandle.getUserId(mOwnerUid));
3129 final CharSequence title = getWindowTag();
3130 if (title != null) {
3131 proto.write(TITLE, title.toString());
3132 }
3133 proto.end(token);
3134 }
3135
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003136 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003137 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003138 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003139 if (stack != null) {
3140 pw.print(" stackId="); pw.print(stack.mStackId);
3141 }
Craig Mautner59c00972012-07-30 12:10:24 -07003142 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003143 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07003144 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08003145 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
3146 pw.print(" package="); pw.print(mAttrs.packageName);
3147 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Jorim Jaggi484851b2017-09-22 16:03:27 +02003148 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs.toString(prefix));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003149 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
3150 pw.print(" h="); pw.print(mRequestedHeight);
3151 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003152 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
3153 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
3154 pw.print(" h="); pw.println(mLastRequestedHeight);
3155 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003156 if (mIsChildWindow || mLayoutAttached) {
3157 pw.print(prefix); pw.print("mParentWindow="); pw.print(getParentWindow());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003158 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
3159 }
3160 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
3161 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
3162 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
3163 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
3164 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
3165 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003166 if (dumpAll) {
3167 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3168 pw.print(" mSubLayer="); pw.print(mSubLayer);
3169 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Wale Ogunwale455fac52016-07-21 07:24:49 -07003170 pw.print(getAnimLayerAdjustment());
Craig Mautnerc2f9be02012-03-27 17:32:29 -07003171 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
3172 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003173 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003174 if (dumpAll) {
3175 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003176 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003177 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
3178 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Bryce Lee6311c4b2017-07-06 14:09:29 -07003179 pw.print(" mAppDied=");pw.print(mAppDied);
3180 pw.print(prefix); pw.print("drawnStateEvaluated=");
3181 pw.print(getDrawnStateEvaluated());
3182 pw.print(prefix); pw.print("mightAffectAllDrawn=");
Jorim Jaggie7d2b852017-08-28 17:55:15 +02003183 pw.println(mightAffectAllDrawn());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003184 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003185 pw.print(prefix); pw.print("mViewVisibility=0x");
3186 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003187 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
3188 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07003189 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
3190 pw.print(" mSystemUiVisibility=0x");
3191 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003192 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003193 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003194 || isParentWindowHidden()|| mPermanentlyHidden || mForceHideNonSystemOverlayWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003195 pw.print(prefix); pw.print("mPolicyVisibility=");
3196 pw.print(mPolicyVisibility);
3197 pw.print(" mPolicyVisibilityAfterAnim=");
3198 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003199 pw.print(" mAppOpVisibility=");
3200 pw.print(mAppOpVisibility);
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003201 pw.print(" parentHidden="); pw.print(isParentWindowHidden());
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003202 pw.print(" mPermanentlyHidden="); pw.print(mPermanentlyHidden);
3203 pw.print(" mForceHideNonSystemOverlayWindow="); pw.println(
3204 mForceHideNonSystemOverlayWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003205 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003206 if (!mRelayoutCalled || mLayoutNeeded) {
3207 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
3208 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003209 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003210 if (mXOffset != 0 || mYOffset != 0) {
3211 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
3212 pw.print(" y="); pw.println(mYOffset);
3213 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003214 if (dumpAll) {
3215 pw.print(prefix); pw.print("mGivenContentInsets=");
3216 mGivenContentInsets.printShortString(pw);
3217 pw.print(" mGivenVisibleInsets=");
3218 mGivenVisibleInsets.printShortString(pw);
3219 pw.println();
3220 if (mTouchableInsets != 0 || mGivenInsetsPending) {
3221 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
3222 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003223 Region region = new Region();
3224 getTouchableRegion(region);
3225 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003226 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003227 pw.print(prefix); pw.print("mFullConfiguration="); pw.println(getConfiguration());
3228 pw.print(prefix); pw.print("mLastReportedConfiguration=");
Bryce Lee2b17afd2017-09-21 10:38:20 -07003229 pw.println(getLastReportedConfiguration());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003230 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07003231 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07003232 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Chong Zhanga8975bd2016-01-28 17:13:47 -08003233 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08003234 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003235 if (dumpAll) {
3236 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
3237 pw.print(" last="); mLastFrame.printShortString(pw);
3238 pw.println();
3239 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003240 if (mEnforceSizeCompat) {
3241 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003242 pw.println();
3243 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003244 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003245 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003246 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003247 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003248 pw.println();
3249 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
3250 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003251 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003252 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003253 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003254 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04003255 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
3256 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003257 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
3258 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003259 pw.print(prefix); pw.print("Cur insets: overscan=");
3260 mOverscanInsets.printShortString(pw);
3261 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003262 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003263 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003264 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003265 pw.print(" outsets="); mOutsets.printShortString(pw);
Adrian Roos5c6b6222017-11-07 17:36:10 +01003266 pw.print(" cutout=" + mDisplayCutout);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003267 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003268 pw.print(prefix); pw.print("Lst insets: overscan=");
3269 mLastOverscanInsets.printShortString(pw);
3270 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003271 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003272 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003273 pw.print(" physical="); mLastOutsets.printShortString(pw);
3274 pw.print(" outset="); mLastOutsets.printShortString(pw);
Adrian Roos5c6b6222017-11-07 17:36:10 +01003275 pw.print(" cutout=" + mLastDisplayCutout);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003276 pw.println();
3277 }
Dianne Hackborn529e7442012-11-01 14:22:28 -07003278 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
3279 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003280 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
3281 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003282 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
3283 pw.print(" mDestroying="); pw.print(mDestroying);
3284 pw.print(" mRemoved="); pw.println(mRemoved);
3285 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07003286 if (getOrientationChanging() || mAppFreezing || mTurnOnScreen
Andrii Kulianb2e37802017-01-11 00:36:44 -08003287 || mReportOrientationChanged) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003288 pw.print(prefix); pw.print("mOrientationChanging=");
3289 pw.print(mOrientationChanging);
Bryce Lee8c3cf382017-07-06 19:47:10 -07003290 pw.print(" configOrientationChanging=");
Bryce Lee2b17afd2017-09-21 10:38:20 -07003291 pw.print(getLastReportedConfiguration().orientation
Bryce Lee8c3cf382017-07-06 19:47:10 -07003292 != getConfiguration().orientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003293 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003294 pw.print(" mTurnOnScreen="); pw.print(mTurnOnScreen);
Andrii Kulianb2e37802017-01-11 00:36:44 -08003295 pw.print(" mReportOrientationChanged="); pw.println(mReportOrientationChanged);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003296 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003297 if (mLastFreezeDuration != 0) {
3298 pw.print(prefix); pw.print("mLastFreezeDuration=");
3299 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
3300 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003301 if (mHScale != 1 || mVScale != 1) {
3302 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
3303 pw.print(" mVScale="); pw.println(mVScale);
3304 }
3305 if (mWallpaperX != -1 || mWallpaperY != -1) {
3306 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
3307 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
3308 }
3309 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
3310 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
3311 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
3312 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003313 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3314 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
3315 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
3316 pw.print(mWallpaperDisplayOffsetX);
3317 pw.print(" mWallpaperDisplayOffsetY=");
3318 pw.println(mWallpaperDisplayOffsetY);
3319 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003320 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07003321 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003322 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003323 if (isDragResizing()) {
3324 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
3325 }
3326 if (computeDragResizing()) {
3327 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
3328 }
Bryce Lee6311c4b2017-07-06 14:09:29 -07003329 pw.print(prefix); pw.println("isOnScreen=" + isOnScreen());
3330 pw.print(prefix); pw.println("isVisible=" + isVisible());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003331 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003332
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003333 @Override
3334 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003335 return Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003336 + " " + getWindowTag();
3337 }
3338
Robert Carra1eb4392015-12-10 12:43:51 -08003339 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003340 CharSequence tag = mAttrs.getTitle();
3341 if (tag == null || tag.length() <= 0) {
3342 tag = mAttrs.packageName;
3343 }
3344 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003345 }
3346
3347 @Override
3348 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003349 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003350 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003351 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003352 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003353 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003354 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003355 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003356 }
3357 return mStringNameCache;
3358 }
Robert Carr58f29132015-10-29 14:19:05 -07003359
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003360 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003361 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003362 clipRect.left = (int) (clipRect.left / mHScale);
3363 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003364 }
3365 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003366 clipRect.top = (int) (clipRect.top / mVScale);
3367 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003368 }
3369 }
Robert Carr31e28482015-12-02 16:53:18 -08003370
Jorim Jaggif5834272016-04-04 20:25:41 -07003371 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
3372 final int pw = containingFrame.width();
3373 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003374 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003375 final boolean inNonFullscreenContainer = !inFullscreenContainer();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003376 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3377
3378 // We need to fit it to the display if either
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003379 // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen
3380 // for the taskless windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003381 // 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 -07003382 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on
3383 // screen, but SurfaceViews want to be always at a specific location so we don't fit it to
3384 // the display.
3385 final boolean fitToDisplay = (task == null || !inNonFullscreenContainer)
Robert Carr6f44db12016-07-21 14:54:43 -07003386 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003387 float x, y;
3388 int w,h;
3389
3390 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3391 if (mAttrs.width < 0) {
3392 w = pw;
3393 } else if (mEnforceSizeCompat) {
3394 w = (int)(mAttrs.width * mGlobalScale + .5f);
3395 } else {
3396 w = mAttrs.width;
3397 }
3398 if (mAttrs.height < 0) {
3399 h = ph;
3400 } else if (mEnforceSizeCompat) {
3401 h = (int)(mAttrs.height * mGlobalScale + .5f);
3402 } else {
3403 h = mAttrs.height;
3404 }
3405 } else {
3406 if (mAttrs.width == MATCH_PARENT) {
3407 w = pw;
3408 } else if (mEnforceSizeCompat) {
3409 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3410 } else {
3411 w = mRequestedWidth;
3412 }
3413 if (mAttrs.height == MATCH_PARENT) {
3414 h = ph;
3415 } else if (mEnforceSizeCompat) {
3416 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3417 } else {
3418 h = mRequestedHeight;
3419 }
3420 }
3421
3422 if (mEnforceSizeCompat) {
3423 x = mAttrs.x * mGlobalScale;
3424 y = mAttrs.y * mGlobalScale;
3425 } else {
3426 x = mAttrs.x;
3427 y = mAttrs.y;
3428 }
3429
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003430 if (inNonFullscreenContainer && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003431 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003432 // required by {@link Gravity#apply} call.
3433 w = Math.min(w, pw);
3434 h = Math.min(h, ph);
3435 }
3436
3437 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003438 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003439 (int) (x + mAttrs.horizontalMargin * pw),
3440 (int) (y + mAttrs.verticalMargin * ph), mFrame);
3441
3442 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003443 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003444 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003445 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003446
3447 // We need to make sure we update the CompatFrame as it is used for
3448 // cropping decisions, etc, on systems where we lack a decor layer.
3449 mCompatFrame.set(mFrame);
3450 if (mEnforceSizeCompat) {
3451 // See comparable block in computeFrameLw.
3452 mCompatFrame.scale(mInvGlobalScale);
3453 }
Robert Carr31e28482015-12-02 16:53:18 -08003454 }
Robert Carr51a1b872015-12-08 14:03:13 -08003455
3456 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003457 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003458 }
3459
Robert Carrf3b72c72016-03-21 18:16:39 -07003460 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003461 return mIsChildWindow
3462 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003463 }
3464
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003465 /**
3466 * Returns true if any window added by an application process that if of type
3467 * {@link android.view.WindowManager.LayoutParams#TYPE_TOAST} or that requires that requires
3468 * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when
3469 * this window is visible.
3470 */
3471 boolean hideNonSystemOverlayWindowsWhenVisible() {
3472 return (mAttrs.privateFlags & PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != 0
3473 && mSession.mCanHideNonSystemOverlayWindows;
3474 }
3475
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003476 /** Returns the parent window if this is a child of another window, else null. */
3477 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003478 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3479 // WindowContainer that isn't a WindowState.
3480 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003481 }
3482
3483 /** Returns the topmost parent window if this is a child of another window, else this. */
3484 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003485 WindowState current = this;
3486 WindowState topParent = current;
3487 while (current != null && current.mIsChildWindow) {
3488 current = current.getParentWindow();
3489 // Parent window can be null if the child is detached from it's parent already, but
3490 // someone still has a reference to access it. So, we return the top parent value we
3491 // already have instead of null.
3492 if (current != null) {
3493 topParent = current;
3494 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003495 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003496 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003497 }
3498
Wale Ogunwale9d147902016-07-16 11:58:55 -07003499 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003500 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003501 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003502 }
3503
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003504 void setWillReplaceWindow(boolean animate) {
3505 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003506 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003507 c.setWillReplaceWindow(animate);
3508 }
3509
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003510 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3511 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3512 // We don't set replacing on starting windows since they are added by window manager and
3513 // not the client so won't be replaced by the client.
3514 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003515 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003516
3517 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003518 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003519 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003520 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003521
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003522 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003523 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003524 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003525 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003526
3527 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003528 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003529 c.clearWillReplaceWindow();
3530 }
3531 }
3532
3533 boolean waitingForReplacement() {
3534 if (mWillReplaceWindow) {
3535 return true;
3536 }
3537
3538 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003539 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003540 if (c.waitingForReplacement()) {
3541 return true;
3542 }
3543 }
3544 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003545 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003546
Chong Zhang4d7369a2016-04-25 16:09:14 -07003547 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003548 final DisplayContent dc = getDisplayContent();
3549 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3550 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3551 dc.setLayoutNeeded();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003552 mService.mWindowPlacerLocked.requestTraversal();
3553 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003554
3555 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003556 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003557 c.requestUpdateWallpaperIfNeeded();
3558 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003559 }
3560
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003561 float translateToWindowX(float x) {
3562 float winX = x - mFrame.left;
3563 if (mEnforceSizeCompat) {
3564 winX *= mGlobalScale;
3565 }
3566 return winX;
3567 }
3568
3569 float translateToWindowY(float y) {
3570 float winY = y - mFrame.top;
3571 if (mEnforceSizeCompat) {
3572 winY *= mGlobalScale;
3573 }
3574 return winY;
3575 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003576
3577 // During activity relaunch due to resize, we sometimes use window replacement
3578 // for only child windows (as the main window is handled by window preservation)
3579 // and the big surface.
3580 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003581 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3582 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3583 // we also want to replace them at such phases, as they won't be covered by window
3584 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003585 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003586 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003587 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003588 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003589
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003590 void setWillReplaceChildWindows() {
3591 if (shouldBeReplacedWithChildren()) {
3592 setWillReplaceWindow(false /* animate */);
3593 }
3594 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003595 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003596 c.setWillReplaceChildWindows();
3597 }
3598 }
3599
3600 WindowState getReplacingWindow() {
3601 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3602 return this;
3603 }
3604 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003605 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003606 final WindowState replacing = c.getReplacingWindow();
3607 if (replacing != null) {
3608 return replacing;
3609 }
3610 }
3611 return null;
3612 }
3613
Jorim Jaggife762342016-10-13 14:33:27 +02003614 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07003615 public int getRotationAnimationHint() {
3616 if (mAppToken != null) {
3617 return mAppToken.mRotationAnimationHint;
3618 } else {
3619 return -1;
3620 }
3621 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003622
Jorim Jaggife762342016-10-13 14:33:27 +02003623 @Override
3624 public boolean isInputMethodWindow() {
3625 return mIsImWindow;
3626 }
3627
Wale Ogunwale9d147902016-07-16 11:58:55 -07003628 // This must be called while inside a transaction.
3629 boolean performShowLocked() {
3630 if (isHiddenFromUserLocked()) {
3631 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3632 hideLw(false);
3633 return false;
3634 }
3635
3636 logPerformShow("performShow on ");
3637
Jorim Jaggia50da602016-12-29 11:51:42 +01003638 final int drawState = mWinAnimator.mDrawState;
3639 if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW)
3640 && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3641 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3642 }
3643
Jorim Jaggib0d27342016-11-01 16:10:42 -07003644 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003645 return false;
3646 }
3647
3648 logPerformShow("Showing ");
3649
3650 mService.enableScreenIfNeededLocked();
3651 mWinAnimator.applyEnterAnimationLocked();
3652
3653 // Force the show in the next prepareSurfaceLocked() call.
3654 mWinAnimator.mLastAlpha = -1;
Robert Carre13b58e2017-08-31 14:50:44 -07003655 if (DEBUG_ANIM) Slog.v(TAG,
Wale Ogunwale9d147902016-07-16 11:58:55 -07003656 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3657 mWinAnimator.mDrawState = HAS_DRAWN;
3658 mService.scheduleAnimationLocked();
3659
3660 if (mHidden) {
3661 mHidden = false;
3662 final DisplayContent displayContent = getDisplayContent();
3663
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003664 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003665 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003666 if (c.mWinAnimator.mSurfaceController != null) {
3667 c.performShowLocked();
3668 // It hadn't been shown, which means layout not performed on it, so now we
3669 // want to make sure to do a layout. If called from within the transaction
3670 // loop, this will cause it to restart with a new layout.
3671 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003672 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003673 }
3674 }
3675 }
3676 }
3677
Wale Ogunwale9d147902016-07-16 11:58:55 -07003678 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003679 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003680 }
3681
3682 return true;
3683 }
3684
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003685 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003686 if (DEBUG_VISIBILITY
Jorim Jaggie4b0f282017-05-17 15:10:29 +02003687 || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003688 Slog.v(TAG, prefix + this
3689 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07003690 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003691 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3692 + " during animation: policyVis=" + mPolicyVisibility
3693 + " parentHidden=" + isParentWindowHidden()
3694 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003695 + (mAppToken != null && mAppToken.hiddenRequested)
3696 + " tok.hidden=" + (mAppToken != null && mAppToken.hidden)
Wale Ogunwale9d147902016-07-16 11:58:55 -07003697 + " animating=" + mWinAnimator.mAnimating
3698 + " tok animating="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003699 + (mWinAnimator.mAppAnimator != null && mWinAnimator.mAppAnimator.animating)
Wale Ogunwale9d147902016-07-16 11:58:55 -07003700 + " Callers=" + Debug.getCallers(4));
3701 }
3702 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003703
3704 WindowInfo getWindowInfo() {
3705 WindowInfo windowInfo = WindowInfo.obtain();
3706 windowInfo.type = mAttrs.type;
3707 windowInfo.layer = mLayer;
3708 windowInfo.token = mClient.asBinder();
Phil Weaver5dc3ebc2017-08-16 13:04:20 -07003709 if (mAppToken != null) {
3710 windowInfo.activityToken = mAppToken.appToken.asBinder();
3711 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003712 windowInfo.title = mAttrs.accessibilityTitle;
3713 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3714 windowInfo.focused = isFocused();
Phil Weaverf00cd142017-03-03 13:44:00 -08003715 Task task = getTask();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003716 windowInfo.inPictureInPicture = (task != null) && task.inPinnedWindowingMode();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003717
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003718 if (mIsChildWindow) {
3719 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003720 }
3721
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003722 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003723 if (childCount > 0) {
3724 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003725 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003726 }
3727 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003728 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003729 windowInfo.childTokens.add(child.mClient.asBinder());
3730 }
3731 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003732 return windowInfo;
3733 }
3734
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003735 int getHighestAnimLayer() {
3736 int highest = mWinAnimator.mAnimLayer;
3737 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003738 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003739 final int childLayer = c.getHighestAnimLayer();
3740 if (childLayer > highest) {
3741 highest = childLayer;
3742 }
3743 }
3744 return highest;
3745 }
3746
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003747 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003748 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003749 if (mChildren.isEmpty()) {
3750 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003751 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003752 }
3753
3754 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003755 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003756 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003757 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003758 }
3759 }
3760
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003761 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003762 // We want to consume the negative sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003763 // below the parent, then this window (the parent), and then the positive sublayer children
3764 // because they need to appear above the parent.
3765 int i = 0;
3766 final int count = mChildren.size();
3767 WindowState child = mChildren.get(i);
3768
3769 while (i < count && child.mSubLayer < 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003770 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003771 return true;
3772 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003773 i++;
3774 if (i >= count) {
3775 break;
3776 }
3777 child = mChildren.get(i);
3778 }
3779
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003780 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003781 return true;
3782 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003783
3784 while (i < count) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003785 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003786 return true;
3787 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003788 i++;
3789 if (i >= count) {
3790 break;
3791 }
3792 child = mChildren.get(i);
3793 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003794
3795 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003796 }
3797
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003798 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003799 // We want to consume the positive sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003800 // above the parent, then this window (the parent), and then the negative sublayer children
3801 // because they need to appear above the parent.
3802 int i = mChildren.size() - 1;
3803 WindowState child = mChildren.get(i);
3804
3805 while (i >= 0 && child.mSubLayer >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003806 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003807 return true;
3808 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003809 --i;
3810 if (i < 0) {
3811 break;
3812 }
3813 child = mChildren.get(i);
3814 }
3815
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003816 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003817 return true;
3818 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003819
3820 while (i >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003821 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003822 return true;
3823 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003824 --i;
3825 if (i < 0) {
3826 break;
3827 }
3828 child = mChildren.get(i);
3829 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003830
3831 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003832 }
3833
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003834 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
3835 boolean traverseTopToBottom) {
3836 if (traverseTopToBottom) {
3837 if (mService.mInputMethodTarget == this) {
3838 // This window is the current IME target, so we need to process the IME windows
3839 // directly above it.
3840 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
3841 return true;
3842 }
3843 }
3844 if (callback.apply(this)) {
3845 return true;
3846 }
3847 } else {
3848 if (callback.apply(this)) {
3849 return true;
3850 }
3851 if (mService.mInputMethodTarget == this) {
3852 // This window is the current IME target, so we need to process the IME windows
3853 // directly above it.
3854 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
3855 return true;
3856 }
3857 }
3858 }
3859
3860 return false;
3861 }
3862
Wale Ogunwaled1880962016-11-08 10:31:59 -08003863 WindowState getWindow(Predicate<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003864 if (mChildren.isEmpty()) {
3865 return callback.test(this) ? this : null;
3866 }
3867
3868 // We want to consume the positive sublayer children first because they need to appear
3869 // above the parent, then this window (the parent), and then the negative sublayer children
3870 // because they need to appear above the parent.
3871 int i = mChildren.size() - 1;
3872 WindowState child = mChildren.get(i);
3873
3874 while (i >= 0 && child.mSubLayer >= 0) {
3875 if (callback.test(child)) {
3876 return child;
3877 }
3878 --i;
3879 if (i < 0) {
3880 break;
3881 }
3882 child = mChildren.get(i);
3883 }
3884
Wale Ogunwaled1880962016-11-08 10:31:59 -08003885 if (callback.test(this)) {
3886 return this;
3887 }
Wale Ogunwale34247952017-02-19 11:57:53 -08003888
3889 while (i >= 0) {
3890 if (callback.test(child)) {
3891 return child;
3892 }
3893 --i;
3894 if (i < 0) {
3895 break;
3896 }
3897 child = mChildren.get(i);
3898 }
3899
3900 return null;
Wale Ogunwaled1880962016-11-08 10:31:59 -08003901 }
3902
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003903 boolean isWindowAnimationSet() {
3904 if (mWinAnimator.isWindowAnimationSet()) {
3905 return true;
3906 }
3907 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003908 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003909 if (c.isWindowAnimationSet()) {
3910 return true;
3911 }
3912 }
3913 return false;
3914 }
3915
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003916 void onExitAnimationDone() {
3917 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
3918 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
3919 + " windowAnimating=" + mWinAnimator.isWindowAnimationSet());
3920
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003921 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003922 // Copying to a different list as multiple children can be removed.
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003923 // TODO: Not sure if we really need to copy this into a different list.
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003924 final LinkedList<WindowState> childWindows = new LinkedList(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003925 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003926 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003927 }
3928 }
3929
3930 if (mWinAnimator.mEnteringAnimation) {
3931 mWinAnimator.mEnteringAnimation = false;
3932 mService.requestTraversal();
3933 // System windows don't have an activity and an app token as a result, but need a way
3934 // to be informed about their entrance animation end.
3935 if (mAppToken == null) {
3936 try {
3937 mClient.dispatchWindowShown();
3938 } catch (RemoteException e) {
3939 }
3940 }
3941 }
3942
3943 if (!mWinAnimator.isWindowAnimationSet()) {
3944 //TODO (multidisplay): Accessibility is supported only for the default display.
3945 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
3946 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
3947 }
3948 }
3949
3950 if (!mAnimatingExit) {
3951 return;
3952 }
3953
3954 if (mWinAnimator.isWindowAnimationSet()) {
3955 return;
3956 }
3957
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07003958 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003959 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
3960
3961 mDestroying = true;
3962
3963 final boolean hasSurface = mWinAnimator.hasSurface();
3964 if (hasSurface) {
3965 mWinAnimator.hide("onExitAnimationDone");
3966 }
3967
3968 // If we have an app token, we ask it to destroy the surface for us, so that it can take
3969 // care to ensure the activity has actually stopped and the surface is not still in use.
3970 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
3971 // transaction.
3972 if (mAppToken != null) {
3973 mAppToken.destroySurfaces();
3974 } else {
3975 if (hasSurface) {
3976 mService.mDestroySurface.add(this);
3977 }
3978 if (mRemoveOnExit) {
3979 mService.mPendingRemove.add(this);
3980 mRemoveOnExit = false;
3981 }
3982 }
3983 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07003984 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003985 }
Dan Willemsen117197f2016-07-30 13:02:59 -07003986
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003987 boolean clearAnimatingFlags() {
3988 boolean didSomething = false;
3989 // We don't want to clear it out for windows that get replaced, because the
3990 // animation depends on the flag to remove the replaced window.
3991 //
3992 // We also don't clear the mAnimatingExit flag for windows which have the
3993 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
3994 // by the client. We should let animation proceed and not clear this flag or
3995 // they won't eventually be removed by WindowStateAnimator#finishExit.
3996 if (!mWillReplaceWindow && !mRemoveOnExit) {
3997 // Clear mAnimating flag together with mAnimatingExit. When animation
3998 // changes from exiting to entering, we need to clear this flag until the
3999 // new animation gets applied, so that isAnimationStarting() becomes true
4000 // until then.
4001 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4002 // placement for this window during this period, one or more frame will
4003 // show up with wrong position or scale.
4004 if (mAnimatingExit) {
4005 mAnimatingExit = false;
4006 didSomething = true;
4007 }
4008 if (mWinAnimator.mAnimating) {
4009 mWinAnimator.mAnimating = false;
4010 didSomething = true;
4011 }
4012 if (mDestroying) {
4013 mDestroying = false;
4014 mService.mDestroySurface.remove(this);
4015 didSomething = true;
4016 }
4017 }
4018
4019 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004020 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004021 }
4022
4023 return didSomething;
4024 }
4025
Winson4b4ba902016-07-27 19:45:52 -07004026 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004027 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004028 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004029
4030 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004031 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004032 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004033 c.hideWallpaperWindow(wasDeferred, reason);
4034 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004035 if (!mWinAnimator.mLastHidden || wasDeferred) {
4036 mWinAnimator.hide(reason);
4037 dispatchWallpaperVisibility(false);
4038 final DisplayContent displayContent = getDisplayContent();
4039 if (displayContent != null) {
4040 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
4041 }
4042 }
4043 }
4044
4045 /**
4046 * Check wallpaper window for visibility change and notify window if so.
4047 * @param visible Current visibility.
4048 */
4049 void dispatchWallpaperVisibility(final boolean visible) {
4050 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07004051 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004052
4053 // Only send notification if the visibility actually changed and we are not trying to hide
4054 // the wallpaper when we are deferring hiding of the wallpaper.
4055 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4056 mWallpaperVisible = visible;
4057 try {
4058 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4059 "Updating vis of wallpaper " + this
4060 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4061 mClient.dispatchAppVisibility(visible);
4062 } catch (RemoteException e) {
4063 }
4064 }
4065 }
4066
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004067 boolean hasVisibleNotDrawnWallpaper() {
4068 if (mWallpaperVisible && !isDrawnLw()) {
4069 return true;
4070 }
4071 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004072 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004073 if (c.hasVisibleNotDrawnWallpaper()) {
4074 return true;
4075 }
4076 }
4077 return false;
4078 }
4079
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004080 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4081 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004082 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004083 c.updateReportedVisibility(results);
4084 }
4085
4086 if (mAppFreezing || mViewVisibility != View.VISIBLE
4087 || mAttrs.type == TYPE_APPLICATION_STARTING
4088 || mDestroying) {
4089 return;
4090 }
4091 if (DEBUG_VISIBILITY) {
4092 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
4093 + ", isAnimationSet=" + mWinAnimator.isAnimationSet());
4094 if (!isDrawnLw()) {
4095 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4096 + " pv=" + mPolicyVisibility
4097 + " mDrawState=" + mWinAnimator.mDrawState
4098 + " ph=" + isParentWindowHidden()
4099 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
4100 + " a=" + mWinAnimator.mAnimating);
4101 }
4102 }
4103
4104 results.numInteresting++;
4105 if (isDrawnLw()) {
4106 results.numDrawn++;
4107 if (!mWinAnimator.isAnimationSet()) {
4108 results.numVisible++;
4109 }
4110 results.nowGone = false;
4111 } else if (mWinAnimator.isAnimationSet()) {
4112 results.nowGone = false;
4113 }
4114 }
4115
Robert Carrfbbde852016-10-18 11:02:28 -07004116 /**
4117 * Calculate the window crop according to system decor policy. In general this is
4118 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4119 * special cases. This rectangle is in screen space.
4120 */
4121 void calculatePolicyCrop(Rect policyCrop) {
4122 final DisplayContent displayContent = getDisplayContent();
4123 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
4124
4125 if (!isDefaultDisplay()) {
4126 // On a different display there is no system decor. Crop the window
4127 // by the screen boundaries.
4128 // TODO(multi-display)
4129 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4130 policyCrop.intersect(-mCompatFrame.left, -mCompatFrame.top,
4131 displayInfo.logicalWidth - mCompatFrame.left,
4132 displayInfo.logicalHeight - mCompatFrame.top);
Robert Carrfbbde852016-10-18 11:02:28 -07004133 } else if (mDecorFrame.isEmpty()) {
4134 // Windows without policy decor aren't cropped.
4135 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4136 } else {
4137 // Crop to the system decor specified by policy.
4138 calculateSystemDecorRect(policyCrop);
4139 }
4140 }
4141
4142 /**
4143 * The system decor rect is the region of the window which is not covered
4144 * by system decorations.
4145 */
4146 private void calculateSystemDecorRect(Rect systemDecorRect) {
4147 final Rect decorRect = mDecorFrame;
4148 final int width = mFrame.width();
4149 final int height = mFrame.height();
4150
4151 // Compute the offset of the window in relation to the decor rect.
4152 final int left = mXOffset + mFrame.left;
4153 final int top = mYOffset + mFrame.top;
4154
4155 // Initialize the decor rect to the entire frame.
4156 if (isDockedResizing()) {
4157 // If we are resizing with the divider, the task bounds might be smaller than the
4158 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4159 // want in this case in order to avoid holes.
4160 //
4161 // We take care to not shrink the width, for surfaces which are larger than
4162 // the display region. Of course this area will not eventually be visible
4163 // but if we truncate the width now, we will calculate incorrectly
4164 // when adjusting to the stack bounds.
4165 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4166 systemDecorRect.set(0, 0,
4167 Math.max(width, displayInfo.logicalWidth),
4168 Math.max(height, displayInfo.logicalHeight));
4169 } else {
4170 systemDecorRect.set(0, 0, width, height);
4171 }
4172
4173 // If a freeform window is animating from a position where it would be cutoff, it would be
4174 // cutoff during the animation. We don't want that, so for the duration of the animation
4175 // we ignore the decor cropping and depend on layering to position windows correctly.
Wale Ogunwale44f036f2017-09-29 05:09:09 -07004176 final boolean cropToDecor = !(inFreeformWindowingMode() && isAnimatingLw());
Robert Carrfbbde852016-10-18 11:02:28 -07004177 if (cropToDecor) {
4178 // Intersect with the decor rect, offsetted by window position.
4179 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
4180 decorRect.right - left, decorRect.bottom - top);
4181 }
4182
4183 // If size compatibility is being applied to the window, the
4184 // surface is scaled relative to the screen. Also apply this
4185 // scaling to the crop rect. We aren't using the standard rect
4186 // scale function because we want to round things to make the crop
4187 // always round to a larger rect to ensure we don't crop too
4188 // much and hide part of the window that should be seen.
4189 if (mEnforceSizeCompat && mInvGlobalScale != 1.0f) {
4190 final float scale = mInvGlobalScale;
4191 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
4192 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
4193 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
4194 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
4195 }
4196
4197 }
4198
4199 /**
4200 * Expand the given rectangle by this windows surface insets. This
4201 * takes you from the 'window size' to the 'surface size'.
4202 * The surface insets are positive in each direction, so we inset by
4203 * the inverse.
4204 */
4205 void expandForSurfaceInsets(Rect r) {
4206 r.inset(-mAttrs.surfaceInsets.left,
4207 -mAttrs.surfaceInsets.top,
4208 -mAttrs.surfaceInsets.right,
4209 -mAttrs.surfaceInsets.bottom);
4210 }
4211
Robert Carrc91d1c32017-02-15 19:37:46 -08004212 boolean surfaceInsetsChanging() {
4213 return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets);
4214 }
4215
Bryce Leef858b572017-06-29 14:03:33 -07004216 int relayoutVisibleWindow(int result, int attrChanges, int oldVisibility) {
Robert Carrecc06b32017-04-18 14:25:10 -07004217 final boolean wasVisible = isVisibleLw();
4218
4219 result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004220 if (mAnimatingExit) {
4221 Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit="
4222 + mRemoveOnExit + ", mDestroying=" + mDestroying);
4223
4224 mWinAnimator.cancelExitAnimationForNextAnimationLocked();
4225 mAnimatingExit = false;
4226 }
4227 if (mDestroying) {
4228 mDestroying = false;
4229 mService.mDestroySurface.remove(this);
4230 }
4231 if (oldVisibility == View.GONE) {
4232 mWinAnimator.mEnterAnimationPending = true;
4233 }
4234
Andrii Kulian8ee72852017-03-10 10:36:45 -08004235 mLastVisibleLayoutRotation = getDisplayContent().getRotation();
Robert Carrc91d1c32017-02-15 19:37:46 -08004236
4237 mWinAnimator.mEnteringAnimation = true;
Bryce Leeae73ba42017-05-05 09:58:25 -07004238
Bryce Leef858b572017-06-29 14:03:33 -07004239 prepareWindowToDisplayDuringRelayout(wasVisible);
Bryce Leeae73ba42017-05-05 09:58:25 -07004240
Robert Carrc91d1c32017-02-15 19:37:46 -08004241 if ((attrChanges & FORMAT_CHANGED) != 0) {
4242 // If the format can't be changed in place, preserve the old surface until the app draws
4243 // on the new one. This prevents blinking when we change elevation of freeform and
4244 // pinned windows.
4245 if (!mWinAnimator.tryChangeFormatInPlaceLocked()) {
4246 mWinAnimator.preserveSurfaceLocked();
4247 result |= RELAYOUT_RES_SURFACE_CHANGED
4248 | RELAYOUT_RES_FIRST_TIME;
4249 }
4250 }
4251
4252 // When we change the Surface size, in scenarios which may require changing
4253 // the surface position in sync with the resize, we use a preserved surface
4254 // so we can freeze it while waiting for the client to report draw on the newly
Winson Chung8bca9e42017-04-16 15:59:43 -07004255 // sized surface. Don't preserve surfaces if the insets change while animating the pinned
4256 // stack since it can lead to issues if a new surface is created while calculating the
4257 // scale for the animation using the source hint rect
4258 // (see WindowStateAnimator#setSurfaceBoundariesLocked()).
Robert Carrc91d1c32017-02-15 19:37:46 -08004259 if (isDragResizeChanged() || isResizedWhileNotDragResizing()
Wale Ogunwale44f036f2017-09-29 05:09:09 -07004260 || (surfaceInsetsChanging() && !inPinnedWindowingMode())) {
Robert Carrc91d1c32017-02-15 19:37:46 -08004261 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
4262
4263 setDragResizing();
4264 setResizedWhileNotDragResizing(false);
4265 // We can only change top level windows to the full-screen surface when
4266 // resizing (as we only have one full-screen surface). So there is no need
4267 // to preserve and destroy windows which are attached to another, they
4268 // will keep their surface and its size may change over time.
4269 if (mHasSurface && !isChildWindow()) {
4270 mWinAnimator.preserveSurfaceLocked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08004271 result |= RELAYOUT_RES_SURFACE_CHANGED |
4272 RELAYOUT_RES_FIRST_TIME;
Robert Carrc91d1c32017-02-15 19:37:46 -08004273 }
4274 }
4275 final boolean freeformResizing = isDragResizing()
4276 && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
4277 final boolean dockedResizing = isDragResizing()
4278 && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
4279 result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0;
4280 result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004281 return result;
4282 }
4283
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004284 /**
4285 * @return True if this window has been laid out at least once; false otherwise.
4286 */
4287 boolean isLaidOut() {
4288 return mLayoutSeq != -1;
4289 }
4290
4291 /**
4292 * Updates the last inset values to the current ones.
4293 */
4294 void updateLastInsetValues() {
4295 mLastOverscanInsets.set(mOverscanInsets);
4296 mLastContentInsets.set(mContentInsets);
4297 mLastVisibleInsets.set(mVisibleInsets);
4298 mLastStableInsets.set(mStableInsets);
4299 mLastOutsets.set(mOutsets);
Adrian Roos5c6b6222017-11-07 17:36:10 +01004300 mLastDisplayCutout = mDisplayCutout;
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004301 }
4302
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004303 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4304 // access to its windows children. Need to investigate re-writing
4305 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4306 static final class UpdateReportedVisibilityResults {
4307 int numInteresting;
4308 int numVisible;
4309 int numDrawn;
4310 boolean nowGone = true;
4311
4312 void reset() {
4313 numInteresting = 0;
4314 numVisible = 0;
4315 numDrawn = 0;
4316 nowGone = true;
4317 }
4318 }
Robert Carraf422a82017-04-10 18:34:33 -07004319
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004320 private static final class WindowId extends IWindowId.Stub {
4321 private final WeakReference<WindowState> mOuter;
4322
4323 private WindowId(WindowState outer) {
4324
4325 // Use a weak reference for the outer class. This is important to prevent the following
4326 // leak: Since we send this class to the client process, binder will keep it alive as
4327 // long as the client keeps it alive. Now, if the window is removed, we need to clear
4328 // out our reference so even though this class is kept alive we don't leak WindowState,
4329 // which can keep a whole lot of classes alive.
4330 mOuter = new WeakReference<>(outer);
4331 }
4332
4333 @Override
4334 public void registerFocusObserver(IWindowFocusObserver observer) {
4335 final WindowState outer = mOuter.get();
4336 if (outer != null) {
4337 outer.registerFocusObserver(observer);
4338 }
4339 }
4340 @Override
4341 public void unregisterFocusObserver(IWindowFocusObserver observer) {
4342 final WindowState outer = mOuter.get();
4343 if (outer != null) {
4344 outer.unregisterFocusObserver(observer);
4345 }
4346 }
4347 @Override
4348 public boolean isFocused() {
4349 final WindowState outer = mOuter.get();
4350 return outer != null && outer.isFocused();
4351 }
4352 }
4353
Robert Carrb1579c82017-09-05 14:54:47 -07004354
4355 @Override
4356 boolean shouldMagnify() {
4357 if (mAttrs.type == TYPE_INPUT_METHOD ||
Robert Carree4d4b92017-11-22 12:21:46 -08004358 mAttrs.type == TYPE_INPUT_METHOD_DIALOG ||
4359 mAttrs.type == TYPE_MAGNIFICATION_OVERLAY ||
4360 mAttrs.type == TYPE_NAVIGATION_BAR ||
4361 // It's tempting to wonder: Have we forgotten the rounded corners overlay?
4362 // worry not: it's a fake TYPE_NAVIGATION_BAR_PANEL
4363 mAttrs.type == TYPE_NAVIGATION_BAR_PANEL ||
4364 mAttrs.type == TYPE_STATUS_BAR) {
Robert Carrb1579c82017-09-05 14:54:47 -07004365 return false;
4366 }
4367 return true;
4368 }
4369
4370 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004371 SurfaceSession getSession() {
4372 if (mSession.mSurfaceSession != null) {
4373 return mSession.mSurfaceSession;
4374 } else {
4375 return getParent().getSession();
4376 }
4377 }
4378
4379 @Override
4380 boolean needsZBoost() {
4381 return getAnimLayerAdjustment() > 0 || mWillReplaceWindow;
4382 }
4383
4384 @Override
4385 SurfaceControl.Builder makeSurface() {
Robert Carr29d196f2017-11-28 12:39:46 -08004386 return getParent().makeChildSurface(this);
Robert Carrb1579c82017-09-05 14:54:47 -07004387 }
4388
Robert Carrf07ef9e2017-11-21 12:12:49 -08004389 private void applyDims(Dimmer dimmer) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07004390 if (!mAnimatingExit && mAppDied) {
4391 mIsDimming = true;
4392 getDimmer().dimAbove(getPendingTransaction(), this, DEFAULT_DIM_AMOUNT_DEAD_WINDOW);
4393 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
4394 && !mAnimatingExit && isVisible()) {
4395 mIsDimming = true;
4396 getDimmer().dimBelow(getPendingTransaction(), this, mAttrs.dimAmount);
4397 }
Robert Carrf07ef9e2017-11-21 12:12:49 -08004398 }
4399
4400 @Override
4401 void prepareSurfaces() {
4402 final Dimmer dimmer = getDimmer();
4403 mIsDimming = false;
4404 if (dimmer != null) {
4405 applyDims(dimmer);
4406 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07004407
Robert Carrb1579c82017-09-05 14:54:47 -07004408 mWinAnimator.prepareSurfaceLocked(true);
4409 super.prepareSurfaces();
4410 }
4411
4412 @Override
4413 void assignLayer(Transaction t, int layer) {
4414 // See comment in assignRelativeLayerForImeTargetChild
4415 if (!isChildWindow()
4416 || (mService.mInputMethodTarget != getParentWindow())
4417 || !inSplitScreenWindowingMode()) {
4418 super.assignLayer(t, layer);
4419 return;
4420 }
4421 getDisplayContent().assignRelativeLayerForImeTargetChild(t, this);
4422 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07004423
4424 @Override
4425 public boolean isDimming() {
4426 return mIsDimming;
4427 }
Robert Carr0eff1872017-12-01 14:27:04 -08004428
4429 // TODO(b/70040778): We should aim to eliminate the last user of TYPE_APPLICATION_MEDIA
4430 // then we can drop all negative layering on the windowing side and simply inherit
4431 // the default implementation here.
4432 public void assignChildLayers(Transaction t) {
4433 int layer = 1;
4434 for (int i = 0; i < mChildren.size(); i++) {
4435 final WindowState w = mChildren.get(i);
4436
4437 // APPLICATION_MEDIA_OVERLAY needs to go above APPLICATION_MEDIA
4438 // while they both need to go below the main window. However the
4439 // relative layering of multiple APPLICATION_MEDIA/OVERLAY has never
4440 // been defined and so we can use static layers and leave it that way.
4441 if (w.mAttrs.type == TYPE_APPLICATION_MEDIA) {
4442 w.assignLayer(t, -2);
4443 } else if (w.mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) {
4444 w.assignLayer(t, -1);
4445 } else {
4446 w.assignLayer(t, layer);
4447 }
4448 w.assignChildLayers(t);
4449 layer++;
4450 }
4451 }
satokcef37fb2011-10-24 21:49:38 +09004452}