blob: 2d47e5442fe04b981d4e8337e7df9ddcbe01040f [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
chaviw1454b392018-08-06 09:54:04 -0700793 public void computeFrameLw() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800794 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700795 // This window is being replaced and either already got information that it's being
796 // removed or we are still waiting for some information. Because of this we don't
797 // want to apply any more changes to it, so it remains in this state until new window
798 // appears.
799 return;
800 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800801 mHaveFrame = true;
802
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700803 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700804 final boolean inFullscreenContainer = inFullscreenContainer();
Robert Carre6275582016-02-29 15:45:45 -0800805 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700806 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800807
Chong Zhangae35fef2016-03-16 15:56:55 -0700808 // If the task has temp inset bounds set, we have to make sure all its windows uses
809 // the temp inset frame. Otherwise different display frames get applied to the main
810 // window and the child window, making them misaligned.
Adrian Roose76b2b52018-03-21 16:22:16 +0100811 // Otherwise we need to clear the inset frame, to avoid using a stale frame after leaving
812 // multi window mode.
813 if (task != null && isInMultiWindowMode()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700814 task.getTempInsetBounds(mInsetFrame);
Adrian Roose76b2b52018-03-21 16:22:16 +0100815 } else {
816 mInsetFrame.setEmpty();
Chong Zhangae35fef2016-03-16 15:56:55 -0700817 }
818
Jorim Jaggif5834272016-04-04 20:25:41 -0700819 // Denotes the actual frame used to calculate the insets and to perform the layout. When
820 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
821 // insets temporarily. By the notion of a task having a different layout frame, we can
822 // achieve that while still moving the task around.
823 final Rect layoutContainingFrame;
824 final Rect layoutDisplayFrame;
825
826 // The offset from the layout containing frame to the actual containing frame.
827 final int layoutXDiff;
828 final int layoutYDiff;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700829 if (inFullscreenContainer || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800830 // We use the parent frame as the containing frame for fullscreen and child windows
chaviw1454b392018-08-06 09:54:04 -0700831 mWindowFrames.mContainingFrame.set(mWindowFrames.mParentFrame);
832 layoutDisplayFrame = mWindowFrames.mDisplayFrame;
833 layoutContainingFrame = mWindowFrames.mParentFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700834 layoutXDiff = 0;
835 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800836 } else {
chaviw553b0212018-07-12 13:37:01 -0700837 getBounds(mWindowFrames.mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100838 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
839
840 // If the bounds are frozen, we still want to translate the window freely and only
841 // freeze the size.
842 Rect frozen = mAppToken.mFrozenBounds.peek();
chaviw553b0212018-07-12 13:37:01 -0700843 mWindowFrames.mContainingFrame.right =
844 mWindowFrames.mContainingFrame.left + frozen.width();
845 mWindowFrames.mContainingFrame.bottom =
846 mWindowFrames.mContainingFrame.top + frozen.height();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100847 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800848 final WindowState imeWin = mWmService.mRoot.getCurrentInputMethodWindow();
Robert Carrfc03b2b2016-03-31 15:22:02 -0700849 // IME is up and obscuring this window. Adjust the window position so it is visible.
Robert Carr825581a2018-03-30 14:00:53 -0700850 if (imeWin != null && imeWin.isVisibleNow() && isInputMethodTarget()) {
chaviw553b0212018-07-12 13:37:01 -0700851 if (inFreeformWindowingMode() && mWindowFrames.mContainingFrame.bottom
chaviw1454b392018-08-06 09:54:04 -0700852 > mWindowFrames.mContentFrame.bottom) {
Winson Chungd73e94b2017-05-31 16:25:30 -0700853 // In freeform we want to move the top up directly.
854 // TODO: Investigate why this is contentFrame not parentFrame.
chaviw553b0212018-07-12 13:37:01 -0700855 mWindowFrames.mContainingFrame.top -= mWindowFrames.mContainingFrame.bottom
chaviw1454b392018-08-06 09:54:04 -0700856 - mWindowFrames.mContentFrame.bottom;
chaviw553b0212018-07-12 13:37:01 -0700857 } else if (!inPinnedWindowingMode() && mWindowFrames.mContainingFrame.bottom
chaviw1454b392018-08-06 09:54:04 -0700858 > mWindowFrames.mParentFrame.bottom) {
Winson Chungd73e94b2017-05-31 16:25:30 -0700859 // But in docked we want to behave like fullscreen and behave as if the task
860 // were given smaller bounds for the purposes of layout. Skip adjustments for
861 // the pinned stack, they are handled separately in the PinnedStackController.
chaviw1454b392018-08-06 09:54:04 -0700862 mWindowFrames.mContainingFrame.bottom = mWindowFrames.mParentFrame.bottom;
Winson Chungd73e94b2017-05-31 16:25:30 -0700863 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700864 }
Skuhne81c524a2015-08-12 13:34:14 -0700865
Robert Carre6275582016-02-29 15:45:45 -0800866 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700867 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
868 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800869 // "content frame" since it is allowed to be outside the visible desktop.
chaviw553b0212018-07-12 13:37:01 -0700870 if (mWindowFrames.mContainingFrame.isEmpty()) {
chaviw1454b392018-08-06 09:54:04 -0700871 mWindowFrames.mContainingFrame.set(mWindowFrames.mContentFrame);
Skuhne81c524a2015-08-12 13:34:14 -0700872 }
Doris Liu06d582d2015-06-01 13:18:43 -0700873 }
Adrian Roos604ef952018-05-15 20:13:13 +0200874
875 final TaskStack stack = getStack();
876 if (inPinnedWindowingMode() && stack != null
877 && stack.lastAnimatingBoundsWasToFullscreen()) {
878 // PIP edge case: When going from pinned to fullscreen, we apply a
879 // tempInsetFrame for the full task - but we're still at the start of the animation.
880 // To prevent a jump if there's a letterbox, restrict to the parent frame.
chaviw1454b392018-08-06 09:54:04 -0700881 mInsetFrame.intersectUnchecked(mWindowFrames.mParentFrame);
882 mWindowFrames.mContainingFrame.intersectUnchecked(mWindowFrames.mParentFrame);
Adrian Roos604ef952018-05-15 20:13:13 +0200883 }
884
chaviw1454b392018-08-06 09:54:04 -0700885 layoutDisplayFrame = new Rect(mWindowFrames.mDisplayFrame);
chaviw553b0212018-07-12 13:37:01 -0700886 mWindowFrames.mDisplayFrame.set(mWindowFrames.mContainingFrame);
887 layoutXDiff =
888 !mInsetFrame.isEmpty() ? mInsetFrame.left - mWindowFrames.mContainingFrame.left
889 : 0;
890 layoutYDiff =
891 !mInsetFrame.isEmpty() ? mInsetFrame.top - mWindowFrames.mContainingFrame.top
892 : 0;
893 layoutContainingFrame =
894 !mInsetFrame.isEmpty() ? mInsetFrame : mWindowFrames.mContainingFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700895 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
chaviw1454b392018-08-06 09:54:04 -0700896 subtractInsets(mWindowFrames.mDisplayFrame, layoutContainingFrame, layoutDisplayFrame,
897 mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700898 if (!layoutInParentFrame()) {
chaviw553b0212018-07-12 13:37:01 -0700899 subtractInsets(mWindowFrames.mContainingFrame, layoutContainingFrame,
chaviw1454b392018-08-06 09:54:04 -0700900 mWindowFrames.mParentFrame, mTmpRect);
901 subtractInsets(mInsetFrame, layoutContainingFrame, mWindowFrames.mParentFrame,
chaviw553b0212018-07-12 13:37:01 -0700902 mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700903 }
Jorim Jaggif5834272016-04-04 20:25:41 -0700904 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700905 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800906
chaviw553b0212018-07-12 13:37:01 -0700907 final int pw = mWindowFrames.mContainingFrame.width();
908 final int ph = mWindowFrames.mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800909
Dianne Hackborn1743b642012-03-12 17:04:43 -0700910 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
911 mLastRequestedWidth = mRequestedWidth;
912 mLastRequestedHeight = mRequestedHeight;
chaviw1454b392018-08-06 09:54:04 -0700913 mWindowFrames.setContentChanged(true);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700914 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800915
chaviw492139a2018-07-16 16:07:35 -0700916 final int fw = mWindowFrames.mFrame.width();
917 final int fh = mWindowFrames.mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800918
Jorim Jaggif5834272016-04-04 20:25:41 -0700919 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
920
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700921 // Calculate the outsets before the content frame gets shrinked to the window frame.
chaviw1454b392018-08-06 09:54:04 -0700922 mWindowFrames.calculateOutsets();
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700923
Craig Mautnera248eee2013-05-07 11:41:27 -0700924 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800925 // final window frame.
chaviw492139a2018-07-16 16:07:35 -0700926 if (windowsAreFloating && !mWindowFrames.mFrame.isEmpty()) {
Robert Carre65a1c42017-02-28 16:52:59 -0800927 // For pinned workspace the frame isn't limited in any particular
928 // way since SystemUI controls the bounds. For freeform however
929 // we want to keep things inside the content frame.
chaviw492139a2018-07-16 16:07:35 -0700930 final Rect limitFrame = task.inPinnedWindowingMode() ? mWindowFrames.mFrame
931 : mWindowFrames.mContentFrame;
Skuhne81c524a2015-08-12 13:34:14 -0700932 // Keep the frame out of the blocked system area, limit it in size to the content area
933 // and make sure that there is always a minimum visible so that the user can drag it
934 // into a usable area..
chaviw492139a2018-07-16 16:07:35 -0700935 final int height = Math.min(mWindowFrames.mFrame.height(), limitFrame.height());
936 final int width = Math.min(limitFrame.width(), mWindowFrames.mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700937 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +0900938 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
939 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
940 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
941 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Robert Carre65a1c42017-02-28 16:52:59 -0800942 final int top = Math.max(limitFrame.top,
chaviw492139a2018-07-16 16:07:35 -0700943 Math.min( mWindowFrames.mFrame.top, limitFrame.bottom - minVisibleHeight));
Robert Carre65a1c42017-02-28 16:52:59 -0800944 final int left = Math.max(limitFrame.left + minVisibleWidth - width,
chaviw492139a2018-07-16 16:07:35 -0700945 Math.min( mWindowFrames.mFrame.left, limitFrame.right - minVisibleWidth));
946 mWindowFrames.mFrame.set(left, top, left + width, top + height);
947 mWindowFrames.mContentFrame.set( mWindowFrames.mFrame);
chaviw553b0212018-07-12 13:37:01 -0700948 mWindowFrames.mVisibleFrame.set(mWindowFrames.mContentFrame);
949 mWindowFrames.mStableFrame.set(mWindowFrames.mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700950 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
chaviw492139a2018-07-16 16:07:35 -0700951 dc.getDockedDividerController().positionDockedStackedDivider(mWindowFrames.mFrame);
952 mWindowFrames.mContentFrame.set(mWindowFrames.mFrame);
953 if (!mWindowFrames.mFrame.equals(mWindowFrames.mLastFrame)) {
Jorim Jaggi192086e2016-03-11 17:17:03 +0100954 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800955 }
Skuhne81c524a2015-08-12 13:34:14 -0700956 } else {
chaviw492139a2018-07-16 16:07:35 -0700957 mWindowFrames.mContentFrame.set(
958 Math.max(mWindowFrames.mContentFrame.left, mWindowFrames.mFrame.left),
959 Math.max(mWindowFrames.mContentFrame.top, mWindowFrames.mFrame.top),
960 Math.min(mWindowFrames.mContentFrame.right, mWindowFrames.mFrame.right),
961 Math.min(mWindowFrames.mContentFrame.bottom, mWindowFrames.mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800962
chaviw492139a2018-07-16 16:07:35 -0700963 mWindowFrames.mVisibleFrame.set(
964 Math.max(mWindowFrames.mVisibleFrame.left, mWindowFrames.mFrame.left),
965 Math.max(mWindowFrames.mVisibleFrame.top, mWindowFrames.mFrame.top),
966 Math.min(mWindowFrames.mVisibleFrame.right, mWindowFrames.mFrame.right),
967 Math.min(mWindowFrames.mVisibleFrame.bottom, mWindowFrames.mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800968
chaviw492139a2018-07-16 16:07:35 -0700969 mWindowFrames.mStableFrame.set(
970 Math.max(mWindowFrames.mStableFrame.left, mWindowFrames.mFrame.left),
971 Math.max(mWindowFrames.mStableFrame.top, mWindowFrames.mFrame.top),
972 Math.min(mWindowFrames.mStableFrame.right, mWindowFrames.mFrame.right),
973 Math.min(mWindowFrames.mStableFrame.bottom, mWindowFrames.mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700974 }
Adrian Roosfa104232014-06-20 16:10:14 -0700975
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700976 if (inFullscreenContainer && !windowsAreFloating) {
Jorim Jaggi899327f2016-02-25 20:44:18 -0500977 // Windows that are not fullscreen can be positioned outside of the display frame,
978 // but that is not a reason to provide them with overscan insets.
chaviw9c81e632018-07-31 11:17:52 -0700979 InsetUtils.insetsBetweenFrames(layoutContainingFrame, mWindowFrames.mOverscanFrame,
980 mWindowFrames.mOverscanInsets);
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800981 }
Craig Mautnereda67292013-04-28 13:50:14 -0700982
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100983 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
chaviw1454b392018-08-06 09:54:04 -0700984 final WmDisplayCutout c = mWindowFrames.mDisplayCutout.calculateRelativeTo(
chaviw553b0212018-07-12 13:37:01 -0700985 mWindowFrames.mDisplayFrame);
chaviw9c81e632018-07-31 11:17:52 -0700986 mWindowFrames.calculateDockedDividerInsets(c.getDisplayCutout().getSafeInsets());
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100987 } else {
Bryce Leef3c6a472017-11-14 14:53:06 -0800988 getDisplayContent().getBounds(mTmpRect);
chaviw9c81e632018-07-31 11:17:52 -0700989 mWindowFrames.calculateInsets(windowsAreFloating, inFullscreenContainer, mTmpRect);
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100990 }
Adrian Roosfa104232014-06-20 16:10:14 -0700991
chaviwcdba9a42018-07-19 11:36:42 -0700992 mWindowFrames.setDisplayCutout(
chaviw1454b392018-08-06 09:54:04 -0700993 mWindowFrames.mDisplayCutout.calculateRelativeTo(mWindowFrames.mFrame));
Jorim Jaggibae2b152018-04-18 17:27:27 +0200994
Jorim Jaggi656f6502016-04-11 21:08:17 -0700995 // Offset the actual frame by the amount layout frame is off.
chaviw9c81e632018-07-31 11:17:52 -0700996 mWindowFrames.offsetFrames(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -0700997
chaviw9c81e632018-07-31 11:17:52 -0700998 mWindowFrames.mCompatFrame.set(mWindowFrames.mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400999 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001000 // If there is a size compatibility scale being applied to the
1001 // window, we need to apply this to its insets so that they are
1002 // reported to the app in its coordinate space.
chaviw9c81e632018-07-31 11:17:52 -07001003 mWindowFrames.scaleInsets(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001004
1005 // Also the scaled frame that we report to the app needs to be
1006 // adjusted to be in its coordinate space.
chaviw9c81e632018-07-31 11:17:52 -07001007 mWindowFrames.mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001008 }
1009
chaviw492139a2018-07-16 16:07:35 -07001010 if (mIsWallpaper && (fw != mWindowFrames.mFrame.width()
1011 || fh != mWindowFrames.mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001012 final DisplayContent displayContent = getDisplayContent();
1013 if (displayContent != null) {
1014 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
chaviw553b0212018-07-12 13:37:01 -07001015 getDisplayContent().mWallpaperController.updateWallpaperOffset(this,
1016 displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001017 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001018 }
1019
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001020 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001021 "Resolving (mRequestedWidth="
1022 + mRequestedWidth + ", mRequestedheight="
1023 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
chaviw492139a2018-07-16 16:07:35 -07001024 + "): frame=" + mWindowFrames.mFrame.toShortString()
chaviw9c81e632018-07-31 11:17:52 -07001025 + " " + mWindowFrames.getInsetsInfo());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001026 }
1027
Bryce Leef3c6a472017-11-14 14:53:06 -08001028 // TODO: Look into whether this override is still necessary.
1029 @Override
1030 public Rect getBounds() {
1031 if (isInMultiWindowMode()) {
1032 return getTask().getBounds();
1033 } else if (mAppToken != null){
1034 return mAppToken.getBounds();
1035 } else {
1036 return super.getBounds();
1037 }
1038 }
1039
Craig Mautnera2c77052012-03-26 12:14:43 -07001040 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001041 public Rect getFrameLw() {
chaviw492139a2018-07-16 16:07:35 -07001042 return mWindowFrames.mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001043 }
1044
Craig Mautnera2c77052012-03-26 12:14:43 -07001045 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001046 public Rect getDisplayFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001047 return mWindowFrames.mDisplayFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001048 }
1049
Craig Mautnera2c77052012-03-26 12:14:43 -07001050 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001051 public Rect getOverscanFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001052 return mWindowFrames.mOverscanFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001053 }
1054
1055 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001056 public Rect getContentFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001057 return mWindowFrames.mContentFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001058 }
1059
Craig Mautnera2c77052012-03-26 12:14:43 -07001060 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001061 public Rect getVisibleFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001062 return mWindowFrames.mVisibleFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001063 }
1064
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001065 Rect getStableFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001066 return mWindowFrames.mStableFrame;
1067 }
1068
1069 Rect getDecorFrame() {
1070 return mWindowFrames.mDecorFrame;
1071 }
1072
1073 Rect getParentFrame() {
1074 return mWindowFrames.mParentFrame;
1075 }
1076
1077 Rect getContainingFrame() {
1078 return mWindowFrames.mContainingFrame;
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001079 }
1080
chaviwcdba9a42018-07-19 11:36:42 -07001081 WmDisplayCutout getWmDisplayCutout() {
1082 return mWindowFrames.mDisplayCutout;
1083 }
1084
chaviw9c81e632018-07-31 11:17:52 -07001085 void getCompatFrame(Rect outFrame) {
1086 outFrame.set(mWindowFrames.mCompatFrame);
1087 }
1088
1089 void getCompatFrameSize(Rect outFrame) {
1090 outFrame.set(0, 0, mWindowFrames.mCompatFrame.width(), mWindowFrames.mCompatFrame.height());
1091 }
1092
Craig Mautnera2c77052012-03-26 12:14:43 -07001093 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001094 public boolean getGivenInsetsPendingLw() {
1095 return mGivenInsetsPending;
1096 }
1097
Craig Mautnera2c77052012-03-26 12:14:43 -07001098 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001099 public Rect getGivenContentInsetsLw() {
1100 return mGivenContentInsets;
1101 }
1102
Craig Mautnera2c77052012-03-26 12:14:43 -07001103 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001104 public Rect getGivenVisibleInsetsLw() {
1105 return mGivenVisibleInsets;
1106 }
1107
Craig Mautnera2c77052012-03-26 12:14:43 -07001108 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001109 public WindowManager.LayoutParams getAttrs() {
1110 return mAttrs;
1111 }
1112
Craig Mautner812d2ca2012-09-27 15:35:34 -07001113 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001114 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001115 return getDisplayContent().getNeedsMenu(this, bottom);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001116 }
1117
Craig Mautner19d59bc2012-09-04 11:15:56 -07001118 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001119 public int getSystemUiVisibility() {
1120 return mSystemUiVisibility;
1121 }
1122
Craig Mautner19d59bc2012-09-04 11:15:56 -07001123 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001124 public int getSurfaceLayer() {
1125 return mLayer;
1126 }
1127
Craig Mautner812d2ca2012-09-27 15:35:34 -07001128 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001129 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001130 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001131 }
1132
1133 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001134 public IApplicationToken getAppToken() {
1135 return mAppToken != null ? mAppToken.appToken : null;
1136 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001137
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001138 @Override
1139 public boolean isVoiceInteraction() {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001140 return mAppToken != null && mAppToken.mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001141 }
1142
Robert Carr31aa98b2016-07-20 15:29:03 -07001143 boolean setReportResizeHints() {
chaviw9c81e632018-07-31 11:17:52 -07001144 return mWindowFrames.setReportResizeHints();
Craig Mautner4c5eb222013-11-18 12:59:05 -08001145 }
1146
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001147 /**
1148 * Adds the window to the resizing list if any of the parameters we use to track the window
1149 * dimensions or insets have changed.
1150 */
1151 void updateResizingWindowIfNeeded() {
1152 final WindowStateAnimator winAnimator = mWinAnimator;
Adrian Roos5251b1d2018-03-23 18:57:43 +01001153 if (!mHasSurface || getDisplayContent().mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001154 return;
1155 }
1156
1157 final Task task = getTask();
1158 // In the case of stack bound animations, the window frames will update (unlike other
1159 // animations which just modify various transformation properties). We don't want to
1160 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1161 // the frame may not correspond to the surface size or the onscreen area at various
1162 // phases in the animation, and the client will become sad and confused.
Winson Chung40a5f932017-04-13 16:39:36 -07001163 if (task != null && task.mStack.isAnimatingBounds()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001164 return;
1165 }
1166
chaviw9c81e632018-07-31 11:17:52 -07001167 boolean didFrameInsetsChange = setReportResizeHints();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001168 boolean configChanged = isConfigChanged();
1169 if (DEBUG_CONFIGURATION && configChanged) {
1170 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1171 }
1172
1173 final boolean dragResizingChanged = isDragResizeChanged()
1174 && !isDragResizingChangeReported();
1175
1176 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
chaviw492139a2018-07-16 16:07:35 -07001177 + " dragResizingChanged=" + dragResizingChanged
1178 + " last=" + mWindowFrames.mLastFrame + " frame=" + mWindowFrames.mFrame);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001179
1180 // We update mLastFrame always rather than in the conditional with the last inset
1181 // variables, because mFrameSizeChanged only tracks the width and height changing.
chaviw492139a2018-07-16 16:07:35 -07001182 mWindowFrames.mLastFrame.set(mWindowFrames.mFrame);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001183
chaviw9c81e632018-07-31 11:17:52 -07001184 if (didFrameInsetsChange
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001185 || winAnimator.mSurfaceResized
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001186 || configChanged
1187 || dragResizingChanged
Andrii Kulianb2e37802017-01-11 00:36:44 -08001188 || mReportOrientationChanged) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001189 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1190 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
chaviw9c81e632018-07-31 11:17:52 -07001191 + " " + mWindowFrames.getInsetsChangedInfo()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001192 + " surfaceResized=" + winAnimator.mSurfaceResized
1193 + " configChanged=" + configChanged
1194 + " dragResizingChanged=" + dragResizingChanged
chaviw9c81e632018-07-31 11:17:52 -07001195 + " reportOrientationChanged=" + mReportOrientationChanged);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001196 }
1197
1198 // If it's a dead window left on screen, and the configuration changed, there is nothing
1199 // we can do about it. Remove the window now.
1200 if (mAppToken != null && mAppDied) {
1201 mAppToken.removeDeadWindows();
1202 return;
1203 }
1204
Jorim Jaggidc9385a2017-05-13 02:00:31 +02001205 updateLastInsetValues();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001206 mWmService.makeWindowFreezingScreenIfNeededLocked(this);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001207
1208 // If the orientation is changing, or we're starting or ending a drag resizing action,
1209 // then we need to hold off on unfreezing the display until this window has been
1210 // redrawn; to do that, we need to go through the process of getting informed by the
1211 // application when it has finished drawing.
Robert Carr09286c92018-02-15 13:52:31 -08001212 if (getOrientationChanging() || dragResizingChanged) {
Robert Carre13b58e2017-08-31 14:50:44 -07001213 if (DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001214 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1215 + ", mDrawState=DRAW_PENDING in " + this
1216 + ", surfaceController " + winAnimator.mSurfaceController);
1217 }
1218 winAnimator.mDrawState = DRAW_PENDING;
1219 if (mAppToken != null) {
1220 mAppToken.clearAllDrawn();
1221 }
1222 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001223 if (!mWmService.mResizingWindows.contains(this)) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001224 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001225 mWmService.mResizingWindows.add(this);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001226 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07001227 } else if (getOrientationChanging()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001228 if (isDrawnLw()) {
1229 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1230 + this + ", surfaceController " + winAnimator.mSurfaceController);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001231 setOrientationChanging(false);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001232 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001233 - mWmService.mDisplayFreezeTime);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001234 }
1235 }
1236 }
1237
Bryce Lee8c3cf382017-07-06 19:47:10 -07001238 boolean getOrientationChanging() {
1239 // In addition to the local state flag, we must also consider the difference in the last
1240 // reported configuration vs. the current state. If the client code has not been informed of
1241 // the change, logic dependent on having finished processing the orientation, such as
1242 // unfreezing, could be improperly triggered.
1243 // TODO(b/62846907): Checking against {@link mLastReportedConfiguration} could be flaky as
1244 // this is not necessarily what the client has processed yet. Find a
1245 // better indicator consistent with the client.
Robert Carr926643f2017-08-02 12:01:12 -07001246 return (mOrientationChanging || (isVisible()
Bryce Lee2b17afd2017-09-21 10:38:20 -07001247 && getConfiguration().orientation != getLastReportedConfiguration().orientation))
Robert Carr9c1c3a02017-08-08 12:59:01 -07001248 && !mSeamlesslyRotated
1249 && !mOrientationChangeTimedOut;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001250 }
1251
1252 void setOrientationChanging(boolean changing) {
1253 mOrientationChanging = changing;
Robert Carr9c1c3a02017-08-08 12:59:01 -07001254 mOrientationChangeTimedOut = false;
1255 }
1256
1257 void orientationChangeTimedOut() {
1258 mOrientationChangeTimedOut = true;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001259 }
1260
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001261 DisplayContent getDisplayContent() {
1262 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001263 }
1264
Adrian Roos5251b1d2018-03-23 18:57:43 +01001265 @Override
1266 void onDisplayChanged(DisplayContent dc) {
1267 super.onDisplayChanged(dc);
1268 // Window was not laid out for this display yet, so make sure mLayoutSeq does not match.
1269 if (dc != null) {
1270 mLayoutSeq = dc.mLayoutSeq - 1;
Brad Stenningaf596412018-04-02 12:03:19 -07001271 mInputWindowHandle.displayId = dc.getDisplayId();
Adrian Roos5251b1d2018-03-23 18:57:43 +01001272 }
1273 }
1274
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001275 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001276 final DisplayContent displayContent = getDisplayContent();
1277 return displayContent != null ? displayContent.getDisplayInfo() : null;
1278 }
1279
Jorim Jaggife762342016-10-13 14:33:27 +02001280 @Override
1281 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001282 final DisplayContent displayContent = getDisplayContent();
1283 if (displayContent == null) {
Brad Stenningaf596412018-04-02 12:03:19 -07001284 return Display.INVALID_DISPLAY;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001285 }
1286 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001287 }
1288
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001289 Task getTask() {
Bryce Lee6d410262017-02-28 15:30:17 -08001290 return mAppToken != null ? mAppToken.getTask() : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001291 }
1292
1293 TaskStack getStack() {
1294 Task task = getTask();
1295 if (task != null) {
1296 if (task.mStack != null) {
1297 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001298 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001299 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001300 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1301 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001302 final DisplayContent dc = getDisplayContent();
1303 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001304 }
1305
Skuhnef932e562015-08-20 12:07:30 -07001306 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001307 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001308 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001309 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001310 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001311 final Task task = getTask();
1312 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001313 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001314 mTmpRect.setEmpty();
1315 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001316 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001317 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001318 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001319 } else {
1320 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001321 }
1322 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001323
chaviw553b0212018-07-12 13:37:01 -07001324 bounds.set(mWindowFrames.mVisibleFrame);
Chong Zhang9184ec62015-09-24 12:32:21 -07001325 if (intersectWithStackBounds) {
1326 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001327 }
1328
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001329 if (bounds.isEmpty()) {
chaviw492139a2018-07-16 16:07:35 -07001330 bounds.set(mWindowFrames.mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001331 if (intersectWithStackBounds) {
1332 bounds.intersect(mTmpRect);
1333 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001334 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001335 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001336 }
1337
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001338 public long getInputDispatchingTimeoutNanos() {
1339 return mAppToken != null
Wale Ogunwale72919d22016-12-08 18:58:50 -08001340 ? mAppToken.mInputDispatchingTimeoutNanos
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001341 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1342 }
1343
Craig Mautnere8552142012-11-07 13:55:47 -08001344 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001345 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001346 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001347 }
1348
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001349 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1350 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1351 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1352 if (dtdx < -.000001f || dtdx > .000001f) return false;
1353 if (dsdy < -.000001f || dsdy > .000001f) return false;
1354 return true;
1355 }
1356
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001357 void prelayout() {
1358 if (mEnforceSizeCompat) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001359 mGlobalScale = getDisplayContent().mCompatibleScreenScale;
1360 mInvGlobalScale = 1 / mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001361 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001362 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001363 }
1364 }
1365
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001366 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001367 boolean hasContentToDisplay() {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001368 if (!mAppFreezing && isDrawnLw() && (mViewVisibility == View.VISIBLE
lumark588a3e82018-07-20 18:53:54 +08001369 || (isAnimating() && !getDisplayContent().mAppTransition.isTransitionSet()))) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001370 return true;
1371 }
1372
Wale Ogunwale44f21802016-09-02 12:49:48 -07001373 return super.hasContentToDisplay();
1374 }
1375
1376 @Override
1377 boolean isVisible() {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001378 return wouldBeVisibleIfPolicyIgnored() && mPolicyVisibility;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001379 }
1380
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001381 /**
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001382 * @return True if the window would be visible if we'd ignore policy visibility, false
1383 * otherwise.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001384 */
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001385 boolean wouldBeVisibleIfPolicyIgnored() {
Jorim Jaggi43530c92017-05-18 01:53:56 +02001386 return mHasSurface && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001387 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001388 }
1389
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001390 @Override
1391 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001392 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001393 }
1394
1395 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001396 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1397 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001398 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001399 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1400 boolean isWinVisibleLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001401 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.isSelfAnimating())
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001402 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001403 }
1404
1405 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001406 * The same as isVisible(), but follows the current hidden state of the associated app token,
1407 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001408 */
1409 boolean isVisibleNow() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001410 return (!mToken.isHidden() || mAttrs.type == TYPE_APPLICATION_STARTING)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001411 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001412 }
1413
1414 /**
1415 * Can this window possibly be a drag/drop target? The test here is
1416 * a combination of the above "visible now" with the check that the
1417 * Input Manager uses when discarding windows from input consideration.
1418 */
1419 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001420 return isVisibleNow() && !mRemoved
1421 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001422 }
1423
1424 /**
1425 * Same as isVisible(), but we also count it as visible between the
1426 * call to IWindowSession.add() and the first relayout().
1427 */
1428 boolean isVisibleOrAdding() {
1429 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001430 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001431 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001432 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001433 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001434 }
1435
1436 /**
1437 * Is this window currently on-screen? It is on-screen either if it
1438 * is visible or it is currently running an animation before no longer
1439 * being visible.
1440 */
1441 boolean isOnScreen() {
Jorim Jaggiaf221d12016-11-15 14:59:57 -08001442 if (!mHasSurface || mDestroying || !mPolicyVisibility) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001443 return false;
1444 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001445 final AppWindowToken atoken = mAppToken;
1446 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001447 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001448 || isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001449 }
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001450 return !isParentWindowHidden() || isAnimating();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001451 }
1452
1453 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001454 * Whether this window's drawn state might affect the drawn states of the app token.
1455 *
Chong Zhang8e4bda92016-05-04 15:08:18 -07001456 * @return true if the window should be considered while evaluating allDrawn flags.
1457 */
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001458 boolean mightAffectAllDrawn() {
1459 final boolean isAppType = mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1460 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION;
1461 return (isOnScreen() || isAppType) && !mAnimatingExit && !mDestroying;
Chong Zhang8e4bda92016-05-04 15:08:18 -07001462 }
1463
1464 /**
1465 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1466 * it must be drawn before allDrawn can become true.
1467 */
1468 boolean isInteresting() {
1469 return mAppToken != null && !mAppDied
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001470 && (!mAppToken.isFreezingScreen() || !mAppFreezing);
Chong Zhang8e4bda92016-05-04 15:08:18 -07001471 }
1472
1473 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001474 * Like isOnScreen(), but we don't return true if the window is part
1475 * of a transition that has not yet been started.
1476 */
1477 boolean isReadyForDisplay() {
lumark588a3e82018-07-20 18:53:54 +08001478 if (mToken.waitingToShow && getDisplayContent().mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001479 return false;
1480 }
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001481 final boolean parentAndClientVisible = !isParentWindowHidden()
1482 && mViewVisibility == View.VISIBLE && !mToken.isHidden();
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001483 return mHasSurface && mPolicyVisibility && !mDestroying
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001484 && (parentAndClientVisible || isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001485 }
1486
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001487 // TODO: Another visibility method that was added late in the release to minimize risk.
1488 @Override
1489 public boolean canAffectSystemUiFlags() {
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001490 final boolean translucent = mAttrs.alpha == 0.0f;
Jorim Jaggi72207752018-01-08 13:16:59 +01001491 if (translucent) {
1492 return false;
1493 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001494 if (mAppToken == null) {
1495 final boolean shown = mWinAnimator.getShown();
1496 final boolean exiting = mAnimatingExit || mDestroying;
Jorim Jaggi72207752018-01-08 13:16:59 +01001497 return shown && !exiting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001498 } else {
Jorim Jaggi50bf59c2018-03-09 17:29:48 +01001499 final Task task = getTask();
1500 final boolean canFromTask = task != null && task.canAffectSystemUiFlags();
1501 return canFromTask && !mAppToken.isHidden();
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001502 }
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001503 }
1504
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001505 /**
1506 * Like isOnScreen, but returns false if the surface hasn't yet
1507 * been drawn.
1508 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001509 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001510 public boolean isDisplayedLw() {
1511 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001512 return isDrawnLw() && mPolicyVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001513 && ((!isParentWindowHidden() && (atoken == null || !atoken.hiddenRequested))
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001514 || isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001515 }
1516
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001517 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001518 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001519 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001520 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001521 public boolean isAnimatingLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001522 return isAnimating();
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001523 }
1524
Craig Mautner812d2ca2012-09-27 15:35:34 -07001525 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001526 public boolean isGoneForLayoutLw() {
1527 final AppWindowToken atoken = mAppToken;
1528 return mViewVisibility == View.GONE
1529 || !mRelayoutCalled
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001530 || (atoken == null && mToken.isHidden())
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001531 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001532 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001533 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001534 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001535 }
1536
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001537 /**
1538 * Returns true if the window has a surface that it has drawn a
1539 * complete UI in to.
1540 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001541 public boolean isDrawFinishedLw() {
1542 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001543 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1544 || mWinAnimator.mDrawState == READY_TO_SHOW
1545 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001546 }
1547
1548 /**
1549 * Returns true if the window has a surface that it has drawn a
1550 * complete UI in to.
1551 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001552 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001553 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001554 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001555 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001556 }
1557
1558 /**
1559 * Return true if the window is opaque and fully drawn. This indicates
1560 * it may obscure windows behind it.
1561 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001562 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001563 // When there is keyguard, wallpaper could be placed over the secure app
1564 // window but invisible. We need to check wallpaper visibility explicitly
1565 // to determine if it's occluding apps.
1566 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1567 || (mIsWallpaper && mWallpaperVisible))
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001568 && isDrawnLw() && !isAnimating();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001569 }
1570
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001571 @Override
1572 void onMovedByResize() {
1573 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001574 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001575 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001576 }
1577
1578 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1579 boolean changed = false;
1580
1581 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001582 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001583 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1584 }
1585
1586 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1587 // Starting window that's exiting will be removed when the animation finishes.
1588 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1589 // to actually remove it.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001590 if (!visible && isVisibleNow() && mAppToken.isSelfAnimating()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001591 mAnimatingExit = true;
1592 mRemoveOnExit = true;
1593 mWindowRemovalAllowed = true;
1594 }
1595 return changed;
1596 }
1597
chaviwe390cbd2018-04-16 15:29:38 -07001598 final boolean isVisibleNow = isVisibleNow();
1599 if (visible != isVisibleNow) {
1600 // Run exit animation if:
1601 // 1. App visibility and WS visibility are different
1602 // 2. App is not running an animation
1603 // 3. WS is currently visible
1604 if (!runningAppAnimation && isVisibleNow) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001605 final AccessibilityController accessibilityController =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001606 mWmService.mAccessibilityController;
chaviwe390cbd2018-04-16 15:29:38 -07001607 final int winTransit = TRANSIT_EXIT;
1608 mWinAnimator.applyAnimationLocked(winTransit, false /* isEntrance */);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001609 //TODO (multidisplay): Magnification is supported only for the default
1610 if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
1611 accessibilityController.onWindowTransitionLocked(this, winTransit);
1612 }
1613 }
1614 changed = true;
1615 setDisplayLayoutNeeded();
1616 }
1617
1618 return changed;
1619 }
1620
1621 boolean onSetAppExiting() {
1622 final DisplayContent displayContent = getDisplayContent();
1623 boolean changed = false;
1624
1625 if (isVisibleNow()) {
1626 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
1627 //TODO (multidisplay): Magnification is supported only for the default
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001628 if (mWmService.mAccessibilityController != null && isDefaultDisplay()) {
1629 mWmService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001630 }
1631 changed = true;
1632 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001633 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001634 }
1635 }
1636
1637 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001638 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001639 changed |= c.onSetAppExiting();
1640 }
1641
1642 return changed;
1643 }
1644
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001645 @Override
1646 void onResize() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001647 final ArrayList<WindowState> resizingWindows = mWmService.mResizingWindows;
Andrii Kulian3dcdf642018-05-23 17:14:00 -07001648 if (mHasSurface && !isGoneForLayoutLw() && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001649 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001650 resizingWindows.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001651 }
1652 if (isGoneForLayoutLw()) {
1653 mResizedWhileGone = true;
1654 }
1655
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001656 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001657 }
1658
1659 void onUnfreezeBounds() {
1660 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001661 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001662 c.onUnfreezeBounds();
1663 }
1664
1665 if (!mHasSurface) {
1666 return;
1667 }
1668
1669 mLayoutNeeded = true;
1670 setDisplayLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001671 if (!mWmService.mResizingWindows.contains(this)) {
1672 mWmService.mResizingWindows.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001673 }
1674 }
1675
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001676 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001677 * If the window has moved due to its containing content frame changing, then notify the
1678 * listeners and optionally animate it. Simply checking a change of position is not enough,
1679 * because being move due to dock divider is not a trigger for animation.
1680 */
chaviw161ea3e2018-01-31 12:01:12 -08001681 void handleWindowMovedIfNeeded() {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001682 if (!hasMoved()) {
1683 return;
1684 }
1685
1686 // Frame has moved, containing content frame has also moved, and we're not currently
1687 // animating... let's do something.
chaviw492139a2018-07-16 16:07:35 -07001688 final int left = mWindowFrames.mFrame.left;
1689 final int top = mWindowFrames.mFrame.top;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001690 final Task task = getTask();
1691 final boolean adjustedForMinimizedDockOrIme = task != null
1692 && (task.mStack.isAdjustedForMinimizedDockedStack()
1693 || task.mStack.isAdjustedForIme());
David Stevens9440dc82017-03-16 19:00:20 -07001694 if (mToken.okToAnimate()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001695 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1696 && !isDragResizing() && !adjustedForMinimizedDockOrIme
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001697 && getWindowConfiguration().hasMovementAnimations()
Adrian Roos0e7b70a2018-06-07 15:29:34 +02001698 && !mWinAnimator.mLastHidden
1699 && !mSeamlesslyRotated) {
chaviw161ea3e2018-01-31 12:01:12 -08001700 startMoveAnimation(left, top);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001701 }
1702
1703 //TODO (multidisplay): Accessibility supported only for the default display.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001704 if (mWmService.mAccessibilityController != null
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001705 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001706 mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001707 }
1708
1709 try {
1710 mClient.moved(left, top);
1711 } catch (RemoteException e) {
1712 }
1713 mMovedByResize = false;
1714 }
1715
1716 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001717 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001718 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1719 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001720 private boolean hasMoved() {
chaviw1454b392018-08-06 09:54:04 -07001721 return mHasSurface && (mWindowFrames.hasContentChanged() || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001722 && !mAnimatingExit
chaviw492139a2018-07-16 16:07:35 -07001723 && (mWindowFrames.mFrame.top != mWindowFrames.mLastFrame.top
1724 || mWindowFrames.mFrame.left != mWindowFrames.mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001725 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001726 }
1727
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001728 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001729 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001730 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001731 return false;
1732 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001733 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001734 }
1735
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001736 boolean fillsDisplay() {
1737 final DisplayInfo displayInfo = getDisplayInfo();
chaviw492139a2018-07-16 16:07:35 -07001738 return mWindowFrames.mFrame.left <= 0 && mWindowFrames.mFrame.top <= 0
1739 && mWindowFrames.mFrame.right >= displayInfo.appWidth
1740 && mWindowFrames.mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001741 }
1742
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001743 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001744 boolean isConfigChanged() {
Bryce Lee2b17afd2017-09-21 10:38:20 -07001745 return !getLastReportedConfiguration().equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001746 }
1747
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001748 void onWindowReplacementTimeout() {
1749 if (mWillReplaceWindow) {
1750 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001751 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001752 // delays removal on certain conditions, which will leave the stale window in the
1753 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1754 //
1755 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001756 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001757 } else {
1758 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001759 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001760 c.onWindowReplacementTimeout();
1761 }
1762 }
1763 }
1764
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001765 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001766 void forceWindowsScaleableInTransaction(boolean force) {
1767 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1768 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1769 }
1770
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001771 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001772 }
1773
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001774 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001775 void removeImmediately() {
1776 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001777
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001778 if (mRemoved) {
1779 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001780 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1781 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001782 return;
1783 }
1784
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001785 mRemoved = true;
1786
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001787 mWillReplaceWindow = false;
1788 if (mReplacementWindow != null) {
1789 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1790 }
1791
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001792 final DisplayContent dc = getDisplayContent();
Robert Carr825581a2018-03-30 14:00:53 -07001793 if (isInputMethodTarget()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001794 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001795 }
1796
1797 final int type = mAttrs.type;
1798 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001799 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001800 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001801 if (mTapExcludeRegionHolder != null) {
1802 // If a tap exclude region container was initialized for this window, then it should've
1803 // also been registered in display.
1804 dc.mTapExcludeProvidingWindows.remove(this);
1805 }
Tiger Huang7c610aa2018-10-27 00:01:01 +08001806 dc.getDisplayPolicy().removeWindowLw(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001807
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001808 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001809
Craig Mautner96868332012-12-04 14:29:11 -08001810 mWinAnimator.destroyDeferredSurfaceLocked();
1811 mWinAnimator.destroySurfaceLocked();
Wale Ogunwale943002b2017-02-15 19:34:01 -08001812 mSession.windowRemovedLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001813 try {
1814 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1815 } catch (RuntimeException e) {
1816 // Ignore if it has already been removed (usually because
1817 // we are doing this as part of processing a death note.)
1818 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001819
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001820 mWmService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001821 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001822
Wale Ogunwale571771c2016-08-26 13:18:50 -07001823 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001824 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001825 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001826 removeIfPossible(false /*keepVisibleDeadWindow*/);
1827 }
1828
Wale Ogunwale571771c2016-08-26 13:18:50 -07001829 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001830 mWindowRemovalAllowed = true;
1831 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1832 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1833
1834 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1835 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1836 "Starting window removed " + this);
1837
Tiger Huang1e5b10a2018-07-30 20:19:51 +08001838 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && isFocused())
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001839 Slog.v(TAG_WM, "Remove " + this + " client="
1840 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1841 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1842 + Debug.getCallers(5));
1843
1844 final long origId = Binder.clearCallingIdentity();
1845
Peter Visontay3556a3b2017-11-01 17:23:17 +00001846 try {
1847 disposeInputChannel();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001848
Peter Visontay3556a3b2017-11-01 17:23:17 +00001849 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1850 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1851 + " mAnimatingExit=" + mAnimatingExit
1852 + " mRemoveOnExit=" + mRemoveOnExit
1853 + " mHasSurface=" + mHasSurface
1854 + " surfaceShowing=" + mWinAnimator.getShown()
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001855 + " animating=" + isAnimating()
Peter Visontay3556a3b2017-11-01 17:23:17 +00001856 + " app-animation="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001857 + (mAppToken != null ? mAppToken.isSelfAnimating() : "false")
Peter Visontay3556a3b2017-11-01 17:23:17 +00001858 + " mWillReplaceWindow=" + mWillReplaceWindow
1859 + " inPendingTransaction="
1860 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001861 + " mDisplayFrozen=" + mWmService.mDisplayFrozen
Peter Visontay3556a3b2017-11-01 17:23:17 +00001862 + " callers=" + Debug.getCallers(6));
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001863
Peter Visontay3556a3b2017-11-01 17:23:17 +00001864 // Visibility of the removed window. Will be used later to update orientation later on.
1865 boolean wasVisible = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001866
Peter Visontay3556a3b2017-11-01 17:23:17 +00001867 final int displayId = getDisplayId();
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001868
Peter Visontay3556a3b2017-11-01 17:23:17 +00001869 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1870 // window until the animation is done. If the display is frozen, just remove immediately,
1871 // since the animation wouldn't be seen.
1872 if (mHasSurface && mToken.okToAnimate()) {
1873 if (mWillReplaceWindow) {
1874 // This window is going to be replaced. We need to keep it around until the new one
1875 // gets added, then we will get rid of this one.
1876 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1877 "Preserving " + this + " until the new one is " + "added");
1878 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1879 // been removed. We probably need another flag to indicate that window removal
1880 // should be deffered vs. overloading the flag that says we are playing an exit
1881 // animation.
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001882 mAnimatingExit = true;
Peter Visontay3556a3b2017-11-01 17:23:17 +00001883 mReplacingRemoveRequested = true;
1884 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001885 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001886
Peter Visontay3556a3b2017-11-01 17:23:17 +00001887 // If we are not currently running the exit animation, we need to see about starting one
1888 wasVisible = isWinVisibleLw();
1889
1890 if (keepVisibleDeadWindow) {
1891 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1892 "Not removing " + this + " because app died while it's visible");
1893
1894 mAppDied = true;
1895 setDisplayLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001896 mWmService.mWindowPlacerLocked.performSurfacePlacement();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001897
1898 // Set up a replacement input channel since the app is now dead.
1899 // We need to catch tapping on the dead window to restart the app.
1900 openInputChannel(null);
Arthur Hung95b38a92018-07-20 18:56:12 +08001901 getDisplayContent().getInputMonitor().updateInputWindowsLw(true /*force*/);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001902 return;
1903 }
1904
1905 if (wasVisible) {
1906 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
1907
1908 // Try starting an animation.
1909 if (mWinAnimator.applyAnimationLocked(transit, false)) {
1910 mAnimatingExit = true;
Jorim Jaggif41e8822018-04-06 17:22:03 +02001911
1912 // mAnimatingExit affects canAffectSystemUiFlags(). Run layout such that
1913 // any change from that is performed immediately.
1914 setDisplayLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001915 mWmService.requestTraversal();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001916 }
1917 //TODO (multidisplay): Magnification is supported only for the default display.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001918 if (mWmService.mAccessibilityController != null
1919 && displayId == DEFAULT_DISPLAY) {
1920 mWmService.mAccessibilityController.onWindowTransitionLocked(this, transit);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001921 }
1922 }
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001923 final boolean isAnimating = isAnimating()
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001924 && (mAppToken == null || !mAppToken.isWaitingForTransitionStart());
Peter Visontay3556a3b2017-11-01 17:23:17 +00001925 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
1926 && mAppToken.isLastWindow(this);
1927 // We delay the removal of a window if it has a showing surface that can be used to run
1928 // exit animation and it is marked as exiting.
1929 // Also, If isn't the an animating starting window that is the last window in the app.
1930 // We allow the removal of the non-animating starting window now as there is no
1931 // additional window or animation that will trigger its removal.
1932 if (mWinAnimator.getShown() && mAnimatingExit
1933 && (!lastWindowIsStartingWindow || isAnimating)) {
1934 // The exit animation is running or should run... wait for it!
1935 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1936 "Not removing " + this + " due to exit animation ");
1937 setupWindowForRemoveOnExit();
1938 if (mAppToken != null) {
1939 mAppToken.updateReportedVisibilityLocked();
1940 }
1941 return;
1942 }
1943 }
1944
1945 removeImmediately();
1946 // Removing a visible window will effect the computed orientation
1947 // So just update orientation if needed.
Riddle Hsu4e611772018-10-31 18:58:28 +08001948 if (wasVisible) {
1949 final DisplayContent displayContent = getDisplayContent();
1950 if (displayContent.updateOrientationFromAppTokens()) {
1951 displayContent.sendNewConfiguration();
1952 }
Peter Visontay3556a3b2017-11-01 17:23:17 +00001953 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001954 mWmService.updateFocusedWindowLocked(isFocused()
Tiger Huang8af6ba42018-06-07 19:24:09 +08001955 ? UPDATE_FOCUS_REMOVING_FOCUS
1956 : UPDATE_FOCUS_NORMAL,
1957 true /*updateInputWindows*/);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001958 } finally {
1959 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001960 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001961 }
1962
1963 private void setupWindowForRemoveOnExit() {
1964 mRemoveOnExit = true;
1965 setDisplayLayoutNeeded();
1966 // Request a focus update as this window's input channel is already gone. Otherwise
1967 // we could have no focused window in input manager.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001968 final boolean focusChanged = mWmService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001969 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001970 mWmService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001971 if (focusChanged) {
Arthur Hung95b38a92018-07-20 18:56:12 +08001972 getDisplayContent().getInputMonitor().updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001973 }
1974 }
1975
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001976 void setHasSurface(boolean hasSurface) {
1977 mHasSurface = hasSurface;
1978 }
1979
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001980 boolean canBeImeTarget() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08001981 if (mIsImWindow) {
1982 // IME windows can't be IME targets. IME targets are required to be below the IME
1983 // windows and that wouldn't be possible if the IME window is its own target...silly.
1984 return false;
1985 }
1986
Winson Chung3d0a74a2017-07-12 12:37:19 -07001987 final boolean windowsAreFocusable = mAppToken == null || mAppToken.windowsAreFocusable();
Winson Chungb1549342017-07-11 09:59:56 -07001988 if (!windowsAreFocusable) {
1989 // This window can't be an IME target if the app's windows should not be focusable.
1990 return false;
1991 }
1992
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08001993 final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001994 final int type = mAttrs.type;
1995
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08001996 // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are set or
1997 // both are cleared...and not a starting window.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001998 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
1999 && type != TYPE_APPLICATION_STARTING) {
2000 return false;
2001 }
2002
2003 if (DEBUG_INPUT_METHOD) {
2004 Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding());
2005 if (!isVisibleOrAdding()) {
2006 Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController
2007 + " relayoutCalled=" + mRelayoutCalled
2008 + " viewVis=" + mViewVisibility
2009 + " policyVis=" + mPolicyVisibility
2010 + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim
2011 + " parentHidden=" + isParentWindowHidden()
2012 + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
2013 if (mAppToken != null) {
2014 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + mAppToken.hiddenRequested);
2015 }
2016 }
2017 }
2018 return isVisibleOrAdding();
2019 }
2020
Chong Zhangacf11402015-11-04 16:23:10 -08002021 private final class DeadWindowEventReceiver extends InputEventReceiver {
2022 DeadWindowEventReceiver(InputChannel inputChannel) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002023 super(inputChannel, mWmService.mH.getLooper());
Chong Zhangacf11402015-11-04 16:23:10 -08002024 }
2025 @Override
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08002026 public void onInputEvent(InputEvent event) {
Chong Zhangacf11402015-11-04 16:23:10 -08002027 finishInputEvent(event, true);
2028 }
2029 }
2030 /**
2031 * Dummy event receiver for windows that died visible.
2032 */
2033 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2034
Chong Zhang112eb8c2015-11-02 11:17:00 -08002035 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002036 if (mInputChannel != null) {
2037 throw new IllegalStateException("Window already has an input channel.");
2038 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002039 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002040 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2041 mInputChannel = inputChannels[0];
2042 mClientChannel = inputChannels[1];
Robert Carreadae822018-10-11 19:07:03 -07002043 mInputWindowHandle.token = mClient.asBinder();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002044 if (outInputChannel != null) {
2045 mClientChannel.transferTo(outInputChannel);
2046 mClientChannel.dispose();
2047 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002048 } else {
2049 // If the window died visible, we setup a dummy input channel, so that taps
2050 // can still detected by input monitor channel, and we can relaunch the app.
2051 // Create dummy event receiver that simply reports all events as handled.
2052 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002053 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002054 mWmService.mInputManager.registerInputChannel(mInputChannel, mClient.asBinder());
Jeff Browncc4f7db2011-08-30 20:34:48 -07002055 }
2056
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002057 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002058 if (mDeadWindowEventReceiver != null) {
2059 mDeadWindowEventReceiver.dispose();
2060 mDeadWindowEventReceiver = null;
2061 }
2062
2063 // unregister server channel first otherwise it complains about broken channel
2064 if (mInputChannel != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002065 mWmService.mInputManager.unregisterInputChannel(mInputChannel);
Robert Carre0a353c2018-08-02 16:38:04 -07002066
Chong Zhangacf11402015-11-04 16:23:10 -08002067 mInputChannel.dispose();
2068 mInputChannel = null;
2069 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002070 if (mClientChannel != null) {
2071 mClientChannel.dispose();
2072 mClientChannel = null;
2073 }
Robert Carreadae822018-10-11 19:07:03 -07002074 mInputWindowHandle.token = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002075 }
2076
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002077 /** Returns true if the replacement window was removed. */
2078 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2079 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2080 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2081 removeReplacedWindow();
2082 return true;
2083 }
2084
2085 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002086 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002087 if (c.removeReplacedWindowIfNeeded(replacement)) {
2088 return true;
2089 }
2090 }
2091 return false;
2092 }
2093
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002094 private void removeReplacedWindow() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002095 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002096 mWillReplaceWindow = false;
2097 mAnimateReplacingWindow = false;
2098 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002099 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002100 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002101 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002102 }
2103 }
2104
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002105 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2106 boolean replacementSet = false;
2107
2108 if (mWillReplaceWindow && mReplacementWindow == null
2109 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2110
2111 mReplacementWindow = replacementCandidate;
2112 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2113 replacementSet = true;
2114 }
2115
2116 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002117 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002118 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2119 }
2120
2121 return replacementSet;
2122 }
2123
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002124 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002125 final DisplayContent dc = getDisplayContent();
2126 if (dc != null) {
2127 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002128 }
2129 }
2130
Chong Zhang5117e272016-05-03 12:47:34 -07002131 void applyAdjustForImeIfNeeded() {
2132 final Task task = getTask();
2133 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2134 task.mStack.applyAdjustForImeIfNeeded(task);
2135 }
2136 }
2137
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002138 @Override
2139 void switchUser() {
2140 super.switchUser();
2141 if (isHiddenFromUserLocked()) {
2142 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2143 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
2144 hideLw(false);
2145 }
2146 }
2147
Riddle Hsuff03df52018-12-05 21:43:02 +08002148 int getSurfaceTouchableRegion(Region region, int flags) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002149 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002150 if (modal && mAppToken != null) {
2151 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002152 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002153 // If this is a modal window we need to dismiss it if it's not full screen and the
2154 // touch happens outside of the frame that displays the content. This means we
2155 // need to intercept touches outside of that window. The dim layer user
2156 // associated with the window (task or stack) will give us the good bounds, as
2157 // they would be used to display the dim layer.
Robert Carrf59b8dd2017-10-02 18:58:36 -07002158 final Task task = getTask();
2159 if (task != null) {
2160 task.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002161 } else {
Robert Carrf59b8dd2017-10-02 18:58:36 -07002162 getStack().getDimBounds(mTmpRect);
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002163 }
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002164 if (inFreeformWindowingMode()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002165 // For freeform windows we the touch region to include the whole surface for the
2166 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002167 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2168 final int delta = WindowManagerService.dipToPixel(
2169 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2170 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002171 }
2172 region.set(mTmpRect);
Robert Carr679ccb02018-08-08 15:32:35 -07002173 region.translate(-mWindowFrames.mFrame.left, -mWindowFrames.mFrame.top);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002174 } else {
2175 // Not modal or full screen modal
Riddle Hsuff03df52018-12-05 21:43:02 +08002176 getTouchableRegion(region, true /* forSurface */);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002177 }
Robert Carra80ad042018-08-14 12:54:20 -07002178
2179 // The area containing the shadows is not touchable.
2180 region.translate(mAttrs.surfaceInsets.left, mAttrs.surfaceInsets.top);
2181
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002182 return flags;
2183 }
2184
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002185 void checkPolicyVisibilityChange() {
2186 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2187 if (DEBUG_VISIBILITY) {
2188 Slog.v(TAG, "Policy visibility changing after anim in " +
2189 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2190 }
2191 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002192 if (!mPolicyVisibility) {
Jorim Jaggi2e05af22017-12-28 15:15:11 +01002193 mWinAnimator.hide("checkPolicyVisibilityChange");
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002194 if (isFocused()) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002195 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2196 "setAnimationLocked: setting mFocusMayChange true");
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002197 mWmService.mFocusMayChange = true;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002198 }
Tetsutoki Shiozawa64c5f0c2018-05-18 10:55:01 +09002199 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002200 // Window is no longer visible -- make sure if we were waiting
2201 // for it to be displayed before enabling the display, that
2202 // we allow the display to be enabled now.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002203 mWmService.enableScreenIfNeededLocked();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002204 }
2205 }
2206 }
2207
2208 void setRequestedSize(int requestedWidth, int requestedHeight) {
2209 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2210 mLayoutNeeded = true;
2211 mRequestedWidth = requestedWidth;
2212 mRequestedHeight = requestedHeight;
2213 }
2214 }
2215
Bryce Leef858b572017-06-29 14:03:33 -07002216 void prepareWindowToDisplayDuringRelayout(boolean wasVisible) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002217 // We need to turn on screen regardless of visibility.
chaviw40234662018-02-07 09:37:16 -08002218 boolean hasTurnScreenOnFlag = (mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0;
2219 boolean allowTheaterMode =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002220 mWmService.mAllowTheaterModeWakeFromLayout || Settings.Global.getInt(
2221 mWmService.mContext.getContentResolver(), Settings.Global.THEATER_MODE_ON, 0)
chaviw40234662018-02-07 09:37:16 -08002222 == 0;
2223 boolean canTurnScreenOn = mAppToken == null || mAppToken.canTurnScreenOn();
2224
2225 // The screen will turn on if the following conditions are met
2226 // 1. The window has the flag FLAG_TURN_SCREEN_ON
2227 // 2. The WMS allows theater mode.
2228 // 3. No AWT or the AWT allows the screen to be turned on. This should only be true once
2229 // per resume to prevent the screen getting getting turned on for each relayout. Set
2230 // canTurnScreenOn will be set to false so the window doesn't turn the screen on again
2231 // during this resume.
2232 // 4. When the screen is not interactive. This is because when the screen is already
2233 // interactive, the value may persist until the next animation, which could potentially
2234 // be occurring while turning off the screen. This would lead to the screen incorrectly
2235 // turning back on.
chaviw474093d2018-03-07 15:03:38 -08002236 if (hasTurnScreenOnFlag) {
2237 if (allowTheaterMode && canTurnScreenOn && !mPowerManagerWrapper.isInteractive()) {
2238 if (DEBUG_VISIBILITY || DEBUG_POWER) {
2239 Slog.v(TAG, "Relayout window turning screen on: " + this);
2240 }
2241 mPowerManagerWrapper.wakeUp(SystemClock.uptimeMillis(),
2242 "android.server.wm:TURN_ON");
chaviw40234662018-02-07 09:37:16 -08002243 }
chaviwb28de1f2018-03-02 10:42:36 -08002244
2245 if (mAppToken != null) {
2246 mAppToken.setCanTurnScreenOn(false);
2247 }
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002248 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002249
2250 // If we were already visible, skip rest of preparation.
2251 if (wasVisible) {
2252 if (DEBUG_VISIBILITY) Slog.v(TAG,
2253 "Already visible and does not turn on screen, skip preparing: " + this);
2254 return;
2255 }
2256
2257 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2258 == SOFT_INPUT_ADJUST_RESIZE) {
2259 mLayoutNeeded = true;
2260 }
2261
David Stevens9440dc82017-03-16 19:00:20 -07002262 if (isDrawnLw() && mToken.okToAnimate()) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002263 mWinAnimator.applyEnterAnimationLocked();
2264 }
Bryce Leef858b572017-06-29 14:03:33 -07002265 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002266
Yunfan Chen75157d72018-07-27 14:47:21 +09002267 private Configuration getProcessGlobalConfiguration() {
2268 // For child windows we want to use the pid for the parent window in case the the child
2269 // window was added from another process.
Yunfan Chen79b96062018-10-17 12:45:23 -07002270 final int pid = getParentWindow() != null ? getParentWindow().mSession.mPid : mSession.mPid;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002271 mTempConfiguration.setTo(mWmService.mProcessConfigurations.get(
2272 pid, mWmService.mRoot.getConfiguration()));
Yunfan Chen75157d72018-07-27 14:47:21 +09002273 return mTempConfiguration;
2274 }
2275
Bryce Leef858b572017-06-29 14:03:33 -07002276 void getMergedConfiguration(MergedConfiguration outConfiguration) {
Yunfan Chen75157d72018-07-27 14:47:21 +09002277 final Configuration globalConfig = getProcessGlobalConfiguration();
Bryce Leef858b572017-06-29 14:03:33 -07002278 final Configuration overrideConfig = getMergedOverrideConfiguration();
2279 outConfiguration.setConfiguration(globalConfig, overrideConfig);
2280 }
2281
Bryce Lee2b17afd2017-09-21 10:38:20 -07002282 void setLastReportedMergedConfiguration(MergedConfiguration config) {
2283 mLastReportedConfiguration.setTo(config);
2284 }
2285
2286 void getLastReportedMergedConfiguration(MergedConfiguration config) {
2287 config.setTo(mLastReportedConfiguration);
2288 }
2289
2290 private Configuration getLastReportedConfiguration() {
2291 return mLastReportedConfiguration.getMergedConfiguration();
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002292 }
2293
2294 void adjustStartingWindowFlags() {
2295 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2296 && mAppToken.startingWindow != null) {
2297 // Special handling of starting window over the base
2298 // window of the app: propagate lock screen flags to it,
2299 // to provide the correct semantics while starting.
2300 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2301 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2302 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2303 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2304 }
2305 }
2306
2307 void setWindowScale(int requestedWidth, int requestedHeight) {
2308 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2309
2310 if (scaledWindow) {
2311 // requested{Width|Height} Surface's physical size
2312 // attrs.{width|height} Size on screen
2313 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2314 mHScale = (mAttrs.width != requestedWidth) ?
2315 (mAttrs.width / (float)requestedWidth) : 1.0f;
2316 mVScale = (mAttrs.height != requestedHeight) ?
2317 (mAttrs.height / (float)requestedHeight) : 1.0f;
2318 } else {
2319 mHScale = mVScale = 1;
2320 }
2321 }
2322
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002323 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002324 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002325 public void binderDied() {
2326 try {
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002327 boolean resetSplitScreenResizing = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002328 synchronized (mWmService.mGlobalLock) {
2329 final WindowState win = mWmService
2330 .windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002331 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002332 if (win != null) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002333 final DisplayContent dc = getDisplayContent();
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002334 if (win.mAppToken != null && win.mAppToken.findMainWindow() == win) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002335 mWmService.mTaskSnapshotController.onAppDied(win.mAppToken);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002336 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002337 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002338 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2339 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002340 // just in case they have the divider at an unstable position. Better
2341 // also reset drag resizing state, because the owner can't do it
2342 // anymore.
Wale Ogunwale61911492017-10-11 08:50:50 -07002343 final TaskStack stack =
Matthew Ng64e77cf2017-10-31 14:01:31 -07002344 dc.getSplitScreenPrimaryStackIgnoringVisibility();
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002345 if (stack != null) {
2346 stack.resetDockedStackToMiddle();
2347 }
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002348 resetSplitScreenResizing = true;
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002349 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002350 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002351 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002352 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002353 }
2354 }
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002355 if (resetSplitScreenResizing) {
2356 try {
2357 // Note: this calls into ActivityManager, so we must *not* hold the window
2358 // manager lock while calling this.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002359 mWmService.mActivityTaskManager.setSplitScreenResizing(false);
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002360 } catch (RemoteException e) {
2361 // Local call, shouldn't return RemoteException.
2362 throw e.rethrowAsRuntimeException();
2363 }
2364 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002365 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002366 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002367 }
2368 }
2369 }
2370
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002371 /**
2372 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2373 * because we want to preserve its location on screen to be re-activated later when the user
2374 * interacts with it.
2375 */
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002376 private boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwale89973222017-04-23 18:39:45 -07002377 if (!isWinVisibleLw() || mAppToken == null || mAppToken.isClientHidden()) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002378 // Not a visible app window or the app isn't dead.
2379 return false;
2380 }
2381
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002382 if (mAttrs.token != mClient.asBinder()) {
2383 // The window was add by a client using another client's app token. We don't want to
2384 // keep the dead window around for this case since this is meant for 'real' apps.
2385 return false;
2386 }
2387
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002388 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2389 // We don't keep starting windows since they were added by the window manager before
2390 // the app even launched.
2391 return false;
2392 }
2393
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002394 return getWindowConfiguration().keepVisibleDeadAppWindowOnScreen();
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002395 }
2396
Tiger Huang513d5e12018-07-16 21:49:50 +08002397 @Override
2398 public boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002399 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002400 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002401 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002402 && (mAppToken == null || mAppToken.windowsAreFocusable())
Robert Carrebdf8582018-09-04 14:50:15 -07002403 && !cantReceiveTouchInput();
Matthew Nge15352e2016-12-20 15:36:29 -08002404 }
2405
Robert Carrebdf8582018-09-04 14:50:15 -07002406 /** @return false if this window desires touch events. */
2407 boolean cantReceiveTouchInput() {
Bryce Lee6d410262017-02-28 15:30:17 -08002408 return mAppToken != null && mAppToken.getTask() != null
2409 && mAppToken.getTask().mStack.shouldIgnoreInput();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002410 }
2411
Craig Mautner749a7bb2012-04-02 13:49:53 -07002412 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002413 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002414 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002415 }
2416
Craig Mautner749a7bb2012-04-02 13:49:53 -07002417 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002418 public boolean showLw(boolean doAnimation) {
2419 return showLw(doAnimation, true);
2420 }
2421
2422 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002423 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002424 return false;
2425 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002426 if (!mAppOpVisibility) {
2427 // Being hidden due to app op request.
2428 return false;
2429 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002430 if (mPermanentlyHidden) {
2431 // Permanently hidden until the app exists as apps aren't prepared
2432 // to handle their windows being removed from under them.
2433 return false;
2434 }
Suprabh Shukla69c71422018-04-02 18:39:01 -07002435 if (mHiddenWhileSuspended) {
2436 // Being hidden due to owner package being suspended.
2437 return false;
2438 }
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002439 if (mForceHideNonSystemOverlayWindow) {
2440 // This is an alert window that is currently force hidden.
2441 return false;
2442 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002443 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002444 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002445 return false;
2446 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002447 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002448 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002449 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02002450 + mPolicyVisibility + " animating=" + isAnimating());
David Stevens9440dc82017-03-16 19:00:20 -07002451 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002452 doAnimation = false;
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02002453 } else if (mPolicyVisibility && !isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002454 // Check for the case where we are currently visible and
2455 // not animating; we do not want to do animation at such a
2456 // point to become visible when we already are.
2457 doAnimation = false;
2458 }
2459 }
2460 mPolicyVisibility = true;
2461 mPolicyVisibilityAfterAnim = true;
2462 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002463 mWinAnimator.applyAnimationLocked(TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002464 }
2465 if (requestAnim) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002466 mWmService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002467 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002468 if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002469 mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002470 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002471 return true;
2472 }
2473
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002474 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002475 public boolean hideLw(boolean doAnimation) {
2476 return hideLw(doAnimation, true);
2477 }
2478
2479 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2480 if (doAnimation) {
David Stevens9440dc82017-03-16 19:00:20 -07002481 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002482 doAnimation = false;
2483 }
2484 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002485 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002486 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002487 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002488 return false;
2489 }
2490 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002491 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02002492 if (!isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002493 doAnimation = false;
2494 }
2495 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002496 mPolicyVisibilityAfterAnim = false;
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002497 final boolean isFocused = isFocused();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002498 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002499 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002500 mPolicyVisibility = false;
2501 // Window is no longer visible -- make sure if we were waiting
2502 // for it to be displayed before enabling the display, that
2503 // we allow the display to be enabled now.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002504 mWmService.enableScreenIfNeededLocked();
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002505 if (isFocused) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002506 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002507 "WindowState.hideLw: setting mFocusMayChange true");
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002508 mWmService.mFocusMayChange = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002509 }
2510 }
2511 if (requestAnim) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002512 mWmService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002513 }
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002514 if (isFocused) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002515 mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002516 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002517 return true;
2518 }
2519
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002520 void setForceHideNonSystemOverlayWindowIfNeeded(boolean forceHide) {
2521 if (mOwnerCanAddInternalSystemWindow
2522 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2523 return;
2524 }
2525 if (mForceHideNonSystemOverlayWindow == forceHide) {
2526 return;
2527 }
2528 mForceHideNonSystemOverlayWindow = forceHide;
2529 if (forceHide) {
2530 hideLw(true /* doAnimation */, true /* requestAnim */);
2531 } else {
2532 showLw(true /* doAnimation */, true /* requestAnim */);
2533 }
2534 }
2535
Suprabh Shukla69c71422018-04-02 18:39:01 -07002536 void setHiddenWhileSuspended(boolean hide) {
2537 if (mOwnerCanAddInternalSystemWindow
2538 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2539 return;
2540 }
2541 if (mHiddenWhileSuspended == hide) {
2542 return;
2543 }
2544 mHiddenWhileSuspended = hide;
2545 if (hide) {
2546 hideLw(true, true);
2547 } else {
2548 showLw(true, true);
2549 }
2550 }
2551
Svet Ganovf7b47252018-02-26 11:11:27 -08002552 private void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002553 if (mAppOpVisibility != state) {
2554 mAppOpVisibility = state;
2555 if (state) {
2556 // If the policy visibility had last been to hide, then this
2557 // will incorrectly show at this point since we lost that
2558 // information. Not a big deal -- for the windows that have app
2559 // ops modifies they should only be hidden by policy due to the
2560 // lock screen, and the user won't be changing this if locked.
2561 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002562 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002563 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002564 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002565 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002566 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002567 }
2568
Svet Ganovf7b47252018-02-26 11:11:27 -08002569 void initAppOpsState() {
2570 if (mAppOp == OP_NONE || !mAppOpVisibility) {
2571 return;
2572 }
2573 // If the app op was MODE_DEFAULT we would have checked the permission
2574 // and add the window only if the permission was granted. Therefore, if
2575 // the mode is MODE_DEFAULT we want the op to succeed as the window is
2576 // shown.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002577 final int mode = mWmService.mAppOps.startOpNoThrow(mAppOp,
Svet Ganovf7b47252018-02-26 11:11:27 -08002578 getOwningUid(), getOwningPackage(), true);
2579 if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) {
2580 setAppOpVisibilityLw(false);
2581 }
2582 }
2583
2584 void resetAppOpsState() {
2585 if (mAppOp != OP_NONE && mAppOpVisibility) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002586 mWmService.mAppOps.finishOp(mAppOp, getOwningUid(), getOwningPackage());
Svet Ganovf7b47252018-02-26 11:11:27 -08002587 }
2588 }
2589
2590 void updateAppOpsState() {
2591 if (mAppOp == OP_NONE) {
2592 return;
2593 }
2594 final int uid = getOwningUid();
2595 final String packageName = getOwningPackage();
2596 if (mAppOpVisibility) {
2597 // There is a race between the check and the finish calls but this is fine
2598 // as this would mean we will get another change callback and will reconcile.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002599 int mode = mWmService.mAppOps.checkOpNoThrow(mAppOp, uid, packageName);
Svet Ganovf7b47252018-02-26 11:11:27 -08002600 if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002601 mWmService.mAppOps.finishOp(mAppOp, uid, packageName);
Svet Ganovf7b47252018-02-26 11:11:27 -08002602 setAppOpVisibilityLw(false);
2603 }
2604 } else {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002605 final int mode = mWmService.mAppOps.startOpNoThrow(mAppOp, uid, packageName, true);
Svet Ganovf7b47252018-02-26 11:11:27 -08002606 if (mode == MODE_ALLOWED || mode == MODE_DEFAULT) {
2607 setAppOpVisibilityLw(true);
2608 }
2609 }
2610 }
2611
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002612 public void hidePermanentlyLw() {
2613 if (!mPermanentlyHidden) {
2614 mPermanentlyHidden = true;
2615 hideLw(true, true);
2616 }
2617 }
2618
Jeff Brownc2932a12014-11-20 18:04:05 -08002619 public void pokeDrawLockLw(long timeout) {
2620 if (isVisibleOrAdding()) {
2621 if (mDrawLock == null) {
2622 // We want the tag name to be somewhat stable so that it is easier to correlate
2623 // in wake lock statistics. So in particular, we don't want to include the
2624 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002625 final CharSequence tag = getWindowTag();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002626 mDrawLock = mWmService.mPowerManager.newWakeLock(DRAW_WAKE_LOCK, "Window:" + tag);
Jeff Brownc2932a12014-11-20 18:04:05 -08002627 mDrawLock.setReferenceCounted(false);
2628 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2629 }
2630 // Each call to acquire resets the timeout.
2631 if (DEBUG_POWER) {
2632 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2633 + mAttrs.packageName);
2634 }
2635 mDrawLock.acquire(timeout);
2636 } else if (DEBUG_POWER) {
2637 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2638 + "owned by " + mAttrs.packageName);
2639 }
2640 }
2641
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002642 @Override
2643 public boolean isAlive() {
2644 return mClient.asBinder().isBinderAlive();
2645 }
2646
Craig Mautnera987d432012-10-11 14:07:58 -07002647 boolean isClosing() {
chaviw4ad54912018-05-30 11:05:44 -07002648 return mAnimatingExit || (mAppToken != null && mAppToken.isClosingOrEnteringPip());
Craig Mautnera987d432012-10-11 14:07:58 -07002649 }
2650
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002651 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2652 animators.add(mWinAnimator);
2653
2654 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002655 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002656 c.addWinAnimatorToList(animators);
2657 }
2658 }
2659
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002660 void sendAppVisibilityToClients() {
2661 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002662
Wale Ogunwale89973222017-04-23 18:39:45 -07002663 final boolean clientHidden = mAppToken.isClientHidden();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002664 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2665 // Don't hide the starting window.
2666 return;
2667 }
2668
Wale Ogunwale89973222017-04-23 18:39:45 -07002669 if (clientHidden) {
2670 // Once we are notifying the client that it's visibility has changed, we need to prevent
2671 // it from destroying child surfaces until the animation has finished. We do this by
2672 // detaching any surface control the client added from the client.
2673 for (int i = mChildren.size() - 1; i >= 0; --i) {
2674 final WindowState c = mChildren.get(i);
2675 c.mWinAnimator.detachChildren();
2676 }
2677
2678 mWinAnimator.detachChildren();
2679 }
2680
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002681 try {
2682 if (DEBUG_VISIBILITY) Slog.v(TAG,
2683 "Setting visibility of " + this + ": " + (!clientHidden));
2684 mClient.dispatchAppVisibility(!clientHidden);
2685 } catch (RemoteException e) {
2686 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002687 }
2688
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002689 void onStartFreezingScreen() {
2690 mAppFreezing = true;
2691 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002692 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002693 c.onStartFreezingScreen();
2694 }
2695 }
2696
2697 boolean onStopFreezingScreen() {
2698 boolean unfrozeWindows = false;
2699 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002700 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002701 unfrozeWindows |= c.onStopFreezingScreen();
2702 }
2703
2704 if (!mAppFreezing) {
2705 return unfrozeWindows;
2706 }
2707
Wale Ogunwale953171d2016-09-30 09:17:30 -07002708 mAppFreezing = false;
2709
Bryce Lee8c3cf382017-07-06 19:47:10 -07002710 if (mHasSurface && !getOrientationChanging()
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002711 && mWmService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002712 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
Bryce Lee8c3cf382017-07-06 19:47:10 -07002713 setOrientationChanging(true);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002714 mWmService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002715 }
2716 mLastFreezeDuration = 0;
2717 setDisplayLayoutNeeded();
2718 return true;
2719 }
2720
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002721 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2722 boolean destroyedSomething = false;
Jorim Jaggi59f3e922018-01-05 15:40:32 +01002723
2724 // Copying to a different list as multiple children can be removed.
2725 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
2726 for (int i = childWindows.size() - 1; i >= 0; --i) {
2727 final WindowState c = childWindows.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002728 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2729 }
2730
Robert Carrdb2f6e62017-03-01 20:17:58 -08002731 if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) {
2732 return destroyedSomething;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002733 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08002734
2735 if (appStopped || mWindowRemovalAllowed) {
2736 mWinAnimator.destroyPreservedSurfaceLocked();
2737 }
2738
2739 if (mDestroying) {
2740 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2741 + " destroySurfaces: appStopped=" + appStopped
2742 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2743 + " win.mRemoveOnExit=" + mRemoveOnExit);
2744 if (!cleanupOnResume || mRemoveOnExit) {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002745 destroySurfaceUnchecked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08002746 }
2747 if (mRemoveOnExit) {
2748 removeImmediately();
2749 }
2750 if (cleanupOnResume) {
2751 requestUpdateWallpaperIfNeeded();
2752 }
2753 mDestroying = false;
2754 destroyedSomething = true;
2755 }
2756
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002757 return destroyedSomething;
2758 }
Chris Craik3131bde2016-05-06 13:39:08 -07002759
Robert Carr89a28ab2017-04-24 15:33:11 -07002760 // Destroy or save the application surface without checking
2761 // various indicators of whether the client has released the surface.
2762 // This is in general unsafe, and most callers should use {@link #destroySurface}
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002763 void destroySurfaceUnchecked() {
2764 mWinAnimator.destroySurfaceLocked();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002765
Chong Zhang92147042016-05-09 12:47:11 -07002766 // Clear animating flags now, since the surface is now gone. (Note this is true even
2767 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2768 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002769 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002770
Craig Mautner69b08182012-09-05 13:07:13 -07002771 @Override
2772 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002773 final DisplayContent displayContent = getDisplayContent();
2774 if (displayContent == null) {
2775 // Only a window that was on a non-default display can be detached from it.
2776 return false;
2777 }
Winson Chung47a3e652014-05-21 16:03:42 -07002778 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002779 }
2780
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002781 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07002782 mShowToOwnerOnly = showToOwnerOnly;
2783 }
2784
Wale Ogunwaleea92d972016-12-08 07:33:13 -08002785 private boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002786 // Child windows are evaluated based on their parent window.
2787 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002788 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale72919d22016-12-08 18:58:50 -08002789 && win.mAppToken != null && win.mAppToken.mShowForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002790
2791 // All window frames that are fullscreen extend above status bar, but some don't extend
2792 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2793 // bottom right.
chaviw492139a2018-07-16 16:07:35 -07002794 if (win.getFrameLw().left <= win.getDisplayFrameLw().left
2795 && win.getFrameLw().top <= win.getDisplayFrameLw().top
2796 && win.getFrameLw().right >= win.getStableFrameLw().right
2797 && win.getFrameLw().bottom >= win.getStableFrameLw().bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002798 // Is a fullscreen window, like the clock alarm. Show to everyone.
2799 return false;
2800 }
2801 }
2802
Craig Mautner341220f2012-10-16 15:20:09 -07002803 return win.mShowToOwnerOnly
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002804 && !mWmService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002805 }
2806
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002807 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2808 outRegion.set(
2809 frame.left + inset.left, frame.top + inset.top,
2810 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002811 }
2812
Riddle Hsuff03df52018-12-05 21:43:02 +08002813 /** Get the touchable region in global coordinates. */
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002814 void getTouchableRegion(Region outRegion) {
Riddle Hsuff03df52018-12-05 21:43:02 +08002815 getTouchableRegion(outRegion, false /* forSurface */);
2816 }
2817
2818 /** If {@param forSuface} is {@code true}, the region will be translated to surface based. */
2819 private void getTouchableRegion(Region outRegion, boolean forSurface) {
Robert Carra80ad042018-08-14 12:54:20 -07002820 if (inPinnedWindowingMode() && !isFocused()) {
2821 outRegion.setEmpty();
2822 return;
2823 }
2824
chaviw492139a2018-07-16 16:07:35 -07002825 final Rect frame = mWindowFrames.mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002826 switch (mTouchableInsets) {
2827 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002828 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002829 outRegion.set(frame);
2830 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002831 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002832 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002833 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002834 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002835 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002836 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002837 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002838 outRegion.set(mGivenTouchableRegion);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002839 break;
2840 }
2841 }
Riddle Hsuff03df52018-12-05 21:43:02 +08002842
2843 if (forSurface) {
2844 if (mTouchableInsets != TOUCHABLE_INSETS_REGION) {
2845 outRegion.translate(-frame.left, -frame.top);
2846 }
2847 outRegion.getBounds(mTmpRect);
2848 applyInsets(outRegion, mTmpRect, mAttrs.surfaceInsets);
2849 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002850 }
2851
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002852 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002853 final Task task = getTask();
2854 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002855 return;
2856 }
2857
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002858 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002859 if (stack == null) {
2860 return;
2861 }
2862
2863 stack.getDimBounds(mTmpRect);
2864 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002865 }
2866
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002867 /**
2868 * Report a focus change. Must be called with no locks held, and consistently
2869 * from the same serialized thread (such as dispatched from a handler).
2870 */
lumark6f13d20b2018-10-19 14:38:15 +08002871 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode,
2872 boolean reportToClient) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002873 try {
lumark6f13d20b2018-10-19 14:38:15 +08002874 mClient.windowFocusChanged(focused, inTouchMode, reportToClient);
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002875 } catch (RemoteException e) {
2876 }
lumark6f13d20b2018-10-19 14:38:15 +08002877 if (mFocusCallbacks != null && reportToClient) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002878 final int N = mFocusCallbacks.beginBroadcast();
2879 for (int i=0; i<N; i++) {
2880 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2881 try {
2882 if (focused) {
2883 obs.focusGained(mWindowId.asBinder());
2884 } else {
2885 obs.focusLost(mWindowId.asBinder());
2886 }
2887 } catch (RemoteException e) {
2888 }
2889 }
2890 mFocusCallbacks.finishBroadcast();
2891 }
2892 }
2893
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002894 @Override
2895 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002896 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002897 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002898 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002899
Yunfan Chen75157d72018-07-27 14:47:21 +09002900 // We use the process config this window is associated with as the based global config since
2901 // the process can override it config, but isn't part of the window hierarchy.
2902 final Configuration config = getProcessGlobalConfiguration();
2903 config.updateFrom(getMergedOverrideConfiguration());
2904 return config;
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002905 }
2906
Craig Mautnerdf88d732014-01-27 09:21:32 -08002907 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002908 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08002909 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002910 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
chaviw9c81e632018-07-31 11:17:52 -07002911 + ": " + mWindowFrames.mCompatFrame);
Bryce Leef858b572017-06-29 14:03:33 -07002912 final MergedConfiguration mergedConfiguration =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002913 new MergedConfiguration(mWmService.mRoot.getConfiguration(),
Bryce Leef858b572017-06-29 14:03:33 -07002914 getMergedOverrideConfiguration());
2915
Bryce Lee2b17afd2017-09-21 10:38:20 -07002916 setLastReportedMergedConfiguration(mergedConfiguration);
Bryce Leef858b572017-06-29 14:03:33 -07002917
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002918 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002919 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
2920
chaviw492139a2018-07-16 16:07:35 -07002921 final Rect frame = mWindowFrames.mFrame;
chaviw9c81e632018-07-31 11:17:52 -07002922 final Rect overscanInsets = mWindowFrames.mLastOverscanInsets;
2923 final Rect contentInsets = mWindowFrames.mLastContentInsets;
2924 final Rect visibleInsets = mWindowFrames.mLastVisibleInsets;
2925 final Rect stableInsets = mWindowFrames.mLastStableInsets;
2926 final Rect outsets = mWindowFrames.mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002927 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Andrii Kulianb2e37802017-01-11 00:36:44 -08002928 final boolean reportOrientation = mReportOrientationChanged;
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002929 final int displayId = getDisplayId();
chaviwcdba9a42018-07-19 11:36:42 -07002930 final DisplayCutout displayCutout = getWmDisplayCutout().getDisplayCutout();
Chet Haase8eb48d22014-09-24 07:31:29 -07002931 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
2932 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002933 // To prevent deadlock simulate one-way call if win.mClient is a local object.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002934 mWmService.mH.post(new Runnable() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002935 @Override
2936 public void run() {
2937 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002938 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07002939 stableInsets, outsets, reportDraw, mergedConfiguration,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002940 reportOrientation, displayId, displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002941 } catch (RemoteException e) {
2942 // Not a remote call, RemoteException won't be raised.
2943 }
2944 }
2945 });
2946 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002947 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002948 outsets, reportDraw, mergedConfiguration, reportOrientation, displayId,
2949 displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002950 }
Svetoslav4604abc2014-06-10 18:59:30 -07002951
2952 //TODO (multidisplay): Accessibility supported only for the default display.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002953 if (mWmService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
2954 mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07002955 }
2956
chaviw9c81e632018-07-31 11:17:52 -07002957 mWindowFrames.resetInsetsChanged();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002958 mWinAnimator.mSurfaceResized = false;
Andrii Kulianb2e37802017-01-11 00:36:44 -08002959 mReportOrientationChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08002960 } catch (RemoteException e) {
Bryce Lee8c3cf382017-07-06 19:47:10 -07002961 setOrientationChanging(false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002962 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002963 - mWmService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08002964 // We are assuming the hosting process is dead or in a zombie state.
2965 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
2966 + ", removing this window.");
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002967 mWmService.mPendingRemove.add(this);
2968 mWmService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002969 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002970 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002971 }
2972
Jorim Jaggif96c90a2018-09-26 16:55:15 +02002973 /**
2974 * Called when the insets state changed.
2975 */
2976 void notifyInsetsChanged() {
2977 try {
2978 mClient.insetsChanged(
2979 getDisplayContent().getInsetsStateController().getInsetsForDispatch(this));
2980 } catch (RemoteException e) {
2981 Slog.w(TAG, "Failed to deliver inset state change", e);
2982 }
2983 }
2984
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002985 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08002986 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
2987 // start even if we haven't received the relayout window, so that the client requests
2988 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
2989 // until the window to small size, otherwise the multithread renderer will shift last
2990 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
2991 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002992 boolean resizing = isDragResizing() || isDragResizeChanged();
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002993 if (getWindowConfiguration().useWindowFrameForBackdrop() || !resizing) {
Garfield Tanfbd8ea62018-10-16 17:09:49 -07002994 // Surface position is now inherited from parent, and BackdropFrameRenderer uses
2995 // backdrop frame to position content. Thus we just keep the size of backdrop frame, and
2996 // remove the offset to avoid double offset from display origin.
2997 mTmpRect.set(frame);
2998 mTmpRect.offsetTo(0, 0);
2999 return mTmpRect;
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003000 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07003001 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003002 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003003 return mTmpRect;
3004 }
3005
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003006 private int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003007 final TaskStack stack = getStack();
3008 if (stack == null) {
3009 return INVALID_STACK_ID;
3010 }
3011 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003012 }
3013
3014 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
3015 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003016 MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId,
3017 DisplayCutout displayCutout)
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003018 throws RemoteException {
Robert Carr09286c92018-02-15 13:52:31 -08003019 final boolean forceRelayout = isDragResizeChanged() || reportOrientation;
Chong Zhangedaf3052016-04-22 15:04:31 -07003020
Jorim Jaggidc249c42015-12-15 14:57:31 -08003021 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003022 reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout,
Tiger Huang7c610aa2018-10-27 00:01:01 +08003023 getDisplayContent().getDisplayPolicy().isNavBarForcedShownLw(this), displayId,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003024 new DisplayCutout.ParcelableWrapper(displayCutout));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003025 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003026 }
3027
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003028 public void registerFocusObserver(IWindowFocusObserver observer) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003029 synchronized (mWmService.mGlobalLock) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003030 if (mFocusCallbacks == null) {
3031 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
3032 }
3033 mFocusCallbacks.register(observer);
3034 }
3035 }
3036
3037 public void unregisterFocusObserver(IWindowFocusObserver observer) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003038 synchronized (mWmService.mGlobalLock) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003039 if (mFocusCallbacks != null) {
3040 mFocusCallbacks.unregister(observer);
3041 }
3042 }
3043 }
3044
Tiger Huang1e5b10a2018-07-30 20:19:51 +08003045 boolean isFocused() {
3046 return getDisplayContent().mCurrentFocus == this;
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003047 }
3048
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003049 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07003050 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003051 final Task task = getTask();
3052 return task != null && !task.isFullscreen();
3053 }
3054
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003055 /** Is this window in a container that takes up the entire screen space? */
3056 private boolean inFullscreenContainer() {
Bryce Leef3c6a472017-11-14 14:53:06 -08003057 return mAppToken == null || (mAppToken.matchParentBounds() && !isInMultiWindowMode());
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003058 }
3059
Andrii Kulian283acd22017-08-03 04:03:51 -07003060 /** @return true when the window is in fullscreen task, but has non-fullscreen bounds set. */
3061 boolean isLetterboxedAppWindow() {
Adrian Roos865c70f2018-01-10 17:32:27 +01003062 return !isInMultiWindowMode() && mAppToken != null && !mAppToken.matchParentBounds()
3063 || isLetterboxedForDisplayCutoutLw();
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003064 }
3065
Adrian Roos865c70f2018-01-10 17:32:27 +01003066 @Override
3067 public boolean isLetterboxedForDisplayCutoutLw() {
3068 if (mAppToken == null) {
3069 // Only windows with an AppWindowToken are letterboxed.
3070 return false;
3071 }
chaviwcdba9a42018-07-19 11:36:42 -07003072 if (!mWindowFrames.parentFrameWasClippedByDisplayCutout()) {
Adrian Roos5ed644f2018-03-19 17:01:05 +01003073 // Cutout didn't make a difference, no letterbox
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003074 return false;
3075 }
Adrian Roosfa02da62018-01-15 16:01:18 +01003076 if (mAttrs.layoutInDisplayCutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003077 // Layout in cutout, no letterbox.
3078 return false;
3079 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003080 if (!mAttrs.isFullscreen()) {
3081 // Not filling the parent frame, no letterbox
3082 return false;
Adrian Roosfa02da62018-01-15 16:01:18 +01003083 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003084 // Otherwise we need a letterbox if the layout was smaller than the app window token allowed
3085 // it to be.
3086 return !frameCoversEntireAppTokenBounds();
3087 }
3088
3089 /**
3090 * @return true if this window covers the entire bounds of its app window token
3091 * @throws NullPointerException if there is no app window token for this window
3092 */
3093 private boolean frameCoversEntireAppTokenBounds() {
3094 mTmpRect.set(mAppToken.getBounds());
chaviw492139a2018-07-16 16:07:35 -07003095 mTmpRect.intersectUnchecked(mWindowFrames.mFrame);
Adrian Roos5ed644f2018-03-19 17:01:05 +01003096 return mAppToken.getBounds().equals(mTmpRect);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003097 }
3098
Adrian Roos23df3a32018-03-15 15:41:13 +01003099 @Override
3100 public boolean isLetterboxedOverlappingWith(Rect rect) {
3101 return mAppToken != null && mAppToken.isLetterboxOverlappingWith(rect);
3102 }
3103
Chong Zhang3005e752015-09-18 18:46:28 -07003104 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003105 return mDragResizing != computeDragResizing();
3106 }
3107
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003108 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003109 void setWaitingForDrawnIfResizingChanged() {
3110 if (isDragResizeChanged()) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003111 mWmService.mWaitingForDrawn.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003112 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003113 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003114 }
3115
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003116 /**
3117 * @return Whether we reported a drag resize change to the application or not already.
3118 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003119 private boolean isDragResizingChangeReported() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003120 return mDragResizingChangeReported;
3121 }
3122
3123 /**
3124 * Resets the state whether we reported a drag resize change to the app.
3125 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003126 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003127 void resetDragResizingChangeReported() {
3128 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003129 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003130 }
3131
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003132 int getResizeMode() {
3133 return mResizeMode;
3134 }
3135
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003136 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003137 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003138 if (task == null) {
3139 return false;
3140 }
Tomasz Mikolajewskiaf20b8d2017-11-20 16:11:33 +09003141 if (!inSplitScreenWindowingMode() && !inFreeformWindowingMode()) {
Winson Chung2af04b32017-01-24 16:21:13 -08003142 return false;
3143 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003144 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003145 // Floating windows never enter drag resize mode.
3146 return false;
3147 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003148 if (task.isDragResizing()) {
3149 return true;
3150 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003151
3152 // If the bounds are currently frozen, it means that the layout size that the app sees
3153 // and the bounds we clip this window to might be different. In order to avoid holes, we
3154 // simulate that we are still resizing so the app fills the hole with the resizing
3155 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003156 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003157 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003158 !task.inFreeformWindowingMode() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003159
Chong Zhang3005e752015-09-18 18:46:28 -07003160 }
3161
3162 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003163 final boolean resizing = computeDragResizing();
3164 if (resizing == mDragResizing) {
3165 return;
3166 }
3167 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003168 final Task task = getTask();
3169 if (task != null && task.isDragResizing()) {
3170 mResizeMode = task.getDragResizeMode();
3171 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003172 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003173 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3174 : DRAG_RESIZE_MODE_FREEFORM;
3175 }
Chong Zhang3005e752015-09-18 18:46:28 -07003176 }
3177
3178 boolean isDragResizing() {
3179 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003180 }
3181
Robert Carr2487ce72016-04-07 15:18:45 -07003182 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003183 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3184 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003185 }
3186
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07003187 @CallSuper
3188 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02003189 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003190 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02003191 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003192 writeIdentifierToProto(proto, IDENTIFIER);
3193 proto.write(DISPLAY_ID, getDisplayId());
3194 proto.write(STACK_ID, getStackId());
3195 mAttrs.writeToProto(proto, ATTRIBUTES);
3196 mGivenContentInsets.writeToProto(proto, GIVEN_CONTENT_INSETS);
chaviw553b0212018-07-12 13:37:01 -07003197 mWindowFrames.writeToProto(proto, WINDOW_FRAMES);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003198 mAttrs.surfaceInsets.writeToProto(proto, SURFACE_INSETS);
Jorim Jaggi45be1c4c2017-12-15 18:44:43 +01003199 mSurfacePosition.writeToProto(proto, SURFACE_POSITION);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003200 mWinAnimator.writeToProto(proto, ANIMATOR);
3201 proto.write(ANIMATING_EXIT, mAnimatingExit);
3202 for (int i = 0; i < mChildren.size(); i++) {
Adrian Roos4921ccf2017-09-28 16:54:06 +02003203 mChildren.get(i).writeToProto(proto, CHILD_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003204 }
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003205 proto.write(REQUESTED_WIDTH, mRequestedWidth);
3206 proto.write(REQUESTED_HEIGHT, mRequestedHeight);
3207 proto.write(VIEW_VISIBILITY, mViewVisibility);
3208 proto.write(SYSTEM_UI_VISIBILITY, mSystemUiVisibility);
3209 proto.write(HAS_SURFACE, mHasSurface);
3210 proto.write(IS_READY_FOR_DISPLAY, isReadyForDisplay());
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003211 proto.write(REMOVE_ON_EXIT, mRemoveOnExit);
3212 proto.write(DESTROYING, mDestroying);
3213 proto.write(REMOVED, mRemoved);
3214 proto.write(IS_ON_SCREEN, isOnScreen());
3215 proto.write(IS_VISIBLE, isVisible());
Vishnu Nairddd80742018-08-21 14:12:46 -07003216 proto.write(PENDING_SEAMLESS_ROTATION, mPendingSeamlessRotate != null);
3217 proto.write(FINISHED_SEAMLESS_ROTATION_FRAME, mFinishSeamlessRotateFrameNumber);
3218 proto.write(FORCE_SEAMLESS_ROTATION, mForceSeamlesslyRotate);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003219 proto.end(token);
3220 }
3221
Vishnu Nair9a3e4062018-01-11 08:42:54 -08003222 @Override
3223 public void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003224 final long token = proto.start(fieldId);
3225 proto.write(HASH_CODE, System.identityHashCode(this));
3226 proto.write(USER_ID, UserHandle.getUserId(mOwnerUid));
3227 final CharSequence title = getWindowTag();
3228 if (title != null) {
3229 proto.write(TITLE, title.toString());
3230 }
3231 proto.end(token);
3232 }
3233
Jorim Jaggia5e10572017-11-15 14:36:26 +01003234 @Override
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003235 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003236 final TaskStack stack = getStack();
chaviwc65fa582018-08-09 15:33:13 -07003237 pw.print(prefix + "mDisplayId=" + getDisplayId());
3238 if (stack != null) {
3239 pw.print(" stackId=" + stack.mStackId);
3240 }
3241 pw.println(" mSession=" + mSession
3242 + " mClient=" + mClient.asBinder());
3243 pw.println(prefix + "mOwnerUid=" + mOwnerUid
3244 + " mShowToOwnerOnly=" + mShowToOwnerOnly
3245 + " package=" + mAttrs.packageName
3246 + " appop=" + AppOpsManager.opToName(mAppOp));
3247 pw.println(prefix + "mAttrs=" + mAttrs.toString(prefix));
3248 pw.println(prefix + "Requested w=" + mRequestedWidth
3249 + " h=" + mRequestedHeight
3250 + " mLayoutSeq=" + mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003251 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
chaviwc65fa582018-08-09 15:33:13 -07003252 pw.println(prefix + "LastRequested w=" + mLastRequestedWidth
3253 + " h=" + mLastRequestedHeight);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003254 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003255 if (mIsChildWindow || mLayoutAttached) {
chaviwc65fa582018-08-09 15:33:13 -07003256 pw.println(prefix + "mParentWindow=" + getParentWindow()
3257 + " mLayoutAttached=" + mLayoutAttached);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003258 }
3259 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
chaviwc65fa582018-08-09 15:33:13 -07003260 pw.println(prefix + "mIsImWindow=" + mIsImWindow
3261 + " mIsWallpaper=" + mIsWallpaper
3262 + " mIsFloatingLayer=" + mIsFloatingLayer
3263 + " mWallpaperVisible=" + mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003264 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003265 if (dumpAll) {
Jorim Jaggi35d328a2018-08-14 17:00:20 +02003266 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3267 pw.print(" mSubLayer="); pw.print(mSubLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003268 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003269 if (dumpAll) {
chaviwc65fa582018-08-09 15:33:13 -07003270 pw.println(prefix + "mToken=" + mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003271 if (mAppToken != null) {
chaviwc65fa582018-08-09 15:33:13 -07003272 pw.println(prefix + "mAppToken=" + mAppToken);
3273 pw.print(prefix + "mAppDied=" + mAppDied);
3274 pw.print(prefix + "drawnStateEvaluated=" + getDrawnStateEvaluated());
3275 pw.println(prefix + "mightAffectAllDrawn=" + mightAffectAllDrawn());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003276 }
chaviwc65fa582018-08-09 15:33:13 -07003277 pw.println(prefix + "mViewVisibility=0x" + Integer.toHexString(mViewVisibility)
3278 + " mHaveFrame=" + mHaveFrame
3279 + " mObscured=" + mObscured);
3280 pw.println(prefix + "mSeq=" + mSeq
3281 + " mSystemUiVisibility=0x" + Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003282 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003283 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
chaviwc65fa582018-08-09 15:33:13 -07003284 || isParentWindowHidden() || mPermanentlyHidden || mForceHideNonSystemOverlayWindow
Suprabh Shukla69c71422018-04-02 18:39:01 -07003285 || mHiddenWhileSuspended) {
chaviwc65fa582018-08-09 15:33:13 -07003286 pw.println(prefix + "mPolicyVisibility=" + mPolicyVisibility
3287 + " mPolicyVisibilityAfterAnim=" + mPolicyVisibilityAfterAnim
3288 + " mAppOpVisibility=" + mAppOpVisibility
3289 + " parentHidden=" + isParentWindowHidden()
3290 + " mPermanentlyHidden=" + mPermanentlyHidden
3291 + " mHiddenWhileSuspended=" + mHiddenWhileSuspended
3292 + " mForceHideNonSystemOverlayWindow=" + mForceHideNonSystemOverlayWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003293 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003294 if (!mRelayoutCalled || mLayoutNeeded) {
chaviwc65fa582018-08-09 15:33:13 -07003295 pw.println(prefix + "mRelayoutCalled=" + mRelayoutCalled
3296 + " mLayoutNeeded=" + mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003297 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003298 if (dumpAll) {
chaviwc65fa582018-08-09 15:33:13 -07003299 pw.println(prefix + "mGivenContentInsets=" + mGivenContentInsets.toShortString(sTmpSB)
3300 + " mGivenVisibleInsets=" + mGivenVisibleInsets.toShortString(sTmpSB));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003301 if (mTouchableInsets != 0 || mGivenInsetsPending) {
chaviwc65fa582018-08-09 15:33:13 -07003302 pw.println(prefix + "mTouchableInsets=" + mTouchableInsets
3303 + " mGivenInsetsPending=" + mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003304 Region region = new Region();
3305 getTouchableRegion(region);
chaviwc65fa582018-08-09 15:33:13 -07003306 pw.println(prefix + "touchable region=" + region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003307 }
chaviwc65fa582018-08-09 15:33:13 -07003308 pw.println(prefix + "mFullConfiguration=" + getConfiguration());
3309 pw.println(prefix + "mLastReportedConfiguration=" + getLastReportedConfiguration());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003310 }
chaviwc65fa582018-08-09 15:33:13 -07003311 pw.println(prefix + "mHasSurface=" + mHasSurface
3312 + " isReadyForDisplay()=" + isReadyForDisplay()
3313 + " mWindowRemovalAllowed=" + mWindowRemovalAllowed);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003314 if (mEnforceSizeCompat) {
chaviw9c81e632018-07-31 11:17:52 -07003315 pw.println(prefix + "mCompatFrame=" + mWindowFrames.mCompatFrame.toShortString(sTmpSB));
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003316 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003317 if (dumpAll) {
chaviw553b0212018-07-12 13:37:01 -07003318 mWindowFrames.dump(pw, prefix);
chaviw9c81e632018-07-31 11:17:52 -07003319 pw.println(prefix + " surface=" + mAttrs.surfaceInsets.toShortString(sTmpSB));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003320 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01003321 super.dump(pw, prefix, dumpAll);
chaviwc65fa582018-08-09 15:33:13 -07003322 pw.println(prefix + mWinAnimator + ":");
Dianne Hackborn529e7442012-11-01 14:22:28 -07003323 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003324 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
chaviwc65fa582018-08-09 15:33:13 -07003325 pw.println(prefix + "mAnimatingExit=" + mAnimatingExit
3326 + " mRemoveOnExit=" + mRemoveOnExit
3327 + " mDestroying=" + mDestroying
3328 + " mRemoved=" + mRemoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003329 }
chaviw40234662018-02-07 09:37:16 -08003330 if (getOrientationChanging() || mAppFreezing || mReportOrientationChanged) {
chaviwc65fa582018-08-09 15:33:13 -07003331 pw.println(prefix + "mOrientationChanging=" + mOrientationChanging
3332 + " configOrientationChanging="
3333 + (getLastReportedConfiguration().orientation != getConfiguration().orientation)
3334 + " mAppFreezing=" + mAppFreezing
3335 + " mReportOrientationChanged=" + mReportOrientationChanged);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003336 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003337 if (mLastFreezeDuration != 0) {
chaviwc65fa582018-08-09 15:33:13 -07003338 pw.print(prefix + "mLastFreezeDuration=");
3339 TimeUtils.formatDuration(mLastFreezeDuration, pw);
3340 pw.println();
Dianne Hackborna57c6952013-03-29 14:46:40 -07003341 }
chaviwc65fa582018-08-09 15:33:13 -07003342 pw.print(prefix + "mForceSeamlesslyRotate=" + mForceSeamlesslyRotate
3343 + " seamlesslyRotate: pending=");
Vishnu Nairddd80742018-08-21 14:12:46 -07003344 if (mPendingSeamlessRotate != null) {
3345 mPendingSeamlessRotate.dump(pw);
3346 } else {
3347 pw.print("null");
Adrian Roos27a90d22018-07-06 02:39:54 -07003348 }
chaviwc65fa582018-08-09 15:33:13 -07003349 pw.println(" finishedFrameNumber=" + mFinishSeamlessRotateFrameNumber);
Vishnu Nairddd80742018-08-21 14:12:46 -07003350
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003351 if (mHScale != 1 || mVScale != 1) {
chaviwc65fa582018-08-09 15:33:13 -07003352 pw.println(prefix + "mHScale=" + mHScale
3353 + " mVScale=" + mVScale);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003354 }
3355 if (mWallpaperX != -1 || mWallpaperY != -1) {
chaviwc65fa582018-08-09 15:33:13 -07003356 pw.println(prefix + "mWallpaperX=" + mWallpaperX
3357 + " mWallpaperY=" + mWallpaperY);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003358 }
3359 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
chaviwc65fa582018-08-09 15:33:13 -07003360 pw.println(prefix + "mWallpaperXStep=" + mWallpaperXStep
3361 + " mWallpaperYStep=" + mWallpaperYStep);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003362 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003363 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3364 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
chaviwc65fa582018-08-09 15:33:13 -07003365 pw.println(prefix + "mWallpaperDisplayOffsetX=" + mWallpaperDisplayOffsetX
3366 + " mWallpaperDisplayOffsetY=" + mWallpaperDisplayOffsetY);
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003367 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003368 if (mDrawLock != null) {
chaviwc65fa582018-08-09 15:33:13 -07003369 pw.println(prefix + "mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003370 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003371 if (isDragResizing()) {
chaviwc65fa582018-08-09 15:33:13 -07003372 pw.println(prefix + "isDragResizing=" + isDragResizing());
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003373 }
3374 if (computeDragResizing()) {
chaviwc65fa582018-08-09 15:33:13 -07003375 pw.println(prefix + "computeDragResizing=" + computeDragResizing());
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003376 }
chaviwc65fa582018-08-09 15:33:13 -07003377 pw.println(prefix + "isOnScreen=" + isOnScreen());
3378 pw.println(prefix + "isVisible=" + isVisible());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003379 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003380
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003381 @Override
3382 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003383 return Integer.toHexString(System.identityHashCode(this))
Jorim Jaggia5e10572017-11-15 14:36:26 +01003384 + " " + getWindowTag();
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003385 }
3386
Robert Carra1eb4392015-12-10 12:43:51 -08003387 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003388 CharSequence tag = mAttrs.getTitle();
3389 if (tag == null || tag.length() <= 0) {
3390 tag = mAttrs.packageName;
3391 }
3392 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003393 }
3394
3395 @Override
3396 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003397 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003398 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003399 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003400 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003401 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003402 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003403 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003404 }
3405 return mStringNameCache;
3406 }
Robert Carr58f29132015-10-29 14:19:05 -07003407
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003408 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003409 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003410 clipRect.left = (int) (clipRect.left / mHScale);
3411 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003412 }
3413 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003414 clipRect.top = (int) (clipRect.top / mVScale);
3415 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003416 }
3417 }
Robert Carr31e28482015-12-02 16:53:18 -08003418
chaviw9c81e632018-07-31 11:17:52 -07003419 private void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003420 final int pw = containingFrame.width();
3421 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003422 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003423 final boolean inNonFullscreenContainer = !inFullscreenContainer();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003424 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3425
3426 // We need to fit it to the display if either
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003427 // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen
3428 // for the taskless windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003429 // 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 -07003430 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on
3431 // screen, but SurfaceViews want to be always at a specific location so we don't fit it to
3432 // the display.
3433 final boolean fitToDisplay = (task == null || !inNonFullscreenContainer)
Robert Carr6f44db12016-07-21 14:54:43 -07003434 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003435 float x, y;
3436 int w,h;
3437
3438 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3439 if (mAttrs.width < 0) {
3440 w = pw;
3441 } else if (mEnforceSizeCompat) {
3442 w = (int)(mAttrs.width * mGlobalScale + .5f);
3443 } else {
3444 w = mAttrs.width;
3445 }
3446 if (mAttrs.height < 0) {
3447 h = ph;
3448 } else if (mEnforceSizeCompat) {
3449 h = (int)(mAttrs.height * mGlobalScale + .5f);
3450 } else {
3451 h = mAttrs.height;
3452 }
3453 } else {
3454 if (mAttrs.width == MATCH_PARENT) {
3455 w = pw;
3456 } else if (mEnforceSizeCompat) {
3457 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3458 } else {
3459 w = mRequestedWidth;
3460 }
3461 if (mAttrs.height == MATCH_PARENT) {
3462 h = ph;
3463 } else if (mEnforceSizeCompat) {
3464 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3465 } else {
3466 h = mRequestedHeight;
3467 }
3468 }
3469
3470 if (mEnforceSizeCompat) {
3471 x = mAttrs.x * mGlobalScale;
3472 y = mAttrs.y * mGlobalScale;
3473 } else {
3474 x = mAttrs.x;
3475 y = mAttrs.y;
3476 }
3477
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003478 if (inNonFullscreenContainer && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003479 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003480 // required by {@link Gravity#apply} call.
3481 w = Math.min(w, pw);
3482 h = Math.min(h, ph);
3483 }
3484
3485 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003486 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003487 (int) (x + mAttrs.horizontalMargin * pw),
chaviw492139a2018-07-16 16:07:35 -07003488 (int) (y + mAttrs.verticalMargin * ph), mWindowFrames.mFrame);
Robert Carr31e28482015-12-02 16:53:18 -08003489
3490 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003491 if (fitToDisplay) {
chaviw492139a2018-07-16 16:07:35 -07003492 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mWindowFrames.mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003493 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003494
3495 // We need to make sure we update the CompatFrame as it is used for
3496 // cropping decisions, etc, on systems where we lack a decor layer.
chaviw9c81e632018-07-31 11:17:52 -07003497 mWindowFrames.mCompatFrame.set(mWindowFrames.mFrame);
Robert Carr6e18c5e2016-02-29 15:57:13 -08003498 if (mEnforceSizeCompat) {
3499 // See comparable block in computeFrameLw.
chaviw9c81e632018-07-31 11:17:52 -07003500 mWindowFrames.mCompatFrame.scale(mInvGlobalScale);
Robert Carr6e18c5e2016-02-29 15:57:13 -08003501 }
Robert Carr31e28482015-12-02 16:53:18 -08003502 }
Robert Carr51a1b872015-12-08 14:03:13 -08003503
3504 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003505 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003506 }
3507
Robert Carrf3b72c72016-03-21 18:16:39 -07003508 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003509 return mIsChildWindow
3510 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003511 }
3512
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003513 /**
3514 * Returns true if any window added by an application process that if of type
3515 * {@link android.view.WindowManager.LayoutParams#TYPE_TOAST} or that requires that requires
3516 * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when
3517 * this window is visible.
3518 */
3519 boolean hideNonSystemOverlayWindowsWhenVisible() {
Philip P. Moltmann66ce2382018-10-09 13:46:11 -07003520 return (mAttrs.privateFlags & SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != 0
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003521 && mSession.mCanHideNonSystemOverlayWindows;
3522 }
3523
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003524 /** Returns the parent window if this is a child of another window, else null. */
3525 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003526 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3527 // WindowContainer that isn't a WindowState.
3528 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003529 }
3530
3531 /** Returns the topmost parent window if this is a child of another window, else this. */
3532 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003533 WindowState current = this;
3534 WindowState topParent = current;
3535 while (current != null && current.mIsChildWindow) {
3536 current = current.getParentWindow();
3537 // Parent window can be null if the child is detached from it's parent already, but
3538 // someone still has a reference to access it. So, we return the top parent value we
3539 // already have instead of null.
3540 if (current != null) {
3541 topParent = current;
3542 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003543 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003544 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003545 }
3546
Wale Ogunwale9d147902016-07-16 11:58:55 -07003547 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003548 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003549 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003550 }
3551
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003552 void setWillReplaceWindow(boolean animate) {
3553 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003554 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003555 c.setWillReplaceWindow(animate);
3556 }
3557
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003558 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3559 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3560 // We don't set replacing on starting windows since they are added by window manager and
3561 // not the client so won't be replaced by the client.
3562 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003563 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003564
3565 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003566 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003567 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003568 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003569
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003570 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003571 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003572 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003573 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003574
3575 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003576 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003577 c.clearWillReplaceWindow();
3578 }
3579 }
3580
3581 boolean waitingForReplacement() {
3582 if (mWillReplaceWindow) {
3583 return true;
3584 }
3585
3586 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003587 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003588 if (c.waitingForReplacement()) {
3589 return true;
3590 }
3591 }
3592 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003593 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003594
Chong Zhang4d7369a2016-04-25 16:09:14 -07003595 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003596 final DisplayContent dc = getDisplayContent();
3597 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3598 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3599 dc.setLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003600 mWmService.mWindowPlacerLocked.requestTraversal();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003601 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003602
3603 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003604 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003605 c.requestUpdateWallpaperIfNeeded();
3606 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003607 }
3608
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003609 float translateToWindowX(float x) {
chaviw492139a2018-07-16 16:07:35 -07003610 float winX = x - mWindowFrames.mFrame.left;
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003611 if (mEnforceSizeCompat) {
3612 winX *= mGlobalScale;
3613 }
3614 return winX;
3615 }
3616
3617 float translateToWindowY(float y) {
chaviw492139a2018-07-16 16:07:35 -07003618 float winY = y - mWindowFrames.mFrame.top;
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003619 if (mEnforceSizeCompat) {
3620 winY *= mGlobalScale;
3621 }
3622 return winY;
3623 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003624
3625 // During activity relaunch due to resize, we sometimes use window replacement
3626 // for only child windows (as the main window is handled by window preservation)
3627 // and the big surface.
3628 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003629 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3630 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3631 // we also want to replace them at such phases, as they won't be covered by window
3632 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003633 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003634 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003635 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003636 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003637
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003638 void setWillReplaceChildWindows() {
3639 if (shouldBeReplacedWithChildren()) {
3640 setWillReplaceWindow(false /* animate */);
3641 }
3642 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003643 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003644 c.setWillReplaceChildWindows();
3645 }
3646 }
3647
3648 WindowState getReplacingWindow() {
3649 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3650 return this;
3651 }
3652 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003653 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003654 final WindowState replacing = c.getReplacingWindow();
3655 if (replacing != null) {
3656 return replacing;
3657 }
3658 }
3659 return null;
3660 }
3661
Jorim Jaggife762342016-10-13 14:33:27 +02003662 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07003663 public int getRotationAnimationHint() {
3664 if (mAppToken != null) {
3665 return mAppToken.mRotationAnimationHint;
3666 } else {
3667 return -1;
3668 }
3669 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003670
Jorim Jaggife762342016-10-13 14:33:27 +02003671 @Override
3672 public boolean isInputMethodWindow() {
3673 return mIsImWindow;
3674 }
3675
Wale Ogunwale9d147902016-07-16 11:58:55 -07003676 // This must be called while inside a transaction.
3677 boolean performShowLocked() {
3678 if (isHiddenFromUserLocked()) {
3679 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3680 hideLw(false);
3681 return false;
3682 }
3683
3684 logPerformShow("performShow on ");
3685
Jorim Jaggia50da602016-12-29 11:51:42 +01003686 final int drawState = mWinAnimator.mDrawState;
3687 if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW)
3688 && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3689 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3690 }
3691
Jorim Jaggib0d27342016-11-01 16:10:42 -07003692 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003693 return false;
3694 }
3695
3696 logPerformShow("Showing ");
3697
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003698 mWmService.enableScreenIfNeededLocked();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003699 mWinAnimator.applyEnterAnimationLocked();
3700
3701 // Force the show in the next prepareSurfaceLocked() call.
3702 mWinAnimator.mLastAlpha = -1;
Robert Carre13b58e2017-08-31 14:50:44 -07003703 if (DEBUG_ANIM) Slog.v(TAG,
Wale Ogunwale9d147902016-07-16 11:58:55 -07003704 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3705 mWinAnimator.mDrawState = HAS_DRAWN;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003706 mWmService.scheduleAnimationLocked();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003707
3708 if (mHidden) {
3709 mHidden = false;
3710 final DisplayContent displayContent = getDisplayContent();
3711
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003712 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003713 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003714 if (c.mWinAnimator.mSurfaceController != null) {
3715 c.performShowLocked();
3716 // It hadn't been shown, which means layout not performed on it, so now we
3717 // want to make sure to do a layout. If called from within the transaction
3718 // loop, this will cause it to restart with a new layout.
3719 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003720 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003721 }
3722 }
3723 }
3724 }
3725
Wale Ogunwale9d147902016-07-16 11:58:55 -07003726 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003727 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003728 }
3729
3730 return true;
3731 }
3732
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003733 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003734 if (DEBUG_VISIBILITY
Jorim Jaggie4b0f282017-05-17 15:10:29 +02003735 || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003736 Slog.v(TAG, prefix + this
3737 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07003738 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003739 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3740 + " during animation: policyVis=" + mPolicyVisibility
3741 + " parentHidden=" + isParentWindowHidden()
3742 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003743 + (mAppToken != null && mAppToken.hiddenRequested)
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003744 + " tok.hidden=" + (mAppToken != null && mAppToken.isHidden())
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02003745 + " animating=" + isAnimating()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003746 + " tok animating="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003747 + (mAppToken != null && mAppToken.isSelfAnimating())
Wale Ogunwale9d147902016-07-16 11:58:55 -07003748 + " Callers=" + Debug.getCallers(4));
3749 }
3750 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003751
3752 WindowInfo getWindowInfo() {
3753 WindowInfo windowInfo = WindowInfo.obtain();
3754 windowInfo.type = mAttrs.type;
3755 windowInfo.layer = mLayer;
3756 windowInfo.token = mClient.asBinder();
Phil Weaver5dc3ebc2017-08-16 13:04:20 -07003757 if (mAppToken != null) {
3758 windowInfo.activityToken = mAppToken.appToken.asBinder();
3759 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003760 windowInfo.title = mAttrs.accessibilityTitle;
Phil Weaverbb2f28a2017-12-22 09:44:28 -08003761 // Panel windows have no public way to set the a11y title directly. Use the
3762 // regular title as a fallback.
Phil Weaver568cf662018-04-24 17:09:26 -07003763 final boolean isPanelWindow = (mAttrs.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW)
3764 && (mAttrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW);
3765 // Accessibility overlays should have titles that work for accessibility, and can't set
3766 // the a11y title themselves.
3767 final boolean isAccessibilityOverlay =
3768 windowInfo.type == WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
3769 if (TextUtils.isEmpty(windowInfo.title) && (isPanelWindow || isAccessibilityOverlay)) {
Jackal Guo25a33cbd2018-08-01 16:08:45 +08003770 final CharSequence title = mAttrs.getTitle();
3771 windowInfo.title = TextUtils.isEmpty(title) ? null : title;
Phil Weaverbb2f28a2017-12-22 09:44:28 -08003772 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003773 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3774 windowInfo.focused = isFocused();
Phil Weaverf00cd142017-03-03 13:44:00 -08003775 Task task = getTask();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003776 windowInfo.inPictureInPicture = (task != null) && task.inPinnedWindowingMode();
Jackal Guoac2b62e2018-08-22 18:28:46 +08003777 windowInfo.hasFlagWatchOutsideTouch =
3778 (mAttrs.flags & WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH) != 0;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003779
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003780 if (mIsChildWindow) {
3781 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003782 }
3783
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003784 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003785 if (childCount > 0) {
3786 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003787 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003788 }
3789 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003790 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003791 windowInfo.childTokens.add(child.mClient.asBinder());
3792 }
3793 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003794 return windowInfo;
3795 }
3796
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003797 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003798 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003799 if (mChildren.isEmpty()) {
3800 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003801 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003802 }
3803
3804 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003805 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003806 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003807 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003808 }
3809 }
3810
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003811 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003812 // We want to consume the negative sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003813 // below the parent, then this window (the parent), and then the positive sublayer children
3814 // because they need to appear above the parent.
3815 int i = 0;
3816 final int count = mChildren.size();
3817 WindowState child = mChildren.get(i);
3818
3819 while (i < count && child.mSubLayer < 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003820 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003821 return true;
3822 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003823 i++;
3824 if (i >= count) {
3825 break;
3826 }
3827 child = mChildren.get(i);
3828 }
3829
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003830 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003831 return true;
3832 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003833
3834 while (i < count) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003835 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003836 return true;
3837 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003838 i++;
3839 if (i >= count) {
3840 break;
3841 }
3842 child = mChildren.get(i);
3843 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003844
3845 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003846 }
3847
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003848 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003849 // We want to consume the positive sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003850 // above the parent, then this window (the parent), and then the negative sublayer children
3851 // because they need to appear above the parent.
3852 int i = mChildren.size() - 1;
3853 WindowState child = mChildren.get(i);
3854
3855 while (i >= 0 && child.mSubLayer >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003856 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003857 return true;
3858 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003859 --i;
3860 if (i < 0) {
3861 break;
3862 }
3863 child = mChildren.get(i);
3864 }
3865
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003866 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003867 return true;
3868 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003869
3870 while (i >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003871 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003872 return true;
3873 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003874 --i;
3875 if (i < 0) {
3876 break;
3877 }
3878 child = mChildren.get(i);
3879 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003880
3881 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003882 }
3883
Robert Carr9785cf32018-04-25 15:06:07 -07003884 private boolean applyImeWindowsIfNeeded(ToBooleanFunction<WindowState> callback,
3885 boolean traverseTopToBottom) {
3886 // If this window is the current IME target, so we need to process the IME windows
3887 // directly above it. The exception is if we are in split screen
3888 // in which case we process the IME at the DisplayContent level to
3889 // ensure it is above the docked divider.
3890 if (isInputMethodTarget() && !inSplitScreenWindowingMode()) {
3891 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
3892 return true;
3893 }
3894 }
3895 return false;
3896 }
3897
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003898 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
3899 boolean traverseTopToBottom) {
3900 if (traverseTopToBottom) {
Robert Carr9785cf32018-04-25 15:06:07 -07003901 if (applyImeWindowsIfNeeded(callback, traverseTopToBottom)
3902 || callback.apply(this)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003903 return true;
3904 }
3905 } else {
Robert Carr9785cf32018-04-25 15:06:07 -07003906 if (callback.apply(this)
3907 || applyImeWindowsIfNeeded(callback, traverseTopToBottom)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003908 return true;
3909 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003910 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003911 return false;
3912 }
3913
Wale Ogunwaled1880962016-11-08 10:31:59 -08003914 WindowState getWindow(Predicate<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003915 if (mChildren.isEmpty()) {
3916 return callback.test(this) ? this : null;
3917 }
3918
3919 // We want to consume the positive sublayer children first because they need to appear
3920 // above the parent, then this window (the parent), and then the negative sublayer children
3921 // because they need to appear above the parent.
3922 int i = mChildren.size() - 1;
3923 WindowState child = mChildren.get(i);
3924
3925 while (i >= 0 && child.mSubLayer >= 0) {
3926 if (callback.test(child)) {
3927 return child;
3928 }
3929 --i;
3930 if (i < 0) {
3931 break;
3932 }
3933 child = mChildren.get(i);
3934 }
3935
Wale Ogunwaled1880962016-11-08 10:31:59 -08003936 if (callback.test(this)) {
3937 return this;
3938 }
Wale Ogunwale34247952017-02-19 11:57:53 -08003939
3940 while (i >= 0) {
3941 if (callback.test(child)) {
3942 return child;
3943 }
3944 --i;
3945 if (i < 0) {
3946 break;
3947 }
3948 child = mChildren.get(i);
3949 }
3950
3951 return null;
Wale Ogunwaled1880962016-11-08 10:31:59 -08003952 }
3953
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01003954 /**
3955 * @return True if we our one of our ancestors has {@link #mAnimatingExit} set to true, false
3956 * otherwise.
3957 */
3958 @VisibleForTesting
3959 boolean isSelfOrAncestorWindowAnimatingExit() {
3960 WindowState window = this;
3961 do {
3962 if (window.mAnimatingExit) {
3963 return true;
3964 }
3965 window = window.getParentWindow();
3966 } while (window != null);
3967 return false;
3968 }
3969
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003970 void onExitAnimationDone() {
3971 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
3972 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
Jorim Jaggia5e10572017-11-15 14:36:26 +01003973 + " selfAnimating=" + isSelfAnimating());
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003974
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003975 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003976 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +01003977 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003978 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003979 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003980 }
3981 }
3982
3983 if (mWinAnimator.mEnteringAnimation) {
3984 mWinAnimator.mEnteringAnimation = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003985 mWmService.requestTraversal();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003986 // System windows don't have an activity and an app token as a result, but need a way
3987 // to be informed about their entrance animation end.
3988 if (mAppToken == null) {
3989 try {
3990 mClient.dispatchWindowShown();
3991 } catch (RemoteException e) {
3992 }
3993 }
3994 }
3995
Jorim Jaggia5e10572017-11-15 14:36:26 +01003996 if (isSelfAnimating()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003997 return;
3998 }
3999
Jorim Jaggia5e10572017-11-15 14:36:26 +01004000 //TODO (multidisplay): Accessibility is supported only for the default display.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004001 if (mWmService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
4002 mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004003 }
4004
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01004005 if (!isSelfOrAncestorWindowAnimatingExit()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004006 return;
4007 }
4008
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07004009 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004010 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
4011
4012 mDestroying = true;
4013
4014 final boolean hasSurface = mWinAnimator.hasSurface();
Jorim Jaggi50575902018-04-10 17:49:30 +02004015
4016 // Use pendingTransaction here so hide is done the same transaction as the other
4017 // animations when exiting
4018 mWinAnimator.hide(getPendingTransaction(), "onExitAnimationDone");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004019
4020 // If we have an app token, we ask it to destroy the surface for us, so that it can take
4021 // care to ensure the activity has actually stopped and the surface is not still in use.
4022 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
4023 // transaction.
4024 if (mAppToken != null) {
4025 mAppToken.destroySurfaces();
4026 } else {
4027 if (hasSurface) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004028 mWmService.mDestroySurface.add(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004029 }
4030 if (mRemoveOnExit) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004031 mWmService.mPendingRemove.add(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004032 mRemoveOnExit = false;
4033 }
4034 }
4035 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07004036 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004037 }
Dan Willemsen117197f2016-07-30 13:02:59 -07004038
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004039 boolean clearAnimatingFlags() {
4040 boolean didSomething = false;
4041 // We don't want to clear it out for windows that get replaced, because the
4042 // animation depends on the flag to remove the replaced window.
4043 //
4044 // We also don't clear the mAnimatingExit flag for windows which have the
4045 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4046 // by the client. We should let animation proceed and not clear this flag or
4047 // they won't eventually be removed by WindowStateAnimator#finishExit.
4048 if (!mWillReplaceWindow && !mRemoveOnExit) {
4049 // Clear mAnimating flag together with mAnimatingExit. When animation
4050 // changes from exiting to entering, we need to clear this flag until the
4051 // new animation gets applied, so that isAnimationStarting() becomes true
4052 // until then.
4053 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4054 // placement for this window during this period, one or more frame will
4055 // show up with wrong position or scale.
4056 if (mAnimatingExit) {
4057 mAnimatingExit = false;
4058 didSomething = true;
4059 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004060 if (mDestroying) {
4061 mDestroying = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004062 mWmService.mDestroySurface.remove(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004063 didSomething = true;
4064 }
4065 }
4066
4067 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004068 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004069 }
4070
4071 return didSomething;
4072 }
4073
Winson4b4ba902016-07-27 19:45:52 -07004074 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004075 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004076 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004077
4078 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004079 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004080 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004081 c.hideWallpaperWindow(wasDeferred, reason);
4082 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004083 if (!mWinAnimator.mLastHidden || wasDeferred) {
4084 mWinAnimator.hide(reason);
Tiger Huang50d45462018-05-25 22:57:52 +08004085 getDisplayContent().mWallpaperController.mDeferredHideWallpaper = null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004086 dispatchWallpaperVisibility(false);
4087 final DisplayContent displayContent = getDisplayContent();
4088 if (displayContent != null) {
4089 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
Tiger Huang50d45462018-05-25 22:57:52 +08004090 if (DEBUG_LAYOUT_REPEATS) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004091 mWmService.mWindowPlacerLocked.debugLayoutRepeats("hideWallpaperWindow " + this,
Tiger Huang50d45462018-05-25 22:57:52 +08004092 displayContent.pendingLayoutChanges);
4093 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004094 }
4095 }
4096 }
4097
4098 /**
4099 * Check wallpaper window for visibility change and notify window if so.
4100 * @param visible Current visibility.
4101 */
4102 void dispatchWallpaperVisibility(final boolean visible) {
4103 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07004104 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004105
4106 // Only send notification if the visibility actually changed and we are not trying to hide
4107 // the wallpaper when we are deferring hiding of the wallpaper.
4108 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4109 mWallpaperVisible = visible;
4110 try {
4111 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4112 "Updating vis of wallpaper " + this
4113 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4114 mClient.dispatchAppVisibility(visible);
4115 } catch (RemoteException e) {
4116 }
4117 }
4118 }
4119
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004120 boolean hasVisibleNotDrawnWallpaper() {
4121 if (mWallpaperVisible && !isDrawnLw()) {
4122 return true;
4123 }
4124 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004125 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004126 if (c.hasVisibleNotDrawnWallpaper()) {
4127 return true;
4128 }
4129 }
4130 return false;
4131 }
4132
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004133 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4134 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004135 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004136 c.updateReportedVisibility(results);
4137 }
4138
4139 if (mAppFreezing || mViewVisibility != View.VISIBLE
4140 || mAttrs.type == TYPE_APPLICATION_STARTING
4141 || mDestroying) {
4142 return;
4143 }
4144 if (DEBUG_VISIBILITY) {
4145 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02004146 + ", animating=" + isAnimating());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004147 if (!isDrawnLw()) {
4148 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4149 + " pv=" + mPolicyVisibility
4150 + " mDrawState=" + mWinAnimator.mDrawState
4151 + " ph=" + isParentWindowHidden()
4152 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02004153 + " a=" + isAnimating());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004154 }
4155 }
4156
4157 results.numInteresting++;
4158 if (isDrawnLw()) {
4159 results.numDrawn++;
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02004160 if (!isAnimating()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004161 results.numVisible++;
4162 }
4163 results.nowGone = false;
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02004164 } else if (isAnimating()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004165 results.nowGone = false;
4166 }
4167 }
4168
Robert Carr683e05d2018-04-18 15:11:04 -07004169 private boolean skipDecorCrop() {
4170 // The decor frame is used to specify the region not covered by the system
4171 // decorations (nav bar, status bar). In case this is empty, for example with
4172 // FLAG_TRANSLUCENT_NAVIGATION, we don't need to do any cropping.
chaviw553b0212018-07-12 13:37:01 -07004173 if (mWindowFrames.mDecorFrame.isEmpty()) {
Robert Carr683e05d2018-04-18 15:11:04 -07004174 return true;
4175 }
4176
4177 // But if we have a frame, and are an application window, then we must be cropped.
4178 if (mAppToken != null) {
4179 return false;
4180 }
4181
4182 // For non application windows, we may be allowed to extend over the decor bars
4183 // depending on our type and permissions assosciated with our token.
4184 return mToken.canLayerAboveSystemBars();
4185 }
4186
Robert Carrfbbde852016-10-18 11:02:28 -07004187 /**
4188 * Calculate the window crop according to system decor policy. In general this is
4189 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4190 * special cases. This rectangle is in screen space.
4191 */
4192 void calculatePolicyCrop(Rect policyCrop) {
4193 final DisplayContent displayContent = getDisplayContent();
4194 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
4195
4196 if (!isDefaultDisplay()) {
4197 // On a different display there is no system decor. Crop the window
4198 // by the screen boundaries.
4199 // TODO(multi-display)
chaviw9c81e632018-07-31 11:17:52 -07004200 policyCrop.set(0, 0, mWindowFrames.mCompatFrame.width(),
4201 mWindowFrames.mCompatFrame.height());
4202 policyCrop.intersect(-mWindowFrames.mCompatFrame.left, -mWindowFrames.mCompatFrame.top,
4203 displayInfo.logicalWidth - mWindowFrames.mCompatFrame.left,
4204 displayInfo.logicalHeight - mWindowFrames.mCompatFrame.top);
Robert Carr683e05d2018-04-18 15:11:04 -07004205 } else if (skipDecorCrop()) {
Robert Carrfbbde852016-10-18 11:02:28 -07004206 // Windows without policy decor aren't cropped.
chaviw9c81e632018-07-31 11:17:52 -07004207 policyCrop.set(0, 0, mWindowFrames.mCompatFrame.width(),
4208 mWindowFrames.mCompatFrame.height());
Robert Carrfbbde852016-10-18 11:02:28 -07004209 } else {
4210 // Crop to the system decor specified by policy.
4211 calculateSystemDecorRect(policyCrop);
4212 }
4213 }
4214
4215 /**
4216 * The system decor rect is the region of the window which is not covered
4217 * by system decorations.
4218 */
4219 private void calculateSystemDecorRect(Rect systemDecorRect) {
chaviw553b0212018-07-12 13:37:01 -07004220 final Rect decorRect = mWindowFrames.mDecorFrame;
chaviw492139a2018-07-16 16:07:35 -07004221 final int width = mWindowFrames.mFrame.width();
4222 final int height = mWindowFrames.mFrame.height();
Robert Carrfbbde852016-10-18 11:02:28 -07004223
chaviw492139a2018-07-16 16:07:35 -07004224 final int left = mWindowFrames.mFrame.left;
4225 final int top = mWindowFrames.mFrame.top;
Robert Carrfbbde852016-10-18 11:02:28 -07004226
4227 // Initialize the decor rect to the entire frame.
4228 if (isDockedResizing()) {
4229 // If we are resizing with the divider, the task bounds might be smaller than the
4230 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4231 // want in this case in order to avoid holes.
4232 //
4233 // We take care to not shrink the width, for surfaces which are larger than
4234 // the display region. Of course this area will not eventually be visible
4235 // but if we truncate the width now, we will calculate incorrectly
4236 // when adjusting to the stack bounds.
4237 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4238 systemDecorRect.set(0, 0,
4239 Math.max(width, displayInfo.logicalWidth),
4240 Math.max(height, displayInfo.logicalHeight));
4241 } else {
4242 systemDecorRect.set(0, 0, width, height);
4243 }
4244
4245 // If a freeform window is animating from a position where it would be cutoff, it would be
4246 // cutoff during the animation. We don't want that, so for the duration of the animation
4247 // we ignore the decor cropping and depend on layering to position windows correctly.
chaviw95136622018-04-09 15:20:06 -07004248
4249 // We also ignore cropping when the window is currently being drag resized in split screen
4250 // to prevent issues with the crop for screenshot.
4251 final boolean cropToDecor =
4252 !(inFreeformWindowingMode() && isAnimatingLw()) && !isDockedResizing();
Robert Carrfbbde852016-10-18 11:02:28 -07004253 if (cropToDecor) {
4254 // Intersect with the decor rect, offsetted by window position.
4255 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
4256 decorRect.right - left, decorRect.bottom - top);
4257 }
4258
4259 // If size compatibility is being applied to the window, the
4260 // surface is scaled relative to the screen. Also apply this
4261 // scaling to the crop rect. We aren't using the standard rect
4262 // scale function because we want to round things to make the crop
4263 // always round to a larger rect to ensure we don't crop too
4264 // much and hide part of the window that should be seen.
4265 if (mEnforceSizeCompat && mInvGlobalScale != 1.0f) {
4266 final float scale = mInvGlobalScale;
4267 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
4268 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
4269 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
4270 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
4271 }
4272
4273 }
4274
4275 /**
4276 * Expand the given rectangle by this windows surface insets. This
4277 * takes you from the 'window size' to the 'surface size'.
4278 * The surface insets are positive in each direction, so we inset by
4279 * the inverse.
4280 */
4281 void expandForSurfaceInsets(Rect r) {
4282 r.inset(-mAttrs.surfaceInsets.left,
4283 -mAttrs.surfaceInsets.top,
4284 -mAttrs.surfaceInsets.right,
4285 -mAttrs.surfaceInsets.bottom);
4286 }
4287
Robert Carrc91d1c32017-02-15 19:37:46 -08004288 boolean surfaceInsetsChanging() {
4289 return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets);
4290 }
4291
Bryce Leef858b572017-06-29 14:03:33 -07004292 int relayoutVisibleWindow(int result, int attrChanges, int oldVisibility) {
Robert Carrecc06b32017-04-18 14:25:10 -07004293 final boolean wasVisible = isVisibleLw();
4294
4295 result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0;
Robert Carr7b3d11d2018-03-15 14:34:45 -07004296
Robert Carrc91d1c32017-02-15 19:37:46 -08004297 if (mAnimatingExit) {
4298 Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit="
4299 + mRemoveOnExit + ", mDestroying=" + mDestroying);
4300
4301 mWinAnimator.cancelExitAnimationForNextAnimationLocked();
4302 mAnimatingExit = false;
4303 }
4304 if (mDestroying) {
4305 mDestroying = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004306 mWmService.mDestroySurface.remove(this);
Robert Carrc91d1c32017-02-15 19:37:46 -08004307 }
4308 if (oldVisibility == View.GONE) {
4309 mWinAnimator.mEnterAnimationPending = true;
4310 }
4311
Andrii Kulian8ee72852017-03-10 10:36:45 -08004312 mLastVisibleLayoutRotation = getDisplayContent().getRotation();
Robert Carrc91d1c32017-02-15 19:37:46 -08004313
4314 mWinAnimator.mEnteringAnimation = true;
Bryce Leeae73ba42017-05-05 09:58:25 -07004315
Bryce Leef858b572017-06-29 14:03:33 -07004316 prepareWindowToDisplayDuringRelayout(wasVisible);
Bryce Leeae73ba42017-05-05 09:58:25 -07004317
Robert Carrc91d1c32017-02-15 19:37:46 -08004318 if ((attrChanges & FORMAT_CHANGED) != 0) {
4319 // If the format can't be changed in place, preserve the old surface until the app draws
4320 // on the new one. This prevents blinking when we change elevation of freeform and
4321 // pinned windows.
4322 if (!mWinAnimator.tryChangeFormatInPlaceLocked()) {
4323 mWinAnimator.preserveSurfaceLocked();
4324 result |= RELAYOUT_RES_SURFACE_CHANGED
4325 | RELAYOUT_RES_FIRST_TIME;
4326 }
4327 }
4328
4329 // When we change the Surface size, in scenarios which may require changing
4330 // the surface position in sync with the resize, we use a preserved surface
4331 // so we can freeze it while waiting for the client to report draw on the newly
Robert Carrc6d5af52018-02-26 17:46:00 -08004332 // sized surface. At the moment this logic is only in place for switching
4333 // in and out of the big surface for split screen resize.
4334 if (isDragResizeChanged()) {
Robert Carrc91d1c32017-02-15 19:37:46 -08004335 setDragResizing();
Robert Carrc91d1c32017-02-15 19:37:46 -08004336 // We can only change top level windows to the full-screen surface when
4337 // resizing (as we only have one full-screen surface). So there is no need
4338 // to preserve and destroy windows which are attached to another, they
4339 // will keep their surface and its size may change over time.
4340 if (mHasSurface && !isChildWindow()) {
4341 mWinAnimator.preserveSurfaceLocked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08004342 result |= RELAYOUT_RES_SURFACE_CHANGED |
4343 RELAYOUT_RES_FIRST_TIME;
Robert Carrc91d1c32017-02-15 19:37:46 -08004344 }
4345 }
4346 final boolean freeformResizing = isDragResizing()
4347 && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
4348 final boolean dockedResizing = isDragResizing()
4349 && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
4350 result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0;
4351 result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004352 return result;
4353 }
4354
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004355 /**
4356 * @return True if this window has been laid out at least once; false otherwise.
4357 */
4358 boolean isLaidOut() {
4359 return mLayoutSeq != -1;
4360 }
4361
4362 /**
4363 * Updates the last inset values to the current ones.
4364 */
4365 void updateLastInsetValues() {
chaviw9c81e632018-07-31 11:17:52 -07004366 mWindowFrames.updateLastInsetValues();
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004367 }
4368
Jorim Jaggia5e10572017-11-15 14:36:26 +01004369 void startAnimation(Animation anim) {
4370 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
chaviw492139a2018-07-16 16:07:35 -07004371 anim.initialize(mWindowFrames.mFrame.width(), mWindowFrames.mFrame.height(),
Jorim Jaggia5e10572017-11-15 14:36:26 +01004372 displayInfo.appWidth, displayInfo.appHeight);
4373 anim.restrictDuration(MAX_ANIMATION_DURATION);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004374 anim.scaleCurrentDuration(mWmService.getWindowAnimationScaleLocked());
Jorim Jaggia5e10572017-11-15 14:36:26 +01004375 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi2e3c31d2017-11-20 19:49:00 +01004376 new WindowAnimationSpec(anim, mSurfacePosition, false /* canSkipFirstFrame */),
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004377 mWmService.mSurfaceAnimationRunner);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004378 startAnimation(mPendingTransaction, adapter);
4379 commitPendingTransaction();
4380 }
4381
chaviw161ea3e2018-01-31 12:01:12 -08004382 private void startMoveAnimation(int left, int top) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01004383 if (DEBUG_ANIM) Slog.v(TAG, "Setting move animation on " + this);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004384 final Point oldPosition = new Point();
4385 final Point newPosition = new Point();
chaviw492139a2018-07-16 16:07:35 -07004386 transformFrameToSurfacePosition(mWindowFrames.mLastFrame.left, mWindowFrames.mLastFrame.top,
4387 oldPosition);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004388 transformFrameToSurfacePosition(left, top, newPosition);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004389 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004390 new MoveAnimationSpec(oldPosition.x, oldPosition.y, newPosition.x, newPosition.y),
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004391 mWmService.mSurfaceAnimationRunner);
chaviw161ea3e2018-01-31 12:01:12 -08004392 startAnimation(getPendingTransaction(), adapter);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004393 }
4394
4395 private void startAnimation(Transaction t, AnimationAdapter adapter) {
4396 startAnimation(t, adapter, mWinAnimator.mLastHidden);
4397 }
4398
4399 @Override
4400 protected void onAnimationFinished() {
4401 mWinAnimator.onAnimationFinished();
4402 }
4403
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004404 /**
4405 * Retrieves the current transformation matrix of the window, relative to the display.
4406 *
4407 * @param float9 A temporary array of 9 floats.
4408 * @param outMatrix Matrix to fill in the transformation.
4409 */
4410 void getTransformationMatrix(float[] float9, Matrix outMatrix) {
4411 float9[Matrix.MSCALE_X] = mWinAnimator.mDsDx;
4412 float9[Matrix.MSKEW_Y] = mWinAnimator.mDtDx;
4413 float9[Matrix.MSKEW_X] = mWinAnimator.mDtDy;
4414 float9[Matrix.MSCALE_Y] = mWinAnimator.mDsDy;
Robert Carr217e7cc2018-01-31 18:08:39 -08004415 int x = mSurfacePosition.x;
4416 int y = mSurfacePosition.y;
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004417
4418 // If changed, also adjust transformFrameToSurfacePosition
4419 final WindowContainer parent = getParent();
4420 if (isChildWindow()) {
4421 final WindowState parentWindow = getParentWindow();
chaviw492139a2018-07-16 16:07:35 -07004422 x += parentWindow.mWindowFrames.mFrame.left - parentWindow.mAttrs.surfaceInsets.left;
4423 y += parentWindow.mWindowFrames.mFrame.top - parentWindow.mAttrs.surfaceInsets.top;
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004424 } else if (parent != null) {
4425 final Rect parentBounds = parent.getBounds();
4426 x += parentBounds.left;
4427 y += parentBounds.top;
4428 }
4429 float9[Matrix.MTRANS_X] = x;
4430 float9[Matrix.MTRANS_Y] = y;
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004431 float9[Matrix.MPERSP_0] = 0;
4432 float9[Matrix.MPERSP_1] = 0;
4433 float9[Matrix.MPERSP_2] = 1;
4434 outMatrix.setValues(float9);
4435 }
4436
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004437 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4438 // access to its windows children. Need to investigate re-writing
4439 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4440 static final class UpdateReportedVisibilityResults {
4441 int numInteresting;
4442 int numVisible;
4443 int numDrawn;
4444 boolean nowGone = true;
4445
4446 void reset() {
4447 numInteresting = 0;
4448 numVisible = 0;
4449 numDrawn = 0;
4450 nowGone = true;
4451 }
4452 }
Robert Carraf422a82017-04-10 18:34:33 -07004453
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004454 private static final class WindowId extends IWindowId.Stub {
4455 private final WeakReference<WindowState> mOuter;
4456
4457 private WindowId(WindowState outer) {
4458
4459 // Use a weak reference for the outer class. This is important to prevent the following
4460 // leak: Since we send this class to the client process, binder will keep it alive as
4461 // long as the client keeps it alive. Now, if the window is removed, we need to clear
4462 // out our reference so even though this class is kept alive we don't leak WindowState,
4463 // which can keep a whole lot of classes alive.
4464 mOuter = new WeakReference<>(outer);
4465 }
4466
4467 @Override
4468 public void registerFocusObserver(IWindowFocusObserver observer) {
4469 final WindowState outer = mOuter.get();
4470 if (outer != null) {
4471 outer.registerFocusObserver(observer);
4472 }
4473 }
4474 @Override
4475 public void unregisterFocusObserver(IWindowFocusObserver observer) {
4476 final WindowState outer = mOuter.get();
4477 if (outer != null) {
4478 outer.unregisterFocusObserver(observer);
4479 }
4480 }
4481 @Override
4482 public boolean isFocused() {
4483 final WindowState outer = mOuter.get();
Tiger Huang1e5b10a2018-07-30 20:19:51 +08004484 if (outer != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004485 synchronized (outer.mWmService.mGlobalLock) {
Tiger Huang1e5b10a2018-07-30 20:19:51 +08004486 return outer.isFocused();
4487 }
4488 }
4489 return false;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004490 }
4491 }
4492
Robert Carrb1579c82017-09-05 14:54:47 -07004493
4494 @Override
4495 boolean shouldMagnify() {
4496 if (mAttrs.type == TYPE_INPUT_METHOD ||
Robert Carree4d4b92017-11-22 12:21:46 -08004497 mAttrs.type == TYPE_INPUT_METHOD_DIALOG ||
4498 mAttrs.type == TYPE_MAGNIFICATION_OVERLAY ||
4499 mAttrs.type == TYPE_NAVIGATION_BAR ||
4500 // It's tempting to wonder: Have we forgotten the rounded corners overlay?
4501 // worry not: it's a fake TYPE_NAVIGATION_BAR_PANEL
Eugene Susla9552b262018-03-13 12:24:50 -07004502 mAttrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Robert Carrb1579c82017-09-05 14:54:47 -07004503 return false;
4504 }
4505 return true;
4506 }
4507
4508 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004509 SurfaceSession getSession() {
4510 if (mSession.mSurfaceSession != null) {
4511 return mSession.mSurfaceSession;
4512 } else {
4513 return getParent().getSession();
4514 }
4515 }
4516
4517 @Override
4518 boolean needsZBoost() {
lumarkff0ab692018-11-05 20:32:30 +08004519 final WindowState inputMethodTarget = getDisplayContent().mInputMethodTarget;
4520 if (mIsImWindow && inputMethodTarget != null) {
4521 final AppWindowToken appToken = inputMethodTarget.mAppToken;
Jorim Jaggib0fc8172017-11-23 17:04:08 +00004522 if (appToken != null) {
4523 return appToken.needsZBoost();
4524 }
4525 }
4526 return mWillReplaceWindow;
Robert Carrb1579c82017-09-05 14:54:47 -07004527 }
4528
Robert Carrf07ef9e2017-11-21 12:12:49 -08004529 private void applyDims(Dimmer dimmer) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07004530 if (!mAnimatingExit && mAppDied) {
4531 mIsDimming = true;
chaviw2fb06bc2018-01-19 17:09:15 -08004532 dimmer.dimAbove(getPendingTransaction(), this, DEFAULT_DIM_AMOUNT_DEAD_WINDOW);
chaviwebcbc342018-02-07 13:19:00 -08004533 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0 && isVisibleNow() && !mHidden) {
chaviw14076152018-02-02 14:51:20 -08004534 // Only show a dim behind when the following is satisfied:
4535 // 1. The window has the flag FLAG_DIM_BEHIND
4536 // 2. The WindowToken is not hidden so dims aren't shown when the window is exiting.
4537 // 3. The WS is considered visible according to the isVisible() method
chaviwebcbc342018-02-07 13:19:00 -08004538 // 4. The WS is not hidden.
Robert Carrf59b8dd2017-10-02 18:58:36 -07004539 mIsDimming = true;
chaviw2fb06bc2018-01-19 17:09:15 -08004540 dimmer.dimBelow(getPendingTransaction(), this, mAttrs.dimAmount);
Robert Carrf59b8dd2017-10-02 18:58:36 -07004541 }
Robert Carrf07ef9e2017-11-21 12:12:49 -08004542 }
4543
4544 @Override
4545 void prepareSurfaces() {
4546 final Dimmer dimmer = getDimmer();
4547 mIsDimming = false;
4548 if (dimmer != null) {
4549 applyDims(dimmer);
4550 }
chaviw2f0567b2018-01-29 16:22:02 -08004551 updateSurfacePosition();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004552
Robert Carrb1579c82017-09-05 14:54:47 -07004553 mWinAnimator.prepareSurfaceLocked(true);
4554 super.prepareSurfaces();
4555 }
4556
4557 @Override
Jorim Jaggia5e10572017-11-15 14:36:26 +01004558 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
4559 super.onAnimationLeashCreated(t, leash);
4560
4561 // Leash is now responsible for position, so set our position to 0.
4562 t.setPosition(mSurfaceControl, 0, 0);
chaviw3e751af2018-01-11 11:22:39 -08004563 mLastSurfacePosition.set(0, 0);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004564 }
4565
4566 @Override
4567 public void onAnimationLeashDestroyed(Transaction t) {
4568 super.onAnimationLeashDestroyed(t);
4569 updateSurfacePosition(t);
4570 }
4571
chaviwe07246a2017-12-12 16:18:29 -08004572 @Override
chaviw2f0567b2018-01-29 16:22:02 -08004573 void updateSurfacePosition() {
4574 updateSurfacePosition(getPendingTransaction());
4575 }
4576
Vishnu Naird8c664b2018-09-24 12:52:35 -07004577 @VisibleForTesting
4578 void updateSurfacePosition(Transaction t) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01004579 if (mSurfaceControl == null) {
4580 return;
4581 }
4582
chaviw492139a2018-07-16 16:07:35 -07004583 transformFrameToSurfacePosition(mWindowFrames.mFrame.left, mWindowFrames.mFrame.top,
4584 mSurfacePosition);
Robert Carrc6d5af52018-02-26 17:46:00 -08004585
Vishnu Nair83537a72018-07-19 21:27:48 -07004586 // Freeze position while we're unrotated, so the surface remains at the position it was
4587 // prior to the rotation.
Vishnu Nairddd80742018-08-21 14:12:46 -07004588 if (!mSurfaceAnimator.hasLeash() && mPendingSeamlessRotate == null
4589 && !mLastSurfacePosition.equals(mSurfacePosition)) {
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004590 t.setPosition(mSurfaceControl, mSurfacePosition.x, mSurfacePosition.y);
chaviw3e751af2018-01-11 11:22:39 -08004591 mLastSurfacePosition.set(mSurfacePosition.x, mSurfacePosition.y);
Robert Carrc6d5af52018-02-26 17:46:00 -08004592 if (surfaceInsetsChanging() && mWinAnimator.hasSurface()) {
4593 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
4594 t.deferTransactionUntil(mSurfaceControl,
4595 mWinAnimator.mSurfaceController.mSurfaceControl.getHandle(),
chaviwbe43ac82018-04-04 15:14:49 -07004596 getFrameNumber());
Robert Carrc6d5af52018-02-26 17:46:00 -08004597 }
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004598 }
4599 }
4600
4601 private void transformFrameToSurfacePosition(int left, int top, Point outPoint) {
4602 outPoint.set(left, top);
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004603
4604 // If changed, also adjust getTransformationMatrix
chaviwe07246a2017-12-12 16:18:29 -08004605 final WindowContainer parentWindowContainer = getParent();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004606 if (isChildWindow()) {
4607 // TODO: This probably falls apart at some point and we should
4608 // actually compute relative coordinates.
Jorim Jaggi50d3f8f2017-12-27 17:41:25 +01004609
4610 // Since the parent was outset by its surface insets, we need to undo the outsetting
4611 // with insetting by the same amount.
Jorim Jaggia5e10572017-11-15 14:36:26 +01004612 final WindowState parent = getParentWindow();
chaviw492139a2018-07-16 16:07:35 -07004613 outPoint.offset(-parent.mWindowFrames.mFrame.left + parent.mAttrs.surfaceInsets.left,
4614 -parent.mWindowFrames.mFrame.top + parent.mAttrs.surfaceInsets.top);
chaviwe07246a2017-12-12 16:18:29 -08004615 } else if (parentWindowContainer != null) {
4616 final Rect parentBounds = parentWindowContainer.getBounds();
4617 outPoint.offset(-parentBounds.left, -parentBounds.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004618 }
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004619
Robert Carr32bcb102018-01-29 15:03:23 -08004620 TaskStack stack = getStack();
4621
4622 // If we have stack outsets, that means the top-left
4623 // will be outset, and we need to inset ourselves
4624 // to account for it. If we actually have shadows we will
4625 // then un-inset ourselves by the surfaceInsets.
4626 if (stack != null) {
4627 final int outset = stack.getStackOutset();
4628 outPoint.offset(outset, outset);
4629 }
4630
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004631 // Expand for surface insets. See WindowState.expandForSurfaceInsets.
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004632 outPoint.offset(-mAttrs.surfaceInsets.left, -mAttrs.surfaceInsets.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004633 }
4634
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004635 boolean needsRelativeLayeringToIme() {
4636 // We only use the relative layering mode in split screen, as part of elevating the IME
4637 // and windows above it's target above the docked divider.
4638 if (!inSplitScreenWindowingMode()) {
4639 return false;
4640 }
4641
4642 if (isChildWindow()) {
4643 // If we are a child of the input method target we need this promotion.
4644 if (getParentWindow().isInputMethodTarget()) {
4645 return true;
4646 }
4647 } else if (mAppToken != null) {
4648 // Likewise if we share a token with the Input method target and are ordered
4649 // above it but not necessarily a child (e.g. a Dialog) then we also need
4650 // this promotion.
lumarkff0ab692018-11-05 20:32:30 +08004651 final WindowState imeTarget = getDisplayContent().mInputMethodTarget;
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004652 boolean inTokenWithAndAboveImeTarget = imeTarget != null && imeTarget != this
4653 && imeTarget.mToken == mToken && imeTarget.compareTo(this) <= 0;
4654 return inTokenWithAndAboveImeTarget;
4655 }
4656 return false;
4657 }
4658
Jorim Jaggia5e10572017-11-15 14:36:26 +01004659 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004660 void assignLayer(Transaction t, int layer) {
4661 // See comment in assignRelativeLayerForImeTargetChild
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004662 if (needsRelativeLayeringToIme()) {
4663 getDisplayContent().assignRelativeLayerForImeTargetChild(t, this);
Robert Carrb1579c82017-09-05 14:54:47 -07004664 return;
4665 }
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004666 super.assignLayer(t, layer);
Robert Carrb1579c82017-09-05 14:54:47 -07004667 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07004668
4669 @Override
4670 public boolean isDimming() {
4671 return mIsDimming;
4672 }
Robert Carr0eff1872017-12-01 14:27:04 -08004673
4674 // TODO(b/70040778): We should aim to eliminate the last user of TYPE_APPLICATION_MEDIA
4675 // then we can drop all negative layering on the windowing side and simply inherit
4676 // the default implementation here.
4677 public void assignChildLayers(Transaction t) {
4678 int layer = 1;
4679 for (int i = 0; i < mChildren.size(); i++) {
4680 final WindowState w = mChildren.get(i);
4681
4682 // APPLICATION_MEDIA_OVERLAY needs to go above APPLICATION_MEDIA
4683 // while they both need to go below the main window. However the
4684 // relative layering of multiple APPLICATION_MEDIA/OVERLAY has never
4685 // been defined and so we can use static layers and leave it that way.
4686 if (w.mAttrs.type == TYPE_APPLICATION_MEDIA) {
4687 w.assignLayer(t, -2);
4688 } else if (w.mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) {
4689 w.assignLayer(t, -1);
4690 } else {
4691 w.assignLayer(t, layer);
4692 }
4693 w.assignChildLayers(t);
4694 layer++;
4695 }
4696 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01004697
Andrii Kulian4b6599e2018-01-15 17:24:08 -08004698 /**
4699 * Update a tap exclude region with a rectangular area identified by provided id. The requested
4700 * area will be clipped to the window bounds.
4701 */
4702 void updateTapExcludeRegion(int regionId, int left, int top, int width, int height) {
4703 final DisplayContent currentDisplay = getDisplayContent();
4704 if (currentDisplay == null) {
4705 throw new IllegalStateException("Trying to update window not attached to any display.");
4706 }
4707
4708 if (mTapExcludeRegionHolder == null) {
4709 mTapExcludeRegionHolder = new TapExcludeRegionHolder();
4710
4711 // Make sure that this window is registered as one that provides a tap exclude region
4712 // for its containing display.
4713 currentDisplay.mTapExcludeProvidingWindows.add(this);
4714 }
4715
4716 mTapExcludeRegionHolder.updateRegion(regionId, left, top, width, height);
4717 // Trigger touch exclude region update on current display.
Tiger Huang1e5b10a2018-07-30 20:19:51 +08004718 currentDisplay.updateTouchExcludeRegion();
Andrii Kulian4b6599e2018-01-15 17:24:08 -08004719 }
4720
4721 /** Union the region with current tap exclude region that this window provides. */
4722 void amendTapExcludeRegion(Region region) {
4723 mTapExcludeRegionHolder.amendRegion(region, getBounds());
4724 }
4725
Robert Carr825581a2018-03-30 14:00:53 -07004726 @Override
4727 public boolean isInputMethodTarget() {
lumarkff0ab692018-11-05 20:32:30 +08004728 return getDisplayContent().mInputMethodTarget == this;
Robert Carr825581a2018-03-30 14:00:53 -07004729 }
4730
chaviwbe43ac82018-04-04 15:14:49 -07004731 long getFrameNumber() {
4732 return mFrameNumber;
4733 }
4734
4735 void setFrameNumber(long frameNumber) {
4736 mFrameNumber = frameNumber;
4737 }
4738
chaviw553b0212018-07-12 13:37:01 -07004739 public void getMaxVisibleBounds(Rect out) {
4740 if (out.isEmpty()) {
4741 out.set(mWindowFrames.mVisibleFrame);
4742 return;
4743 }
4744
4745 if (mWindowFrames.mVisibleFrame.left < out.left) {
4746 out.left = mWindowFrames.mVisibleFrame.left;
4747 }
4748 if (mWindowFrames.mVisibleFrame.top < out.top) {
4749 out.top = mWindowFrames.mVisibleFrame.top;
4750 }
4751 if (mWindowFrames.mVisibleFrame.right > out.right) {
4752 out.right = mWindowFrames.mVisibleFrame.right;
4753 }
4754 if (mWindowFrames.mVisibleFrame.bottom > out.bottom) {
4755 out.bottom = mWindowFrames.mVisibleFrame.bottom;
4756 }
4757 }
4758
chaviw9c81e632018-07-31 11:17:52 -07004759 /**
4760 * Copy the inset values over so they can be sent back to the client when a relayout occurs.
4761 */
4762 void getInsetsForRelayout(Rect outOverscanInsets, Rect outContentInsets, Rect outVisibleInsets,
4763 Rect outStableInsets, Rect outOutsets) {
4764 outOverscanInsets.set(mWindowFrames.mOverscanInsets);
4765 outContentInsets.set(mWindowFrames.mContentInsets);
4766 outVisibleInsets.set(mWindowFrames.mVisibleInsets);
4767 outStableInsets.set(mWindowFrames.mStableInsets);
4768 outOutsets.set(mWindowFrames.mOutsets);
4769
4770 mLastRelayoutContentInsets.set(mWindowFrames.mContentInsets);
4771 }
4772
4773 void getContentInsets(Rect outContentInsets) {
4774 outContentInsets.set(mWindowFrames.mContentInsets);
4775 }
4776
4777 Rect getContentInsets() {
4778 return mWindowFrames.mContentInsets;
4779 }
4780
4781 void getStableInsets(Rect outStableInsets) {
4782 outStableInsets.set(mWindowFrames.mStableInsets);
4783 }
4784
4785 Rect getStableInsets() {
4786 return mWindowFrames.mStableInsets;
4787 }
4788
4789 void resetLastContentInsets() {
4790 mWindowFrames.resetLastContentInsets();
4791 }
4792
4793 Rect getVisibleInsets() {
4794 return mWindowFrames.mVisibleInsets;
4795 }
4796
chaviw1454b392018-08-06 09:54:04 -07004797 @Override
4798 public WindowFrames getWindowFrames() {
4799 return mWindowFrames;
4800 }
4801
4802 void resetContentChanged() {
4803 mWindowFrames.setContentChanged(false);
4804 }
4805
Jorim Jaggif96c90a2018-09-26 16:55:15 +02004806 void setInsetProvider(InsetsSourceProvider insetProvider) {
4807 mInsetProvider = insetProvider;
4808 }
4809
4810 InsetsSourceProvider getInsetProvider() {
4811 return mInsetProvider;
4812 }
4813
Jorim Jaggia5e10572017-11-15 14:36:26 +01004814 private final class MoveAnimationSpec implements AnimationSpec {
4815
4816 private final long mDuration;
4817 private Interpolator mInterpolator;
4818 private Point mFrom = new Point();
4819 private Point mTo = new Point();
4820
4821 private MoveAnimationSpec(int fromX, int fromY, int toX, int toY) {
4822 final Animation anim = AnimationUtils.loadAnimation(mContext,
4823 com.android.internal.R.anim.window_move_from_decor);
Jorim Jaggi08f75cf2018-01-08 14:38:53 +01004824 mDuration = (long)
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004825 (anim.computeDurationHint() * mWmService.getWindowAnimationScaleLocked());
Jorim Jaggia5e10572017-11-15 14:36:26 +01004826 mInterpolator = anim.getInterpolator();
4827 mFrom.set(fromX, fromY);
4828 mTo.set(toX, toY);
4829 }
4830
4831 @Override
4832 public long getDuration() {
4833 return mDuration;
4834 }
4835
4836 @Override
4837 public void apply(Transaction t, SurfaceControl leash, long currentPlayTime) {
4838 final float fraction = (float) currentPlayTime / getDuration();
4839 final float v = mInterpolator.getInterpolation(fraction);
4840 t.setPosition(leash, mFrom.x + (mTo.x - mFrom.x) * v,
4841 mFrom.y + (mTo.y - mFrom.y) * v);
4842 }
Jorim Jaggif75d1612018-02-27 15:05:21 +01004843
4844 @Override
4845 public void dump(PrintWriter pw, String prefix) {
chaviwc65fa582018-08-09 15:33:13 -07004846 pw.println(prefix + "from=" + mFrom
4847 + " to=" + mTo
4848 + " duration=" + mDuration);
Jorim Jaggif75d1612018-02-27 15:05:21 +01004849 }
4850
4851 @Override
4852 public void writeToProtoInner(ProtoOutputStream proto) {
4853 final long token = proto.start(MOVE);
4854 mFrom.writeToProto(proto, FROM);
4855 mTo.writeToProto(proto, TO);
Kweku Adams21b8d262018-03-30 12:19:58 -07004856 proto.write(DURATION_MS, mDuration);
Jorim Jaggif75d1612018-02-27 15:05:21 +01004857 proto.end(token);
4858 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01004859 }
satokcef37fb2011-10-24 21:49:38 +09004860}