blob: 087bd6a80c73d4cef4a53f5b9b730ed11eadbf55 [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;
Tiger Huangdf87af82018-05-25 22:57:52 +080088import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
Jorim Jaggi02886a82016-12-06 09:10:06 -080089import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
90import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
91import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
92import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020093import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Jorim Jaggi02886a82016-12-06 09:10:06 -080094import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080095import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
96import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
97import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
98import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
Jorim Jaggia5e10572017-11-15 14:36:26 +010099import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800100import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
101import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
102import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
103import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
104import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
105import static com.android.server.wm.WindowManagerService.localLOGV;
106import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING;
107import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
108import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN;
109import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700110import static com.android.server.wm.IdentifierProto.HASH_CODE;
111import static com.android.server.wm.IdentifierProto.TITLE;
112import static com.android.server.wm.IdentifierProto.USER_ID;
113import static com.android.server.wm.AnimationSpecProto.MOVE;
Kweku Adams21b8d262018-03-30 12:19:58 -0700114import static com.android.server.wm.MoveAnimationSpecProto.DURATION_MS;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700115import static com.android.server.wm.MoveAnimationSpecProto.FROM;
116import static com.android.server.wm.MoveAnimationSpecProto.TO;
117import static com.android.server.wm.WindowStateProto.ANIMATING_EXIT;
118import static com.android.server.wm.WindowStateProto.ANIMATOR;
119import static com.android.server.wm.WindowStateProto.ATTRIBUTES;
120import static com.android.server.wm.WindowStateProto.CHILD_WINDOWS;
121import static com.android.server.wm.WindowStateProto.CONTAINING_FRAME;
122import static com.android.server.wm.WindowStateProto.CONTENT_FRAME;
123import static com.android.server.wm.WindowStateProto.CONTENT_INSETS;
124import static com.android.server.wm.WindowStateProto.CUTOUT;
125import static com.android.server.wm.WindowStateProto.DECOR_FRAME;
126import static com.android.server.wm.WindowStateProto.DESTROYING;
127import static com.android.server.wm.WindowStateProto.DISPLAY_FRAME;
128import static com.android.server.wm.WindowStateProto.DISPLAY_ID;
Adrian Roos2cadc5c2018-07-06 02:39:54 -0700129import static com.android.server.wm.WindowStateProto.FINISHED_FORCED_SEAMLESS_ROTATION_FRAME;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700130import static com.android.server.wm.WindowStateProto.FRAME;
131import static com.android.server.wm.WindowStateProto.GIVEN_CONTENT_INSETS;
132import static com.android.server.wm.WindowStateProto.HAS_SURFACE;
133import static com.android.server.wm.WindowStateProto.IDENTIFIER;
134import static com.android.server.wm.WindowStateProto.IS_ON_SCREEN;
135import static com.android.server.wm.WindowStateProto.IS_READY_FOR_DISPLAY;
136import static com.android.server.wm.WindowStateProto.IS_VISIBLE;
137import static com.android.server.wm.WindowStateProto.OUTSETS;
138import static com.android.server.wm.WindowStateProto.OUTSET_FRAME;
139import static com.android.server.wm.WindowStateProto.OVERSCAN_FRAME;
140import static com.android.server.wm.WindowStateProto.OVERSCAN_INSETS;
141import static com.android.server.wm.WindowStateProto.PARENT_FRAME;
Adrian Roos2cadc5c2018-07-06 02:39:54 -0700142import static com.android.server.wm.WindowStateProto.PENDING_FORCED_SEAMLESS_ROTATION;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700143import static com.android.server.wm.WindowStateProto.REMOVED;
144import static com.android.server.wm.WindowStateProto.REMOVE_ON_EXIT;
145import static com.android.server.wm.WindowStateProto.REQUESTED_HEIGHT;
146import static com.android.server.wm.WindowStateProto.REQUESTED_WIDTH;
147import static com.android.server.wm.WindowStateProto.STABLE_INSETS;
148import static com.android.server.wm.WindowStateProto.STACK_ID;
149import static com.android.server.wm.WindowStateProto.SURFACE_INSETS;
150import static com.android.server.wm.WindowStateProto.SURFACE_POSITION;
151import static com.android.server.wm.WindowStateProto.SYSTEM_UI_VISIBILITY;
152import static com.android.server.wm.WindowStateProto.VIEW_VISIBILITY;
153import static com.android.server.wm.WindowStateProto.VISIBLE_FRAME;
154import static com.android.server.wm.WindowStateProto.VISIBLE_INSETS;
155import static com.android.server.wm.WindowStateProto.WINDOW_CONTAINER;
Adrian Roos41f7e9d2018-06-07 15:29:34 +0200156import static com.android.server.wm.utils.CoordinateTransforms.transformRect;
157import static com.android.server.wm.utils.CoordinateTransforms.transformToRotation;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800158
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700159import android.annotation.CallSuper;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800160import android.app.AppOpsManager;
161import android.content.Context;
162import android.content.res.Configuration;
163import android.graphics.Matrix;
164import android.graphics.PixelFormat;
165import android.graphics.Point;
166import android.graphics.Rect;
167import android.graphics.Region;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700168import android.os.Binder;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700169import android.os.Debug;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800170import android.os.IBinder;
171import android.os.PowerManager;
172import android.os.RemoteCallbackList;
173import android.os.RemoteException;
174import android.os.SystemClock;
175import android.os.Trace;
176import android.os.UserHandle;
177import android.os.WorkSource;
chaviw40234662018-02-07 09:37:16 -0800178import android.provider.Settings;
Phil Weaverbb2f28a2017-12-22 09:44:28 -0800179import android.text.TextUtils;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800180import android.util.DisplayMetrics;
Jorim Jaggie7d2b852017-08-28 17:55:15 +0200181import android.util.MergedConfiguration;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800182import android.util.Slog;
183import android.util.TimeUtils;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700184import android.util.proto.ProtoOutputStream;
Brad Stenningaf596412018-04-02 12:03:19 -0700185import android.view.Display;
Adrian Roos5c6b6222017-11-07 17:36:10 +0100186import android.view.DisplayCutout;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800187import android.view.DisplayInfo;
188import android.view.Gravity;
189import android.view.IApplicationToken;
190import android.view.IWindow;
191import android.view.IWindowFocusObserver;
192import android.view.IWindowId;
193import android.view.InputChannel;
194import android.view.InputEvent;
195import android.view.InputEventReceiver;
Robert Carrb1579c82017-09-05 14:54:47 -0700196import android.view.SurfaceControl;
197import android.view.SurfaceSession;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800198import android.view.View;
199import android.view.ViewTreeObserver;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700200import android.view.WindowInfo;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800201import android.view.WindowManager;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100202import android.view.animation.Animation;
203import android.view.animation.AnimationUtils;
204import android.view.animation.Interpolator;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800205
Jorim Jaggi4876b4a2018-01-11 15:43:49 +0100206import com.android.internal.annotations.VisibleForTesting;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800207import com.android.internal.util.ToBooleanFunction;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800208import com.android.server.input.InputWindowHandle;
Adrian Roose99bc052017-11-20 17:55:31 +0100209import com.android.server.policy.WindowManagerPolicy;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100210import com.android.server.wm.LocalAnimationAdapter.AnimationSpec;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100211import com.android.server.wm.utils.WmDisplayCutout;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800212
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800213import java.io.PrintWriter;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200214import java.lang.ref.WeakReference;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800215import java.util.ArrayList;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700216import java.util.Comparator;
Wale Ogunwaled1880962016-11-08 10:31:59 -0800217import java.util.function.Predicate;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800218
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700219/** A window in the window manager. */
220class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800221 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800222
Skuhne81c524a2015-08-12 13:34:14 -0700223 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700224 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
225 // use hard-coded min sizes for now.
226 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
227 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700228
229 // The thickness of a window resize handle outside the window bounds on the free form workspace
230 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700231 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700232
Craig Mautnere7ae2502012-03-26 17:11:19 -0700233 final WindowManagerPolicy mPolicy;
234 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800235 final Session mSession;
236 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800237 final int mAppOp;
238 // UserId and appId of the owner. Don't display windows of non-current user.
239 final int mOwnerUid;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800240 /** The owner has {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} */
241 final boolean mOwnerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200242 final WindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800243 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700244 // The same object as mToken if this is an app window and null for non-app windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800245 AppWindowToken mAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700246
247 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
248 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800249 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
250 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700251 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800252 final int mBaseLayer;
253 final int mSubLayer;
254 final boolean mLayoutAttached;
255 final boolean mIsImWindow;
256 final boolean mIsWallpaper;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700257 private final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700258 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700259 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800260 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700261 int mSystemUiVisibility;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700262 /**
263 * The visibility of the window based on policy like {@link WindowManagerPolicy}.
264 * Normally set by calling {@link #showLw} and {@link #hideLw}.
265 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800266 boolean mPolicyVisibility = true;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700267 /**
268 * What {@link #mPolicyVisibility} should be set to after a transition animation.
269 * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and
270 * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit
271 * animation is done.
272 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800273 boolean mPolicyVisibilityAfterAnim = true;
Suprabh Shukla69c71422018-04-02 18:39:01 -0700274 // overlay window is hidden because the owning app is suspended
275 private boolean mHiddenWhileSuspended;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700276 private boolean mAppOpVisibility = true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700277 boolean mPermanentlyHidden; // the window should never be shown again
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700278 // This is a non-system overlay window that is currently force hidden.
279 private boolean mForceHideNonSystemOverlayWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800280 boolean mAppFreezing;
chaviwebcbc342018-02-07 13:19:00 -0800281 boolean mHidden = true; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800282 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700283 private boolean mDragResizing;
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200284 private boolean mDragResizingChangeReported = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700285 private int mResizeMode;
Adrian Roos28c25e22018-05-31 18:07:28 +0200286 /**
287 * Special mode that is intended only for the rounded corner overlay: during rotation
288 * transition, we un-rotate the window token such that the window appears as it did before the
289 * rotation.
290 */
291 final boolean mForceSeamlesslyRotate;
292 ForcedSeamlessRotator mPendingForcedSeamlessRotate;
Adrian Roos2cadc5c2018-07-06 02:39:54 -0700293 long mFinishForcedSeamlessRotateFrameNumber;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700294
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700295 private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800296
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700297 /**
298 * The window size that was requested by the application. These are in
299 * the application's coordinate space (without compatibility scale applied).
300 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800301 int mRequestedWidth;
302 int mRequestedHeight;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700303 private int mLastRequestedWidth;
304 private int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700305
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800306 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800307 boolean mHaveFrame;
308 boolean mObscured;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800309
310 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700311
Andrii Kulian9d91ca62016-09-29 22:28:09 -0700312 /**
313 * Used to store last reported to client configuration and check if we have newer available.
314 * We'll send configuration to client only if it is different from the last applied one and
315 * client won't perform unnecessary updates.
316 */
Bryce Lee2b17afd2017-09-21 10:38:20 -0700317 private final MergedConfiguration mLastReportedConfiguration = new MergedConfiguration();
Craig Mautnera2c77052012-03-26 12:14:43 -0700318
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700319 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700320 * Insets that determine the actually visible area. These are in the application's
321 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800322 */
323 final Rect mVisibleInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700324 private final Rect mLastVisibleInsets = new Rect();
325 private boolean mVisibleInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800326
327 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700328 * Insets that are covered by system windows (such as the status bar) and
329 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700330 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800331 */
332 final Rect mContentInsets = new Rect();
333 final Rect mLastContentInsets = new Rect();
Robert Carr18f622f2017-05-08 11:20:43 -0700334
335 /**
336 * The last content insets returned to the client in relayout. We use
337 * these in the bounds animation to ensure we only observe inset changes
338 * at the same time that a client resizes it's surface so that we may use
339 * the geometryAppliesWithResize synchronization mechanism to keep
340 * the contents in place.
341 */
342 final Rect mLastRelayoutContentInsets = new Rect();
343
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700344 private boolean mContentInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800345
346 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800347 * Insets that determine the area covered by the display overscan region. These are in the
348 * application's coordinate space (without compatibility scale applied).
349 */
350 final Rect mOverscanInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700351 private final Rect mLastOverscanInsets = new Rect();
352 private boolean mOverscanInsetsChanged;
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800353
354 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700355 * Insets that determine the area covered by the stable system windows. These are in the
356 * application's coordinate space (without compatibility scale applied).
357 */
358 final Rect mStableInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700359 private final Rect mLastStableInsets = new Rect();
360 private boolean mStableInsetsChanged;
Adrian Roosfa104232014-06-20 16:10:14 -0700361
362 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700363 * Outsets determine the area outside of the surface where we want to pretend that it's possible
364 * to draw anyway.
365 */
366 final Rect mOutsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700367 private final Rect mLastOutsets = new Rect();
368 private boolean mOutsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700369
Adrian Roos5c6b6222017-11-07 17:36:10 +0100370 /** Part of the display that has been cut away. See {@link DisplayCutout}. */
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100371 WmDisplayCutout mDisplayCutout = WmDisplayCutout.NO_CUTOUT;
372 private WmDisplayCutout mLastDisplayCutout = WmDisplayCutout.NO_CUTOUT;
Adrian Roos5c6b6222017-11-07 17:36:10 +0100373 private boolean mDisplayCutoutChanged;
374
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700375 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800376 * Set to true if we are waiting for this window to receive its
377 * given internal insets before laying out other windows based on it.
378 */
379 boolean mGivenInsetsPending;
380
381 /**
382 * These are the content insets that were given during layout for
383 * this window, to be applied to windows behind it.
384 */
385 final Rect mGivenContentInsets = new Rect();
386
387 /**
388 * These are the visible insets that were given during layout for
389 * this window, to be applied to windows behind it.
390 */
391 final Rect mGivenVisibleInsets = new Rect();
392
393 /**
394 * This is the given touchable area relative to the window frame, or null if none.
395 */
396 final Region mGivenTouchableRegion = new Region();
397
398 /**
399 * Flag indicating whether the touchable region should be adjusted by
400 * the visible insets; if false the area outside the visible insets is
401 * NOT touchable, so we must use those to adjust the frame during hit
402 * tests.
403 */
404 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
405
406 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400407 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700408 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800409 float mHScale=1, mVScale=1;
410 float mLastHScale=1, mLastVScale=1;
411 final Matrix mTmpMatrix = new Matrix();
412
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700413 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800414 final Rect mFrame = new Rect();
415 final Rect mLastFrame = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700416 private boolean mFrameSizeChanged = false;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700417 // Frame that is scaled to the application's coordinate space when in
418 // screen size compatibility mode.
419 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800420
421 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700422
Adrian Roos604ef952018-05-15 20:13:13 +0200423 final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700424
Adrian Roos5ed644f2018-03-19 17:01:05 +0100425 /** Whether the parent frame would have been different if there was no display cutout. */
426 private boolean mParentFrameWasClippedByDisplayCutout;
427
Wale Ogunwale94596652015-02-06 19:27:34 -0800428 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
429 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700430 final Rect mDisplayFrame = new Rect();
431
432 // The region of the display frame that the display type supports displaying content on. This
433 // is mostly a special case for TV where some displays don’t have the entire display usable.
434 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
435 // window display contents to extend into the overscan region.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700436 private final Rect mOverscanFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700437
438 // The display frame minus the stable insets. This value is always constant regardless of if
439 // the status bar or navigation bar is visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700440 private final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800441
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700442 // The area not occupied by the status and navigation bars. So, if both status and navigation
443 // bars are visible, the decor frame is equal to the stable frame.
444 final Rect mDecorFrame = new Rect();
445
446 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
447 // minus the area occupied by the IME if the IME is present.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700448 private final Rect mContentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700449
450 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
451 // displays hint text.
452 final Rect mVisibleFrame = new Rect();
453
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700454 // Frame that includes dead area outside of the surface but where we want to pretend that it's
455 // possible to draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700456 private final Rect mOutsetFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700457
Jorim Jaggidc249c42015-12-15 14:57:31 -0800458 /**
459 * Usually empty. Set to the task's tempInsetFrame. See
460 *{@link android.app.IActivityManager#resizeDockedStack}.
461 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700462 private final Rect mInsetFrame = new Rect();
Jorim Jaggidc249c42015-12-15 14:57:31 -0800463
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800464 boolean mContentChanged;
465
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800466 // If a window showing a wallpaper: the requested offset for the
467 // wallpaper; if a wallpaper window: the currently applied offset.
468 float mWallpaperX = -1;
469 float mWallpaperY = -1;
470
471 // If a window showing a wallpaper: what fraction of the offset
472 // range corresponds to a full virtual screen.
473 float mWallpaperXStep = -1;
474 float mWallpaperYStep = -1;
475
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700476 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
477 // to its window; if a wallpaper window: not used.
478 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
479 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
480
Craig Mautner2268e7e2012-12-13 15:40:00 -0800481 /**
482 * This is set after IWindowSession.relayout() has been called at
483 * least once for the window. It allows us to detect the situation
484 * where we don't yet have a surface, but should have one soon, so
485 * we can give the window focus before waiting for the relayout.
486 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800487 boolean mRelayoutCalled;
488
Robert Carrfed10072016-05-26 11:48:49 -0700489 boolean mInRelayout;
490
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800491 /**
492 * If the application has called relayout() with changes that can
493 * impact its window's size, we need to perform a layout pass on it
494 * even if it is not currently visible for layout. This is set
495 * when in that case until the layout is done.
496 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800497 boolean mLayoutNeeded;
498
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800499 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800500 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800501
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800502 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800503 boolean mDestroying;
504
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800505 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800506 boolean mRemoveOnExit;
507
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800508 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800509 * Whether the app died while it was visible, if true we might need
510 * to continue to show it until it's restarted.
511 */
512 boolean mAppDied;
513
514 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800515 * Set when the orientation is changing and this window has not yet
516 * been updated for the new orientation.
517 */
Bryce Lee8c3cf382017-07-06 19:47:10 -0700518 private boolean mOrientationChanging;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800519
Dianne Hackborna57c6952013-03-29 14:46:40 -0700520 /**
Robert Carr9c1c3a02017-08-08 12:59:01 -0700521 * Sometimes in addition to the mOrientationChanging
522 * flag we report that the orientation is changing
523 * due to a mismatch in current and reported configuration.
524 *
525 * In the case of timeout we still need to make sure we
526 * leave the orientation changing state though, so we
527 * use this as a special time out escape hatch.
528 */
529 private boolean mOrientationChangeTimedOut;
530
531 /**
Robert Carr237028a2016-07-26 10:39:45 -0700532 * The orientation during the last visible call to relayout. If our
533 * current orientation is different, the window can't be ready
534 * to be shown.
535 */
536 int mLastVisibleLayoutRotation = -1;
537
538 /**
Andrii Kulianb2e37802017-01-11 00:36:44 -0800539 * Set when we need to report the orientation change to client to trigger a relayout.
540 */
541 boolean mReportOrientationChanged;
542
543 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700544 * How long we last kept the screen frozen.
545 */
546 int mLastFreezeDuration;
547
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800548 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800549 boolean mRemoved;
550
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800551 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800552 * It is save to remove the window and destroy the surface because the client requested removal
553 * or some other higher level component said so (e.g. activity manager).
554 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800555 */
Svetoslav Ganov200adfb2016-10-18 13:29:27 -0700556 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800557
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800558 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700559 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800560 InputChannel mInputChannel;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700561 private InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800562
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800563 // Used to improve performance of toString()
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700564 private String mStringNameCache;
565 private CharSequence mLastTitle;
566 private boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800567
Craig Mautnera2c77052012-03-26 12:14:43 -0700568 final WindowStateAnimator mWinAnimator;
569
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700570 boolean mHasSurface = false;
571
Craig Mautner88400d32012-09-30 12:35:45 -0700572 /** When true this window can be displayed on screens owther than mOwnerUid's */
573 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700574
Chong Zhang92147042016-05-09 12:47:11 -0700575 // Whether the window was visible when we set the app to invisible last time. WM uses
576 // this as a hint to restore the surface (if available) for early animation next time
577 // the app is brought visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700578 private boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800579
Robert Carra1eb4392015-12-10 12:43:51 -0800580 // This window will be replaced due to relaunch. This allows window manager
581 // to differentiate between simple removal of a window and replacement. In the latter case it
582 // will preserve the old window until the new one is drawn.
583 boolean mWillReplaceWindow = false;
584 // If true, the replaced window was already requested to be removed.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700585 private boolean mReplacingRemoveRequested = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800586 // Whether the replacement of the window should trigger app transition animation.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700587 private boolean mAnimateReplacingWindow = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800588 // If not null, the window that will be used to replace the old one. This is being set when
589 // the window is added and unset when this window reports its first draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700590 private WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700591 // For the new window in the replacement transition, if we have
592 // requested to replace without animation, then we should
593 // make sure we also don't apply an enter animation for
594 // the new window.
595 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800596 // Whether this window is being moved via the resize API
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700597 private boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800598
Jeff Brownc2932a12014-11-20 18:04:05 -0800599 /**
600 * Wake lock for drawing.
601 * Even though it's slightly more expensive to do so, we will use a separate wake lock
602 * for each app that is requesting to draw while dozing so that we can accurately track
603 * who is preventing the system from suspending.
604 * This lock is only acquired on first use.
605 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700606 private PowerManager.WakeLock mDrawLock;
Jeff Brownc2932a12014-11-20 18:04:05 -0800607
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700608 final private Rect mTmpRect = new Rect();
609
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800610 /**
611 * Whether the window was resized by us while it was gone for layout.
612 */
613 boolean mResizedWhileGone = false;
614
Robert Carr6da3cc02016-06-16 15:17:07 -0700615 /**
616 * During seamless rotation we have two phases, first the old window contents
617 * are rotated to look as if they didn't move in the new coordinate system. Then we
618 * have to freeze updates to this layer (to preserve the transformation) until
619 * the resize actually occurs. This is true from when the transformation is set
620 * and false until the transaction to resize is sent.
621 */
622 boolean mSeamlesslyRotated = false;
623
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700624 /**
Robert Carrc91d1c32017-02-15 19:37:46 -0800625 * Surface insets from the previous call to relayout(), used to track
626 * if we are changing the Surface insets.
627 */
628 final Rect mLastSurfaceInsets = new Rect();
629
630 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700631 * A flag set by the {@link WindowState} parent to indicate that the parent has examined this
632 * {@link WindowState} in its overall drawing context. This book-keeping allows the parent to
633 * make sure all children have been considered.
634 */
635 private boolean mDrawnStateEvaluated;
636
Jorim Jaggia5e10572017-11-15 14:36:26 +0100637 private final Point mSurfacePosition = new Point();
638
Bryce Leed390deb2017-06-22 13:14:28 -0700639 /**
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800640 * A region inside of this window to be excluded from touch-related focus switches.
641 */
642 private TapExcludeRegionHolder mTapExcludeRegionHolder;
643
644 /**
chaviw40234662018-02-07 09:37:16 -0800645 * Used for testing because the real PowerManager is final.
646 */
647 private PowerManagerWrapper mPowerManagerWrapper;
648
649 /**
chaviwbe43ac82018-04-04 15:14:49 -0700650 * A frame number in which changes requested in this layout will be rendered.
651 */
652 private long mFrameNumber = -1;
653
654 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700655 * 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 -0700656 * of z-order and 1 otherwise.
657 */
Griff Hazen51d00d82016-11-22 15:39:24 -0800658 private static final Comparator<WindowState> sWindowSubLayerComparator =
659 new Comparator<WindowState>() {
660 @Override
661 public int compare(WindowState w1, WindowState w2) {
662 final int layer1 = w1.mSubLayer;
663 final int layer2 = w2.mSubLayer;
664 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
665 // We insert the child window into the list ordered by
666 // the sub-layer. For same sub-layers, the negative one
667 // should go below others; the positive one should go
668 // above others.
669 return -1;
670 }
671 return 1;
672 };
673 };
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700674
Robert Carrf59b8dd2017-10-02 18:58:36 -0700675 /**
676 * Indicates whether we have requested a Dim (in the sense of {@link Dimmer}) from our host
677 * container.
678 */
679 private boolean mIsDimming = false;
680
681 private static final float DEFAULT_DIM_AMOUNT_DEAD_WINDOW = 0.5f;
682
Adrian Roos28c25e22018-05-31 18:07:28 +0200683 void forceSeamlesslyRotateIfAllowed(int oldRotation, int rotation) {
684 if (mForceSeamlesslyRotate) {
Adrian Roos73ab97c2018-08-02 15:56:15 +0200685 if (mPendingForcedSeamlessRotate != null) {
686 oldRotation = mPendingForcedSeamlessRotate.getOldRotation();
687 }
688
Adrian Roos28c25e22018-05-31 18:07:28 +0200689 mPendingForcedSeamlessRotate = new ForcedSeamlessRotator(
690 oldRotation, rotation, getDisplayInfo());
691 mPendingForcedSeamlessRotate.unrotate(this.mToken);
692 }
693 }
694
chaviw40234662018-02-07 09:37:16 -0800695 interface PowerManagerWrapper {
696 void wakeUp(long time, String reason);
697
698 boolean isInteractive();
699
700 }
701
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800702 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
chaviw40234662018-02-07 09:37:16 -0800703 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
704 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow) {
705 this(service, s, c, token, parentWindow, appOp, seq, a, viewVisibility, ownerId,
706 ownerCanAddInternalSystemWindow, new PowerManagerWrapper() {
707 @Override
708 public void wakeUp(long time, String reason) {
709 service.mPowerManager.wakeUp(time, reason);
710 }
711
712 @Override
713 public boolean isInteractive() {
714 return service.mPowerManager.isInteractive();
715 }
716 });
717 }
718
719 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
720 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
721 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow,
722 PowerManagerWrapper powerManagerWrapper) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100723 super(service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800724 mSession = s;
725 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800726 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800727 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700728 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700729 mOwnerUid = ownerId;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800730 mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200731 mWindowId = new WindowId(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800732 mAttrs.copyFrom(a);
Robert Carrb08ed042018-03-12 15:49:08 -0700733 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800734 mViewVisibility = viewVisibility;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700735 mPolicy = mService.mPolicy;
736 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800737 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700738 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700739 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
chaviw40234662018-02-07 09:37:16 -0800740 mPowerManagerWrapper = powerManagerWrapper;
Adrian Roos28c25e22018-05-31 18:07:28 +0200741 mForceSeamlesslyRotate = token.mRoundedCornerOverlay;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700742 if (localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700743 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700744 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800745 try {
746 c.asBinder().linkToDeath(deathRecipient, 0);
747 } catch (RemoteException e) {
748 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700749 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800750 mLayoutAttached = false;
751 mIsImWindow = false;
752 mIsWallpaper = false;
753 mIsFloatingLayer = false;
754 mBaseLayer = 0;
755 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700756 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700757 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800758 return;
759 }
760 mDeathRecipient = deathRecipient;
761
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700762 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800763 // The multiplier here is to reserve space for multiple
764 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800765 mBaseLayer = mPolicy.getWindowLayerLw(parentWindow)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700766 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800767 mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700768 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900769
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700770 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow);
771 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900772
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800773 mLayoutAttached = mAttrs.type !=
774 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700775 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
776 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
777 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800778 } else {
779 // The multiplier here is to reserve space for multiple
780 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800781 mBaseLayer = mPolicy.getWindowLayerLw(this)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700782 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800783 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700784 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800785 mLayoutAttached = false;
786 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
787 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
788 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800789 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700790 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800791
Wale Ogunwale72919d22016-12-08 18:58:50 -0800792 if (mAppToken != null && mAppToken.mShowForAllUsers) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700793 // Windows for apps that can show for all users should also show when the device is
794 // locked.
795 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
Craig Mautner19ab8282014-05-07 10:35:34 -0700796 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800797
Craig Mautner322e4032012-07-13 13:35:20 -0700798 mWinAnimator = new WindowStateAnimator(this);
799 mWinAnimator.mAlpha = a.alpha;
800
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800801 mRequestedWidth = 0;
802 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700803 mLastRequestedWidth = 0;
804 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800805 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800806 mInputWindowHandle = new InputWindowHandle(
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800807 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this, c,
808 getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800809 }
810
811 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700812 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800813 mSession.windowAddedLocked(mAttrs.packageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800814 }
815
Bryce Leed390deb2017-06-22 13:14:28 -0700816 /**
817 * Returns whether this {@link WindowState} has been considered for drawing by its parent.
818 */
Bryce Lee6311c4b2017-07-06 14:09:29 -0700819 boolean getDrawnStateEvaluated() {
Bryce Leed390deb2017-06-22 13:14:28 -0700820 return mDrawnStateEvaluated;
821 }
822
823 /**
824 * Sets whether this {@link WindowState} has been considered for drawing by its parent. Should
825 * be cleared when detached from parent.
826 */
827 void setDrawnStateEvaluated(boolean evaluated) {
828 mDrawnStateEvaluated = evaluated;
829 }
830
831 @Override
832 void onParentSet() {
833 super.onParentSet();
834 setDrawnStateEvaluated(false /*evaluated*/);
Robert Carr24be9ab2018-04-30 17:54:53 -0700835
836 getDisplayContent().reapplyMagnificationSpec();
Bryce Leed390deb2017-06-22 13:14:28 -0700837 }
838
Craig Mautnera2c77052012-03-26 12:14:43 -0700839 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800840 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800841 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800842 }
843
844 @Override
845 public String getOwningPackage() {
846 return mAttrs.packageName;
847 }
848
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800849 @Override
850 public boolean canAddInternalSystemWindow() {
851 return mOwnerCanAddInternalSystemWindow;
852 }
853
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200854 @Override
855 public boolean canAcquireSleepToken() {
856 return mSession.mCanAcquireSleepToken;
857 }
858
Jorim Jaggif5834272016-04-04 20:25:41 -0700859 /**
860 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
861 * from {@param frame}. In other words, it applies the insets that would result if
862 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700863 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
864 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700865 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700866 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
867 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
868 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
869 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
870 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700871 frame.inset(left, top, right, bottom);
872 }
873
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800874 @Override
Robert Carr43521762016-10-28 13:15:04 -0700875 public void computeFrameLw(Rect parentFrame, Rect displayFrame, Rect overscanFrame,
876 Rect contentFrame, Rect visibleFrame, Rect decorFrame, Rect stableFrame,
Adrian Roos5ed644f2018-03-19 17:01:05 +0100877 Rect outsetFrame, WmDisplayCutout displayCutout,
878 boolean parentFrameWasClippedByDisplayCutout) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800879 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700880 // This window is being replaced and either already got information that it's being
881 // removed or we are still waiting for some information. Because of this we don't
882 // want to apply any more changes to it, so it remains in this state until new window
883 // appears.
884 return;
885 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800886 mHaveFrame = true;
Adrian Roos5ed644f2018-03-19 17:01:05 +0100887 mParentFrameWasClippedByDisplayCutout = parentFrameWasClippedByDisplayCutout;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800888
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700889 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700890 final boolean inFullscreenContainer = inFullscreenContainer();
Robert Carre6275582016-02-29 15:45:45 -0800891 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700892 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800893
Chong Zhangae35fef2016-03-16 15:56:55 -0700894 // If the task has temp inset bounds set, we have to make sure all its windows uses
895 // the temp inset frame. Otherwise different display frames get applied to the main
896 // window and the child window, making them misaligned.
Adrian Roose76b2b52018-03-21 16:22:16 +0100897 // Otherwise we need to clear the inset frame, to avoid using a stale frame after leaving
898 // multi window mode.
899 if (task != null && isInMultiWindowMode()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700900 task.getTempInsetBounds(mInsetFrame);
Adrian Roose76b2b52018-03-21 16:22:16 +0100901 } else {
902 mInsetFrame.setEmpty();
Chong Zhangae35fef2016-03-16 15:56:55 -0700903 }
904
Jorim Jaggif5834272016-04-04 20:25:41 -0700905 // Denotes the actual frame used to calculate the insets and to perform the layout. When
906 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
907 // insets temporarily. By the notion of a task having a different layout frame, we can
908 // achieve that while still moving the task around.
909 final Rect layoutContainingFrame;
910 final Rect layoutDisplayFrame;
911
912 // The offset from the layout containing frame to the actual containing frame.
913 final int layoutXDiff;
914 final int layoutYDiff;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700915 if (inFullscreenContainer || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800916 // We use the parent frame as the containing frame for fullscreen and child windows
Robert Carr43521762016-10-28 13:15:04 -0700917 mContainingFrame.set(parentFrame);
918 mDisplayFrame.set(displayFrame);
919 layoutDisplayFrame = displayFrame;
920 layoutContainingFrame = parentFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700921 layoutXDiff = 0;
922 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800923 } else {
Bryce Leef3c6a472017-11-14 14:53:06 -0800924 getBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100925 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
926
927 // If the bounds are frozen, we still want to translate the window freely and only
928 // freeze the size.
929 Rect frozen = mAppToken.mFrozenBounds.peek();
930 mContainingFrame.right = mContainingFrame.left + frozen.width();
931 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
932 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800933 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700934 // IME is up and obscuring this window. Adjust the window position so it is visible.
Robert Carr825581a2018-03-30 14:00:53 -0700935 if (imeWin != null && imeWin.isVisibleNow() && isInputMethodTarget()) {
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700936 if (inFreeformWindowingMode()
Winson Chungd73e94b2017-05-31 16:25:30 -0700937 && mContainingFrame.bottom > contentFrame.bottom) {
938 // In freeform we want to move the top up directly.
939 // TODO: Investigate why this is contentFrame not parentFrame.
940 mContainingFrame.top -= mContainingFrame.bottom - contentFrame.bottom;
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700941 } else if (!inPinnedWindowingMode()
Winson Chungd73e94b2017-05-31 16:25:30 -0700942 && mContainingFrame.bottom > parentFrame.bottom) {
943 // But in docked we want to behave like fullscreen and behave as if the task
944 // were given smaller bounds for the purposes of layout. Skip adjustments for
945 // the pinned stack, they are handled separately in the PinnedStackController.
946 mContainingFrame.bottom = parentFrame.bottom;
947 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700948 }
Skuhne81c524a2015-08-12 13:34:14 -0700949
Robert Carre6275582016-02-29 15:45:45 -0800950 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700951 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
952 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800953 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700954 if (mContainingFrame.isEmpty()) {
Robert Carr43521762016-10-28 13:15:04 -0700955 mContainingFrame.set(contentFrame);
Skuhne81c524a2015-08-12 13:34:14 -0700956 }
Doris Liu06d582d2015-06-01 13:18:43 -0700957 }
Adrian Roos604ef952018-05-15 20:13:13 +0200958
959 final TaskStack stack = getStack();
960 if (inPinnedWindowingMode() && stack != null
961 && stack.lastAnimatingBoundsWasToFullscreen()) {
962 // PIP edge case: When going from pinned to fullscreen, we apply a
963 // tempInsetFrame for the full task - but we're still at the start of the animation.
964 // To prevent a jump if there's a letterbox, restrict to the parent frame.
965 mInsetFrame.intersectUnchecked(parentFrame);
966 mContainingFrame.intersectUnchecked(parentFrame);
967 }
968
Wale Ogunwale94596652015-02-06 19:27:34 -0800969 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700970 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
971 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
972 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700973 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
Robert Carr43521762016-10-28 13:15:04 -0700974 subtractInsets(mDisplayFrame, layoutContainingFrame, displayFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700975 if (!layoutInParentFrame()) {
Robert Carr43521762016-10-28 13:15:04 -0700976 subtractInsets(mContainingFrame, layoutContainingFrame, parentFrame, mTmpRect);
977 subtractInsets(mInsetFrame, layoutContainingFrame, parentFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700978 }
Robert Carr43521762016-10-28 13:15:04 -0700979 layoutDisplayFrame = displayFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700980 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700981 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800982
Craig Mautner967212c2013-04-13 21:10:58 -0700983 final int pw = mContainingFrame.width();
984 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800985
Robert Carr43521762016-10-28 13:15:04 -0700986 if (!mParentFrame.equals(parentFrame)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800987 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Robert Carr43521762016-10-28 13:15:04 -0700988 // + " to " + parentFrame);
989 mParentFrame.set(parentFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800990 mContentChanged = true;
991 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700992 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
993 mLastRequestedWidth = mRequestedWidth;
994 mLastRequestedHeight = mRequestedHeight;
995 mContentChanged = true;
996 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800997
Robert Carr43521762016-10-28 13:15:04 -0700998 mOverscanFrame.set(overscanFrame);
999 mContentFrame.set(contentFrame);
1000 mVisibleFrame.set(visibleFrame);
1001 mDecorFrame.set(decorFrame);
1002 mStableFrame.set(stableFrame);
1003 final boolean hasOutsets = outsetFrame != null;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001004 if (hasOutsets) {
Robert Carr43521762016-10-28 13:15:04 -07001005 mOutsetFrame.set(outsetFrame);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001006 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001007
Craig Mautnereda67292013-04-28 13:50:14 -07001008 final int fw = mFrame.width();
1009 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001010
Jorim Jaggif5834272016-04-04 20:25:41 -07001011 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
1012
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -07001013 // Calculate the outsets before the content frame gets shrinked to the window frame.
1014 if (hasOutsets) {
1015 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
1016 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
1017 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
1018 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
1019 } else {
1020 mOutsets.set(0, 0, 0, 0);
1021 }
1022
Craig Mautnera248eee2013-05-07 11:41:27 -07001023 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001024 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -08001025 if (windowsAreFloating && !mFrame.isEmpty()) {
Robert Carre65a1c42017-02-28 16:52:59 -08001026 // For pinned workspace the frame isn't limited in any particular
1027 // way since SystemUI controls the bounds. For freeform however
1028 // we want to keep things inside the content frame.
Wale Ogunwale44f036f2017-09-29 05:09:09 -07001029 final Rect limitFrame = task.inPinnedWindowingMode() ? mFrame : mContentFrame;
Skuhne81c524a2015-08-12 13:34:14 -07001030 // Keep the frame out of the blocked system area, limit it in size to the content area
1031 // and make sure that there is always a minimum visible so that the user can drag it
1032 // into a usable area..
Robert Carre65a1c42017-02-28 16:52:59 -08001033 final int height = Math.min(mFrame.height(), limitFrame.height());
1034 final int width = Math.min(limitFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -07001035 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +09001036 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
1037 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
1038 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
1039 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Robert Carre65a1c42017-02-28 16:52:59 -08001040 final int top = Math.max(limitFrame.top,
1041 Math.min(mFrame.top, limitFrame.bottom - minVisibleHeight));
1042 final int left = Math.max(limitFrame.left + minVisibleWidth - width,
1043 Math.min(mFrame.left, limitFrame.right - minVisibleWidth));
Skuhne81c524a2015-08-12 13:34:14 -07001044 mFrame.set(left, top, left + width, top + height);
1045 mContentFrame.set(mFrame);
1046 mVisibleFrame.set(mContentFrame);
1047 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -07001048 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001049 dc.getDockedDividerController().positionDockedStackedDivider(mFrame);
Jorim Jaggi192086e2016-03-11 17:17:03 +01001050 mContentFrame.set(mFrame);
1051 if (!mFrame.equals(mLastFrame)) {
1052 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -08001053 }
Skuhne81c524a2015-08-12 13:34:14 -07001054 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -07001055 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
1056 Math.max(mContentFrame.top, mFrame.top),
1057 Math.min(mContentFrame.right, mFrame.right),
1058 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001059
Jorim Jaggi656f6502016-04-11 21:08:17 -07001060 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
1061 Math.max(mVisibleFrame.top, mFrame.top),
1062 Math.min(mVisibleFrame.right, mFrame.right),
1063 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001064
Jorim Jaggi656f6502016-04-11 21:08:17 -07001065 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
1066 Math.max(mStableFrame.top, mFrame.top),
1067 Math.min(mStableFrame.right, mFrame.right),
1068 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -07001069 }
Adrian Roosfa104232014-06-20 16:10:14 -07001070
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07001071 if (inFullscreenContainer && !windowsAreFloating) {
Jorim Jaggi899327f2016-02-25 20:44:18 -05001072 // Windows that are not fullscreen can be positioned outside of the display frame,
1073 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -07001074 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
1075 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
1076 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
1077 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -08001078 }
Craig Mautnereda67292013-04-28 13:50:14 -07001079
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001080 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001081 // For the docked divider, we calculate the stable insets like a full-screen window
1082 // so it can use it to calculate the snap positions.
Adrian Roos7377f582018-03-20 16:56:22 +01001083 final WmDisplayCutout c = displayCutout.calculateRelativeTo(mDisplayFrame);
1084 mTmpRect.set(mDisplayFrame);
1085 mTmpRect.inset(c.getDisplayCutout().getSafeInsets());
1086 mTmpRect.intersectUnchecked(mStableFrame);
1087
1088 mStableInsets.set(Math.max(mTmpRect.left - mDisplayFrame.left, 0),
1089 Math.max(mTmpRect.top - mDisplayFrame.top, 0),
1090 Math.max(mDisplayFrame.right - mTmpRect.right, 0),
1091 Math.max(mDisplayFrame.bottom - mTmpRect.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -08001092
1093 // The divider doesn't care about insets in any case, so set it to empty so we don't
1094 // trigger a relayout when moving it.
1095 mContentInsets.setEmpty();
1096 mVisibleInsets.setEmpty();
Adrian Roos7377f582018-03-20 16:56:22 +01001097 displayCutout = WmDisplayCutout.NO_CUTOUT;
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001098 } else {
Bryce Leef3c6a472017-11-14 14:53:06 -08001099 getDisplayContent().getBounds(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -07001100 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
1101 // non-fullscreen mode.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07001102 boolean overrideRightInset = !windowsAreFloating && !inFullscreenContainer
1103 && mFrame.right > mTmpRect.right;
1104 boolean overrideBottomInset = !windowsAreFloating && !inFullscreenContainer
1105 && mFrame.bottom > mTmpRect.bottom;
Jorim Jaggi656f6502016-04-11 21:08:17 -07001106 mContentInsets.set(mContentFrame.left - mFrame.left,
1107 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -07001108 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -07001109 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -07001110 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -07001111 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -08001112
Jorim Jaggi656f6502016-04-11 21:08:17 -07001113 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
1114 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -07001115 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -07001116 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -07001117 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -07001118 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -08001119
Jorim Jaggi656f6502016-04-11 21:08:17 -07001120 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
1121 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -07001122 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -07001123 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -07001124 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -07001125 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001126 }
Adrian Roosfa104232014-06-20 16:10:14 -07001127
Jorim Jaggibae2b152018-04-18 17:27:27 +02001128 mDisplayCutout = displayCutout.calculateRelativeTo(mFrame);
1129
Jorim Jaggi656f6502016-04-11 21:08:17 -07001130 // Offset the actual frame by the amount layout frame is off.
1131 mFrame.offset(-layoutXDiff, -layoutYDiff);
1132 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -07001133 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
1134 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
1135 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
1136
Craig Mautnereda67292013-04-28 13:50:14 -07001137 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001138 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001139 // If there is a size compatibility scale being applied to the
1140 // window, we need to apply this to its insets so that they are
1141 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -07001142 mOverscanInsets.scale(mInvGlobalScale);
1143 mContentInsets.scale(mInvGlobalScale);
1144 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -07001145 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001146 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001147
1148 // Also the scaled frame that we report to the app needs to be
1149 // adjusted to be in its coordinate space.
1150 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001151 }
1152
Craig Mautnereda67292013-04-28 13:50:14 -07001153 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001154 final DisplayContent displayContent = getDisplayContent();
1155 if (displayContent != null) {
1156 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwale0303c572016-10-20 10:16:29 -07001157 getDisplayContent().mWallpaperController.updateWallpaperOffset(
Wale Ogunwalee8069dc2015-08-18 09:52:01 -07001158 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001159 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001160 }
1161
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001162 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001163 "Resolving (mRequestedWidth="
1164 + mRequestedWidth + ", mRequestedheight="
1165 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
1166 + "): frame=" + mFrame.toShortString()
1167 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07001168 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -07001169 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001170 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001171 }
1172
Bryce Leef3c6a472017-11-14 14:53:06 -08001173 // TODO: Look into whether this override is still necessary.
1174 @Override
1175 public Rect getBounds() {
1176 if (isInMultiWindowMode()) {
1177 return getTask().getBounds();
1178 } else if (mAppToken != null){
1179 return mAppToken.getBounds();
1180 } else {
1181 return super.getBounds();
1182 }
1183 }
1184
Craig Mautnera2c77052012-03-26 12:14:43 -07001185 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001186 public Rect getFrameLw() {
1187 return mFrame;
1188 }
1189
Craig Mautnera2c77052012-03-26 12:14:43 -07001190 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001191 public Rect getDisplayFrameLw() {
1192 return mDisplayFrame;
1193 }
1194
Craig Mautnera2c77052012-03-26 12:14:43 -07001195 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001196 public Rect getOverscanFrameLw() {
1197 return mOverscanFrame;
1198 }
1199
1200 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001201 public Rect getContentFrameLw() {
1202 return mContentFrame;
1203 }
1204
Craig Mautnera2c77052012-03-26 12:14:43 -07001205 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001206 public Rect getVisibleFrameLw() {
1207 return mVisibleFrame;
1208 }
1209
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001210 Rect getStableFrameLw() {
1211 return mStableFrame;
1212 }
1213
Craig Mautnera2c77052012-03-26 12:14:43 -07001214 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001215 public boolean getGivenInsetsPendingLw() {
1216 return mGivenInsetsPending;
1217 }
1218
Craig Mautnera2c77052012-03-26 12:14:43 -07001219 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001220 public Rect getGivenContentInsetsLw() {
1221 return mGivenContentInsets;
1222 }
1223
Craig Mautnera2c77052012-03-26 12:14:43 -07001224 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001225 public Rect getGivenVisibleInsetsLw() {
1226 return mGivenVisibleInsets;
1227 }
1228
Craig Mautnera2c77052012-03-26 12:14:43 -07001229 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001230 public WindowManager.LayoutParams getAttrs() {
1231 return mAttrs;
1232 }
1233
Craig Mautner812d2ca2012-09-27 15:35:34 -07001234 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001235 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001236 return getDisplayContent().getNeedsMenu(this, bottom);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001237 }
1238
Craig Mautner19d59bc2012-09-04 11:15:56 -07001239 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001240 public int getSystemUiVisibility() {
1241 return mSystemUiVisibility;
1242 }
1243
Craig Mautner19d59bc2012-09-04 11:15:56 -07001244 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001245 public int getSurfaceLayer() {
1246 return mLayer;
1247 }
1248
Craig Mautner812d2ca2012-09-27 15:35:34 -07001249 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001250 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001251 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001252 }
1253
1254 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001255 public IApplicationToken getAppToken() {
1256 return mAppToken != null ? mAppToken.appToken : null;
1257 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001258
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001259 @Override
1260 public boolean isVoiceInteraction() {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001261 return mAppToken != null && mAppToken.mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001262 }
1263
Robert Carr31aa98b2016-07-20 15:29:03 -07001264 boolean setReportResizeHints() {
Craig Mautner4c5eb222013-11-18 12:59:05 -08001265 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1266 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1267 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001268 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001269 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
Robert Carr31aa98b2016-07-20 15:29:03 -07001270 mFrameSizeChanged |= (mLastFrame.width() != mFrame.width()) ||
1271 (mLastFrame.height() != mFrame.height());
Adrian Roos5c6b6222017-11-07 17:36:10 +01001272 mDisplayCutoutChanged |= !mLastDisplayCutout.equals(mDisplayCutout);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001273 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
Adrian Roos5c6b6222017-11-07 17:36:10 +01001274 || mOutsetsChanged || mFrameSizeChanged || mDisplayCutoutChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001275 }
1276
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001277 /**
1278 * Adds the window to the resizing list if any of the parameters we use to track the window
1279 * dimensions or insets have changed.
1280 */
1281 void updateResizingWindowIfNeeded() {
1282 final WindowStateAnimator winAnimator = mWinAnimator;
Adrian Roos5251b1d2018-03-23 18:57:43 +01001283 if (!mHasSurface || getDisplayContent().mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001284 return;
1285 }
1286
1287 final Task task = getTask();
1288 // In the case of stack bound animations, the window frames will update (unlike other
1289 // animations which just modify various transformation properties). We don't want to
1290 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1291 // the frame may not correspond to the surface size or the onscreen area at various
1292 // phases in the animation, and the client will become sad and confused.
Winson Chung40a5f932017-04-13 16:39:36 -07001293 if (task != null && task.mStack.isAnimatingBounds()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001294 return;
1295 }
1296
1297 setReportResizeHints();
1298 boolean configChanged = isConfigChanged();
1299 if (DEBUG_CONFIGURATION && configChanged) {
1300 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1301 }
1302
1303 final boolean dragResizingChanged = isDragResizeChanged()
1304 && !isDragResizingChangeReported();
1305
1306 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
1307 + " dragResizingChanged=" + dragResizingChanged + " last=" + mLastFrame
1308 + " frame=" + mFrame);
1309
1310 // We update mLastFrame always rather than in the conditional with the last inset
1311 // variables, because mFrameSizeChanged only tracks the width and height changing.
1312 mLastFrame.set(mFrame);
1313
1314 if (mContentInsetsChanged
1315 || mVisibleInsetsChanged
Adrian Rooscb938492018-04-16 17:10:32 +02001316 || mStableInsetsChanged
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001317 || winAnimator.mSurfaceResized
1318 || mOutsetsChanged
1319 || mFrameSizeChanged
Adrian Roos5c6b6222017-11-07 17:36:10 +01001320 || mDisplayCutoutChanged
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001321 || configChanged
1322 || dragResizingChanged
Andrii Kulianb2e37802017-01-11 00:36:44 -08001323 || mReportOrientationChanged) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001324 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1325 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
1326 + " contentInsetsChanged=" + mContentInsetsChanged
1327 + " " + mContentInsets.toShortString()
1328 + " visibleInsetsChanged=" + mVisibleInsetsChanged
1329 + " " + mVisibleInsets.toShortString()
1330 + " stableInsetsChanged=" + mStableInsetsChanged
1331 + " " + mStableInsets.toShortString()
1332 + " outsetsChanged=" + mOutsetsChanged
1333 + " " + mOutsets.toShortString()
1334 + " surfaceResized=" + winAnimator.mSurfaceResized
1335 + " configChanged=" + configChanged
1336 + " dragResizingChanged=" + dragResizingChanged
Adrian Roos5c6b6222017-11-07 17:36:10 +01001337 + " reportOrientationChanged=" + mReportOrientationChanged
1338 + " displayCutoutChanged=" + mDisplayCutoutChanged);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001339 }
1340
1341 // If it's a dead window left on screen, and the configuration changed, there is nothing
1342 // we can do about it. Remove the window now.
1343 if (mAppToken != null && mAppDied) {
1344 mAppToken.removeDeadWindows();
1345 return;
1346 }
1347
Jorim Jaggidc9385a2017-05-13 02:00:31 +02001348 updateLastInsetValues();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001349 mService.makeWindowFreezingScreenIfNeededLocked(this);
1350
1351 // If the orientation is changing, or we're starting or ending a drag resizing action,
1352 // then we need to hold off on unfreezing the display until this window has been
1353 // redrawn; to do that, we need to go through the process of getting informed by the
1354 // application when it has finished drawing.
Robert Carr09286c92018-02-15 13:52:31 -08001355 if (getOrientationChanging() || dragResizingChanged) {
Robert Carre13b58e2017-08-31 14:50:44 -07001356 if (DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001357 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1358 + ", mDrawState=DRAW_PENDING in " + this
1359 + ", surfaceController " + winAnimator.mSurfaceController);
1360 }
1361 winAnimator.mDrawState = DRAW_PENDING;
1362 if (mAppToken != null) {
1363 mAppToken.clearAllDrawn();
1364 }
1365 }
1366 if (!mService.mResizingWindows.contains(this)) {
1367 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
1368 mService.mResizingWindows.add(this);
1369 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07001370 } else if (getOrientationChanging()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001371 if (isDrawnLw()) {
1372 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1373 + this + ", surfaceController " + winAnimator.mSurfaceController);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001374 setOrientationChanging(false);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001375 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1376 - mService.mDisplayFreezeTime);
1377 }
1378 }
1379 }
1380
Bryce Lee8c3cf382017-07-06 19:47:10 -07001381 boolean getOrientationChanging() {
1382 // In addition to the local state flag, we must also consider the difference in the last
1383 // reported configuration vs. the current state. If the client code has not been informed of
1384 // the change, logic dependent on having finished processing the orientation, such as
1385 // unfreezing, could be improperly triggered.
1386 // TODO(b/62846907): Checking against {@link mLastReportedConfiguration} could be flaky as
1387 // this is not necessarily what the client has processed yet. Find a
1388 // better indicator consistent with the client.
Robert Carr926643f2017-08-02 12:01:12 -07001389 return (mOrientationChanging || (isVisible()
Bryce Lee2b17afd2017-09-21 10:38:20 -07001390 && getConfiguration().orientation != getLastReportedConfiguration().orientation))
Robert Carr9c1c3a02017-08-08 12:59:01 -07001391 && !mSeamlesslyRotated
1392 && !mOrientationChangeTimedOut;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001393 }
1394
1395 void setOrientationChanging(boolean changing) {
1396 mOrientationChanging = changing;
Robert Carr9c1c3a02017-08-08 12:59:01 -07001397 mOrientationChangeTimedOut = false;
1398 }
1399
1400 void orientationChangeTimedOut() {
1401 mOrientationChangeTimedOut = true;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001402 }
1403
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001404 DisplayContent getDisplayContent() {
1405 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001406 }
1407
Adrian Roos5251b1d2018-03-23 18:57:43 +01001408 @Override
1409 void onDisplayChanged(DisplayContent dc) {
1410 super.onDisplayChanged(dc);
1411 // Window was not laid out for this display yet, so make sure mLayoutSeq does not match.
1412 if (dc != null) {
1413 mLayoutSeq = dc.mLayoutSeq - 1;
Brad Stenningaf596412018-04-02 12:03:19 -07001414 mInputWindowHandle.displayId = dc.getDisplayId();
Adrian Roos5251b1d2018-03-23 18:57:43 +01001415 }
1416 }
1417
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001418 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001419 final DisplayContent displayContent = getDisplayContent();
1420 return displayContent != null ? displayContent.getDisplayInfo() : null;
1421 }
1422
Jorim Jaggife762342016-10-13 14:33:27 +02001423 @Override
1424 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001425 final DisplayContent displayContent = getDisplayContent();
1426 if (displayContent == null) {
Brad Stenningaf596412018-04-02 12:03:19 -07001427 return Display.INVALID_DISPLAY;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001428 }
1429 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001430 }
1431
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001432 Task getTask() {
Bryce Lee6d410262017-02-28 15:30:17 -08001433 return mAppToken != null ? mAppToken.getTask() : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001434 }
1435
1436 TaskStack getStack() {
1437 Task task = getTask();
1438 if (task != null) {
1439 if (task.mStack != null) {
1440 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001441 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001442 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001443 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1444 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001445 final DisplayContent dc = getDisplayContent();
1446 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001447 }
1448
Skuhnef932e562015-08-20 12:07:30 -07001449 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001450 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001451 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001452 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001453 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001454 final Task task = getTask();
1455 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001456 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001457 mTmpRect.setEmpty();
1458 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001459 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001460 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001461 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001462 } else {
1463 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001464 }
1465 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001466
Chong Zhang9184ec62015-09-24 12:32:21 -07001467 bounds.set(mVisibleFrame);
1468 if (intersectWithStackBounds) {
1469 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001470 }
1471
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001472 if (bounds.isEmpty()) {
1473 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001474 if (intersectWithStackBounds) {
1475 bounds.intersect(mTmpRect);
1476 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001477 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001478 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001479 }
1480
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001481 public long getInputDispatchingTimeoutNanos() {
1482 return mAppToken != null
Wale Ogunwale72919d22016-12-08 18:58:50 -08001483 ? mAppToken.mInputDispatchingTimeoutNanos
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001484 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1485 }
1486
Craig Mautnere8552142012-11-07 13:55:47 -08001487 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001488 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001489 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001490 }
1491
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001492 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1493 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1494 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1495 if (dtdx < -.000001f || dtdx > .000001f) return false;
1496 if (dsdy < -.000001f || dsdy > .000001f) return false;
1497 return true;
1498 }
1499
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001500 void prelayout() {
1501 if (mEnforceSizeCompat) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001502 mGlobalScale = getDisplayContent().mCompatibleScreenScale;
1503 mInvGlobalScale = 1 / mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001504 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001505 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001506 }
1507 }
1508
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001509 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001510 boolean hasContentToDisplay() {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001511 if (!mAppFreezing && isDrawnLw() && (mViewVisibility == View.VISIBLE
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001512 || (mWinAnimator.isAnimationSet() && !mService.mAppTransition.isTransitionSet()))) {
1513 return true;
1514 }
1515
Wale Ogunwale44f21802016-09-02 12:49:48 -07001516 return super.hasContentToDisplay();
1517 }
1518
1519 @Override
1520 boolean isVisible() {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001521 return wouldBeVisibleIfPolicyIgnored() && mPolicyVisibility;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001522 }
1523
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001524 /**
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001525 * @return True if the window would be visible if we'd ignore policy visibility, false
1526 * otherwise.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001527 */
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001528 boolean wouldBeVisibleIfPolicyIgnored() {
Jorim Jaggi43530c92017-05-18 01:53:56 +02001529 return mHasSurface && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001530 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001531 }
1532
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001533 @Override
1534 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001535 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001536 }
1537
1538 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001539 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1540 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001541 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001542 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1543 boolean isWinVisibleLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001544 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.isSelfAnimating())
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001545 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001546 }
1547
1548 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001549 * The same as isVisible(), but follows the current hidden state of the associated app token,
1550 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001551 */
1552 boolean isVisibleNow() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001553 return (!mToken.isHidden() || mAttrs.type == TYPE_APPLICATION_STARTING)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001554 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001555 }
1556
1557 /**
1558 * Can this window possibly be a drag/drop target? The test here is
1559 * a combination of the above "visible now" with the check that the
1560 * Input Manager uses when discarding windows from input consideration.
1561 */
1562 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001563 return isVisibleNow() && !mRemoved
1564 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001565 }
1566
1567 /**
1568 * Same as isVisible(), but we also count it as visible between the
1569 * call to IWindowSession.add() and the first relayout().
1570 */
1571 boolean isVisibleOrAdding() {
1572 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001573 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001574 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001575 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001576 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001577 }
1578
1579 /**
1580 * Is this window currently on-screen? It is on-screen either if it
1581 * is visible or it is currently running an animation before no longer
1582 * being visible.
1583 */
1584 boolean isOnScreen() {
Jorim Jaggiaf221d12016-11-15 14:59:57 -08001585 if (!mHasSurface || mDestroying || !mPolicyVisibility) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001586 return false;
1587 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001588 final AppWindowToken atoken = mAppToken;
1589 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001590 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001591 || mWinAnimator.isAnimationSet());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001592 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01001593 return !isParentWindowHidden() || mWinAnimator.isAnimationSet();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001594 }
1595
1596 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001597 * Whether this window's drawn state might affect the drawn states of the app token.
1598 *
Chong Zhang8e4bda92016-05-04 15:08:18 -07001599 * @return true if the window should be considered while evaluating allDrawn flags.
1600 */
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001601 boolean mightAffectAllDrawn() {
1602 final boolean isAppType = mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1603 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION;
1604 return (isOnScreen() || isAppType) && !mAnimatingExit && !mDestroying;
Chong Zhang8e4bda92016-05-04 15:08:18 -07001605 }
1606
1607 /**
1608 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1609 * it must be drawn before allDrawn can become true.
1610 */
1611 boolean isInteresting() {
1612 return mAppToken != null && !mAppDied
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001613 && (!mAppToken.isFreezingScreen() || !mAppFreezing);
Chong Zhang8e4bda92016-05-04 15:08:18 -07001614 }
1615
1616 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001617 * Like isOnScreen(), but we don't return true if the window is part
1618 * of a transition that has not yet been started.
1619 */
1620 boolean isReadyForDisplay() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001621 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001622 return false;
1623 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001624 return mHasSurface && mPolicyVisibility && !mDestroying
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001625 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.isHidden())
1626 || mWinAnimator.isAnimationSet());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001627 }
1628
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001629 // TODO: Another visibility method that was added late in the release to minimize risk.
1630 @Override
1631 public boolean canAffectSystemUiFlags() {
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001632 final boolean translucent = mAttrs.alpha == 0.0f;
Jorim Jaggi72207752018-01-08 13:16:59 +01001633 if (translucent) {
1634 return false;
1635 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001636 if (mAppToken == null) {
1637 final boolean shown = mWinAnimator.getShown();
1638 final boolean exiting = mAnimatingExit || mDestroying;
Jorim Jaggi72207752018-01-08 13:16:59 +01001639 return shown && !exiting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001640 } else {
Jorim Jaggi50bf59c2018-03-09 17:29:48 +01001641 final Task task = getTask();
1642 final boolean canFromTask = task != null && task.canAffectSystemUiFlags();
1643 return canFromTask && !mAppToken.isHidden();
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001644 }
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001645 }
1646
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001647 /**
1648 * Like isOnScreen, but returns false if the surface hasn't yet
1649 * been drawn.
1650 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001651 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001652 public boolean isDisplayedLw() {
1653 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001654 return isDrawnLw() && mPolicyVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001655 && ((!isParentWindowHidden() && (atoken == null || !atoken.hiddenRequested))
1656 || mWinAnimator.isAnimationSet());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001657 }
1658
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001659 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001660 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001661 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001662 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001663 public boolean isAnimatingLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001664 return isAnimating();
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001665 }
1666
Craig Mautner812d2ca2012-09-27 15:35:34 -07001667 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001668 public boolean isGoneForLayoutLw() {
1669 final AppWindowToken atoken = mAppToken;
1670 return mViewVisibility == View.GONE
1671 || !mRelayoutCalled
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001672 || (atoken == null && mToken.isHidden())
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001673 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001674 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001675 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001676 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001677 }
1678
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001679 /**
1680 * Returns true if the window has a surface that it has drawn a
1681 * complete UI in to.
1682 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001683 public boolean isDrawFinishedLw() {
1684 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001685 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1686 || mWinAnimator.mDrawState == READY_TO_SHOW
1687 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001688 }
1689
1690 /**
1691 * Returns true if the window has a surface that it has drawn a
1692 * complete UI in to.
1693 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001694 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001695 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001696 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001697 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001698 }
1699
1700 /**
1701 * Return true if the window is opaque and fully drawn. This indicates
1702 * it may obscure windows behind it.
1703 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001704 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001705 // When there is keyguard, wallpaper could be placed over the secure app
1706 // window but invisible. We need to check wallpaper visibility explicitly
1707 // to determine if it's occluding apps.
1708 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1709 || (mIsWallpaper && mWallpaperVisible))
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001710 && isDrawnLw() && !mWinAnimator.isAnimationSet();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001711 }
1712
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001713 @Override
1714 void onMovedByResize() {
1715 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001716 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001717 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001718 }
1719
1720 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1721 boolean changed = false;
1722
1723 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001724 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001725 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1726 }
1727
1728 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1729 // Starting window that's exiting will be removed when the animation finishes.
1730 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1731 // to actually remove it.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001732 if (!visible && isVisibleNow() && mAppToken.isSelfAnimating()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001733 mAnimatingExit = true;
1734 mRemoveOnExit = true;
1735 mWindowRemovalAllowed = true;
1736 }
1737 return changed;
1738 }
1739
chaviwe390cbd2018-04-16 15:29:38 -07001740 final boolean isVisibleNow = isVisibleNow();
1741 if (visible != isVisibleNow) {
1742 // Run exit animation if:
1743 // 1. App visibility and WS visibility are different
1744 // 2. App is not running an animation
1745 // 3. WS is currently visible
1746 if (!runningAppAnimation && isVisibleNow) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001747 final AccessibilityController accessibilityController =
1748 mService.mAccessibilityController;
chaviwe390cbd2018-04-16 15:29:38 -07001749 final int winTransit = TRANSIT_EXIT;
1750 mWinAnimator.applyAnimationLocked(winTransit, false /* isEntrance */);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001751 //TODO (multidisplay): Magnification is supported only for the default
1752 if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
1753 accessibilityController.onWindowTransitionLocked(this, winTransit);
1754 }
1755 }
1756 changed = true;
1757 setDisplayLayoutNeeded();
1758 }
1759
1760 return changed;
1761 }
1762
1763 boolean onSetAppExiting() {
1764 final DisplayContent displayContent = getDisplayContent();
1765 boolean changed = false;
1766
1767 if (isVisibleNow()) {
1768 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
1769 //TODO (multidisplay): Magnification is supported only for the default
1770 if (mService.mAccessibilityController != null && isDefaultDisplay()) {
1771 mService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
1772 }
1773 changed = true;
1774 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001775 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001776 }
1777 }
1778
1779 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001780 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001781 changed |= c.onSetAppExiting();
1782 }
1783
1784 return changed;
1785 }
1786
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001787 @Override
1788 void onResize() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001789 final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
Andrii Kulian3dcdf642018-05-23 17:14:00 -07001790 if (mHasSurface && !isGoneForLayoutLw() && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001791 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001792 resizingWindows.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001793 }
1794 if (isGoneForLayoutLw()) {
1795 mResizedWhileGone = true;
1796 }
1797
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001798 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001799 }
1800
1801 void onUnfreezeBounds() {
1802 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001803 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001804 c.onUnfreezeBounds();
1805 }
1806
1807 if (!mHasSurface) {
1808 return;
1809 }
1810
1811 mLayoutNeeded = true;
1812 setDisplayLayoutNeeded();
1813 if (!mService.mResizingWindows.contains(this)) {
1814 mService.mResizingWindows.add(this);
1815 }
1816 }
1817
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001818 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001819 * If the window has moved due to its containing content frame changing, then notify the
1820 * listeners and optionally animate it. Simply checking a change of position is not enough,
1821 * because being move due to dock divider is not a trigger for animation.
1822 */
chaviw161ea3e2018-01-31 12:01:12 -08001823 void handleWindowMovedIfNeeded() {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001824 if (!hasMoved()) {
1825 return;
1826 }
1827
1828 // Frame has moved, containing content frame has also moved, and we're not currently
1829 // animating... let's do something.
1830 final int left = mFrame.left;
1831 final int top = mFrame.top;
1832 final Task task = getTask();
1833 final boolean adjustedForMinimizedDockOrIme = task != null
1834 && (task.mStack.isAdjustedForMinimizedDockedStack()
1835 || task.mStack.isAdjustedForIme());
David Stevens9440dc82017-03-16 19:00:20 -07001836 if (mToken.okToAnimate()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001837 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1838 && !isDragResizing() && !adjustedForMinimizedDockOrIme
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001839 && getWindowConfiguration().hasMovementAnimations()
Adrian Roos41f7e9d2018-06-07 15:29:34 +02001840 && !mWinAnimator.mLastHidden
1841 && !mSeamlesslyRotated) {
chaviw161ea3e2018-01-31 12:01:12 -08001842 startMoveAnimation(left, top);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001843 }
1844
1845 //TODO (multidisplay): Accessibility supported only for the default display.
1846 if (mService.mAccessibilityController != null
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001847 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001848 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
1849 }
1850
1851 try {
1852 mClient.moved(left, top);
1853 } catch (RemoteException e) {
1854 }
1855 mMovedByResize = false;
1856 }
1857
1858 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001859 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001860 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1861 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001862 private boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001863 return mHasSurface && (mContentChanged || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001864 && !mAnimatingExit
Chong Zhangbd0d9372015-12-28 15:18:29 -08001865 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001866 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001867 }
1868
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001869 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001870 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001871 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001872 return false;
1873 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001874 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001875 }
1876
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001877 boolean fillsDisplay() {
1878 final DisplayInfo displayInfo = getDisplayInfo();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001879 return mFrame.left <= 0 && mFrame.top <= 0
1880 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001881 }
1882
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001883 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001884 boolean isConfigChanged() {
Bryce Lee2b17afd2017-09-21 10:38:20 -07001885 return !getLastReportedConfiguration().equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001886 }
1887
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001888 void onWindowReplacementTimeout() {
1889 if (mWillReplaceWindow) {
1890 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001891 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001892 // delays removal on certain conditions, which will leave the stale window in the
1893 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1894 //
1895 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001896 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001897 } else {
1898 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001899 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001900 c.onWindowReplacementTimeout();
1901 }
1902 }
1903 }
1904
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001905 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001906 void forceWindowsScaleableInTransaction(boolean force) {
1907 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1908 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1909 }
1910
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001911 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001912 }
1913
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001914 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001915 void removeImmediately() {
1916 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001917
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001918 if (mRemoved) {
1919 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001920 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1921 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001922 return;
1923 }
1924
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001925 mRemoved = true;
1926
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001927 mWillReplaceWindow = false;
1928 if (mReplacementWindow != null) {
1929 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1930 }
1931
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001932 final DisplayContent dc = getDisplayContent();
Robert Carr825581a2018-03-30 14:00:53 -07001933 if (isInputMethodTarget()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001934 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001935 }
1936
1937 final int type = mAttrs.type;
1938 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001939 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001940 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001941 if (mTapExcludeRegionHolder != null) {
1942 // If a tap exclude region container was initialized for this window, then it should've
1943 // also been registered in display.
1944 dc.mTapExcludeProvidingWindows.remove(this);
1945 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001946 mPolicy.removeWindowLw(this);
1947
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001948 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001949
Craig Mautner96868332012-12-04 14:29:11 -08001950 mWinAnimator.destroyDeferredSurfaceLocked();
1951 mWinAnimator.destroySurfaceLocked();
Wale Ogunwale943002b2017-02-15 19:34:01 -08001952 mSession.windowRemovedLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001953 try {
1954 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1955 } catch (RuntimeException e) {
1956 // Ignore if it has already been removed (usually because
1957 // we are doing this as part of processing a death note.)
1958 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001959
1960 mService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001961 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001962
Wale Ogunwale571771c2016-08-26 13:18:50 -07001963 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001964 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001965 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001966 removeIfPossible(false /*keepVisibleDeadWindow*/);
1967 }
1968
Wale Ogunwale571771c2016-08-26 13:18:50 -07001969 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001970 mWindowRemovalAllowed = true;
1971 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1972 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1973
1974 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1975 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1976 "Starting window removed " + this);
1977
1978 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && this == mService.mCurrentFocus)
1979 Slog.v(TAG_WM, "Remove " + this + " client="
1980 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1981 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1982 + Debug.getCallers(5));
1983
1984 final long origId = Binder.clearCallingIdentity();
1985
Peter Visontay3556a3b2017-11-01 17:23:17 +00001986 try {
1987 disposeInputChannel();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001988
Peter Visontay3556a3b2017-11-01 17:23:17 +00001989 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1990 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1991 + " mAnimatingExit=" + mAnimatingExit
1992 + " mRemoveOnExit=" + mRemoveOnExit
1993 + " mHasSurface=" + mHasSurface
1994 + " surfaceShowing=" + mWinAnimator.getShown()
1995 + " isAnimationSet=" + mWinAnimator.isAnimationSet()
1996 + " app-animation="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001997 + (mAppToken != null ? mAppToken.isSelfAnimating() : "false")
Peter Visontay3556a3b2017-11-01 17:23:17 +00001998 + " mWillReplaceWindow=" + mWillReplaceWindow
1999 + " inPendingTransaction="
2000 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
2001 + " mDisplayFrozen=" + mService.mDisplayFrozen
2002 + " callers=" + Debug.getCallers(6));
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002003
Peter Visontay3556a3b2017-11-01 17:23:17 +00002004 // Visibility of the removed window. Will be used later to update orientation later on.
2005 boolean wasVisible = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002006
Peter Visontay3556a3b2017-11-01 17:23:17 +00002007 final int displayId = getDisplayId();
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002008
Peter Visontay3556a3b2017-11-01 17:23:17 +00002009 // First, see if we need to run an animation. If we do, we have to hold off on removing the
2010 // window until the animation is done. If the display is frozen, just remove immediately,
2011 // since the animation wouldn't be seen.
2012 if (mHasSurface && mToken.okToAnimate()) {
2013 if (mWillReplaceWindow) {
2014 // This window is going to be replaced. We need to keep it around until the new one
2015 // gets added, then we will get rid of this one.
2016 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
2017 "Preserving " + this + " until the new one is " + "added");
2018 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
2019 // been removed. We probably need another flag to indicate that window removal
2020 // should be deffered vs. overloading the flag that says we are playing an exit
2021 // animation.
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002022 mAnimatingExit = true;
Peter Visontay3556a3b2017-11-01 17:23:17 +00002023 mReplacingRemoveRequested = true;
2024 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002025 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002026
Peter Visontay3556a3b2017-11-01 17:23:17 +00002027 // If we are not currently running the exit animation, we need to see about starting one
2028 wasVisible = isWinVisibleLw();
2029
2030 if (keepVisibleDeadWindow) {
2031 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
2032 "Not removing " + this + " because app died while it's visible");
2033
2034 mAppDied = true;
2035 setDisplayLayoutNeeded();
2036 mService.mWindowPlacerLocked.performSurfacePlacement();
2037
2038 // Set up a replacement input channel since the app is now dead.
2039 // We need to catch tapping on the dead window to restart the app.
2040 openInputChannel(null);
2041 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
2042 return;
2043 }
2044
2045 if (wasVisible) {
2046 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
2047
2048 // Try starting an animation.
2049 if (mWinAnimator.applyAnimationLocked(transit, false)) {
2050 mAnimatingExit = true;
Jorim Jaggif41e8822018-04-06 17:22:03 +02002051
2052 // mAnimatingExit affects canAffectSystemUiFlags(). Run layout such that
2053 // any change from that is performed immediately.
2054 setDisplayLayoutNeeded();
2055 mService.requestTraversal();
Peter Visontay3556a3b2017-11-01 17:23:17 +00002056 }
2057 //TODO (multidisplay): Magnification is supported only for the default display.
2058 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
2059 mService.mAccessibilityController.onWindowTransitionLocked(this, transit);
2060 }
2061 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002062 final boolean isAnimating = mWinAnimator.isAnimationSet()
2063 && (mAppToken == null || !mAppToken.isWaitingForTransitionStart());
Peter Visontay3556a3b2017-11-01 17:23:17 +00002064 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
2065 && mAppToken.isLastWindow(this);
2066 // We delay the removal of a window if it has a showing surface that can be used to run
2067 // exit animation and it is marked as exiting.
2068 // Also, If isn't the an animating starting window that is the last window in the app.
2069 // We allow the removal of the non-animating starting window now as there is no
2070 // additional window or animation that will trigger its removal.
2071 if (mWinAnimator.getShown() && mAnimatingExit
2072 && (!lastWindowIsStartingWindow || isAnimating)) {
2073 // The exit animation is running or should run... wait for it!
2074 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
2075 "Not removing " + this + " due to exit animation ");
2076 setupWindowForRemoveOnExit();
2077 if (mAppToken != null) {
2078 mAppToken.updateReportedVisibilityLocked();
2079 }
2080 return;
2081 }
2082 }
2083
2084 removeImmediately();
2085 // Removing a visible window will effect the computed orientation
2086 // So just update orientation if needed.
Robert Carrae606b42018-02-15 15:36:23 -08002087 if (wasVisible && mService.updateOrientationFromAppTokensLocked(displayId)) {
Peter Visontay3556a3b2017-11-01 17:23:17 +00002088 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
2089 }
2090 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
2091 } finally {
2092 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002093 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002094 }
2095
2096 private void setupWindowForRemoveOnExit() {
2097 mRemoveOnExit = true;
2098 setDisplayLayoutNeeded();
2099 // Request a focus update as this window's input channel is already gone. Otherwise
2100 // we could have no focused window in input manager.
2101 final boolean focusChanged = mService.updateFocusedWindowLocked(
2102 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
2103 mService.mWindowPlacerLocked.performSurfacePlacement();
2104 if (focusChanged) {
2105 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2106 }
2107 }
2108
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08002109 void setHasSurface(boolean hasSurface) {
2110 mHasSurface = hasSurface;
2111 }
2112
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002113 boolean canBeImeTarget() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002114 if (mIsImWindow) {
2115 // IME windows can't be IME targets. IME targets are required to be below the IME
2116 // windows and that wouldn't be possible if the IME window is its own target...silly.
2117 return false;
2118 }
2119
Winson Chung3d0a74a2017-07-12 12:37:19 -07002120 final boolean windowsAreFocusable = mAppToken == null || mAppToken.windowsAreFocusable();
Winson Chungb1549342017-07-11 09:59:56 -07002121 if (!windowsAreFocusable) {
2122 // This window can't be an IME target if the app's windows should not be focusable.
2123 return false;
2124 }
2125
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002126 final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002127 final int type = mAttrs.type;
2128
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002129 // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are set or
2130 // both are cleared...and not a starting window.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002131 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
2132 && type != TYPE_APPLICATION_STARTING) {
2133 return false;
2134 }
2135
2136 if (DEBUG_INPUT_METHOD) {
2137 Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding());
2138 if (!isVisibleOrAdding()) {
2139 Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController
2140 + " relayoutCalled=" + mRelayoutCalled
2141 + " viewVis=" + mViewVisibility
2142 + " policyVis=" + mPolicyVisibility
2143 + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim
2144 + " parentHidden=" + isParentWindowHidden()
2145 + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
2146 if (mAppToken != null) {
2147 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + mAppToken.hiddenRequested);
2148 }
2149 }
2150 }
2151 return isVisibleOrAdding();
2152 }
2153
Chong Zhangacf11402015-11-04 16:23:10 -08002154 private final class DeadWindowEventReceiver extends InputEventReceiver {
2155 DeadWindowEventReceiver(InputChannel inputChannel) {
2156 super(inputChannel, mService.mH.getLooper());
2157 }
2158 @Override
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -07002159 public void onInputEvent(InputEvent event, int displayId) {
Chong Zhangacf11402015-11-04 16:23:10 -08002160 finishInputEvent(event, true);
2161 }
2162 }
2163 /**
2164 * Dummy event receiver for windows that died visible.
2165 */
2166 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2167
Chong Zhang112eb8c2015-11-02 11:17:00 -08002168 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002169 if (mInputChannel != null) {
2170 throw new IllegalStateException("Window already has an input channel.");
2171 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002172 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002173 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2174 mInputChannel = inputChannels[0];
2175 mClientChannel = inputChannels[1];
2176 mInputWindowHandle.inputChannel = inputChannels[0];
2177 if (outInputChannel != null) {
2178 mClientChannel.transferTo(outInputChannel);
2179 mClientChannel.dispose();
2180 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002181 } else {
2182 // If the window died visible, we setup a dummy input channel, so that taps
2183 // can still detected by input monitor channel, and we can relaunch the app.
2184 // Create dummy event receiver that simply reports all events as handled.
2185 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002186 }
2187 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002188 }
2189
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002190 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002191 if (mDeadWindowEventReceiver != null) {
2192 mDeadWindowEventReceiver.dispose();
2193 mDeadWindowEventReceiver = null;
2194 }
2195
2196 // unregister server channel first otherwise it complains about broken channel
2197 if (mInputChannel != null) {
2198 mService.mInputManager.unregisterInputChannel(mInputChannel);
2199 mInputChannel.dispose();
2200 mInputChannel = null;
2201 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002202 if (mClientChannel != null) {
2203 mClientChannel.dispose();
2204 mClientChannel = null;
2205 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07002206 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002207 }
2208
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002209 /** Returns true if the replacement window was removed. */
2210 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2211 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2212 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2213 removeReplacedWindow();
2214 return true;
2215 }
2216
2217 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002218 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002219 if (c.removeReplacedWindowIfNeeded(replacement)) {
2220 return true;
2221 }
2222 }
2223 return false;
2224 }
2225
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002226 private void removeReplacedWindow() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002227 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002228 mWillReplaceWindow = false;
2229 mAnimateReplacingWindow = false;
2230 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002231 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002232 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002233 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002234 }
2235 }
2236
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002237 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2238 boolean replacementSet = false;
2239
2240 if (mWillReplaceWindow && mReplacementWindow == null
2241 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2242
2243 mReplacementWindow = replacementCandidate;
2244 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2245 replacementSet = true;
2246 }
2247
2248 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002249 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002250 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2251 }
2252
2253 return replacementSet;
2254 }
2255
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002256 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002257 final DisplayContent dc = getDisplayContent();
2258 if (dc != null) {
2259 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002260 }
2261 }
2262
Chong Zhang5117e272016-05-03 12:47:34 -07002263 void applyAdjustForImeIfNeeded() {
2264 final Task task = getTask();
2265 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2266 task.mStack.applyAdjustForImeIfNeeded(task);
2267 }
2268 }
2269
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002270 @Override
2271 void switchUser() {
2272 super.switchUser();
2273 if (isHiddenFromUserLocked()) {
2274 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2275 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
2276 hideLw(false);
2277 }
2278 }
2279
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002280 int getTouchableRegion(Region region, int flags) {
2281 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002282 if (modal && mAppToken != null) {
2283 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002284 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002285 // If this is a modal window we need to dismiss it if it's not full screen and the
2286 // touch happens outside of the frame that displays the content. This means we
2287 // need to intercept touches outside of that window. The dim layer user
2288 // associated with the window (task or stack) will give us the good bounds, as
2289 // they would be used to display the dim layer.
Robert Carrf59b8dd2017-10-02 18:58:36 -07002290 final Task task = getTask();
2291 if (task != null) {
2292 task.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002293 } else {
Robert Carrf59b8dd2017-10-02 18:58:36 -07002294 getStack().getDimBounds(mTmpRect);
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002295 }
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002296 if (inFreeformWindowingMode()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002297 // For freeform windows we the touch region to include the whole surface for the
2298 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002299 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2300 final int delta = WindowManagerService.dipToPixel(
2301 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2302 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002303 }
2304 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002305 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002306 } else {
2307 // Not modal or full screen modal
2308 getTouchableRegion(region);
2309 }
2310 return flags;
2311 }
2312
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002313 void checkPolicyVisibilityChange() {
2314 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2315 if (DEBUG_VISIBILITY) {
2316 Slog.v(TAG, "Policy visibility changing after anim in " +
2317 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2318 }
2319 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002320 if (!mPolicyVisibility) {
Jorim Jaggi2e05af22017-12-28 15:15:11 +01002321 mWinAnimator.hide("checkPolicyVisibilityChange");
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002322 if (mService.mCurrentFocus == this) {
2323 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2324 "setAnimationLocked: setting mFocusMayChange true");
2325 mService.mFocusMayChange = true;
2326 }
Tetsutoki Shiozawa64c5f0c2018-05-18 10:55:01 +09002327 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002328 // Window is no longer visible -- make sure if we were waiting
2329 // for it to be displayed before enabling the display, that
2330 // we allow the display to be enabled now.
2331 mService.enableScreenIfNeededLocked();
2332 }
2333 }
2334 }
2335
2336 void setRequestedSize(int requestedWidth, int requestedHeight) {
2337 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2338 mLayoutNeeded = true;
2339 mRequestedWidth = requestedWidth;
2340 mRequestedHeight = requestedHeight;
2341 }
2342 }
2343
Bryce Leef858b572017-06-29 14:03:33 -07002344 void prepareWindowToDisplayDuringRelayout(boolean wasVisible) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002345 // We need to turn on screen regardless of visibility.
chaviw40234662018-02-07 09:37:16 -08002346 boolean hasTurnScreenOnFlag = (mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0;
2347 boolean allowTheaterMode =
2348 mService.mAllowTheaterModeWakeFromLayout || Settings.Global.getInt(
2349 mService.mContext.getContentResolver(), Settings.Global.THEATER_MODE_ON, 0)
2350 == 0;
2351 boolean canTurnScreenOn = mAppToken == null || mAppToken.canTurnScreenOn();
2352
2353 // The screen will turn on if the following conditions are met
2354 // 1. The window has the flag FLAG_TURN_SCREEN_ON
2355 // 2. The WMS allows theater mode.
2356 // 3. No AWT or the AWT allows the screen to be turned on. This should only be true once
2357 // per resume to prevent the screen getting getting turned on for each relayout. Set
2358 // canTurnScreenOn will be set to false so the window doesn't turn the screen on again
2359 // during this resume.
2360 // 4. When the screen is not interactive. This is because when the screen is already
2361 // interactive, the value may persist until the next animation, which could potentially
2362 // be occurring while turning off the screen. This would lead to the screen incorrectly
2363 // turning back on.
chaviw474093d2018-03-07 15:03:38 -08002364 if (hasTurnScreenOnFlag) {
2365 if (allowTheaterMode && canTurnScreenOn && !mPowerManagerWrapper.isInteractive()) {
2366 if (DEBUG_VISIBILITY || DEBUG_POWER) {
2367 Slog.v(TAG, "Relayout window turning screen on: " + this);
2368 }
2369 mPowerManagerWrapper.wakeUp(SystemClock.uptimeMillis(),
2370 "android.server.wm:TURN_ON");
chaviw40234662018-02-07 09:37:16 -08002371 }
chaviwb28de1f2018-03-02 10:42:36 -08002372
2373 if (mAppToken != null) {
2374 mAppToken.setCanTurnScreenOn(false);
2375 }
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002376 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002377
2378 // If we were already visible, skip rest of preparation.
2379 if (wasVisible) {
2380 if (DEBUG_VISIBILITY) Slog.v(TAG,
2381 "Already visible and does not turn on screen, skip preparing: " + this);
2382 return;
2383 }
2384
2385 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2386 == SOFT_INPUT_ADJUST_RESIZE) {
2387 mLayoutNeeded = true;
2388 }
2389
David Stevens9440dc82017-03-16 19:00:20 -07002390 if (isDrawnLw() && mToken.okToAnimate()) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002391 mWinAnimator.applyEnterAnimationLocked();
2392 }
Bryce Leef858b572017-06-29 14:03:33 -07002393 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002394
Bryce Leef858b572017-06-29 14:03:33 -07002395 void getMergedConfiguration(MergedConfiguration outConfiguration) {
2396 final Configuration globalConfig = mService.mRoot.getConfiguration();
2397 final Configuration overrideConfig = getMergedOverrideConfiguration();
2398 outConfiguration.setConfiguration(globalConfig, overrideConfig);
2399 }
2400
Bryce Lee2b17afd2017-09-21 10:38:20 -07002401 void setLastReportedMergedConfiguration(MergedConfiguration config) {
2402 mLastReportedConfiguration.setTo(config);
2403 }
2404
2405 void getLastReportedMergedConfiguration(MergedConfiguration config) {
2406 config.setTo(mLastReportedConfiguration);
2407 }
2408
2409 private Configuration getLastReportedConfiguration() {
2410 return mLastReportedConfiguration.getMergedConfiguration();
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002411 }
2412
2413 void adjustStartingWindowFlags() {
2414 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2415 && mAppToken.startingWindow != null) {
2416 // Special handling of starting window over the base
2417 // window of the app: propagate lock screen flags to it,
2418 // to provide the correct semantics while starting.
2419 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2420 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2421 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2422 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2423 }
2424 }
2425
2426 void setWindowScale(int requestedWidth, int requestedHeight) {
2427 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2428
2429 if (scaledWindow) {
2430 // requested{Width|Height} Surface's physical size
2431 // attrs.{width|height} Size on screen
2432 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2433 mHScale = (mAttrs.width != requestedWidth) ?
2434 (mAttrs.width / (float)requestedWidth) : 1.0f;
2435 mVScale = (mAttrs.height != requestedHeight) ?
2436 (mAttrs.height / (float)requestedHeight) : 1.0f;
2437 } else {
2438 mHScale = mVScale = 1;
2439 }
2440 }
2441
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002442 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002443 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002444 public void binderDied() {
2445 try {
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002446 boolean resetSplitScreenResizing = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002447 synchronized(mService.mWindowMap) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002448 final WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002449 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002450 if (win != null) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002451 final DisplayContent dc = getDisplayContent();
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002452 if (win.mAppToken != null && win.mAppToken.findMainWindow() == win) {
2453 mService.mTaskSnapshotController.onAppDied(win.mAppToken);
2454 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002455 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002456 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2457 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002458 // just in case they have the divider at an unstable position. Better
2459 // also reset drag resizing state, because the owner can't do it
2460 // anymore.
Wale Ogunwale61911492017-10-11 08:50:50 -07002461 final TaskStack stack =
Matthew Ng64e77cf2017-10-31 14:01:31 -07002462 dc.getSplitScreenPrimaryStackIgnoringVisibility();
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002463 if (stack != null) {
2464 stack.resetDockedStackToMiddle();
2465 }
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002466 resetSplitScreenResizing = true;
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002467 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002468 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002469 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002470 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002471 }
2472 }
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002473 if (resetSplitScreenResizing) {
2474 try {
2475 // Note: this calls into ActivityManager, so we must *not* hold the window
2476 // manager lock while calling this.
2477 mService.mActivityManager.setSplitScreenResizing(false);
2478 } catch (RemoteException e) {
2479 // Local call, shouldn't return RemoteException.
2480 throw e.rethrowAsRuntimeException();
2481 }
2482 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002483 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002484 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002485 }
2486 }
2487 }
2488
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002489 /**
2490 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2491 * because we want to preserve its location on screen to be re-activated later when the user
2492 * interacts with it.
2493 */
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002494 private boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwale89973222017-04-23 18:39:45 -07002495 if (!isWinVisibleLw() || mAppToken == null || mAppToken.isClientHidden()) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002496 // Not a visible app window or the app isn't dead.
2497 return false;
2498 }
2499
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002500 if (mAttrs.token != mClient.asBinder()) {
2501 // The window was add by a client using another client's app token. We don't want to
2502 // keep the dead window around for this case since this is meant for 'real' apps.
2503 return false;
2504 }
2505
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002506 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2507 // We don't keep starting windows since they were added by the window manager before
2508 // the app even launched.
2509 return false;
2510 }
2511
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002512 return getWindowConfiguration().keepVisibleDeadAppWindowOnScreen();
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002513 }
2514
Wale Ogunwaled045c822015-12-02 09:14:28 -08002515 /** @return true if this window desires key events. */
2516 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002517 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002518 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002519 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002520 && (mAppToken == null || mAppToken.windowsAreFocusable())
Matthew Nge15352e2016-12-20 15:36:29 -08002521 && !canReceiveTouchInput();
2522 }
2523
2524 /** @return true if this window desires touch events. */
2525 boolean canReceiveTouchInput() {
Bryce Lee6d410262017-02-28 15:30:17 -08002526 return mAppToken != null && mAppToken.getTask() != null
2527 && mAppToken.getTask().mStack.shouldIgnoreInput();
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 hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002532 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002533 }
2534
Craig Mautner749a7bb2012-04-02 13:49:53 -07002535 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002536 public boolean showLw(boolean doAnimation) {
2537 return showLw(doAnimation, true);
2538 }
2539
2540 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002541 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002542 return false;
2543 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002544 if (!mAppOpVisibility) {
2545 // Being hidden due to app op request.
2546 return false;
2547 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002548 if (mPermanentlyHidden) {
2549 // Permanently hidden until the app exists as apps aren't prepared
2550 // to handle their windows being removed from under them.
2551 return false;
2552 }
Suprabh Shukla69c71422018-04-02 18:39:01 -07002553 if (mHiddenWhileSuspended) {
2554 // Being hidden due to owner package being suspended.
2555 return false;
2556 }
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002557 if (mForceHideNonSystemOverlayWindow) {
2558 // This is an alert window that is currently force hidden.
2559 return false;
2560 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002561 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002562 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002563 return false;
2564 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002565 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002566 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002567 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Jorim Jaggia5e10572017-11-15 14:36:26 +01002568 + mPolicyVisibility + " isAnimationSet=" + mWinAnimator.isAnimationSet());
David Stevens9440dc82017-03-16 19:00:20 -07002569 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002570 doAnimation = false;
Jorim Jaggia5e10572017-11-15 14:36:26 +01002571 } else if (mPolicyVisibility && !mWinAnimator.isAnimationSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002572 // Check for the case where we are currently visible and
2573 // not animating; we do not want to do animation at such a
2574 // point to become visible when we already are.
2575 doAnimation = false;
2576 }
2577 }
2578 mPolicyVisibility = true;
2579 mPolicyVisibilityAfterAnim = true;
2580 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002581 mWinAnimator.applyAnimationLocked(TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002582 }
2583 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002584 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002585 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002586 if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) {
2587 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2588 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002589 return true;
2590 }
2591
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002592 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002593 public boolean hideLw(boolean doAnimation) {
2594 return hideLw(doAnimation, true);
2595 }
2596
2597 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2598 if (doAnimation) {
David Stevens9440dc82017-03-16 19:00:20 -07002599 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002600 doAnimation = false;
2601 }
2602 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002603 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002604 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002605 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002606 return false;
2607 }
2608 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002609 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
Jorim Jaggia5e10572017-11-15 14:36:26 +01002610 if (!mWinAnimator.isAnimationSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002611 doAnimation = false;
2612 }
2613 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002614 mPolicyVisibilityAfterAnim = false;
2615 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002616 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002617 mPolicyVisibility = false;
2618 // Window is no longer visible -- make sure if we were waiting
2619 // for it to be displayed before enabling the display, that
2620 // we allow the display to be enabled now.
2621 mService.enableScreenIfNeededLocked();
2622 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002623 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002624 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002625 mService.mFocusMayChange = true;
2626 }
2627 }
2628 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002629 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002630 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002631 if (mService.mCurrentFocus == this) {
2632 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2633 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002634 return true;
2635 }
2636
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002637 void setForceHideNonSystemOverlayWindowIfNeeded(boolean forceHide) {
2638 if (mOwnerCanAddInternalSystemWindow
2639 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2640 return;
2641 }
2642 if (mForceHideNonSystemOverlayWindow == forceHide) {
2643 return;
2644 }
2645 mForceHideNonSystemOverlayWindow = forceHide;
2646 if (forceHide) {
2647 hideLw(true /* doAnimation */, true /* requestAnim */);
2648 } else {
2649 showLw(true /* doAnimation */, true /* requestAnim */);
2650 }
2651 }
2652
Suprabh Shukla69c71422018-04-02 18:39:01 -07002653 void setHiddenWhileSuspended(boolean hide) {
2654 if (mOwnerCanAddInternalSystemWindow
2655 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2656 return;
2657 }
2658 if (mHiddenWhileSuspended == hide) {
2659 return;
2660 }
2661 mHiddenWhileSuspended = hide;
2662 if (hide) {
2663 hideLw(true, true);
2664 } else {
2665 showLw(true, true);
2666 }
2667 }
2668
Svet Ganovf7b47252018-02-26 11:11:27 -08002669 private void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002670 if (mAppOpVisibility != state) {
2671 mAppOpVisibility = state;
2672 if (state) {
2673 // If the policy visibility had last been to hide, then this
2674 // will incorrectly show at this point since we lost that
2675 // information. Not a big deal -- for the windows that have app
2676 // ops modifies they should only be hidden by policy due to the
2677 // lock screen, and the user won't be changing this if locked.
2678 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002679 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002680 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002681 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002682 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002683 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002684 }
2685
Svet Ganovf7b47252018-02-26 11:11:27 -08002686 void initAppOpsState() {
2687 if (mAppOp == OP_NONE || !mAppOpVisibility) {
2688 return;
2689 }
2690 // If the app op was MODE_DEFAULT we would have checked the permission
2691 // and add the window only if the permission was granted. Therefore, if
2692 // the mode is MODE_DEFAULT we want the op to succeed as the window is
2693 // shown.
2694 final int mode = mService.mAppOps.startOpNoThrow(mAppOp,
2695 getOwningUid(), getOwningPackage(), true);
2696 if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) {
2697 setAppOpVisibilityLw(false);
2698 }
2699 }
2700
2701 void resetAppOpsState() {
2702 if (mAppOp != OP_NONE && mAppOpVisibility) {
2703 mService.mAppOps.finishOp(mAppOp, getOwningUid(), getOwningPackage());
2704 }
2705 }
2706
2707 void updateAppOpsState() {
2708 if (mAppOp == OP_NONE) {
2709 return;
2710 }
2711 final int uid = getOwningUid();
2712 final String packageName = getOwningPackage();
2713 if (mAppOpVisibility) {
2714 // There is a race between the check and the finish calls but this is fine
2715 // as this would mean we will get another change callback and will reconcile.
2716 int mode = mService.mAppOps.checkOpNoThrow(mAppOp, uid, packageName);
2717 if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) {
2718 mService.mAppOps.finishOp(mAppOp, uid, packageName);
2719 setAppOpVisibilityLw(false);
2720 }
2721 } else {
Svet Ganov522ed242018-03-07 21:40:28 -08002722 final int mode = mService.mAppOps.startOpNoThrow(mAppOp, uid, packageName, true);
Svet Ganovf7b47252018-02-26 11:11:27 -08002723 if (mode == MODE_ALLOWED || mode == MODE_DEFAULT) {
2724 setAppOpVisibilityLw(true);
2725 }
2726 }
2727 }
2728
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002729 public void hidePermanentlyLw() {
2730 if (!mPermanentlyHidden) {
2731 mPermanentlyHidden = true;
2732 hideLw(true, true);
2733 }
2734 }
2735
Jeff Brownc2932a12014-11-20 18:04:05 -08002736 public void pokeDrawLockLw(long timeout) {
2737 if (isVisibleOrAdding()) {
2738 if (mDrawLock == null) {
2739 // We want the tag name to be somewhat stable so that it is easier to correlate
2740 // in wake lock statistics. So in particular, we don't want to include the
2741 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002742 final CharSequence tag = getWindowTag();
chaviw40234662018-02-07 09:37:16 -08002743 mDrawLock = mService.mPowerManager.newWakeLock(DRAW_WAKE_LOCK, "Window:" + tag);
Jeff Brownc2932a12014-11-20 18:04:05 -08002744 mDrawLock.setReferenceCounted(false);
2745 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2746 }
2747 // Each call to acquire resets the timeout.
2748 if (DEBUG_POWER) {
2749 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2750 + mAttrs.packageName);
2751 }
2752 mDrawLock.acquire(timeout);
2753 } else if (DEBUG_POWER) {
2754 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2755 + "owned by " + mAttrs.packageName);
2756 }
2757 }
2758
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002759 @Override
2760 public boolean isAlive() {
2761 return mClient.asBinder().isBinderAlive();
2762 }
2763
Craig Mautnera987d432012-10-11 14:07:58 -07002764 boolean isClosing() {
chaviw4ad54912018-05-30 11:05:44 -07002765 return mAnimatingExit || (mAppToken != null && mAppToken.isClosingOrEnteringPip());
Craig Mautnera987d432012-10-11 14:07:58 -07002766 }
2767
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002768 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2769 animators.add(mWinAnimator);
2770
2771 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002772 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002773 c.addWinAnimatorToList(animators);
2774 }
2775 }
2776
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002777 void sendAppVisibilityToClients() {
2778 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002779
Wale Ogunwale89973222017-04-23 18:39:45 -07002780 final boolean clientHidden = mAppToken.isClientHidden();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002781 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2782 // Don't hide the starting window.
2783 return;
2784 }
2785
Wale Ogunwale89973222017-04-23 18:39:45 -07002786 if (clientHidden) {
2787 // Once we are notifying the client that it's visibility has changed, we need to prevent
2788 // it from destroying child surfaces until the animation has finished. We do this by
2789 // detaching any surface control the client added from the client.
2790 for (int i = mChildren.size() - 1; i >= 0; --i) {
2791 final WindowState c = mChildren.get(i);
2792 c.mWinAnimator.detachChildren();
2793 }
2794
2795 mWinAnimator.detachChildren();
2796 }
2797
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002798 try {
2799 if (DEBUG_VISIBILITY) Slog.v(TAG,
2800 "Setting visibility of " + this + ": " + (!clientHidden));
2801 mClient.dispatchAppVisibility(!clientHidden);
2802 } catch (RemoteException e) {
2803 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002804 }
2805
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002806 void onStartFreezingScreen() {
2807 mAppFreezing = true;
2808 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002809 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002810 c.onStartFreezingScreen();
2811 }
2812 }
2813
2814 boolean onStopFreezingScreen() {
2815 boolean unfrozeWindows = false;
2816 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002817 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002818 unfrozeWindows |= c.onStopFreezingScreen();
2819 }
2820
2821 if (!mAppFreezing) {
2822 return unfrozeWindows;
2823 }
2824
Wale Ogunwale953171d2016-09-30 09:17:30 -07002825 mAppFreezing = false;
2826
Bryce Lee8c3cf382017-07-06 19:47:10 -07002827 if (mHasSurface && !getOrientationChanging()
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002828 && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
2829 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
Bryce Lee8c3cf382017-07-06 19:47:10 -07002830 setOrientationChanging(true);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002831 mService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002832 }
2833 mLastFreezeDuration = 0;
2834 setDisplayLayoutNeeded();
2835 return true;
2836 }
2837
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002838 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2839 boolean destroyedSomething = false;
Jorim Jaggi59f3e922018-01-05 15:40:32 +01002840
2841 // Copying to a different list as multiple children can be removed.
2842 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
2843 for (int i = childWindows.size() - 1; i >= 0; --i) {
2844 final WindowState c = childWindows.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002845 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2846 }
2847
Robert Carrdb2f6e62017-03-01 20:17:58 -08002848 if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) {
2849 return destroyedSomething;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002850 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08002851
2852 if (appStopped || mWindowRemovalAllowed) {
2853 mWinAnimator.destroyPreservedSurfaceLocked();
2854 }
2855
2856 if (mDestroying) {
2857 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2858 + " destroySurfaces: appStopped=" + appStopped
2859 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2860 + " win.mRemoveOnExit=" + mRemoveOnExit);
2861 if (!cleanupOnResume || mRemoveOnExit) {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002862 destroySurfaceUnchecked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08002863 }
2864 if (mRemoveOnExit) {
2865 removeImmediately();
2866 }
2867 if (cleanupOnResume) {
2868 requestUpdateWallpaperIfNeeded();
2869 }
2870 mDestroying = false;
2871 destroyedSomething = true;
2872 }
2873
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002874 return destroyedSomething;
2875 }
Chris Craik3131bde2016-05-06 13:39:08 -07002876
Robert Carr89a28ab2017-04-24 15:33:11 -07002877 // Destroy or save the application surface without checking
2878 // various indicators of whether the client has released the surface.
2879 // This is in general unsafe, and most callers should use {@link #destroySurface}
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002880 void destroySurfaceUnchecked() {
2881 mWinAnimator.destroySurfaceLocked();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002882
Chong Zhang92147042016-05-09 12:47:11 -07002883 // Clear animating flags now, since the surface is now gone. (Note this is true even
2884 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2885 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002886 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002887
Craig Mautner69b08182012-09-05 13:07:13 -07002888 @Override
2889 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002890 final DisplayContent displayContent = getDisplayContent();
2891 if (displayContent == null) {
2892 // Only a window that was on a non-default display can be detached from it.
2893 return false;
2894 }
Winson Chung47a3e652014-05-21 16:03:42 -07002895 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002896 }
2897
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002898 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07002899 mShowToOwnerOnly = showToOwnerOnly;
2900 }
2901
Wale Ogunwaleea92d972016-12-08 07:33:13 -08002902 private boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002903 // Child windows are evaluated based on their parent window.
2904 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002905 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale72919d22016-12-08 18:58:50 -08002906 && win.mAppToken != null && win.mAppToken.mShowForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002907
2908 // All window frames that are fullscreen extend above status bar, but some don't extend
2909 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2910 // bottom right.
2911 if (win.mFrame.left <= win.mDisplayFrame.left
2912 && win.mFrame.top <= win.mDisplayFrame.top
2913 && win.mFrame.right >= win.mStableFrame.right
2914 && win.mFrame.bottom >= win.mStableFrame.bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002915 // Is a fullscreen window, like the clock alarm. Show to everyone.
2916 return false;
2917 }
2918 }
2919
Craig Mautner341220f2012-10-16 15:20:09 -07002920 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01002921 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002922 }
2923
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002924 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2925 outRegion.set(
2926 frame.left + inset.left, frame.top + inset.top,
2927 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002928 }
2929
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002930 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002931 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002932 switch (mTouchableInsets) {
2933 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002934 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002935 outRegion.set(frame);
2936 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002937 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002938 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002939 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002940 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002941 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002942 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002943 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002944 outRegion.set(mGivenTouchableRegion);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002945 outRegion.translate(frame.left, frame.top);
2946 break;
2947 }
2948 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002949 cropRegionToStackBoundsIfNeeded(outRegion);
2950 }
2951
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002952 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002953 final Task task = getTask();
2954 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002955 return;
2956 }
2957
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002958 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002959 if (stack == null) {
2960 return;
2961 }
2962
2963 stack.getDimBounds(mTmpRect);
2964 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002965 }
2966
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002967 /**
2968 * Report a focus change. Must be called with no locks held, and consistently
2969 * from the same serialized thread (such as dispatched from a handler).
2970 */
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07002971 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002972 try {
2973 mClient.windowFocusChanged(focused, inTouchMode);
2974 } catch (RemoteException e) {
2975 }
2976 if (mFocusCallbacks != null) {
2977 final int N = mFocusCallbacks.beginBroadcast();
2978 for (int i=0; i<N; i++) {
2979 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2980 try {
2981 if (focused) {
2982 obs.focusGained(mWindowId.asBinder());
2983 } else {
2984 obs.focusLost(mWindowId.asBinder());
2985 }
2986 } catch (RemoteException e) {
2987 }
2988 }
2989 mFocusCallbacks.finishBroadcast();
2990 }
2991 }
2992
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002993 @Override
2994 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002995 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002996 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002997 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002998
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002999 return super.getConfiguration();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07003000 }
3001
Craig Mautnerdf88d732014-01-27 09:21:32 -08003002 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003003 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08003004 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003005 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
3006 + ": " + mCompatFrame);
Bryce Leef858b572017-06-29 14:03:33 -07003007 final MergedConfiguration mergedConfiguration =
3008 new MergedConfiguration(mService.mRoot.getConfiguration(),
3009 getMergedOverrideConfiguration());
3010
Bryce Lee2b17afd2017-09-21 10:38:20 -07003011 setLastReportedMergedConfiguration(mergedConfiguration);
Bryce Leef858b572017-06-29 14:03:33 -07003012
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003013 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003014 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
3015
Craig Mautnerdf88d732014-01-27 09:21:32 -08003016 final Rect frame = mFrame;
3017 final Rect overscanInsets = mLastOverscanInsets;
3018 final Rect contentInsets = mLastContentInsets;
3019 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07003020 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003021 final Rect outsets = mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003022 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003023 final boolean reportOrientation = mReportOrientationChanged;
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003024 final int displayId = getDisplayId();
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01003025 final DisplayCutout displayCutout = mDisplayCutout.getDisplayCutout();
Chet Haase8eb48d22014-09-24 07:31:29 -07003026 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
3027 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08003028 // To prevent deadlock simulate one-way call if win.mClient is a local object.
3029 mService.mH.post(new Runnable() {
3030 @Override
3031 public void run() {
3032 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003033 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003034 stableInsets, outsets, reportDraw, mergedConfiguration,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003035 reportOrientation, displayId, displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003036 } catch (RemoteException e) {
3037 // Not a remote call, RemoteException won't be raised.
3038 }
3039 }
3040 });
3041 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003042 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003043 outsets, reportDraw, mergedConfiguration, reportOrientation, displayId,
3044 displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003045 }
Svetoslav4604abc2014-06-10 18:59:30 -07003046
3047 //TODO (multidisplay): Accessibility supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07003048 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07003049 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07003050 }
3051
Craig Mautnerdf88d732014-01-27 09:21:32 -08003052 mOverscanInsetsChanged = false;
3053 mContentInsetsChanged = false;
3054 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07003055 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003056 mOutsetsChanged = false;
Robert Carr31aa98b2016-07-20 15:29:03 -07003057 mFrameSizeChanged = false;
Adrian Roos5c6b6222017-11-07 17:36:10 +01003058 mDisplayCutoutChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003059 mWinAnimator.mSurfaceResized = false;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003060 mReportOrientationChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003061 } catch (RemoteException e) {
Bryce Lee8c3cf382017-07-06 19:47:10 -07003062 setOrientationChanging(false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003063 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
3064 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08003065 // We are assuming the hosting process is dead or in a zombie state.
3066 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
3067 + ", removing this window.");
3068 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07003069 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003070 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003071 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003072 }
3073
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003074 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08003075 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
3076 // start even if we haven't received the relayout window, so that the client requests
3077 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
3078 // until the window to small size, otherwise the multithread renderer will shift last
3079 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
3080 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003081 boolean resizing = isDragResizing() || isDragResizeChanged();
Wale Ogunwale3382ab12017-07-27 08:55:03 -07003082 if (getWindowConfiguration().useWindowFrameForBackdrop() || !resizing) {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003083 return frame;
3084 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07003085 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003086 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003087 return mTmpRect;
3088 }
3089
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003090 private int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003091 final TaskStack stack = getStack();
3092 if (stack == null) {
3093 return INVALID_STACK_ID;
3094 }
3095 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003096 }
3097
3098 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
3099 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003100 MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId,
3101 DisplayCutout displayCutout)
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003102 throws RemoteException {
Robert Carr09286c92018-02-15 13:52:31 -08003103 final boolean forceRelayout = isDragResizeChanged() || reportOrientation;
Chong Zhangedaf3052016-04-22 15:04:31 -07003104
Jorim Jaggidc249c42015-12-15 14:57:31 -08003105 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003106 reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003107 mPolicy.isNavBarForcedShownLw(this), displayId,
3108 new DisplayCutout.ParcelableWrapper(displayCutout));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003109 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003110 }
3111
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003112 public void registerFocusObserver(IWindowFocusObserver observer) {
3113 synchronized(mService.mWindowMap) {
3114 if (mFocusCallbacks == null) {
3115 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
3116 }
3117 mFocusCallbacks.register(observer);
3118 }
3119 }
3120
3121 public void unregisterFocusObserver(IWindowFocusObserver observer) {
3122 synchronized(mService.mWindowMap) {
3123 if (mFocusCallbacks != null) {
3124 mFocusCallbacks.unregister(observer);
3125 }
3126 }
3127 }
3128
3129 public boolean isFocused() {
3130 synchronized(mService.mWindowMap) {
3131 return mService.mCurrentFocus == this;
3132 }
3133 }
3134
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003135 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07003136 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003137 final Task task = getTask();
3138 return task != null && !task.isFullscreen();
3139 }
3140
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003141 /** Is this window in a container that takes up the entire screen space? */
3142 private boolean inFullscreenContainer() {
Bryce Leef3c6a472017-11-14 14:53:06 -08003143 return mAppToken == null || (mAppToken.matchParentBounds() && !isInMultiWindowMode());
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003144 }
3145
Andrii Kulian283acd22017-08-03 04:03:51 -07003146 /** @return true when the window is in fullscreen task, but has non-fullscreen bounds set. */
3147 boolean isLetterboxedAppWindow() {
Adrian Roos865c70f2018-01-10 17:32:27 +01003148 return !isInMultiWindowMode() && mAppToken != null && !mAppToken.matchParentBounds()
3149 || isLetterboxedForDisplayCutoutLw();
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003150 }
3151
Adrian Roos865c70f2018-01-10 17:32:27 +01003152 @Override
3153 public boolean isLetterboxedForDisplayCutoutLw() {
3154 if (mAppToken == null) {
3155 // Only windows with an AppWindowToken are letterboxed.
3156 return false;
3157 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003158 if (!mParentFrameWasClippedByDisplayCutout) {
3159 // Cutout didn't make a difference, no letterbox
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003160 return false;
3161 }
Adrian Roosfa02da62018-01-15 16:01:18 +01003162 if (mAttrs.layoutInDisplayCutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003163 // Layout in cutout, no letterbox.
3164 return false;
3165 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003166 if (!mAttrs.isFullscreen()) {
3167 // Not filling the parent frame, no letterbox
3168 return false;
Adrian Roosfa02da62018-01-15 16:01:18 +01003169 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003170 // Otherwise we need a letterbox if the layout was smaller than the app window token allowed
3171 // it to be.
3172 return !frameCoversEntireAppTokenBounds();
3173 }
3174
3175 /**
3176 * @return true if this window covers the entire bounds of its app window token
3177 * @throws NullPointerException if there is no app window token for this window
3178 */
3179 private boolean frameCoversEntireAppTokenBounds() {
3180 mTmpRect.set(mAppToken.getBounds());
3181 mTmpRect.intersectUnchecked(mFrame);
3182 return mAppToken.getBounds().equals(mTmpRect);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003183 }
3184
Adrian Roos23df3a32018-03-15 15:41:13 +01003185 @Override
3186 public boolean isLetterboxedOverlappingWith(Rect rect) {
3187 return mAppToken != null && mAppToken.isLetterboxOverlappingWith(rect);
3188 }
3189
Chong Zhang3005e752015-09-18 18:46:28 -07003190 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003191 return mDragResizing != computeDragResizing();
3192 }
3193
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003194 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003195 void setWaitingForDrawnIfResizingChanged() {
3196 if (isDragResizeChanged()) {
3197 mService.mWaitingForDrawn.add(this);
3198 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003199 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003200 }
3201
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003202 /**
3203 * @return Whether we reported a drag resize change to the application or not already.
3204 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003205 private boolean isDragResizingChangeReported() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003206 return mDragResizingChangeReported;
3207 }
3208
3209 /**
3210 * Resets the state whether we reported a drag resize change to the app.
3211 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003212 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003213 void resetDragResizingChangeReported() {
3214 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003215 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003216 }
3217
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003218 int getResizeMode() {
3219 return mResizeMode;
3220 }
3221
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003222 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003223 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003224 if (task == null) {
3225 return false;
3226 }
Tomasz Mikolajewskiaf20b8d2017-11-20 16:11:33 +09003227 if (!inSplitScreenWindowingMode() && !inFreeformWindowingMode()) {
Winson Chung2af04b32017-01-24 16:21:13 -08003228 return false;
3229 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003230 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003231 // Floating windows never enter drag resize mode.
3232 return false;
3233 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003234 if (task.isDragResizing()) {
3235 return true;
3236 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003237
3238 // If the bounds are currently frozen, it means that the layout size that the app sees
3239 // and the bounds we clip this window to might be different. In order to avoid holes, we
3240 // simulate that we are still resizing so the app fills the hole with the resizing
3241 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003242 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003243 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003244 !task.inFreeformWindowingMode() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003245
Chong Zhang3005e752015-09-18 18:46:28 -07003246 }
3247
3248 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003249 final boolean resizing = computeDragResizing();
3250 if (resizing == mDragResizing) {
3251 return;
3252 }
3253 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003254 final Task task = getTask();
3255 if (task != null && task.isDragResizing()) {
3256 mResizeMode = task.getDragResizeMode();
3257 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003258 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003259 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3260 : DRAG_RESIZE_MODE_FREEFORM;
3261 }
Chong Zhang3005e752015-09-18 18:46:28 -07003262 }
3263
3264 boolean isDragResizing() {
3265 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003266 }
3267
Robert Carr2487ce72016-04-07 15:18:45 -07003268 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003269 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3270 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003271 }
3272
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07003273 @CallSuper
3274 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02003275 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003276 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02003277 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003278 writeIdentifierToProto(proto, IDENTIFIER);
3279 proto.write(DISPLAY_ID, getDisplayId());
3280 proto.write(STACK_ID, getStackId());
3281 mAttrs.writeToProto(proto, ATTRIBUTES);
3282 mGivenContentInsets.writeToProto(proto, GIVEN_CONTENT_INSETS);
3283 mFrame.writeToProto(proto, FRAME);
3284 mContainingFrame.writeToProto(proto, CONTAINING_FRAME);
3285 mParentFrame.writeToProto(proto, PARENT_FRAME);
3286 mContentFrame.writeToProto(proto, CONTENT_FRAME);
3287 mContentInsets.writeToProto(proto, CONTENT_INSETS);
3288 mAttrs.surfaceInsets.writeToProto(proto, SURFACE_INSETS);
Jorim Jaggi45be1c4c2017-12-15 18:44:43 +01003289 mSurfacePosition.writeToProto(proto, SURFACE_POSITION);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003290 mWinAnimator.writeToProto(proto, ANIMATOR);
3291 proto.write(ANIMATING_EXIT, mAnimatingExit);
3292 for (int i = 0; i < mChildren.size(); i++) {
Adrian Roos4921ccf2017-09-28 16:54:06 +02003293 mChildren.get(i).writeToProto(proto, CHILD_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003294 }
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003295 proto.write(REQUESTED_WIDTH, mRequestedWidth);
3296 proto.write(REQUESTED_HEIGHT, mRequestedHeight);
3297 proto.write(VIEW_VISIBILITY, mViewVisibility);
3298 proto.write(SYSTEM_UI_VISIBILITY, mSystemUiVisibility);
3299 proto.write(HAS_SURFACE, mHasSurface);
3300 proto.write(IS_READY_FOR_DISPLAY, isReadyForDisplay());
3301 mDisplayFrame.writeToProto(proto, DISPLAY_FRAME);
3302 mOverscanFrame.writeToProto(proto, OVERSCAN_FRAME);
3303 mVisibleFrame.writeToProto(proto, VISIBLE_FRAME);
3304 mDecorFrame.writeToProto(proto, DECOR_FRAME);
3305 mOutsetFrame.writeToProto(proto, OUTSET_FRAME);
3306 mOverscanInsets.writeToProto(proto, OVERSCAN_INSETS);
3307 mVisibleInsets.writeToProto(proto, VISIBLE_INSETS);
3308 mStableInsets.writeToProto(proto, STABLE_INSETS);
3309 mOutsets.writeToProto(proto, OUTSETS);
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01003310 mDisplayCutout.getDisplayCutout().writeToProto(proto, CUTOUT);
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003311 proto.write(REMOVE_ON_EXIT, mRemoveOnExit);
3312 proto.write(DESTROYING, mDestroying);
3313 proto.write(REMOVED, mRemoved);
3314 proto.write(IS_ON_SCREEN, isOnScreen());
3315 proto.write(IS_VISIBLE, isVisible());
Adrian Roos2cadc5c2018-07-06 02:39:54 -07003316 if (mForceSeamlesslyRotate) {
3317 proto.write(PENDING_FORCED_SEAMLESS_ROTATION, mPendingForcedSeamlessRotate != null);
3318 proto.write(FINISHED_FORCED_SEAMLESS_ROTATION_FRAME,
3319 mFinishForcedSeamlessRotateFrameNumber);
3320 }
Steven Timotiusaf03df62017-07-18 16:56:43 -07003321 proto.end(token);
3322 }
3323
Vishnu Nair9a3e4062018-01-11 08:42:54 -08003324 @Override
3325 public void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003326 final long token = proto.start(fieldId);
3327 proto.write(HASH_CODE, System.identityHashCode(this));
3328 proto.write(USER_ID, UserHandle.getUserId(mOwnerUid));
3329 final CharSequence title = getWindowTag();
3330 if (title != null) {
3331 proto.write(TITLE, title.toString());
3332 }
3333 proto.end(token);
3334 }
3335
Jorim Jaggia5e10572017-11-15 14:36:26 +01003336 @Override
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003337 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003338 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003339 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003340 if (stack != null) {
3341 pw.print(" stackId="); pw.print(stack.mStackId);
3342 }
Craig Mautner59c00972012-07-30 12:10:24 -07003343 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003344 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07003345 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08003346 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
3347 pw.print(" package="); pw.print(mAttrs.packageName);
3348 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Jorim Jaggi484851b2017-09-22 16:03:27 +02003349 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs.toString(prefix));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003350 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
3351 pw.print(" h="); pw.print(mRequestedHeight);
3352 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003353 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
3354 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
3355 pw.print(" h="); pw.println(mLastRequestedHeight);
3356 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003357 if (mIsChildWindow || mLayoutAttached) {
3358 pw.print(prefix); pw.print("mParentWindow="); pw.print(getParentWindow());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003359 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
3360 }
3361 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
3362 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
3363 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
3364 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
3365 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
3366 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003367 if (dumpAll) {
3368 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3369 pw.print(" mSubLayer="); pw.print(mSubLayer);
3370 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautnerc2f9be02012-03-27 17:32:29 -07003371 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
3372 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003373 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003374 if (dumpAll) {
3375 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003376 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003377 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
3378 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Bryce Lee6311c4b2017-07-06 14:09:29 -07003379 pw.print(" mAppDied=");pw.print(mAppDied);
3380 pw.print(prefix); pw.print("drawnStateEvaluated=");
3381 pw.print(getDrawnStateEvaluated());
3382 pw.print(prefix); pw.print("mightAffectAllDrawn=");
Jorim Jaggie7d2b852017-08-28 17:55:15 +02003383 pw.println(mightAffectAllDrawn());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003384 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003385 pw.print(prefix); pw.print("mViewVisibility=0x");
3386 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003387 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
3388 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07003389 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
3390 pw.print(" mSystemUiVisibility=0x");
3391 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003392 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003393 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
Suprabh Shukla69c71422018-04-02 18:39:01 -07003394 || isParentWindowHidden()|| mPermanentlyHidden || mForceHideNonSystemOverlayWindow
3395 || mHiddenWhileSuspended) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003396 pw.print(prefix); pw.print("mPolicyVisibility=");
3397 pw.print(mPolicyVisibility);
3398 pw.print(" mPolicyVisibilityAfterAnim=");
3399 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003400 pw.print(" mAppOpVisibility=");
3401 pw.print(mAppOpVisibility);
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003402 pw.print(" parentHidden="); pw.print(isParentWindowHidden());
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003403 pw.print(" mPermanentlyHidden="); pw.print(mPermanentlyHidden);
Suprabh Shukla69c71422018-04-02 18:39:01 -07003404 pw.print(" mHiddenWhileSuspended="); pw.print(mHiddenWhileSuspended);
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003405 pw.print(" mForceHideNonSystemOverlayWindow="); pw.println(
3406 mForceHideNonSystemOverlayWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003407 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003408 if (!mRelayoutCalled || mLayoutNeeded) {
3409 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
3410 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003411 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003412 if (dumpAll) {
3413 pw.print(prefix); pw.print("mGivenContentInsets=");
3414 mGivenContentInsets.printShortString(pw);
3415 pw.print(" mGivenVisibleInsets=");
3416 mGivenVisibleInsets.printShortString(pw);
3417 pw.println();
3418 if (mTouchableInsets != 0 || mGivenInsetsPending) {
3419 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
3420 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003421 Region region = new Region();
3422 getTouchableRegion(region);
3423 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003424 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003425 pw.print(prefix); pw.print("mFullConfiguration="); pw.println(getConfiguration());
3426 pw.print(prefix); pw.print("mLastReportedConfiguration=");
Bryce Lee2b17afd2017-09-21 10:38:20 -07003427 pw.println(getLastReportedConfiguration());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003428 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07003429 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Chong Zhanga8975bd2016-01-28 17:13:47 -08003430 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08003431 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003432 if (dumpAll) {
3433 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
3434 pw.print(" last="); mLastFrame.printShortString(pw);
3435 pw.println();
3436 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003437 if (mEnforceSizeCompat) {
3438 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003439 pw.println();
3440 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003441 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003442 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003443 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003444 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003445 pw.println();
3446 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
3447 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003448 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003449 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003450 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003451 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04003452 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
3453 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003454 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
3455 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003456 pw.print(prefix); pw.print("Cur insets: overscan=");
3457 mOverscanInsets.printShortString(pw);
3458 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003459 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003460 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003461 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003462 pw.print(" outsets="); mOutsets.printShortString(pw);
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01003463 pw.print(" cutout=" + mDisplayCutout.getDisplayCutout());
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003464 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003465 pw.print(prefix); pw.print("Lst insets: overscan=");
3466 mLastOverscanInsets.printShortString(pw);
3467 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003468 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003469 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003470 pw.print(" physical="); mLastOutsets.printShortString(pw);
3471 pw.print(" outset="); mLastOutsets.printShortString(pw);
Adrian Roos5c6b6222017-11-07 17:36:10 +01003472 pw.print(" cutout=" + mLastDisplayCutout);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003473 pw.println();
3474 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01003475 super.dump(pw, prefix, dumpAll);
Dianne Hackborn529e7442012-11-01 14:22:28 -07003476 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
3477 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003478 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
3479 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003480 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
3481 pw.print(" mDestroying="); pw.print(mDestroying);
3482 pw.print(" mRemoved="); pw.println(mRemoved);
3483 }
chaviw40234662018-02-07 09:37:16 -08003484 if (getOrientationChanging() || mAppFreezing || mReportOrientationChanged) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003485 pw.print(prefix); pw.print("mOrientationChanging=");
3486 pw.print(mOrientationChanging);
Bryce Lee8c3cf382017-07-06 19:47:10 -07003487 pw.print(" configOrientationChanging=");
Bryce Lee2b17afd2017-09-21 10:38:20 -07003488 pw.print(getLastReportedConfiguration().orientation
Bryce Lee8c3cf382017-07-06 19:47:10 -07003489 != getConfiguration().orientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003490 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
Andrii Kulianb2e37802017-01-11 00:36:44 -08003491 pw.print(" mReportOrientationChanged="); pw.println(mReportOrientationChanged);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003492 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003493 if (mLastFreezeDuration != 0) {
3494 pw.print(prefix); pw.print("mLastFreezeDuration=");
3495 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
3496 }
Adrian Roos2cadc5c2018-07-06 02:39:54 -07003497 if (mForceSeamlesslyRotate) {
3498 pw.print(prefix); pw.print("forceSeamlesslyRotate: pending=");
3499 if (mPendingForcedSeamlessRotate != null) {
3500 mPendingForcedSeamlessRotate.dump(pw);
3501 } else {
3502 pw.print("null");
3503 }
3504 pw.print(" finishedFrameNumber="); pw.print(mFinishForcedSeamlessRotateFrameNumber);
3505 pw.println();
3506 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003507 if (mHScale != 1 || mVScale != 1) {
3508 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
3509 pw.print(" mVScale="); pw.println(mVScale);
3510 }
3511 if (mWallpaperX != -1 || mWallpaperY != -1) {
3512 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
3513 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
3514 }
3515 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
3516 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
3517 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
3518 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003519 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3520 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
3521 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
3522 pw.print(mWallpaperDisplayOffsetX);
3523 pw.print(" mWallpaperDisplayOffsetY=");
3524 pw.println(mWallpaperDisplayOffsetY);
3525 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003526 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07003527 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003528 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003529 if (isDragResizing()) {
3530 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
3531 }
3532 if (computeDragResizing()) {
3533 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
3534 }
Bryce Lee6311c4b2017-07-06 14:09:29 -07003535 pw.print(prefix); pw.println("isOnScreen=" + isOnScreen());
3536 pw.print(prefix); pw.println("isVisible=" + isVisible());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003537 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003538
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003539 @Override
3540 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003541 return Integer.toHexString(System.identityHashCode(this))
Jorim Jaggia5e10572017-11-15 14:36:26 +01003542 + " " + getWindowTag();
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003543 }
3544
Robert Carra1eb4392015-12-10 12:43:51 -08003545 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003546 CharSequence tag = mAttrs.getTitle();
3547 if (tag == null || tag.length() <= 0) {
3548 tag = mAttrs.packageName;
3549 }
3550 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003551 }
3552
3553 @Override
3554 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003555 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003556 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003557 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003558 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003559 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003560 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003561 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003562 }
3563 return mStringNameCache;
3564 }
Robert Carr58f29132015-10-29 14:19:05 -07003565
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003566 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003567 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003568 clipRect.left = (int) (clipRect.left / mHScale);
3569 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003570 }
3571 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003572 clipRect.top = (int) (clipRect.top / mVScale);
3573 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003574 }
3575 }
Robert Carr31e28482015-12-02 16:53:18 -08003576
Jorim Jaggif5834272016-04-04 20:25:41 -07003577 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
3578 final int pw = containingFrame.width();
3579 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003580 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003581 final boolean inNonFullscreenContainer = !inFullscreenContainer();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003582 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3583
3584 // We need to fit it to the display if either
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003585 // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen
3586 // for the taskless windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003587 // 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 -07003588 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on
3589 // screen, but SurfaceViews want to be always at a specific location so we don't fit it to
3590 // the display.
3591 final boolean fitToDisplay = (task == null || !inNonFullscreenContainer)
Robert Carr6f44db12016-07-21 14:54:43 -07003592 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003593 float x, y;
3594 int w,h;
3595
3596 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3597 if (mAttrs.width < 0) {
3598 w = pw;
3599 } else if (mEnforceSizeCompat) {
3600 w = (int)(mAttrs.width * mGlobalScale + .5f);
3601 } else {
3602 w = mAttrs.width;
3603 }
3604 if (mAttrs.height < 0) {
3605 h = ph;
3606 } else if (mEnforceSizeCompat) {
3607 h = (int)(mAttrs.height * mGlobalScale + .5f);
3608 } else {
3609 h = mAttrs.height;
3610 }
3611 } else {
3612 if (mAttrs.width == MATCH_PARENT) {
3613 w = pw;
3614 } else if (mEnforceSizeCompat) {
3615 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3616 } else {
3617 w = mRequestedWidth;
3618 }
3619 if (mAttrs.height == MATCH_PARENT) {
3620 h = ph;
3621 } else if (mEnforceSizeCompat) {
3622 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3623 } else {
3624 h = mRequestedHeight;
3625 }
3626 }
3627
3628 if (mEnforceSizeCompat) {
3629 x = mAttrs.x * mGlobalScale;
3630 y = mAttrs.y * mGlobalScale;
3631 } else {
3632 x = mAttrs.x;
3633 y = mAttrs.y;
3634 }
3635
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003636 if (inNonFullscreenContainer && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003637 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003638 // required by {@link Gravity#apply} call.
3639 w = Math.min(w, pw);
3640 h = Math.min(h, ph);
3641 }
3642
3643 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003644 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003645 (int) (x + mAttrs.horizontalMargin * pw),
3646 (int) (y + mAttrs.verticalMargin * ph), mFrame);
3647
3648 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003649 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003650 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003651 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003652
3653 // We need to make sure we update the CompatFrame as it is used for
3654 // cropping decisions, etc, on systems where we lack a decor layer.
3655 mCompatFrame.set(mFrame);
3656 if (mEnforceSizeCompat) {
3657 // See comparable block in computeFrameLw.
3658 mCompatFrame.scale(mInvGlobalScale);
3659 }
Robert Carr31e28482015-12-02 16:53:18 -08003660 }
Robert Carr51a1b872015-12-08 14:03:13 -08003661
3662 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003663 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003664 }
3665
Robert Carrf3b72c72016-03-21 18:16:39 -07003666 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003667 return mIsChildWindow
3668 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003669 }
3670
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003671 /**
3672 * Returns true if any window added by an application process that if of type
3673 * {@link android.view.WindowManager.LayoutParams#TYPE_TOAST} or that requires that requires
3674 * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when
3675 * this window is visible.
3676 */
3677 boolean hideNonSystemOverlayWindowsWhenVisible() {
3678 return (mAttrs.privateFlags & PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != 0
3679 && mSession.mCanHideNonSystemOverlayWindows;
3680 }
3681
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003682 /** Returns the parent window if this is a child of another window, else null. */
3683 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003684 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3685 // WindowContainer that isn't a WindowState.
3686 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003687 }
3688
3689 /** Returns the topmost parent window if this is a child of another window, else this. */
3690 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003691 WindowState current = this;
3692 WindowState topParent = current;
3693 while (current != null && current.mIsChildWindow) {
3694 current = current.getParentWindow();
3695 // Parent window can be null if the child is detached from it's parent already, but
3696 // someone still has a reference to access it. So, we return the top parent value we
3697 // already have instead of null.
3698 if (current != null) {
3699 topParent = current;
3700 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003701 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003702 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003703 }
3704
Wale Ogunwale9d147902016-07-16 11:58:55 -07003705 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003706 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003707 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003708 }
3709
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003710 void setWillReplaceWindow(boolean animate) {
3711 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003712 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003713 c.setWillReplaceWindow(animate);
3714 }
3715
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003716 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3717 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3718 // We don't set replacing on starting windows since they are added by window manager and
3719 // not the client so won't be replaced by the client.
3720 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003721 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003722
3723 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003724 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003725 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003726 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003727
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003728 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003729 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003730 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003731 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003732
3733 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003734 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003735 c.clearWillReplaceWindow();
3736 }
3737 }
3738
3739 boolean waitingForReplacement() {
3740 if (mWillReplaceWindow) {
3741 return true;
3742 }
3743
3744 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003745 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003746 if (c.waitingForReplacement()) {
3747 return true;
3748 }
3749 }
3750 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003751 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003752
Chong Zhang4d7369a2016-04-25 16:09:14 -07003753 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003754 final DisplayContent dc = getDisplayContent();
3755 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3756 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3757 dc.setLayoutNeeded();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003758 mService.mWindowPlacerLocked.requestTraversal();
3759 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003760
3761 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003762 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003763 c.requestUpdateWallpaperIfNeeded();
3764 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003765 }
3766
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003767 float translateToWindowX(float x) {
3768 float winX = x - mFrame.left;
3769 if (mEnforceSizeCompat) {
3770 winX *= mGlobalScale;
3771 }
3772 return winX;
3773 }
3774
3775 float translateToWindowY(float y) {
3776 float winY = y - mFrame.top;
3777 if (mEnforceSizeCompat) {
3778 winY *= mGlobalScale;
3779 }
3780 return winY;
3781 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003782
3783 // During activity relaunch due to resize, we sometimes use window replacement
3784 // for only child windows (as the main window is handled by window preservation)
3785 // and the big surface.
3786 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003787 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3788 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3789 // we also want to replace them at such phases, as they won't be covered by window
3790 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003791 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003792 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003793 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003794 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003795
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003796 void setWillReplaceChildWindows() {
3797 if (shouldBeReplacedWithChildren()) {
3798 setWillReplaceWindow(false /* animate */);
3799 }
3800 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003801 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003802 c.setWillReplaceChildWindows();
3803 }
3804 }
3805
3806 WindowState getReplacingWindow() {
3807 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3808 return this;
3809 }
3810 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003811 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003812 final WindowState replacing = c.getReplacingWindow();
3813 if (replacing != null) {
3814 return replacing;
3815 }
3816 }
3817 return null;
3818 }
3819
Jorim Jaggife762342016-10-13 14:33:27 +02003820 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07003821 public int getRotationAnimationHint() {
3822 if (mAppToken != null) {
3823 return mAppToken.mRotationAnimationHint;
3824 } else {
3825 return -1;
3826 }
3827 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003828
Jorim Jaggife762342016-10-13 14:33:27 +02003829 @Override
3830 public boolean isInputMethodWindow() {
3831 return mIsImWindow;
3832 }
3833
Wale Ogunwale9d147902016-07-16 11:58:55 -07003834 // This must be called while inside a transaction.
3835 boolean performShowLocked() {
3836 if (isHiddenFromUserLocked()) {
3837 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3838 hideLw(false);
3839 return false;
3840 }
3841
3842 logPerformShow("performShow on ");
3843
Jorim Jaggia50da602016-12-29 11:51:42 +01003844 final int drawState = mWinAnimator.mDrawState;
3845 if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW)
3846 && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3847 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3848 }
3849
Jorim Jaggib0d27342016-11-01 16:10:42 -07003850 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003851 return false;
3852 }
3853
3854 logPerformShow("Showing ");
3855
3856 mService.enableScreenIfNeededLocked();
3857 mWinAnimator.applyEnterAnimationLocked();
3858
3859 // Force the show in the next prepareSurfaceLocked() call.
3860 mWinAnimator.mLastAlpha = -1;
Robert Carre13b58e2017-08-31 14:50:44 -07003861 if (DEBUG_ANIM) Slog.v(TAG,
Wale Ogunwale9d147902016-07-16 11:58:55 -07003862 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3863 mWinAnimator.mDrawState = HAS_DRAWN;
3864 mService.scheduleAnimationLocked();
3865
3866 if (mHidden) {
3867 mHidden = false;
3868 final DisplayContent displayContent = getDisplayContent();
3869
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003870 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003871 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003872 if (c.mWinAnimator.mSurfaceController != null) {
3873 c.performShowLocked();
3874 // It hadn't been shown, which means layout not performed on it, so now we
3875 // want to make sure to do a layout. If called from within the transaction
3876 // loop, this will cause it to restart with a new layout.
3877 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003878 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003879 }
3880 }
3881 }
3882 }
3883
Wale Ogunwale9d147902016-07-16 11:58:55 -07003884 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003885 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003886 }
3887
3888 return true;
3889 }
3890
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003891 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003892 if (DEBUG_VISIBILITY
Jorim Jaggie4b0f282017-05-17 15:10:29 +02003893 || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003894 Slog.v(TAG, prefix + this
3895 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07003896 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003897 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3898 + " during animation: policyVis=" + mPolicyVisibility
3899 + " parentHidden=" + isParentWindowHidden()
3900 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003901 + (mAppToken != null && mAppToken.hiddenRequested)
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003902 + " tok.hidden=" + (mAppToken != null && mAppToken.isHidden())
Jorim Jaggia5e10572017-11-15 14:36:26 +01003903 + " animationSet=" + mWinAnimator.isAnimationSet()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003904 + " tok animating="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003905 + (mAppToken != null && mAppToken.isSelfAnimating())
Wale Ogunwale9d147902016-07-16 11:58:55 -07003906 + " Callers=" + Debug.getCallers(4));
3907 }
3908 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003909
3910 WindowInfo getWindowInfo() {
3911 WindowInfo windowInfo = WindowInfo.obtain();
3912 windowInfo.type = mAttrs.type;
3913 windowInfo.layer = mLayer;
3914 windowInfo.token = mClient.asBinder();
Phil Weaver5dc3ebc2017-08-16 13:04:20 -07003915 if (mAppToken != null) {
3916 windowInfo.activityToken = mAppToken.appToken.asBinder();
3917 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003918 windowInfo.title = mAttrs.accessibilityTitle;
Phil Weaverbb2f28a2017-12-22 09:44:28 -08003919 // Panel windows have no public way to set the a11y title directly. Use the
3920 // regular title as a fallback.
Phil Weaver568cf662018-04-24 17:09:26 -07003921 final boolean isPanelWindow = (mAttrs.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW)
3922 && (mAttrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW);
3923 // Accessibility overlays should have titles that work for accessibility, and can't set
3924 // the a11y title themselves.
3925 final boolean isAccessibilityOverlay =
3926 windowInfo.type == WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
3927 if (TextUtils.isEmpty(windowInfo.title) && (isPanelWindow || isAccessibilityOverlay)) {
Phil Weaverbb2f28a2017-12-22 09:44:28 -08003928 windowInfo.title = mAttrs.getTitle();
3929 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003930 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3931 windowInfo.focused = isFocused();
Phil Weaverf00cd142017-03-03 13:44:00 -08003932 Task task = getTask();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003933 windowInfo.inPictureInPicture = (task != null) && task.inPinnedWindowingMode();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003934
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003935 if (mIsChildWindow) {
3936 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003937 }
3938
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003939 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003940 if (childCount > 0) {
3941 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003942 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003943 }
3944 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003945 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003946 windowInfo.childTokens.add(child.mClient.asBinder());
3947 }
3948 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003949 return windowInfo;
3950 }
3951
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003952 int getHighestAnimLayer() {
3953 int highest = mWinAnimator.mAnimLayer;
3954 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003955 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003956 final int childLayer = c.getHighestAnimLayer();
3957 if (childLayer > highest) {
3958 highest = childLayer;
3959 }
3960 }
3961 return highest;
3962 }
3963
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003964 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003965 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003966 if (mChildren.isEmpty()) {
3967 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003968 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003969 }
3970
3971 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003972 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003973 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003974 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003975 }
3976 }
3977
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003978 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003979 // We want to consume the negative sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003980 // below the parent, then this window (the parent), and then the positive sublayer children
3981 // because they need to appear above the parent.
3982 int i = 0;
3983 final int count = mChildren.size();
3984 WindowState child = mChildren.get(i);
3985
3986 while (i < count && child.mSubLayer < 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003987 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003988 return true;
3989 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003990 i++;
3991 if (i >= count) {
3992 break;
3993 }
3994 child = mChildren.get(i);
3995 }
3996
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003997 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003998 return true;
3999 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004000
4001 while (i < count) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004002 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004003 return true;
4004 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004005 i++;
4006 if (i >= count) {
4007 break;
4008 }
4009 child = mChildren.get(i);
4010 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004011
4012 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004013 }
4014
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004015 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004016 // We want to consume the positive sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004017 // above the parent, then this window (the parent), and then the negative sublayer children
4018 // because they need to appear above the parent.
4019 int i = mChildren.size() - 1;
4020 WindowState child = mChildren.get(i);
4021
4022 while (i >= 0 && child.mSubLayer >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004023 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004024 return true;
4025 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004026 --i;
4027 if (i < 0) {
4028 break;
4029 }
4030 child = mChildren.get(i);
4031 }
4032
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004033 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004034 return true;
4035 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004036
4037 while (i >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004038 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004039 return true;
4040 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004041 --i;
4042 if (i < 0) {
4043 break;
4044 }
4045 child = mChildren.get(i);
4046 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004047
4048 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004049 }
4050
Robert Carr9785cf32018-04-25 15:06:07 -07004051 private boolean applyImeWindowsIfNeeded(ToBooleanFunction<WindowState> callback,
4052 boolean traverseTopToBottom) {
4053 // If this window is the current IME target, so we need to process the IME windows
4054 // directly above it. The exception is if we are in split screen
4055 // in which case we process the IME at the DisplayContent level to
4056 // ensure it is above the docked divider.
4057 if (isInputMethodTarget() && !inSplitScreenWindowingMode()) {
4058 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
4059 return true;
4060 }
4061 }
4062 return false;
4063 }
4064
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004065 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
4066 boolean traverseTopToBottom) {
4067 if (traverseTopToBottom) {
Robert Carr9785cf32018-04-25 15:06:07 -07004068 if (applyImeWindowsIfNeeded(callback, traverseTopToBottom)
4069 || callback.apply(this)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004070 return true;
4071 }
4072 } else {
Robert Carr9785cf32018-04-25 15:06:07 -07004073 if (callback.apply(this)
4074 || applyImeWindowsIfNeeded(callback, traverseTopToBottom)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004075 return true;
4076 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004077 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004078 return false;
4079 }
4080
Wale Ogunwaled1880962016-11-08 10:31:59 -08004081 WindowState getWindow(Predicate<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004082 if (mChildren.isEmpty()) {
4083 return callback.test(this) ? this : null;
4084 }
4085
4086 // We want to consume the positive sublayer children first because they need to appear
4087 // above the parent, then this window (the parent), and then the negative sublayer children
4088 // because they need to appear above the parent.
4089 int i = mChildren.size() - 1;
4090 WindowState child = mChildren.get(i);
4091
4092 while (i >= 0 && child.mSubLayer >= 0) {
4093 if (callback.test(child)) {
4094 return child;
4095 }
4096 --i;
4097 if (i < 0) {
4098 break;
4099 }
4100 child = mChildren.get(i);
4101 }
4102
Wale Ogunwaled1880962016-11-08 10:31:59 -08004103 if (callback.test(this)) {
4104 return this;
4105 }
Wale Ogunwale34247952017-02-19 11:57:53 -08004106
4107 while (i >= 0) {
4108 if (callback.test(child)) {
4109 return child;
4110 }
4111 --i;
4112 if (i < 0) {
4113 break;
4114 }
4115 child = mChildren.get(i);
4116 }
4117
4118 return null;
Wale Ogunwaled1880962016-11-08 10:31:59 -08004119 }
4120
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01004121 /**
4122 * @return True if we our one of our ancestors has {@link #mAnimatingExit} set to true, false
4123 * otherwise.
4124 */
4125 @VisibleForTesting
4126 boolean isSelfOrAncestorWindowAnimatingExit() {
4127 WindowState window = this;
4128 do {
4129 if (window.mAnimatingExit) {
4130 return true;
4131 }
4132 window = window.getParentWindow();
4133 } while (window != null);
4134 return false;
4135 }
4136
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004137 void onExitAnimationDone() {
4138 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
4139 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
Jorim Jaggia5e10572017-11-15 14:36:26 +01004140 + " selfAnimating=" + isSelfAnimating());
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004141
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004142 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004143 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +01004144 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004145 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004146 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004147 }
4148 }
4149
4150 if (mWinAnimator.mEnteringAnimation) {
4151 mWinAnimator.mEnteringAnimation = false;
4152 mService.requestTraversal();
4153 // System windows don't have an activity and an app token as a result, but need a way
4154 // to be informed about their entrance animation end.
4155 if (mAppToken == null) {
4156 try {
4157 mClient.dispatchWindowShown();
4158 } catch (RemoteException e) {
4159 }
4160 }
4161 }
4162
Jorim Jaggia5e10572017-11-15 14:36:26 +01004163 if (isSelfAnimating()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004164 return;
4165 }
4166
Jorim Jaggia5e10572017-11-15 14:36:26 +01004167 //TODO (multidisplay): Accessibility is supported only for the default display.
4168 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
4169 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
4170 }
4171
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01004172 if (!isSelfOrAncestorWindowAnimatingExit()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004173 return;
4174 }
4175
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07004176 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004177 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
4178
4179 mDestroying = true;
4180
4181 final boolean hasSurface = mWinAnimator.hasSurface();
Jorim Jaggi50575902018-04-10 17:49:30 +02004182
4183 // Use pendingTransaction here so hide is done the same transaction as the other
4184 // animations when exiting
4185 mWinAnimator.hide(getPendingTransaction(), "onExitAnimationDone");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004186
4187 // If we have an app token, we ask it to destroy the surface for us, so that it can take
4188 // care to ensure the activity has actually stopped and the surface is not still in use.
4189 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
4190 // transaction.
4191 if (mAppToken != null) {
4192 mAppToken.destroySurfaces();
4193 } else {
4194 if (hasSurface) {
4195 mService.mDestroySurface.add(this);
4196 }
4197 if (mRemoveOnExit) {
4198 mService.mPendingRemove.add(this);
4199 mRemoveOnExit = false;
4200 }
4201 }
4202 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07004203 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004204 }
Dan Willemsen117197f2016-07-30 13:02:59 -07004205
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004206 boolean clearAnimatingFlags() {
4207 boolean didSomething = false;
4208 // We don't want to clear it out for windows that get replaced, because the
4209 // animation depends on the flag to remove the replaced window.
4210 //
4211 // We also don't clear the mAnimatingExit flag for windows which have the
4212 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4213 // by the client. We should let animation proceed and not clear this flag or
4214 // they won't eventually be removed by WindowStateAnimator#finishExit.
4215 if (!mWillReplaceWindow && !mRemoveOnExit) {
4216 // Clear mAnimating flag together with mAnimatingExit. When animation
4217 // changes from exiting to entering, we need to clear this flag until the
4218 // new animation gets applied, so that isAnimationStarting() becomes true
4219 // until then.
4220 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4221 // placement for this window during this period, one or more frame will
4222 // show up with wrong position or scale.
4223 if (mAnimatingExit) {
4224 mAnimatingExit = false;
4225 didSomething = true;
4226 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004227 if (mDestroying) {
4228 mDestroying = false;
4229 mService.mDestroySurface.remove(this);
4230 didSomething = true;
4231 }
4232 }
4233
4234 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004235 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004236 }
4237
4238 return didSomething;
4239 }
4240
Winson4b4ba902016-07-27 19:45:52 -07004241 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004242 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004243 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004244
4245 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004246 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004247 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004248 c.hideWallpaperWindow(wasDeferred, reason);
4249 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004250 if (!mWinAnimator.mLastHidden || wasDeferred) {
4251 mWinAnimator.hide(reason);
Tiger Huangdf87af82018-05-25 22:57:52 +08004252 getDisplayContent().mWallpaperController.mDeferredHideWallpaper = null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004253 dispatchWallpaperVisibility(false);
4254 final DisplayContent displayContent = getDisplayContent();
4255 if (displayContent != null) {
4256 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
Tiger Huangdf87af82018-05-25 22:57:52 +08004257 if (DEBUG_LAYOUT_REPEATS) {
4258 mService.mWindowPlacerLocked.debugLayoutRepeats("hideWallpaperWindow " + this,
4259 displayContent.pendingLayoutChanges);
4260 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004261 }
4262 }
4263 }
4264
4265 /**
4266 * Check wallpaper window for visibility change and notify window if so.
4267 * @param visible Current visibility.
4268 */
4269 void dispatchWallpaperVisibility(final boolean visible) {
4270 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07004271 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004272
4273 // Only send notification if the visibility actually changed and we are not trying to hide
4274 // the wallpaper when we are deferring hiding of the wallpaper.
4275 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4276 mWallpaperVisible = visible;
4277 try {
4278 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4279 "Updating vis of wallpaper " + this
4280 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4281 mClient.dispatchAppVisibility(visible);
4282 } catch (RemoteException e) {
4283 }
4284 }
4285 }
4286
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004287 boolean hasVisibleNotDrawnWallpaper() {
4288 if (mWallpaperVisible && !isDrawnLw()) {
4289 return true;
4290 }
4291 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004292 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004293 if (c.hasVisibleNotDrawnWallpaper()) {
4294 return true;
4295 }
4296 }
4297 return false;
4298 }
4299
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004300 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4301 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004302 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004303 c.updateReportedVisibility(results);
4304 }
4305
4306 if (mAppFreezing || mViewVisibility != View.VISIBLE
4307 || mAttrs.type == TYPE_APPLICATION_STARTING
4308 || mDestroying) {
4309 return;
4310 }
4311 if (DEBUG_VISIBILITY) {
4312 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
4313 + ", isAnimationSet=" + mWinAnimator.isAnimationSet());
4314 if (!isDrawnLw()) {
4315 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4316 + " pv=" + mPolicyVisibility
4317 + " mDrawState=" + mWinAnimator.mDrawState
4318 + " ph=" + isParentWindowHidden()
4319 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
Jorim Jaggia5e10572017-11-15 14:36:26 +01004320 + " a=" + mWinAnimator.isAnimationSet());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004321 }
4322 }
4323
4324 results.numInteresting++;
4325 if (isDrawnLw()) {
4326 results.numDrawn++;
4327 if (!mWinAnimator.isAnimationSet()) {
4328 results.numVisible++;
4329 }
4330 results.nowGone = false;
4331 } else if (mWinAnimator.isAnimationSet()) {
4332 results.nowGone = false;
4333 }
4334 }
4335
Robert Carr683e05d2018-04-18 15:11:04 -07004336 private boolean skipDecorCrop() {
4337 // The decor frame is used to specify the region not covered by the system
4338 // decorations (nav bar, status bar). In case this is empty, for example with
4339 // FLAG_TRANSLUCENT_NAVIGATION, we don't need to do any cropping.
4340 if (mDecorFrame.isEmpty()) {
4341 return true;
4342 }
4343
4344 // But if we have a frame, and are an application window, then we must be cropped.
4345 if (mAppToken != null) {
4346 return false;
4347 }
4348
4349 // For non application windows, we may be allowed to extend over the decor bars
4350 // depending on our type and permissions assosciated with our token.
4351 return mToken.canLayerAboveSystemBars();
4352 }
4353
Robert Carrfbbde852016-10-18 11:02:28 -07004354 /**
4355 * Calculate the window crop according to system decor policy. In general this is
4356 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4357 * special cases. This rectangle is in screen space.
4358 */
4359 void calculatePolicyCrop(Rect policyCrop) {
4360 final DisplayContent displayContent = getDisplayContent();
4361 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
4362
4363 if (!isDefaultDisplay()) {
4364 // On a different display there is no system decor. Crop the window
4365 // by the screen boundaries.
4366 // TODO(multi-display)
4367 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4368 policyCrop.intersect(-mCompatFrame.left, -mCompatFrame.top,
4369 displayInfo.logicalWidth - mCompatFrame.left,
4370 displayInfo.logicalHeight - mCompatFrame.top);
Robert Carr683e05d2018-04-18 15:11:04 -07004371 } else if (skipDecorCrop()) {
Robert Carrfbbde852016-10-18 11:02:28 -07004372 // Windows without policy decor aren't cropped.
4373 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4374 } else {
4375 // Crop to the system decor specified by policy.
4376 calculateSystemDecorRect(policyCrop);
4377 }
4378 }
4379
4380 /**
4381 * The system decor rect is the region of the window which is not covered
4382 * by system decorations.
4383 */
4384 private void calculateSystemDecorRect(Rect systemDecorRect) {
4385 final Rect decorRect = mDecorFrame;
4386 final int width = mFrame.width();
4387 final int height = mFrame.height();
4388
Robert Carr217e7cc2018-01-31 18:08:39 -08004389 final int left = mFrame.left;
4390 final int top = mFrame.top;
Robert Carrfbbde852016-10-18 11:02:28 -07004391
4392 // Initialize the decor rect to the entire frame.
4393 if (isDockedResizing()) {
4394 // If we are resizing with the divider, the task bounds might be smaller than the
4395 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4396 // want in this case in order to avoid holes.
4397 //
4398 // We take care to not shrink the width, for surfaces which are larger than
4399 // the display region. Of course this area will not eventually be visible
4400 // but if we truncate the width now, we will calculate incorrectly
4401 // when adjusting to the stack bounds.
4402 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4403 systemDecorRect.set(0, 0,
4404 Math.max(width, displayInfo.logicalWidth),
4405 Math.max(height, displayInfo.logicalHeight));
4406 } else {
4407 systemDecorRect.set(0, 0, width, height);
4408 }
4409
4410 // If a freeform window is animating from a position where it would be cutoff, it would be
4411 // cutoff during the animation. We don't want that, so for the duration of the animation
4412 // we ignore the decor cropping and depend on layering to position windows correctly.
chaviw95136622018-04-09 15:20:06 -07004413
4414 // We also ignore cropping when the window is currently being drag resized in split screen
4415 // to prevent issues with the crop for screenshot.
4416 final boolean cropToDecor =
4417 !(inFreeformWindowingMode() && isAnimatingLw()) && !isDockedResizing();
Robert Carrfbbde852016-10-18 11:02:28 -07004418 if (cropToDecor) {
4419 // Intersect with the decor rect, offsetted by window position.
4420 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
4421 decorRect.right - left, decorRect.bottom - top);
4422 }
4423
4424 // If size compatibility is being applied to the window, the
4425 // surface is scaled relative to the screen. Also apply this
4426 // scaling to the crop rect. We aren't using the standard rect
4427 // scale function because we want to round things to make the crop
4428 // always round to a larger rect to ensure we don't crop too
4429 // much and hide part of the window that should be seen.
4430 if (mEnforceSizeCompat && mInvGlobalScale != 1.0f) {
4431 final float scale = mInvGlobalScale;
4432 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
4433 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
4434 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
4435 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
4436 }
4437
4438 }
4439
4440 /**
4441 * Expand the given rectangle by this windows surface insets. This
4442 * takes you from the 'window size' to the 'surface size'.
4443 * The surface insets are positive in each direction, so we inset by
4444 * the inverse.
4445 */
4446 void expandForSurfaceInsets(Rect r) {
4447 r.inset(-mAttrs.surfaceInsets.left,
4448 -mAttrs.surfaceInsets.top,
4449 -mAttrs.surfaceInsets.right,
4450 -mAttrs.surfaceInsets.bottom);
4451 }
4452
Robert Carrc91d1c32017-02-15 19:37:46 -08004453 boolean surfaceInsetsChanging() {
4454 return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets);
4455 }
4456
Bryce Leef858b572017-06-29 14:03:33 -07004457 int relayoutVisibleWindow(int result, int attrChanges, int oldVisibility) {
Robert Carrecc06b32017-04-18 14:25:10 -07004458 final boolean wasVisible = isVisibleLw();
4459
4460 result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0;
Robert Carr7b3d11d2018-03-15 14:34:45 -07004461
Robert Carrc91d1c32017-02-15 19:37:46 -08004462 if (mAnimatingExit) {
4463 Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit="
4464 + mRemoveOnExit + ", mDestroying=" + mDestroying);
4465
4466 mWinAnimator.cancelExitAnimationForNextAnimationLocked();
4467 mAnimatingExit = false;
4468 }
4469 if (mDestroying) {
4470 mDestroying = false;
4471 mService.mDestroySurface.remove(this);
4472 }
4473 if (oldVisibility == View.GONE) {
4474 mWinAnimator.mEnterAnimationPending = true;
4475 }
4476
Andrii Kulian8ee72852017-03-10 10:36:45 -08004477 mLastVisibleLayoutRotation = getDisplayContent().getRotation();
Robert Carrc91d1c32017-02-15 19:37:46 -08004478
4479 mWinAnimator.mEnteringAnimation = true;
Bryce Leeae73ba42017-05-05 09:58:25 -07004480
Bryce Leef858b572017-06-29 14:03:33 -07004481 prepareWindowToDisplayDuringRelayout(wasVisible);
Bryce Leeae73ba42017-05-05 09:58:25 -07004482
Robert Carrc91d1c32017-02-15 19:37:46 -08004483 if ((attrChanges & FORMAT_CHANGED) != 0) {
4484 // If the format can't be changed in place, preserve the old surface until the app draws
4485 // on the new one. This prevents blinking when we change elevation of freeform and
4486 // pinned windows.
4487 if (!mWinAnimator.tryChangeFormatInPlaceLocked()) {
4488 mWinAnimator.preserveSurfaceLocked();
4489 result |= RELAYOUT_RES_SURFACE_CHANGED
4490 | RELAYOUT_RES_FIRST_TIME;
4491 }
4492 }
4493
4494 // When we change the Surface size, in scenarios which may require changing
4495 // the surface position in sync with the resize, we use a preserved surface
4496 // so we can freeze it while waiting for the client to report draw on the newly
Robert Carrc6d5af52018-02-26 17:46:00 -08004497 // sized surface. At the moment this logic is only in place for switching
4498 // in and out of the big surface for split screen resize.
4499 if (isDragResizeChanged()) {
Robert Carrc91d1c32017-02-15 19:37:46 -08004500 setDragResizing();
Robert Carrc91d1c32017-02-15 19:37:46 -08004501 // We can only change top level windows to the full-screen surface when
4502 // resizing (as we only have one full-screen surface). So there is no need
4503 // to preserve and destroy windows which are attached to another, they
4504 // will keep their surface and its size may change over time.
4505 if (mHasSurface && !isChildWindow()) {
4506 mWinAnimator.preserveSurfaceLocked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08004507 result |= RELAYOUT_RES_SURFACE_CHANGED |
4508 RELAYOUT_RES_FIRST_TIME;
Robert Carrc91d1c32017-02-15 19:37:46 -08004509 }
4510 }
4511 final boolean freeformResizing = isDragResizing()
4512 && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
4513 final boolean dockedResizing = isDragResizing()
4514 && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
4515 result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0;
4516 result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004517 return result;
4518 }
4519
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004520 /**
4521 * @return True if this window has been laid out at least once; false otherwise.
4522 */
4523 boolean isLaidOut() {
4524 return mLayoutSeq != -1;
4525 }
4526
4527 /**
4528 * Updates the last inset values to the current ones.
4529 */
4530 void updateLastInsetValues() {
4531 mLastOverscanInsets.set(mOverscanInsets);
4532 mLastContentInsets.set(mContentInsets);
4533 mLastVisibleInsets.set(mVisibleInsets);
4534 mLastStableInsets.set(mStableInsets);
4535 mLastOutsets.set(mOutsets);
Adrian Roos5c6b6222017-11-07 17:36:10 +01004536 mLastDisplayCutout = mDisplayCutout;
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004537 }
4538
Jorim Jaggia5e10572017-11-15 14:36:26 +01004539 void startAnimation(Animation anim) {
4540 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4541 anim.initialize(mFrame.width(), mFrame.height(),
4542 displayInfo.appWidth, displayInfo.appHeight);
4543 anim.restrictDuration(MAX_ANIMATION_DURATION);
4544 anim.scaleCurrentDuration(mService.getWindowAnimationScaleLocked());
4545 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi2e3c31d2017-11-20 19:49:00 +01004546 new WindowAnimationSpec(anim, mSurfacePosition, false /* canSkipFirstFrame */),
4547 mService.mSurfaceAnimationRunner);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004548 startAnimation(mPendingTransaction, adapter);
4549 commitPendingTransaction();
4550 }
4551
chaviw161ea3e2018-01-31 12:01:12 -08004552 private void startMoveAnimation(int left, int top) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01004553 if (DEBUG_ANIM) Slog.v(TAG, "Setting move animation on " + this);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004554 final Point oldPosition = new Point();
4555 final Point newPosition = new Point();
4556 transformFrameToSurfacePosition(mLastFrame.left, mLastFrame.top, oldPosition);
4557 transformFrameToSurfacePosition(left, top, newPosition);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004558 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004559 new MoveAnimationSpec(oldPosition.x, oldPosition.y, newPosition.x, newPosition.y),
Jorim Jaggia5e10572017-11-15 14:36:26 +01004560 mService.mSurfaceAnimationRunner);
chaviw161ea3e2018-01-31 12:01:12 -08004561 startAnimation(getPendingTransaction(), adapter);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004562 }
4563
4564 private void startAnimation(Transaction t, AnimationAdapter adapter) {
4565 startAnimation(t, adapter, mWinAnimator.mLastHidden);
4566 }
4567
4568 @Override
4569 protected void onAnimationFinished() {
4570 mWinAnimator.onAnimationFinished();
4571 }
4572
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004573 /**
4574 * Retrieves the current transformation matrix of the window, relative to the display.
4575 *
4576 * @param float9 A temporary array of 9 floats.
4577 * @param outMatrix Matrix to fill in the transformation.
4578 */
4579 void getTransformationMatrix(float[] float9, Matrix outMatrix) {
4580 float9[Matrix.MSCALE_X] = mWinAnimator.mDsDx;
4581 float9[Matrix.MSKEW_Y] = mWinAnimator.mDtDx;
4582 float9[Matrix.MSKEW_X] = mWinAnimator.mDtDy;
4583 float9[Matrix.MSCALE_Y] = mWinAnimator.mDsDy;
Robert Carr217e7cc2018-01-31 18:08:39 -08004584 int x = mSurfacePosition.x;
4585 int y = mSurfacePosition.y;
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004586
4587 // If changed, also adjust transformFrameToSurfacePosition
4588 final WindowContainer parent = getParent();
4589 if (isChildWindow()) {
4590 final WindowState parentWindow = getParentWindow();
4591 x += parentWindow.mFrame.left - parentWindow.mAttrs.surfaceInsets.left;
4592 y += parentWindow.mFrame.top - parentWindow.mAttrs.surfaceInsets.top;
4593 } else if (parent != null) {
4594 final Rect parentBounds = parent.getBounds();
4595 x += parentBounds.left;
4596 y += parentBounds.top;
4597 }
4598 float9[Matrix.MTRANS_X] = x;
4599 float9[Matrix.MTRANS_Y] = y;
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004600 float9[Matrix.MPERSP_0] = 0;
4601 float9[Matrix.MPERSP_1] = 0;
4602 float9[Matrix.MPERSP_2] = 1;
4603 outMatrix.setValues(float9);
4604 }
4605
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004606 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4607 // access to its windows children. Need to investigate re-writing
4608 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4609 static final class UpdateReportedVisibilityResults {
4610 int numInteresting;
4611 int numVisible;
4612 int numDrawn;
4613 boolean nowGone = true;
4614
4615 void reset() {
4616 numInteresting = 0;
4617 numVisible = 0;
4618 numDrawn = 0;
4619 nowGone = true;
4620 }
4621 }
Robert Carraf422a82017-04-10 18:34:33 -07004622
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004623 private static final class WindowId extends IWindowId.Stub {
4624 private final WeakReference<WindowState> mOuter;
4625
4626 private WindowId(WindowState outer) {
4627
4628 // Use a weak reference for the outer class. This is important to prevent the following
4629 // leak: Since we send this class to the client process, binder will keep it alive as
4630 // long as the client keeps it alive. Now, if the window is removed, we need to clear
4631 // out our reference so even though this class is kept alive we don't leak WindowState,
4632 // which can keep a whole lot of classes alive.
4633 mOuter = new WeakReference<>(outer);
4634 }
4635
4636 @Override
4637 public void registerFocusObserver(IWindowFocusObserver observer) {
4638 final WindowState outer = mOuter.get();
4639 if (outer != null) {
4640 outer.registerFocusObserver(observer);
4641 }
4642 }
4643 @Override
4644 public void unregisterFocusObserver(IWindowFocusObserver observer) {
4645 final WindowState outer = mOuter.get();
4646 if (outer != null) {
4647 outer.unregisterFocusObserver(observer);
4648 }
4649 }
4650 @Override
4651 public boolean isFocused() {
4652 final WindowState outer = mOuter.get();
4653 return outer != null && outer.isFocused();
4654 }
4655 }
4656
Robert Carrb1579c82017-09-05 14:54:47 -07004657
4658 @Override
4659 boolean shouldMagnify() {
4660 if (mAttrs.type == TYPE_INPUT_METHOD ||
Robert Carree4d4b92017-11-22 12:21:46 -08004661 mAttrs.type == TYPE_INPUT_METHOD_DIALOG ||
4662 mAttrs.type == TYPE_MAGNIFICATION_OVERLAY ||
4663 mAttrs.type == TYPE_NAVIGATION_BAR ||
4664 // It's tempting to wonder: Have we forgotten the rounded corners overlay?
4665 // worry not: it's a fake TYPE_NAVIGATION_BAR_PANEL
Eugene Susla31e3bb92018-03-13 12:24:50 -07004666 mAttrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Robert Carrb1579c82017-09-05 14:54:47 -07004667 return false;
4668 }
4669 return true;
4670 }
4671
4672 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004673 SurfaceSession getSession() {
4674 if (mSession.mSurfaceSession != null) {
4675 return mSession.mSurfaceSession;
4676 } else {
4677 return getParent().getSession();
4678 }
4679 }
4680
4681 @Override
4682 boolean needsZBoost() {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00004683 if (mIsImWindow && mService.mInputMethodTarget != null) {
4684 final AppWindowToken appToken = mService.mInputMethodTarget.mAppToken;
4685 if (appToken != null) {
4686 return appToken.needsZBoost();
4687 }
4688 }
4689 return mWillReplaceWindow;
Robert Carrb1579c82017-09-05 14:54:47 -07004690 }
4691
Robert Carrf07ef9e2017-11-21 12:12:49 -08004692 private void applyDims(Dimmer dimmer) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07004693 if (!mAnimatingExit && mAppDied) {
4694 mIsDimming = true;
chaviw2fb06bc2018-01-19 17:09:15 -08004695 dimmer.dimAbove(getPendingTransaction(), this, DEFAULT_DIM_AMOUNT_DEAD_WINDOW);
chaviwebcbc342018-02-07 13:19:00 -08004696 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0 && isVisibleNow() && !mHidden) {
chaviw14076152018-02-02 14:51:20 -08004697 // Only show a dim behind when the following is satisfied:
4698 // 1. The window has the flag FLAG_DIM_BEHIND
4699 // 2. The WindowToken is not hidden so dims aren't shown when the window is exiting.
4700 // 3. The WS is considered visible according to the isVisible() method
chaviwebcbc342018-02-07 13:19:00 -08004701 // 4. The WS is not hidden.
Robert Carrf59b8dd2017-10-02 18:58:36 -07004702 mIsDimming = true;
chaviw2fb06bc2018-01-19 17:09:15 -08004703 dimmer.dimBelow(getPendingTransaction(), this, mAttrs.dimAmount);
Robert Carrf59b8dd2017-10-02 18:58:36 -07004704 }
Robert Carrf07ef9e2017-11-21 12:12:49 -08004705 }
4706
4707 @Override
4708 void prepareSurfaces() {
4709 final Dimmer dimmer = getDimmer();
4710 mIsDimming = false;
4711 if (dimmer != null) {
4712 applyDims(dimmer);
4713 }
chaviw2f0567b2018-01-29 16:22:02 -08004714 updateSurfacePosition();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004715
Robert Carrb1579c82017-09-05 14:54:47 -07004716 mWinAnimator.prepareSurfaceLocked(true);
4717 super.prepareSurfaces();
4718 }
4719
4720 @Override
Jorim Jaggia5e10572017-11-15 14:36:26 +01004721 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
4722 super.onAnimationLeashCreated(t, leash);
4723
4724 // Leash is now responsible for position, so set our position to 0.
4725 t.setPosition(mSurfaceControl, 0, 0);
chaviw3e751af2018-01-11 11:22:39 -08004726 mLastSurfacePosition.set(0, 0);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004727 }
4728
4729 @Override
4730 public void onAnimationLeashDestroyed(Transaction t) {
4731 super.onAnimationLeashDestroyed(t);
4732 updateSurfacePosition(t);
4733 }
4734
chaviwe07246a2017-12-12 16:18:29 -08004735 @Override
chaviw2f0567b2018-01-29 16:22:02 -08004736 void updateSurfacePosition() {
4737 updateSurfacePosition(getPendingTransaction());
4738 }
4739
4740 private void updateSurfacePosition(Transaction t) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01004741 if (mSurfaceControl == null) {
4742 return;
4743 }
4744
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004745 transformFrameToSurfacePosition(mFrame.left, mFrame.top, mSurfacePosition);
Robert Carrc6d5af52018-02-26 17:46:00 -08004746
Adrian Roos28c25e22018-05-31 18:07:28 +02004747 // Freeze position while we're unrotated, so the surface remains at the position it was
4748 // prior to the rotation.
4749 if (!mSurfaceAnimator.hasLeash() && mPendingForcedSeamlessRotate == null &&
4750 !mLastSurfacePosition.equals(mSurfacePosition)) {
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004751 t.setPosition(mSurfaceControl, mSurfacePosition.x, mSurfacePosition.y);
chaviw3e751af2018-01-11 11:22:39 -08004752 mLastSurfacePosition.set(mSurfacePosition.x, mSurfacePosition.y);
Robert Carrc6d5af52018-02-26 17:46:00 -08004753 if (surfaceInsetsChanging() && mWinAnimator.hasSurface()) {
4754 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
4755 t.deferTransactionUntil(mSurfaceControl,
4756 mWinAnimator.mSurfaceController.mSurfaceControl.getHandle(),
chaviwbe43ac82018-04-04 15:14:49 -07004757 getFrameNumber());
Robert Carrc6d5af52018-02-26 17:46:00 -08004758 }
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004759 }
4760 }
4761
4762 private void transformFrameToSurfacePosition(int left, int top, Point outPoint) {
4763 outPoint.set(left, top);
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004764
4765 // If changed, also adjust getTransformationMatrix
chaviwe07246a2017-12-12 16:18:29 -08004766 final WindowContainer parentWindowContainer = getParent();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004767 if (isChildWindow()) {
4768 // TODO: This probably falls apart at some point and we should
4769 // actually compute relative coordinates.
Jorim Jaggi50d3f8f2017-12-27 17:41:25 +01004770
4771 // Since the parent was outset by its surface insets, we need to undo the outsetting
4772 // with insetting by the same amount.
Jorim Jaggia5e10572017-11-15 14:36:26 +01004773 final WindowState parent = getParentWindow();
Jorim Jaggi50d3f8f2017-12-27 17:41:25 +01004774 outPoint.offset(-parent.mFrame.left + parent.mAttrs.surfaceInsets.left,
4775 -parent.mFrame.top + parent.mAttrs.surfaceInsets.top);
chaviwe07246a2017-12-12 16:18:29 -08004776 } else if (parentWindowContainer != null) {
4777 final Rect parentBounds = parentWindowContainer.getBounds();
4778 outPoint.offset(-parentBounds.left, -parentBounds.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004779 }
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004780
Robert Carr32bcb102018-01-29 15:03:23 -08004781 TaskStack stack = getStack();
4782
4783 // If we have stack outsets, that means the top-left
4784 // will be outset, and we need to inset ourselves
4785 // to account for it. If we actually have shadows we will
4786 // then un-inset ourselves by the surfaceInsets.
4787 if (stack != null) {
4788 final int outset = stack.getStackOutset();
4789 outPoint.offset(outset, outset);
4790 }
4791
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004792 // Expand for surface insets. See WindowState.expandForSurfaceInsets.
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004793 outPoint.offset(-mAttrs.surfaceInsets.left, -mAttrs.surfaceInsets.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004794 }
4795
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004796 boolean needsRelativeLayeringToIme() {
4797 // We only use the relative layering mode in split screen, as part of elevating the IME
4798 // and windows above it's target above the docked divider.
4799 if (!inSplitScreenWindowingMode()) {
4800 return false;
4801 }
4802
4803 if (isChildWindow()) {
4804 // If we are a child of the input method target we need this promotion.
4805 if (getParentWindow().isInputMethodTarget()) {
4806 return true;
4807 }
4808 } else if (mAppToken != null) {
4809 // Likewise if we share a token with the Input method target and are ordered
4810 // above it but not necessarily a child (e.g. a Dialog) then we also need
4811 // this promotion.
4812 final WindowState imeTarget = mService.mInputMethodTarget;
4813 boolean inTokenWithAndAboveImeTarget = imeTarget != null && imeTarget != this
4814 && imeTarget.mToken == mToken && imeTarget.compareTo(this) <= 0;
4815 return inTokenWithAndAboveImeTarget;
4816 }
4817 return false;
4818 }
4819
Jorim Jaggia5e10572017-11-15 14:36:26 +01004820 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004821 void assignLayer(Transaction t, int layer) {
4822 // See comment in assignRelativeLayerForImeTargetChild
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004823 if (needsRelativeLayeringToIme()) {
4824 getDisplayContent().assignRelativeLayerForImeTargetChild(t, this);
Robert Carrb1579c82017-09-05 14:54:47 -07004825 return;
4826 }
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004827 super.assignLayer(t, layer);
Robert Carrb1579c82017-09-05 14:54:47 -07004828 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07004829
4830 @Override
4831 public boolean isDimming() {
4832 return mIsDimming;
4833 }
Robert Carr0eff1872017-12-01 14:27:04 -08004834
4835 // TODO(b/70040778): We should aim to eliminate the last user of TYPE_APPLICATION_MEDIA
4836 // then we can drop all negative layering on the windowing side and simply inherit
4837 // the default implementation here.
4838 public void assignChildLayers(Transaction t) {
4839 int layer = 1;
4840 for (int i = 0; i < mChildren.size(); i++) {
4841 final WindowState w = mChildren.get(i);
4842
4843 // APPLICATION_MEDIA_OVERLAY needs to go above APPLICATION_MEDIA
4844 // while they both need to go below the main window. However the
4845 // relative layering of multiple APPLICATION_MEDIA/OVERLAY has never
4846 // been defined and so we can use static layers and leave it that way.
4847 if (w.mAttrs.type == TYPE_APPLICATION_MEDIA) {
4848 w.assignLayer(t, -2);
4849 } else if (w.mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) {
4850 w.assignLayer(t, -1);
4851 } else {
4852 w.assignLayer(t, layer);
4853 }
4854 w.assignChildLayers(t);
4855 layer++;
4856 }
4857 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01004858
Andrii Kulian4b6599e2018-01-15 17:24:08 -08004859 /**
4860 * Update a tap exclude region with a rectangular area identified by provided id. The requested
4861 * area will be clipped to the window bounds.
4862 */
4863 void updateTapExcludeRegion(int regionId, int left, int top, int width, int height) {
4864 final DisplayContent currentDisplay = getDisplayContent();
4865 if (currentDisplay == null) {
4866 throw new IllegalStateException("Trying to update window not attached to any display.");
4867 }
4868
4869 if (mTapExcludeRegionHolder == null) {
4870 mTapExcludeRegionHolder = new TapExcludeRegionHolder();
4871
4872 // Make sure that this window is registered as one that provides a tap exclude region
4873 // for its containing display.
4874 currentDisplay.mTapExcludeProvidingWindows.add(this);
4875 }
4876
4877 mTapExcludeRegionHolder.updateRegion(regionId, left, top, width, height);
4878 // Trigger touch exclude region update on current display.
4879 final boolean isAppFocusedOnDisplay = mService.mFocusedApp != null
4880 && mService.mFocusedApp.getDisplayContent() == currentDisplay;
4881 currentDisplay.setTouchExcludeRegion(isAppFocusedOnDisplay ? mService.mFocusedApp.getTask()
4882 : null);
4883 }
4884
4885 /** Union the region with current tap exclude region that this window provides. */
4886 void amendTapExcludeRegion(Region region) {
4887 mTapExcludeRegionHolder.amendRegion(region, getBounds());
4888 }
4889
Robert Carr825581a2018-03-30 14:00:53 -07004890 @Override
4891 public boolean isInputMethodTarget() {
4892 return mService.mInputMethodTarget == this;
4893 }
4894
chaviwbe43ac82018-04-04 15:14:49 -07004895 long getFrameNumber() {
4896 return mFrameNumber;
4897 }
4898
4899 void setFrameNumber(long frameNumber) {
4900 mFrameNumber = frameNumber;
4901 }
4902
Adrian Roos41f7e9d2018-06-07 15:29:34 +02004903 @Override
4904 void seamlesslyRotate(Transaction t, int oldRotation, int newRotation) {
Adrian Roos28c25e22018-05-31 18:07:28 +02004905 // Invisible windows, the wallpaper, and force seamlessly rotated windows do not participate
4906 // in the regular seamless rotation animation.
4907 if (!isVisibleNow() || mIsWallpaper || mForceSeamlesslyRotate) {
Adrian Roos41f7e9d2018-06-07 15:29:34 +02004908 return;
4909 }
4910 final Matrix transform = mTmpMatrix;
4911
4912 mService.markForSeamlessRotation(this, true);
4913
4914 // We rotated the screen, but have not performed a new layout pass yet. In the mean time,
4915 // we recompute the coordinates of mFrame in the new orientation, so the surface can be
4916 // properly placed.
4917 transformToRotation(oldRotation, newRotation, getDisplayInfo(), transform);
4918 transformRect(transform, mFrame, null /* tmpRectF */);
4919
4920 updateSurfacePosition(t);
4921 mWinAnimator.seamlesslyRotate(t, oldRotation, newRotation);
4922
4923 // Dispatch to children only after mFrame has been updated, as it's needed in the
4924 // child's updateSurfacePosition.
4925 super.seamlesslyRotate(t, oldRotation, newRotation);
4926 }
4927
Jorim Jaggia5e10572017-11-15 14:36:26 +01004928 private final class MoveAnimationSpec implements AnimationSpec {
4929
4930 private final long mDuration;
4931 private Interpolator mInterpolator;
4932 private Point mFrom = new Point();
4933 private Point mTo = new Point();
4934
4935 private MoveAnimationSpec(int fromX, int fromY, int toX, int toY) {
4936 final Animation anim = AnimationUtils.loadAnimation(mContext,
4937 com.android.internal.R.anim.window_move_from_decor);
Jorim Jaggi08f75cf2018-01-08 14:38:53 +01004938 mDuration = (long)
4939 (anim.computeDurationHint() * mService.getWindowAnimationScaleLocked());
Jorim Jaggia5e10572017-11-15 14:36:26 +01004940 mInterpolator = anim.getInterpolator();
4941 mFrom.set(fromX, fromY);
4942 mTo.set(toX, toY);
4943 }
4944
4945 @Override
4946 public long getDuration() {
4947 return mDuration;
4948 }
4949
4950 @Override
4951 public void apply(Transaction t, SurfaceControl leash, long currentPlayTime) {
4952 final float fraction = (float) currentPlayTime / getDuration();
4953 final float v = mInterpolator.getInterpolation(fraction);
4954 t.setPosition(leash, mFrom.x + (mTo.x - mFrom.x) * v,
4955 mFrom.y + (mTo.y - mFrom.y) * v);
4956 }
Jorim Jaggif75d1612018-02-27 15:05:21 +01004957
4958 @Override
4959 public void dump(PrintWriter pw, String prefix) {
4960 pw.print(prefix); pw.print("from="); pw.print(mFrom);
4961 pw.print(" to="); pw.print(mTo);
4962 pw.print(" duration="); pw.println(mDuration);
4963 }
4964
4965 @Override
4966 public void writeToProtoInner(ProtoOutputStream proto) {
4967 final long token = proto.start(MOVE);
4968 mFrom.writeToProto(proto, FROM);
4969 mTo.writeToProto(proto, TO);
Kweku Adams21b8d262018-03-30 12:19:58 -07004970 proto.write(DURATION_MS, mDuration);
Jorim Jaggif75d1612018-02-27 15:05:21 +01004971 proto.end(token);
4972 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01004973 }
satokcef37fb2011-10-24 21:49:38 +09004974}