blob: d9366f0beedae9fba8dbf491a9d1b67cd2ca0f80 [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
Wale Ogunwale65ebd952018-04-25 15:41:44 -070019import static android.app.ActivityTaskManager.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;
49import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
50import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
51import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
52import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
53import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
Philip P. Moltmann66ce2382018-10-09 13:46:11 -070054import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Jorim Jaggi02886a82016-12-06 09:10:06 -080055import 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;
Vishnu Nairddd80742018-08-21 14:12:46 -070074
Adrian Roose99bc052017-11-20 17:55:31 +010075import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
76import static com.android.server.policy.WindowManagerPolicy.TRANSIT_ENTER;
77import static com.android.server.policy.WindowManagerPolicy.TRANSIT_EXIT;
78import static com.android.server.policy.WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
Vishnu Nairddd80742018-08-21 14:12:46 -070079import static com.android.server.wm.AnimationSpecProto.MOVE;
Jorim Jaggi02886a82016-12-06 09:10:06 -080080import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
81import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
Vishnu Nairddd80742018-08-21 14:12:46 -070082import static com.android.server.wm.IdentifierProto.HASH_CODE;
83import static com.android.server.wm.IdentifierProto.TITLE;
84import static com.android.server.wm.IdentifierProto.USER_ID;
85import static com.android.server.wm.MoveAnimationSpecProto.DURATION_MS;
86import static com.android.server.wm.MoveAnimationSpecProto.FROM;
87import static com.android.server.wm.MoveAnimationSpecProto.TO;
Jorim Jaggi02886a82016-12-06 09:10:06 -080088import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
89import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
90import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
91import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
92import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
93import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
94import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Jorim Jaggi02886a82016-12-06 09:10:06 -080095import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
Tiger Huang50d45462018-05-25 22:57:52 +080096import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
Jorim Jaggi02886a82016-12-06 09:10:06 -080097import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
98import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
99import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
100import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200101import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800102import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800103import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
104import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
105import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100106import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800107import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
108import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
109import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Tiger Huang8af6ba42018-06-07 19:24:09 +0800110import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_REMOVING_FOCUS;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800111import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
112import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
113import static com.android.server.wm.WindowManagerService.localLOGV;
114import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING;
115import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
116import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN;
117import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700118import static com.android.server.wm.WindowStateProto.ANIMATING_EXIT;
119import static com.android.server.wm.WindowStateProto.ANIMATOR;
120import static com.android.server.wm.WindowStateProto.ATTRIBUTES;
121import static com.android.server.wm.WindowStateProto.CHILD_WINDOWS;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700122import static com.android.server.wm.WindowStateProto.DESTROYING;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700123import static com.android.server.wm.WindowStateProto.DISPLAY_ID;
Vishnu Nairddd80742018-08-21 14:12:46 -0700124import static com.android.server.wm.WindowStateProto.FINISHED_SEAMLESS_ROTATION_FRAME;
125import static com.android.server.wm.WindowStateProto.FORCE_SEAMLESS_ROTATION;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700126import static com.android.server.wm.WindowStateProto.GIVEN_CONTENT_INSETS;
127import static com.android.server.wm.WindowStateProto.HAS_SURFACE;
128import static com.android.server.wm.WindowStateProto.IDENTIFIER;
129import static com.android.server.wm.WindowStateProto.IS_ON_SCREEN;
130import static com.android.server.wm.WindowStateProto.IS_READY_FOR_DISPLAY;
131import static com.android.server.wm.WindowStateProto.IS_VISIBLE;
Vishnu Nairddd80742018-08-21 14:12:46 -0700132import static com.android.server.wm.WindowStateProto.PENDING_SEAMLESS_ROTATION;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700133import static com.android.server.wm.WindowStateProto.REMOVED;
134import static com.android.server.wm.WindowStateProto.REMOVE_ON_EXIT;
135import static com.android.server.wm.WindowStateProto.REQUESTED_HEIGHT;
136import static com.android.server.wm.WindowStateProto.REQUESTED_WIDTH;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700137import static com.android.server.wm.WindowStateProto.STACK_ID;
138import static com.android.server.wm.WindowStateProto.SURFACE_INSETS;
139import static com.android.server.wm.WindowStateProto.SURFACE_POSITION;
140import static com.android.server.wm.WindowStateProto.SYSTEM_UI_VISIBILITY;
141import static com.android.server.wm.WindowStateProto.VIEW_VISIBILITY;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700142import static com.android.server.wm.WindowStateProto.WINDOW_CONTAINER;
chaviw553b0212018-07-12 13:37:01 -0700143import static com.android.server.wm.WindowStateProto.WINDOW_FRAMES;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800144
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700145import android.annotation.CallSuper;
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200146import android.annotation.Nullable;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800147import android.app.AppOpsManager;
148import android.content.Context;
149import android.content.res.Configuration;
150import android.graphics.Matrix;
151import android.graphics.PixelFormat;
152import android.graphics.Point;
153import android.graphics.Rect;
154import android.graphics.Region;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700155import android.os.Binder;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700156import android.os.Debug;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800157import android.os.IBinder;
158import android.os.PowerManager;
159import android.os.RemoteCallbackList;
160import android.os.RemoteException;
161import android.os.SystemClock;
162import android.os.Trace;
163import android.os.UserHandle;
164import android.os.WorkSource;
chaviw40234662018-02-07 09:37:16 -0800165import android.provider.Settings;
Phil Weaverbb2f28a2017-12-22 09:44:28 -0800166import android.text.TextUtils;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800167import android.util.DisplayMetrics;
Jorim Jaggie7d2b852017-08-28 17:55:15 +0200168import android.util.MergedConfiguration;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800169import android.util.Slog;
170import android.util.TimeUtils;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700171import android.util.proto.ProtoOutputStream;
Brad Stenningaf596412018-04-02 12:03:19 -0700172import android.view.Display;
Adrian Roos5c6b6222017-11-07 17:36:10 +0100173import android.view.DisplayCutout;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800174import android.view.DisplayInfo;
175import android.view.Gravity;
176import android.view.IApplicationToken;
177import android.view.IWindow;
178import android.view.IWindowFocusObserver;
179import android.view.IWindowId;
180import android.view.InputChannel;
181import android.view.InputEvent;
182import android.view.InputEventReceiver;
Tiger Huang7c610aa2018-10-27 00:01:01 +0800183import android.view.InputWindowHandle;
Vishnu Nairba183352018-11-21 11:16:49 -0800184import android.view.Surface.Rotation;
Robert Carrb1579c82017-09-05 14:54:47 -0700185import android.view.SurfaceControl;
186import android.view.SurfaceSession;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800187import android.view.View;
188import android.view.ViewTreeObserver;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700189import android.view.WindowInfo;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800190import android.view.WindowManager;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100191import android.view.animation.Animation;
192import android.view.animation.AnimationUtils;
193import android.view.animation.Interpolator;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800194
Jorim Jaggi4876b4a2018-01-11 15:43:49 +0100195import com.android.internal.annotations.VisibleForTesting;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800196import com.android.internal.util.ToBooleanFunction;
Adrian Roose99bc052017-11-20 17:55:31 +0100197import com.android.server.policy.WindowManagerPolicy;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100198import com.android.server.wm.LocalAnimationAdapter.AnimationSpec;
chaviw9c81e632018-07-31 11:17:52 -0700199import com.android.server.wm.utils.InsetUtils;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100200import com.android.server.wm.utils.WmDisplayCutout;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800201
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800202import java.io.PrintWriter;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200203import java.lang.ref.WeakReference;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800204import java.util.ArrayList;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700205import java.util.Comparator;
Wale Ogunwaled1880962016-11-08 10:31:59 -0800206import java.util.function.Predicate;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800207
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700208/** A window in the window manager. */
209class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800210 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800211
Skuhne81c524a2015-08-12 13:34:14 -0700212 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700213 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
214 // use hard-coded min sizes for now.
215 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
216 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700217
218 // The thickness of a window resize handle outside the window bounds on the free form workspace
219 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700220 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700221
Craig Mautnere7ae2502012-03-26 17:11:19 -0700222 final WindowManagerPolicy mPolicy;
223 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800224 final Session mSession;
225 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800226 final int mAppOp;
227 // UserId and appId of the owner. Don't display windows of non-current user.
228 final int mOwnerUid;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800229 /** The owner has {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} */
230 final boolean mOwnerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200231 final WindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800232 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700233 // The same object as mToken if this is an app window and null for non-app windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800234 AppWindowToken mAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700235
236 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
237 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800238 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
239 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700240 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800241 final int mBaseLayer;
242 final int mSubLayer;
243 final boolean mLayoutAttached;
244 final boolean mIsImWindow;
245 final boolean mIsWallpaper;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700246 private final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700247 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700248 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800249 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700250 int mSystemUiVisibility;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700251 /**
252 * The visibility of the window based on policy like {@link WindowManagerPolicy}.
253 * Normally set by calling {@link #showLw} and {@link #hideLw}.
254 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800255 boolean mPolicyVisibility = true;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700256 /**
257 * What {@link #mPolicyVisibility} should be set to after a transition animation.
258 * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and
259 * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit
260 * animation is done.
261 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800262 boolean mPolicyVisibilityAfterAnim = true;
Suprabh Shukla69c71422018-04-02 18:39:01 -0700263 // overlay window is hidden because the owning app is suspended
264 private boolean mHiddenWhileSuspended;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700265 private boolean mAppOpVisibility = true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700266 boolean mPermanentlyHidden; // the window should never be shown again
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700267 // This is a non-system overlay window that is currently force hidden.
268 private boolean mForceHideNonSystemOverlayWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800269 boolean mAppFreezing;
chaviwebcbc342018-02-07 13:19:00 -0800270 boolean mHidden = true; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800271 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700272 private boolean mDragResizing;
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200273 private boolean mDragResizingChangeReported = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700274 private int mResizeMode;
Vishnu Nair83537a72018-07-19 21:27:48 -0700275 /**
276 * Special mode that is intended only for the rounded corner overlay: during rotation
277 * transition, we un-rotate the window token such that the window appears as it did before the
278 * rotation.
Vishnu Nair83537a72018-07-19 21:27:48 -0700279 */
280 final boolean mForceSeamlesslyRotate;
Vishnu Nairddd80742018-08-21 14:12:46 -0700281 SeamlessRotator mPendingSeamlessRotate;
282 long mFinishSeamlessRotateFrameNumber;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700283
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700284 private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800285
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700286 /**
287 * The window size that was requested by the application. These are in
288 * the application's coordinate space (without compatibility scale applied).
289 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800290 int mRequestedWidth;
291 int mRequestedHeight;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700292 private int mLastRequestedWidth;
293 private int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700294
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800295 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800296 boolean mHaveFrame;
297 boolean mObscured;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800298
299 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700300
Andrii Kulian9d91ca62016-09-29 22:28:09 -0700301 /**
302 * Used to store last reported to client configuration and check if we have newer available.
303 * We'll send configuration to client only if it is different from the last applied one and
304 * client won't perform unnecessary updates.
305 */
Bryce Lee2b17afd2017-09-21 10:38:20 -0700306 private final MergedConfiguration mLastReportedConfiguration = new MergedConfiguration();
Craig Mautnera2c77052012-03-26 12:14:43 -0700307
Yunfan Chen75157d72018-07-27 14:47:21 +0900308 private final Configuration mTempConfiguration = new Configuration();
309
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700310 /**
Robert Carr18f622f2017-05-08 11:20:43 -0700311 * The last content insets returned to the client in relayout. We use
312 * these in the bounds animation to ensure we only observe inset changes
313 * at the same time that a client resizes it's surface so that we may use
314 * the geometryAppliesWithResize synchronization mechanism to keep
315 * the contents in place.
316 */
317 final Rect mLastRelayoutContentInsets = new Rect();
318
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700319 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800320 * Set to true if we are waiting for this window to receive its
321 * given internal insets before laying out other windows based on it.
322 */
323 boolean mGivenInsetsPending;
324
325 /**
326 * These are the content insets that were given during layout for
327 * this window, to be applied to windows behind it.
328 */
329 final Rect mGivenContentInsets = new Rect();
330
331 /**
332 * These are the visible insets that were given during layout for
333 * this window, to be applied to windows behind it.
334 */
335 final Rect mGivenVisibleInsets = new Rect();
336
337 /**
338 * This is the given touchable area relative to the window frame, or null if none.
339 */
340 final Region mGivenTouchableRegion = new Region();
341
342 /**
343 * Flag indicating whether the touchable region should be adjusted by
344 * the visible insets; if false the area outside the visible insets is
345 * NOT touchable, so we must use those to adjust the frame during hit
346 * tests.
347 */
348 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
349
350 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400351 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700352 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800353 float mHScale=1, mVScale=1;
354 float mLastHScale=1, mLastVScale=1;
355 final Matrix mTmpMatrix = new Matrix();
356
chaviw553b0212018-07-12 13:37:01 -0700357 private final WindowFrames mWindowFrames = new WindowFrames();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700358
Jorim Jaggidc249c42015-12-15 14:57:31 -0800359 /**
360 * Usually empty. Set to the task's tempInsetFrame. See
Wale Ogunwale04d9cb52018-04-30 13:55:07 -0700361 *{@link android.app.IActivityTaskManager#resizeDockedStack}.
Jorim Jaggidc249c42015-12-15 14:57:31 -0800362 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700363 private final Rect mInsetFrame = new Rect();
Jorim Jaggidc249c42015-12-15 14:57:31 -0800364
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800365 // If a window showing a wallpaper: the requested offset for the
366 // wallpaper; if a wallpaper window: the currently applied offset.
367 float mWallpaperX = -1;
368 float mWallpaperY = -1;
369
370 // If a window showing a wallpaper: what fraction of the offset
371 // range corresponds to a full virtual screen.
372 float mWallpaperXStep = -1;
373 float mWallpaperYStep = -1;
374
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700375 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
376 // to its window; if a wallpaper window: not used.
377 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
378 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
379
Craig Mautner2268e7e2012-12-13 15:40:00 -0800380 /**
381 * This is set after IWindowSession.relayout() has been called at
382 * least once for the window. It allows us to detect the situation
383 * where we don't yet have a surface, but should have one soon, so
384 * we can give the window focus before waiting for the relayout.
385 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800386 boolean mRelayoutCalled;
387
Robert Carrfed10072016-05-26 11:48:49 -0700388 boolean mInRelayout;
389
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800390 /**
391 * If the application has called relayout() with changes that can
392 * impact its window's size, we need to perform a layout pass on it
393 * even if it is not currently visible for layout. This is set
394 * when in that case until the layout is done.
395 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800396 boolean mLayoutNeeded;
397
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800398 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800399 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800400
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800401 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800402 boolean mDestroying;
403
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800404 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800405 boolean mRemoveOnExit;
406
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800407 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800408 * Whether the app died while it was visible, if true we might need
409 * to continue to show it until it's restarted.
410 */
411 boolean mAppDied;
412
413 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800414 * Set when the orientation is changing and this window has not yet
415 * been updated for the new orientation.
416 */
Bryce Lee8c3cf382017-07-06 19:47:10 -0700417 private boolean mOrientationChanging;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800418
Dianne Hackborna57c6952013-03-29 14:46:40 -0700419 /**
Robert Carr9c1c3a02017-08-08 12:59:01 -0700420 * Sometimes in addition to the mOrientationChanging
421 * flag we report that the orientation is changing
422 * due to a mismatch in current and reported configuration.
423 *
424 * In the case of timeout we still need to make sure we
425 * leave the orientation changing state though, so we
426 * use this as a special time out escape hatch.
427 */
428 private boolean mOrientationChangeTimedOut;
429
430 /**
Robert Carr237028a2016-07-26 10:39:45 -0700431 * The orientation during the last visible call to relayout. If our
432 * current orientation is different, the window can't be ready
433 * to be shown.
434 */
435 int mLastVisibleLayoutRotation = -1;
436
437 /**
Andrii Kulianb2e37802017-01-11 00:36:44 -0800438 * Set when we need to report the orientation change to client to trigger a relayout.
439 */
440 boolean mReportOrientationChanged;
441
442 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700443 * How long we last kept the screen frozen.
444 */
445 int mLastFreezeDuration;
446
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800447 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800448 boolean mRemoved;
449
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800450 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800451 * It is save to remove the window and destroy the surface because the client requested removal
452 * or some other higher level component said so (e.g. activity manager).
453 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800454 */
Svetoslav Ganov200adfb2016-10-18 13:29:27 -0700455 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800456
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800457 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700458 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800459 InputChannel mInputChannel;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700460 private InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800461
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800462 // Used to improve performance of toString()
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700463 private String mStringNameCache;
464 private CharSequence mLastTitle;
465 private boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800466
Craig Mautnera2c77052012-03-26 12:14:43 -0700467 final WindowStateAnimator mWinAnimator;
468
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700469 boolean mHasSurface = false;
470
Craig Mautner88400d32012-09-30 12:35:45 -0700471 /** When true this window can be displayed on screens owther than mOwnerUid's */
472 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700473
Chong Zhang92147042016-05-09 12:47:11 -0700474 // Whether the window was visible when we set the app to invisible last time. WM uses
475 // this as a hint to restore the surface (if available) for early animation next time
476 // the app is brought visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700477 private boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800478
Robert Carra1eb4392015-12-10 12:43:51 -0800479 // This window will be replaced due to relaunch. This allows window manager
480 // to differentiate between simple removal of a window and replacement. In the latter case it
481 // will preserve the old window until the new one is drawn.
482 boolean mWillReplaceWindow = false;
483 // If true, the replaced window was already requested to be removed.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700484 private boolean mReplacingRemoveRequested = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800485 // Whether the replacement of the window should trigger app transition animation.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700486 private boolean mAnimateReplacingWindow = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800487 // If not null, the window that will be used to replace the old one. This is being set when
488 // the window is added and unset when this window reports its first draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700489 private WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700490 // For the new window in the replacement transition, if we have
491 // requested to replace without animation, then we should
492 // make sure we also don't apply an enter animation for
493 // the new window.
494 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800495 // Whether this window is being moved via the resize API
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700496 private boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800497
Jeff Brownc2932a12014-11-20 18:04:05 -0800498 /**
499 * Wake lock for drawing.
500 * Even though it's slightly more expensive to do so, we will use a separate wake lock
501 * for each app that is requesting to draw while dozing so that we can accurately track
502 * who is preventing the system from suspending.
503 * This lock is only acquired on first use.
504 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700505 private PowerManager.WakeLock mDrawLock;
Jeff Brownc2932a12014-11-20 18:04:05 -0800506
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700507 final private Rect mTmpRect = new Rect();
508
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800509 /**
510 * Whether the window was resized by us while it was gone for layout.
511 */
512 boolean mResizedWhileGone = false;
513
Robert Carr6da3cc02016-06-16 15:17:07 -0700514 /**
515 * During seamless rotation we have two phases, first the old window contents
516 * are rotated to look as if they didn't move in the new coordinate system. Then we
517 * have to freeze updates to this layer (to preserve the transformation) until
518 * the resize actually occurs. This is true from when the transformation is set
519 * and false until the transaction to resize is sent.
520 */
521 boolean mSeamlesslyRotated = false;
522
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700523 /**
Robert Carrc91d1c32017-02-15 19:37:46 -0800524 * Surface insets from the previous call to relayout(), used to track
525 * if we are changing the Surface insets.
526 */
527 final Rect mLastSurfaceInsets = new Rect();
528
529 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700530 * A flag set by the {@link WindowState} parent to indicate that the parent has examined this
531 * {@link WindowState} in its overall drawing context. This book-keeping allows the parent to
532 * make sure all children have been considered.
533 */
534 private boolean mDrawnStateEvaluated;
535
Jorim Jaggia5e10572017-11-15 14:36:26 +0100536 private final Point mSurfacePosition = new Point();
537
Bryce Leed390deb2017-06-22 13:14:28 -0700538 /**
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800539 * A region inside of this window to be excluded from touch-related focus switches.
540 */
541 private TapExcludeRegionHolder mTapExcludeRegionHolder;
542
543 /**
chaviw40234662018-02-07 09:37:16 -0800544 * Used for testing because the real PowerManager is final.
545 */
546 private PowerManagerWrapper mPowerManagerWrapper;
547
548 /**
chaviwbe43ac82018-04-04 15:14:49 -0700549 * A frame number in which changes requested in this layout will be rendered.
550 */
551 private long mFrameNumber = -1;
552
chaviwc65fa582018-08-09 15:33:13 -0700553 private static final StringBuilder sTmpSB = new StringBuilder();
554
chaviwbe43ac82018-04-04 15:14:49 -0700555 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700556 * 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 -0700557 * of z-order and 1 otherwise.
558 */
Griff Hazen51d00d82016-11-22 15:39:24 -0800559 private static final Comparator<WindowState> sWindowSubLayerComparator =
560 new Comparator<WindowState>() {
561 @Override
562 public int compare(WindowState w1, WindowState w2) {
563 final int layer1 = w1.mSubLayer;
564 final int layer2 = w2.mSubLayer;
565 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
566 // We insert the child window into the list ordered by
567 // the sub-layer. For same sub-layers, the negative one
568 // should go below others; the positive one should go
569 // above others.
570 return -1;
571 }
572 return 1;
573 };
574 };
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700575
Robert Carrf59b8dd2017-10-02 18:58:36 -0700576 /**
577 * Indicates whether we have requested a Dim (in the sense of {@link Dimmer}) from our host
578 * container.
579 */
580 private boolean mIsDimming = false;
581
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200582 private @Nullable InsetsSourceProvider mInsetProvider;
583
Robert Carrf59b8dd2017-10-02 18:58:36 -0700584 private static final float DEFAULT_DIM_AMOUNT_DEAD_WINDOW = 0.5f;
585
Vishnu Nairba183352018-11-21 11:16:49 -0800586 void seamlesslyRotateIfAllowed(Transaction transaction, @Rotation int oldRotation,
587 @Rotation int rotation, boolean requested) {
Vishnu Nairddd80742018-08-21 14:12:46 -0700588 // Invisible windows and the wallpaper do not participate in the seamless rotation animation
589 if (!isVisibleNow() || mIsWallpaper) {
590 return;
591 }
Adrian Roosfaa102f2018-08-02 15:56:15 +0200592
Vishnu Nairddd80742018-08-21 14:12:46 -0700593 if (mPendingSeamlessRotate != null) {
594 oldRotation = mPendingSeamlessRotate.getOldRotation();
595 }
596
597 if (mForceSeamlesslyRotate || requested) {
598 mPendingSeamlessRotate = new SeamlessRotator(oldRotation, rotation, getDisplayInfo());
Vishnu Nairec634062018-09-20 20:16:18 -0700599 mPendingSeamlessRotate.unrotate(transaction, this);
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800600 mWmService.markForSeamlessRotation(this, true);
Vishnu Nairddd80742018-08-21 14:12:46 -0700601 }
602 }
603
Vishnu Nairba183352018-11-21 11:16:49 -0800604 void finishSeamlessRotation(boolean timeout) {
Vishnu Nairddd80742018-08-21 14:12:46 -0700605 if (mPendingSeamlessRotate != null) {
Vishnu Nairba183352018-11-21 11:16:49 -0800606 mPendingSeamlessRotate.finish(this, timeout);
Vishnu Nairddd80742018-08-21 14:12:46 -0700607 mFinishSeamlessRotateFrameNumber = getFrameNumber();
608 mPendingSeamlessRotate = null;
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800609 mWmService.markForSeamlessRotation(this, false);
Vishnu Nair83537a72018-07-19 21:27:48 -0700610 }
611 }
612
chaviw40234662018-02-07 09:37:16 -0800613 interface PowerManagerWrapper {
614 void wakeUp(long time, String reason);
615
616 boolean isInteractive();
617
618 }
619
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800620 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
chaviw40234662018-02-07 09:37:16 -0800621 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
622 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow) {
623 this(service, s, c, token, parentWindow, appOp, seq, a, viewVisibility, ownerId,
624 ownerCanAddInternalSystemWindow, new PowerManagerWrapper() {
625 @Override
626 public void wakeUp(long time, String reason) {
627 service.mPowerManager.wakeUp(time, reason);
628 }
629
630 @Override
631 public boolean isInteractive() {
632 return service.mPowerManager.isInteractive();
633 }
634 });
635 }
636
637 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
638 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
639 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow,
640 PowerManagerWrapper powerManagerWrapper) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100641 super(service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800642 mSession = s;
643 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800644 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800645 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700646 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700647 mOwnerUid = ownerId;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800648 mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200649 mWindowId = new WindowId(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800650 mAttrs.copyFrom(a);
Robert Carrb08ed042018-03-12 15:49:08 -0700651 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800652 mViewVisibility = viewVisibility;
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800653 mPolicy = mWmService.mPolicy;
654 mContext = mWmService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800655 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700656 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700657 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
chaviw40234662018-02-07 09:37:16 -0800658 mPowerManagerWrapper = powerManagerWrapper;
Vishnu Nair83537a72018-07-19 21:27:48 -0700659 mForceSeamlesslyRotate = token.mRoundedCornerOverlay;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700660 if (localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700661 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700662 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800663 try {
664 c.asBinder().linkToDeath(deathRecipient, 0);
665 } catch (RemoteException e) {
666 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700667 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800668 mLayoutAttached = false;
669 mIsImWindow = false;
670 mIsWallpaper = false;
671 mIsFloatingLayer = false;
672 mBaseLayer = 0;
673 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700674 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700675 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800676 return;
677 }
678 mDeathRecipient = deathRecipient;
679
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700680 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800681 // The multiplier here is to reserve space for multiple
682 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800683 mBaseLayer = mPolicy.getWindowLayerLw(parentWindow)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700684 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800685 mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700686 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900687
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700688 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow);
689 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900690
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800691 mLayoutAttached = mAttrs.type !=
692 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700693 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
694 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
695 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800696 } else {
697 // The multiplier here is to reserve space for multiple
698 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800699 mBaseLayer = mPolicy.getWindowLayerLw(this)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700700 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800701 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700702 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800703 mLayoutAttached = false;
704 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
705 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
706 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800707 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700708 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800709
Wale Ogunwale72919d22016-12-08 18:58:50 -0800710 if (mAppToken != null && mAppToken.mShowForAllUsers) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700711 // Windows for apps that can show for all users should also show when the device is
712 // locked.
713 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
Craig Mautner19ab8282014-05-07 10:35:34 -0700714 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800715
Craig Mautner322e4032012-07-13 13:35:20 -0700716 mWinAnimator = new WindowStateAnimator(this);
717 mWinAnimator.mAlpha = a.alpha;
718
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800719 mRequestedWidth = 0;
720 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700721 mLastRequestedWidth = 0;
722 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800723 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800724 mInputWindowHandle = new InputWindowHandle(
Robert Carre0a353c2018-08-02 16:38:04 -0700725 mAppToken != null ? mAppToken.mInputApplicationHandle : null, c,
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800726 getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800727 }
728
729 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700730 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800731 mSession.windowAddedLocked(mAttrs.packageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800732 }
733
Bryce Leed390deb2017-06-22 13:14:28 -0700734 /**
735 * Returns whether this {@link WindowState} has been considered for drawing by its parent.
736 */
Bryce Lee6311c4b2017-07-06 14:09:29 -0700737 boolean getDrawnStateEvaluated() {
Bryce Leed390deb2017-06-22 13:14:28 -0700738 return mDrawnStateEvaluated;
739 }
740
741 /**
742 * Sets whether this {@link WindowState} has been considered for drawing by its parent. Should
743 * be cleared when detached from parent.
744 */
745 void setDrawnStateEvaluated(boolean evaluated) {
746 mDrawnStateEvaluated = evaluated;
747 }
748
749 @Override
750 void onParentSet() {
751 super.onParentSet();
752 setDrawnStateEvaluated(false /*evaluated*/);
Robert Carr24be9ab2018-04-30 17:54:53 -0700753
754 getDisplayContent().reapplyMagnificationSpec();
Bryce Leed390deb2017-06-22 13:14:28 -0700755 }
756
Craig Mautnera2c77052012-03-26 12:14:43 -0700757 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800758 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800759 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800760 }
761
762 @Override
763 public String getOwningPackage() {
764 return mAttrs.packageName;
765 }
766
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800767 @Override
768 public boolean canAddInternalSystemWindow() {
769 return mOwnerCanAddInternalSystemWindow;
770 }
771
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200772 @Override
773 public boolean canAcquireSleepToken() {
774 return mSession.mCanAcquireSleepToken;
775 }
776
Jorim Jaggif5834272016-04-04 20:25:41 -0700777 /**
778 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
779 * from {@param frame}. In other words, it applies the insets that would result if
780 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700781 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
782 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700783 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700784 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
785 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
786 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
787 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
788 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700789 frame.inset(left, top, right, bottom);
790 }
791
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800792 @Override
Evan Roskyed6767f2018-10-26 17:21:06 -0700793 public Rect getDisplayedBounds() {
794 final Task task = getTask();
795 if (task != null) {
796 Rect bounds = task.getOverrideDisplayedBounds();
797 if (!bounds.isEmpty()) {
798 return bounds;
799 }
800 }
801 return super.getDisplayedBounds();
802 }
803
804 @Override
chaviw1454b392018-08-06 09:54:04 -0700805 public void computeFrameLw() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800806 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700807 // This window is being replaced and either already got information that it's being
808 // removed or we are still waiting for some information. Because of this we don't
809 // want to apply any more changes to it, so it remains in this state until new window
810 // appears.
811 return;
812 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800813 mHaveFrame = true;
814
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700815 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700816 final boolean inFullscreenContainer = inFullscreenContainer();
Robert Carre6275582016-02-29 15:45:45 -0800817 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700818 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800819
Evan Roskyed6767f2018-10-26 17:21:06 -0700820 mInsetFrame.set(getBounds());
Chong Zhangae35fef2016-03-16 15:56:55 -0700821
Jorim Jaggif5834272016-04-04 20:25:41 -0700822 // Denotes the actual frame used to calculate the insets and to perform the layout. When
823 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
824 // insets temporarily. By the notion of a task having a different layout frame, we can
825 // achieve that while still moving the task around.
826 final Rect layoutContainingFrame;
827 final Rect layoutDisplayFrame;
828
829 // The offset from the layout containing frame to the actual containing frame.
830 final int layoutXDiff;
831 final int layoutYDiff;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700832 if (inFullscreenContainer || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800833 // We use the parent frame as the containing frame for fullscreen and child windows
chaviw1454b392018-08-06 09:54:04 -0700834 mWindowFrames.mContainingFrame.set(mWindowFrames.mParentFrame);
835 layoutDisplayFrame = mWindowFrames.mDisplayFrame;
836 layoutContainingFrame = mWindowFrames.mParentFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700837 layoutXDiff = 0;
838 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800839 } else {
Evan Roskyed6767f2018-10-26 17:21:06 -0700840 mWindowFrames.mContainingFrame.set(getDisplayedBounds());
Jorim Jaggi0429f352015-12-22 16:29:16 +0100841 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
842
843 // If the bounds are frozen, we still want to translate the window freely and only
844 // freeze the size.
845 Rect frozen = mAppToken.mFrozenBounds.peek();
chaviw553b0212018-07-12 13:37:01 -0700846 mWindowFrames.mContainingFrame.right =
847 mWindowFrames.mContainingFrame.left + frozen.width();
848 mWindowFrames.mContainingFrame.bottom =
849 mWindowFrames.mContainingFrame.top + frozen.height();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100850 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800851 final WindowState imeWin = mWmService.mRoot.getCurrentInputMethodWindow();
Robert Carrfc03b2b2016-03-31 15:22:02 -0700852 // IME is up and obscuring this window. Adjust the window position so it is visible.
Robert Carr825581a2018-03-30 14:00:53 -0700853 if (imeWin != null && imeWin.isVisibleNow() && isInputMethodTarget()) {
chaviw553b0212018-07-12 13:37:01 -0700854 if (inFreeformWindowingMode() && mWindowFrames.mContainingFrame.bottom
chaviw1454b392018-08-06 09:54:04 -0700855 > mWindowFrames.mContentFrame.bottom) {
Winson Chungd73e94b2017-05-31 16:25:30 -0700856 // In freeform we want to move the top up directly.
857 // TODO: Investigate why this is contentFrame not parentFrame.
chaviw553b0212018-07-12 13:37:01 -0700858 mWindowFrames.mContainingFrame.top -= mWindowFrames.mContainingFrame.bottom
chaviw1454b392018-08-06 09:54:04 -0700859 - mWindowFrames.mContentFrame.bottom;
chaviw553b0212018-07-12 13:37:01 -0700860 } else if (!inPinnedWindowingMode() && mWindowFrames.mContainingFrame.bottom
chaviw1454b392018-08-06 09:54:04 -0700861 > mWindowFrames.mParentFrame.bottom) {
Winson Chungd73e94b2017-05-31 16:25:30 -0700862 // But in docked we want to behave like fullscreen and behave as if the task
863 // were given smaller bounds for the purposes of layout. Skip adjustments for
864 // the pinned stack, they are handled separately in the PinnedStackController.
chaviw1454b392018-08-06 09:54:04 -0700865 mWindowFrames.mContainingFrame.bottom = mWindowFrames.mParentFrame.bottom;
Winson Chungd73e94b2017-05-31 16:25:30 -0700866 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700867 }
Skuhne81c524a2015-08-12 13:34:14 -0700868
Robert Carre6275582016-02-29 15:45:45 -0800869 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700870 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
871 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800872 // "content frame" since it is allowed to be outside the visible desktop.
chaviw553b0212018-07-12 13:37:01 -0700873 if (mWindowFrames.mContainingFrame.isEmpty()) {
chaviw1454b392018-08-06 09:54:04 -0700874 mWindowFrames.mContainingFrame.set(mWindowFrames.mContentFrame);
Skuhne81c524a2015-08-12 13:34:14 -0700875 }
Doris Liu06d582d2015-06-01 13:18:43 -0700876 }
Adrian Roos604ef952018-05-15 20:13:13 +0200877
878 final TaskStack stack = getStack();
879 if (inPinnedWindowingMode() && stack != null
880 && stack.lastAnimatingBoundsWasToFullscreen()) {
881 // PIP edge case: When going from pinned to fullscreen, we apply a
882 // tempInsetFrame for the full task - but we're still at the start of the animation.
883 // To prevent a jump if there's a letterbox, restrict to the parent frame.
chaviw1454b392018-08-06 09:54:04 -0700884 mInsetFrame.intersectUnchecked(mWindowFrames.mParentFrame);
885 mWindowFrames.mContainingFrame.intersectUnchecked(mWindowFrames.mParentFrame);
Adrian Roos604ef952018-05-15 20:13:13 +0200886 }
887
chaviw1454b392018-08-06 09:54:04 -0700888 layoutDisplayFrame = new Rect(mWindowFrames.mDisplayFrame);
chaviw553b0212018-07-12 13:37:01 -0700889 mWindowFrames.mDisplayFrame.set(mWindowFrames.mContainingFrame);
Evan Roskyed6767f2018-10-26 17:21:06 -0700890 layoutXDiff = mInsetFrame.left - mWindowFrames.mContainingFrame.left;
891 layoutYDiff = mInsetFrame.top - mWindowFrames.mContainingFrame.top;
892 layoutContainingFrame = mInsetFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700893 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
chaviw1454b392018-08-06 09:54:04 -0700894 subtractInsets(mWindowFrames.mDisplayFrame, layoutContainingFrame, layoutDisplayFrame,
895 mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700896 if (!layoutInParentFrame()) {
chaviw553b0212018-07-12 13:37:01 -0700897 subtractInsets(mWindowFrames.mContainingFrame, layoutContainingFrame,
chaviw1454b392018-08-06 09:54:04 -0700898 mWindowFrames.mParentFrame, mTmpRect);
899 subtractInsets(mInsetFrame, layoutContainingFrame, mWindowFrames.mParentFrame,
chaviw553b0212018-07-12 13:37:01 -0700900 mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700901 }
Jorim Jaggif5834272016-04-04 20:25:41 -0700902 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700903 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800904
chaviw553b0212018-07-12 13:37:01 -0700905 final int pw = mWindowFrames.mContainingFrame.width();
906 final int ph = mWindowFrames.mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800907
Dianne Hackborn1743b642012-03-12 17:04:43 -0700908 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
909 mLastRequestedWidth = mRequestedWidth;
910 mLastRequestedHeight = mRequestedHeight;
chaviw1454b392018-08-06 09:54:04 -0700911 mWindowFrames.setContentChanged(true);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700912 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800913
chaviw492139a2018-07-16 16:07:35 -0700914 final int fw = mWindowFrames.mFrame.width();
915 final int fh = mWindowFrames.mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800916
Jorim Jaggif5834272016-04-04 20:25:41 -0700917 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
918
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700919 // Calculate the outsets before the content frame gets shrinked to the window frame.
chaviw1454b392018-08-06 09:54:04 -0700920 mWindowFrames.calculateOutsets();
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700921
Craig Mautnera248eee2013-05-07 11:41:27 -0700922 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800923 // final window frame.
chaviw492139a2018-07-16 16:07:35 -0700924 if (windowsAreFloating && !mWindowFrames.mFrame.isEmpty()) {
Robert Carre65a1c42017-02-28 16:52:59 -0800925 // For pinned workspace the frame isn't limited in any particular
926 // way since SystemUI controls the bounds. For freeform however
927 // we want to keep things inside the content frame.
chaviw492139a2018-07-16 16:07:35 -0700928 final Rect limitFrame = task.inPinnedWindowingMode() ? mWindowFrames.mFrame
929 : mWindowFrames.mContentFrame;
Skuhne81c524a2015-08-12 13:34:14 -0700930 // Keep the frame out of the blocked system area, limit it in size to the content area
931 // and make sure that there is always a minimum visible so that the user can drag it
932 // into a usable area..
chaviw492139a2018-07-16 16:07:35 -0700933 final int height = Math.min(mWindowFrames.mFrame.height(), limitFrame.height());
934 final int width = Math.min(limitFrame.width(), mWindowFrames.mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700935 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +0900936 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
937 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
938 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
939 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Robert Carre65a1c42017-02-28 16:52:59 -0800940 final int top = Math.max(limitFrame.top,
chaviw492139a2018-07-16 16:07:35 -0700941 Math.min( mWindowFrames.mFrame.top, limitFrame.bottom - minVisibleHeight));
Robert Carre65a1c42017-02-28 16:52:59 -0800942 final int left = Math.max(limitFrame.left + minVisibleWidth - width,
chaviw492139a2018-07-16 16:07:35 -0700943 Math.min( mWindowFrames.mFrame.left, limitFrame.right - minVisibleWidth));
944 mWindowFrames.mFrame.set(left, top, left + width, top + height);
945 mWindowFrames.mContentFrame.set( mWindowFrames.mFrame);
chaviw553b0212018-07-12 13:37:01 -0700946 mWindowFrames.mVisibleFrame.set(mWindowFrames.mContentFrame);
947 mWindowFrames.mStableFrame.set(mWindowFrames.mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700948 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
chaviw492139a2018-07-16 16:07:35 -0700949 dc.getDockedDividerController().positionDockedStackedDivider(mWindowFrames.mFrame);
950 mWindowFrames.mContentFrame.set(mWindowFrames.mFrame);
951 if (!mWindowFrames.mFrame.equals(mWindowFrames.mLastFrame)) {
Jorim Jaggi192086e2016-03-11 17:17:03 +0100952 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800953 }
Skuhne81c524a2015-08-12 13:34:14 -0700954 } else {
chaviw492139a2018-07-16 16:07:35 -0700955 mWindowFrames.mContentFrame.set(
956 Math.max(mWindowFrames.mContentFrame.left, mWindowFrames.mFrame.left),
957 Math.max(mWindowFrames.mContentFrame.top, mWindowFrames.mFrame.top),
958 Math.min(mWindowFrames.mContentFrame.right, mWindowFrames.mFrame.right),
959 Math.min(mWindowFrames.mContentFrame.bottom, mWindowFrames.mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800960
chaviw492139a2018-07-16 16:07:35 -0700961 mWindowFrames.mVisibleFrame.set(
962 Math.max(mWindowFrames.mVisibleFrame.left, mWindowFrames.mFrame.left),
963 Math.max(mWindowFrames.mVisibleFrame.top, mWindowFrames.mFrame.top),
964 Math.min(mWindowFrames.mVisibleFrame.right, mWindowFrames.mFrame.right),
965 Math.min(mWindowFrames.mVisibleFrame.bottom, mWindowFrames.mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800966
chaviw492139a2018-07-16 16:07:35 -0700967 mWindowFrames.mStableFrame.set(
968 Math.max(mWindowFrames.mStableFrame.left, mWindowFrames.mFrame.left),
969 Math.max(mWindowFrames.mStableFrame.top, mWindowFrames.mFrame.top),
970 Math.min(mWindowFrames.mStableFrame.right, mWindowFrames.mFrame.right),
971 Math.min(mWindowFrames.mStableFrame.bottom, mWindowFrames.mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700972 }
Adrian Roosfa104232014-06-20 16:10:14 -0700973
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700974 if (inFullscreenContainer && !windowsAreFloating) {
Jorim Jaggi899327f2016-02-25 20:44:18 -0500975 // Windows that are not fullscreen can be positioned outside of the display frame,
976 // but that is not a reason to provide them with overscan insets.
chaviw9c81e632018-07-31 11:17:52 -0700977 InsetUtils.insetsBetweenFrames(layoutContainingFrame, mWindowFrames.mOverscanFrame,
978 mWindowFrames.mOverscanInsets);
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800979 }
Craig Mautnereda67292013-04-28 13:50:14 -0700980
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100981 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
chaviw1454b392018-08-06 09:54:04 -0700982 final WmDisplayCutout c = mWindowFrames.mDisplayCutout.calculateRelativeTo(
chaviw553b0212018-07-12 13:37:01 -0700983 mWindowFrames.mDisplayFrame);
chaviw9c81e632018-07-31 11:17:52 -0700984 mWindowFrames.calculateDockedDividerInsets(c.getDisplayCutout().getSafeInsets());
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100985 } else {
Bryce Leef3c6a472017-11-14 14:53:06 -0800986 getDisplayContent().getBounds(mTmpRect);
chaviw9c81e632018-07-31 11:17:52 -0700987 mWindowFrames.calculateInsets(windowsAreFloating, inFullscreenContainer, mTmpRect);
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100988 }
Adrian Roosfa104232014-06-20 16:10:14 -0700989
chaviwcdba9a42018-07-19 11:36:42 -0700990 mWindowFrames.setDisplayCutout(
chaviw1454b392018-08-06 09:54:04 -0700991 mWindowFrames.mDisplayCutout.calculateRelativeTo(mWindowFrames.mFrame));
Jorim Jaggibae2b152018-04-18 17:27:27 +0200992
Jorim Jaggi656f6502016-04-11 21:08:17 -0700993 // Offset the actual frame by the amount layout frame is off.
chaviw9c81e632018-07-31 11:17:52 -0700994 mWindowFrames.offsetFrames(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -0700995
chaviw9c81e632018-07-31 11:17:52 -0700996 mWindowFrames.mCompatFrame.set(mWindowFrames.mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400997 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700998 // If there is a size compatibility scale being applied to the
999 // window, we need to apply this to its insets so that they are
1000 // reported to the app in its coordinate space.
chaviw9c81e632018-07-31 11:17:52 -07001001 mWindowFrames.scaleInsets(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001002
1003 // Also the scaled frame that we report to the app needs to be
1004 // adjusted to be in its coordinate space.
chaviw9c81e632018-07-31 11:17:52 -07001005 mWindowFrames.mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001006 }
1007
chaviw492139a2018-07-16 16:07:35 -07001008 if (mIsWallpaper && (fw != mWindowFrames.mFrame.width()
1009 || fh != mWindowFrames.mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001010 final DisplayContent displayContent = getDisplayContent();
1011 if (displayContent != null) {
1012 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
chaviw553b0212018-07-12 13:37:01 -07001013 getDisplayContent().mWallpaperController.updateWallpaperOffset(this,
1014 displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001015 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001016 }
1017
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001018 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001019 "Resolving (mRequestedWidth="
1020 + mRequestedWidth + ", mRequestedheight="
1021 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
chaviw492139a2018-07-16 16:07:35 -07001022 + "): frame=" + mWindowFrames.mFrame.toShortString()
chaviw9c81e632018-07-31 11:17:52 -07001023 + " " + mWindowFrames.getInsetsInfo());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001024 }
1025
Bryce Leef3c6a472017-11-14 14:53:06 -08001026 // TODO: Look into whether this override is still necessary.
1027 @Override
1028 public Rect getBounds() {
1029 if (isInMultiWindowMode()) {
1030 return getTask().getBounds();
1031 } else if (mAppToken != null){
1032 return mAppToken.getBounds();
1033 } else {
1034 return super.getBounds();
1035 }
1036 }
1037
Craig Mautnera2c77052012-03-26 12:14:43 -07001038 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001039 public Rect getFrameLw() {
chaviw492139a2018-07-16 16:07:35 -07001040 return mWindowFrames.mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001041 }
1042
Craig Mautnera2c77052012-03-26 12:14:43 -07001043 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001044 public Rect getDisplayFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001045 return mWindowFrames.mDisplayFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001046 }
1047
Craig Mautnera2c77052012-03-26 12:14:43 -07001048 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001049 public Rect getOverscanFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001050 return mWindowFrames.mOverscanFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001051 }
1052
1053 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001054 public Rect getContentFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001055 return mWindowFrames.mContentFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001056 }
1057
Craig Mautnera2c77052012-03-26 12:14:43 -07001058 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001059 public Rect getVisibleFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001060 return mWindowFrames.mVisibleFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001061 }
1062
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001063 Rect getStableFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001064 return mWindowFrames.mStableFrame;
1065 }
1066
1067 Rect getDecorFrame() {
1068 return mWindowFrames.mDecorFrame;
1069 }
1070
1071 Rect getParentFrame() {
1072 return mWindowFrames.mParentFrame;
1073 }
1074
1075 Rect getContainingFrame() {
1076 return mWindowFrames.mContainingFrame;
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001077 }
1078
chaviwcdba9a42018-07-19 11:36:42 -07001079 WmDisplayCutout getWmDisplayCutout() {
1080 return mWindowFrames.mDisplayCutout;
1081 }
1082
chaviw9c81e632018-07-31 11:17:52 -07001083 void getCompatFrame(Rect outFrame) {
1084 outFrame.set(mWindowFrames.mCompatFrame);
1085 }
1086
1087 void getCompatFrameSize(Rect outFrame) {
1088 outFrame.set(0, 0, mWindowFrames.mCompatFrame.width(), mWindowFrames.mCompatFrame.height());
1089 }
1090
Craig Mautnera2c77052012-03-26 12:14:43 -07001091 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001092 public boolean getGivenInsetsPendingLw() {
1093 return mGivenInsetsPending;
1094 }
1095
Craig Mautnera2c77052012-03-26 12:14:43 -07001096 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001097 public Rect getGivenContentInsetsLw() {
1098 return mGivenContentInsets;
1099 }
1100
Craig Mautnera2c77052012-03-26 12:14:43 -07001101 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001102 public Rect getGivenVisibleInsetsLw() {
1103 return mGivenVisibleInsets;
1104 }
1105
Craig Mautnera2c77052012-03-26 12:14:43 -07001106 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001107 public WindowManager.LayoutParams getAttrs() {
1108 return mAttrs;
1109 }
1110
Craig Mautner812d2ca2012-09-27 15:35:34 -07001111 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001112 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001113 return getDisplayContent().getNeedsMenu(this, bottom);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001114 }
1115
Craig Mautner19d59bc2012-09-04 11:15:56 -07001116 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001117 public int getSystemUiVisibility() {
1118 return mSystemUiVisibility;
1119 }
1120
Craig Mautner19d59bc2012-09-04 11:15:56 -07001121 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001122 public int getSurfaceLayer() {
1123 return mLayer;
1124 }
1125
Craig Mautner812d2ca2012-09-27 15:35:34 -07001126 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001127 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001128 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001129 }
1130
1131 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001132 public IApplicationToken getAppToken() {
1133 return mAppToken != null ? mAppToken.appToken : null;
1134 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001135
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001136 @Override
1137 public boolean isVoiceInteraction() {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001138 return mAppToken != null && mAppToken.mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001139 }
1140
Robert Carr31aa98b2016-07-20 15:29:03 -07001141 boolean setReportResizeHints() {
chaviw9c81e632018-07-31 11:17:52 -07001142 return mWindowFrames.setReportResizeHints();
Craig Mautner4c5eb222013-11-18 12:59:05 -08001143 }
1144
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001145 /**
1146 * Adds the window to the resizing list if any of the parameters we use to track the window
1147 * dimensions or insets have changed.
1148 */
1149 void updateResizingWindowIfNeeded() {
1150 final WindowStateAnimator winAnimator = mWinAnimator;
Adrian Roos5251b1d2018-03-23 18:57:43 +01001151 if (!mHasSurface || getDisplayContent().mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001152 return;
1153 }
1154
1155 final Task task = getTask();
1156 // In the case of stack bound animations, the window frames will update (unlike other
1157 // animations which just modify various transformation properties). We don't want to
1158 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1159 // the frame may not correspond to the surface size or the onscreen area at various
1160 // phases in the animation, and the client will become sad and confused.
Winson Chung40a5f932017-04-13 16:39:36 -07001161 if (task != null && task.mStack.isAnimatingBounds()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001162 return;
1163 }
1164
chaviw9c81e632018-07-31 11:17:52 -07001165 boolean didFrameInsetsChange = setReportResizeHints();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001166 boolean configChanged = isConfigChanged();
1167 if (DEBUG_CONFIGURATION && configChanged) {
1168 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1169 }
1170
1171 final boolean dragResizingChanged = isDragResizeChanged()
1172 && !isDragResizingChangeReported();
1173
1174 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
chaviw492139a2018-07-16 16:07:35 -07001175 + " dragResizingChanged=" + dragResizingChanged
1176 + " last=" + mWindowFrames.mLastFrame + " frame=" + mWindowFrames.mFrame);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001177
1178 // We update mLastFrame always rather than in the conditional with the last inset
1179 // variables, because mFrameSizeChanged only tracks the width and height changing.
chaviw492139a2018-07-16 16:07:35 -07001180 mWindowFrames.mLastFrame.set(mWindowFrames.mFrame);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001181
chaviw9c81e632018-07-31 11:17:52 -07001182 if (didFrameInsetsChange
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001183 || winAnimator.mSurfaceResized
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001184 || configChanged
1185 || dragResizingChanged
Andrii Kulianb2e37802017-01-11 00:36:44 -08001186 || mReportOrientationChanged) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001187 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1188 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
chaviw9c81e632018-07-31 11:17:52 -07001189 + " " + mWindowFrames.getInsetsChangedInfo()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001190 + " surfaceResized=" + winAnimator.mSurfaceResized
1191 + " configChanged=" + configChanged
1192 + " dragResizingChanged=" + dragResizingChanged
chaviw9c81e632018-07-31 11:17:52 -07001193 + " reportOrientationChanged=" + mReportOrientationChanged);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001194 }
1195
1196 // If it's a dead window left on screen, and the configuration changed, there is nothing
1197 // we can do about it. Remove the window now.
1198 if (mAppToken != null && mAppDied) {
1199 mAppToken.removeDeadWindows();
1200 return;
1201 }
1202
Jorim Jaggidc9385a2017-05-13 02:00:31 +02001203 updateLastInsetValues();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001204 mWmService.makeWindowFreezingScreenIfNeededLocked(this);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001205
1206 // If the orientation is changing, or we're starting or ending a drag resizing action,
1207 // then we need to hold off on unfreezing the display until this window has been
1208 // redrawn; to do that, we need to go through the process of getting informed by the
1209 // application when it has finished drawing.
Robert Carr09286c92018-02-15 13:52:31 -08001210 if (getOrientationChanging() || dragResizingChanged) {
Robert Carre13b58e2017-08-31 14:50:44 -07001211 if (DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001212 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1213 + ", mDrawState=DRAW_PENDING in " + this
1214 + ", surfaceController " + winAnimator.mSurfaceController);
1215 }
1216 winAnimator.mDrawState = DRAW_PENDING;
1217 if (mAppToken != null) {
1218 mAppToken.clearAllDrawn();
1219 }
1220 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001221 if (!mWmService.mResizingWindows.contains(this)) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001222 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001223 mWmService.mResizingWindows.add(this);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001224 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07001225 } else if (getOrientationChanging()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001226 if (isDrawnLw()) {
1227 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1228 + this + ", surfaceController " + winAnimator.mSurfaceController);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001229 setOrientationChanging(false);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001230 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001231 - mWmService.mDisplayFreezeTime);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001232 }
1233 }
1234 }
1235
Bryce Lee8c3cf382017-07-06 19:47:10 -07001236 boolean getOrientationChanging() {
1237 // In addition to the local state flag, we must also consider the difference in the last
1238 // reported configuration vs. the current state. If the client code has not been informed of
1239 // the change, logic dependent on having finished processing the orientation, such as
1240 // unfreezing, could be improperly triggered.
1241 // TODO(b/62846907): Checking against {@link mLastReportedConfiguration} could be flaky as
1242 // this is not necessarily what the client has processed yet. Find a
1243 // better indicator consistent with the client.
Robert Carr926643f2017-08-02 12:01:12 -07001244 return (mOrientationChanging || (isVisible()
Bryce Lee2b17afd2017-09-21 10:38:20 -07001245 && getConfiguration().orientation != getLastReportedConfiguration().orientation))
Robert Carr9c1c3a02017-08-08 12:59:01 -07001246 && !mSeamlesslyRotated
1247 && !mOrientationChangeTimedOut;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001248 }
1249
1250 void setOrientationChanging(boolean changing) {
1251 mOrientationChanging = changing;
Robert Carr9c1c3a02017-08-08 12:59:01 -07001252 mOrientationChangeTimedOut = false;
1253 }
1254
1255 void orientationChangeTimedOut() {
1256 mOrientationChangeTimedOut = true;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001257 }
1258
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001259 DisplayContent getDisplayContent() {
1260 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001261 }
1262
Adrian Roos5251b1d2018-03-23 18:57:43 +01001263 @Override
1264 void onDisplayChanged(DisplayContent dc) {
1265 super.onDisplayChanged(dc);
1266 // Window was not laid out for this display yet, so make sure mLayoutSeq does not match.
1267 if (dc != null) {
1268 mLayoutSeq = dc.mLayoutSeq - 1;
Brad Stenningaf596412018-04-02 12:03:19 -07001269 mInputWindowHandle.displayId = dc.getDisplayId();
Adrian Roos5251b1d2018-03-23 18:57:43 +01001270 }
1271 }
1272
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001273 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001274 final DisplayContent displayContent = getDisplayContent();
1275 return displayContent != null ? displayContent.getDisplayInfo() : null;
1276 }
1277
Jorim Jaggife762342016-10-13 14:33:27 +02001278 @Override
1279 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001280 final DisplayContent displayContent = getDisplayContent();
1281 if (displayContent == null) {
Brad Stenningaf596412018-04-02 12:03:19 -07001282 return Display.INVALID_DISPLAY;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001283 }
1284 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001285 }
1286
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001287 Task getTask() {
Bryce Lee6d410262017-02-28 15:30:17 -08001288 return mAppToken != null ? mAppToken.getTask() : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001289 }
1290
1291 TaskStack getStack() {
1292 Task task = getTask();
1293 if (task != null) {
1294 if (task.mStack != null) {
1295 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001296 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001297 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001298 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1299 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001300 final DisplayContent dc = getDisplayContent();
1301 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001302 }
1303
Skuhnef932e562015-08-20 12:07:30 -07001304 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001305 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001306 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001307 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001308 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001309 final Task task = getTask();
1310 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001311 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001312 mTmpRect.setEmpty();
1313 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001314 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001315 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001316 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001317 } else {
1318 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001319 }
1320 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001321
chaviw553b0212018-07-12 13:37:01 -07001322 bounds.set(mWindowFrames.mVisibleFrame);
Chong Zhang9184ec62015-09-24 12:32:21 -07001323 if (intersectWithStackBounds) {
1324 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001325 }
1326
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001327 if (bounds.isEmpty()) {
chaviw492139a2018-07-16 16:07:35 -07001328 bounds.set(mWindowFrames.mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001329 if (intersectWithStackBounds) {
1330 bounds.intersect(mTmpRect);
1331 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001332 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001333 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001334 }
1335
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001336 public long getInputDispatchingTimeoutNanos() {
1337 return mAppToken != null
Wale Ogunwale72919d22016-12-08 18:58:50 -08001338 ? mAppToken.mInputDispatchingTimeoutNanos
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001339 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1340 }
1341
Craig Mautnere8552142012-11-07 13:55:47 -08001342 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001343 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001344 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001345 }
1346
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001347 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1348 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1349 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1350 if (dtdx < -.000001f || dtdx > .000001f) return false;
1351 if (dsdy < -.000001f || dsdy > .000001f) return false;
1352 return true;
1353 }
1354
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001355 void prelayout() {
1356 if (mEnforceSizeCompat) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001357 mGlobalScale = getDisplayContent().mCompatibleScreenScale;
1358 mInvGlobalScale = 1 / mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001359 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001360 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001361 }
1362 }
1363
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001364 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001365 boolean hasContentToDisplay() {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001366 if (!mAppFreezing && isDrawnLw() && (mViewVisibility == View.VISIBLE
lumark588a3e82018-07-20 18:53:54 +08001367 || (isAnimating() && !getDisplayContent().mAppTransition.isTransitionSet()))) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001368 return true;
1369 }
1370
Wale Ogunwale44f21802016-09-02 12:49:48 -07001371 return super.hasContentToDisplay();
1372 }
1373
1374 @Override
1375 boolean isVisible() {
Jorim Jaggicfd6f3b2018-11-07 15:30:18 +01001376 return wouldBeVisibleIfPolicyIgnored() && mPolicyVisibility
1377 // If we don't have a provider, this window isn't used as a window generating
1378 // insets, so nobody can hide it over the inset APIs.
1379 && (mInsetProvider == null || mInsetProvider.isClientVisible());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001380 }
1381
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001382 /**
Jorim Jaggicfd6f3b2018-11-07 15:30:18 +01001383 * @return {@code true} if the window would be visible if we'd ignore policy visibility,
1384 * {@code false} otherwise.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001385 */
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001386 boolean wouldBeVisibleIfPolicyIgnored() {
Jorim Jaggi43530c92017-05-18 01:53:56 +02001387 return mHasSurface && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001388 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001389 }
1390
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001391 @Override
1392 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001393 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001394 }
1395
1396 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001397 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1398 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001399 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001400 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1401 boolean isWinVisibleLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001402 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.isSelfAnimating())
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001403 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001404 }
1405
1406 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001407 * The same as isVisible(), but follows the current hidden state of the associated app token,
1408 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001409 */
1410 boolean isVisibleNow() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001411 return (!mToken.isHidden() || mAttrs.type == TYPE_APPLICATION_STARTING)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001412 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001413 }
1414
1415 /**
1416 * Can this window possibly be a drag/drop target? The test here is
1417 * a combination of the above "visible now" with the check that the
1418 * Input Manager uses when discarding windows from input consideration.
1419 */
1420 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001421 return isVisibleNow() && !mRemoved
1422 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001423 }
1424
1425 /**
1426 * Same as isVisible(), but we also count it as visible between the
1427 * call to IWindowSession.add() and the first relayout().
1428 */
1429 boolean isVisibleOrAdding() {
1430 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001431 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001432 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001433 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001434 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001435 }
1436
1437 /**
1438 * Is this window currently on-screen? It is on-screen either if it
1439 * is visible or it is currently running an animation before no longer
1440 * being visible.
1441 */
1442 boolean isOnScreen() {
Jorim Jaggiaf221d12016-11-15 14:59:57 -08001443 if (!mHasSurface || mDestroying || !mPolicyVisibility) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001444 return false;
1445 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001446 final AppWindowToken atoken = mAppToken;
1447 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001448 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001449 || isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001450 }
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001451 return !isParentWindowHidden() || isAnimating();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001452 }
1453
1454 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001455 * Whether this window's drawn state might affect the drawn states of the app token.
1456 *
Chong Zhang8e4bda92016-05-04 15:08:18 -07001457 * @return true if the window should be considered while evaluating allDrawn flags.
1458 */
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001459 boolean mightAffectAllDrawn() {
1460 final boolean isAppType = mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1461 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION;
1462 return (isOnScreen() || isAppType) && !mAnimatingExit && !mDestroying;
Chong Zhang8e4bda92016-05-04 15:08:18 -07001463 }
1464
1465 /**
1466 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1467 * it must be drawn before allDrawn can become true.
1468 */
1469 boolean isInteresting() {
1470 return mAppToken != null && !mAppDied
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001471 && (!mAppToken.isFreezingScreen() || !mAppFreezing);
Chong Zhang8e4bda92016-05-04 15:08:18 -07001472 }
1473
1474 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001475 * Like isOnScreen(), but we don't return true if the window is part
1476 * of a transition that has not yet been started.
1477 */
1478 boolean isReadyForDisplay() {
lumark588a3e82018-07-20 18:53:54 +08001479 if (mToken.waitingToShow && getDisplayContent().mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001480 return false;
1481 }
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001482 final boolean parentAndClientVisible = !isParentWindowHidden()
1483 && mViewVisibility == View.VISIBLE && !mToken.isHidden();
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001484 return mHasSurface && mPolicyVisibility && !mDestroying
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001485 && (parentAndClientVisible || isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001486 }
1487
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001488 // TODO: Another visibility method that was added late in the release to minimize risk.
1489 @Override
1490 public boolean canAffectSystemUiFlags() {
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001491 final boolean translucent = mAttrs.alpha == 0.0f;
Jorim Jaggi72207752018-01-08 13:16:59 +01001492 if (translucent) {
1493 return false;
1494 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001495 if (mAppToken == null) {
1496 final boolean shown = mWinAnimator.getShown();
1497 final boolean exiting = mAnimatingExit || mDestroying;
Jorim Jaggi72207752018-01-08 13:16:59 +01001498 return shown && !exiting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001499 } else {
Jorim Jaggi50bf59c2018-03-09 17:29:48 +01001500 final Task task = getTask();
1501 final boolean canFromTask = task != null && task.canAffectSystemUiFlags();
1502 return canFromTask && !mAppToken.isHidden();
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001503 }
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001504 }
1505
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001506 /**
1507 * Like isOnScreen, but returns false if the surface hasn't yet
1508 * been drawn.
1509 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001510 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001511 public boolean isDisplayedLw() {
1512 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001513 return isDrawnLw() && mPolicyVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001514 && ((!isParentWindowHidden() && (atoken == null || !atoken.hiddenRequested))
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001515 || isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001516 }
1517
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001518 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001519 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001520 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001521 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001522 public boolean isAnimatingLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001523 return isAnimating();
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001524 }
1525
Craig Mautner812d2ca2012-09-27 15:35:34 -07001526 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001527 public boolean isGoneForLayoutLw() {
1528 final AppWindowToken atoken = mAppToken;
1529 return mViewVisibility == View.GONE
1530 || !mRelayoutCalled
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001531 || (atoken == null && mToken.isHidden())
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001532 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001533 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001534 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001535 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001536 }
1537
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001538 /**
1539 * Returns true if the window has a surface that it has drawn a
1540 * complete UI in to.
1541 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001542 public boolean isDrawFinishedLw() {
1543 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001544 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1545 || mWinAnimator.mDrawState == READY_TO_SHOW
1546 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001547 }
1548
1549 /**
1550 * Returns true if the window has a surface that it has drawn a
1551 * complete UI in to.
1552 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001553 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001554 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001555 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001556 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001557 }
1558
1559 /**
1560 * Return true if the window is opaque and fully drawn. This indicates
1561 * it may obscure windows behind it.
1562 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001563 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001564 // When there is keyguard, wallpaper could be placed over the secure app
1565 // window but invisible. We need to check wallpaper visibility explicitly
1566 // to determine if it's occluding apps.
1567 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1568 || (mIsWallpaper && mWallpaperVisible))
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001569 && isDrawnLw() && !isAnimating();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001570 }
1571
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001572 @Override
1573 void onMovedByResize() {
1574 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001575 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001576 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001577 }
1578
1579 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1580 boolean changed = false;
1581
1582 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001583 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001584 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1585 }
1586
1587 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1588 // Starting window that's exiting will be removed when the animation finishes.
1589 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1590 // to actually remove it.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001591 if (!visible && isVisibleNow() && mAppToken.isSelfAnimating()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001592 mAnimatingExit = true;
1593 mRemoveOnExit = true;
1594 mWindowRemovalAllowed = true;
1595 }
1596 return changed;
1597 }
1598
chaviwe390cbd2018-04-16 15:29:38 -07001599 final boolean isVisibleNow = isVisibleNow();
1600 if (visible != isVisibleNow) {
1601 // Run exit animation if:
1602 // 1. App visibility and WS visibility are different
1603 // 2. App is not running an animation
1604 // 3. WS is currently visible
1605 if (!runningAppAnimation && isVisibleNow) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001606 final AccessibilityController accessibilityController =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001607 mWmService.mAccessibilityController;
chaviwe390cbd2018-04-16 15:29:38 -07001608 final int winTransit = TRANSIT_EXIT;
1609 mWinAnimator.applyAnimationLocked(winTransit, false /* isEntrance */);
Rhed Jao02655dc2018-10-30 20:44:52 +08001610 if (accessibilityController != null) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001611 accessibilityController.onWindowTransitionLocked(this, winTransit);
1612 }
1613 }
1614 changed = true;
1615 setDisplayLayoutNeeded();
1616 }
1617
1618 return changed;
1619 }
1620
1621 boolean onSetAppExiting() {
1622 final DisplayContent displayContent = getDisplayContent();
1623 boolean changed = false;
1624
1625 if (isVisibleNow()) {
1626 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
Rhed Jao02655dc2018-10-30 20:44:52 +08001627 if (mWmService.mAccessibilityController != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001628 mWmService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001629 }
1630 changed = true;
1631 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001632 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001633 }
1634 }
1635
1636 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001637 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001638 changed |= c.onSetAppExiting();
1639 }
1640
1641 return changed;
1642 }
1643
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001644 @Override
1645 void onResize() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001646 final ArrayList<WindowState> resizingWindows = mWmService.mResizingWindows;
Andrii Kulian3dcdf642018-05-23 17:14:00 -07001647 if (mHasSurface && !isGoneForLayoutLw() && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001648 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001649 resizingWindows.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001650 }
1651 if (isGoneForLayoutLw()) {
1652 mResizedWhileGone = true;
1653 }
1654
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001655 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001656 }
1657
1658 void onUnfreezeBounds() {
1659 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001660 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001661 c.onUnfreezeBounds();
1662 }
1663
1664 if (!mHasSurface) {
1665 return;
1666 }
1667
1668 mLayoutNeeded = true;
1669 setDisplayLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001670 if (!mWmService.mResizingWindows.contains(this)) {
1671 mWmService.mResizingWindows.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001672 }
1673 }
1674
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001675 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001676 * If the window has moved due to its containing content frame changing, then notify the
1677 * listeners and optionally animate it. Simply checking a change of position is not enough,
1678 * because being move due to dock divider is not a trigger for animation.
1679 */
chaviw161ea3e2018-01-31 12:01:12 -08001680 void handleWindowMovedIfNeeded() {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001681 if (!hasMoved()) {
1682 return;
1683 }
1684
1685 // Frame has moved, containing content frame has also moved, and we're not currently
1686 // animating... let's do something.
chaviw492139a2018-07-16 16:07:35 -07001687 final int left = mWindowFrames.mFrame.left;
1688 final int top = mWindowFrames.mFrame.top;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001689 final Task task = getTask();
1690 final boolean adjustedForMinimizedDockOrIme = task != null
1691 && (task.mStack.isAdjustedForMinimizedDockedStack()
1692 || task.mStack.isAdjustedForIme());
David Stevens9440dc82017-03-16 19:00:20 -07001693 if (mToken.okToAnimate()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001694 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1695 && !isDragResizing() && !adjustedForMinimizedDockOrIme
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001696 && getWindowConfiguration().hasMovementAnimations()
Adrian Roos0e7b70a2018-06-07 15:29:34 +02001697 && !mWinAnimator.mLastHidden
1698 && !mSeamlesslyRotated) {
chaviw161ea3e2018-01-31 12:01:12 -08001699 startMoveAnimation(left, top);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001700 }
1701
1702 //TODO (multidisplay): Accessibility supported only for the default display.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001703 if (mWmService.mAccessibilityController != null
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001704 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001705 mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001706 }
1707
1708 try {
1709 mClient.moved(left, top);
1710 } catch (RemoteException e) {
1711 }
1712 mMovedByResize = false;
1713 }
1714
1715 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001716 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001717 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1718 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001719 private boolean hasMoved() {
chaviw1454b392018-08-06 09:54:04 -07001720 return mHasSurface && (mWindowFrames.hasContentChanged() || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001721 && !mAnimatingExit
chaviw492139a2018-07-16 16:07:35 -07001722 && (mWindowFrames.mFrame.top != mWindowFrames.mLastFrame.top
1723 || mWindowFrames.mFrame.left != mWindowFrames.mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001724 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001725 }
1726
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001727 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001728 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001729 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001730 return false;
1731 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001732 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001733 }
1734
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001735 boolean fillsDisplay() {
1736 final DisplayInfo displayInfo = getDisplayInfo();
chaviw492139a2018-07-16 16:07:35 -07001737 return mWindowFrames.mFrame.left <= 0 && mWindowFrames.mFrame.top <= 0
1738 && mWindowFrames.mFrame.right >= displayInfo.appWidth
1739 && mWindowFrames.mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001740 }
1741
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001742 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001743 boolean isConfigChanged() {
Bryce Lee2b17afd2017-09-21 10:38:20 -07001744 return !getLastReportedConfiguration().equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001745 }
1746
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001747 void onWindowReplacementTimeout() {
1748 if (mWillReplaceWindow) {
1749 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001750 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001751 // delays removal on certain conditions, which will leave the stale window in the
1752 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1753 //
1754 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001755 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001756 } else {
1757 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001758 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001759 c.onWindowReplacementTimeout();
1760 }
1761 }
1762 }
1763
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001764 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001765 void forceWindowsScaleableInTransaction(boolean force) {
1766 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1767 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1768 }
1769
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001770 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001771 }
1772
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001773 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001774 void removeImmediately() {
1775 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001776
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001777 if (mRemoved) {
1778 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001779 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1780 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001781 return;
1782 }
1783
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001784 mRemoved = true;
1785
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001786 mWillReplaceWindow = false;
1787 if (mReplacementWindow != null) {
1788 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1789 }
1790
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001791 final DisplayContent dc = getDisplayContent();
Robert Carr825581a2018-03-30 14:00:53 -07001792 if (isInputMethodTarget()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001793 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001794 }
1795
1796 final int type = mAttrs.type;
1797 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001798 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001799 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001800 if (mTapExcludeRegionHolder != null) {
1801 // If a tap exclude region container was initialized for this window, then it should've
1802 // also been registered in display.
1803 dc.mTapExcludeProvidingWindows.remove(this);
1804 }
Tiger Huang7c610aa2018-10-27 00:01:01 +08001805 dc.getDisplayPolicy().removeWindowLw(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001806
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001807 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001808
Craig Mautner96868332012-12-04 14:29:11 -08001809 mWinAnimator.destroyDeferredSurfaceLocked();
1810 mWinAnimator.destroySurfaceLocked();
Wale Ogunwale943002b2017-02-15 19:34:01 -08001811 mSession.windowRemovedLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001812 try {
1813 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1814 } catch (RuntimeException e) {
1815 // Ignore if it has already been removed (usually because
1816 // we are doing this as part of processing a death note.)
1817 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001818
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001819 mWmService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001820 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001821
Wale Ogunwale571771c2016-08-26 13:18:50 -07001822 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001823 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001824 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001825 removeIfPossible(false /*keepVisibleDeadWindow*/);
1826 }
1827
Wale Ogunwale571771c2016-08-26 13:18:50 -07001828 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001829 mWindowRemovalAllowed = true;
1830 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1831 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1832
1833 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1834 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1835 "Starting window removed " + this);
1836
Tiger Huang1e5b10a2018-07-30 20:19:51 +08001837 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && isFocused())
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001838 Slog.v(TAG_WM, "Remove " + this + " client="
1839 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1840 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1841 + Debug.getCallers(5));
1842
1843 final long origId = Binder.clearCallingIdentity();
1844
Peter Visontay3556a3b2017-11-01 17:23:17 +00001845 try {
1846 disposeInputChannel();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001847
Peter Visontay3556a3b2017-11-01 17:23:17 +00001848 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1849 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1850 + " mAnimatingExit=" + mAnimatingExit
1851 + " mRemoveOnExit=" + mRemoveOnExit
1852 + " mHasSurface=" + mHasSurface
1853 + " surfaceShowing=" + mWinAnimator.getShown()
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001854 + " animating=" + isAnimating()
Peter Visontay3556a3b2017-11-01 17:23:17 +00001855 + " app-animation="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001856 + (mAppToken != null ? mAppToken.isSelfAnimating() : "false")
Peter Visontay3556a3b2017-11-01 17:23:17 +00001857 + " mWillReplaceWindow=" + mWillReplaceWindow
1858 + " inPendingTransaction="
1859 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001860 + " mDisplayFrozen=" + mWmService.mDisplayFrozen
Peter Visontay3556a3b2017-11-01 17:23:17 +00001861 + " callers=" + Debug.getCallers(6));
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001862
Peter Visontay3556a3b2017-11-01 17:23:17 +00001863 // Visibility of the removed window. Will be used later to update orientation later on.
1864 boolean wasVisible = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001865
Peter Visontay3556a3b2017-11-01 17:23:17 +00001866 final int displayId = getDisplayId();
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001867
Peter Visontay3556a3b2017-11-01 17:23:17 +00001868 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1869 // window until the animation is done. If the display is frozen, just remove immediately,
1870 // since the animation wouldn't be seen.
1871 if (mHasSurface && mToken.okToAnimate()) {
1872 if (mWillReplaceWindow) {
1873 // This window is going to be replaced. We need to keep it around until the new one
1874 // gets added, then we will get rid of this one.
1875 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1876 "Preserving " + this + " until the new one is " + "added");
1877 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1878 // been removed. We probably need another flag to indicate that window removal
1879 // should be deffered vs. overloading the flag that says we are playing an exit
1880 // animation.
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001881 mAnimatingExit = true;
Peter Visontay3556a3b2017-11-01 17:23:17 +00001882 mReplacingRemoveRequested = true;
1883 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001884 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001885
Peter Visontay3556a3b2017-11-01 17:23:17 +00001886 // If we are not currently running the exit animation, we need to see about starting one
1887 wasVisible = isWinVisibleLw();
1888
1889 if (keepVisibleDeadWindow) {
1890 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1891 "Not removing " + this + " because app died while it's visible");
1892
1893 mAppDied = true;
1894 setDisplayLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001895 mWmService.mWindowPlacerLocked.performSurfacePlacement();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001896
1897 // Set up a replacement input channel since the app is now dead.
1898 // We need to catch tapping on the dead window to restart the app.
1899 openInputChannel(null);
Arthur Hung95b38a92018-07-20 18:56:12 +08001900 getDisplayContent().getInputMonitor().updateInputWindowsLw(true /*force*/);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001901 return;
1902 }
1903
1904 if (wasVisible) {
1905 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
1906
1907 // Try starting an animation.
1908 if (mWinAnimator.applyAnimationLocked(transit, false)) {
1909 mAnimatingExit = true;
Jorim Jaggif41e8822018-04-06 17:22:03 +02001910
1911 // mAnimatingExit affects canAffectSystemUiFlags(). Run layout such that
1912 // any change from that is performed immediately.
1913 setDisplayLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001914 mWmService.requestTraversal();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001915 }
Rhed Jao02655dc2018-10-30 20:44:52 +08001916 if (mWmService.mAccessibilityController != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001917 mWmService.mAccessibilityController.onWindowTransitionLocked(this, transit);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001918 }
1919 }
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001920 final boolean isAnimating = isAnimating()
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001921 && (mAppToken == null || !mAppToken.isWaitingForTransitionStart());
Peter Visontay3556a3b2017-11-01 17:23:17 +00001922 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
1923 && mAppToken.isLastWindow(this);
1924 // We delay the removal of a window if it has a showing surface that can be used to run
1925 // exit animation and it is marked as exiting.
1926 // Also, If isn't the an animating starting window that is the last window in the app.
1927 // We allow the removal of the non-animating starting window now as there is no
1928 // additional window or animation that will trigger its removal.
1929 if (mWinAnimator.getShown() && mAnimatingExit
1930 && (!lastWindowIsStartingWindow || isAnimating)) {
1931 // The exit animation is running or should run... wait for it!
1932 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1933 "Not removing " + this + " due to exit animation ");
1934 setupWindowForRemoveOnExit();
1935 if (mAppToken != null) {
1936 mAppToken.updateReportedVisibilityLocked();
1937 }
1938 return;
1939 }
1940 }
1941
1942 removeImmediately();
1943 // Removing a visible window will effect the computed orientation
1944 // So just update orientation if needed.
Riddle Hsu4e611772018-10-31 18:58:28 +08001945 if (wasVisible) {
1946 final DisplayContent displayContent = getDisplayContent();
1947 if (displayContent.updateOrientationFromAppTokens()) {
1948 displayContent.sendNewConfiguration();
1949 }
Peter Visontay3556a3b2017-11-01 17:23:17 +00001950 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001951 mWmService.updateFocusedWindowLocked(isFocused()
Tiger Huang8af6ba42018-06-07 19:24:09 +08001952 ? UPDATE_FOCUS_REMOVING_FOCUS
1953 : UPDATE_FOCUS_NORMAL,
1954 true /*updateInputWindows*/);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001955 } finally {
1956 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001957 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001958 }
1959
1960 private void setupWindowForRemoveOnExit() {
1961 mRemoveOnExit = true;
1962 setDisplayLayoutNeeded();
1963 // Request a focus update as this window's input channel is already gone. Otherwise
1964 // we could have no focused window in input manager.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001965 final boolean focusChanged = mWmService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001966 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001967 mWmService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001968 if (focusChanged) {
Arthur Hung95b38a92018-07-20 18:56:12 +08001969 getDisplayContent().getInputMonitor().updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001970 }
1971 }
1972
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001973 void setHasSurface(boolean hasSurface) {
1974 mHasSurface = hasSurface;
1975 }
1976
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001977 boolean canBeImeTarget() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08001978 if (mIsImWindow) {
1979 // IME windows can't be IME targets. IME targets are required to be below the IME
1980 // windows and that wouldn't be possible if the IME window is its own target...silly.
1981 return false;
1982 }
1983
Winson Chung3d0a74a2017-07-12 12:37:19 -07001984 final boolean windowsAreFocusable = mAppToken == null || mAppToken.windowsAreFocusable();
Winson Chungb1549342017-07-11 09:59:56 -07001985 if (!windowsAreFocusable) {
1986 // This window can't be an IME target if the app's windows should not be focusable.
1987 return false;
1988 }
1989
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08001990 final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001991 final int type = mAttrs.type;
1992
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08001993 // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are set or
1994 // both are cleared...and not a starting window.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001995 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
1996 && type != TYPE_APPLICATION_STARTING) {
1997 return false;
1998 }
1999
2000 if (DEBUG_INPUT_METHOD) {
2001 Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding());
2002 if (!isVisibleOrAdding()) {
2003 Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController
2004 + " relayoutCalled=" + mRelayoutCalled
2005 + " viewVis=" + mViewVisibility
2006 + " policyVis=" + mPolicyVisibility
2007 + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim
2008 + " parentHidden=" + isParentWindowHidden()
2009 + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
2010 if (mAppToken != null) {
2011 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + mAppToken.hiddenRequested);
2012 }
2013 }
2014 }
2015 return isVisibleOrAdding();
2016 }
2017
Chong Zhangacf11402015-11-04 16:23:10 -08002018 private final class DeadWindowEventReceiver extends InputEventReceiver {
2019 DeadWindowEventReceiver(InputChannel inputChannel) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002020 super(inputChannel, mWmService.mH.getLooper());
Chong Zhangacf11402015-11-04 16:23:10 -08002021 }
2022 @Override
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08002023 public void onInputEvent(InputEvent event) {
Chong Zhangacf11402015-11-04 16:23:10 -08002024 finishInputEvent(event, true);
2025 }
2026 }
2027 /**
2028 * Dummy event receiver for windows that died visible.
2029 */
2030 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2031
Chong Zhang112eb8c2015-11-02 11:17:00 -08002032 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002033 if (mInputChannel != null) {
2034 throw new IllegalStateException("Window already has an input channel.");
2035 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002036 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002037 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2038 mInputChannel = inputChannels[0];
2039 mClientChannel = inputChannels[1];
Robert Carreadae822018-10-11 19:07:03 -07002040 mInputWindowHandle.token = mClient.asBinder();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002041 if (outInputChannel != null) {
2042 mClientChannel.transferTo(outInputChannel);
2043 mClientChannel.dispose();
2044 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002045 } else {
2046 // If the window died visible, we setup a dummy input channel, so that taps
2047 // can still detected by input monitor channel, and we can relaunch the app.
2048 // Create dummy event receiver that simply reports all events as handled.
2049 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002050 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002051 mWmService.mInputManager.registerInputChannel(mInputChannel, mClient.asBinder());
Jeff Browncc4f7db2011-08-30 20:34:48 -07002052 }
2053
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002054 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002055 if (mDeadWindowEventReceiver != null) {
2056 mDeadWindowEventReceiver.dispose();
2057 mDeadWindowEventReceiver = null;
2058 }
2059
2060 // unregister server channel first otherwise it complains about broken channel
2061 if (mInputChannel != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002062 mWmService.mInputManager.unregisterInputChannel(mInputChannel);
Robert Carre0a353c2018-08-02 16:38:04 -07002063
Chong Zhangacf11402015-11-04 16:23:10 -08002064 mInputChannel.dispose();
2065 mInputChannel = null;
2066 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002067 if (mClientChannel != null) {
2068 mClientChannel.dispose();
2069 mClientChannel = null;
2070 }
Robert Carreadae822018-10-11 19:07:03 -07002071 mInputWindowHandle.token = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002072 }
2073
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002074 /** Returns true if the replacement window was removed. */
2075 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2076 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2077 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2078 removeReplacedWindow();
2079 return true;
2080 }
2081
2082 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002083 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002084 if (c.removeReplacedWindowIfNeeded(replacement)) {
2085 return true;
2086 }
2087 }
2088 return false;
2089 }
2090
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002091 private void removeReplacedWindow() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002092 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002093 mWillReplaceWindow = false;
2094 mAnimateReplacingWindow = false;
2095 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002096 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002097 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002098 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002099 }
2100 }
2101
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002102 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2103 boolean replacementSet = false;
2104
2105 if (mWillReplaceWindow && mReplacementWindow == null
2106 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2107
2108 mReplacementWindow = replacementCandidate;
2109 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2110 replacementSet = true;
2111 }
2112
2113 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002114 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002115 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2116 }
2117
2118 return replacementSet;
2119 }
2120
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002121 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002122 final DisplayContent dc = getDisplayContent();
2123 if (dc != null) {
2124 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002125 }
2126 }
2127
Chong Zhang5117e272016-05-03 12:47:34 -07002128 void applyAdjustForImeIfNeeded() {
2129 final Task task = getTask();
2130 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2131 task.mStack.applyAdjustForImeIfNeeded(task);
2132 }
2133 }
2134
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002135 @Override
2136 void switchUser() {
2137 super.switchUser();
2138 if (isHiddenFromUserLocked()) {
2139 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2140 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
2141 hideLw(false);
2142 }
2143 }
2144
Riddle Hsuff03df52018-12-05 21:43:02 +08002145 int getSurfaceTouchableRegion(Region region, int flags) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002146 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002147 if (modal && mAppToken != null) {
2148 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002149 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002150 // If this is a modal window we need to dismiss it if it's not full screen and the
2151 // touch happens outside of the frame that displays the content. This means we
2152 // need to intercept touches outside of that window. The dim layer user
2153 // associated with the window (task or stack) will give us the good bounds, as
2154 // they would be used to display the dim layer.
Robert Carrf59b8dd2017-10-02 18:58:36 -07002155 final Task task = getTask();
2156 if (task != null) {
2157 task.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002158 } else {
Robert Carrf59b8dd2017-10-02 18:58:36 -07002159 getStack().getDimBounds(mTmpRect);
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002160 }
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002161 if (inFreeformWindowingMode()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002162 // For freeform windows we the touch region to include the whole surface for the
2163 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002164 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2165 final int delta = WindowManagerService.dipToPixel(
2166 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2167 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002168 }
2169 region.set(mTmpRect);
Riddle Hsub5e960f2018-12-07 14:51:26 +08002170 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002171 } else {
2172 // Not modal or full screen modal
Riddle Hsub5e960f2018-12-07 14:51:26 +08002173 getTouchableRegion(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002174 }
Riddle Hsub5e960f2018-12-07 14:51:26 +08002175 // Translate to surface based coordinates.
2176 region.translate(-mWindowFrames.mFrame.left, -mWindowFrames.mFrame.top);
Robert Carra80ad042018-08-14 12:54:20 -07002177
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002178 return flags;
2179 }
2180
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002181 void checkPolicyVisibilityChange() {
2182 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2183 if (DEBUG_VISIBILITY) {
2184 Slog.v(TAG, "Policy visibility changing after anim in " +
2185 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2186 }
2187 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002188 if (!mPolicyVisibility) {
Jorim Jaggi2e05af22017-12-28 15:15:11 +01002189 mWinAnimator.hide("checkPolicyVisibilityChange");
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002190 if (isFocused()) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002191 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2192 "setAnimationLocked: setting mFocusMayChange true");
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002193 mWmService.mFocusMayChange = true;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002194 }
Tetsutoki Shiozawa64c5f0c2018-05-18 10:55:01 +09002195 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002196 // Window is no longer visible -- make sure if we were waiting
2197 // for it to be displayed before enabling the display, that
2198 // we allow the display to be enabled now.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002199 mWmService.enableScreenIfNeededLocked();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002200 }
2201 }
2202 }
2203
2204 void setRequestedSize(int requestedWidth, int requestedHeight) {
2205 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2206 mLayoutNeeded = true;
2207 mRequestedWidth = requestedWidth;
2208 mRequestedHeight = requestedHeight;
2209 }
2210 }
2211
Bryce Leef858b572017-06-29 14:03:33 -07002212 void prepareWindowToDisplayDuringRelayout(boolean wasVisible) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002213 // We need to turn on screen regardless of visibility.
chaviw40234662018-02-07 09:37:16 -08002214 boolean hasTurnScreenOnFlag = (mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0;
2215 boolean allowTheaterMode =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002216 mWmService.mAllowTheaterModeWakeFromLayout || Settings.Global.getInt(
2217 mWmService.mContext.getContentResolver(), Settings.Global.THEATER_MODE_ON, 0)
chaviw40234662018-02-07 09:37:16 -08002218 == 0;
2219 boolean canTurnScreenOn = mAppToken == null || mAppToken.canTurnScreenOn();
2220
2221 // The screen will turn on if the following conditions are met
2222 // 1. The window has the flag FLAG_TURN_SCREEN_ON
2223 // 2. The WMS allows theater mode.
2224 // 3. No AWT or the AWT allows the screen to be turned on. This should only be true once
2225 // per resume to prevent the screen getting getting turned on for each relayout. Set
2226 // canTurnScreenOn will be set to false so the window doesn't turn the screen on again
2227 // during this resume.
2228 // 4. When the screen is not interactive. This is because when the screen is already
2229 // interactive, the value may persist until the next animation, which could potentially
2230 // be occurring while turning off the screen. This would lead to the screen incorrectly
2231 // turning back on.
chaviw474093d2018-03-07 15:03:38 -08002232 if (hasTurnScreenOnFlag) {
2233 if (allowTheaterMode && canTurnScreenOn && !mPowerManagerWrapper.isInteractive()) {
2234 if (DEBUG_VISIBILITY || DEBUG_POWER) {
2235 Slog.v(TAG, "Relayout window turning screen on: " + this);
2236 }
2237 mPowerManagerWrapper.wakeUp(SystemClock.uptimeMillis(),
2238 "android.server.wm:TURN_ON");
chaviw40234662018-02-07 09:37:16 -08002239 }
chaviwb28de1f2018-03-02 10:42:36 -08002240
2241 if (mAppToken != null) {
2242 mAppToken.setCanTurnScreenOn(false);
2243 }
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002244 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002245
2246 // If we were already visible, skip rest of preparation.
2247 if (wasVisible) {
2248 if (DEBUG_VISIBILITY) Slog.v(TAG,
2249 "Already visible and does not turn on screen, skip preparing: " + this);
2250 return;
2251 }
2252
2253 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2254 == SOFT_INPUT_ADJUST_RESIZE) {
2255 mLayoutNeeded = true;
2256 }
2257
David Stevens9440dc82017-03-16 19:00:20 -07002258 if (isDrawnLw() && mToken.okToAnimate()) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002259 mWinAnimator.applyEnterAnimationLocked();
2260 }
Bryce Leef858b572017-06-29 14:03:33 -07002261 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002262
Yunfan Chen75157d72018-07-27 14:47:21 +09002263 private Configuration getProcessGlobalConfiguration() {
2264 // For child windows we want to use the pid for the parent window in case the the child
2265 // window was added from another process.
Yunfan Chen79b96062018-10-17 12:45:23 -07002266 final int pid = getParentWindow() != null ? getParentWindow().mSession.mPid : mSession.mPid;
Yunfan Chenc2ff6cf2018-12-04 16:56:21 -08002267 final Configuration processConfig =
2268 mWmService.mAtmService.getGlobalConfigurationForPid(pid);
2269 mTempConfiguration.setTo(processConfig == null
2270 ? mWmService.mRoot.getConfiguration() : processConfig);
Yunfan Chen75157d72018-07-27 14:47:21 +09002271 return mTempConfiguration;
2272 }
2273
Bryce Leef858b572017-06-29 14:03:33 -07002274 void getMergedConfiguration(MergedConfiguration outConfiguration) {
Yunfan Chen75157d72018-07-27 14:47:21 +09002275 final Configuration globalConfig = getProcessGlobalConfiguration();
Bryce Leef858b572017-06-29 14:03:33 -07002276 final Configuration overrideConfig = getMergedOverrideConfiguration();
2277 outConfiguration.setConfiguration(globalConfig, overrideConfig);
2278 }
2279
Bryce Lee2b17afd2017-09-21 10:38:20 -07002280 void setLastReportedMergedConfiguration(MergedConfiguration config) {
2281 mLastReportedConfiguration.setTo(config);
2282 }
2283
2284 void getLastReportedMergedConfiguration(MergedConfiguration config) {
2285 config.setTo(mLastReportedConfiguration);
2286 }
2287
2288 private Configuration getLastReportedConfiguration() {
2289 return mLastReportedConfiguration.getMergedConfiguration();
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002290 }
2291
2292 void adjustStartingWindowFlags() {
2293 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2294 && mAppToken.startingWindow != null) {
2295 // Special handling of starting window over the base
2296 // window of the app: propagate lock screen flags to it,
2297 // to provide the correct semantics while starting.
2298 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2299 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2300 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2301 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2302 }
2303 }
2304
2305 void setWindowScale(int requestedWidth, int requestedHeight) {
2306 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2307
2308 if (scaledWindow) {
2309 // requested{Width|Height} Surface's physical size
2310 // attrs.{width|height} Size on screen
2311 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2312 mHScale = (mAttrs.width != requestedWidth) ?
2313 (mAttrs.width / (float)requestedWidth) : 1.0f;
2314 mVScale = (mAttrs.height != requestedHeight) ?
2315 (mAttrs.height / (float)requestedHeight) : 1.0f;
2316 } else {
2317 mHScale = mVScale = 1;
2318 }
2319 }
2320
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002321 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002322 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002323 public void binderDied() {
2324 try {
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002325 boolean resetSplitScreenResizing = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002326 synchronized (mWmService.mGlobalLock) {
2327 final WindowState win = mWmService
2328 .windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002329 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002330 if (win != null) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002331 final DisplayContent dc = getDisplayContent();
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002332 if (win.mAppToken != null && win.mAppToken.findMainWindow() == win) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002333 mWmService.mTaskSnapshotController.onAppDied(win.mAppToken);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002334 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002335 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002336 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2337 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002338 // just in case they have the divider at an unstable position. Better
2339 // also reset drag resizing state, because the owner can't do it
2340 // anymore.
Wale Ogunwale61911492017-10-11 08:50:50 -07002341 final TaskStack stack =
Matthew Ng64e77cf2017-10-31 14:01:31 -07002342 dc.getSplitScreenPrimaryStackIgnoringVisibility();
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002343 if (stack != null) {
2344 stack.resetDockedStackToMiddle();
2345 }
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002346 resetSplitScreenResizing = true;
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002347 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002348 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002349 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002350 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002351 }
2352 }
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002353 if (resetSplitScreenResizing) {
2354 try {
2355 // Note: this calls into ActivityManager, so we must *not* hold the window
2356 // manager lock while calling this.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002357 mWmService.mActivityTaskManager.setSplitScreenResizing(false);
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002358 } catch (RemoteException e) {
2359 // Local call, shouldn't return RemoteException.
2360 throw e.rethrowAsRuntimeException();
2361 }
2362 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002363 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002364 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002365 }
2366 }
2367 }
2368
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002369 /**
2370 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2371 * because we want to preserve its location on screen to be re-activated later when the user
2372 * interacts with it.
2373 */
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002374 private boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwale89973222017-04-23 18:39:45 -07002375 if (!isWinVisibleLw() || mAppToken == null || mAppToken.isClientHidden()) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002376 // Not a visible app window or the app isn't dead.
2377 return false;
2378 }
2379
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002380 if (mAttrs.token != mClient.asBinder()) {
2381 // The window was add by a client using another client's app token. We don't want to
2382 // keep the dead window around for this case since this is meant for 'real' apps.
2383 return false;
2384 }
2385
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002386 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2387 // We don't keep starting windows since they were added by the window manager before
2388 // the app even launched.
2389 return false;
2390 }
2391
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002392 return getWindowConfiguration().keepVisibleDeadAppWindowOnScreen();
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002393 }
2394
Tiger Huang513d5e12018-07-16 21:49:50 +08002395 @Override
2396 public boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002397 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002398 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002399 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002400 && (mAppToken == null || mAppToken.windowsAreFocusable())
Robert Carrebdf8582018-09-04 14:50:15 -07002401 && !cantReceiveTouchInput();
Matthew Nge15352e2016-12-20 15:36:29 -08002402 }
2403
Robert Carrebdf8582018-09-04 14:50:15 -07002404 /** @return false if this window desires touch events. */
2405 boolean cantReceiveTouchInput() {
Bryce Lee6d410262017-02-28 15:30:17 -08002406 return mAppToken != null && mAppToken.getTask() != null
2407 && mAppToken.getTask().mStack.shouldIgnoreInput();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002408 }
2409
Craig Mautner749a7bb2012-04-02 13:49:53 -07002410 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002411 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002412 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002413 }
2414
Craig Mautner749a7bb2012-04-02 13:49:53 -07002415 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002416 public boolean showLw(boolean doAnimation) {
2417 return showLw(doAnimation, true);
2418 }
2419
2420 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002421 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002422 return false;
2423 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002424 if (!mAppOpVisibility) {
2425 // Being hidden due to app op request.
2426 return false;
2427 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002428 if (mPermanentlyHidden) {
2429 // Permanently hidden until the app exists as apps aren't prepared
2430 // to handle their windows being removed from under them.
2431 return false;
2432 }
Suprabh Shukla69c71422018-04-02 18:39:01 -07002433 if (mHiddenWhileSuspended) {
2434 // Being hidden due to owner package being suspended.
2435 return false;
2436 }
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002437 if (mForceHideNonSystemOverlayWindow) {
2438 // This is an alert window that is currently force hidden.
2439 return false;
2440 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002441 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002442 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002443 return false;
2444 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002445 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002446 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002447 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02002448 + mPolicyVisibility + " animating=" + isAnimating());
David Stevens9440dc82017-03-16 19:00:20 -07002449 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002450 doAnimation = false;
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02002451 } else if (mPolicyVisibility && !isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002452 // Check for the case where we are currently visible and
2453 // not animating; we do not want to do animation at such a
2454 // point to become visible when we already are.
2455 doAnimation = false;
2456 }
2457 }
2458 mPolicyVisibility = true;
2459 mPolicyVisibilityAfterAnim = true;
2460 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002461 mWinAnimator.applyAnimationLocked(TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002462 }
2463 if (requestAnim) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002464 mWmService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002465 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002466 if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002467 mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002468 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002469 return true;
2470 }
2471
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002472 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002473 public boolean hideLw(boolean doAnimation) {
2474 return hideLw(doAnimation, true);
2475 }
2476
2477 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2478 if (doAnimation) {
David Stevens9440dc82017-03-16 19:00:20 -07002479 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002480 doAnimation = false;
2481 }
2482 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002483 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002484 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002485 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002486 return false;
2487 }
2488 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002489 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02002490 if (!isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002491 doAnimation = false;
2492 }
2493 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002494 mPolicyVisibilityAfterAnim = false;
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002495 final boolean isFocused = isFocused();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002496 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002497 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002498 mPolicyVisibility = false;
2499 // Window is no longer visible -- make sure if we were waiting
2500 // for it to be displayed before enabling the display, that
2501 // we allow the display to be enabled now.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002502 mWmService.enableScreenIfNeededLocked();
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002503 if (isFocused) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002504 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002505 "WindowState.hideLw: setting mFocusMayChange true");
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002506 mWmService.mFocusMayChange = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002507 }
2508 }
2509 if (requestAnim) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002510 mWmService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002511 }
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002512 if (isFocused) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002513 mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002514 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002515 return true;
2516 }
2517
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002518 void setForceHideNonSystemOverlayWindowIfNeeded(boolean forceHide) {
2519 if (mOwnerCanAddInternalSystemWindow
2520 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2521 return;
2522 }
2523 if (mForceHideNonSystemOverlayWindow == forceHide) {
2524 return;
2525 }
2526 mForceHideNonSystemOverlayWindow = forceHide;
2527 if (forceHide) {
2528 hideLw(true /* doAnimation */, true /* requestAnim */);
2529 } else {
2530 showLw(true /* doAnimation */, true /* requestAnim */);
2531 }
2532 }
2533
Suprabh Shukla69c71422018-04-02 18:39:01 -07002534 void setHiddenWhileSuspended(boolean hide) {
2535 if (mOwnerCanAddInternalSystemWindow
2536 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2537 return;
2538 }
2539 if (mHiddenWhileSuspended == hide) {
2540 return;
2541 }
2542 mHiddenWhileSuspended = hide;
2543 if (hide) {
2544 hideLw(true, true);
2545 } else {
2546 showLw(true, true);
2547 }
2548 }
2549
Svet Ganovf7b47252018-02-26 11:11:27 -08002550 private void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002551 if (mAppOpVisibility != state) {
2552 mAppOpVisibility = state;
2553 if (state) {
2554 // If the policy visibility had last been to hide, then this
2555 // will incorrectly show at this point since we lost that
2556 // information. Not a big deal -- for the windows that have app
2557 // ops modifies they should only be hidden by policy due to the
2558 // lock screen, and the user won't be changing this if locked.
2559 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002560 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002561 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002562 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002563 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002564 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002565 }
2566
Svet Ganovf7b47252018-02-26 11:11:27 -08002567 void initAppOpsState() {
2568 if (mAppOp == OP_NONE || !mAppOpVisibility) {
2569 return;
2570 }
2571 // If the app op was MODE_DEFAULT we would have checked the permission
2572 // and add the window only if the permission was granted. Therefore, if
2573 // the mode is MODE_DEFAULT we want the op to succeed as the window is
2574 // shown.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002575 final int mode = mWmService.mAppOps.startOpNoThrow(mAppOp,
Svet Ganovf7b47252018-02-26 11:11:27 -08002576 getOwningUid(), getOwningPackage(), true);
2577 if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) {
2578 setAppOpVisibilityLw(false);
2579 }
2580 }
2581
2582 void resetAppOpsState() {
2583 if (mAppOp != OP_NONE && mAppOpVisibility) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002584 mWmService.mAppOps.finishOp(mAppOp, getOwningUid(), getOwningPackage());
Svet Ganovf7b47252018-02-26 11:11:27 -08002585 }
2586 }
2587
2588 void updateAppOpsState() {
2589 if (mAppOp == OP_NONE) {
2590 return;
2591 }
2592 final int uid = getOwningUid();
2593 final String packageName = getOwningPackage();
2594 if (mAppOpVisibility) {
2595 // There is a race between the check and the finish calls but this is fine
2596 // as this would mean we will get another change callback and will reconcile.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002597 int mode = mWmService.mAppOps.checkOpNoThrow(mAppOp, uid, packageName);
Svet Ganovf7b47252018-02-26 11:11:27 -08002598 if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002599 mWmService.mAppOps.finishOp(mAppOp, uid, packageName);
Svet Ganovf7b47252018-02-26 11:11:27 -08002600 setAppOpVisibilityLw(false);
2601 }
2602 } else {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002603 final int mode = mWmService.mAppOps.startOpNoThrow(mAppOp, uid, packageName, true);
Svet Ganovf7b47252018-02-26 11:11:27 -08002604 if (mode == MODE_ALLOWED || mode == MODE_DEFAULT) {
2605 setAppOpVisibilityLw(true);
2606 }
2607 }
2608 }
2609
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002610 public void hidePermanentlyLw() {
2611 if (!mPermanentlyHidden) {
2612 mPermanentlyHidden = true;
2613 hideLw(true, true);
2614 }
2615 }
2616
Jeff Brownc2932a12014-11-20 18:04:05 -08002617 public void pokeDrawLockLw(long timeout) {
2618 if (isVisibleOrAdding()) {
2619 if (mDrawLock == null) {
2620 // We want the tag name to be somewhat stable so that it is easier to correlate
2621 // in wake lock statistics. So in particular, we don't want to include the
2622 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002623 final CharSequence tag = getWindowTag();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002624 mDrawLock = mWmService.mPowerManager.newWakeLock(DRAW_WAKE_LOCK, "Window:" + tag);
Jeff Brownc2932a12014-11-20 18:04:05 -08002625 mDrawLock.setReferenceCounted(false);
2626 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2627 }
2628 // Each call to acquire resets the timeout.
2629 if (DEBUG_POWER) {
2630 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2631 + mAttrs.packageName);
2632 }
2633 mDrawLock.acquire(timeout);
2634 } else if (DEBUG_POWER) {
2635 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2636 + "owned by " + mAttrs.packageName);
2637 }
2638 }
2639
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002640 @Override
2641 public boolean isAlive() {
2642 return mClient.asBinder().isBinderAlive();
2643 }
2644
Craig Mautnera987d432012-10-11 14:07:58 -07002645 boolean isClosing() {
chaviw4ad54912018-05-30 11:05:44 -07002646 return mAnimatingExit || (mAppToken != null && mAppToken.isClosingOrEnteringPip());
Craig Mautnera987d432012-10-11 14:07:58 -07002647 }
2648
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002649 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2650 animators.add(mWinAnimator);
2651
2652 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002653 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002654 c.addWinAnimatorToList(animators);
2655 }
2656 }
2657
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002658 void sendAppVisibilityToClients() {
2659 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002660
Wale Ogunwale89973222017-04-23 18:39:45 -07002661 final boolean clientHidden = mAppToken.isClientHidden();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002662 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2663 // Don't hide the starting window.
2664 return;
2665 }
2666
Wale Ogunwale89973222017-04-23 18:39:45 -07002667 if (clientHidden) {
2668 // Once we are notifying the client that it's visibility has changed, we need to prevent
2669 // it from destroying child surfaces until the animation has finished. We do this by
2670 // detaching any surface control the client added from the client.
2671 for (int i = mChildren.size() - 1; i >= 0; --i) {
2672 final WindowState c = mChildren.get(i);
2673 c.mWinAnimator.detachChildren();
2674 }
2675
2676 mWinAnimator.detachChildren();
2677 }
2678
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002679 try {
2680 if (DEBUG_VISIBILITY) Slog.v(TAG,
2681 "Setting visibility of " + this + ": " + (!clientHidden));
2682 mClient.dispatchAppVisibility(!clientHidden);
2683 } catch (RemoteException e) {
2684 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002685 }
2686
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002687 void onStartFreezingScreen() {
2688 mAppFreezing = true;
2689 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002690 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002691 c.onStartFreezingScreen();
2692 }
2693 }
2694
2695 boolean onStopFreezingScreen() {
2696 boolean unfrozeWindows = false;
2697 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002698 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002699 unfrozeWindows |= c.onStopFreezingScreen();
2700 }
2701
2702 if (!mAppFreezing) {
2703 return unfrozeWindows;
2704 }
2705
Wale Ogunwale953171d2016-09-30 09:17:30 -07002706 mAppFreezing = false;
2707
Bryce Lee8c3cf382017-07-06 19:47:10 -07002708 if (mHasSurface && !getOrientationChanging()
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002709 && mWmService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002710 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
Bryce Lee8c3cf382017-07-06 19:47:10 -07002711 setOrientationChanging(true);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002712 mWmService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002713 }
2714 mLastFreezeDuration = 0;
2715 setDisplayLayoutNeeded();
2716 return true;
2717 }
2718
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002719 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2720 boolean destroyedSomething = false;
Jorim Jaggi59f3e922018-01-05 15:40:32 +01002721
2722 // Copying to a different list as multiple children can be removed.
2723 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
2724 for (int i = childWindows.size() - 1; i >= 0; --i) {
2725 final WindowState c = childWindows.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002726 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2727 }
2728
Robert Carrdb2f6e62017-03-01 20:17:58 -08002729 if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) {
2730 return destroyedSomething;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002731 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08002732
2733 if (appStopped || mWindowRemovalAllowed) {
2734 mWinAnimator.destroyPreservedSurfaceLocked();
2735 }
2736
2737 if (mDestroying) {
2738 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2739 + " destroySurfaces: appStopped=" + appStopped
2740 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2741 + " win.mRemoveOnExit=" + mRemoveOnExit);
2742 if (!cleanupOnResume || mRemoveOnExit) {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002743 destroySurfaceUnchecked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08002744 }
2745 if (mRemoveOnExit) {
2746 removeImmediately();
2747 }
2748 if (cleanupOnResume) {
2749 requestUpdateWallpaperIfNeeded();
2750 }
2751 mDestroying = false;
2752 destroyedSomething = true;
2753 }
2754
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002755 return destroyedSomething;
2756 }
Chris Craik3131bde2016-05-06 13:39:08 -07002757
Robert Carr89a28ab2017-04-24 15:33:11 -07002758 // Destroy or save the application surface without checking
2759 // various indicators of whether the client has released the surface.
2760 // This is in general unsafe, and most callers should use {@link #destroySurface}
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002761 void destroySurfaceUnchecked() {
2762 mWinAnimator.destroySurfaceLocked();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002763
Chong Zhang92147042016-05-09 12:47:11 -07002764 // Clear animating flags now, since the surface is now gone. (Note this is true even
2765 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2766 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002767 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002768
Craig Mautner69b08182012-09-05 13:07:13 -07002769 @Override
2770 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002771 final DisplayContent displayContent = getDisplayContent();
2772 if (displayContent == null) {
2773 // Only a window that was on a non-default display can be detached from it.
2774 return false;
2775 }
Winson Chung47a3e652014-05-21 16:03:42 -07002776 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002777 }
2778
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002779 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07002780 mShowToOwnerOnly = showToOwnerOnly;
2781 }
2782
Wale Ogunwaleea92d972016-12-08 07:33:13 -08002783 private boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002784 // Child windows are evaluated based on their parent window.
2785 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002786 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale72919d22016-12-08 18:58:50 -08002787 && win.mAppToken != null && win.mAppToken.mShowForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002788
2789 // All window frames that are fullscreen extend above status bar, but some don't extend
2790 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2791 // bottom right.
chaviw492139a2018-07-16 16:07:35 -07002792 if (win.getFrameLw().left <= win.getDisplayFrameLw().left
2793 && win.getFrameLw().top <= win.getDisplayFrameLw().top
2794 && win.getFrameLw().right >= win.getStableFrameLw().right
2795 && win.getFrameLw().bottom >= win.getStableFrameLw().bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002796 // Is a fullscreen window, like the clock alarm. Show to everyone.
2797 return false;
2798 }
2799 }
2800
Craig Mautner341220f2012-10-16 15:20:09 -07002801 return win.mShowToOwnerOnly
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002802 && !mWmService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002803 }
2804
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002805 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2806 outRegion.set(
2807 frame.left + inset.left, frame.top + inset.top,
2808 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002809 }
2810
Riddle Hsuff03df52018-12-05 21:43:02 +08002811 /** Get the touchable region in global coordinates. */
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002812 void getTouchableRegion(Region outRegion) {
chaviw492139a2018-07-16 16:07:35 -07002813 final Rect frame = mWindowFrames.mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002814 switch (mTouchableInsets) {
2815 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002816 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002817 outRegion.set(frame);
2818 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002819 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002820 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002821 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002822 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002823 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002824 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002825 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002826 outRegion.set(mGivenTouchableRegion);
Riddle Hsub5e960f2018-12-07 14:51:26 +08002827 outRegion.translate(frame.left, frame.top);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002828 break;
2829 }
2830 }
Vishnu Nairb9246322018-12-06 13:54:02 -08002831 cropRegionToStackBoundsIfNeeded(outRegion);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002832 }
2833
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002834 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002835 final Task task = getTask();
2836 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002837 return;
2838 }
2839
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002840 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002841 if (stack == null) {
2842 return;
2843 }
2844
2845 stack.getDimBounds(mTmpRect);
2846 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002847 }
2848
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002849 /**
2850 * Report a focus change. Must be called with no locks held, and consistently
2851 * from the same serialized thread (such as dispatched from a handler).
2852 */
Tiger Huang51c5a1d2018-12-11 20:24:51 +08002853 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002854 try {
Tiger Huang51c5a1d2018-12-11 20:24:51 +08002855 mClient.windowFocusChanged(focused, inTouchMode);
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002856 } catch (RemoteException e) {
2857 }
Tiger Huang51c5a1d2018-12-11 20:24:51 +08002858 if (mFocusCallbacks != null) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002859 final int N = mFocusCallbacks.beginBroadcast();
2860 for (int i=0; i<N; i++) {
2861 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2862 try {
2863 if (focused) {
2864 obs.focusGained(mWindowId.asBinder());
2865 } else {
2866 obs.focusLost(mWindowId.asBinder());
2867 }
2868 } catch (RemoteException e) {
2869 }
2870 }
2871 mFocusCallbacks.finishBroadcast();
2872 }
2873 }
2874
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002875 @Override
2876 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002877 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002878 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002879 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002880
Yunfan Chen75157d72018-07-27 14:47:21 +09002881 // We use the process config this window is associated with as the based global config since
2882 // the process can override it config, but isn't part of the window hierarchy.
2883 final Configuration config = getProcessGlobalConfiguration();
2884 config.updateFrom(getMergedOverrideConfiguration());
2885 return config;
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002886 }
2887
Craig Mautnerdf88d732014-01-27 09:21:32 -08002888 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002889 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08002890 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002891 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
chaviw9c81e632018-07-31 11:17:52 -07002892 + ": " + mWindowFrames.mCompatFrame);
Bryce Leef858b572017-06-29 14:03:33 -07002893 final MergedConfiguration mergedConfiguration =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002894 new MergedConfiguration(mWmService.mRoot.getConfiguration(),
Bryce Leef858b572017-06-29 14:03:33 -07002895 getMergedOverrideConfiguration());
2896
Bryce Lee2b17afd2017-09-21 10:38:20 -07002897 setLastReportedMergedConfiguration(mergedConfiguration);
Bryce Leef858b572017-06-29 14:03:33 -07002898
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002899 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002900 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
2901
chaviw492139a2018-07-16 16:07:35 -07002902 final Rect frame = mWindowFrames.mFrame;
chaviw9c81e632018-07-31 11:17:52 -07002903 final Rect overscanInsets = mWindowFrames.mLastOverscanInsets;
2904 final Rect contentInsets = mWindowFrames.mLastContentInsets;
2905 final Rect visibleInsets = mWindowFrames.mLastVisibleInsets;
2906 final Rect stableInsets = mWindowFrames.mLastStableInsets;
2907 final Rect outsets = mWindowFrames.mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002908 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Andrii Kulianb2e37802017-01-11 00:36:44 -08002909 final boolean reportOrientation = mReportOrientationChanged;
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002910 final int displayId = getDisplayId();
chaviwcdba9a42018-07-19 11:36:42 -07002911 final DisplayCutout displayCutout = getWmDisplayCutout().getDisplayCutout();
Chet Haase8eb48d22014-09-24 07:31:29 -07002912 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
2913 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002914 // To prevent deadlock simulate one-way call if win.mClient is a local object.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002915 mWmService.mH.post(new Runnable() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002916 @Override
2917 public void run() {
2918 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002919 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07002920 stableInsets, outsets, reportDraw, mergedConfiguration,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002921 reportOrientation, displayId, displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002922 } catch (RemoteException e) {
2923 // Not a remote call, RemoteException won't be raised.
2924 }
2925 }
2926 });
2927 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002928 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002929 outsets, reportDraw, mergedConfiguration, reportOrientation, displayId,
2930 displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002931 }
Svetoslav4604abc2014-06-10 18:59:30 -07002932
2933 //TODO (multidisplay): Accessibility supported only for the default display.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002934 if (mWmService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
2935 mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07002936 }
2937
chaviw9c81e632018-07-31 11:17:52 -07002938 mWindowFrames.resetInsetsChanged();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002939 mWinAnimator.mSurfaceResized = false;
Andrii Kulianb2e37802017-01-11 00:36:44 -08002940 mReportOrientationChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08002941 } catch (RemoteException e) {
Bryce Lee8c3cf382017-07-06 19:47:10 -07002942 setOrientationChanging(false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002943 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002944 - mWmService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08002945 // We are assuming the hosting process is dead or in a zombie state.
2946 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
2947 + ", removing this window.");
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002948 mWmService.mPendingRemove.add(this);
2949 mWmService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002950 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002951 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002952 }
2953
Jorim Jaggif96c90a2018-09-26 16:55:15 +02002954 /**
2955 * Called when the insets state changed.
2956 */
2957 void notifyInsetsChanged() {
2958 try {
2959 mClient.insetsChanged(
2960 getDisplayContent().getInsetsStateController().getInsetsForDispatch(this));
2961 } catch (RemoteException e) {
2962 Slog.w(TAG, "Failed to deliver inset state change", e);
2963 }
2964 }
2965
Jorim Jaggib6030952018-10-23 18:31:52 +02002966 void notifyInsetsControlChanged() {
2967 final InsetsStateController stateController =
2968 getDisplayContent().getInsetsStateController();
2969 try {
2970 mClient.insetsControlChanged(stateController.getInsetsForDispatch(this),
2971 stateController.getControlsForDispatch(this));
2972 } catch (RemoteException e) {
2973 Slog.w(TAG, "Failed to deliver inset state change", e);
2974 }
2975 }
2976
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002977 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08002978 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
2979 // start even if we haven't received the relayout window, so that the client requests
2980 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
2981 // until the window to small size, otherwise the multithread renderer will shift last
2982 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
2983 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002984 boolean resizing = isDragResizing() || isDragResizeChanged();
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002985 if (getWindowConfiguration().useWindowFrameForBackdrop() || !resizing) {
Garfield Tanfbd8ea62018-10-16 17:09:49 -07002986 // Surface position is now inherited from parent, and BackdropFrameRenderer uses
2987 // backdrop frame to position content. Thus we just keep the size of backdrop frame, and
2988 // remove the offset to avoid double offset from display origin.
2989 mTmpRect.set(frame);
2990 mTmpRect.offsetTo(0, 0);
2991 return mTmpRect;
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002992 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07002993 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002994 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002995 return mTmpRect;
2996 }
2997
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002998 private int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002999 final TaskStack stack = getStack();
3000 if (stack == null) {
3001 return INVALID_STACK_ID;
3002 }
3003 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003004 }
3005
3006 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
3007 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003008 MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId,
3009 DisplayCutout displayCutout)
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003010 throws RemoteException {
Robert Carr09286c92018-02-15 13:52:31 -08003011 final boolean forceRelayout = isDragResizeChanged() || reportOrientation;
Chong Zhangedaf3052016-04-22 15:04:31 -07003012
Jorim Jaggidc249c42015-12-15 14:57:31 -08003013 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003014 reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout,
Tiger Huang7c610aa2018-10-27 00:01:01 +08003015 getDisplayContent().getDisplayPolicy().isNavBarForcedShownLw(this), displayId,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003016 new DisplayCutout.ParcelableWrapper(displayCutout));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003017 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003018 }
3019
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003020 public void registerFocusObserver(IWindowFocusObserver observer) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003021 synchronized (mWmService.mGlobalLock) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003022 if (mFocusCallbacks == null) {
3023 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
3024 }
3025 mFocusCallbacks.register(observer);
3026 }
3027 }
3028
3029 public void unregisterFocusObserver(IWindowFocusObserver observer) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003030 synchronized (mWmService.mGlobalLock) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003031 if (mFocusCallbacks != null) {
3032 mFocusCallbacks.unregister(observer);
3033 }
3034 }
3035 }
3036
Tiger Huang1e5b10a2018-07-30 20:19:51 +08003037 boolean isFocused() {
3038 return getDisplayContent().mCurrentFocus == this;
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003039 }
3040
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003041 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07003042 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003043 final Task task = getTask();
3044 return task != null && !task.isFullscreen();
3045 }
3046
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003047 /** Is this window in a container that takes up the entire screen space? */
3048 private boolean inFullscreenContainer() {
Bryce Leef3c6a472017-11-14 14:53:06 -08003049 return mAppToken == null || (mAppToken.matchParentBounds() && !isInMultiWindowMode());
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003050 }
3051
Andrii Kulian283acd22017-08-03 04:03:51 -07003052 /** @return true when the window is in fullscreen task, but has non-fullscreen bounds set. */
3053 boolean isLetterboxedAppWindow() {
Adrian Roos865c70f2018-01-10 17:32:27 +01003054 return !isInMultiWindowMode() && mAppToken != null && !mAppToken.matchParentBounds()
3055 || isLetterboxedForDisplayCutoutLw();
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003056 }
3057
Adrian Roos865c70f2018-01-10 17:32:27 +01003058 @Override
3059 public boolean isLetterboxedForDisplayCutoutLw() {
3060 if (mAppToken == null) {
3061 // Only windows with an AppWindowToken are letterboxed.
3062 return false;
3063 }
chaviwcdba9a42018-07-19 11:36:42 -07003064 if (!mWindowFrames.parentFrameWasClippedByDisplayCutout()) {
Adrian Roos5ed644f2018-03-19 17:01:05 +01003065 // Cutout didn't make a difference, no letterbox
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003066 return false;
3067 }
Adrian Roosfa02da62018-01-15 16:01:18 +01003068 if (mAttrs.layoutInDisplayCutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003069 // Layout in cutout, no letterbox.
3070 return false;
3071 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003072 if (!mAttrs.isFullscreen()) {
3073 // Not filling the parent frame, no letterbox
3074 return false;
Adrian Roosfa02da62018-01-15 16:01:18 +01003075 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003076 // Otherwise we need a letterbox if the layout was smaller than the app window token allowed
3077 // it to be.
3078 return !frameCoversEntireAppTokenBounds();
3079 }
3080
3081 /**
3082 * @return true if this window covers the entire bounds of its app window token
3083 * @throws NullPointerException if there is no app window token for this window
3084 */
3085 private boolean frameCoversEntireAppTokenBounds() {
3086 mTmpRect.set(mAppToken.getBounds());
chaviw492139a2018-07-16 16:07:35 -07003087 mTmpRect.intersectUnchecked(mWindowFrames.mFrame);
Adrian Roos5ed644f2018-03-19 17:01:05 +01003088 return mAppToken.getBounds().equals(mTmpRect);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003089 }
3090
Adrian Roos23df3a32018-03-15 15:41:13 +01003091 @Override
3092 public boolean isLetterboxedOverlappingWith(Rect rect) {
3093 return mAppToken != null && mAppToken.isLetterboxOverlappingWith(rect);
3094 }
3095
Chong Zhang3005e752015-09-18 18:46:28 -07003096 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003097 return mDragResizing != computeDragResizing();
3098 }
3099
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003100 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003101 void setWaitingForDrawnIfResizingChanged() {
3102 if (isDragResizeChanged()) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003103 mWmService.mWaitingForDrawn.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003104 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003105 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003106 }
3107
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003108 /**
3109 * @return Whether we reported a drag resize change to the application or not already.
3110 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003111 private boolean isDragResizingChangeReported() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003112 return mDragResizingChangeReported;
3113 }
3114
3115 /**
3116 * Resets the state whether we reported a drag resize change to the app.
3117 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003118 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003119 void resetDragResizingChangeReported() {
3120 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003121 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003122 }
3123
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003124 int getResizeMode() {
3125 return mResizeMode;
3126 }
3127
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003128 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003129 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003130 if (task == null) {
3131 return false;
3132 }
Tomasz Mikolajewskiaf20b8d2017-11-20 16:11:33 +09003133 if (!inSplitScreenWindowingMode() && !inFreeformWindowingMode()) {
Winson Chung2af04b32017-01-24 16:21:13 -08003134 return false;
3135 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003136 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003137 // Floating windows never enter drag resize mode.
3138 return false;
3139 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003140 if (task.isDragResizing()) {
3141 return true;
3142 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003143
3144 // If the bounds are currently frozen, it means that the layout size that the app sees
3145 // and the bounds we clip this window to might be different. In order to avoid holes, we
3146 // simulate that we are still resizing so the app fills the hole with the resizing
3147 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003148 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003149 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003150 !task.inFreeformWindowingMode() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003151
Chong Zhang3005e752015-09-18 18:46:28 -07003152 }
3153
3154 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003155 final boolean resizing = computeDragResizing();
3156 if (resizing == mDragResizing) {
3157 return;
3158 }
3159 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003160 final Task task = getTask();
3161 if (task != null && task.isDragResizing()) {
3162 mResizeMode = task.getDragResizeMode();
3163 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003164 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003165 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3166 : DRAG_RESIZE_MODE_FREEFORM;
3167 }
Chong Zhang3005e752015-09-18 18:46:28 -07003168 }
3169
3170 boolean isDragResizing() {
3171 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003172 }
3173
Robert Carr2487ce72016-04-07 15:18:45 -07003174 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003175 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3176 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003177 }
3178
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07003179 @CallSuper
3180 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02003181 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003182 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02003183 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003184 writeIdentifierToProto(proto, IDENTIFIER);
3185 proto.write(DISPLAY_ID, getDisplayId());
3186 proto.write(STACK_ID, getStackId());
3187 mAttrs.writeToProto(proto, ATTRIBUTES);
3188 mGivenContentInsets.writeToProto(proto, GIVEN_CONTENT_INSETS);
chaviw553b0212018-07-12 13:37:01 -07003189 mWindowFrames.writeToProto(proto, WINDOW_FRAMES);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003190 mAttrs.surfaceInsets.writeToProto(proto, SURFACE_INSETS);
Jorim Jaggi45be1c4c2017-12-15 18:44:43 +01003191 mSurfacePosition.writeToProto(proto, SURFACE_POSITION);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003192 mWinAnimator.writeToProto(proto, ANIMATOR);
3193 proto.write(ANIMATING_EXIT, mAnimatingExit);
3194 for (int i = 0; i < mChildren.size(); i++) {
Adrian Roos4921ccf2017-09-28 16:54:06 +02003195 mChildren.get(i).writeToProto(proto, CHILD_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003196 }
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003197 proto.write(REQUESTED_WIDTH, mRequestedWidth);
3198 proto.write(REQUESTED_HEIGHT, mRequestedHeight);
3199 proto.write(VIEW_VISIBILITY, mViewVisibility);
3200 proto.write(SYSTEM_UI_VISIBILITY, mSystemUiVisibility);
3201 proto.write(HAS_SURFACE, mHasSurface);
3202 proto.write(IS_READY_FOR_DISPLAY, isReadyForDisplay());
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003203 proto.write(REMOVE_ON_EXIT, mRemoveOnExit);
3204 proto.write(DESTROYING, mDestroying);
3205 proto.write(REMOVED, mRemoved);
3206 proto.write(IS_ON_SCREEN, isOnScreen());
3207 proto.write(IS_VISIBLE, isVisible());
Vishnu Nairddd80742018-08-21 14:12:46 -07003208 proto.write(PENDING_SEAMLESS_ROTATION, mPendingSeamlessRotate != null);
3209 proto.write(FINISHED_SEAMLESS_ROTATION_FRAME, mFinishSeamlessRotateFrameNumber);
3210 proto.write(FORCE_SEAMLESS_ROTATION, mForceSeamlesslyRotate);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003211 proto.end(token);
3212 }
3213
Vishnu Nair9a3e4062018-01-11 08:42:54 -08003214 @Override
3215 public void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003216 final long token = proto.start(fieldId);
3217 proto.write(HASH_CODE, System.identityHashCode(this));
3218 proto.write(USER_ID, UserHandle.getUserId(mOwnerUid));
3219 final CharSequence title = getWindowTag();
3220 if (title != null) {
3221 proto.write(TITLE, title.toString());
3222 }
3223 proto.end(token);
3224 }
3225
Jorim Jaggia5e10572017-11-15 14:36:26 +01003226 @Override
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003227 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003228 final TaskStack stack = getStack();
chaviwc65fa582018-08-09 15:33:13 -07003229 pw.print(prefix + "mDisplayId=" + getDisplayId());
3230 if (stack != null) {
3231 pw.print(" stackId=" + stack.mStackId);
3232 }
3233 pw.println(" mSession=" + mSession
3234 + " mClient=" + mClient.asBinder());
3235 pw.println(prefix + "mOwnerUid=" + mOwnerUid
3236 + " mShowToOwnerOnly=" + mShowToOwnerOnly
3237 + " package=" + mAttrs.packageName
3238 + " appop=" + AppOpsManager.opToName(mAppOp));
3239 pw.println(prefix + "mAttrs=" + mAttrs.toString(prefix));
3240 pw.println(prefix + "Requested w=" + mRequestedWidth
3241 + " h=" + mRequestedHeight
3242 + " mLayoutSeq=" + mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003243 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
chaviwc65fa582018-08-09 15:33:13 -07003244 pw.println(prefix + "LastRequested w=" + mLastRequestedWidth
3245 + " h=" + mLastRequestedHeight);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003246 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003247 if (mIsChildWindow || mLayoutAttached) {
chaviwc65fa582018-08-09 15:33:13 -07003248 pw.println(prefix + "mParentWindow=" + getParentWindow()
3249 + " mLayoutAttached=" + mLayoutAttached);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003250 }
3251 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
chaviwc65fa582018-08-09 15:33:13 -07003252 pw.println(prefix + "mIsImWindow=" + mIsImWindow
3253 + " mIsWallpaper=" + mIsWallpaper
3254 + " mIsFloatingLayer=" + mIsFloatingLayer
3255 + " mWallpaperVisible=" + mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003256 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003257 if (dumpAll) {
Jorim Jaggi35d328a2018-08-14 17:00:20 +02003258 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3259 pw.print(" mSubLayer="); pw.print(mSubLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003260 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003261 if (dumpAll) {
chaviwc65fa582018-08-09 15:33:13 -07003262 pw.println(prefix + "mToken=" + mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003263 if (mAppToken != null) {
chaviwc65fa582018-08-09 15:33:13 -07003264 pw.println(prefix + "mAppToken=" + mAppToken);
3265 pw.print(prefix + "mAppDied=" + mAppDied);
3266 pw.print(prefix + "drawnStateEvaluated=" + getDrawnStateEvaluated());
3267 pw.println(prefix + "mightAffectAllDrawn=" + mightAffectAllDrawn());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003268 }
chaviwc65fa582018-08-09 15:33:13 -07003269 pw.println(prefix + "mViewVisibility=0x" + Integer.toHexString(mViewVisibility)
3270 + " mHaveFrame=" + mHaveFrame
3271 + " mObscured=" + mObscured);
3272 pw.println(prefix + "mSeq=" + mSeq
3273 + " mSystemUiVisibility=0x" + Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003274 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003275 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
chaviwc65fa582018-08-09 15:33:13 -07003276 || isParentWindowHidden() || mPermanentlyHidden || mForceHideNonSystemOverlayWindow
Suprabh Shukla69c71422018-04-02 18:39:01 -07003277 || mHiddenWhileSuspended) {
chaviwc65fa582018-08-09 15:33:13 -07003278 pw.println(prefix + "mPolicyVisibility=" + mPolicyVisibility
3279 + " mPolicyVisibilityAfterAnim=" + mPolicyVisibilityAfterAnim
3280 + " mAppOpVisibility=" + mAppOpVisibility
3281 + " parentHidden=" + isParentWindowHidden()
3282 + " mPermanentlyHidden=" + mPermanentlyHidden
3283 + " mHiddenWhileSuspended=" + mHiddenWhileSuspended
3284 + " mForceHideNonSystemOverlayWindow=" + mForceHideNonSystemOverlayWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003285 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003286 if (!mRelayoutCalled || mLayoutNeeded) {
chaviwc65fa582018-08-09 15:33:13 -07003287 pw.println(prefix + "mRelayoutCalled=" + mRelayoutCalled
3288 + " mLayoutNeeded=" + mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003289 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003290 if (dumpAll) {
chaviwc65fa582018-08-09 15:33:13 -07003291 pw.println(prefix + "mGivenContentInsets=" + mGivenContentInsets.toShortString(sTmpSB)
3292 + " mGivenVisibleInsets=" + mGivenVisibleInsets.toShortString(sTmpSB));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003293 if (mTouchableInsets != 0 || mGivenInsetsPending) {
chaviwc65fa582018-08-09 15:33:13 -07003294 pw.println(prefix + "mTouchableInsets=" + mTouchableInsets
3295 + " mGivenInsetsPending=" + mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003296 Region region = new Region();
3297 getTouchableRegion(region);
chaviwc65fa582018-08-09 15:33:13 -07003298 pw.println(prefix + "touchable region=" + region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003299 }
chaviwc65fa582018-08-09 15:33:13 -07003300 pw.println(prefix + "mFullConfiguration=" + getConfiguration());
3301 pw.println(prefix + "mLastReportedConfiguration=" + getLastReportedConfiguration());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003302 }
chaviwc65fa582018-08-09 15:33:13 -07003303 pw.println(prefix + "mHasSurface=" + mHasSurface
3304 + " isReadyForDisplay()=" + isReadyForDisplay()
3305 + " mWindowRemovalAllowed=" + mWindowRemovalAllowed);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003306 if (mEnforceSizeCompat) {
chaviw9c81e632018-07-31 11:17:52 -07003307 pw.println(prefix + "mCompatFrame=" + mWindowFrames.mCompatFrame.toShortString(sTmpSB));
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003308 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003309 if (dumpAll) {
chaviw553b0212018-07-12 13:37:01 -07003310 mWindowFrames.dump(pw, prefix);
chaviw9c81e632018-07-31 11:17:52 -07003311 pw.println(prefix + " surface=" + mAttrs.surfaceInsets.toShortString(sTmpSB));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003312 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01003313 super.dump(pw, prefix, dumpAll);
chaviwc65fa582018-08-09 15:33:13 -07003314 pw.println(prefix + mWinAnimator + ":");
Dianne Hackborn529e7442012-11-01 14:22:28 -07003315 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003316 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
chaviwc65fa582018-08-09 15:33:13 -07003317 pw.println(prefix + "mAnimatingExit=" + mAnimatingExit
3318 + " mRemoveOnExit=" + mRemoveOnExit
3319 + " mDestroying=" + mDestroying
3320 + " mRemoved=" + mRemoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003321 }
chaviw40234662018-02-07 09:37:16 -08003322 if (getOrientationChanging() || mAppFreezing || mReportOrientationChanged) {
chaviwc65fa582018-08-09 15:33:13 -07003323 pw.println(prefix + "mOrientationChanging=" + mOrientationChanging
3324 + " configOrientationChanging="
3325 + (getLastReportedConfiguration().orientation != getConfiguration().orientation)
3326 + " mAppFreezing=" + mAppFreezing
3327 + " mReportOrientationChanged=" + mReportOrientationChanged);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003328 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003329 if (mLastFreezeDuration != 0) {
chaviwc65fa582018-08-09 15:33:13 -07003330 pw.print(prefix + "mLastFreezeDuration=");
3331 TimeUtils.formatDuration(mLastFreezeDuration, pw);
3332 pw.println();
Dianne Hackborna57c6952013-03-29 14:46:40 -07003333 }
chaviwc65fa582018-08-09 15:33:13 -07003334 pw.print(prefix + "mForceSeamlesslyRotate=" + mForceSeamlesslyRotate
3335 + " seamlesslyRotate: pending=");
Vishnu Nairddd80742018-08-21 14:12:46 -07003336 if (mPendingSeamlessRotate != null) {
3337 mPendingSeamlessRotate.dump(pw);
3338 } else {
3339 pw.print("null");
Adrian Roos27a90d22018-07-06 02:39:54 -07003340 }
chaviwc65fa582018-08-09 15:33:13 -07003341 pw.println(" finishedFrameNumber=" + mFinishSeamlessRotateFrameNumber);
Vishnu Nairddd80742018-08-21 14:12:46 -07003342
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003343 if (mHScale != 1 || mVScale != 1) {
chaviwc65fa582018-08-09 15:33:13 -07003344 pw.println(prefix + "mHScale=" + mHScale
3345 + " mVScale=" + mVScale);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003346 }
3347 if (mWallpaperX != -1 || mWallpaperY != -1) {
chaviwc65fa582018-08-09 15:33:13 -07003348 pw.println(prefix + "mWallpaperX=" + mWallpaperX
3349 + " mWallpaperY=" + mWallpaperY);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003350 }
3351 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
chaviwc65fa582018-08-09 15:33:13 -07003352 pw.println(prefix + "mWallpaperXStep=" + mWallpaperXStep
3353 + " mWallpaperYStep=" + mWallpaperYStep);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003354 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003355 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3356 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
chaviwc65fa582018-08-09 15:33:13 -07003357 pw.println(prefix + "mWallpaperDisplayOffsetX=" + mWallpaperDisplayOffsetX
3358 + " mWallpaperDisplayOffsetY=" + mWallpaperDisplayOffsetY);
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003359 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003360 if (mDrawLock != null) {
chaviwc65fa582018-08-09 15:33:13 -07003361 pw.println(prefix + "mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003362 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003363 if (isDragResizing()) {
chaviwc65fa582018-08-09 15:33:13 -07003364 pw.println(prefix + "isDragResizing=" + isDragResizing());
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003365 }
3366 if (computeDragResizing()) {
chaviwc65fa582018-08-09 15:33:13 -07003367 pw.println(prefix + "computeDragResizing=" + computeDragResizing());
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003368 }
chaviwc65fa582018-08-09 15:33:13 -07003369 pw.println(prefix + "isOnScreen=" + isOnScreen());
3370 pw.println(prefix + "isVisible=" + isVisible());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003371 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003372
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003373 @Override
3374 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003375 return Integer.toHexString(System.identityHashCode(this))
Jorim Jaggia5e10572017-11-15 14:36:26 +01003376 + " " + getWindowTag();
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003377 }
3378
Robert Carra1eb4392015-12-10 12:43:51 -08003379 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003380 CharSequence tag = mAttrs.getTitle();
3381 if (tag == null || tag.length() <= 0) {
3382 tag = mAttrs.packageName;
3383 }
3384 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003385 }
3386
3387 @Override
3388 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003389 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003390 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003391 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003392 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003393 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003394 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003395 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003396 }
3397 return mStringNameCache;
3398 }
Robert Carr58f29132015-10-29 14:19:05 -07003399
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003400 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003401 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003402 clipRect.left = (int) (clipRect.left / mHScale);
3403 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003404 }
3405 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003406 clipRect.top = (int) (clipRect.top / mVScale);
3407 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003408 }
3409 }
Robert Carr31e28482015-12-02 16:53:18 -08003410
chaviw9c81e632018-07-31 11:17:52 -07003411 private void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003412 final int pw = containingFrame.width();
3413 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003414 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003415 final boolean inNonFullscreenContainer = !inFullscreenContainer();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003416 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3417
3418 // We need to fit it to the display if either
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003419 // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen
3420 // for the taskless windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003421 // 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 -07003422 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on
3423 // screen, but SurfaceViews want to be always at a specific location so we don't fit it to
3424 // the display.
3425 final boolean fitToDisplay = (task == null || !inNonFullscreenContainer)
Robert Carr6f44db12016-07-21 14:54:43 -07003426 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003427 float x, y;
3428 int w,h;
3429
3430 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3431 if (mAttrs.width < 0) {
3432 w = pw;
3433 } else if (mEnforceSizeCompat) {
3434 w = (int)(mAttrs.width * mGlobalScale + .5f);
3435 } else {
3436 w = mAttrs.width;
3437 }
3438 if (mAttrs.height < 0) {
3439 h = ph;
3440 } else if (mEnforceSizeCompat) {
3441 h = (int)(mAttrs.height * mGlobalScale + .5f);
3442 } else {
3443 h = mAttrs.height;
3444 }
3445 } else {
3446 if (mAttrs.width == MATCH_PARENT) {
3447 w = pw;
3448 } else if (mEnforceSizeCompat) {
3449 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3450 } else {
3451 w = mRequestedWidth;
3452 }
3453 if (mAttrs.height == MATCH_PARENT) {
3454 h = ph;
3455 } else if (mEnforceSizeCompat) {
3456 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3457 } else {
3458 h = mRequestedHeight;
3459 }
3460 }
3461
3462 if (mEnforceSizeCompat) {
3463 x = mAttrs.x * mGlobalScale;
3464 y = mAttrs.y * mGlobalScale;
3465 } else {
3466 x = mAttrs.x;
3467 y = mAttrs.y;
3468 }
3469
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003470 if (inNonFullscreenContainer && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003471 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003472 // required by {@link Gravity#apply} call.
3473 w = Math.min(w, pw);
3474 h = Math.min(h, ph);
3475 }
3476
3477 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003478 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003479 (int) (x + mAttrs.horizontalMargin * pw),
chaviw492139a2018-07-16 16:07:35 -07003480 (int) (y + mAttrs.verticalMargin * ph), mWindowFrames.mFrame);
Robert Carr31e28482015-12-02 16:53:18 -08003481
3482 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003483 if (fitToDisplay) {
chaviw492139a2018-07-16 16:07:35 -07003484 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mWindowFrames.mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003485 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003486
3487 // We need to make sure we update the CompatFrame as it is used for
3488 // cropping decisions, etc, on systems where we lack a decor layer.
chaviw9c81e632018-07-31 11:17:52 -07003489 mWindowFrames.mCompatFrame.set(mWindowFrames.mFrame);
Robert Carr6e18c5e2016-02-29 15:57:13 -08003490 if (mEnforceSizeCompat) {
3491 // See comparable block in computeFrameLw.
chaviw9c81e632018-07-31 11:17:52 -07003492 mWindowFrames.mCompatFrame.scale(mInvGlobalScale);
Robert Carr6e18c5e2016-02-29 15:57:13 -08003493 }
Robert Carr31e28482015-12-02 16:53:18 -08003494 }
Robert Carr51a1b872015-12-08 14:03:13 -08003495
3496 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003497 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003498 }
3499
Robert Carrf3b72c72016-03-21 18:16:39 -07003500 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003501 return mIsChildWindow
3502 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003503 }
3504
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003505 /**
3506 * Returns true if any window added by an application process that if of type
3507 * {@link android.view.WindowManager.LayoutParams#TYPE_TOAST} or that requires that requires
3508 * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when
3509 * this window is visible.
3510 */
3511 boolean hideNonSystemOverlayWindowsWhenVisible() {
Philip P. Moltmann66ce2382018-10-09 13:46:11 -07003512 return (mAttrs.privateFlags & SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != 0
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003513 && mSession.mCanHideNonSystemOverlayWindows;
3514 }
3515
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003516 /** Returns the parent window if this is a child of another window, else null. */
3517 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003518 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3519 // WindowContainer that isn't a WindowState.
3520 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003521 }
3522
3523 /** Returns the topmost parent window if this is a child of another window, else this. */
3524 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003525 WindowState current = this;
3526 WindowState topParent = current;
3527 while (current != null && current.mIsChildWindow) {
3528 current = current.getParentWindow();
3529 // Parent window can be null if the child is detached from it's parent already, but
3530 // someone still has a reference to access it. So, we return the top parent value we
3531 // already have instead of null.
3532 if (current != null) {
3533 topParent = current;
3534 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003535 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003536 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003537 }
3538
Wale Ogunwale9d147902016-07-16 11:58:55 -07003539 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003540 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003541 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003542 }
3543
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003544 void setWillReplaceWindow(boolean animate) {
3545 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003546 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003547 c.setWillReplaceWindow(animate);
3548 }
3549
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003550 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3551 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3552 // We don't set replacing on starting windows since they are added by window manager and
3553 // not the client so won't be replaced by the client.
3554 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003555 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003556
3557 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003558 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003559 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003560 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003561
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003562 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003563 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003564 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003565 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003566
3567 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003568 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003569 c.clearWillReplaceWindow();
3570 }
3571 }
3572
3573 boolean waitingForReplacement() {
3574 if (mWillReplaceWindow) {
3575 return true;
3576 }
3577
3578 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003579 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003580 if (c.waitingForReplacement()) {
3581 return true;
3582 }
3583 }
3584 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003585 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003586
Chong Zhang4d7369a2016-04-25 16:09:14 -07003587 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003588 final DisplayContent dc = getDisplayContent();
3589 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3590 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3591 dc.setLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003592 mWmService.mWindowPlacerLocked.requestTraversal();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003593 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003594
3595 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003596 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003597 c.requestUpdateWallpaperIfNeeded();
3598 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003599 }
3600
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003601 float translateToWindowX(float x) {
chaviw492139a2018-07-16 16:07:35 -07003602 float winX = x - mWindowFrames.mFrame.left;
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003603 if (mEnforceSizeCompat) {
3604 winX *= mGlobalScale;
3605 }
3606 return winX;
3607 }
3608
3609 float translateToWindowY(float y) {
chaviw492139a2018-07-16 16:07:35 -07003610 float winY = y - mWindowFrames.mFrame.top;
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003611 if (mEnforceSizeCompat) {
3612 winY *= mGlobalScale;
3613 }
3614 return winY;
3615 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003616
3617 // During activity relaunch due to resize, we sometimes use window replacement
3618 // for only child windows (as the main window is handled by window preservation)
3619 // and the big surface.
3620 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003621 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3622 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3623 // we also want to replace them at such phases, as they won't be covered by window
3624 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003625 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003626 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003627 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003628 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003629
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003630 void setWillReplaceChildWindows() {
3631 if (shouldBeReplacedWithChildren()) {
3632 setWillReplaceWindow(false /* animate */);
3633 }
3634 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003635 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003636 c.setWillReplaceChildWindows();
3637 }
3638 }
3639
3640 WindowState getReplacingWindow() {
3641 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3642 return this;
3643 }
3644 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003645 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003646 final WindowState replacing = c.getReplacingWindow();
3647 if (replacing != null) {
3648 return replacing;
3649 }
3650 }
3651 return null;
3652 }
3653
Jorim Jaggife762342016-10-13 14:33:27 +02003654 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07003655 public int getRotationAnimationHint() {
3656 if (mAppToken != null) {
3657 return mAppToken.mRotationAnimationHint;
3658 } else {
3659 return -1;
3660 }
3661 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003662
Jorim Jaggife762342016-10-13 14:33:27 +02003663 @Override
3664 public boolean isInputMethodWindow() {
3665 return mIsImWindow;
3666 }
3667
Wale Ogunwale9d147902016-07-16 11:58:55 -07003668 // This must be called while inside a transaction.
3669 boolean performShowLocked() {
3670 if (isHiddenFromUserLocked()) {
3671 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3672 hideLw(false);
3673 return false;
3674 }
3675
3676 logPerformShow("performShow on ");
3677
Jorim Jaggia50da602016-12-29 11:51:42 +01003678 final int drawState = mWinAnimator.mDrawState;
3679 if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW)
3680 && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3681 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3682 }
3683
Jorim Jaggib0d27342016-11-01 16:10:42 -07003684 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003685 return false;
3686 }
3687
3688 logPerformShow("Showing ");
3689
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003690 mWmService.enableScreenIfNeededLocked();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003691 mWinAnimator.applyEnterAnimationLocked();
3692
3693 // Force the show in the next prepareSurfaceLocked() call.
3694 mWinAnimator.mLastAlpha = -1;
Robert Carre13b58e2017-08-31 14:50:44 -07003695 if (DEBUG_ANIM) Slog.v(TAG,
Wale Ogunwale9d147902016-07-16 11:58:55 -07003696 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3697 mWinAnimator.mDrawState = HAS_DRAWN;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003698 mWmService.scheduleAnimationLocked();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003699
3700 if (mHidden) {
3701 mHidden = false;
3702 final DisplayContent displayContent = getDisplayContent();
3703
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003704 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003705 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003706 if (c.mWinAnimator.mSurfaceController != null) {
3707 c.performShowLocked();
3708 // It hadn't been shown, which means layout not performed on it, so now we
3709 // want to make sure to do a layout. If called from within the transaction
3710 // loop, this will cause it to restart with a new layout.
3711 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003712 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003713 }
3714 }
3715 }
3716 }
3717
Wale Ogunwale9d147902016-07-16 11:58:55 -07003718 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003719 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003720 }
3721
3722 return true;
3723 }
3724
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003725 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003726 if (DEBUG_VISIBILITY
Jorim Jaggie4b0f282017-05-17 15:10:29 +02003727 || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003728 Slog.v(TAG, prefix + this
3729 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07003730 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003731 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3732 + " during animation: policyVis=" + mPolicyVisibility
3733 + " parentHidden=" + isParentWindowHidden()
3734 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003735 + (mAppToken != null && mAppToken.hiddenRequested)
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003736 + " tok.hidden=" + (mAppToken != null && mAppToken.isHidden())
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02003737 + " animating=" + isAnimating()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003738 + " tok animating="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003739 + (mAppToken != null && mAppToken.isSelfAnimating())
Wale Ogunwale9d147902016-07-16 11:58:55 -07003740 + " Callers=" + Debug.getCallers(4));
3741 }
3742 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003743
3744 WindowInfo getWindowInfo() {
3745 WindowInfo windowInfo = WindowInfo.obtain();
3746 windowInfo.type = mAttrs.type;
3747 windowInfo.layer = mLayer;
3748 windowInfo.token = mClient.asBinder();
Phil Weaver5dc3ebc2017-08-16 13:04:20 -07003749 if (mAppToken != null) {
3750 windowInfo.activityToken = mAppToken.appToken.asBinder();
3751 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003752 windowInfo.title = mAttrs.accessibilityTitle;
Phil Weaverbb2f28a2017-12-22 09:44:28 -08003753 // Panel windows have no public way to set the a11y title directly. Use the
3754 // regular title as a fallback.
Phil Weaver568cf662018-04-24 17:09:26 -07003755 final boolean isPanelWindow = (mAttrs.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW)
3756 && (mAttrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW);
3757 // Accessibility overlays should have titles that work for accessibility, and can't set
3758 // the a11y title themselves.
3759 final boolean isAccessibilityOverlay =
3760 windowInfo.type == WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
3761 if (TextUtils.isEmpty(windowInfo.title) && (isPanelWindow || isAccessibilityOverlay)) {
Jackal Guo25a33cbd2018-08-01 16:08:45 +08003762 final CharSequence title = mAttrs.getTitle();
3763 windowInfo.title = TextUtils.isEmpty(title) ? null : title;
Phil Weaverbb2f28a2017-12-22 09:44:28 -08003764 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003765 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3766 windowInfo.focused = isFocused();
Phil Weaverf00cd142017-03-03 13:44:00 -08003767 Task task = getTask();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003768 windowInfo.inPictureInPicture = (task != null) && task.inPinnedWindowingMode();
Jackal Guoac2b62e2018-08-22 18:28:46 +08003769 windowInfo.hasFlagWatchOutsideTouch =
3770 (mAttrs.flags & WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH) != 0;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003771
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003772 if (mIsChildWindow) {
3773 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003774 }
3775
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003776 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003777 if (childCount > 0) {
3778 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003779 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003780 }
3781 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003782 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003783 windowInfo.childTokens.add(child.mClient.asBinder());
3784 }
3785 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003786 return windowInfo;
3787 }
3788
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003789 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003790 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003791 if (mChildren.isEmpty()) {
3792 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003793 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003794 }
3795
3796 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003797 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003798 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003799 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003800 }
3801 }
3802
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003803 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003804 // We want to consume the negative sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003805 // below the parent, then this window (the parent), and then the positive sublayer children
3806 // because they need to appear above the parent.
3807 int i = 0;
3808 final int count = mChildren.size();
3809 WindowState child = mChildren.get(i);
3810
3811 while (i < count && child.mSubLayer < 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003812 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003813 return true;
3814 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003815 i++;
3816 if (i >= count) {
3817 break;
3818 }
3819 child = mChildren.get(i);
3820 }
3821
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003822 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003823 return true;
3824 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003825
3826 while (i < count) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003827 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003828 return true;
3829 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003830 i++;
3831 if (i >= count) {
3832 break;
3833 }
3834 child = mChildren.get(i);
3835 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003836
3837 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003838 }
3839
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003840 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003841 // We want to consume the positive sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003842 // above the parent, then this window (the parent), and then the negative sublayer children
3843 // because they need to appear above the parent.
3844 int i = mChildren.size() - 1;
3845 WindowState child = mChildren.get(i);
3846
3847 while (i >= 0 && child.mSubLayer >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003848 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003849 return true;
3850 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003851 --i;
3852 if (i < 0) {
3853 break;
3854 }
3855 child = mChildren.get(i);
3856 }
3857
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003858 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003859 return true;
3860 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003861
3862 while (i >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003863 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003864 return true;
3865 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003866 --i;
3867 if (i < 0) {
3868 break;
3869 }
3870 child = mChildren.get(i);
3871 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003872
3873 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003874 }
3875
Robert Carr9785cf32018-04-25 15:06:07 -07003876 private boolean applyImeWindowsIfNeeded(ToBooleanFunction<WindowState> callback,
3877 boolean traverseTopToBottom) {
3878 // If this window is the current IME target, so we need to process the IME windows
3879 // directly above it. The exception is if we are in split screen
3880 // in which case we process the IME at the DisplayContent level to
3881 // ensure it is above the docked divider.
3882 if (isInputMethodTarget() && !inSplitScreenWindowingMode()) {
3883 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
3884 return true;
3885 }
3886 }
3887 return false;
3888 }
3889
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003890 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
3891 boolean traverseTopToBottom) {
3892 if (traverseTopToBottom) {
Robert Carr9785cf32018-04-25 15:06:07 -07003893 if (applyImeWindowsIfNeeded(callback, traverseTopToBottom)
3894 || callback.apply(this)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003895 return true;
3896 }
3897 } else {
Robert Carr9785cf32018-04-25 15:06:07 -07003898 if (callback.apply(this)
3899 || applyImeWindowsIfNeeded(callback, traverseTopToBottom)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003900 return true;
3901 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003902 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003903 return false;
3904 }
3905
Wale Ogunwaled1880962016-11-08 10:31:59 -08003906 WindowState getWindow(Predicate<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003907 if (mChildren.isEmpty()) {
3908 return callback.test(this) ? this : null;
3909 }
3910
3911 // We want to consume the positive sublayer children first because they need to appear
3912 // above the parent, then this window (the parent), and then the negative sublayer children
3913 // because they need to appear above the parent.
3914 int i = mChildren.size() - 1;
3915 WindowState child = mChildren.get(i);
3916
3917 while (i >= 0 && child.mSubLayer >= 0) {
3918 if (callback.test(child)) {
3919 return child;
3920 }
3921 --i;
3922 if (i < 0) {
3923 break;
3924 }
3925 child = mChildren.get(i);
3926 }
3927
Wale Ogunwaled1880962016-11-08 10:31:59 -08003928 if (callback.test(this)) {
3929 return this;
3930 }
Wale Ogunwale34247952017-02-19 11:57:53 -08003931
3932 while (i >= 0) {
3933 if (callback.test(child)) {
3934 return child;
3935 }
3936 --i;
3937 if (i < 0) {
3938 break;
3939 }
3940 child = mChildren.get(i);
3941 }
3942
3943 return null;
Wale Ogunwaled1880962016-11-08 10:31:59 -08003944 }
3945
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01003946 /**
3947 * @return True if we our one of our ancestors has {@link #mAnimatingExit} set to true, false
3948 * otherwise.
3949 */
3950 @VisibleForTesting
3951 boolean isSelfOrAncestorWindowAnimatingExit() {
3952 WindowState window = this;
3953 do {
3954 if (window.mAnimatingExit) {
3955 return true;
3956 }
3957 window = window.getParentWindow();
3958 } while (window != null);
3959 return false;
3960 }
3961
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003962 void onExitAnimationDone() {
3963 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
3964 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
Jorim Jaggia5e10572017-11-15 14:36:26 +01003965 + " selfAnimating=" + isSelfAnimating());
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003966
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003967 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003968 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +01003969 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003970 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003971 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003972 }
3973 }
3974
3975 if (mWinAnimator.mEnteringAnimation) {
3976 mWinAnimator.mEnteringAnimation = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003977 mWmService.requestTraversal();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003978 // System windows don't have an activity and an app token as a result, but need a way
3979 // to be informed about their entrance animation end.
3980 if (mAppToken == null) {
3981 try {
3982 mClient.dispatchWindowShown();
3983 } catch (RemoteException e) {
3984 }
3985 }
3986 }
3987
Jorim Jaggia5e10572017-11-15 14:36:26 +01003988 if (isSelfAnimating()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003989 return;
3990 }
3991
Jorim Jaggia5e10572017-11-15 14:36:26 +01003992 //TODO (multidisplay): Accessibility is supported only for the default display.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003993 if (mWmService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
3994 mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Jorim Jaggia5e10572017-11-15 14:36:26 +01003995 }
3996
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01003997 if (!isSelfOrAncestorWindowAnimatingExit()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003998 return;
3999 }
4000
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07004001 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004002 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
4003
4004 mDestroying = true;
4005
4006 final boolean hasSurface = mWinAnimator.hasSurface();
Jorim Jaggi50575902018-04-10 17:49:30 +02004007
4008 // Use pendingTransaction here so hide is done the same transaction as the other
4009 // animations when exiting
4010 mWinAnimator.hide(getPendingTransaction(), "onExitAnimationDone");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004011
4012 // If we have an app token, we ask it to destroy the surface for us, so that it can take
4013 // care to ensure the activity has actually stopped and the surface is not still in use.
4014 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
4015 // transaction.
4016 if (mAppToken != null) {
4017 mAppToken.destroySurfaces();
4018 } else {
4019 if (hasSurface) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004020 mWmService.mDestroySurface.add(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004021 }
4022 if (mRemoveOnExit) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004023 mWmService.mPendingRemove.add(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004024 mRemoveOnExit = false;
4025 }
4026 }
4027 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07004028 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004029 }
Dan Willemsen117197f2016-07-30 13:02:59 -07004030
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004031 boolean clearAnimatingFlags() {
4032 boolean didSomething = false;
4033 // We don't want to clear it out for windows that get replaced, because the
4034 // animation depends on the flag to remove the replaced window.
4035 //
4036 // We also don't clear the mAnimatingExit flag for windows which have the
4037 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4038 // by the client. We should let animation proceed and not clear this flag or
4039 // they won't eventually be removed by WindowStateAnimator#finishExit.
4040 if (!mWillReplaceWindow && !mRemoveOnExit) {
4041 // Clear mAnimating flag together with mAnimatingExit. When animation
4042 // changes from exiting to entering, we need to clear this flag until the
4043 // new animation gets applied, so that isAnimationStarting() becomes true
4044 // until then.
4045 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4046 // placement for this window during this period, one or more frame will
4047 // show up with wrong position or scale.
4048 if (mAnimatingExit) {
4049 mAnimatingExit = false;
4050 didSomething = true;
4051 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004052 if (mDestroying) {
4053 mDestroying = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004054 mWmService.mDestroySurface.remove(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004055 didSomething = true;
4056 }
4057 }
4058
4059 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004060 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004061 }
4062
4063 return didSomething;
4064 }
4065
Winson4b4ba902016-07-27 19:45:52 -07004066 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004067 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004068 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004069
4070 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004071 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004072 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004073 c.hideWallpaperWindow(wasDeferred, reason);
4074 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004075 if (!mWinAnimator.mLastHidden || wasDeferred) {
4076 mWinAnimator.hide(reason);
Tiger Huang50d45462018-05-25 22:57:52 +08004077 getDisplayContent().mWallpaperController.mDeferredHideWallpaper = null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004078 dispatchWallpaperVisibility(false);
4079 final DisplayContent displayContent = getDisplayContent();
4080 if (displayContent != null) {
4081 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
Tiger Huang50d45462018-05-25 22:57:52 +08004082 if (DEBUG_LAYOUT_REPEATS) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004083 mWmService.mWindowPlacerLocked.debugLayoutRepeats("hideWallpaperWindow " + this,
Tiger Huang50d45462018-05-25 22:57:52 +08004084 displayContent.pendingLayoutChanges);
4085 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004086 }
4087 }
4088 }
4089
4090 /**
4091 * Check wallpaper window for visibility change and notify window if so.
4092 * @param visible Current visibility.
4093 */
4094 void dispatchWallpaperVisibility(final boolean visible) {
4095 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07004096 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004097
4098 // Only send notification if the visibility actually changed and we are not trying to hide
4099 // the wallpaper when we are deferring hiding of the wallpaper.
4100 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4101 mWallpaperVisible = visible;
4102 try {
4103 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4104 "Updating vis of wallpaper " + this
4105 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4106 mClient.dispatchAppVisibility(visible);
4107 } catch (RemoteException e) {
4108 }
4109 }
4110 }
4111
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004112 boolean hasVisibleNotDrawnWallpaper() {
4113 if (mWallpaperVisible && !isDrawnLw()) {
4114 return true;
4115 }
4116 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004117 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004118 if (c.hasVisibleNotDrawnWallpaper()) {
4119 return true;
4120 }
4121 }
4122 return false;
4123 }
4124
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004125 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4126 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004127 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004128 c.updateReportedVisibility(results);
4129 }
4130
4131 if (mAppFreezing || mViewVisibility != View.VISIBLE
4132 || mAttrs.type == TYPE_APPLICATION_STARTING
4133 || mDestroying) {
4134 return;
4135 }
4136 if (DEBUG_VISIBILITY) {
4137 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02004138 + ", animating=" + isAnimating());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004139 if (!isDrawnLw()) {
4140 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4141 + " pv=" + mPolicyVisibility
4142 + " mDrawState=" + mWinAnimator.mDrawState
4143 + " ph=" + isParentWindowHidden()
4144 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02004145 + " a=" + isAnimating());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004146 }
4147 }
4148
4149 results.numInteresting++;
4150 if (isDrawnLw()) {
4151 results.numDrawn++;
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02004152 if (!isAnimating()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004153 results.numVisible++;
4154 }
4155 results.nowGone = false;
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02004156 } else if (isAnimating()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004157 results.nowGone = false;
4158 }
4159 }
4160
Robert Carr683e05d2018-04-18 15:11:04 -07004161 private boolean skipDecorCrop() {
4162 // The decor frame is used to specify the region not covered by the system
4163 // decorations (nav bar, status bar). In case this is empty, for example with
4164 // FLAG_TRANSLUCENT_NAVIGATION, we don't need to do any cropping.
chaviw553b0212018-07-12 13:37:01 -07004165 if (mWindowFrames.mDecorFrame.isEmpty()) {
Robert Carr683e05d2018-04-18 15:11:04 -07004166 return true;
4167 }
4168
4169 // But if we have a frame, and are an application window, then we must be cropped.
4170 if (mAppToken != null) {
4171 return false;
4172 }
4173
4174 // For non application windows, we may be allowed to extend over the decor bars
4175 // depending on our type and permissions assosciated with our token.
4176 return mToken.canLayerAboveSystemBars();
4177 }
4178
Robert Carrfbbde852016-10-18 11:02:28 -07004179 /**
4180 * Calculate the window crop according to system decor policy. In general this is
4181 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4182 * special cases. This rectangle is in screen space.
4183 */
4184 void calculatePolicyCrop(Rect policyCrop) {
4185 final DisplayContent displayContent = getDisplayContent();
4186 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
4187
4188 if (!isDefaultDisplay()) {
4189 // On a different display there is no system decor. Crop the window
4190 // by the screen boundaries.
4191 // TODO(multi-display)
chaviw9c81e632018-07-31 11:17:52 -07004192 policyCrop.set(0, 0, mWindowFrames.mCompatFrame.width(),
4193 mWindowFrames.mCompatFrame.height());
4194 policyCrop.intersect(-mWindowFrames.mCompatFrame.left, -mWindowFrames.mCompatFrame.top,
4195 displayInfo.logicalWidth - mWindowFrames.mCompatFrame.left,
4196 displayInfo.logicalHeight - mWindowFrames.mCompatFrame.top);
Robert Carr683e05d2018-04-18 15:11:04 -07004197 } else if (skipDecorCrop()) {
Robert Carrfbbde852016-10-18 11:02:28 -07004198 // Windows without policy decor aren't cropped.
chaviw9c81e632018-07-31 11:17:52 -07004199 policyCrop.set(0, 0, mWindowFrames.mCompatFrame.width(),
4200 mWindowFrames.mCompatFrame.height());
Robert Carrfbbde852016-10-18 11:02:28 -07004201 } else {
4202 // Crop to the system decor specified by policy.
4203 calculateSystemDecorRect(policyCrop);
4204 }
4205 }
4206
4207 /**
4208 * The system decor rect is the region of the window which is not covered
4209 * by system decorations.
4210 */
4211 private void calculateSystemDecorRect(Rect systemDecorRect) {
chaviw553b0212018-07-12 13:37:01 -07004212 final Rect decorRect = mWindowFrames.mDecorFrame;
chaviw492139a2018-07-16 16:07:35 -07004213 final int width = mWindowFrames.mFrame.width();
4214 final int height = mWindowFrames.mFrame.height();
Robert Carrfbbde852016-10-18 11:02:28 -07004215
chaviw492139a2018-07-16 16:07:35 -07004216 final int left = mWindowFrames.mFrame.left;
4217 final int top = mWindowFrames.mFrame.top;
Robert Carrfbbde852016-10-18 11:02:28 -07004218
4219 // Initialize the decor rect to the entire frame.
4220 if (isDockedResizing()) {
4221 // If we are resizing with the divider, the task bounds might be smaller than the
4222 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4223 // want in this case in order to avoid holes.
4224 //
4225 // We take care to not shrink the width, for surfaces which are larger than
4226 // the display region. Of course this area will not eventually be visible
4227 // but if we truncate the width now, we will calculate incorrectly
4228 // when adjusting to the stack bounds.
4229 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4230 systemDecorRect.set(0, 0,
4231 Math.max(width, displayInfo.logicalWidth),
4232 Math.max(height, displayInfo.logicalHeight));
4233 } else {
4234 systemDecorRect.set(0, 0, width, height);
4235 }
4236
4237 // If a freeform window is animating from a position where it would be cutoff, it would be
4238 // cutoff during the animation. We don't want that, so for the duration of the animation
4239 // we ignore the decor cropping and depend on layering to position windows correctly.
chaviw95136622018-04-09 15:20:06 -07004240
4241 // We also ignore cropping when the window is currently being drag resized in split screen
4242 // to prevent issues with the crop for screenshot.
4243 final boolean cropToDecor =
4244 !(inFreeformWindowingMode() && isAnimatingLw()) && !isDockedResizing();
Robert Carrfbbde852016-10-18 11:02:28 -07004245 if (cropToDecor) {
4246 // Intersect with the decor rect, offsetted by window position.
4247 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
4248 decorRect.right - left, decorRect.bottom - top);
4249 }
4250
4251 // If size compatibility is being applied to the window, the
4252 // surface is scaled relative to the screen. Also apply this
4253 // scaling to the crop rect. We aren't using the standard rect
4254 // scale function because we want to round things to make the crop
4255 // always round to a larger rect to ensure we don't crop too
4256 // much and hide part of the window that should be seen.
4257 if (mEnforceSizeCompat && mInvGlobalScale != 1.0f) {
4258 final float scale = mInvGlobalScale;
4259 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
4260 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
4261 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
4262 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
4263 }
4264
4265 }
4266
4267 /**
4268 * Expand the given rectangle by this windows surface insets. This
4269 * takes you from the 'window size' to the 'surface size'.
4270 * The surface insets are positive in each direction, so we inset by
4271 * the inverse.
4272 */
4273 void expandForSurfaceInsets(Rect r) {
4274 r.inset(-mAttrs.surfaceInsets.left,
4275 -mAttrs.surfaceInsets.top,
4276 -mAttrs.surfaceInsets.right,
4277 -mAttrs.surfaceInsets.bottom);
4278 }
4279
Robert Carrc91d1c32017-02-15 19:37:46 -08004280 boolean surfaceInsetsChanging() {
4281 return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets);
4282 }
4283
Bryce Leef858b572017-06-29 14:03:33 -07004284 int relayoutVisibleWindow(int result, int attrChanges, int oldVisibility) {
Robert Carrecc06b32017-04-18 14:25:10 -07004285 final boolean wasVisible = isVisibleLw();
4286
4287 result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0;
Robert Carr7b3d11d2018-03-15 14:34:45 -07004288
Robert Carrc91d1c32017-02-15 19:37:46 -08004289 if (mAnimatingExit) {
4290 Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit="
4291 + mRemoveOnExit + ", mDestroying=" + mDestroying);
4292
4293 mWinAnimator.cancelExitAnimationForNextAnimationLocked();
4294 mAnimatingExit = false;
4295 }
4296 if (mDestroying) {
4297 mDestroying = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004298 mWmService.mDestroySurface.remove(this);
Robert Carrc91d1c32017-02-15 19:37:46 -08004299 }
4300 if (oldVisibility == View.GONE) {
4301 mWinAnimator.mEnterAnimationPending = true;
4302 }
4303
Andrii Kulian8ee72852017-03-10 10:36:45 -08004304 mLastVisibleLayoutRotation = getDisplayContent().getRotation();
Robert Carrc91d1c32017-02-15 19:37:46 -08004305
4306 mWinAnimator.mEnteringAnimation = true;
Bryce Leeae73ba42017-05-05 09:58:25 -07004307
Bryce Leef858b572017-06-29 14:03:33 -07004308 prepareWindowToDisplayDuringRelayout(wasVisible);
Bryce Leeae73ba42017-05-05 09:58:25 -07004309
Robert Carrc91d1c32017-02-15 19:37:46 -08004310 if ((attrChanges & FORMAT_CHANGED) != 0) {
4311 // If the format can't be changed in place, preserve the old surface until the app draws
4312 // on the new one. This prevents blinking when we change elevation of freeform and
4313 // pinned windows.
4314 if (!mWinAnimator.tryChangeFormatInPlaceLocked()) {
4315 mWinAnimator.preserveSurfaceLocked();
4316 result |= RELAYOUT_RES_SURFACE_CHANGED
4317 | RELAYOUT_RES_FIRST_TIME;
4318 }
4319 }
4320
4321 // When we change the Surface size, in scenarios which may require changing
4322 // the surface position in sync with the resize, we use a preserved surface
4323 // so we can freeze it while waiting for the client to report draw on the newly
Robert Carrc6d5af52018-02-26 17:46:00 -08004324 // sized surface. At the moment this logic is only in place for switching
4325 // in and out of the big surface for split screen resize.
4326 if (isDragResizeChanged()) {
Robert Carrc91d1c32017-02-15 19:37:46 -08004327 setDragResizing();
Robert Carrc91d1c32017-02-15 19:37:46 -08004328 // We can only change top level windows to the full-screen surface when
4329 // resizing (as we only have one full-screen surface). So there is no need
4330 // to preserve and destroy windows which are attached to another, they
4331 // will keep their surface and its size may change over time.
4332 if (mHasSurface && !isChildWindow()) {
4333 mWinAnimator.preserveSurfaceLocked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08004334 result |= RELAYOUT_RES_SURFACE_CHANGED |
4335 RELAYOUT_RES_FIRST_TIME;
Robert Carrc91d1c32017-02-15 19:37:46 -08004336 }
4337 }
4338 final boolean freeformResizing = isDragResizing()
4339 && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
4340 final boolean dockedResizing = isDragResizing()
4341 && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
4342 result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0;
4343 result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004344 return result;
4345 }
4346
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004347 /**
4348 * @return True if this window has been laid out at least once; false otherwise.
4349 */
4350 boolean isLaidOut() {
4351 return mLayoutSeq != -1;
4352 }
4353
4354 /**
4355 * Updates the last inset values to the current ones.
4356 */
4357 void updateLastInsetValues() {
chaviw9c81e632018-07-31 11:17:52 -07004358 mWindowFrames.updateLastInsetValues();
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004359 }
4360
Jorim Jaggia5e10572017-11-15 14:36:26 +01004361 void startAnimation(Animation anim) {
4362 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
chaviw492139a2018-07-16 16:07:35 -07004363 anim.initialize(mWindowFrames.mFrame.width(), mWindowFrames.mFrame.height(),
Jorim Jaggia5e10572017-11-15 14:36:26 +01004364 displayInfo.appWidth, displayInfo.appHeight);
4365 anim.restrictDuration(MAX_ANIMATION_DURATION);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004366 anim.scaleCurrentDuration(mWmService.getWindowAnimationScaleLocked());
Jorim Jaggia5e10572017-11-15 14:36:26 +01004367 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi2e3c31d2017-11-20 19:49:00 +01004368 new WindowAnimationSpec(anim, mSurfacePosition, false /* canSkipFirstFrame */),
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004369 mWmService.mSurfaceAnimationRunner);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004370 startAnimation(mPendingTransaction, adapter);
4371 commitPendingTransaction();
4372 }
4373
chaviw161ea3e2018-01-31 12:01:12 -08004374 private void startMoveAnimation(int left, int top) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01004375 if (DEBUG_ANIM) Slog.v(TAG, "Setting move animation on " + this);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004376 final Point oldPosition = new Point();
4377 final Point newPosition = new Point();
chaviw492139a2018-07-16 16:07:35 -07004378 transformFrameToSurfacePosition(mWindowFrames.mLastFrame.left, mWindowFrames.mLastFrame.top,
4379 oldPosition);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004380 transformFrameToSurfacePosition(left, top, newPosition);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004381 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004382 new MoveAnimationSpec(oldPosition.x, oldPosition.y, newPosition.x, newPosition.y),
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004383 mWmService.mSurfaceAnimationRunner);
chaviw161ea3e2018-01-31 12:01:12 -08004384 startAnimation(getPendingTransaction(), adapter);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004385 }
4386
4387 private void startAnimation(Transaction t, AnimationAdapter adapter) {
4388 startAnimation(t, adapter, mWinAnimator.mLastHidden);
4389 }
4390
4391 @Override
4392 protected void onAnimationFinished() {
4393 mWinAnimator.onAnimationFinished();
4394 }
4395
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004396 /**
4397 * Retrieves the current transformation matrix of the window, relative to the display.
4398 *
4399 * @param float9 A temporary array of 9 floats.
4400 * @param outMatrix Matrix to fill in the transformation.
4401 */
4402 void getTransformationMatrix(float[] float9, Matrix outMatrix) {
4403 float9[Matrix.MSCALE_X] = mWinAnimator.mDsDx;
4404 float9[Matrix.MSKEW_Y] = mWinAnimator.mDtDx;
4405 float9[Matrix.MSKEW_X] = mWinAnimator.mDtDy;
4406 float9[Matrix.MSCALE_Y] = mWinAnimator.mDsDy;
Robert Carr217e7cc2018-01-31 18:08:39 -08004407 int x = mSurfacePosition.x;
4408 int y = mSurfacePosition.y;
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004409
4410 // If changed, also adjust transformFrameToSurfacePosition
4411 final WindowContainer parent = getParent();
4412 if (isChildWindow()) {
4413 final WindowState parentWindow = getParentWindow();
chaviw492139a2018-07-16 16:07:35 -07004414 x += parentWindow.mWindowFrames.mFrame.left - parentWindow.mAttrs.surfaceInsets.left;
4415 y += parentWindow.mWindowFrames.mFrame.top - parentWindow.mAttrs.surfaceInsets.top;
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004416 } else if (parent != null) {
4417 final Rect parentBounds = parent.getBounds();
4418 x += parentBounds.left;
4419 y += parentBounds.top;
4420 }
4421 float9[Matrix.MTRANS_X] = x;
4422 float9[Matrix.MTRANS_Y] = y;
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004423 float9[Matrix.MPERSP_0] = 0;
4424 float9[Matrix.MPERSP_1] = 0;
4425 float9[Matrix.MPERSP_2] = 1;
4426 outMatrix.setValues(float9);
4427 }
4428
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004429 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4430 // access to its windows children. Need to investigate re-writing
4431 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4432 static final class UpdateReportedVisibilityResults {
4433 int numInteresting;
4434 int numVisible;
4435 int numDrawn;
4436 boolean nowGone = true;
4437
4438 void reset() {
4439 numInteresting = 0;
4440 numVisible = 0;
4441 numDrawn = 0;
4442 nowGone = true;
4443 }
4444 }
Robert Carraf422a82017-04-10 18:34:33 -07004445
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004446 private static final class WindowId extends IWindowId.Stub {
4447 private final WeakReference<WindowState> mOuter;
4448
4449 private WindowId(WindowState outer) {
4450
4451 // Use a weak reference for the outer class. This is important to prevent the following
4452 // leak: Since we send this class to the client process, binder will keep it alive as
4453 // long as the client keeps it alive. Now, if the window is removed, we need to clear
4454 // out our reference so even though this class is kept alive we don't leak WindowState,
4455 // which can keep a whole lot of classes alive.
4456 mOuter = new WeakReference<>(outer);
4457 }
4458
4459 @Override
4460 public void registerFocusObserver(IWindowFocusObserver observer) {
4461 final WindowState outer = mOuter.get();
4462 if (outer != null) {
4463 outer.registerFocusObserver(observer);
4464 }
4465 }
4466 @Override
4467 public void unregisterFocusObserver(IWindowFocusObserver observer) {
4468 final WindowState outer = mOuter.get();
4469 if (outer != null) {
4470 outer.unregisterFocusObserver(observer);
4471 }
4472 }
4473 @Override
4474 public boolean isFocused() {
4475 final WindowState outer = mOuter.get();
Tiger Huang1e5b10a2018-07-30 20:19:51 +08004476 if (outer != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004477 synchronized (outer.mWmService.mGlobalLock) {
Tiger Huang1e5b10a2018-07-30 20:19:51 +08004478 return outer.isFocused();
4479 }
4480 }
4481 return false;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004482 }
4483 }
4484
Robert Carrb1579c82017-09-05 14:54:47 -07004485
4486 @Override
4487 boolean shouldMagnify() {
4488 if (mAttrs.type == TYPE_INPUT_METHOD ||
Robert Carree4d4b92017-11-22 12:21:46 -08004489 mAttrs.type == TYPE_INPUT_METHOD_DIALOG ||
4490 mAttrs.type == TYPE_MAGNIFICATION_OVERLAY ||
4491 mAttrs.type == TYPE_NAVIGATION_BAR ||
4492 // It's tempting to wonder: Have we forgotten the rounded corners overlay?
4493 // worry not: it's a fake TYPE_NAVIGATION_BAR_PANEL
Eugene Susla9552b262018-03-13 12:24:50 -07004494 mAttrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Robert Carrb1579c82017-09-05 14:54:47 -07004495 return false;
4496 }
4497 return true;
4498 }
4499
4500 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004501 SurfaceSession getSession() {
4502 if (mSession.mSurfaceSession != null) {
4503 return mSession.mSurfaceSession;
4504 } else {
4505 return getParent().getSession();
4506 }
4507 }
4508
4509 @Override
4510 boolean needsZBoost() {
lumarkff0ab692018-11-05 20:32:30 +08004511 final WindowState inputMethodTarget = getDisplayContent().mInputMethodTarget;
4512 if (mIsImWindow && inputMethodTarget != null) {
4513 final AppWindowToken appToken = inputMethodTarget.mAppToken;
Jorim Jaggib0fc8172017-11-23 17:04:08 +00004514 if (appToken != null) {
4515 return appToken.needsZBoost();
4516 }
4517 }
4518 return mWillReplaceWindow;
Robert Carrb1579c82017-09-05 14:54:47 -07004519 }
4520
Robert Carrf07ef9e2017-11-21 12:12:49 -08004521 private void applyDims(Dimmer dimmer) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07004522 if (!mAnimatingExit && mAppDied) {
4523 mIsDimming = true;
chaviw2fb06bc2018-01-19 17:09:15 -08004524 dimmer.dimAbove(getPendingTransaction(), this, DEFAULT_DIM_AMOUNT_DEAD_WINDOW);
chaviwebcbc342018-02-07 13:19:00 -08004525 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0 && isVisibleNow() && !mHidden) {
chaviw14076152018-02-02 14:51:20 -08004526 // Only show a dim behind when the following is satisfied:
4527 // 1. The window has the flag FLAG_DIM_BEHIND
4528 // 2. The WindowToken is not hidden so dims aren't shown when the window is exiting.
4529 // 3. The WS is considered visible according to the isVisible() method
chaviwebcbc342018-02-07 13:19:00 -08004530 // 4. The WS is not hidden.
Robert Carrf59b8dd2017-10-02 18:58:36 -07004531 mIsDimming = true;
chaviw2fb06bc2018-01-19 17:09:15 -08004532 dimmer.dimBelow(getPendingTransaction(), this, mAttrs.dimAmount);
Robert Carrf59b8dd2017-10-02 18:58:36 -07004533 }
Robert Carrf07ef9e2017-11-21 12:12:49 -08004534 }
4535
4536 @Override
4537 void prepareSurfaces() {
4538 final Dimmer dimmer = getDimmer();
4539 mIsDimming = false;
4540 if (dimmer != null) {
4541 applyDims(dimmer);
4542 }
chaviw2f0567b2018-01-29 16:22:02 -08004543 updateSurfacePosition();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004544
Robert Carrb1579c82017-09-05 14:54:47 -07004545 mWinAnimator.prepareSurfaceLocked(true);
4546 super.prepareSurfaces();
4547 }
4548
4549 @Override
Jorim Jaggia5e10572017-11-15 14:36:26 +01004550 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
4551 super.onAnimationLeashCreated(t, leash);
4552
4553 // Leash is now responsible for position, so set our position to 0.
4554 t.setPosition(mSurfaceControl, 0, 0);
chaviw3e751af2018-01-11 11:22:39 -08004555 mLastSurfacePosition.set(0, 0);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004556 }
4557
4558 @Override
4559 public void onAnimationLeashDestroyed(Transaction t) {
4560 super.onAnimationLeashDestroyed(t);
4561 updateSurfacePosition(t);
4562 }
4563
chaviwe07246a2017-12-12 16:18:29 -08004564 @Override
chaviw2f0567b2018-01-29 16:22:02 -08004565 void updateSurfacePosition() {
4566 updateSurfacePosition(getPendingTransaction());
4567 }
4568
Vishnu Naird8c664b2018-09-24 12:52:35 -07004569 @VisibleForTesting
4570 void updateSurfacePosition(Transaction t) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01004571 if (mSurfaceControl == null) {
4572 return;
4573 }
4574
chaviw492139a2018-07-16 16:07:35 -07004575 transformFrameToSurfacePosition(mWindowFrames.mFrame.left, mWindowFrames.mFrame.top,
4576 mSurfacePosition);
Robert Carrc6d5af52018-02-26 17:46:00 -08004577
Vishnu Nair83537a72018-07-19 21:27:48 -07004578 // Freeze position while we're unrotated, so the surface remains at the position it was
4579 // prior to the rotation.
Vishnu Nairddd80742018-08-21 14:12:46 -07004580 if (!mSurfaceAnimator.hasLeash() && mPendingSeamlessRotate == null
4581 && !mLastSurfacePosition.equals(mSurfacePosition)) {
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004582 t.setPosition(mSurfaceControl, mSurfacePosition.x, mSurfacePosition.y);
chaviw3e751af2018-01-11 11:22:39 -08004583 mLastSurfacePosition.set(mSurfacePosition.x, mSurfacePosition.y);
Robert Carrc6d5af52018-02-26 17:46:00 -08004584 if (surfaceInsetsChanging() && mWinAnimator.hasSurface()) {
4585 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
4586 t.deferTransactionUntil(mSurfaceControl,
4587 mWinAnimator.mSurfaceController.mSurfaceControl.getHandle(),
chaviwbe43ac82018-04-04 15:14:49 -07004588 getFrameNumber());
Robert Carrc6d5af52018-02-26 17:46:00 -08004589 }
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004590 }
4591 }
4592
4593 private void transformFrameToSurfacePosition(int left, int top, Point outPoint) {
4594 outPoint.set(left, top);
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004595
4596 // If changed, also adjust getTransformationMatrix
chaviwe07246a2017-12-12 16:18:29 -08004597 final WindowContainer parentWindowContainer = getParent();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004598 if (isChildWindow()) {
4599 // TODO: This probably falls apart at some point and we should
4600 // actually compute relative coordinates.
Jorim Jaggi50d3f8f2017-12-27 17:41:25 +01004601
4602 // Since the parent was outset by its surface insets, we need to undo the outsetting
4603 // with insetting by the same amount.
Jorim Jaggia5e10572017-11-15 14:36:26 +01004604 final WindowState parent = getParentWindow();
chaviw492139a2018-07-16 16:07:35 -07004605 outPoint.offset(-parent.mWindowFrames.mFrame.left + parent.mAttrs.surfaceInsets.left,
4606 -parent.mWindowFrames.mFrame.top + parent.mAttrs.surfaceInsets.top);
chaviwe07246a2017-12-12 16:18:29 -08004607 } else if (parentWindowContainer != null) {
Evan Roskyed6767f2018-10-26 17:21:06 -07004608 final Rect parentBounds = parentWindowContainer.getDisplayedBounds();
chaviwe07246a2017-12-12 16:18:29 -08004609 outPoint.offset(-parentBounds.left, -parentBounds.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004610 }
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004611
Robert Carr32bcb102018-01-29 15:03:23 -08004612 TaskStack stack = getStack();
4613
4614 // If we have stack outsets, that means the top-left
4615 // will be outset, and we need to inset ourselves
4616 // to account for it. If we actually have shadows we will
4617 // then un-inset ourselves by the surfaceInsets.
4618 if (stack != null) {
4619 final int outset = stack.getStackOutset();
4620 outPoint.offset(outset, outset);
4621 }
4622
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004623 // Expand for surface insets. See WindowState.expandForSurfaceInsets.
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004624 outPoint.offset(-mAttrs.surfaceInsets.left, -mAttrs.surfaceInsets.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004625 }
4626
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004627 boolean needsRelativeLayeringToIme() {
4628 // We only use the relative layering mode in split screen, as part of elevating the IME
4629 // and windows above it's target above the docked divider.
4630 if (!inSplitScreenWindowingMode()) {
4631 return false;
4632 }
4633
4634 if (isChildWindow()) {
4635 // If we are a child of the input method target we need this promotion.
4636 if (getParentWindow().isInputMethodTarget()) {
4637 return true;
4638 }
4639 } else if (mAppToken != null) {
4640 // Likewise if we share a token with the Input method target and are ordered
4641 // above it but not necessarily a child (e.g. a Dialog) then we also need
4642 // this promotion.
lumarkff0ab692018-11-05 20:32:30 +08004643 final WindowState imeTarget = getDisplayContent().mInputMethodTarget;
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004644 boolean inTokenWithAndAboveImeTarget = imeTarget != null && imeTarget != this
4645 && imeTarget.mToken == mToken && imeTarget.compareTo(this) <= 0;
4646 return inTokenWithAndAboveImeTarget;
4647 }
4648 return false;
4649 }
4650
Jorim Jaggia5e10572017-11-15 14:36:26 +01004651 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004652 void assignLayer(Transaction t, int layer) {
4653 // See comment in assignRelativeLayerForImeTargetChild
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004654 if (needsRelativeLayeringToIme()) {
4655 getDisplayContent().assignRelativeLayerForImeTargetChild(t, this);
Robert Carrb1579c82017-09-05 14:54:47 -07004656 return;
4657 }
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004658 super.assignLayer(t, layer);
Robert Carrb1579c82017-09-05 14:54:47 -07004659 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07004660
4661 @Override
4662 public boolean isDimming() {
4663 return mIsDimming;
4664 }
Robert Carr0eff1872017-12-01 14:27:04 -08004665
4666 // TODO(b/70040778): We should aim to eliminate the last user of TYPE_APPLICATION_MEDIA
4667 // then we can drop all negative layering on the windowing side and simply inherit
4668 // the default implementation here.
4669 public void assignChildLayers(Transaction t) {
4670 int layer = 1;
4671 for (int i = 0; i < mChildren.size(); i++) {
4672 final WindowState w = mChildren.get(i);
4673
4674 // APPLICATION_MEDIA_OVERLAY needs to go above APPLICATION_MEDIA
4675 // while they both need to go below the main window. However the
4676 // relative layering of multiple APPLICATION_MEDIA/OVERLAY has never
4677 // been defined and so we can use static layers and leave it that way.
4678 if (w.mAttrs.type == TYPE_APPLICATION_MEDIA) {
4679 w.assignLayer(t, -2);
4680 } else if (w.mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) {
4681 w.assignLayer(t, -1);
4682 } else {
4683 w.assignLayer(t, layer);
4684 }
4685 w.assignChildLayers(t);
4686 layer++;
4687 }
4688 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01004689
Andrii Kulian4b6599e2018-01-15 17:24:08 -08004690 /**
4691 * Update a tap exclude region with a rectangular area identified by provided id. The requested
4692 * area will be clipped to the window bounds.
4693 */
4694 void updateTapExcludeRegion(int regionId, int left, int top, int width, int height) {
4695 final DisplayContent currentDisplay = getDisplayContent();
4696 if (currentDisplay == null) {
4697 throw new IllegalStateException("Trying to update window not attached to any display.");
4698 }
4699
4700 if (mTapExcludeRegionHolder == null) {
4701 mTapExcludeRegionHolder = new TapExcludeRegionHolder();
4702
4703 // Make sure that this window is registered as one that provides a tap exclude region
4704 // for its containing display.
4705 currentDisplay.mTapExcludeProvidingWindows.add(this);
4706 }
4707
4708 mTapExcludeRegionHolder.updateRegion(regionId, left, top, width, height);
4709 // Trigger touch exclude region update on current display.
Tiger Huang1e5b10a2018-07-30 20:19:51 +08004710 currentDisplay.updateTouchExcludeRegion();
Andrii Kulian4b6599e2018-01-15 17:24:08 -08004711 }
4712
4713 /** Union the region with current tap exclude region that this window provides. */
4714 void amendTapExcludeRegion(Region region) {
4715 mTapExcludeRegionHolder.amendRegion(region, getBounds());
4716 }
4717
Robert Carr825581a2018-03-30 14:00:53 -07004718 @Override
4719 public boolean isInputMethodTarget() {
lumarkff0ab692018-11-05 20:32:30 +08004720 return getDisplayContent().mInputMethodTarget == this;
Robert Carr825581a2018-03-30 14:00:53 -07004721 }
4722
chaviwbe43ac82018-04-04 15:14:49 -07004723 long getFrameNumber() {
4724 return mFrameNumber;
4725 }
4726
4727 void setFrameNumber(long frameNumber) {
4728 mFrameNumber = frameNumber;
4729 }
4730
chaviw553b0212018-07-12 13:37:01 -07004731 public void getMaxVisibleBounds(Rect out) {
4732 if (out.isEmpty()) {
4733 out.set(mWindowFrames.mVisibleFrame);
4734 return;
4735 }
4736
4737 if (mWindowFrames.mVisibleFrame.left < out.left) {
4738 out.left = mWindowFrames.mVisibleFrame.left;
4739 }
4740 if (mWindowFrames.mVisibleFrame.top < out.top) {
4741 out.top = mWindowFrames.mVisibleFrame.top;
4742 }
4743 if (mWindowFrames.mVisibleFrame.right > out.right) {
4744 out.right = mWindowFrames.mVisibleFrame.right;
4745 }
4746 if (mWindowFrames.mVisibleFrame.bottom > out.bottom) {
4747 out.bottom = mWindowFrames.mVisibleFrame.bottom;
4748 }
4749 }
4750
chaviw9c81e632018-07-31 11:17:52 -07004751 /**
4752 * Copy the inset values over so they can be sent back to the client when a relayout occurs.
4753 */
4754 void getInsetsForRelayout(Rect outOverscanInsets, Rect outContentInsets, Rect outVisibleInsets,
4755 Rect outStableInsets, Rect outOutsets) {
4756 outOverscanInsets.set(mWindowFrames.mOverscanInsets);
4757 outContentInsets.set(mWindowFrames.mContentInsets);
4758 outVisibleInsets.set(mWindowFrames.mVisibleInsets);
4759 outStableInsets.set(mWindowFrames.mStableInsets);
4760 outOutsets.set(mWindowFrames.mOutsets);
4761
4762 mLastRelayoutContentInsets.set(mWindowFrames.mContentInsets);
4763 }
4764
4765 void getContentInsets(Rect outContentInsets) {
4766 outContentInsets.set(mWindowFrames.mContentInsets);
4767 }
4768
4769 Rect getContentInsets() {
4770 return mWindowFrames.mContentInsets;
4771 }
4772
4773 void getStableInsets(Rect outStableInsets) {
4774 outStableInsets.set(mWindowFrames.mStableInsets);
4775 }
4776
4777 Rect getStableInsets() {
4778 return mWindowFrames.mStableInsets;
4779 }
4780
4781 void resetLastContentInsets() {
4782 mWindowFrames.resetLastContentInsets();
4783 }
4784
4785 Rect getVisibleInsets() {
4786 return mWindowFrames.mVisibleInsets;
4787 }
4788
chaviw1454b392018-08-06 09:54:04 -07004789 @Override
4790 public WindowFrames getWindowFrames() {
4791 return mWindowFrames;
4792 }
4793
4794 void resetContentChanged() {
4795 mWindowFrames.setContentChanged(false);
4796 }
4797
Jorim Jaggif96c90a2018-09-26 16:55:15 +02004798 void setInsetProvider(InsetsSourceProvider insetProvider) {
4799 mInsetProvider = insetProvider;
4800 }
4801
4802 InsetsSourceProvider getInsetProvider() {
4803 return mInsetProvider;
4804 }
4805
Jorim Jaggia5e10572017-11-15 14:36:26 +01004806 private final class MoveAnimationSpec implements AnimationSpec {
4807
4808 private final long mDuration;
4809 private Interpolator mInterpolator;
4810 private Point mFrom = new Point();
4811 private Point mTo = new Point();
4812
4813 private MoveAnimationSpec(int fromX, int fromY, int toX, int toY) {
4814 final Animation anim = AnimationUtils.loadAnimation(mContext,
4815 com.android.internal.R.anim.window_move_from_decor);
Jorim Jaggi08f75cf2018-01-08 14:38:53 +01004816 mDuration = (long)
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004817 (anim.computeDurationHint() * mWmService.getWindowAnimationScaleLocked());
Jorim Jaggia5e10572017-11-15 14:36:26 +01004818 mInterpolator = anim.getInterpolator();
4819 mFrom.set(fromX, fromY);
4820 mTo.set(toX, toY);
4821 }
4822
4823 @Override
4824 public long getDuration() {
4825 return mDuration;
4826 }
4827
4828 @Override
4829 public void apply(Transaction t, SurfaceControl leash, long currentPlayTime) {
4830 final float fraction = (float) currentPlayTime / getDuration();
4831 final float v = mInterpolator.getInterpolation(fraction);
4832 t.setPosition(leash, mFrom.x + (mTo.x - mFrom.x) * v,
4833 mFrom.y + (mTo.y - mFrom.y) * v);
4834 }
Jorim Jaggif75d1612018-02-27 15:05:21 +01004835
4836 @Override
4837 public void dump(PrintWriter pw, String prefix) {
chaviwc65fa582018-08-09 15:33:13 -07004838 pw.println(prefix + "from=" + mFrom
4839 + " to=" + mTo
4840 + " duration=" + mDuration);
Jorim Jaggif75d1612018-02-27 15:05:21 +01004841 }
4842
4843 @Override
4844 public void writeToProtoInner(ProtoOutputStream proto) {
4845 final long token = proto.start(MOVE);
4846 mFrom.writeToProto(proto, FROM);
4847 mTo.writeToProto(proto, TO);
Kweku Adams21b8d262018-03-30 12:19:58 -07004848 proto.write(DURATION_MS, mDuration);
Jorim Jaggif75d1612018-02-27 15:05:21 +01004849 proto.end(token);
4850 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01004851 }
satokcef37fb2011-10-24 21:49:38 +09004852}