blob: 009f3930d02e32718a980649fb2f9b9aabe55446 [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;
Svet Ganovf7b47252018-02-26 11:11:27 -080020import static android.app.AppOpsManager.MODE_ALLOWED;
21import static android.app.AppOpsManager.MODE_DEFAULT;
22import static android.app.AppOpsManager.OP_NONE;
chaviw40234662018-02-07 09:37:16 -080023import static android.os.PowerManager.DRAW_WAKE_LOCK;
Jorim Jaggi02886a82016-12-06 09:10:06 -080024import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
25import static android.view.Display.DEFAULT_DISPLAY;
Jorim Jaggia5e10572017-11-15 14:36:26 +010026import static android.view.SurfaceControl.Transaction;
Jorim Jaggi02886a82016-12-06 09:10:06 -080027import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
28import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
29import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
30import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
31import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
32import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW;
33import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
34import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
35import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
36import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
37import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
38import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
39import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
40import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080041import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
42import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
43import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Robert Carrc91d1c32017-02-15 19:37:46 -080044import static android.view.WindowManager.LayoutParams.FORMAT_CHANGED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080045import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
Adrian Roosfa02da62018-01-15 16:01:18 +010046import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Jorim Jaggi02886a82016-12-06 09:10:06 -080047import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
48import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070049import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Jorim Jaggi02886a82016-12-06 09:10:06 -080050import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
51import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
52import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
53import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
54import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
55import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Robert Carr0eff1872017-12-01 14:27:04 -080056import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;
Vishnu Nair1d0fa072018-01-04 07:53:00 -080057import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080058import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
59import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
60import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
61import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
62import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
63import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Robert Carrb1579c82017-09-05 14:54:47 -070064import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY;
65import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
Robert Carree4d4b92017-11-22 12:21:46 -080066import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070067import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Jorim Jaggi02886a82016-12-06 09:10:06 -080068import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070069import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType;
Robert Carrc91d1c32017-02-15 19:37:46 -080070import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED;
71import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM;
72import static android.view.WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME;
73import static android.view.WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED;
Adrian Roose99bc052017-11-20 17:55:31 +010074import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
75import static com.android.server.policy.WindowManagerPolicy.TRANSIT_ENTER;
76import static com.android.server.policy.WindowManagerPolicy.TRANSIT_EXIT;
77import static com.android.server.policy.WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
Jorim Jaggi02886a82016-12-06 09:10:06 -080078import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
79import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
80import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
81import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
82import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
83import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
84import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
85import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
86import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Jorim Jaggi02886a82016-12-06 09:10:06 -080087import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
88import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
89import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
90import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
91import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020092import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Jorim Jaggi02886a82016-12-06 09:10:06 -080093import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080094import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
95import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
96import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
97import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
Jorim Jaggia5e10572017-11-15 14:36:26 +010098import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
Jorim Jaggi02886a82016-12-06 09:10:06 -080099import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
100import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
101import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
102import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
103import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
104import static com.android.server.wm.WindowManagerService.localLOGV;
105import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING;
106import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
107import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN;
108import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700109import static com.android.server.wm.IdentifierProto.HASH_CODE;
110import static com.android.server.wm.IdentifierProto.TITLE;
111import static com.android.server.wm.IdentifierProto.USER_ID;
112import static com.android.server.wm.AnimationSpecProto.MOVE;
Kweku Adams21b8d262018-03-30 12:19:58 -0700113import static com.android.server.wm.MoveAnimationSpecProto.DURATION_MS;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700114import static com.android.server.wm.MoveAnimationSpecProto.FROM;
115import static com.android.server.wm.MoveAnimationSpecProto.TO;
116import static com.android.server.wm.WindowStateProto.ANIMATING_EXIT;
117import static com.android.server.wm.WindowStateProto.ANIMATOR;
118import static com.android.server.wm.WindowStateProto.ATTRIBUTES;
119import static com.android.server.wm.WindowStateProto.CHILD_WINDOWS;
120import static com.android.server.wm.WindowStateProto.CONTAINING_FRAME;
121import static com.android.server.wm.WindowStateProto.CONTENT_FRAME;
122import static com.android.server.wm.WindowStateProto.CONTENT_INSETS;
123import static com.android.server.wm.WindowStateProto.CUTOUT;
124import static com.android.server.wm.WindowStateProto.DECOR_FRAME;
125import static com.android.server.wm.WindowStateProto.DESTROYING;
126import static com.android.server.wm.WindowStateProto.DISPLAY_FRAME;
127import static com.android.server.wm.WindowStateProto.DISPLAY_ID;
Adrian Roos2cadc5c2018-07-06 02:39:54 -0700128import static com.android.server.wm.WindowStateProto.FINISHED_FORCED_SEAMLESS_ROTATION_FRAME;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700129import static com.android.server.wm.WindowStateProto.FRAME;
130import static com.android.server.wm.WindowStateProto.GIVEN_CONTENT_INSETS;
131import static com.android.server.wm.WindowStateProto.HAS_SURFACE;
132import static com.android.server.wm.WindowStateProto.IDENTIFIER;
133import static com.android.server.wm.WindowStateProto.IS_ON_SCREEN;
134import static com.android.server.wm.WindowStateProto.IS_READY_FOR_DISPLAY;
135import static com.android.server.wm.WindowStateProto.IS_VISIBLE;
136import static com.android.server.wm.WindowStateProto.OUTSETS;
137import static com.android.server.wm.WindowStateProto.OUTSET_FRAME;
138import static com.android.server.wm.WindowStateProto.OVERSCAN_FRAME;
139import static com.android.server.wm.WindowStateProto.OVERSCAN_INSETS;
140import static com.android.server.wm.WindowStateProto.PARENT_FRAME;
Adrian Roos2cadc5c2018-07-06 02:39:54 -0700141import static com.android.server.wm.WindowStateProto.PENDING_FORCED_SEAMLESS_ROTATION;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700142import static com.android.server.wm.WindowStateProto.REMOVED;
143import static com.android.server.wm.WindowStateProto.REMOVE_ON_EXIT;
144import static com.android.server.wm.WindowStateProto.REQUESTED_HEIGHT;
145import static com.android.server.wm.WindowStateProto.REQUESTED_WIDTH;
146import static com.android.server.wm.WindowStateProto.STABLE_INSETS;
147import static com.android.server.wm.WindowStateProto.STACK_ID;
148import static com.android.server.wm.WindowStateProto.SURFACE_INSETS;
149import static com.android.server.wm.WindowStateProto.SURFACE_POSITION;
150import static com.android.server.wm.WindowStateProto.SYSTEM_UI_VISIBILITY;
151import static com.android.server.wm.WindowStateProto.VIEW_VISIBILITY;
152import static com.android.server.wm.WindowStateProto.VISIBLE_FRAME;
153import static com.android.server.wm.WindowStateProto.VISIBLE_INSETS;
154import static com.android.server.wm.WindowStateProto.WINDOW_CONTAINER;
Adrian Roos41f7e9d2018-06-07 15:29:34 +0200155import static com.android.server.wm.utils.CoordinateTransforms.transformRect;
156import static com.android.server.wm.utils.CoordinateTransforms.transformToRotation;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800157
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700158import android.annotation.CallSuper;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800159import android.app.AppOpsManager;
160import android.content.Context;
161import android.content.res.Configuration;
162import android.graphics.Matrix;
163import android.graphics.PixelFormat;
164import android.graphics.Point;
165import android.graphics.Rect;
166import android.graphics.Region;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700167import android.os.Binder;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700168import android.os.Debug;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800169import android.os.IBinder;
170import android.os.PowerManager;
171import android.os.RemoteCallbackList;
172import android.os.RemoteException;
173import android.os.SystemClock;
174import android.os.Trace;
175import android.os.UserHandle;
176import android.os.WorkSource;
chaviw40234662018-02-07 09:37:16 -0800177import android.provider.Settings;
Phil Weaverbb2f28a2017-12-22 09:44:28 -0800178import android.text.TextUtils;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800179import android.util.DisplayMetrics;
Jorim Jaggie7d2b852017-08-28 17:55:15 +0200180import android.util.MergedConfiguration;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800181import android.util.Slog;
182import android.util.TimeUtils;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700183import android.util.proto.ProtoOutputStream;
Brad Stenningaf596412018-04-02 12:03:19 -0700184import android.view.Display;
Adrian Roos5c6b6222017-11-07 17:36:10 +0100185import android.view.DisplayCutout;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800186import android.view.DisplayInfo;
187import android.view.Gravity;
188import android.view.IApplicationToken;
189import android.view.IWindow;
190import android.view.IWindowFocusObserver;
191import android.view.IWindowId;
192import android.view.InputChannel;
193import android.view.InputEvent;
194import android.view.InputEventReceiver;
Robert Carrb1579c82017-09-05 14:54:47 -0700195import android.view.SurfaceControl;
196import android.view.SurfaceSession;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800197import android.view.View;
198import android.view.ViewTreeObserver;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700199import android.view.WindowInfo;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800200import android.view.WindowManager;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100201import android.view.animation.Animation;
202import android.view.animation.AnimationUtils;
203import android.view.animation.Interpolator;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800204
Jorim Jaggi4876b4a2018-01-11 15:43:49 +0100205import com.android.internal.annotations.VisibleForTesting;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800206import com.android.internal.util.ToBooleanFunction;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800207import com.android.server.input.InputWindowHandle;
Adrian Roose99bc052017-11-20 17:55:31 +0100208import com.android.server.policy.WindowManagerPolicy;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100209import com.android.server.wm.LocalAnimationAdapter.AnimationSpec;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100210import com.android.server.wm.utils.WmDisplayCutout;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800211
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800212import java.io.PrintWriter;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200213import java.lang.ref.WeakReference;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800214import java.util.ArrayList;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700215import java.util.Comparator;
Wale Ogunwaled1880962016-11-08 10:31:59 -0800216import java.util.function.Predicate;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800217
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700218/** A window in the window manager. */
219class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800220 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800221
Skuhne81c524a2015-08-12 13:34:14 -0700222 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700223 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
224 // use hard-coded min sizes for now.
225 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
226 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700227
228 // The thickness of a window resize handle outside the window bounds on the free form workspace
229 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700230 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700231
Craig Mautnere7ae2502012-03-26 17:11:19 -0700232 final WindowManagerPolicy mPolicy;
233 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800234 final Session mSession;
235 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800236 final int mAppOp;
237 // UserId and appId of the owner. Don't display windows of non-current user.
238 final int mOwnerUid;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800239 /** The owner has {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} */
240 final boolean mOwnerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200241 final WindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800242 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700243 // The same object as mToken if this is an app window and null for non-app windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800244 AppWindowToken mAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700245
246 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
247 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800248 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
249 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700250 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800251 final int mBaseLayer;
252 final int mSubLayer;
253 final boolean mLayoutAttached;
254 final boolean mIsImWindow;
255 final boolean mIsWallpaper;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700256 private final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700257 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700258 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800259 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700260 int mSystemUiVisibility;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700261 /**
262 * The visibility of the window based on policy like {@link WindowManagerPolicy}.
263 * Normally set by calling {@link #showLw} and {@link #hideLw}.
264 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800265 boolean mPolicyVisibility = true;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700266 /**
267 * What {@link #mPolicyVisibility} should be set to after a transition animation.
268 * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and
269 * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit
270 * animation is done.
271 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800272 boolean mPolicyVisibilityAfterAnim = true;
Suprabh Shukla69c71422018-04-02 18:39:01 -0700273 // overlay window is hidden because the owning app is suspended
274 private boolean mHiddenWhileSuspended;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700275 private boolean mAppOpVisibility = true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700276 boolean mPermanentlyHidden; // the window should never be shown again
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700277 // This is a non-system overlay window that is currently force hidden.
278 private boolean mForceHideNonSystemOverlayWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800279 boolean mAppFreezing;
chaviwebcbc342018-02-07 13:19:00 -0800280 boolean mHidden = true; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800281 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700282 private boolean mDragResizing;
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200283 private boolean mDragResizingChangeReported = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700284 private int mResizeMode;
Adrian Roos28c25e22018-05-31 18:07:28 +0200285 /**
286 * Special mode that is intended only for the rounded corner overlay: during rotation
287 * transition, we un-rotate the window token such that the window appears as it did before the
288 * rotation.
289 */
290 final boolean mForceSeamlesslyRotate;
291 ForcedSeamlessRotator mPendingForcedSeamlessRotate;
Adrian Roos2cadc5c2018-07-06 02:39:54 -0700292 long mFinishForcedSeamlessRotateFrameNumber;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700293
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700294 private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800295
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700296 /**
297 * The window size that was requested by the application. These are in
298 * the application's coordinate space (without compatibility scale applied).
299 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800300 int mRequestedWidth;
301 int mRequestedHeight;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700302 private int mLastRequestedWidth;
303 private int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700304
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800305 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800306 boolean mHaveFrame;
307 boolean mObscured;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800308
309 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700310
Andrii Kulian9d91ca62016-09-29 22:28:09 -0700311 /**
312 * Used to store last reported to client configuration and check if we have newer available.
313 * We'll send configuration to client only if it is different from the last applied one and
314 * client won't perform unnecessary updates.
315 */
Bryce Lee2b17afd2017-09-21 10:38:20 -0700316 private final MergedConfiguration mLastReportedConfiguration = new MergedConfiguration();
Craig Mautnera2c77052012-03-26 12:14:43 -0700317
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700318 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700319 * Insets that determine the actually visible area. These are in the application's
320 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800321 */
322 final Rect mVisibleInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700323 private final Rect mLastVisibleInsets = new Rect();
324 private boolean mVisibleInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800325
326 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700327 * Insets that are covered by system windows (such as the status bar) and
328 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700329 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800330 */
331 final Rect mContentInsets = new Rect();
332 final Rect mLastContentInsets = new Rect();
Robert Carr18f622f2017-05-08 11:20:43 -0700333
334 /**
335 * The last content insets returned to the client in relayout. We use
336 * these in the bounds animation to ensure we only observe inset changes
337 * at the same time that a client resizes it's surface so that we may use
338 * the geometryAppliesWithResize synchronization mechanism to keep
339 * the contents in place.
340 */
341 final Rect mLastRelayoutContentInsets = new Rect();
342
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700343 private boolean mContentInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800344
345 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800346 * Insets that determine the area covered by the display overscan region. These are in the
347 * application's coordinate space (without compatibility scale applied).
348 */
349 final Rect mOverscanInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700350 private final Rect mLastOverscanInsets = new Rect();
351 private boolean mOverscanInsetsChanged;
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800352
353 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700354 * Insets that determine the area covered by the stable system windows. These are in the
355 * application's coordinate space (without compatibility scale applied).
356 */
357 final Rect mStableInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700358 private final Rect mLastStableInsets = new Rect();
359 private boolean mStableInsetsChanged;
Adrian Roosfa104232014-06-20 16:10:14 -0700360
361 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700362 * Outsets determine the area outside of the surface where we want to pretend that it's possible
363 * to draw anyway.
364 */
365 final Rect mOutsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700366 private final Rect mLastOutsets = new Rect();
367 private boolean mOutsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700368
Adrian Roos5c6b6222017-11-07 17:36:10 +0100369 /** Part of the display that has been cut away. See {@link DisplayCutout}. */
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100370 WmDisplayCutout mDisplayCutout = WmDisplayCutout.NO_CUTOUT;
371 private WmDisplayCutout mLastDisplayCutout = WmDisplayCutout.NO_CUTOUT;
Adrian Roos5c6b6222017-11-07 17:36:10 +0100372 private boolean mDisplayCutoutChanged;
373
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700374 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800375 * Set to true if we are waiting for this window to receive its
376 * given internal insets before laying out other windows based on it.
377 */
378 boolean mGivenInsetsPending;
379
380 /**
381 * These are the content insets that were given during layout for
382 * this window, to be applied to windows behind it.
383 */
384 final Rect mGivenContentInsets = new Rect();
385
386 /**
387 * These are the visible insets that were given during layout for
388 * this window, to be applied to windows behind it.
389 */
390 final Rect mGivenVisibleInsets = new Rect();
391
392 /**
393 * This is the given touchable area relative to the window frame, or null if none.
394 */
395 final Region mGivenTouchableRegion = new Region();
396
397 /**
398 * Flag indicating whether the touchable region should be adjusted by
399 * the visible insets; if false the area outside the visible insets is
400 * NOT touchable, so we must use those to adjust the frame during hit
401 * tests.
402 */
403 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
404
405 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400406 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700407 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800408 float mHScale=1, mVScale=1;
409 float mLastHScale=1, mLastVScale=1;
410 final Matrix mTmpMatrix = new Matrix();
411
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700412 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800413 final Rect mFrame = new Rect();
414 final Rect mLastFrame = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700415 private boolean mFrameSizeChanged = false;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700416 // Frame that is scaled to the application's coordinate space when in
417 // screen size compatibility mode.
418 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800419
420 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700421
Adrian Roos604ef952018-05-15 20:13:13 +0200422 final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700423
Adrian Roos5ed644f2018-03-19 17:01:05 +0100424 /** Whether the parent frame would have been different if there was no display cutout. */
425 private boolean mParentFrameWasClippedByDisplayCutout;
426
Wale Ogunwale94596652015-02-06 19:27:34 -0800427 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
428 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700429 final Rect mDisplayFrame = new Rect();
430
431 // The region of the display frame that the display type supports displaying content on. This
432 // is mostly a special case for TV where some displays don’t have the entire display usable.
433 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
434 // window display contents to extend into the overscan region.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700435 private final Rect mOverscanFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700436
437 // The display frame minus the stable insets. This value is always constant regardless of if
438 // the status bar or navigation bar is visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700439 private final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800440
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700441 // The area not occupied by the status and navigation bars. So, if both status and navigation
442 // bars are visible, the decor frame is equal to the stable frame.
443 final Rect mDecorFrame = new Rect();
444
445 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
446 // minus the area occupied by the IME if the IME is present.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700447 private final Rect mContentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700448
449 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
450 // displays hint text.
451 final Rect mVisibleFrame = new Rect();
452
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700453 // Frame that includes dead area outside of the surface but where we want to pretend that it's
454 // possible to draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700455 private final Rect mOutsetFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700456
Jorim Jaggidc249c42015-12-15 14:57:31 -0800457 /**
458 * Usually empty. Set to the task's tempInsetFrame. See
459 *{@link android.app.IActivityManager#resizeDockedStack}.
460 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700461 private final Rect mInsetFrame = new Rect();
Jorim Jaggidc249c42015-12-15 14:57:31 -0800462
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800463 boolean mContentChanged;
464
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800465 // If a window showing a wallpaper: the requested offset for the
466 // wallpaper; if a wallpaper window: the currently applied offset.
467 float mWallpaperX = -1;
468 float mWallpaperY = -1;
469
470 // If a window showing a wallpaper: what fraction of the offset
471 // range corresponds to a full virtual screen.
472 float mWallpaperXStep = -1;
473 float mWallpaperYStep = -1;
474
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700475 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
476 // to its window; if a wallpaper window: not used.
477 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
478 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
479
Craig Mautner2268e7e2012-12-13 15:40:00 -0800480 /**
481 * This is set after IWindowSession.relayout() has been called at
482 * least once for the window. It allows us to detect the situation
483 * where we don't yet have a surface, but should have one soon, so
484 * we can give the window focus before waiting for the relayout.
485 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800486 boolean mRelayoutCalled;
487
Robert Carrfed10072016-05-26 11:48:49 -0700488 boolean mInRelayout;
489
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800490 /**
491 * If the application has called relayout() with changes that can
492 * impact its window's size, we need to perform a layout pass on it
493 * even if it is not currently visible for layout. This is set
494 * when in that case until the layout is done.
495 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800496 boolean mLayoutNeeded;
497
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800498 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800499 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800500
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800501 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800502 boolean mDestroying;
503
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800504 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800505 boolean mRemoveOnExit;
506
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800507 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800508 * Whether the app died while it was visible, if true we might need
509 * to continue to show it until it's restarted.
510 */
511 boolean mAppDied;
512
513 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800514 * Set when the orientation is changing and this window has not yet
515 * been updated for the new orientation.
516 */
Bryce Lee8c3cf382017-07-06 19:47:10 -0700517 private boolean mOrientationChanging;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800518
Dianne Hackborna57c6952013-03-29 14:46:40 -0700519 /**
Robert Carr9c1c3a02017-08-08 12:59:01 -0700520 * Sometimes in addition to the mOrientationChanging
521 * flag we report that the orientation is changing
522 * due to a mismatch in current and reported configuration.
523 *
524 * In the case of timeout we still need to make sure we
525 * leave the orientation changing state though, so we
526 * use this as a special time out escape hatch.
527 */
528 private boolean mOrientationChangeTimedOut;
529
530 /**
Robert Carr237028a2016-07-26 10:39:45 -0700531 * The orientation during the last visible call to relayout. If our
532 * current orientation is different, the window can't be ready
533 * to be shown.
534 */
535 int mLastVisibleLayoutRotation = -1;
536
537 /**
Andrii Kulianb2e37802017-01-11 00:36:44 -0800538 * Set when we need to report the orientation change to client to trigger a relayout.
539 */
540 boolean mReportOrientationChanged;
541
542 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700543 * How long we last kept the screen frozen.
544 */
545 int mLastFreezeDuration;
546
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800547 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800548 boolean mRemoved;
549
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800550 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800551 * It is save to remove the window and destroy the surface because the client requested removal
552 * or some other higher level component said so (e.g. activity manager).
553 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800554 */
Svetoslav Ganov200adfb2016-10-18 13:29:27 -0700555 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800556
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800557 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700558 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800559 InputChannel mInputChannel;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700560 private InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800561
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800562 // Used to improve performance of toString()
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700563 private String mStringNameCache;
564 private CharSequence mLastTitle;
565 private boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800566
Craig Mautnera2c77052012-03-26 12:14:43 -0700567 final WindowStateAnimator mWinAnimator;
568
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700569 boolean mHasSurface = false;
570
Craig Mautner88400d32012-09-30 12:35:45 -0700571 /** When true this window can be displayed on screens owther than mOwnerUid's */
572 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700573
Chong Zhang92147042016-05-09 12:47:11 -0700574 // Whether the window was visible when we set the app to invisible last time. WM uses
575 // this as a hint to restore the surface (if available) for early animation next time
576 // the app is brought visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700577 private boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800578
Robert Carra1eb4392015-12-10 12:43:51 -0800579 // This window will be replaced due to relaunch. This allows window manager
580 // to differentiate between simple removal of a window and replacement. In the latter case it
581 // will preserve the old window until the new one is drawn.
582 boolean mWillReplaceWindow = false;
583 // If true, the replaced window was already requested to be removed.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700584 private boolean mReplacingRemoveRequested = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800585 // Whether the replacement of the window should trigger app transition animation.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700586 private boolean mAnimateReplacingWindow = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800587 // If not null, the window that will be used to replace the old one. This is being set when
588 // the window is added and unset when this window reports its first draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700589 private WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700590 // For the new window in the replacement transition, if we have
591 // requested to replace without animation, then we should
592 // make sure we also don't apply an enter animation for
593 // the new window.
594 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800595 // Whether this window is being moved via the resize API
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700596 private boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800597
Jeff Brownc2932a12014-11-20 18:04:05 -0800598 /**
599 * Wake lock for drawing.
600 * Even though it's slightly more expensive to do so, we will use a separate wake lock
601 * for each app that is requesting to draw while dozing so that we can accurately track
602 * who is preventing the system from suspending.
603 * This lock is only acquired on first use.
604 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700605 private PowerManager.WakeLock mDrawLock;
Jeff Brownc2932a12014-11-20 18:04:05 -0800606
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700607 final private Rect mTmpRect = new Rect();
608
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800609 /**
610 * Whether the window was resized by us while it was gone for layout.
611 */
612 boolean mResizedWhileGone = false;
613
Robert Carr6da3cc02016-06-16 15:17:07 -0700614 /**
615 * During seamless rotation we have two phases, first the old window contents
616 * are rotated to look as if they didn't move in the new coordinate system. Then we
617 * have to freeze updates to this layer (to preserve the transformation) until
618 * the resize actually occurs. This is true from when the transformation is set
619 * and false until the transaction to resize is sent.
620 */
621 boolean mSeamlesslyRotated = false;
622
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700623 /**
Robert Carrc91d1c32017-02-15 19:37:46 -0800624 * Surface insets from the previous call to relayout(), used to track
625 * if we are changing the Surface insets.
626 */
627 final Rect mLastSurfaceInsets = new Rect();
628
629 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700630 * A flag set by the {@link WindowState} parent to indicate that the parent has examined this
631 * {@link WindowState} in its overall drawing context. This book-keeping allows the parent to
632 * make sure all children have been considered.
633 */
634 private boolean mDrawnStateEvaluated;
635
Jorim Jaggia5e10572017-11-15 14:36:26 +0100636 private final Point mSurfacePosition = new Point();
637
Bryce Leed390deb2017-06-22 13:14:28 -0700638 /**
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800639 * A region inside of this window to be excluded from touch-related focus switches.
640 */
641 private TapExcludeRegionHolder mTapExcludeRegionHolder;
642
643 /**
chaviw40234662018-02-07 09:37:16 -0800644 * Used for testing because the real PowerManager is final.
645 */
646 private PowerManagerWrapper mPowerManagerWrapper;
647
648 /**
chaviwbe43ac82018-04-04 15:14:49 -0700649 * A frame number in which changes requested in this layout will be rendered.
650 */
651 private long mFrameNumber = -1;
652
653 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700654 * 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 -0700655 * of z-order and 1 otherwise.
656 */
Griff Hazen51d00d82016-11-22 15:39:24 -0800657 private static final Comparator<WindowState> sWindowSubLayerComparator =
658 new Comparator<WindowState>() {
659 @Override
660 public int compare(WindowState w1, WindowState w2) {
661 final int layer1 = w1.mSubLayer;
662 final int layer2 = w2.mSubLayer;
663 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
664 // We insert the child window into the list ordered by
665 // the sub-layer. For same sub-layers, the negative one
666 // should go below others; the positive one should go
667 // above others.
668 return -1;
669 }
670 return 1;
671 };
672 };
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700673
Robert Carrf59b8dd2017-10-02 18:58:36 -0700674 /**
675 * Indicates whether we have requested a Dim (in the sense of {@link Dimmer}) from our host
676 * container.
677 */
678 private boolean mIsDimming = false;
679
680 private static final float DEFAULT_DIM_AMOUNT_DEAD_WINDOW = 0.5f;
681
Adrian Roos28c25e22018-05-31 18:07:28 +0200682 void forceSeamlesslyRotateIfAllowed(int oldRotation, int rotation) {
683 if (mForceSeamlesslyRotate) {
684 mPendingForcedSeamlessRotate = new ForcedSeamlessRotator(
685 oldRotation, rotation, getDisplayInfo());
686 mPendingForcedSeamlessRotate.unrotate(this.mToken);
687 }
688 }
689
chaviw40234662018-02-07 09:37:16 -0800690 interface PowerManagerWrapper {
691 void wakeUp(long time, String reason);
692
693 boolean isInteractive();
694
695 }
696
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800697 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
chaviw40234662018-02-07 09:37:16 -0800698 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
699 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow) {
700 this(service, s, c, token, parentWindow, appOp, seq, a, viewVisibility, ownerId,
701 ownerCanAddInternalSystemWindow, new PowerManagerWrapper() {
702 @Override
703 public void wakeUp(long time, String reason) {
704 service.mPowerManager.wakeUp(time, reason);
705 }
706
707 @Override
708 public boolean isInteractive() {
709 return service.mPowerManager.isInteractive();
710 }
711 });
712 }
713
714 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
715 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
716 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow,
717 PowerManagerWrapper powerManagerWrapper) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100718 super(service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800719 mSession = s;
720 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800721 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800722 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700723 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700724 mOwnerUid = ownerId;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800725 mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200726 mWindowId = new WindowId(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800727 mAttrs.copyFrom(a);
Robert Carrb08ed042018-03-12 15:49:08 -0700728 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800729 mViewVisibility = viewVisibility;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700730 mPolicy = mService.mPolicy;
731 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800732 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700733 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700734 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
chaviw40234662018-02-07 09:37:16 -0800735 mPowerManagerWrapper = powerManagerWrapper;
Adrian Roos28c25e22018-05-31 18:07:28 +0200736 mForceSeamlesslyRotate = token.mRoundedCornerOverlay;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700737 if (localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700738 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700739 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800740 try {
741 c.asBinder().linkToDeath(deathRecipient, 0);
742 } catch (RemoteException e) {
743 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700744 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800745 mLayoutAttached = false;
746 mIsImWindow = false;
747 mIsWallpaper = false;
748 mIsFloatingLayer = false;
749 mBaseLayer = 0;
750 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700751 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700752 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800753 return;
754 }
755 mDeathRecipient = deathRecipient;
756
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700757 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800758 // The multiplier here is to reserve space for multiple
759 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800760 mBaseLayer = mPolicy.getWindowLayerLw(parentWindow)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700761 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800762 mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700763 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900764
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700765 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow);
766 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900767
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800768 mLayoutAttached = mAttrs.type !=
769 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700770 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
771 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
772 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800773 } else {
774 // The multiplier here is to reserve space for multiple
775 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800776 mBaseLayer = mPolicy.getWindowLayerLw(this)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700777 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800778 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700779 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800780 mLayoutAttached = false;
781 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
782 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
783 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800784 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700785 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800786
Wale Ogunwale72919d22016-12-08 18:58:50 -0800787 if (mAppToken != null && mAppToken.mShowForAllUsers) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700788 // Windows for apps that can show for all users should also show when the device is
789 // locked.
790 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
Craig Mautner19ab8282014-05-07 10:35:34 -0700791 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800792
Craig Mautner322e4032012-07-13 13:35:20 -0700793 mWinAnimator = new WindowStateAnimator(this);
794 mWinAnimator.mAlpha = a.alpha;
795
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800796 mRequestedWidth = 0;
797 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700798 mLastRequestedWidth = 0;
799 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800800 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800801 mInputWindowHandle = new InputWindowHandle(
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800802 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this, c,
803 getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800804 }
805
806 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700807 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800808 mSession.windowAddedLocked(mAttrs.packageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800809 }
810
Bryce Leed390deb2017-06-22 13:14:28 -0700811 /**
812 * Returns whether this {@link WindowState} has been considered for drawing by its parent.
813 */
Bryce Lee6311c4b2017-07-06 14:09:29 -0700814 boolean getDrawnStateEvaluated() {
Bryce Leed390deb2017-06-22 13:14:28 -0700815 return mDrawnStateEvaluated;
816 }
817
818 /**
819 * Sets whether this {@link WindowState} has been considered for drawing by its parent. Should
820 * be cleared when detached from parent.
821 */
822 void setDrawnStateEvaluated(boolean evaluated) {
823 mDrawnStateEvaluated = evaluated;
824 }
825
826 @Override
827 void onParentSet() {
828 super.onParentSet();
829 setDrawnStateEvaluated(false /*evaluated*/);
Robert Carr24be9ab2018-04-30 17:54:53 -0700830
831 getDisplayContent().reapplyMagnificationSpec();
Bryce Leed390deb2017-06-22 13:14:28 -0700832 }
833
Craig Mautnera2c77052012-03-26 12:14:43 -0700834 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800835 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800836 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800837 }
838
839 @Override
840 public String getOwningPackage() {
841 return mAttrs.packageName;
842 }
843
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800844 @Override
845 public boolean canAddInternalSystemWindow() {
846 return mOwnerCanAddInternalSystemWindow;
847 }
848
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200849 @Override
850 public boolean canAcquireSleepToken() {
851 return mSession.mCanAcquireSleepToken;
852 }
853
Jorim Jaggif5834272016-04-04 20:25:41 -0700854 /**
855 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
856 * from {@param frame}. In other words, it applies the insets that would result if
857 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700858 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
859 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700860 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700861 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
862 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
863 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
864 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
865 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700866 frame.inset(left, top, right, bottom);
867 }
868
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800869 @Override
Robert Carr43521762016-10-28 13:15:04 -0700870 public void computeFrameLw(Rect parentFrame, Rect displayFrame, Rect overscanFrame,
871 Rect contentFrame, Rect visibleFrame, Rect decorFrame, Rect stableFrame,
Adrian Roos5ed644f2018-03-19 17:01:05 +0100872 Rect outsetFrame, WmDisplayCutout displayCutout,
873 boolean parentFrameWasClippedByDisplayCutout) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800874 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700875 // This window is being replaced and either already got information that it's being
876 // removed or we are still waiting for some information. Because of this we don't
877 // want to apply any more changes to it, so it remains in this state until new window
878 // appears.
879 return;
880 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800881 mHaveFrame = true;
Adrian Roos5ed644f2018-03-19 17:01:05 +0100882 mParentFrameWasClippedByDisplayCutout = parentFrameWasClippedByDisplayCutout;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800883
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700884 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700885 final boolean inFullscreenContainer = inFullscreenContainer();
Robert Carre6275582016-02-29 15:45:45 -0800886 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700887 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800888
Chong Zhangae35fef2016-03-16 15:56:55 -0700889 // If the task has temp inset bounds set, we have to make sure all its windows uses
890 // the temp inset frame. Otherwise different display frames get applied to the main
891 // window and the child window, making them misaligned.
Adrian Roose76b2b52018-03-21 16:22:16 +0100892 // Otherwise we need to clear the inset frame, to avoid using a stale frame after leaving
893 // multi window mode.
894 if (task != null && isInMultiWindowMode()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700895 task.getTempInsetBounds(mInsetFrame);
Adrian Roose76b2b52018-03-21 16:22:16 +0100896 } else {
897 mInsetFrame.setEmpty();
Chong Zhangae35fef2016-03-16 15:56:55 -0700898 }
899
Jorim Jaggif5834272016-04-04 20:25:41 -0700900 // Denotes the actual frame used to calculate the insets and to perform the layout. When
901 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
902 // insets temporarily. By the notion of a task having a different layout frame, we can
903 // achieve that while still moving the task around.
904 final Rect layoutContainingFrame;
905 final Rect layoutDisplayFrame;
906
907 // The offset from the layout containing frame to the actual containing frame.
908 final int layoutXDiff;
909 final int layoutYDiff;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700910 if (inFullscreenContainer || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800911 // We use the parent frame as the containing frame for fullscreen and child windows
Robert Carr43521762016-10-28 13:15:04 -0700912 mContainingFrame.set(parentFrame);
913 mDisplayFrame.set(displayFrame);
914 layoutDisplayFrame = displayFrame;
915 layoutContainingFrame = parentFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700916 layoutXDiff = 0;
917 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800918 } else {
Bryce Leef3c6a472017-11-14 14:53:06 -0800919 getBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100920 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
921
922 // If the bounds are frozen, we still want to translate the window freely and only
923 // freeze the size.
924 Rect frozen = mAppToken.mFrozenBounds.peek();
925 mContainingFrame.right = mContainingFrame.left + frozen.width();
926 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
927 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800928 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700929 // IME is up and obscuring this window. Adjust the window position so it is visible.
Robert Carr825581a2018-03-30 14:00:53 -0700930 if (imeWin != null && imeWin.isVisibleNow() && isInputMethodTarget()) {
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700931 if (inFreeformWindowingMode()
Winson Chungd73e94b2017-05-31 16:25:30 -0700932 && mContainingFrame.bottom > contentFrame.bottom) {
933 // In freeform we want to move the top up directly.
934 // TODO: Investigate why this is contentFrame not parentFrame.
935 mContainingFrame.top -= mContainingFrame.bottom - contentFrame.bottom;
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700936 } else if (!inPinnedWindowingMode()
Winson Chungd73e94b2017-05-31 16:25:30 -0700937 && mContainingFrame.bottom > parentFrame.bottom) {
938 // But in docked we want to behave like fullscreen and behave as if the task
939 // were given smaller bounds for the purposes of layout. Skip adjustments for
940 // the pinned stack, they are handled separately in the PinnedStackController.
941 mContainingFrame.bottom = parentFrame.bottom;
942 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700943 }
Skuhne81c524a2015-08-12 13:34:14 -0700944
Robert Carre6275582016-02-29 15:45:45 -0800945 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700946 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
947 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800948 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700949 if (mContainingFrame.isEmpty()) {
Robert Carr43521762016-10-28 13:15:04 -0700950 mContainingFrame.set(contentFrame);
Skuhne81c524a2015-08-12 13:34:14 -0700951 }
Doris Liu06d582d2015-06-01 13:18:43 -0700952 }
Adrian Roos604ef952018-05-15 20:13:13 +0200953
954 final TaskStack stack = getStack();
955 if (inPinnedWindowingMode() && stack != null
956 && stack.lastAnimatingBoundsWasToFullscreen()) {
957 // PIP edge case: When going from pinned to fullscreen, we apply a
958 // tempInsetFrame for the full task - but we're still at the start of the animation.
959 // To prevent a jump if there's a letterbox, restrict to the parent frame.
960 mInsetFrame.intersectUnchecked(parentFrame);
961 mContainingFrame.intersectUnchecked(parentFrame);
962 }
963
Wale Ogunwale94596652015-02-06 19:27:34 -0800964 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700965 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
966 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
967 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700968 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
Robert Carr43521762016-10-28 13:15:04 -0700969 subtractInsets(mDisplayFrame, layoutContainingFrame, displayFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700970 if (!layoutInParentFrame()) {
Robert Carr43521762016-10-28 13:15:04 -0700971 subtractInsets(mContainingFrame, layoutContainingFrame, parentFrame, mTmpRect);
972 subtractInsets(mInsetFrame, layoutContainingFrame, parentFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700973 }
Robert Carr43521762016-10-28 13:15:04 -0700974 layoutDisplayFrame = displayFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700975 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700976 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800977
Craig Mautner967212c2013-04-13 21:10:58 -0700978 final int pw = mContainingFrame.width();
979 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800980
Robert Carr43521762016-10-28 13:15:04 -0700981 if (!mParentFrame.equals(parentFrame)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800982 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Robert Carr43521762016-10-28 13:15:04 -0700983 // + " to " + parentFrame);
984 mParentFrame.set(parentFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800985 mContentChanged = true;
986 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700987 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
988 mLastRequestedWidth = mRequestedWidth;
989 mLastRequestedHeight = mRequestedHeight;
990 mContentChanged = true;
991 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800992
Robert Carr43521762016-10-28 13:15:04 -0700993 mOverscanFrame.set(overscanFrame);
994 mContentFrame.set(contentFrame);
995 mVisibleFrame.set(visibleFrame);
996 mDecorFrame.set(decorFrame);
997 mStableFrame.set(stableFrame);
998 final boolean hasOutsets = outsetFrame != null;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700999 if (hasOutsets) {
Robert Carr43521762016-10-28 13:15:04 -07001000 mOutsetFrame.set(outsetFrame);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001001 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001002
Craig Mautnereda67292013-04-28 13:50:14 -07001003 final int fw = mFrame.width();
1004 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001005
Jorim Jaggif5834272016-04-04 20:25:41 -07001006 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
1007
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -07001008 // Calculate the outsets before the content frame gets shrinked to the window frame.
1009 if (hasOutsets) {
1010 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
1011 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
1012 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
1013 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
1014 } else {
1015 mOutsets.set(0, 0, 0, 0);
1016 }
1017
Craig Mautnera248eee2013-05-07 11:41:27 -07001018 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001019 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -08001020 if (windowsAreFloating && !mFrame.isEmpty()) {
Robert Carre65a1c42017-02-28 16:52:59 -08001021 // For pinned workspace the frame isn't limited in any particular
1022 // way since SystemUI controls the bounds. For freeform however
1023 // we want to keep things inside the content frame.
Wale Ogunwale44f036f2017-09-29 05:09:09 -07001024 final Rect limitFrame = task.inPinnedWindowingMode() ? mFrame : mContentFrame;
Skuhne81c524a2015-08-12 13:34:14 -07001025 // Keep the frame out of the blocked system area, limit it in size to the content area
1026 // and make sure that there is always a minimum visible so that the user can drag it
1027 // into a usable area..
Robert Carre65a1c42017-02-28 16:52:59 -08001028 final int height = Math.min(mFrame.height(), limitFrame.height());
1029 final int width = Math.min(limitFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -07001030 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +09001031 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
1032 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
1033 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
1034 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Robert Carre65a1c42017-02-28 16:52:59 -08001035 final int top = Math.max(limitFrame.top,
1036 Math.min(mFrame.top, limitFrame.bottom - minVisibleHeight));
1037 final int left = Math.max(limitFrame.left + minVisibleWidth - width,
1038 Math.min(mFrame.left, limitFrame.right - minVisibleWidth));
Skuhne81c524a2015-08-12 13:34:14 -07001039 mFrame.set(left, top, left + width, top + height);
1040 mContentFrame.set(mFrame);
1041 mVisibleFrame.set(mContentFrame);
1042 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -07001043 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001044 dc.getDockedDividerController().positionDockedStackedDivider(mFrame);
Jorim Jaggi192086e2016-03-11 17:17:03 +01001045 mContentFrame.set(mFrame);
1046 if (!mFrame.equals(mLastFrame)) {
1047 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -08001048 }
Skuhne81c524a2015-08-12 13:34:14 -07001049 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -07001050 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
1051 Math.max(mContentFrame.top, mFrame.top),
1052 Math.min(mContentFrame.right, mFrame.right),
1053 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001054
Jorim Jaggi656f6502016-04-11 21:08:17 -07001055 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
1056 Math.max(mVisibleFrame.top, mFrame.top),
1057 Math.min(mVisibleFrame.right, mFrame.right),
1058 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001059
Jorim Jaggi656f6502016-04-11 21:08:17 -07001060 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
1061 Math.max(mStableFrame.top, mFrame.top),
1062 Math.min(mStableFrame.right, mFrame.right),
1063 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -07001064 }
Adrian Roosfa104232014-06-20 16:10:14 -07001065
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07001066 if (inFullscreenContainer && !windowsAreFloating) {
Jorim Jaggi899327f2016-02-25 20:44:18 -05001067 // Windows that are not fullscreen can be positioned outside of the display frame,
1068 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -07001069 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
1070 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
1071 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
1072 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -08001073 }
Craig Mautnereda67292013-04-28 13:50:14 -07001074
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001075 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001076 // For the docked divider, we calculate the stable insets like a full-screen window
1077 // so it can use it to calculate the snap positions.
Adrian Roos7377f582018-03-20 16:56:22 +01001078 final WmDisplayCutout c = displayCutout.calculateRelativeTo(mDisplayFrame);
1079 mTmpRect.set(mDisplayFrame);
1080 mTmpRect.inset(c.getDisplayCutout().getSafeInsets());
1081 mTmpRect.intersectUnchecked(mStableFrame);
1082
1083 mStableInsets.set(Math.max(mTmpRect.left - mDisplayFrame.left, 0),
1084 Math.max(mTmpRect.top - mDisplayFrame.top, 0),
1085 Math.max(mDisplayFrame.right - mTmpRect.right, 0),
1086 Math.max(mDisplayFrame.bottom - mTmpRect.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -08001087
1088 // The divider doesn't care about insets in any case, so set it to empty so we don't
1089 // trigger a relayout when moving it.
1090 mContentInsets.setEmpty();
1091 mVisibleInsets.setEmpty();
Adrian Roos7377f582018-03-20 16:56:22 +01001092 displayCutout = WmDisplayCutout.NO_CUTOUT;
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001093 } else {
Bryce Leef3c6a472017-11-14 14:53:06 -08001094 getDisplayContent().getBounds(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -07001095 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
1096 // non-fullscreen mode.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07001097 boolean overrideRightInset = !windowsAreFloating && !inFullscreenContainer
1098 && mFrame.right > mTmpRect.right;
1099 boolean overrideBottomInset = !windowsAreFloating && !inFullscreenContainer
1100 && mFrame.bottom > mTmpRect.bottom;
Jorim Jaggi656f6502016-04-11 21:08:17 -07001101 mContentInsets.set(mContentFrame.left - mFrame.left,
1102 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -07001103 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -07001104 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -07001105 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -07001106 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -08001107
Jorim Jaggi656f6502016-04-11 21:08:17 -07001108 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
1109 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -07001110 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -07001111 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -07001112 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -07001113 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -08001114
Jorim Jaggi656f6502016-04-11 21:08:17 -07001115 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
1116 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -07001117 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -07001118 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -07001119 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -07001120 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001121 }
Adrian Roosfa104232014-06-20 16:10:14 -07001122
Jorim Jaggibae2b152018-04-18 17:27:27 +02001123 mDisplayCutout = displayCutout.calculateRelativeTo(mFrame);
1124
Jorim Jaggi656f6502016-04-11 21:08:17 -07001125 // Offset the actual frame by the amount layout frame is off.
1126 mFrame.offset(-layoutXDiff, -layoutYDiff);
1127 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -07001128 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
1129 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
1130 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
1131
Craig Mautnereda67292013-04-28 13:50:14 -07001132 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001133 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001134 // If there is a size compatibility scale being applied to the
1135 // window, we need to apply this to its insets so that they are
1136 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -07001137 mOverscanInsets.scale(mInvGlobalScale);
1138 mContentInsets.scale(mInvGlobalScale);
1139 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -07001140 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001141 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001142
1143 // Also the scaled frame that we report to the app needs to be
1144 // adjusted to be in its coordinate space.
1145 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001146 }
1147
Craig Mautnereda67292013-04-28 13:50:14 -07001148 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001149 final DisplayContent displayContent = getDisplayContent();
1150 if (displayContent != null) {
1151 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwale0303c572016-10-20 10:16:29 -07001152 getDisplayContent().mWallpaperController.updateWallpaperOffset(
Wale Ogunwalee8069dc2015-08-18 09:52:01 -07001153 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001154 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001155 }
1156
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001157 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001158 "Resolving (mRequestedWidth="
1159 + mRequestedWidth + ", mRequestedheight="
1160 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
1161 + "): frame=" + mFrame.toShortString()
1162 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07001163 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -07001164 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001165 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001166 }
1167
Bryce Leef3c6a472017-11-14 14:53:06 -08001168 // TODO: Look into whether this override is still necessary.
1169 @Override
1170 public Rect getBounds() {
1171 if (isInMultiWindowMode()) {
1172 return getTask().getBounds();
1173 } else if (mAppToken != null){
1174 return mAppToken.getBounds();
1175 } else {
1176 return super.getBounds();
1177 }
1178 }
1179
Craig Mautnera2c77052012-03-26 12:14:43 -07001180 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001181 public Rect getFrameLw() {
1182 return mFrame;
1183 }
1184
Craig Mautnera2c77052012-03-26 12:14:43 -07001185 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001186 public Rect getDisplayFrameLw() {
1187 return mDisplayFrame;
1188 }
1189
Craig Mautnera2c77052012-03-26 12:14:43 -07001190 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001191 public Rect getOverscanFrameLw() {
1192 return mOverscanFrame;
1193 }
1194
1195 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001196 public Rect getContentFrameLw() {
1197 return mContentFrame;
1198 }
1199
Craig Mautnera2c77052012-03-26 12:14:43 -07001200 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001201 public Rect getVisibleFrameLw() {
1202 return mVisibleFrame;
1203 }
1204
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001205 Rect getStableFrameLw() {
1206 return mStableFrame;
1207 }
1208
Craig Mautnera2c77052012-03-26 12:14:43 -07001209 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001210 public boolean getGivenInsetsPendingLw() {
1211 return mGivenInsetsPending;
1212 }
1213
Craig Mautnera2c77052012-03-26 12:14:43 -07001214 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001215 public Rect getGivenContentInsetsLw() {
1216 return mGivenContentInsets;
1217 }
1218
Craig Mautnera2c77052012-03-26 12:14:43 -07001219 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001220 public Rect getGivenVisibleInsetsLw() {
1221 return mGivenVisibleInsets;
1222 }
1223
Craig Mautnera2c77052012-03-26 12:14:43 -07001224 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001225 public WindowManager.LayoutParams getAttrs() {
1226 return mAttrs;
1227 }
1228
Craig Mautner812d2ca2012-09-27 15:35:34 -07001229 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001230 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001231 return getDisplayContent().getNeedsMenu(this, bottom);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001232 }
1233
Craig Mautner19d59bc2012-09-04 11:15:56 -07001234 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001235 public int getSystemUiVisibility() {
1236 return mSystemUiVisibility;
1237 }
1238
Craig Mautner19d59bc2012-09-04 11:15:56 -07001239 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001240 public int getSurfaceLayer() {
1241 return mLayer;
1242 }
1243
Craig Mautner812d2ca2012-09-27 15:35:34 -07001244 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001245 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001246 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001247 }
1248
1249 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001250 public IApplicationToken getAppToken() {
1251 return mAppToken != null ? mAppToken.appToken : null;
1252 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001253
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001254 @Override
1255 public boolean isVoiceInteraction() {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001256 return mAppToken != null && mAppToken.mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001257 }
1258
Robert Carr31aa98b2016-07-20 15:29:03 -07001259 boolean setReportResizeHints() {
Craig Mautner4c5eb222013-11-18 12:59:05 -08001260 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1261 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1262 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001263 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001264 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
Robert Carr31aa98b2016-07-20 15:29:03 -07001265 mFrameSizeChanged |= (mLastFrame.width() != mFrame.width()) ||
1266 (mLastFrame.height() != mFrame.height());
Adrian Roos5c6b6222017-11-07 17:36:10 +01001267 mDisplayCutoutChanged |= !mLastDisplayCutout.equals(mDisplayCutout);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001268 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
Adrian Roos5c6b6222017-11-07 17:36:10 +01001269 || mOutsetsChanged || mFrameSizeChanged || mDisplayCutoutChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001270 }
1271
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001272 /**
1273 * Adds the window to the resizing list if any of the parameters we use to track the window
1274 * dimensions or insets have changed.
1275 */
1276 void updateResizingWindowIfNeeded() {
1277 final WindowStateAnimator winAnimator = mWinAnimator;
Adrian Roos5251b1d2018-03-23 18:57:43 +01001278 if (!mHasSurface || getDisplayContent().mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001279 return;
1280 }
1281
1282 final Task task = getTask();
1283 // In the case of stack bound animations, the window frames will update (unlike other
1284 // animations which just modify various transformation properties). We don't want to
1285 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1286 // the frame may not correspond to the surface size or the onscreen area at various
1287 // phases in the animation, and the client will become sad and confused.
Winson Chung40a5f932017-04-13 16:39:36 -07001288 if (task != null && task.mStack.isAnimatingBounds()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001289 return;
1290 }
1291
1292 setReportResizeHints();
1293 boolean configChanged = isConfigChanged();
1294 if (DEBUG_CONFIGURATION && configChanged) {
1295 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1296 }
1297
1298 final boolean dragResizingChanged = isDragResizeChanged()
1299 && !isDragResizingChangeReported();
1300
1301 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
1302 + " dragResizingChanged=" + dragResizingChanged + " last=" + mLastFrame
1303 + " frame=" + mFrame);
1304
1305 // We update mLastFrame always rather than in the conditional with the last inset
1306 // variables, because mFrameSizeChanged only tracks the width and height changing.
1307 mLastFrame.set(mFrame);
1308
1309 if (mContentInsetsChanged
1310 || mVisibleInsetsChanged
Adrian Rooscb938492018-04-16 17:10:32 +02001311 || mStableInsetsChanged
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001312 || winAnimator.mSurfaceResized
1313 || mOutsetsChanged
1314 || mFrameSizeChanged
Adrian Roos5c6b6222017-11-07 17:36:10 +01001315 || mDisplayCutoutChanged
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001316 || configChanged
1317 || dragResizingChanged
Andrii Kulianb2e37802017-01-11 00:36:44 -08001318 || mReportOrientationChanged) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001319 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1320 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
1321 + " contentInsetsChanged=" + mContentInsetsChanged
1322 + " " + mContentInsets.toShortString()
1323 + " visibleInsetsChanged=" + mVisibleInsetsChanged
1324 + " " + mVisibleInsets.toShortString()
1325 + " stableInsetsChanged=" + mStableInsetsChanged
1326 + " " + mStableInsets.toShortString()
1327 + " outsetsChanged=" + mOutsetsChanged
1328 + " " + mOutsets.toShortString()
1329 + " surfaceResized=" + winAnimator.mSurfaceResized
1330 + " configChanged=" + configChanged
1331 + " dragResizingChanged=" + dragResizingChanged
Adrian Roos5c6b6222017-11-07 17:36:10 +01001332 + " reportOrientationChanged=" + mReportOrientationChanged
1333 + " displayCutoutChanged=" + mDisplayCutoutChanged);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001334 }
1335
1336 // If it's a dead window left on screen, and the configuration changed, there is nothing
1337 // we can do about it. Remove the window now.
1338 if (mAppToken != null && mAppDied) {
1339 mAppToken.removeDeadWindows();
1340 return;
1341 }
1342
Jorim Jaggidc9385a2017-05-13 02:00:31 +02001343 updateLastInsetValues();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001344 mService.makeWindowFreezingScreenIfNeededLocked(this);
1345
1346 // If the orientation is changing, or we're starting or ending a drag resizing action,
1347 // then we need to hold off on unfreezing the display until this window has been
1348 // redrawn; to do that, we need to go through the process of getting informed by the
1349 // application when it has finished drawing.
Robert Carr09286c92018-02-15 13:52:31 -08001350 if (getOrientationChanging() || dragResizingChanged) {
Robert Carre13b58e2017-08-31 14:50:44 -07001351 if (DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001352 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1353 + ", mDrawState=DRAW_PENDING in " + this
1354 + ", surfaceController " + winAnimator.mSurfaceController);
1355 }
1356 winAnimator.mDrawState = DRAW_PENDING;
1357 if (mAppToken != null) {
1358 mAppToken.clearAllDrawn();
1359 }
1360 }
1361 if (!mService.mResizingWindows.contains(this)) {
1362 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
1363 mService.mResizingWindows.add(this);
1364 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07001365 } else if (getOrientationChanging()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001366 if (isDrawnLw()) {
1367 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1368 + this + ", surfaceController " + winAnimator.mSurfaceController);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001369 setOrientationChanging(false);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001370 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1371 - mService.mDisplayFreezeTime);
1372 }
1373 }
1374 }
1375
Bryce Lee8c3cf382017-07-06 19:47:10 -07001376 boolean getOrientationChanging() {
1377 // In addition to the local state flag, we must also consider the difference in the last
1378 // reported configuration vs. the current state. If the client code has not been informed of
1379 // the change, logic dependent on having finished processing the orientation, such as
1380 // unfreezing, could be improperly triggered.
1381 // TODO(b/62846907): Checking against {@link mLastReportedConfiguration} could be flaky as
1382 // this is not necessarily what the client has processed yet. Find a
1383 // better indicator consistent with the client.
Robert Carr926643f2017-08-02 12:01:12 -07001384 return (mOrientationChanging || (isVisible()
Bryce Lee2b17afd2017-09-21 10:38:20 -07001385 && getConfiguration().orientation != getLastReportedConfiguration().orientation))
Robert Carr9c1c3a02017-08-08 12:59:01 -07001386 && !mSeamlesslyRotated
1387 && !mOrientationChangeTimedOut;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001388 }
1389
1390 void setOrientationChanging(boolean changing) {
1391 mOrientationChanging = changing;
Robert Carr9c1c3a02017-08-08 12:59:01 -07001392 mOrientationChangeTimedOut = false;
1393 }
1394
1395 void orientationChangeTimedOut() {
1396 mOrientationChangeTimedOut = true;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001397 }
1398
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001399 DisplayContent getDisplayContent() {
1400 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001401 }
1402
Adrian Roos5251b1d2018-03-23 18:57:43 +01001403 @Override
1404 void onDisplayChanged(DisplayContent dc) {
1405 super.onDisplayChanged(dc);
1406 // Window was not laid out for this display yet, so make sure mLayoutSeq does not match.
1407 if (dc != null) {
1408 mLayoutSeq = dc.mLayoutSeq - 1;
Brad Stenningaf596412018-04-02 12:03:19 -07001409 mInputWindowHandle.displayId = dc.getDisplayId();
Adrian Roos5251b1d2018-03-23 18:57:43 +01001410 }
1411 }
1412
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001413 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001414 final DisplayContent displayContent = getDisplayContent();
1415 return displayContent != null ? displayContent.getDisplayInfo() : null;
1416 }
1417
Jorim Jaggife762342016-10-13 14:33:27 +02001418 @Override
1419 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001420 final DisplayContent displayContent = getDisplayContent();
1421 if (displayContent == null) {
Brad Stenningaf596412018-04-02 12:03:19 -07001422 return Display.INVALID_DISPLAY;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001423 }
1424 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001425 }
1426
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001427 Task getTask() {
Bryce Lee6d410262017-02-28 15:30:17 -08001428 return mAppToken != null ? mAppToken.getTask() : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001429 }
1430
1431 TaskStack getStack() {
1432 Task task = getTask();
1433 if (task != null) {
1434 if (task.mStack != null) {
1435 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001436 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001437 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001438 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1439 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001440 final DisplayContent dc = getDisplayContent();
1441 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001442 }
1443
Skuhnef932e562015-08-20 12:07:30 -07001444 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001445 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001446 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001447 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001448 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001449 final Task task = getTask();
1450 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001451 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001452 mTmpRect.setEmpty();
1453 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001454 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001455 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001456 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001457 } else {
1458 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001459 }
1460 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001461
Chong Zhang9184ec62015-09-24 12:32:21 -07001462 bounds.set(mVisibleFrame);
1463 if (intersectWithStackBounds) {
1464 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001465 }
1466
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001467 if (bounds.isEmpty()) {
1468 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001469 if (intersectWithStackBounds) {
1470 bounds.intersect(mTmpRect);
1471 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001472 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001473 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001474 }
1475
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001476 public long getInputDispatchingTimeoutNanos() {
1477 return mAppToken != null
Wale Ogunwale72919d22016-12-08 18:58:50 -08001478 ? mAppToken.mInputDispatchingTimeoutNanos
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001479 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1480 }
1481
Craig Mautnere8552142012-11-07 13:55:47 -08001482 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001483 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001484 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001485 }
1486
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001487 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1488 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1489 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1490 if (dtdx < -.000001f || dtdx > .000001f) return false;
1491 if (dsdy < -.000001f || dsdy > .000001f) return false;
1492 return true;
1493 }
1494
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001495 void prelayout() {
1496 if (mEnforceSizeCompat) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001497 mGlobalScale = getDisplayContent().mCompatibleScreenScale;
1498 mInvGlobalScale = 1 / mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001499 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001500 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001501 }
1502 }
1503
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001504 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001505 boolean hasContentToDisplay() {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001506 if (!mAppFreezing && isDrawnLw() && (mViewVisibility == View.VISIBLE
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001507 || (mWinAnimator.isAnimationSet() && !mService.mAppTransition.isTransitionSet()))) {
1508 return true;
1509 }
1510
Wale Ogunwale44f21802016-09-02 12:49:48 -07001511 return super.hasContentToDisplay();
1512 }
1513
1514 @Override
1515 boolean isVisible() {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001516 return wouldBeVisibleIfPolicyIgnored() && mPolicyVisibility;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001517 }
1518
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001519 /**
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001520 * @return True if the window would be visible if we'd ignore policy visibility, false
1521 * otherwise.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001522 */
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001523 boolean wouldBeVisibleIfPolicyIgnored() {
Jorim Jaggi43530c92017-05-18 01:53:56 +02001524 return mHasSurface && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001525 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001526 }
1527
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001528 @Override
1529 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001530 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001531 }
1532
1533 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001534 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1535 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001536 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001537 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1538 boolean isWinVisibleLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001539 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.isSelfAnimating())
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001540 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001541 }
1542
1543 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001544 * The same as isVisible(), but follows the current hidden state of the associated app token,
1545 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001546 */
1547 boolean isVisibleNow() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001548 return (!mToken.isHidden() || mAttrs.type == TYPE_APPLICATION_STARTING)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001549 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001550 }
1551
1552 /**
1553 * Can this window possibly be a drag/drop target? The test here is
1554 * a combination of the above "visible now" with the check that the
1555 * Input Manager uses when discarding windows from input consideration.
1556 */
1557 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001558 return isVisibleNow() && !mRemoved
1559 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001560 }
1561
1562 /**
1563 * Same as isVisible(), but we also count it as visible between the
1564 * call to IWindowSession.add() and the first relayout().
1565 */
1566 boolean isVisibleOrAdding() {
1567 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001568 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001569 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001570 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001571 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001572 }
1573
1574 /**
1575 * Is this window currently on-screen? It is on-screen either if it
1576 * is visible or it is currently running an animation before no longer
1577 * being visible.
1578 */
1579 boolean isOnScreen() {
Jorim Jaggiaf221d12016-11-15 14:59:57 -08001580 if (!mHasSurface || mDestroying || !mPolicyVisibility) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001581 return false;
1582 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001583 final AppWindowToken atoken = mAppToken;
1584 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001585 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001586 || mWinAnimator.isAnimationSet());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001587 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01001588 return !isParentWindowHidden() || mWinAnimator.isAnimationSet();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001589 }
1590
1591 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001592 * Whether this window's drawn state might affect the drawn states of the app token.
1593 *
Chong Zhang8e4bda92016-05-04 15:08:18 -07001594 * @return true if the window should be considered while evaluating allDrawn flags.
1595 */
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001596 boolean mightAffectAllDrawn() {
1597 final boolean isAppType = mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1598 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION;
1599 return (isOnScreen() || isAppType) && !mAnimatingExit && !mDestroying;
Chong Zhang8e4bda92016-05-04 15:08:18 -07001600 }
1601
1602 /**
1603 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1604 * it must be drawn before allDrawn can become true.
1605 */
1606 boolean isInteresting() {
1607 return mAppToken != null && !mAppDied
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001608 && (!mAppToken.isFreezingScreen() || !mAppFreezing);
Chong Zhang8e4bda92016-05-04 15:08:18 -07001609 }
1610
1611 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001612 * Like isOnScreen(), but we don't return true if the window is part
1613 * of a transition that has not yet been started.
1614 */
1615 boolean isReadyForDisplay() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001616 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001617 return false;
1618 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001619 return mHasSurface && mPolicyVisibility && !mDestroying
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001620 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.isHidden())
1621 || mWinAnimator.isAnimationSet());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001622 }
1623
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001624 // TODO: Another visibility method that was added late in the release to minimize risk.
1625 @Override
1626 public boolean canAffectSystemUiFlags() {
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001627 final boolean translucent = mAttrs.alpha == 0.0f;
Jorim Jaggi72207752018-01-08 13:16:59 +01001628 if (translucent) {
1629 return false;
1630 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001631 if (mAppToken == null) {
1632 final boolean shown = mWinAnimator.getShown();
1633 final boolean exiting = mAnimatingExit || mDestroying;
Jorim Jaggi72207752018-01-08 13:16:59 +01001634 return shown && !exiting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001635 } else {
Jorim Jaggi50bf59c2018-03-09 17:29:48 +01001636 final Task task = getTask();
1637 final boolean canFromTask = task != null && task.canAffectSystemUiFlags();
1638 return canFromTask && !mAppToken.isHidden();
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001639 }
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001640 }
1641
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001642 /**
1643 * Like isOnScreen, but returns false if the surface hasn't yet
1644 * been drawn.
1645 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001646 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001647 public boolean isDisplayedLw() {
1648 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001649 return isDrawnLw() && mPolicyVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001650 && ((!isParentWindowHidden() && (atoken == null || !atoken.hiddenRequested))
1651 || mWinAnimator.isAnimationSet());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001652 }
1653
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001654 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001655 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001656 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001657 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001658 public boolean isAnimatingLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001659 return isAnimating();
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001660 }
1661
Craig Mautner812d2ca2012-09-27 15:35:34 -07001662 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001663 public boolean isGoneForLayoutLw() {
1664 final AppWindowToken atoken = mAppToken;
1665 return mViewVisibility == View.GONE
1666 || !mRelayoutCalled
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001667 || (atoken == null && mToken.isHidden())
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001668 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001669 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001670 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001671 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001672 }
1673
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001674 /**
1675 * Returns true if the window has a surface that it has drawn a
1676 * complete UI in to.
1677 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001678 public boolean isDrawFinishedLw() {
1679 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001680 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1681 || mWinAnimator.mDrawState == READY_TO_SHOW
1682 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001683 }
1684
1685 /**
1686 * Returns true if the window has a surface that it has drawn a
1687 * complete UI in to.
1688 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001689 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001690 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001691 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001692 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001693 }
1694
1695 /**
1696 * Return true if the window is opaque and fully drawn. This indicates
1697 * it may obscure windows behind it.
1698 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001699 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001700 // When there is keyguard, wallpaper could be placed over the secure app
1701 // window but invisible. We need to check wallpaper visibility explicitly
1702 // to determine if it's occluding apps.
1703 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1704 || (mIsWallpaper && mWallpaperVisible))
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001705 && isDrawnLw() && !mWinAnimator.isAnimationSet();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001706 }
1707
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001708 @Override
1709 void onMovedByResize() {
1710 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001711 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001712 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001713 }
1714
1715 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1716 boolean changed = false;
1717
1718 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001719 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001720 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1721 }
1722
1723 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1724 // Starting window that's exiting will be removed when the animation finishes.
1725 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1726 // to actually remove it.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001727 if (!visible && isVisibleNow() && mAppToken.isSelfAnimating()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001728 mAnimatingExit = true;
1729 mRemoveOnExit = true;
1730 mWindowRemovalAllowed = true;
1731 }
1732 return changed;
1733 }
1734
chaviwe390cbd2018-04-16 15:29:38 -07001735 final boolean isVisibleNow = isVisibleNow();
1736 if (visible != isVisibleNow) {
1737 // Run exit animation if:
1738 // 1. App visibility and WS visibility are different
1739 // 2. App is not running an animation
1740 // 3. WS is currently visible
1741 if (!runningAppAnimation && isVisibleNow) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001742 final AccessibilityController accessibilityController =
1743 mService.mAccessibilityController;
chaviwe390cbd2018-04-16 15:29:38 -07001744 final int winTransit = TRANSIT_EXIT;
1745 mWinAnimator.applyAnimationLocked(winTransit, false /* isEntrance */);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001746 //TODO (multidisplay): Magnification is supported only for the default
1747 if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
1748 accessibilityController.onWindowTransitionLocked(this, winTransit);
1749 }
1750 }
1751 changed = true;
1752 setDisplayLayoutNeeded();
1753 }
1754
1755 return changed;
1756 }
1757
1758 boolean onSetAppExiting() {
1759 final DisplayContent displayContent = getDisplayContent();
1760 boolean changed = false;
1761
1762 if (isVisibleNow()) {
1763 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
1764 //TODO (multidisplay): Magnification is supported only for the default
1765 if (mService.mAccessibilityController != null && isDefaultDisplay()) {
1766 mService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
1767 }
1768 changed = true;
1769 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001770 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001771 }
1772 }
1773
1774 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001775 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001776 changed |= c.onSetAppExiting();
1777 }
1778
1779 return changed;
1780 }
1781
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001782 @Override
1783 void onResize() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001784 final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
Andrii Kulian3dcdf642018-05-23 17:14:00 -07001785 if (mHasSurface && !isGoneForLayoutLw() && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001786 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001787 resizingWindows.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001788 }
1789 if (isGoneForLayoutLw()) {
1790 mResizedWhileGone = true;
1791 }
1792
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001793 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001794 }
1795
1796 void onUnfreezeBounds() {
1797 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001798 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001799 c.onUnfreezeBounds();
1800 }
1801
1802 if (!mHasSurface) {
1803 return;
1804 }
1805
1806 mLayoutNeeded = true;
1807 setDisplayLayoutNeeded();
1808 if (!mService.mResizingWindows.contains(this)) {
1809 mService.mResizingWindows.add(this);
1810 }
1811 }
1812
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001813 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001814 * If the window has moved due to its containing content frame changing, then notify the
1815 * listeners and optionally animate it. Simply checking a change of position is not enough,
1816 * because being move due to dock divider is not a trigger for animation.
1817 */
chaviw161ea3e2018-01-31 12:01:12 -08001818 void handleWindowMovedIfNeeded() {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001819 if (!hasMoved()) {
1820 return;
1821 }
1822
1823 // Frame has moved, containing content frame has also moved, and we're not currently
1824 // animating... let's do something.
1825 final int left = mFrame.left;
1826 final int top = mFrame.top;
1827 final Task task = getTask();
1828 final boolean adjustedForMinimizedDockOrIme = task != null
1829 && (task.mStack.isAdjustedForMinimizedDockedStack()
1830 || task.mStack.isAdjustedForIme());
David Stevens9440dc82017-03-16 19:00:20 -07001831 if (mToken.okToAnimate()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001832 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1833 && !isDragResizing() && !adjustedForMinimizedDockOrIme
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001834 && getWindowConfiguration().hasMovementAnimations()
Adrian Roos41f7e9d2018-06-07 15:29:34 +02001835 && !mWinAnimator.mLastHidden
1836 && !mSeamlesslyRotated) {
chaviw161ea3e2018-01-31 12:01:12 -08001837 startMoveAnimation(left, top);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001838 }
1839
1840 //TODO (multidisplay): Accessibility supported only for the default display.
1841 if (mService.mAccessibilityController != null
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001842 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001843 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
1844 }
1845
1846 try {
1847 mClient.moved(left, top);
1848 } catch (RemoteException e) {
1849 }
1850 mMovedByResize = false;
1851 }
1852
1853 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001854 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001855 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1856 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001857 private boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001858 return mHasSurface && (mContentChanged || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001859 && !mAnimatingExit
Chong Zhangbd0d9372015-12-28 15:18:29 -08001860 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001861 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001862 }
1863
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001864 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001865 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001866 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001867 return false;
1868 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001869 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001870 }
1871
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001872 boolean fillsDisplay() {
1873 final DisplayInfo displayInfo = getDisplayInfo();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001874 return mFrame.left <= 0 && mFrame.top <= 0
1875 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001876 }
1877
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001878 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001879 boolean isConfigChanged() {
Bryce Lee2b17afd2017-09-21 10:38:20 -07001880 return !getLastReportedConfiguration().equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001881 }
1882
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001883 void onWindowReplacementTimeout() {
1884 if (mWillReplaceWindow) {
1885 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001886 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001887 // delays removal on certain conditions, which will leave the stale window in the
1888 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1889 //
1890 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001891 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001892 } else {
1893 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001894 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001895 c.onWindowReplacementTimeout();
1896 }
1897 }
1898 }
1899
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001900 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001901 void forceWindowsScaleableInTransaction(boolean force) {
1902 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1903 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1904 }
1905
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001906 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001907 }
1908
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001909 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001910 void removeImmediately() {
1911 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001912
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001913 if (mRemoved) {
1914 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001915 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1916 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001917 return;
1918 }
1919
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001920 mRemoved = true;
1921
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001922 mWillReplaceWindow = false;
1923 if (mReplacementWindow != null) {
1924 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1925 }
1926
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001927 final DisplayContent dc = getDisplayContent();
Robert Carr825581a2018-03-30 14:00:53 -07001928 if (isInputMethodTarget()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001929 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001930 }
1931
1932 final int type = mAttrs.type;
1933 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001934 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001935 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001936 if (mTapExcludeRegionHolder != null) {
1937 // If a tap exclude region container was initialized for this window, then it should've
1938 // also been registered in display.
1939 dc.mTapExcludeProvidingWindows.remove(this);
1940 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001941 mPolicy.removeWindowLw(this);
1942
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001943 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001944
Craig Mautner96868332012-12-04 14:29:11 -08001945 mWinAnimator.destroyDeferredSurfaceLocked();
1946 mWinAnimator.destroySurfaceLocked();
Wale Ogunwale943002b2017-02-15 19:34:01 -08001947 mSession.windowRemovedLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001948 try {
1949 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1950 } catch (RuntimeException e) {
1951 // Ignore if it has already been removed (usually because
1952 // we are doing this as part of processing a death note.)
1953 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001954
1955 mService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001956 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001957
Wale Ogunwale571771c2016-08-26 13:18:50 -07001958 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001959 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001960 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001961 removeIfPossible(false /*keepVisibleDeadWindow*/);
1962 }
1963
Wale Ogunwale571771c2016-08-26 13:18:50 -07001964 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001965 mWindowRemovalAllowed = true;
1966 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1967 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1968
1969 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1970 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1971 "Starting window removed " + this);
1972
1973 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && this == mService.mCurrentFocus)
1974 Slog.v(TAG_WM, "Remove " + this + " client="
1975 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1976 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1977 + Debug.getCallers(5));
1978
1979 final long origId = Binder.clearCallingIdentity();
1980
Peter Visontay3556a3b2017-11-01 17:23:17 +00001981 try {
1982 disposeInputChannel();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001983
Peter Visontay3556a3b2017-11-01 17:23:17 +00001984 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1985 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1986 + " mAnimatingExit=" + mAnimatingExit
1987 + " mRemoveOnExit=" + mRemoveOnExit
1988 + " mHasSurface=" + mHasSurface
1989 + " surfaceShowing=" + mWinAnimator.getShown()
1990 + " isAnimationSet=" + mWinAnimator.isAnimationSet()
1991 + " app-animation="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001992 + (mAppToken != null ? mAppToken.isSelfAnimating() : "false")
Peter Visontay3556a3b2017-11-01 17:23:17 +00001993 + " mWillReplaceWindow=" + mWillReplaceWindow
1994 + " inPendingTransaction="
1995 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
1996 + " mDisplayFrozen=" + mService.mDisplayFrozen
1997 + " callers=" + Debug.getCallers(6));
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001998
Peter Visontay3556a3b2017-11-01 17:23:17 +00001999 // Visibility of the removed window. Will be used later to update orientation later on.
2000 boolean wasVisible = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002001
Peter Visontay3556a3b2017-11-01 17:23:17 +00002002 final int displayId = getDisplayId();
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002003
Peter Visontay3556a3b2017-11-01 17:23:17 +00002004 // First, see if we need to run an animation. If we do, we have to hold off on removing the
2005 // window until the animation is done. If the display is frozen, just remove immediately,
2006 // since the animation wouldn't be seen.
2007 if (mHasSurface && mToken.okToAnimate()) {
2008 if (mWillReplaceWindow) {
2009 // This window is going to be replaced. We need to keep it around until the new one
2010 // gets added, then we will get rid of this one.
2011 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
2012 "Preserving " + this + " until the new one is " + "added");
2013 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
2014 // been removed. We probably need another flag to indicate that window removal
2015 // should be deffered vs. overloading the flag that says we are playing an exit
2016 // animation.
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002017 mAnimatingExit = true;
Peter Visontay3556a3b2017-11-01 17:23:17 +00002018 mReplacingRemoveRequested = true;
2019 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002020 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002021
Peter Visontay3556a3b2017-11-01 17:23:17 +00002022 // If we are not currently running the exit animation, we need to see about starting one
2023 wasVisible = isWinVisibleLw();
2024
2025 if (keepVisibleDeadWindow) {
2026 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
2027 "Not removing " + this + " because app died while it's visible");
2028
2029 mAppDied = true;
2030 setDisplayLayoutNeeded();
2031 mService.mWindowPlacerLocked.performSurfacePlacement();
2032
2033 // Set up a replacement input channel since the app is now dead.
2034 // We need to catch tapping on the dead window to restart the app.
2035 openInputChannel(null);
2036 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
2037 return;
2038 }
2039
2040 if (wasVisible) {
2041 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
2042
2043 // Try starting an animation.
2044 if (mWinAnimator.applyAnimationLocked(transit, false)) {
2045 mAnimatingExit = true;
Jorim Jaggif41e8822018-04-06 17:22:03 +02002046
2047 // mAnimatingExit affects canAffectSystemUiFlags(). Run layout such that
2048 // any change from that is performed immediately.
2049 setDisplayLayoutNeeded();
2050 mService.requestTraversal();
Peter Visontay3556a3b2017-11-01 17:23:17 +00002051 }
2052 //TODO (multidisplay): Magnification is supported only for the default display.
2053 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
2054 mService.mAccessibilityController.onWindowTransitionLocked(this, transit);
2055 }
2056 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002057 final boolean isAnimating = mWinAnimator.isAnimationSet()
2058 && (mAppToken == null || !mAppToken.isWaitingForTransitionStart());
Peter Visontay3556a3b2017-11-01 17:23:17 +00002059 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
2060 && mAppToken.isLastWindow(this);
2061 // We delay the removal of a window if it has a showing surface that can be used to run
2062 // exit animation and it is marked as exiting.
2063 // Also, If isn't the an animating starting window that is the last window in the app.
2064 // We allow the removal of the non-animating starting window now as there is no
2065 // additional window or animation that will trigger its removal.
2066 if (mWinAnimator.getShown() && mAnimatingExit
2067 && (!lastWindowIsStartingWindow || isAnimating)) {
2068 // The exit animation is running or should run... wait for it!
2069 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
2070 "Not removing " + this + " due to exit animation ");
2071 setupWindowForRemoveOnExit();
2072 if (mAppToken != null) {
2073 mAppToken.updateReportedVisibilityLocked();
2074 }
2075 return;
2076 }
2077 }
2078
2079 removeImmediately();
2080 // Removing a visible window will effect the computed orientation
2081 // So just update orientation if needed.
Robert Carrae606b42018-02-15 15:36:23 -08002082 if (wasVisible && mService.updateOrientationFromAppTokensLocked(displayId)) {
Peter Visontay3556a3b2017-11-01 17:23:17 +00002083 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
2084 }
2085 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
2086 } finally {
2087 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002088 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002089 }
2090
2091 private void setupWindowForRemoveOnExit() {
2092 mRemoveOnExit = true;
2093 setDisplayLayoutNeeded();
2094 // Request a focus update as this window's input channel is already gone. Otherwise
2095 // we could have no focused window in input manager.
2096 final boolean focusChanged = mService.updateFocusedWindowLocked(
2097 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
2098 mService.mWindowPlacerLocked.performSurfacePlacement();
2099 if (focusChanged) {
2100 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2101 }
2102 }
2103
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08002104 void setHasSurface(boolean hasSurface) {
2105 mHasSurface = hasSurface;
2106 }
2107
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002108 boolean canBeImeTarget() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002109 if (mIsImWindow) {
2110 // IME windows can't be IME targets. IME targets are required to be below the IME
2111 // windows and that wouldn't be possible if the IME window is its own target...silly.
2112 return false;
2113 }
2114
Winson Chung3d0a74a2017-07-12 12:37:19 -07002115 final boolean windowsAreFocusable = mAppToken == null || mAppToken.windowsAreFocusable();
Winson Chungb1549342017-07-11 09:59:56 -07002116 if (!windowsAreFocusable) {
2117 // This window can't be an IME target if the app's windows should not be focusable.
2118 return false;
2119 }
2120
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002121 final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002122 final int type = mAttrs.type;
2123
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002124 // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are set or
2125 // both are cleared...and not a starting window.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002126 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
2127 && type != TYPE_APPLICATION_STARTING) {
2128 return false;
2129 }
2130
2131 if (DEBUG_INPUT_METHOD) {
2132 Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding());
2133 if (!isVisibleOrAdding()) {
2134 Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController
2135 + " relayoutCalled=" + mRelayoutCalled
2136 + " viewVis=" + mViewVisibility
2137 + " policyVis=" + mPolicyVisibility
2138 + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim
2139 + " parentHidden=" + isParentWindowHidden()
2140 + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
2141 if (mAppToken != null) {
2142 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + mAppToken.hiddenRequested);
2143 }
2144 }
2145 }
2146 return isVisibleOrAdding();
2147 }
2148
Chong Zhangacf11402015-11-04 16:23:10 -08002149 private final class DeadWindowEventReceiver extends InputEventReceiver {
2150 DeadWindowEventReceiver(InputChannel inputChannel) {
2151 super(inputChannel, mService.mH.getLooper());
2152 }
2153 @Override
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -07002154 public void onInputEvent(InputEvent event, int displayId) {
Chong Zhangacf11402015-11-04 16:23:10 -08002155 finishInputEvent(event, true);
2156 }
2157 }
2158 /**
2159 * Dummy event receiver for windows that died visible.
2160 */
2161 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2162
Chong Zhang112eb8c2015-11-02 11:17:00 -08002163 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002164 if (mInputChannel != null) {
2165 throw new IllegalStateException("Window already has an input channel.");
2166 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002167 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002168 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2169 mInputChannel = inputChannels[0];
2170 mClientChannel = inputChannels[1];
2171 mInputWindowHandle.inputChannel = inputChannels[0];
2172 if (outInputChannel != null) {
2173 mClientChannel.transferTo(outInputChannel);
2174 mClientChannel.dispose();
2175 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002176 } else {
2177 // If the window died visible, we setup a dummy input channel, so that taps
2178 // can still detected by input monitor channel, and we can relaunch the app.
2179 // Create dummy event receiver that simply reports all events as handled.
2180 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002181 }
2182 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002183 }
2184
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002185 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002186 if (mDeadWindowEventReceiver != null) {
2187 mDeadWindowEventReceiver.dispose();
2188 mDeadWindowEventReceiver = null;
2189 }
2190
2191 // unregister server channel first otherwise it complains about broken channel
2192 if (mInputChannel != null) {
2193 mService.mInputManager.unregisterInputChannel(mInputChannel);
2194 mInputChannel.dispose();
2195 mInputChannel = null;
2196 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002197 if (mClientChannel != null) {
2198 mClientChannel.dispose();
2199 mClientChannel = null;
2200 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07002201 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002202 }
2203
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002204 /** Returns true if the replacement window was removed. */
2205 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2206 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2207 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2208 removeReplacedWindow();
2209 return true;
2210 }
2211
2212 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002213 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002214 if (c.removeReplacedWindowIfNeeded(replacement)) {
2215 return true;
2216 }
2217 }
2218 return false;
2219 }
2220
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002221 private void removeReplacedWindow() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002222 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002223 mWillReplaceWindow = false;
2224 mAnimateReplacingWindow = false;
2225 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002226 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002227 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002228 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002229 }
2230 }
2231
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002232 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2233 boolean replacementSet = false;
2234
2235 if (mWillReplaceWindow && mReplacementWindow == null
2236 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2237
2238 mReplacementWindow = replacementCandidate;
2239 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2240 replacementSet = true;
2241 }
2242
2243 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002244 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002245 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2246 }
2247
2248 return replacementSet;
2249 }
2250
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002251 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002252 final DisplayContent dc = getDisplayContent();
2253 if (dc != null) {
2254 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002255 }
2256 }
2257
Chong Zhang5117e272016-05-03 12:47:34 -07002258 void applyAdjustForImeIfNeeded() {
2259 final Task task = getTask();
2260 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2261 task.mStack.applyAdjustForImeIfNeeded(task);
2262 }
2263 }
2264
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002265 @Override
2266 void switchUser() {
2267 super.switchUser();
2268 if (isHiddenFromUserLocked()) {
2269 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2270 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
2271 hideLw(false);
2272 }
2273 }
2274
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002275 int getTouchableRegion(Region region, int flags) {
2276 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002277 if (modal && mAppToken != null) {
2278 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002279 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002280 // If this is a modal window we need to dismiss it if it's not full screen and the
2281 // touch happens outside of the frame that displays the content. This means we
2282 // need to intercept touches outside of that window. The dim layer user
2283 // associated with the window (task or stack) will give us the good bounds, as
2284 // they would be used to display the dim layer.
Robert Carrf59b8dd2017-10-02 18:58:36 -07002285 final Task task = getTask();
2286 if (task != null) {
2287 task.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002288 } else {
Robert Carrf59b8dd2017-10-02 18:58:36 -07002289 getStack().getDimBounds(mTmpRect);
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002290 }
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002291 if (inFreeformWindowingMode()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002292 // For freeform windows we the touch region to include the whole surface for the
2293 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002294 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2295 final int delta = WindowManagerService.dipToPixel(
2296 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2297 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002298 }
2299 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002300 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002301 } else {
2302 // Not modal or full screen modal
2303 getTouchableRegion(region);
2304 }
2305 return flags;
2306 }
2307
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002308 void checkPolicyVisibilityChange() {
2309 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2310 if (DEBUG_VISIBILITY) {
2311 Slog.v(TAG, "Policy visibility changing after anim in " +
2312 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2313 }
2314 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002315 if (!mPolicyVisibility) {
Jorim Jaggi2e05af22017-12-28 15:15:11 +01002316 mWinAnimator.hide("checkPolicyVisibilityChange");
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002317 if (mService.mCurrentFocus == this) {
2318 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2319 "setAnimationLocked: setting mFocusMayChange true");
2320 mService.mFocusMayChange = true;
2321 }
Tetsutoki Shiozawa64c5f0c2018-05-18 10:55:01 +09002322 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002323 // Window is no longer visible -- make sure if we were waiting
2324 // for it to be displayed before enabling the display, that
2325 // we allow the display to be enabled now.
2326 mService.enableScreenIfNeededLocked();
2327 }
2328 }
2329 }
2330
2331 void setRequestedSize(int requestedWidth, int requestedHeight) {
2332 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2333 mLayoutNeeded = true;
2334 mRequestedWidth = requestedWidth;
2335 mRequestedHeight = requestedHeight;
2336 }
2337 }
2338
Bryce Leef858b572017-06-29 14:03:33 -07002339 void prepareWindowToDisplayDuringRelayout(boolean wasVisible) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002340 // We need to turn on screen regardless of visibility.
chaviw40234662018-02-07 09:37:16 -08002341 boolean hasTurnScreenOnFlag = (mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0;
2342 boolean allowTheaterMode =
2343 mService.mAllowTheaterModeWakeFromLayout || Settings.Global.getInt(
2344 mService.mContext.getContentResolver(), Settings.Global.THEATER_MODE_ON, 0)
2345 == 0;
2346 boolean canTurnScreenOn = mAppToken == null || mAppToken.canTurnScreenOn();
2347
2348 // The screen will turn on if the following conditions are met
2349 // 1. The window has the flag FLAG_TURN_SCREEN_ON
2350 // 2. The WMS allows theater mode.
2351 // 3. No AWT or the AWT allows the screen to be turned on. This should only be true once
2352 // per resume to prevent the screen getting getting turned on for each relayout. Set
2353 // canTurnScreenOn will be set to false so the window doesn't turn the screen on again
2354 // during this resume.
2355 // 4. When the screen is not interactive. This is because when the screen is already
2356 // interactive, the value may persist until the next animation, which could potentially
2357 // be occurring while turning off the screen. This would lead to the screen incorrectly
2358 // turning back on.
chaviw474093d2018-03-07 15:03:38 -08002359 if (hasTurnScreenOnFlag) {
2360 if (allowTheaterMode && canTurnScreenOn && !mPowerManagerWrapper.isInteractive()) {
2361 if (DEBUG_VISIBILITY || DEBUG_POWER) {
2362 Slog.v(TAG, "Relayout window turning screen on: " + this);
2363 }
2364 mPowerManagerWrapper.wakeUp(SystemClock.uptimeMillis(),
2365 "android.server.wm:TURN_ON");
chaviw40234662018-02-07 09:37:16 -08002366 }
chaviwb28de1f2018-03-02 10:42:36 -08002367
2368 if (mAppToken != null) {
2369 mAppToken.setCanTurnScreenOn(false);
2370 }
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002371 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002372
2373 // If we were already visible, skip rest of preparation.
2374 if (wasVisible) {
2375 if (DEBUG_VISIBILITY) Slog.v(TAG,
2376 "Already visible and does not turn on screen, skip preparing: " + this);
2377 return;
2378 }
2379
2380 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2381 == SOFT_INPUT_ADJUST_RESIZE) {
2382 mLayoutNeeded = true;
2383 }
2384
David Stevens9440dc82017-03-16 19:00:20 -07002385 if (isDrawnLw() && mToken.okToAnimate()) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002386 mWinAnimator.applyEnterAnimationLocked();
2387 }
Bryce Leef858b572017-06-29 14:03:33 -07002388 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002389
Bryce Leef858b572017-06-29 14:03:33 -07002390 void getMergedConfiguration(MergedConfiguration outConfiguration) {
2391 final Configuration globalConfig = mService.mRoot.getConfiguration();
2392 final Configuration overrideConfig = getMergedOverrideConfiguration();
2393 outConfiguration.setConfiguration(globalConfig, overrideConfig);
2394 }
2395
Bryce Lee2b17afd2017-09-21 10:38:20 -07002396 void setLastReportedMergedConfiguration(MergedConfiguration config) {
2397 mLastReportedConfiguration.setTo(config);
2398 }
2399
2400 void getLastReportedMergedConfiguration(MergedConfiguration config) {
2401 config.setTo(mLastReportedConfiguration);
2402 }
2403
2404 private Configuration getLastReportedConfiguration() {
2405 return mLastReportedConfiguration.getMergedConfiguration();
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002406 }
2407
2408 void adjustStartingWindowFlags() {
2409 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2410 && mAppToken.startingWindow != null) {
2411 // Special handling of starting window over the base
2412 // window of the app: propagate lock screen flags to it,
2413 // to provide the correct semantics while starting.
2414 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2415 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2416 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2417 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2418 }
2419 }
2420
2421 void setWindowScale(int requestedWidth, int requestedHeight) {
2422 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2423
2424 if (scaledWindow) {
2425 // requested{Width|Height} Surface's physical size
2426 // attrs.{width|height} Size on screen
2427 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2428 mHScale = (mAttrs.width != requestedWidth) ?
2429 (mAttrs.width / (float)requestedWidth) : 1.0f;
2430 mVScale = (mAttrs.height != requestedHeight) ?
2431 (mAttrs.height / (float)requestedHeight) : 1.0f;
2432 } else {
2433 mHScale = mVScale = 1;
2434 }
2435 }
2436
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002437 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002438 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002439 public void binderDied() {
2440 try {
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002441 boolean resetSplitScreenResizing = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002442 synchronized(mService.mWindowMap) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002443 final WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002444 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002445 if (win != null) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002446 final DisplayContent dc = getDisplayContent();
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002447 if (win.mAppToken != null && win.mAppToken.findMainWindow() == win) {
2448 mService.mTaskSnapshotController.onAppDied(win.mAppToken);
2449 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002450 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002451 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2452 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002453 // just in case they have the divider at an unstable position. Better
2454 // also reset drag resizing state, because the owner can't do it
2455 // anymore.
Wale Ogunwale61911492017-10-11 08:50:50 -07002456 final TaskStack stack =
Matthew Ng64e77cf2017-10-31 14:01:31 -07002457 dc.getSplitScreenPrimaryStackIgnoringVisibility();
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002458 if (stack != null) {
2459 stack.resetDockedStackToMiddle();
2460 }
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002461 resetSplitScreenResizing = true;
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002462 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002463 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002464 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002465 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002466 }
2467 }
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002468 if (resetSplitScreenResizing) {
2469 try {
2470 // Note: this calls into ActivityManager, so we must *not* hold the window
2471 // manager lock while calling this.
2472 mService.mActivityManager.setSplitScreenResizing(false);
2473 } catch (RemoteException e) {
2474 // Local call, shouldn't return RemoteException.
2475 throw e.rethrowAsRuntimeException();
2476 }
2477 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002478 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002479 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002480 }
2481 }
2482 }
2483
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002484 /**
2485 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2486 * because we want to preserve its location on screen to be re-activated later when the user
2487 * interacts with it.
2488 */
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002489 private boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwale89973222017-04-23 18:39:45 -07002490 if (!isWinVisibleLw() || mAppToken == null || mAppToken.isClientHidden()) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002491 // Not a visible app window or the app isn't dead.
2492 return false;
2493 }
2494
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002495 if (mAttrs.token != mClient.asBinder()) {
2496 // The window was add by a client using another client's app token. We don't want to
2497 // keep the dead window around for this case since this is meant for 'real' apps.
2498 return false;
2499 }
2500
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002501 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2502 // We don't keep starting windows since they were added by the window manager before
2503 // the app even launched.
2504 return false;
2505 }
2506
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002507 return getWindowConfiguration().keepVisibleDeadAppWindowOnScreen();
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002508 }
2509
Wale Ogunwaled045c822015-12-02 09:14:28 -08002510 /** @return true if this window desires key events. */
2511 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002512 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002513 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002514 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002515 && (mAppToken == null || mAppToken.windowsAreFocusable())
Matthew Nge15352e2016-12-20 15:36:29 -08002516 && !canReceiveTouchInput();
2517 }
2518
2519 /** @return true if this window desires touch events. */
2520 boolean canReceiveTouchInput() {
Bryce Lee6d410262017-02-28 15:30:17 -08002521 return mAppToken != null && mAppToken.getTask() != null
2522 && mAppToken.getTask().mStack.shouldIgnoreInput();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002523 }
2524
Craig Mautner749a7bb2012-04-02 13:49:53 -07002525 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002526 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002527 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002528 }
2529
Craig Mautner749a7bb2012-04-02 13:49:53 -07002530 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002531 public boolean showLw(boolean doAnimation) {
2532 return showLw(doAnimation, true);
2533 }
2534
2535 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002536 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002537 return false;
2538 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002539 if (!mAppOpVisibility) {
2540 // Being hidden due to app op request.
2541 return false;
2542 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002543 if (mPermanentlyHidden) {
2544 // Permanently hidden until the app exists as apps aren't prepared
2545 // to handle their windows being removed from under them.
2546 return false;
2547 }
Suprabh Shukla69c71422018-04-02 18:39:01 -07002548 if (mHiddenWhileSuspended) {
2549 // Being hidden due to owner package being suspended.
2550 return false;
2551 }
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002552 if (mForceHideNonSystemOverlayWindow) {
2553 // This is an alert window that is currently force hidden.
2554 return false;
2555 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002556 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002557 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002558 return false;
2559 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002560 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002561 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002562 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Jorim Jaggia5e10572017-11-15 14:36:26 +01002563 + mPolicyVisibility + " isAnimationSet=" + mWinAnimator.isAnimationSet());
David Stevens9440dc82017-03-16 19:00:20 -07002564 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002565 doAnimation = false;
Jorim Jaggia5e10572017-11-15 14:36:26 +01002566 } else if (mPolicyVisibility && !mWinAnimator.isAnimationSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002567 // Check for the case where we are currently visible and
2568 // not animating; we do not want to do animation at such a
2569 // point to become visible when we already are.
2570 doAnimation = false;
2571 }
2572 }
2573 mPolicyVisibility = true;
2574 mPolicyVisibilityAfterAnim = true;
2575 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002576 mWinAnimator.applyAnimationLocked(TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002577 }
2578 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002579 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002580 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002581 if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) {
2582 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2583 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002584 return true;
2585 }
2586
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002587 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002588 public boolean hideLw(boolean doAnimation) {
2589 return hideLw(doAnimation, true);
2590 }
2591
2592 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2593 if (doAnimation) {
David Stevens9440dc82017-03-16 19:00:20 -07002594 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002595 doAnimation = false;
2596 }
2597 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002598 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002599 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002600 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002601 return false;
2602 }
2603 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002604 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
Jorim Jaggia5e10572017-11-15 14:36:26 +01002605 if (!mWinAnimator.isAnimationSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002606 doAnimation = false;
2607 }
2608 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002609 mPolicyVisibilityAfterAnim = false;
2610 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002611 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002612 mPolicyVisibility = false;
2613 // Window is no longer visible -- make sure if we were waiting
2614 // for it to be displayed before enabling the display, that
2615 // we allow the display to be enabled now.
2616 mService.enableScreenIfNeededLocked();
2617 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002618 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002619 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002620 mService.mFocusMayChange = true;
2621 }
2622 }
2623 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002624 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002625 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002626 if (mService.mCurrentFocus == this) {
2627 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2628 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002629 return true;
2630 }
2631
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002632 void setForceHideNonSystemOverlayWindowIfNeeded(boolean forceHide) {
2633 if (mOwnerCanAddInternalSystemWindow
2634 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2635 return;
2636 }
2637 if (mForceHideNonSystemOverlayWindow == forceHide) {
2638 return;
2639 }
2640 mForceHideNonSystemOverlayWindow = forceHide;
2641 if (forceHide) {
2642 hideLw(true /* doAnimation */, true /* requestAnim */);
2643 } else {
2644 showLw(true /* doAnimation */, true /* requestAnim */);
2645 }
2646 }
2647
Suprabh Shukla69c71422018-04-02 18:39:01 -07002648 void setHiddenWhileSuspended(boolean hide) {
2649 if (mOwnerCanAddInternalSystemWindow
2650 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2651 return;
2652 }
2653 if (mHiddenWhileSuspended == hide) {
2654 return;
2655 }
2656 mHiddenWhileSuspended = hide;
2657 if (hide) {
2658 hideLw(true, true);
2659 } else {
2660 showLw(true, true);
2661 }
2662 }
2663
Svet Ganovf7b47252018-02-26 11:11:27 -08002664 private void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002665 if (mAppOpVisibility != state) {
2666 mAppOpVisibility = state;
2667 if (state) {
2668 // If the policy visibility had last been to hide, then this
2669 // will incorrectly show at this point since we lost that
2670 // information. Not a big deal -- for the windows that have app
2671 // ops modifies they should only be hidden by policy due to the
2672 // lock screen, and the user won't be changing this if locked.
2673 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002674 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002675 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002676 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002677 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002678 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002679 }
2680
Svet Ganovf7b47252018-02-26 11:11:27 -08002681 void initAppOpsState() {
2682 if (mAppOp == OP_NONE || !mAppOpVisibility) {
2683 return;
2684 }
2685 // If the app op was MODE_DEFAULT we would have checked the permission
2686 // and add the window only if the permission was granted. Therefore, if
2687 // the mode is MODE_DEFAULT we want the op to succeed as the window is
2688 // shown.
2689 final int mode = mService.mAppOps.startOpNoThrow(mAppOp,
2690 getOwningUid(), getOwningPackage(), true);
2691 if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) {
2692 setAppOpVisibilityLw(false);
2693 }
2694 }
2695
2696 void resetAppOpsState() {
2697 if (mAppOp != OP_NONE && mAppOpVisibility) {
2698 mService.mAppOps.finishOp(mAppOp, getOwningUid(), getOwningPackage());
2699 }
2700 }
2701
2702 void updateAppOpsState() {
2703 if (mAppOp == OP_NONE) {
2704 return;
2705 }
2706 final int uid = getOwningUid();
2707 final String packageName = getOwningPackage();
2708 if (mAppOpVisibility) {
2709 // There is a race between the check and the finish calls but this is fine
2710 // as this would mean we will get another change callback and will reconcile.
2711 int mode = mService.mAppOps.checkOpNoThrow(mAppOp, uid, packageName);
2712 if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) {
2713 mService.mAppOps.finishOp(mAppOp, uid, packageName);
2714 setAppOpVisibilityLw(false);
2715 }
2716 } else {
Svet Ganov522ed242018-03-07 21:40:28 -08002717 final int mode = mService.mAppOps.startOpNoThrow(mAppOp, uid, packageName, true);
Svet Ganovf7b47252018-02-26 11:11:27 -08002718 if (mode == MODE_ALLOWED || mode == MODE_DEFAULT) {
2719 setAppOpVisibilityLw(true);
2720 }
2721 }
2722 }
2723
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002724 public void hidePermanentlyLw() {
2725 if (!mPermanentlyHidden) {
2726 mPermanentlyHidden = true;
2727 hideLw(true, true);
2728 }
2729 }
2730
Jeff Brownc2932a12014-11-20 18:04:05 -08002731 public void pokeDrawLockLw(long timeout) {
2732 if (isVisibleOrAdding()) {
2733 if (mDrawLock == null) {
2734 // We want the tag name to be somewhat stable so that it is easier to correlate
2735 // in wake lock statistics. So in particular, we don't want to include the
2736 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002737 final CharSequence tag = getWindowTag();
chaviw40234662018-02-07 09:37:16 -08002738 mDrawLock = mService.mPowerManager.newWakeLock(DRAW_WAKE_LOCK, "Window:" + tag);
Jeff Brownc2932a12014-11-20 18:04:05 -08002739 mDrawLock.setReferenceCounted(false);
2740 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2741 }
2742 // Each call to acquire resets the timeout.
2743 if (DEBUG_POWER) {
2744 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2745 + mAttrs.packageName);
2746 }
2747 mDrawLock.acquire(timeout);
2748 } else if (DEBUG_POWER) {
2749 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2750 + "owned by " + mAttrs.packageName);
2751 }
2752 }
2753
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002754 @Override
2755 public boolean isAlive() {
2756 return mClient.asBinder().isBinderAlive();
2757 }
2758
Craig Mautnera987d432012-10-11 14:07:58 -07002759 boolean isClosing() {
chaviw4ad54912018-05-30 11:05:44 -07002760 return mAnimatingExit || (mAppToken != null && mAppToken.isClosingOrEnteringPip());
Craig Mautnera987d432012-10-11 14:07:58 -07002761 }
2762
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002763 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2764 animators.add(mWinAnimator);
2765
2766 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002767 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002768 c.addWinAnimatorToList(animators);
2769 }
2770 }
2771
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002772 void sendAppVisibilityToClients() {
2773 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002774
Wale Ogunwale89973222017-04-23 18:39:45 -07002775 final boolean clientHidden = mAppToken.isClientHidden();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002776 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2777 // Don't hide the starting window.
2778 return;
2779 }
2780
Wale Ogunwale89973222017-04-23 18:39:45 -07002781 if (clientHidden) {
2782 // Once we are notifying the client that it's visibility has changed, we need to prevent
2783 // it from destroying child surfaces until the animation has finished. We do this by
2784 // detaching any surface control the client added from the client.
2785 for (int i = mChildren.size() - 1; i >= 0; --i) {
2786 final WindowState c = mChildren.get(i);
2787 c.mWinAnimator.detachChildren();
2788 }
2789
2790 mWinAnimator.detachChildren();
2791 }
2792
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002793 try {
2794 if (DEBUG_VISIBILITY) Slog.v(TAG,
2795 "Setting visibility of " + this + ": " + (!clientHidden));
2796 mClient.dispatchAppVisibility(!clientHidden);
2797 } catch (RemoteException e) {
2798 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002799 }
2800
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002801 void onStartFreezingScreen() {
2802 mAppFreezing = true;
2803 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002804 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002805 c.onStartFreezingScreen();
2806 }
2807 }
2808
2809 boolean onStopFreezingScreen() {
2810 boolean unfrozeWindows = false;
2811 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002812 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002813 unfrozeWindows |= c.onStopFreezingScreen();
2814 }
2815
2816 if (!mAppFreezing) {
2817 return unfrozeWindows;
2818 }
2819
Wale Ogunwale953171d2016-09-30 09:17:30 -07002820 mAppFreezing = false;
2821
Bryce Lee8c3cf382017-07-06 19:47:10 -07002822 if (mHasSurface && !getOrientationChanging()
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002823 && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
2824 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
Bryce Lee8c3cf382017-07-06 19:47:10 -07002825 setOrientationChanging(true);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002826 mService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002827 }
2828 mLastFreezeDuration = 0;
2829 setDisplayLayoutNeeded();
2830 return true;
2831 }
2832
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002833 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2834 boolean destroyedSomething = false;
Jorim Jaggi59f3e922018-01-05 15:40:32 +01002835
2836 // Copying to a different list as multiple children can be removed.
2837 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
2838 for (int i = childWindows.size() - 1; i >= 0; --i) {
2839 final WindowState c = childWindows.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002840 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2841 }
2842
Robert Carrdb2f6e62017-03-01 20:17:58 -08002843 if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) {
2844 return destroyedSomething;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002845 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08002846
2847 if (appStopped || mWindowRemovalAllowed) {
2848 mWinAnimator.destroyPreservedSurfaceLocked();
2849 }
2850
2851 if (mDestroying) {
2852 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2853 + " destroySurfaces: appStopped=" + appStopped
2854 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2855 + " win.mRemoveOnExit=" + mRemoveOnExit);
2856 if (!cleanupOnResume || mRemoveOnExit) {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002857 destroySurfaceUnchecked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08002858 }
2859 if (mRemoveOnExit) {
2860 removeImmediately();
2861 }
2862 if (cleanupOnResume) {
2863 requestUpdateWallpaperIfNeeded();
2864 }
2865 mDestroying = false;
2866 destroyedSomething = true;
2867 }
2868
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002869 return destroyedSomething;
2870 }
Chris Craik3131bde2016-05-06 13:39:08 -07002871
Robert Carr89a28ab2017-04-24 15:33:11 -07002872 // Destroy or save the application surface without checking
2873 // various indicators of whether the client has released the surface.
2874 // This is in general unsafe, and most callers should use {@link #destroySurface}
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002875 void destroySurfaceUnchecked() {
2876 mWinAnimator.destroySurfaceLocked();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002877
Chong Zhang92147042016-05-09 12:47:11 -07002878 // Clear animating flags now, since the surface is now gone. (Note this is true even
2879 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2880 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002881 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002882
Craig Mautner69b08182012-09-05 13:07:13 -07002883 @Override
2884 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002885 final DisplayContent displayContent = getDisplayContent();
2886 if (displayContent == null) {
2887 // Only a window that was on a non-default display can be detached from it.
2888 return false;
2889 }
Winson Chung47a3e652014-05-21 16:03:42 -07002890 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002891 }
2892
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002893 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07002894 mShowToOwnerOnly = showToOwnerOnly;
2895 }
2896
Wale Ogunwaleea92d972016-12-08 07:33:13 -08002897 private boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002898 // Child windows are evaluated based on their parent window.
2899 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002900 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale72919d22016-12-08 18:58:50 -08002901 && win.mAppToken != null && win.mAppToken.mShowForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002902
2903 // All window frames that are fullscreen extend above status bar, but some don't extend
2904 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2905 // bottom right.
2906 if (win.mFrame.left <= win.mDisplayFrame.left
2907 && win.mFrame.top <= win.mDisplayFrame.top
2908 && win.mFrame.right >= win.mStableFrame.right
2909 && win.mFrame.bottom >= win.mStableFrame.bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002910 // Is a fullscreen window, like the clock alarm. Show to everyone.
2911 return false;
2912 }
2913 }
2914
Craig Mautner341220f2012-10-16 15:20:09 -07002915 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01002916 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002917 }
2918
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002919 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2920 outRegion.set(
2921 frame.left + inset.left, frame.top + inset.top,
2922 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002923 }
2924
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002925 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002926 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002927 switch (mTouchableInsets) {
2928 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002929 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002930 outRegion.set(frame);
2931 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002932 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002933 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002934 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002935 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002936 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002937 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002938 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002939 outRegion.set(mGivenTouchableRegion);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002940 outRegion.translate(frame.left, frame.top);
2941 break;
2942 }
2943 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002944 cropRegionToStackBoundsIfNeeded(outRegion);
2945 }
2946
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002947 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002948 final Task task = getTask();
2949 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002950 return;
2951 }
2952
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002953 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002954 if (stack == null) {
2955 return;
2956 }
2957
2958 stack.getDimBounds(mTmpRect);
2959 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002960 }
2961
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002962 /**
2963 * Report a focus change. Must be called with no locks held, and consistently
2964 * from the same serialized thread (such as dispatched from a handler).
2965 */
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07002966 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002967 try {
2968 mClient.windowFocusChanged(focused, inTouchMode);
2969 } catch (RemoteException e) {
2970 }
2971 if (mFocusCallbacks != null) {
2972 final int N = mFocusCallbacks.beginBroadcast();
2973 for (int i=0; i<N; i++) {
2974 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2975 try {
2976 if (focused) {
2977 obs.focusGained(mWindowId.asBinder());
2978 } else {
2979 obs.focusLost(mWindowId.asBinder());
2980 }
2981 } catch (RemoteException e) {
2982 }
2983 }
2984 mFocusCallbacks.finishBroadcast();
2985 }
2986 }
2987
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002988 @Override
2989 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002990 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002991 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002992 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002993
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002994 return super.getConfiguration();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002995 }
2996
Craig Mautnerdf88d732014-01-27 09:21:32 -08002997 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002998 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08002999 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003000 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
3001 + ": " + mCompatFrame);
Bryce Leef858b572017-06-29 14:03:33 -07003002 final MergedConfiguration mergedConfiguration =
3003 new MergedConfiguration(mService.mRoot.getConfiguration(),
3004 getMergedOverrideConfiguration());
3005
Bryce Lee2b17afd2017-09-21 10:38:20 -07003006 setLastReportedMergedConfiguration(mergedConfiguration);
Bryce Leef858b572017-06-29 14:03:33 -07003007
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003008 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003009 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
3010
Craig Mautnerdf88d732014-01-27 09:21:32 -08003011 final Rect frame = mFrame;
3012 final Rect overscanInsets = mLastOverscanInsets;
3013 final Rect contentInsets = mLastContentInsets;
3014 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07003015 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003016 final Rect outsets = mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003017 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003018 final boolean reportOrientation = mReportOrientationChanged;
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003019 final int displayId = getDisplayId();
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01003020 final DisplayCutout displayCutout = mDisplayCutout.getDisplayCutout();
Chet Haase8eb48d22014-09-24 07:31:29 -07003021 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
3022 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08003023 // To prevent deadlock simulate one-way call if win.mClient is a local object.
3024 mService.mH.post(new Runnable() {
3025 @Override
3026 public void run() {
3027 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003028 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003029 stableInsets, outsets, reportDraw, mergedConfiguration,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003030 reportOrientation, displayId, displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003031 } catch (RemoteException e) {
3032 // Not a remote call, RemoteException won't be raised.
3033 }
3034 }
3035 });
3036 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003037 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003038 outsets, reportDraw, mergedConfiguration, reportOrientation, displayId,
3039 displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003040 }
Svetoslav4604abc2014-06-10 18:59:30 -07003041
3042 //TODO (multidisplay): Accessibility supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07003043 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07003044 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07003045 }
3046
Craig Mautnerdf88d732014-01-27 09:21:32 -08003047 mOverscanInsetsChanged = false;
3048 mContentInsetsChanged = false;
3049 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07003050 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003051 mOutsetsChanged = false;
Robert Carr31aa98b2016-07-20 15:29:03 -07003052 mFrameSizeChanged = false;
Adrian Roos5c6b6222017-11-07 17:36:10 +01003053 mDisplayCutoutChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003054 mWinAnimator.mSurfaceResized = false;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003055 mReportOrientationChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003056 } catch (RemoteException e) {
Bryce Lee8c3cf382017-07-06 19:47:10 -07003057 setOrientationChanging(false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003058 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
3059 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08003060 // We are assuming the hosting process is dead or in a zombie state.
3061 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
3062 + ", removing this window.");
3063 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07003064 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003065 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003066 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003067 }
3068
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003069 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08003070 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
3071 // start even if we haven't received the relayout window, so that the client requests
3072 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
3073 // until the window to small size, otherwise the multithread renderer will shift last
3074 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
3075 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003076 boolean resizing = isDragResizing() || isDragResizeChanged();
Wale Ogunwale3382ab12017-07-27 08:55:03 -07003077 if (getWindowConfiguration().useWindowFrameForBackdrop() || !resizing) {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003078 return frame;
3079 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07003080 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003081 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003082 return mTmpRect;
3083 }
3084
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003085 private int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003086 final TaskStack stack = getStack();
3087 if (stack == null) {
3088 return INVALID_STACK_ID;
3089 }
3090 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003091 }
3092
3093 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
3094 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003095 MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId,
3096 DisplayCutout displayCutout)
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003097 throws RemoteException {
Robert Carr09286c92018-02-15 13:52:31 -08003098 final boolean forceRelayout = isDragResizeChanged() || reportOrientation;
Chong Zhangedaf3052016-04-22 15:04:31 -07003099
Jorim Jaggidc249c42015-12-15 14:57:31 -08003100 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003101 reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003102 mPolicy.isNavBarForcedShownLw(this), displayId,
3103 new DisplayCutout.ParcelableWrapper(displayCutout));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003104 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003105 }
3106
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003107 public void registerFocusObserver(IWindowFocusObserver observer) {
3108 synchronized(mService.mWindowMap) {
3109 if (mFocusCallbacks == null) {
3110 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
3111 }
3112 mFocusCallbacks.register(observer);
3113 }
3114 }
3115
3116 public void unregisterFocusObserver(IWindowFocusObserver observer) {
3117 synchronized(mService.mWindowMap) {
3118 if (mFocusCallbacks != null) {
3119 mFocusCallbacks.unregister(observer);
3120 }
3121 }
3122 }
3123
3124 public boolean isFocused() {
3125 synchronized(mService.mWindowMap) {
3126 return mService.mCurrentFocus == this;
3127 }
3128 }
3129
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003130 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07003131 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003132 final Task task = getTask();
3133 return task != null && !task.isFullscreen();
3134 }
3135
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003136 /** Is this window in a container that takes up the entire screen space? */
3137 private boolean inFullscreenContainer() {
Bryce Leef3c6a472017-11-14 14:53:06 -08003138 return mAppToken == null || (mAppToken.matchParentBounds() && !isInMultiWindowMode());
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003139 }
3140
Andrii Kulian283acd22017-08-03 04:03:51 -07003141 /** @return true when the window is in fullscreen task, but has non-fullscreen bounds set. */
3142 boolean isLetterboxedAppWindow() {
Adrian Roos865c70f2018-01-10 17:32:27 +01003143 return !isInMultiWindowMode() && mAppToken != null && !mAppToken.matchParentBounds()
3144 || isLetterboxedForDisplayCutoutLw();
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003145 }
3146
Adrian Roos865c70f2018-01-10 17:32:27 +01003147 @Override
3148 public boolean isLetterboxedForDisplayCutoutLw() {
3149 if (mAppToken == null) {
3150 // Only windows with an AppWindowToken are letterboxed.
3151 return false;
3152 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003153 if (!mParentFrameWasClippedByDisplayCutout) {
3154 // Cutout didn't make a difference, no letterbox
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003155 return false;
3156 }
Adrian Roosfa02da62018-01-15 16:01:18 +01003157 if (mAttrs.layoutInDisplayCutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003158 // Layout in cutout, no letterbox.
3159 return false;
3160 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003161 if (!mAttrs.isFullscreen()) {
3162 // Not filling the parent frame, no letterbox
3163 return false;
Adrian Roosfa02da62018-01-15 16:01:18 +01003164 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003165 // Otherwise we need a letterbox if the layout was smaller than the app window token allowed
3166 // it to be.
3167 return !frameCoversEntireAppTokenBounds();
3168 }
3169
3170 /**
3171 * @return true if this window covers the entire bounds of its app window token
3172 * @throws NullPointerException if there is no app window token for this window
3173 */
3174 private boolean frameCoversEntireAppTokenBounds() {
3175 mTmpRect.set(mAppToken.getBounds());
3176 mTmpRect.intersectUnchecked(mFrame);
3177 return mAppToken.getBounds().equals(mTmpRect);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003178 }
3179
Adrian Roos23df3a32018-03-15 15:41:13 +01003180 @Override
3181 public boolean isLetterboxedOverlappingWith(Rect rect) {
3182 return mAppToken != null && mAppToken.isLetterboxOverlappingWith(rect);
3183 }
3184
Chong Zhang3005e752015-09-18 18:46:28 -07003185 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003186 return mDragResizing != computeDragResizing();
3187 }
3188
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003189 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003190 void setWaitingForDrawnIfResizingChanged() {
3191 if (isDragResizeChanged()) {
3192 mService.mWaitingForDrawn.add(this);
3193 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003194 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003195 }
3196
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003197 /**
3198 * @return Whether we reported a drag resize change to the application or not already.
3199 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003200 private boolean isDragResizingChangeReported() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003201 return mDragResizingChangeReported;
3202 }
3203
3204 /**
3205 * Resets the state whether we reported a drag resize change to the app.
3206 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003207 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003208 void resetDragResizingChangeReported() {
3209 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003210 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003211 }
3212
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003213 int getResizeMode() {
3214 return mResizeMode;
3215 }
3216
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003217 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003218 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003219 if (task == null) {
3220 return false;
3221 }
Tomasz Mikolajewskiaf20b8d2017-11-20 16:11:33 +09003222 if (!inSplitScreenWindowingMode() && !inFreeformWindowingMode()) {
Winson Chung2af04b32017-01-24 16:21:13 -08003223 return false;
3224 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003225 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003226 // Floating windows never enter drag resize mode.
3227 return false;
3228 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003229 if (task.isDragResizing()) {
3230 return true;
3231 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003232
3233 // If the bounds are currently frozen, it means that the layout size that the app sees
3234 // and the bounds we clip this window to might be different. In order to avoid holes, we
3235 // simulate that we are still resizing so the app fills the hole with the resizing
3236 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003237 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003238 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003239 !task.inFreeformWindowingMode() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003240
Chong Zhang3005e752015-09-18 18:46:28 -07003241 }
3242
3243 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003244 final boolean resizing = computeDragResizing();
3245 if (resizing == mDragResizing) {
3246 return;
3247 }
3248 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003249 final Task task = getTask();
3250 if (task != null && task.isDragResizing()) {
3251 mResizeMode = task.getDragResizeMode();
3252 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003253 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003254 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3255 : DRAG_RESIZE_MODE_FREEFORM;
3256 }
Chong Zhang3005e752015-09-18 18:46:28 -07003257 }
3258
3259 boolean isDragResizing() {
3260 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003261 }
3262
Robert Carr2487ce72016-04-07 15:18:45 -07003263 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003264 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3265 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003266 }
3267
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07003268 @CallSuper
3269 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02003270 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003271 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02003272 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003273 writeIdentifierToProto(proto, IDENTIFIER);
3274 proto.write(DISPLAY_ID, getDisplayId());
3275 proto.write(STACK_ID, getStackId());
3276 mAttrs.writeToProto(proto, ATTRIBUTES);
3277 mGivenContentInsets.writeToProto(proto, GIVEN_CONTENT_INSETS);
3278 mFrame.writeToProto(proto, FRAME);
3279 mContainingFrame.writeToProto(proto, CONTAINING_FRAME);
3280 mParentFrame.writeToProto(proto, PARENT_FRAME);
3281 mContentFrame.writeToProto(proto, CONTENT_FRAME);
3282 mContentInsets.writeToProto(proto, CONTENT_INSETS);
3283 mAttrs.surfaceInsets.writeToProto(proto, SURFACE_INSETS);
Jorim Jaggi45be1c4c2017-12-15 18:44:43 +01003284 mSurfacePosition.writeToProto(proto, SURFACE_POSITION);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003285 mWinAnimator.writeToProto(proto, ANIMATOR);
3286 proto.write(ANIMATING_EXIT, mAnimatingExit);
3287 for (int i = 0; i < mChildren.size(); i++) {
Adrian Roos4921ccf2017-09-28 16:54:06 +02003288 mChildren.get(i).writeToProto(proto, CHILD_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003289 }
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003290 proto.write(REQUESTED_WIDTH, mRequestedWidth);
3291 proto.write(REQUESTED_HEIGHT, mRequestedHeight);
3292 proto.write(VIEW_VISIBILITY, mViewVisibility);
3293 proto.write(SYSTEM_UI_VISIBILITY, mSystemUiVisibility);
3294 proto.write(HAS_SURFACE, mHasSurface);
3295 proto.write(IS_READY_FOR_DISPLAY, isReadyForDisplay());
3296 mDisplayFrame.writeToProto(proto, DISPLAY_FRAME);
3297 mOverscanFrame.writeToProto(proto, OVERSCAN_FRAME);
3298 mVisibleFrame.writeToProto(proto, VISIBLE_FRAME);
3299 mDecorFrame.writeToProto(proto, DECOR_FRAME);
3300 mOutsetFrame.writeToProto(proto, OUTSET_FRAME);
3301 mOverscanInsets.writeToProto(proto, OVERSCAN_INSETS);
3302 mVisibleInsets.writeToProto(proto, VISIBLE_INSETS);
3303 mStableInsets.writeToProto(proto, STABLE_INSETS);
3304 mOutsets.writeToProto(proto, OUTSETS);
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01003305 mDisplayCutout.getDisplayCutout().writeToProto(proto, CUTOUT);
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003306 proto.write(REMOVE_ON_EXIT, mRemoveOnExit);
3307 proto.write(DESTROYING, mDestroying);
3308 proto.write(REMOVED, mRemoved);
3309 proto.write(IS_ON_SCREEN, isOnScreen());
3310 proto.write(IS_VISIBLE, isVisible());
Adrian Roos2cadc5c2018-07-06 02:39:54 -07003311 if (mForceSeamlesslyRotate) {
3312 proto.write(PENDING_FORCED_SEAMLESS_ROTATION, mPendingForcedSeamlessRotate != null);
3313 proto.write(FINISHED_FORCED_SEAMLESS_ROTATION_FRAME,
3314 mFinishForcedSeamlessRotateFrameNumber);
3315 }
Steven Timotiusaf03df62017-07-18 16:56:43 -07003316 proto.end(token);
3317 }
3318
Vishnu Nair9a3e4062018-01-11 08:42:54 -08003319 @Override
3320 public void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003321 final long token = proto.start(fieldId);
3322 proto.write(HASH_CODE, System.identityHashCode(this));
3323 proto.write(USER_ID, UserHandle.getUserId(mOwnerUid));
3324 final CharSequence title = getWindowTag();
3325 if (title != null) {
3326 proto.write(TITLE, title.toString());
3327 }
3328 proto.end(token);
3329 }
3330
Jorim Jaggia5e10572017-11-15 14:36:26 +01003331 @Override
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003332 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003333 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003334 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003335 if (stack != null) {
3336 pw.print(" stackId="); pw.print(stack.mStackId);
3337 }
Craig Mautner59c00972012-07-30 12:10:24 -07003338 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003339 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07003340 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08003341 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
3342 pw.print(" package="); pw.print(mAttrs.packageName);
3343 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Jorim Jaggi484851b2017-09-22 16:03:27 +02003344 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs.toString(prefix));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003345 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
3346 pw.print(" h="); pw.print(mRequestedHeight);
3347 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003348 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
3349 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
3350 pw.print(" h="); pw.println(mLastRequestedHeight);
3351 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003352 if (mIsChildWindow || mLayoutAttached) {
3353 pw.print(prefix); pw.print("mParentWindow="); pw.print(getParentWindow());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003354 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
3355 }
3356 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
3357 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
3358 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
3359 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
3360 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
3361 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003362 if (dumpAll) {
3363 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3364 pw.print(" mSubLayer="); pw.print(mSubLayer);
3365 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautnerc2f9be02012-03-27 17:32:29 -07003366 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
3367 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003368 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003369 if (dumpAll) {
3370 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003371 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003372 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
3373 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Bryce Lee6311c4b2017-07-06 14:09:29 -07003374 pw.print(" mAppDied=");pw.print(mAppDied);
3375 pw.print(prefix); pw.print("drawnStateEvaluated=");
3376 pw.print(getDrawnStateEvaluated());
3377 pw.print(prefix); pw.print("mightAffectAllDrawn=");
Jorim Jaggie7d2b852017-08-28 17:55:15 +02003378 pw.println(mightAffectAllDrawn());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003379 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003380 pw.print(prefix); pw.print("mViewVisibility=0x");
3381 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003382 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
3383 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07003384 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
3385 pw.print(" mSystemUiVisibility=0x");
3386 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003387 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003388 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
Suprabh Shukla69c71422018-04-02 18:39:01 -07003389 || isParentWindowHidden()|| mPermanentlyHidden || mForceHideNonSystemOverlayWindow
3390 || mHiddenWhileSuspended) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003391 pw.print(prefix); pw.print("mPolicyVisibility=");
3392 pw.print(mPolicyVisibility);
3393 pw.print(" mPolicyVisibilityAfterAnim=");
3394 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003395 pw.print(" mAppOpVisibility=");
3396 pw.print(mAppOpVisibility);
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003397 pw.print(" parentHidden="); pw.print(isParentWindowHidden());
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003398 pw.print(" mPermanentlyHidden="); pw.print(mPermanentlyHidden);
Suprabh Shukla69c71422018-04-02 18:39:01 -07003399 pw.print(" mHiddenWhileSuspended="); pw.print(mHiddenWhileSuspended);
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003400 pw.print(" mForceHideNonSystemOverlayWindow="); pw.println(
3401 mForceHideNonSystemOverlayWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003402 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003403 if (!mRelayoutCalled || mLayoutNeeded) {
3404 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
3405 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003406 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003407 if (dumpAll) {
3408 pw.print(prefix); pw.print("mGivenContentInsets=");
3409 mGivenContentInsets.printShortString(pw);
3410 pw.print(" mGivenVisibleInsets=");
3411 mGivenVisibleInsets.printShortString(pw);
3412 pw.println();
3413 if (mTouchableInsets != 0 || mGivenInsetsPending) {
3414 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
3415 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003416 Region region = new Region();
3417 getTouchableRegion(region);
3418 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003419 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003420 pw.print(prefix); pw.print("mFullConfiguration="); pw.println(getConfiguration());
3421 pw.print(prefix); pw.print("mLastReportedConfiguration=");
Bryce Lee2b17afd2017-09-21 10:38:20 -07003422 pw.println(getLastReportedConfiguration());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003423 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07003424 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Chong Zhanga8975bd2016-01-28 17:13:47 -08003425 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08003426 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003427 if (dumpAll) {
3428 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
3429 pw.print(" last="); mLastFrame.printShortString(pw);
3430 pw.println();
3431 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003432 if (mEnforceSizeCompat) {
3433 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003434 pw.println();
3435 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003436 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003437 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003438 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003439 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003440 pw.println();
3441 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
3442 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003443 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003444 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003445 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003446 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04003447 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
3448 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003449 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
3450 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003451 pw.print(prefix); pw.print("Cur insets: overscan=");
3452 mOverscanInsets.printShortString(pw);
3453 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003454 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003455 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003456 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003457 pw.print(" outsets="); mOutsets.printShortString(pw);
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01003458 pw.print(" cutout=" + mDisplayCutout.getDisplayCutout());
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003459 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003460 pw.print(prefix); pw.print("Lst insets: overscan=");
3461 mLastOverscanInsets.printShortString(pw);
3462 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003463 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003464 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003465 pw.print(" physical="); mLastOutsets.printShortString(pw);
3466 pw.print(" outset="); mLastOutsets.printShortString(pw);
Adrian Roos5c6b6222017-11-07 17:36:10 +01003467 pw.print(" cutout=" + mLastDisplayCutout);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003468 pw.println();
3469 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01003470 super.dump(pw, prefix, dumpAll);
Dianne Hackborn529e7442012-11-01 14:22:28 -07003471 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
3472 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003473 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
3474 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003475 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
3476 pw.print(" mDestroying="); pw.print(mDestroying);
3477 pw.print(" mRemoved="); pw.println(mRemoved);
3478 }
chaviw40234662018-02-07 09:37:16 -08003479 if (getOrientationChanging() || mAppFreezing || mReportOrientationChanged) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003480 pw.print(prefix); pw.print("mOrientationChanging=");
3481 pw.print(mOrientationChanging);
Bryce Lee8c3cf382017-07-06 19:47:10 -07003482 pw.print(" configOrientationChanging=");
Bryce Lee2b17afd2017-09-21 10:38:20 -07003483 pw.print(getLastReportedConfiguration().orientation
Bryce Lee8c3cf382017-07-06 19:47:10 -07003484 != getConfiguration().orientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003485 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
Andrii Kulianb2e37802017-01-11 00:36:44 -08003486 pw.print(" mReportOrientationChanged="); pw.println(mReportOrientationChanged);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003487 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003488 if (mLastFreezeDuration != 0) {
3489 pw.print(prefix); pw.print("mLastFreezeDuration=");
3490 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
3491 }
Adrian Roos2cadc5c2018-07-06 02:39:54 -07003492 if (mForceSeamlesslyRotate) {
3493 pw.print(prefix); pw.print("forceSeamlesslyRotate: pending=");
3494 if (mPendingForcedSeamlessRotate != null) {
3495 mPendingForcedSeamlessRotate.dump(pw);
3496 } else {
3497 pw.print("null");
3498 }
3499 pw.print(" finishedFrameNumber="); pw.print(mFinishForcedSeamlessRotateFrameNumber);
3500 pw.println();
3501 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003502 if (mHScale != 1 || mVScale != 1) {
3503 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
3504 pw.print(" mVScale="); pw.println(mVScale);
3505 }
3506 if (mWallpaperX != -1 || mWallpaperY != -1) {
3507 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
3508 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
3509 }
3510 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
3511 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
3512 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
3513 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003514 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3515 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
3516 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
3517 pw.print(mWallpaperDisplayOffsetX);
3518 pw.print(" mWallpaperDisplayOffsetY=");
3519 pw.println(mWallpaperDisplayOffsetY);
3520 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003521 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07003522 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003523 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003524 if (isDragResizing()) {
3525 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
3526 }
3527 if (computeDragResizing()) {
3528 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
3529 }
Bryce Lee6311c4b2017-07-06 14:09:29 -07003530 pw.print(prefix); pw.println("isOnScreen=" + isOnScreen());
3531 pw.print(prefix); pw.println("isVisible=" + isVisible());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003532 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003533
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003534 @Override
3535 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003536 return Integer.toHexString(System.identityHashCode(this))
Jorim Jaggia5e10572017-11-15 14:36:26 +01003537 + " " + getWindowTag();
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003538 }
3539
Robert Carra1eb4392015-12-10 12:43:51 -08003540 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003541 CharSequence tag = mAttrs.getTitle();
3542 if (tag == null || tag.length() <= 0) {
3543 tag = mAttrs.packageName;
3544 }
3545 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003546 }
3547
3548 @Override
3549 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003550 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003551 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003552 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003553 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003554 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003555 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003556 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003557 }
3558 return mStringNameCache;
3559 }
Robert Carr58f29132015-10-29 14:19:05 -07003560
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003561 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003562 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003563 clipRect.left = (int) (clipRect.left / mHScale);
3564 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003565 }
3566 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003567 clipRect.top = (int) (clipRect.top / mVScale);
3568 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003569 }
3570 }
Robert Carr31e28482015-12-02 16:53:18 -08003571
Jorim Jaggif5834272016-04-04 20:25:41 -07003572 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
3573 final int pw = containingFrame.width();
3574 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003575 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003576 final boolean inNonFullscreenContainer = !inFullscreenContainer();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003577 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3578
3579 // We need to fit it to the display if either
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003580 // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen
3581 // for the taskless windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003582 // 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 -07003583 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on
3584 // screen, but SurfaceViews want to be always at a specific location so we don't fit it to
3585 // the display.
3586 final boolean fitToDisplay = (task == null || !inNonFullscreenContainer)
Robert Carr6f44db12016-07-21 14:54:43 -07003587 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003588 float x, y;
3589 int w,h;
3590
3591 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3592 if (mAttrs.width < 0) {
3593 w = pw;
3594 } else if (mEnforceSizeCompat) {
3595 w = (int)(mAttrs.width * mGlobalScale + .5f);
3596 } else {
3597 w = mAttrs.width;
3598 }
3599 if (mAttrs.height < 0) {
3600 h = ph;
3601 } else if (mEnforceSizeCompat) {
3602 h = (int)(mAttrs.height * mGlobalScale + .5f);
3603 } else {
3604 h = mAttrs.height;
3605 }
3606 } else {
3607 if (mAttrs.width == MATCH_PARENT) {
3608 w = pw;
3609 } else if (mEnforceSizeCompat) {
3610 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3611 } else {
3612 w = mRequestedWidth;
3613 }
3614 if (mAttrs.height == MATCH_PARENT) {
3615 h = ph;
3616 } else if (mEnforceSizeCompat) {
3617 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3618 } else {
3619 h = mRequestedHeight;
3620 }
3621 }
3622
3623 if (mEnforceSizeCompat) {
3624 x = mAttrs.x * mGlobalScale;
3625 y = mAttrs.y * mGlobalScale;
3626 } else {
3627 x = mAttrs.x;
3628 y = mAttrs.y;
3629 }
3630
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003631 if (inNonFullscreenContainer && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003632 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003633 // required by {@link Gravity#apply} call.
3634 w = Math.min(w, pw);
3635 h = Math.min(h, ph);
3636 }
3637
3638 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003639 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003640 (int) (x + mAttrs.horizontalMargin * pw),
3641 (int) (y + mAttrs.verticalMargin * ph), mFrame);
3642
3643 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003644 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003645 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003646 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003647
3648 // We need to make sure we update the CompatFrame as it is used for
3649 // cropping decisions, etc, on systems where we lack a decor layer.
3650 mCompatFrame.set(mFrame);
3651 if (mEnforceSizeCompat) {
3652 // See comparable block in computeFrameLw.
3653 mCompatFrame.scale(mInvGlobalScale);
3654 }
Robert Carr31e28482015-12-02 16:53:18 -08003655 }
Robert Carr51a1b872015-12-08 14:03:13 -08003656
3657 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003658 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003659 }
3660
Robert Carrf3b72c72016-03-21 18:16:39 -07003661 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003662 return mIsChildWindow
3663 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003664 }
3665
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003666 /**
3667 * Returns true if any window added by an application process that if of type
3668 * {@link android.view.WindowManager.LayoutParams#TYPE_TOAST} or that requires that requires
3669 * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when
3670 * this window is visible.
3671 */
3672 boolean hideNonSystemOverlayWindowsWhenVisible() {
3673 return (mAttrs.privateFlags & PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != 0
3674 && mSession.mCanHideNonSystemOverlayWindows;
3675 }
3676
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003677 /** Returns the parent window if this is a child of another window, else null. */
3678 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003679 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3680 // WindowContainer that isn't a WindowState.
3681 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003682 }
3683
3684 /** Returns the topmost parent window if this is a child of another window, else this. */
3685 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003686 WindowState current = this;
3687 WindowState topParent = current;
3688 while (current != null && current.mIsChildWindow) {
3689 current = current.getParentWindow();
3690 // Parent window can be null if the child is detached from it's parent already, but
3691 // someone still has a reference to access it. So, we return the top parent value we
3692 // already have instead of null.
3693 if (current != null) {
3694 topParent = current;
3695 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003696 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003697 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003698 }
3699
Wale Ogunwale9d147902016-07-16 11:58:55 -07003700 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003701 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003702 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003703 }
3704
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003705 void setWillReplaceWindow(boolean animate) {
3706 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003707 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003708 c.setWillReplaceWindow(animate);
3709 }
3710
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003711 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3712 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3713 // We don't set replacing on starting windows since they are added by window manager and
3714 // not the client so won't be replaced by the client.
3715 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003716 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003717
3718 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003719 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003720 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003721 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003722
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003723 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003724 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003725 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003726 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003727
3728 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003729 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003730 c.clearWillReplaceWindow();
3731 }
3732 }
3733
3734 boolean waitingForReplacement() {
3735 if (mWillReplaceWindow) {
3736 return true;
3737 }
3738
3739 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003740 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003741 if (c.waitingForReplacement()) {
3742 return true;
3743 }
3744 }
3745 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003746 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003747
Chong Zhang4d7369a2016-04-25 16:09:14 -07003748 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003749 final DisplayContent dc = getDisplayContent();
3750 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3751 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3752 dc.setLayoutNeeded();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003753 mService.mWindowPlacerLocked.requestTraversal();
3754 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003755
3756 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003757 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003758 c.requestUpdateWallpaperIfNeeded();
3759 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003760 }
3761
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003762 float translateToWindowX(float x) {
3763 float winX = x - mFrame.left;
3764 if (mEnforceSizeCompat) {
3765 winX *= mGlobalScale;
3766 }
3767 return winX;
3768 }
3769
3770 float translateToWindowY(float y) {
3771 float winY = y - mFrame.top;
3772 if (mEnforceSizeCompat) {
3773 winY *= mGlobalScale;
3774 }
3775 return winY;
3776 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003777
3778 // During activity relaunch due to resize, we sometimes use window replacement
3779 // for only child windows (as the main window is handled by window preservation)
3780 // and the big surface.
3781 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003782 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3783 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3784 // we also want to replace them at such phases, as they won't be covered by window
3785 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003786 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003787 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003788 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003789 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003790
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003791 void setWillReplaceChildWindows() {
3792 if (shouldBeReplacedWithChildren()) {
3793 setWillReplaceWindow(false /* animate */);
3794 }
3795 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003796 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003797 c.setWillReplaceChildWindows();
3798 }
3799 }
3800
3801 WindowState getReplacingWindow() {
3802 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3803 return this;
3804 }
3805 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003806 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003807 final WindowState replacing = c.getReplacingWindow();
3808 if (replacing != null) {
3809 return replacing;
3810 }
3811 }
3812 return null;
3813 }
3814
Jorim Jaggife762342016-10-13 14:33:27 +02003815 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07003816 public int getRotationAnimationHint() {
3817 if (mAppToken != null) {
3818 return mAppToken.mRotationAnimationHint;
3819 } else {
3820 return -1;
3821 }
3822 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003823
Jorim Jaggife762342016-10-13 14:33:27 +02003824 @Override
3825 public boolean isInputMethodWindow() {
3826 return mIsImWindow;
3827 }
3828
Wale Ogunwale9d147902016-07-16 11:58:55 -07003829 // This must be called while inside a transaction.
3830 boolean performShowLocked() {
3831 if (isHiddenFromUserLocked()) {
3832 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3833 hideLw(false);
3834 return false;
3835 }
3836
3837 logPerformShow("performShow on ");
3838
Jorim Jaggia50da602016-12-29 11:51:42 +01003839 final int drawState = mWinAnimator.mDrawState;
3840 if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW)
3841 && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3842 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3843 }
3844
Jorim Jaggib0d27342016-11-01 16:10:42 -07003845 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003846 return false;
3847 }
3848
3849 logPerformShow("Showing ");
3850
3851 mService.enableScreenIfNeededLocked();
3852 mWinAnimator.applyEnterAnimationLocked();
3853
3854 // Force the show in the next prepareSurfaceLocked() call.
3855 mWinAnimator.mLastAlpha = -1;
Robert Carre13b58e2017-08-31 14:50:44 -07003856 if (DEBUG_ANIM) Slog.v(TAG,
Wale Ogunwale9d147902016-07-16 11:58:55 -07003857 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3858 mWinAnimator.mDrawState = HAS_DRAWN;
3859 mService.scheduleAnimationLocked();
3860
3861 if (mHidden) {
3862 mHidden = false;
3863 final DisplayContent displayContent = getDisplayContent();
3864
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003865 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003866 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003867 if (c.mWinAnimator.mSurfaceController != null) {
3868 c.performShowLocked();
3869 // It hadn't been shown, which means layout not performed on it, so now we
3870 // want to make sure to do a layout. If called from within the transaction
3871 // loop, this will cause it to restart with a new layout.
3872 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003873 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003874 }
3875 }
3876 }
3877 }
3878
Wale Ogunwale9d147902016-07-16 11:58:55 -07003879 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003880 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003881 }
3882
3883 return true;
3884 }
3885
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003886 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003887 if (DEBUG_VISIBILITY
Jorim Jaggie4b0f282017-05-17 15:10:29 +02003888 || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003889 Slog.v(TAG, prefix + this
3890 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07003891 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003892 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3893 + " during animation: policyVis=" + mPolicyVisibility
3894 + " parentHidden=" + isParentWindowHidden()
3895 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003896 + (mAppToken != null && mAppToken.hiddenRequested)
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003897 + " tok.hidden=" + (mAppToken != null && mAppToken.isHidden())
Jorim Jaggia5e10572017-11-15 14:36:26 +01003898 + " animationSet=" + mWinAnimator.isAnimationSet()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003899 + " tok animating="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003900 + (mAppToken != null && mAppToken.isSelfAnimating())
Wale Ogunwale9d147902016-07-16 11:58:55 -07003901 + " Callers=" + Debug.getCallers(4));
3902 }
3903 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003904
3905 WindowInfo getWindowInfo() {
3906 WindowInfo windowInfo = WindowInfo.obtain();
3907 windowInfo.type = mAttrs.type;
3908 windowInfo.layer = mLayer;
3909 windowInfo.token = mClient.asBinder();
Phil Weaver5dc3ebc2017-08-16 13:04:20 -07003910 if (mAppToken != null) {
3911 windowInfo.activityToken = mAppToken.appToken.asBinder();
3912 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003913 windowInfo.title = mAttrs.accessibilityTitle;
Phil Weaverbb2f28a2017-12-22 09:44:28 -08003914 // Panel windows have no public way to set the a11y title directly. Use the
3915 // regular title as a fallback.
Phil Weaver568cf662018-04-24 17:09:26 -07003916 final boolean isPanelWindow = (mAttrs.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW)
3917 && (mAttrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW);
3918 // Accessibility overlays should have titles that work for accessibility, and can't set
3919 // the a11y title themselves.
3920 final boolean isAccessibilityOverlay =
3921 windowInfo.type == WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
3922 if (TextUtils.isEmpty(windowInfo.title) && (isPanelWindow || isAccessibilityOverlay)) {
Phil Weaverbb2f28a2017-12-22 09:44:28 -08003923 windowInfo.title = mAttrs.getTitle();
3924 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003925 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3926 windowInfo.focused = isFocused();
Phil Weaverf00cd142017-03-03 13:44:00 -08003927 Task task = getTask();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003928 windowInfo.inPictureInPicture = (task != null) && task.inPinnedWindowingMode();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003929
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003930 if (mIsChildWindow) {
3931 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003932 }
3933
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003934 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003935 if (childCount > 0) {
3936 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003937 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003938 }
3939 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003940 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003941 windowInfo.childTokens.add(child.mClient.asBinder());
3942 }
3943 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003944 return windowInfo;
3945 }
3946
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003947 int getHighestAnimLayer() {
3948 int highest = mWinAnimator.mAnimLayer;
3949 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003950 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003951 final int childLayer = c.getHighestAnimLayer();
3952 if (childLayer > highest) {
3953 highest = childLayer;
3954 }
3955 }
3956 return highest;
3957 }
3958
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003959 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003960 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003961 if (mChildren.isEmpty()) {
3962 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003963 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003964 }
3965
3966 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003967 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003968 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003969 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003970 }
3971 }
3972
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003973 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003974 // We want to consume the negative sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003975 // below the parent, then this window (the parent), and then the positive sublayer children
3976 // because they need to appear above the parent.
3977 int i = 0;
3978 final int count = mChildren.size();
3979 WindowState child = mChildren.get(i);
3980
3981 while (i < count && child.mSubLayer < 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003982 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003983 return true;
3984 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003985 i++;
3986 if (i >= count) {
3987 break;
3988 }
3989 child = mChildren.get(i);
3990 }
3991
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003992 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003993 return true;
3994 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003995
3996 while (i < count) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003997 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003998 return true;
3999 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004000 i++;
4001 if (i >= count) {
4002 break;
4003 }
4004 child = mChildren.get(i);
4005 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004006
4007 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004008 }
4009
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004010 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004011 // We want to consume the positive sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004012 // above the parent, then this window (the parent), and then the negative sublayer children
4013 // because they need to appear above the parent.
4014 int i = mChildren.size() - 1;
4015 WindowState child = mChildren.get(i);
4016
4017 while (i >= 0 && child.mSubLayer >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004018 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004019 return true;
4020 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004021 --i;
4022 if (i < 0) {
4023 break;
4024 }
4025 child = mChildren.get(i);
4026 }
4027
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004028 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004029 return true;
4030 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004031
4032 while (i >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004033 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004034 return true;
4035 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004036 --i;
4037 if (i < 0) {
4038 break;
4039 }
4040 child = mChildren.get(i);
4041 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004042
4043 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004044 }
4045
Robert Carr9785cf32018-04-25 15:06:07 -07004046 private boolean applyImeWindowsIfNeeded(ToBooleanFunction<WindowState> callback,
4047 boolean traverseTopToBottom) {
4048 // If this window is the current IME target, so we need to process the IME windows
4049 // directly above it. The exception is if we are in split screen
4050 // in which case we process the IME at the DisplayContent level to
4051 // ensure it is above the docked divider.
4052 if (isInputMethodTarget() && !inSplitScreenWindowingMode()) {
4053 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
4054 return true;
4055 }
4056 }
4057 return false;
4058 }
4059
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004060 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
4061 boolean traverseTopToBottom) {
4062 if (traverseTopToBottom) {
Robert Carr9785cf32018-04-25 15:06:07 -07004063 if (applyImeWindowsIfNeeded(callback, traverseTopToBottom)
4064 || callback.apply(this)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004065 return true;
4066 }
4067 } else {
Robert Carr9785cf32018-04-25 15:06:07 -07004068 if (callback.apply(this)
4069 || applyImeWindowsIfNeeded(callback, traverseTopToBottom)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004070 return true;
4071 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004072 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004073 return false;
4074 }
4075
Wale Ogunwaled1880962016-11-08 10:31:59 -08004076 WindowState getWindow(Predicate<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004077 if (mChildren.isEmpty()) {
4078 return callback.test(this) ? this : null;
4079 }
4080
4081 // We want to consume the positive sublayer children first because they need to appear
4082 // above the parent, then this window (the parent), and then the negative sublayer children
4083 // because they need to appear above the parent.
4084 int i = mChildren.size() - 1;
4085 WindowState child = mChildren.get(i);
4086
4087 while (i >= 0 && child.mSubLayer >= 0) {
4088 if (callback.test(child)) {
4089 return child;
4090 }
4091 --i;
4092 if (i < 0) {
4093 break;
4094 }
4095 child = mChildren.get(i);
4096 }
4097
Wale Ogunwaled1880962016-11-08 10:31:59 -08004098 if (callback.test(this)) {
4099 return this;
4100 }
Wale Ogunwale34247952017-02-19 11:57:53 -08004101
4102 while (i >= 0) {
4103 if (callback.test(child)) {
4104 return child;
4105 }
4106 --i;
4107 if (i < 0) {
4108 break;
4109 }
4110 child = mChildren.get(i);
4111 }
4112
4113 return null;
Wale Ogunwaled1880962016-11-08 10:31:59 -08004114 }
4115
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01004116 /**
4117 * @return True if we our one of our ancestors has {@link #mAnimatingExit} set to true, false
4118 * otherwise.
4119 */
4120 @VisibleForTesting
4121 boolean isSelfOrAncestorWindowAnimatingExit() {
4122 WindowState window = this;
4123 do {
4124 if (window.mAnimatingExit) {
4125 return true;
4126 }
4127 window = window.getParentWindow();
4128 } while (window != null);
4129 return false;
4130 }
4131
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004132 void onExitAnimationDone() {
4133 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
4134 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
Jorim Jaggia5e10572017-11-15 14:36:26 +01004135 + " selfAnimating=" + isSelfAnimating());
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004136
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004137 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004138 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +01004139 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004140 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004141 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004142 }
4143 }
4144
4145 if (mWinAnimator.mEnteringAnimation) {
4146 mWinAnimator.mEnteringAnimation = false;
4147 mService.requestTraversal();
4148 // System windows don't have an activity and an app token as a result, but need a way
4149 // to be informed about their entrance animation end.
4150 if (mAppToken == null) {
4151 try {
4152 mClient.dispatchWindowShown();
4153 } catch (RemoteException e) {
4154 }
4155 }
4156 }
4157
Jorim Jaggia5e10572017-11-15 14:36:26 +01004158 if (isSelfAnimating()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004159 return;
4160 }
4161
Jorim Jaggia5e10572017-11-15 14:36:26 +01004162 //TODO (multidisplay): Accessibility is supported only for the default display.
4163 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
4164 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
4165 }
4166
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01004167 if (!isSelfOrAncestorWindowAnimatingExit()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004168 return;
4169 }
4170
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07004171 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004172 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
4173
4174 mDestroying = true;
4175
4176 final boolean hasSurface = mWinAnimator.hasSurface();
Jorim Jaggi50575902018-04-10 17:49:30 +02004177
4178 // Use pendingTransaction here so hide is done the same transaction as the other
4179 // animations when exiting
4180 mWinAnimator.hide(getPendingTransaction(), "onExitAnimationDone");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004181
4182 // If we have an app token, we ask it to destroy the surface for us, so that it can take
4183 // care to ensure the activity has actually stopped and the surface is not still in use.
4184 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
4185 // transaction.
4186 if (mAppToken != null) {
4187 mAppToken.destroySurfaces();
4188 } else {
4189 if (hasSurface) {
4190 mService.mDestroySurface.add(this);
4191 }
4192 if (mRemoveOnExit) {
4193 mService.mPendingRemove.add(this);
4194 mRemoveOnExit = false;
4195 }
4196 }
4197 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07004198 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004199 }
Dan Willemsen117197f2016-07-30 13:02:59 -07004200
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004201 boolean clearAnimatingFlags() {
4202 boolean didSomething = false;
4203 // We don't want to clear it out for windows that get replaced, because the
4204 // animation depends on the flag to remove the replaced window.
4205 //
4206 // We also don't clear the mAnimatingExit flag for windows which have the
4207 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4208 // by the client. We should let animation proceed and not clear this flag or
4209 // they won't eventually be removed by WindowStateAnimator#finishExit.
4210 if (!mWillReplaceWindow && !mRemoveOnExit) {
4211 // Clear mAnimating flag together with mAnimatingExit. When animation
4212 // changes from exiting to entering, we need to clear this flag until the
4213 // new animation gets applied, so that isAnimationStarting() becomes true
4214 // until then.
4215 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4216 // placement for this window during this period, one or more frame will
4217 // show up with wrong position or scale.
4218 if (mAnimatingExit) {
4219 mAnimatingExit = false;
4220 didSomething = true;
4221 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004222 if (mDestroying) {
4223 mDestroying = false;
4224 mService.mDestroySurface.remove(this);
4225 didSomething = true;
4226 }
4227 }
4228
4229 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004230 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004231 }
4232
4233 return didSomething;
4234 }
4235
Winson4b4ba902016-07-27 19:45:52 -07004236 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004237 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004238 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004239
4240 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004241 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004242 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004243 c.hideWallpaperWindow(wasDeferred, reason);
4244 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004245 if (!mWinAnimator.mLastHidden || wasDeferred) {
4246 mWinAnimator.hide(reason);
4247 dispatchWallpaperVisibility(false);
4248 final DisplayContent displayContent = getDisplayContent();
4249 if (displayContent != null) {
4250 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
4251 }
4252 }
4253 }
4254
4255 /**
4256 * Check wallpaper window for visibility change and notify window if so.
4257 * @param visible Current visibility.
4258 */
4259 void dispatchWallpaperVisibility(final boolean visible) {
4260 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07004261 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004262
4263 // Only send notification if the visibility actually changed and we are not trying to hide
4264 // the wallpaper when we are deferring hiding of the wallpaper.
4265 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4266 mWallpaperVisible = visible;
4267 try {
4268 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4269 "Updating vis of wallpaper " + this
4270 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4271 mClient.dispatchAppVisibility(visible);
4272 } catch (RemoteException e) {
4273 }
4274 }
4275 }
4276
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004277 boolean hasVisibleNotDrawnWallpaper() {
4278 if (mWallpaperVisible && !isDrawnLw()) {
4279 return true;
4280 }
4281 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004282 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004283 if (c.hasVisibleNotDrawnWallpaper()) {
4284 return true;
4285 }
4286 }
4287 return false;
4288 }
4289
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004290 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4291 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004292 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004293 c.updateReportedVisibility(results);
4294 }
4295
4296 if (mAppFreezing || mViewVisibility != View.VISIBLE
4297 || mAttrs.type == TYPE_APPLICATION_STARTING
4298 || mDestroying) {
4299 return;
4300 }
4301 if (DEBUG_VISIBILITY) {
4302 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
4303 + ", isAnimationSet=" + mWinAnimator.isAnimationSet());
4304 if (!isDrawnLw()) {
4305 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4306 + " pv=" + mPolicyVisibility
4307 + " mDrawState=" + mWinAnimator.mDrawState
4308 + " ph=" + isParentWindowHidden()
4309 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
Jorim Jaggia5e10572017-11-15 14:36:26 +01004310 + " a=" + mWinAnimator.isAnimationSet());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004311 }
4312 }
4313
4314 results.numInteresting++;
4315 if (isDrawnLw()) {
4316 results.numDrawn++;
4317 if (!mWinAnimator.isAnimationSet()) {
4318 results.numVisible++;
4319 }
4320 results.nowGone = false;
4321 } else if (mWinAnimator.isAnimationSet()) {
4322 results.nowGone = false;
4323 }
4324 }
4325
Robert Carr683e05d2018-04-18 15:11:04 -07004326 private boolean skipDecorCrop() {
4327 // The decor frame is used to specify the region not covered by the system
4328 // decorations (nav bar, status bar). In case this is empty, for example with
4329 // FLAG_TRANSLUCENT_NAVIGATION, we don't need to do any cropping.
4330 if (mDecorFrame.isEmpty()) {
4331 return true;
4332 }
4333
4334 // But if we have a frame, and are an application window, then we must be cropped.
4335 if (mAppToken != null) {
4336 return false;
4337 }
4338
4339 // For non application windows, we may be allowed to extend over the decor bars
4340 // depending on our type and permissions assosciated with our token.
4341 return mToken.canLayerAboveSystemBars();
4342 }
4343
Robert Carrfbbde852016-10-18 11:02:28 -07004344 /**
4345 * Calculate the window crop according to system decor policy. In general this is
4346 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4347 * special cases. This rectangle is in screen space.
4348 */
4349 void calculatePolicyCrop(Rect policyCrop) {
4350 final DisplayContent displayContent = getDisplayContent();
4351 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
4352
4353 if (!isDefaultDisplay()) {
4354 // On a different display there is no system decor. Crop the window
4355 // by the screen boundaries.
4356 // TODO(multi-display)
4357 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4358 policyCrop.intersect(-mCompatFrame.left, -mCompatFrame.top,
4359 displayInfo.logicalWidth - mCompatFrame.left,
4360 displayInfo.logicalHeight - mCompatFrame.top);
Robert Carr683e05d2018-04-18 15:11:04 -07004361 } else if (skipDecorCrop()) {
Robert Carrfbbde852016-10-18 11:02:28 -07004362 // Windows without policy decor aren't cropped.
4363 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4364 } else {
4365 // Crop to the system decor specified by policy.
4366 calculateSystemDecorRect(policyCrop);
4367 }
4368 }
4369
4370 /**
4371 * The system decor rect is the region of the window which is not covered
4372 * by system decorations.
4373 */
4374 private void calculateSystemDecorRect(Rect systemDecorRect) {
4375 final Rect decorRect = mDecorFrame;
4376 final int width = mFrame.width();
4377 final int height = mFrame.height();
4378
Robert Carr217e7cc2018-01-31 18:08:39 -08004379 final int left = mFrame.left;
4380 final int top = mFrame.top;
Robert Carrfbbde852016-10-18 11:02:28 -07004381
4382 // Initialize the decor rect to the entire frame.
4383 if (isDockedResizing()) {
4384 // If we are resizing with the divider, the task bounds might be smaller than the
4385 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4386 // want in this case in order to avoid holes.
4387 //
4388 // We take care to not shrink the width, for surfaces which are larger than
4389 // the display region. Of course this area will not eventually be visible
4390 // but if we truncate the width now, we will calculate incorrectly
4391 // when adjusting to the stack bounds.
4392 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4393 systemDecorRect.set(0, 0,
4394 Math.max(width, displayInfo.logicalWidth),
4395 Math.max(height, displayInfo.logicalHeight));
4396 } else {
4397 systemDecorRect.set(0, 0, width, height);
4398 }
4399
4400 // If a freeform window is animating from a position where it would be cutoff, it would be
4401 // cutoff during the animation. We don't want that, so for the duration of the animation
4402 // we ignore the decor cropping and depend on layering to position windows correctly.
chaviw95136622018-04-09 15:20:06 -07004403
4404 // We also ignore cropping when the window is currently being drag resized in split screen
4405 // to prevent issues with the crop for screenshot.
4406 final boolean cropToDecor =
4407 !(inFreeformWindowingMode() && isAnimatingLw()) && !isDockedResizing();
Robert Carrfbbde852016-10-18 11:02:28 -07004408 if (cropToDecor) {
4409 // Intersect with the decor rect, offsetted by window position.
4410 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
4411 decorRect.right - left, decorRect.bottom - top);
4412 }
4413
4414 // If size compatibility is being applied to the window, the
4415 // surface is scaled relative to the screen. Also apply this
4416 // scaling to the crop rect. We aren't using the standard rect
4417 // scale function because we want to round things to make the crop
4418 // always round to a larger rect to ensure we don't crop too
4419 // much and hide part of the window that should be seen.
4420 if (mEnforceSizeCompat && mInvGlobalScale != 1.0f) {
4421 final float scale = mInvGlobalScale;
4422 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
4423 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
4424 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
4425 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
4426 }
4427
4428 }
4429
4430 /**
4431 * Expand the given rectangle by this windows surface insets. This
4432 * takes you from the 'window size' to the 'surface size'.
4433 * The surface insets are positive in each direction, so we inset by
4434 * the inverse.
4435 */
4436 void expandForSurfaceInsets(Rect r) {
4437 r.inset(-mAttrs.surfaceInsets.left,
4438 -mAttrs.surfaceInsets.top,
4439 -mAttrs.surfaceInsets.right,
4440 -mAttrs.surfaceInsets.bottom);
4441 }
4442
Robert Carrc91d1c32017-02-15 19:37:46 -08004443 boolean surfaceInsetsChanging() {
4444 return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets);
4445 }
4446
Bryce Leef858b572017-06-29 14:03:33 -07004447 int relayoutVisibleWindow(int result, int attrChanges, int oldVisibility) {
Robert Carrecc06b32017-04-18 14:25:10 -07004448 final boolean wasVisible = isVisibleLw();
4449
4450 result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0;
Robert Carr7b3d11d2018-03-15 14:34:45 -07004451
Robert Carrc91d1c32017-02-15 19:37:46 -08004452 if (mAnimatingExit) {
4453 Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit="
4454 + mRemoveOnExit + ", mDestroying=" + mDestroying);
4455
4456 mWinAnimator.cancelExitAnimationForNextAnimationLocked();
4457 mAnimatingExit = false;
4458 }
4459 if (mDestroying) {
4460 mDestroying = false;
4461 mService.mDestroySurface.remove(this);
4462 }
4463 if (oldVisibility == View.GONE) {
4464 mWinAnimator.mEnterAnimationPending = true;
4465 }
4466
Andrii Kulian8ee72852017-03-10 10:36:45 -08004467 mLastVisibleLayoutRotation = getDisplayContent().getRotation();
Robert Carrc91d1c32017-02-15 19:37:46 -08004468
4469 mWinAnimator.mEnteringAnimation = true;
Bryce Leeae73ba42017-05-05 09:58:25 -07004470
Bryce Leef858b572017-06-29 14:03:33 -07004471 prepareWindowToDisplayDuringRelayout(wasVisible);
Bryce Leeae73ba42017-05-05 09:58:25 -07004472
Robert Carrc91d1c32017-02-15 19:37:46 -08004473 if ((attrChanges & FORMAT_CHANGED) != 0) {
4474 // If the format can't be changed in place, preserve the old surface until the app draws
4475 // on the new one. This prevents blinking when we change elevation of freeform and
4476 // pinned windows.
4477 if (!mWinAnimator.tryChangeFormatInPlaceLocked()) {
4478 mWinAnimator.preserveSurfaceLocked();
4479 result |= RELAYOUT_RES_SURFACE_CHANGED
4480 | RELAYOUT_RES_FIRST_TIME;
4481 }
4482 }
4483
4484 // When we change the Surface size, in scenarios which may require changing
4485 // the surface position in sync with the resize, we use a preserved surface
4486 // so we can freeze it while waiting for the client to report draw on the newly
Robert Carrc6d5af52018-02-26 17:46:00 -08004487 // sized surface. At the moment this logic is only in place for switching
4488 // in and out of the big surface for split screen resize.
4489 if (isDragResizeChanged()) {
Robert Carrc91d1c32017-02-15 19:37:46 -08004490 setDragResizing();
Robert Carrc91d1c32017-02-15 19:37:46 -08004491 // We can only change top level windows to the full-screen surface when
4492 // resizing (as we only have one full-screen surface). So there is no need
4493 // to preserve and destroy windows which are attached to another, they
4494 // will keep their surface and its size may change over time.
4495 if (mHasSurface && !isChildWindow()) {
4496 mWinAnimator.preserveSurfaceLocked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08004497 result |= RELAYOUT_RES_SURFACE_CHANGED |
4498 RELAYOUT_RES_FIRST_TIME;
Robert Carrc91d1c32017-02-15 19:37:46 -08004499 }
4500 }
4501 final boolean freeformResizing = isDragResizing()
4502 && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
4503 final boolean dockedResizing = isDragResizing()
4504 && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
4505 result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0;
4506 result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004507 return result;
4508 }
4509
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004510 /**
4511 * @return True if this window has been laid out at least once; false otherwise.
4512 */
4513 boolean isLaidOut() {
4514 return mLayoutSeq != -1;
4515 }
4516
4517 /**
4518 * Updates the last inset values to the current ones.
4519 */
4520 void updateLastInsetValues() {
4521 mLastOverscanInsets.set(mOverscanInsets);
4522 mLastContentInsets.set(mContentInsets);
4523 mLastVisibleInsets.set(mVisibleInsets);
4524 mLastStableInsets.set(mStableInsets);
4525 mLastOutsets.set(mOutsets);
Adrian Roos5c6b6222017-11-07 17:36:10 +01004526 mLastDisplayCutout = mDisplayCutout;
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004527 }
4528
Jorim Jaggia5e10572017-11-15 14:36:26 +01004529 void startAnimation(Animation anim) {
4530 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4531 anim.initialize(mFrame.width(), mFrame.height(),
4532 displayInfo.appWidth, displayInfo.appHeight);
4533 anim.restrictDuration(MAX_ANIMATION_DURATION);
4534 anim.scaleCurrentDuration(mService.getWindowAnimationScaleLocked());
4535 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi2e3c31d2017-11-20 19:49:00 +01004536 new WindowAnimationSpec(anim, mSurfacePosition, false /* canSkipFirstFrame */),
4537 mService.mSurfaceAnimationRunner);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004538 startAnimation(mPendingTransaction, adapter);
4539 commitPendingTransaction();
4540 }
4541
chaviw161ea3e2018-01-31 12:01:12 -08004542 private void startMoveAnimation(int left, int top) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01004543 if (DEBUG_ANIM) Slog.v(TAG, "Setting move animation on " + this);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004544 final Point oldPosition = new Point();
4545 final Point newPosition = new Point();
4546 transformFrameToSurfacePosition(mLastFrame.left, mLastFrame.top, oldPosition);
4547 transformFrameToSurfacePosition(left, top, newPosition);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004548 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004549 new MoveAnimationSpec(oldPosition.x, oldPosition.y, newPosition.x, newPosition.y),
Jorim Jaggia5e10572017-11-15 14:36:26 +01004550 mService.mSurfaceAnimationRunner);
chaviw161ea3e2018-01-31 12:01:12 -08004551 startAnimation(getPendingTransaction(), adapter);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004552 }
4553
4554 private void startAnimation(Transaction t, AnimationAdapter adapter) {
4555 startAnimation(t, adapter, mWinAnimator.mLastHidden);
4556 }
4557
4558 @Override
4559 protected void onAnimationFinished() {
4560 mWinAnimator.onAnimationFinished();
4561 }
4562
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004563 /**
4564 * Retrieves the current transformation matrix of the window, relative to the display.
4565 *
4566 * @param float9 A temporary array of 9 floats.
4567 * @param outMatrix Matrix to fill in the transformation.
4568 */
4569 void getTransformationMatrix(float[] float9, Matrix outMatrix) {
4570 float9[Matrix.MSCALE_X] = mWinAnimator.mDsDx;
4571 float9[Matrix.MSKEW_Y] = mWinAnimator.mDtDx;
4572 float9[Matrix.MSKEW_X] = mWinAnimator.mDtDy;
4573 float9[Matrix.MSCALE_Y] = mWinAnimator.mDsDy;
Robert Carr217e7cc2018-01-31 18:08:39 -08004574 int x = mSurfacePosition.x;
4575 int y = mSurfacePosition.y;
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004576
4577 // If changed, also adjust transformFrameToSurfacePosition
4578 final WindowContainer parent = getParent();
4579 if (isChildWindow()) {
4580 final WindowState parentWindow = getParentWindow();
4581 x += parentWindow.mFrame.left - parentWindow.mAttrs.surfaceInsets.left;
4582 y += parentWindow.mFrame.top - parentWindow.mAttrs.surfaceInsets.top;
4583 } else if (parent != null) {
4584 final Rect parentBounds = parent.getBounds();
4585 x += parentBounds.left;
4586 y += parentBounds.top;
4587 }
4588 float9[Matrix.MTRANS_X] = x;
4589 float9[Matrix.MTRANS_Y] = y;
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004590 float9[Matrix.MPERSP_0] = 0;
4591 float9[Matrix.MPERSP_1] = 0;
4592 float9[Matrix.MPERSP_2] = 1;
4593 outMatrix.setValues(float9);
4594 }
4595
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004596 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4597 // access to its windows children. Need to investigate re-writing
4598 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4599 static final class UpdateReportedVisibilityResults {
4600 int numInteresting;
4601 int numVisible;
4602 int numDrawn;
4603 boolean nowGone = true;
4604
4605 void reset() {
4606 numInteresting = 0;
4607 numVisible = 0;
4608 numDrawn = 0;
4609 nowGone = true;
4610 }
4611 }
Robert Carraf422a82017-04-10 18:34:33 -07004612
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004613 private static final class WindowId extends IWindowId.Stub {
4614 private final WeakReference<WindowState> mOuter;
4615
4616 private WindowId(WindowState outer) {
4617
4618 // Use a weak reference for the outer class. This is important to prevent the following
4619 // leak: Since we send this class to the client process, binder will keep it alive as
4620 // long as the client keeps it alive. Now, if the window is removed, we need to clear
4621 // out our reference so even though this class is kept alive we don't leak WindowState,
4622 // which can keep a whole lot of classes alive.
4623 mOuter = new WeakReference<>(outer);
4624 }
4625
4626 @Override
4627 public void registerFocusObserver(IWindowFocusObserver observer) {
4628 final WindowState outer = mOuter.get();
4629 if (outer != null) {
4630 outer.registerFocusObserver(observer);
4631 }
4632 }
4633 @Override
4634 public void unregisterFocusObserver(IWindowFocusObserver observer) {
4635 final WindowState outer = mOuter.get();
4636 if (outer != null) {
4637 outer.unregisterFocusObserver(observer);
4638 }
4639 }
4640 @Override
4641 public boolean isFocused() {
4642 final WindowState outer = mOuter.get();
4643 return outer != null && outer.isFocused();
4644 }
4645 }
4646
Robert Carrb1579c82017-09-05 14:54:47 -07004647
4648 @Override
4649 boolean shouldMagnify() {
4650 if (mAttrs.type == TYPE_INPUT_METHOD ||
Robert Carree4d4b92017-11-22 12:21:46 -08004651 mAttrs.type == TYPE_INPUT_METHOD_DIALOG ||
4652 mAttrs.type == TYPE_MAGNIFICATION_OVERLAY ||
4653 mAttrs.type == TYPE_NAVIGATION_BAR ||
4654 // It's tempting to wonder: Have we forgotten the rounded corners overlay?
4655 // worry not: it's a fake TYPE_NAVIGATION_BAR_PANEL
Eugene Susla31e3bb92018-03-13 12:24:50 -07004656 mAttrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Robert Carrb1579c82017-09-05 14:54:47 -07004657 return false;
4658 }
4659 return true;
4660 }
4661
4662 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004663 SurfaceSession getSession() {
4664 if (mSession.mSurfaceSession != null) {
4665 return mSession.mSurfaceSession;
4666 } else {
4667 return getParent().getSession();
4668 }
4669 }
4670
4671 @Override
4672 boolean needsZBoost() {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00004673 if (mIsImWindow && mService.mInputMethodTarget != null) {
4674 final AppWindowToken appToken = mService.mInputMethodTarget.mAppToken;
4675 if (appToken != null) {
4676 return appToken.needsZBoost();
4677 }
4678 }
4679 return mWillReplaceWindow;
Robert Carrb1579c82017-09-05 14:54:47 -07004680 }
4681
Robert Carrf07ef9e2017-11-21 12:12:49 -08004682 private void applyDims(Dimmer dimmer) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07004683 if (!mAnimatingExit && mAppDied) {
4684 mIsDimming = true;
chaviw2fb06bc2018-01-19 17:09:15 -08004685 dimmer.dimAbove(getPendingTransaction(), this, DEFAULT_DIM_AMOUNT_DEAD_WINDOW);
chaviwebcbc342018-02-07 13:19:00 -08004686 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0 && isVisibleNow() && !mHidden) {
chaviw14076152018-02-02 14:51:20 -08004687 // Only show a dim behind when the following is satisfied:
4688 // 1. The window has the flag FLAG_DIM_BEHIND
4689 // 2. The WindowToken is not hidden so dims aren't shown when the window is exiting.
4690 // 3. The WS is considered visible according to the isVisible() method
chaviwebcbc342018-02-07 13:19:00 -08004691 // 4. The WS is not hidden.
Robert Carrf59b8dd2017-10-02 18:58:36 -07004692 mIsDimming = true;
chaviw2fb06bc2018-01-19 17:09:15 -08004693 dimmer.dimBelow(getPendingTransaction(), this, mAttrs.dimAmount);
Robert Carrf59b8dd2017-10-02 18:58:36 -07004694 }
Robert Carrf07ef9e2017-11-21 12:12:49 -08004695 }
4696
4697 @Override
4698 void prepareSurfaces() {
4699 final Dimmer dimmer = getDimmer();
4700 mIsDimming = false;
4701 if (dimmer != null) {
4702 applyDims(dimmer);
4703 }
chaviw2f0567b2018-01-29 16:22:02 -08004704 updateSurfacePosition();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004705
Robert Carrb1579c82017-09-05 14:54:47 -07004706 mWinAnimator.prepareSurfaceLocked(true);
4707 super.prepareSurfaces();
4708 }
4709
4710 @Override
Jorim Jaggia5e10572017-11-15 14:36:26 +01004711 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
4712 super.onAnimationLeashCreated(t, leash);
4713
4714 // Leash is now responsible for position, so set our position to 0.
4715 t.setPosition(mSurfaceControl, 0, 0);
chaviw3e751af2018-01-11 11:22:39 -08004716 mLastSurfacePosition.set(0, 0);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004717 }
4718
4719 @Override
4720 public void onAnimationLeashDestroyed(Transaction t) {
4721 super.onAnimationLeashDestroyed(t);
4722 updateSurfacePosition(t);
4723 }
4724
chaviwe07246a2017-12-12 16:18:29 -08004725 @Override
chaviw2f0567b2018-01-29 16:22:02 -08004726 void updateSurfacePosition() {
4727 updateSurfacePosition(getPendingTransaction());
4728 }
4729
4730 private void updateSurfacePosition(Transaction t) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01004731 if (mSurfaceControl == null) {
4732 return;
4733 }
4734
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004735 transformFrameToSurfacePosition(mFrame.left, mFrame.top, mSurfacePosition);
Robert Carrc6d5af52018-02-26 17:46:00 -08004736
Adrian Roos28c25e22018-05-31 18:07:28 +02004737 // Freeze position while we're unrotated, so the surface remains at the position it was
4738 // prior to the rotation.
4739 if (!mSurfaceAnimator.hasLeash() && mPendingForcedSeamlessRotate == null &&
4740 !mLastSurfacePosition.equals(mSurfacePosition)) {
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004741 t.setPosition(mSurfaceControl, mSurfacePosition.x, mSurfacePosition.y);
chaviw3e751af2018-01-11 11:22:39 -08004742 mLastSurfacePosition.set(mSurfacePosition.x, mSurfacePosition.y);
Robert Carrc6d5af52018-02-26 17:46:00 -08004743 if (surfaceInsetsChanging() && mWinAnimator.hasSurface()) {
4744 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
4745 t.deferTransactionUntil(mSurfaceControl,
4746 mWinAnimator.mSurfaceController.mSurfaceControl.getHandle(),
chaviwbe43ac82018-04-04 15:14:49 -07004747 getFrameNumber());
Robert Carrc6d5af52018-02-26 17:46:00 -08004748 }
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004749 }
4750 }
4751
4752 private void transformFrameToSurfacePosition(int left, int top, Point outPoint) {
4753 outPoint.set(left, top);
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004754
4755 // If changed, also adjust getTransformationMatrix
chaviwe07246a2017-12-12 16:18:29 -08004756 final WindowContainer parentWindowContainer = getParent();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004757 if (isChildWindow()) {
4758 // TODO: This probably falls apart at some point and we should
4759 // actually compute relative coordinates.
Jorim Jaggi50d3f8f2017-12-27 17:41:25 +01004760
4761 // Since the parent was outset by its surface insets, we need to undo the outsetting
4762 // with insetting by the same amount.
Jorim Jaggia5e10572017-11-15 14:36:26 +01004763 final WindowState parent = getParentWindow();
Jorim Jaggi50d3f8f2017-12-27 17:41:25 +01004764 outPoint.offset(-parent.mFrame.left + parent.mAttrs.surfaceInsets.left,
4765 -parent.mFrame.top + parent.mAttrs.surfaceInsets.top);
chaviwe07246a2017-12-12 16:18:29 -08004766 } else if (parentWindowContainer != null) {
4767 final Rect parentBounds = parentWindowContainer.getBounds();
4768 outPoint.offset(-parentBounds.left, -parentBounds.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004769 }
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004770
Robert Carr32bcb102018-01-29 15:03:23 -08004771 TaskStack stack = getStack();
4772
4773 // If we have stack outsets, that means the top-left
4774 // will be outset, and we need to inset ourselves
4775 // to account for it. If we actually have shadows we will
4776 // then un-inset ourselves by the surfaceInsets.
4777 if (stack != null) {
4778 final int outset = stack.getStackOutset();
4779 outPoint.offset(outset, outset);
4780 }
4781
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004782 // Expand for surface insets. See WindowState.expandForSurfaceInsets.
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004783 outPoint.offset(-mAttrs.surfaceInsets.left, -mAttrs.surfaceInsets.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004784 }
4785
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004786 boolean needsRelativeLayeringToIme() {
4787 // We only use the relative layering mode in split screen, as part of elevating the IME
4788 // and windows above it's target above the docked divider.
4789 if (!inSplitScreenWindowingMode()) {
4790 return false;
4791 }
4792
4793 if (isChildWindow()) {
4794 // If we are a child of the input method target we need this promotion.
4795 if (getParentWindow().isInputMethodTarget()) {
4796 return true;
4797 }
4798 } else if (mAppToken != null) {
4799 // Likewise if we share a token with the Input method target and are ordered
4800 // above it but not necessarily a child (e.g. a Dialog) then we also need
4801 // this promotion.
4802 final WindowState imeTarget = mService.mInputMethodTarget;
4803 boolean inTokenWithAndAboveImeTarget = imeTarget != null && imeTarget != this
4804 && imeTarget.mToken == mToken && imeTarget.compareTo(this) <= 0;
4805 return inTokenWithAndAboveImeTarget;
4806 }
4807 return false;
4808 }
4809
Jorim Jaggia5e10572017-11-15 14:36:26 +01004810 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004811 void assignLayer(Transaction t, int layer) {
4812 // See comment in assignRelativeLayerForImeTargetChild
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004813 if (needsRelativeLayeringToIme()) {
4814 getDisplayContent().assignRelativeLayerForImeTargetChild(t, this);
Robert Carrb1579c82017-09-05 14:54:47 -07004815 return;
4816 }
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004817 super.assignLayer(t, layer);
Robert Carrb1579c82017-09-05 14:54:47 -07004818 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07004819
4820 @Override
4821 public boolean isDimming() {
4822 return mIsDimming;
4823 }
Robert Carr0eff1872017-12-01 14:27:04 -08004824
4825 // TODO(b/70040778): We should aim to eliminate the last user of TYPE_APPLICATION_MEDIA
4826 // then we can drop all negative layering on the windowing side and simply inherit
4827 // the default implementation here.
4828 public void assignChildLayers(Transaction t) {
4829 int layer = 1;
4830 for (int i = 0; i < mChildren.size(); i++) {
4831 final WindowState w = mChildren.get(i);
4832
4833 // APPLICATION_MEDIA_OVERLAY needs to go above APPLICATION_MEDIA
4834 // while they both need to go below the main window. However the
4835 // relative layering of multiple APPLICATION_MEDIA/OVERLAY has never
4836 // been defined and so we can use static layers and leave it that way.
4837 if (w.mAttrs.type == TYPE_APPLICATION_MEDIA) {
4838 w.assignLayer(t, -2);
4839 } else if (w.mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) {
4840 w.assignLayer(t, -1);
4841 } else {
4842 w.assignLayer(t, layer);
4843 }
4844 w.assignChildLayers(t);
4845 layer++;
4846 }
4847 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01004848
Andrii Kulian4b6599e2018-01-15 17:24:08 -08004849 /**
4850 * Update a tap exclude region with a rectangular area identified by provided id. The requested
4851 * area will be clipped to the window bounds.
4852 */
4853 void updateTapExcludeRegion(int regionId, int left, int top, int width, int height) {
4854 final DisplayContent currentDisplay = getDisplayContent();
4855 if (currentDisplay == null) {
4856 throw new IllegalStateException("Trying to update window not attached to any display.");
4857 }
4858
4859 if (mTapExcludeRegionHolder == null) {
4860 mTapExcludeRegionHolder = new TapExcludeRegionHolder();
4861
4862 // Make sure that this window is registered as one that provides a tap exclude region
4863 // for its containing display.
4864 currentDisplay.mTapExcludeProvidingWindows.add(this);
4865 }
4866
4867 mTapExcludeRegionHolder.updateRegion(regionId, left, top, width, height);
4868 // Trigger touch exclude region update on current display.
4869 final boolean isAppFocusedOnDisplay = mService.mFocusedApp != null
4870 && mService.mFocusedApp.getDisplayContent() == currentDisplay;
4871 currentDisplay.setTouchExcludeRegion(isAppFocusedOnDisplay ? mService.mFocusedApp.getTask()
4872 : null);
4873 }
4874
4875 /** Union the region with current tap exclude region that this window provides. */
4876 void amendTapExcludeRegion(Region region) {
4877 mTapExcludeRegionHolder.amendRegion(region, getBounds());
4878 }
4879
Robert Carr825581a2018-03-30 14:00:53 -07004880 @Override
4881 public boolean isInputMethodTarget() {
4882 return mService.mInputMethodTarget == this;
4883 }
4884
chaviwbe43ac82018-04-04 15:14:49 -07004885 long getFrameNumber() {
4886 return mFrameNumber;
4887 }
4888
4889 void setFrameNumber(long frameNumber) {
4890 mFrameNumber = frameNumber;
4891 }
4892
Adrian Roos41f7e9d2018-06-07 15:29:34 +02004893 @Override
4894 void seamlesslyRotate(Transaction t, int oldRotation, int newRotation) {
Adrian Roos28c25e22018-05-31 18:07:28 +02004895 // Invisible windows, the wallpaper, and force seamlessly rotated windows do not participate
4896 // in the regular seamless rotation animation.
4897 if (!isVisibleNow() || mIsWallpaper || mForceSeamlesslyRotate) {
Adrian Roos41f7e9d2018-06-07 15:29:34 +02004898 return;
4899 }
4900 final Matrix transform = mTmpMatrix;
4901
4902 mService.markForSeamlessRotation(this, true);
4903
4904 // We rotated the screen, but have not performed a new layout pass yet. In the mean time,
4905 // we recompute the coordinates of mFrame in the new orientation, so the surface can be
4906 // properly placed.
4907 transformToRotation(oldRotation, newRotation, getDisplayInfo(), transform);
4908 transformRect(transform, mFrame, null /* tmpRectF */);
4909
4910 updateSurfacePosition(t);
4911 mWinAnimator.seamlesslyRotate(t, oldRotation, newRotation);
4912
4913 // Dispatch to children only after mFrame has been updated, as it's needed in the
4914 // child's updateSurfacePosition.
4915 super.seamlesslyRotate(t, oldRotation, newRotation);
4916 }
4917
Jorim Jaggia5e10572017-11-15 14:36:26 +01004918 private final class MoveAnimationSpec implements AnimationSpec {
4919
4920 private final long mDuration;
4921 private Interpolator mInterpolator;
4922 private Point mFrom = new Point();
4923 private Point mTo = new Point();
4924
4925 private MoveAnimationSpec(int fromX, int fromY, int toX, int toY) {
4926 final Animation anim = AnimationUtils.loadAnimation(mContext,
4927 com.android.internal.R.anim.window_move_from_decor);
Jorim Jaggi08f75cf2018-01-08 14:38:53 +01004928 mDuration = (long)
4929 (anim.computeDurationHint() * mService.getWindowAnimationScaleLocked());
Jorim Jaggia5e10572017-11-15 14:36:26 +01004930 mInterpolator = anim.getInterpolator();
4931 mFrom.set(fromX, fromY);
4932 mTo.set(toX, toY);
4933 }
4934
4935 @Override
4936 public long getDuration() {
4937 return mDuration;
4938 }
4939
4940 @Override
4941 public void apply(Transaction t, SurfaceControl leash, long currentPlayTime) {
4942 final float fraction = (float) currentPlayTime / getDuration();
4943 final float v = mInterpolator.getInterpolation(fraction);
4944 t.setPosition(leash, mFrom.x + (mTo.x - mFrom.x) * v,
4945 mFrom.y + (mTo.y - mFrom.y) * v);
4946 }
Jorim Jaggif75d1612018-02-27 15:05:21 +01004947
4948 @Override
4949 public void dump(PrintWriter pw, String prefix) {
4950 pw.print(prefix); pw.print("from="); pw.print(mFrom);
4951 pw.print(" to="); pw.print(mTo);
4952 pw.print(" duration="); pw.println(mDuration);
4953 }
4954
4955 @Override
4956 public void writeToProtoInner(ProtoOutputStream proto) {
4957 final long token = proto.start(MOVE);
4958 mFrom.writeToProto(proto, FROM);
4959 mTo.writeToProto(proto, TO);
Kweku Adams21b8d262018-03-30 12:19:58 -07004960 proto.write(DURATION_MS, mDuration);
Jorim Jaggif75d1612018-02-27 15:05:21 +01004961 proto.end(token);
4962 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01004963 }
satokcef37fb2011-10-24 21:49:38 +09004964}