blob: 48cd6b68c4163317edf31185d08c185ea60b2a1c [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;
Michael Wrighte3001042019-02-05 00:13:14 +0000159import android.os.PowerManager.WakeReason;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800160import android.os.RemoteCallbackList;
161import android.os.RemoteException;
162import android.os.SystemClock;
163import android.os.Trace;
164import android.os.UserHandle;
165import android.os.WorkSource;
chaviw40234662018-02-07 09:37:16 -0800166import android.provider.Settings;
Phil Weaverbb2f28a2017-12-22 09:44:28 -0800167import android.text.TextUtils;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800168import android.util.DisplayMetrics;
Jorim Jaggie7d2b852017-08-28 17:55:15 +0200169import android.util.MergedConfiguration;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800170import android.util.Slog;
171import android.util.TimeUtils;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700172import android.util.proto.ProtoOutputStream;
Brad Stenningaf596412018-04-02 12:03:19 -0700173import android.view.Display;
Adrian Roos5c6b6222017-11-07 17:36:10 +0100174import android.view.DisplayCutout;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800175import android.view.DisplayInfo;
176import android.view.Gravity;
177import android.view.IApplicationToken;
178import android.view.IWindow;
179import android.view.IWindowFocusObserver;
180import android.view.IWindowId;
181import android.view.InputChannel;
182import android.view.InputEvent;
183import android.view.InputEventReceiver;
Tiger Huang7c610aa2018-10-27 00:01:01 +0800184import android.view.InputWindowHandle;
Vishnu Nairba183352018-11-21 11:16:49 -0800185import android.view.Surface.Rotation;
Robert Carrb1579c82017-09-05 14:54:47 -0700186import android.view.SurfaceControl;
187import android.view.SurfaceSession;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800188import android.view.View;
189import android.view.ViewTreeObserver;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700190import android.view.WindowInfo;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800191import android.view.WindowManager;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100192import android.view.animation.Animation;
193import android.view.animation.AnimationUtils;
194import android.view.animation.Interpolator;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800195
Jorim Jaggi4876b4a2018-01-11 15:43:49 +0100196import com.android.internal.annotations.VisibleForTesting;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800197import com.android.internal.util.ToBooleanFunction;
Adrian Roose99bc052017-11-20 17:55:31 +0100198import com.android.server.policy.WindowManagerPolicy;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100199import com.android.server.wm.LocalAnimationAdapter.AnimationSpec;
chaviw9c81e632018-07-31 11:17:52 -0700200import com.android.server.wm.utils.InsetUtils;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100201import com.android.server.wm.utils.WmDisplayCutout;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800202
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800203import java.io.PrintWriter;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200204import java.lang.ref.WeakReference;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800205import java.util.ArrayList;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700206import java.util.Comparator;
Wale Ogunwaled1880962016-11-08 10:31:59 -0800207import java.util.function.Predicate;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800208
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700209/** A window in the window manager. */
210class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800211 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800212
Skuhne81c524a2015-08-12 13:34:14 -0700213 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700214 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
215 // use hard-coded min sizes for now.
216 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
217 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700218
219 // The thickness of a window resize handle outside the window bounds on the free form workspace
220 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700221 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700222
Craig Mautnere7ae2502012-03-26 17:11:19 -0700223 final WindowManagerPolicy mPolicy;
224 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800225 final Session mSession;
226 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800227 final int mAppOp;
228 // UserId and appId of the owner. Don't display windows of non-current user.
229 final int mOwnerUid;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800230 /** The owner has {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} */
231 final boolean mOwnerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200232 final WindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800233 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700234 // The same object as mToken if this is an app window and null for non-app windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800235 AppWindowToken mAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700236
237 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
238 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800239 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
240 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700241 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800242 final int mBaseLayer;
243 final int mSubLayer;
244 final boolean mLayoutAttached;
245 final boolean mIsImWindow;
246 final boolean mIsWallpaper;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700247 private final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700248 int mSeq;
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
Riddle Hsub398da32019-01-21 21:48:16 +0800507 private final Rect mTmpRect = new Rect();
508 private final Point mTmpPoint = new Point();
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700509
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800510 /**
511 * Whether the window was resized by us while it was gone for layout.
512 */
513 boolean mResizedWhileGone = false;
514
Robert Carr6da3cc02016-06-16 15:17:07 -0700515 /**
516 * During seamless rotation we have two phases, first the old window contents
517 * are rotated to look as if they didn't move in the new coordinate system. Then we
518 * have to freeze updates to this layer (to preserve the transformation) until
519 * the resize actually occurs. This is true from when the transformation is set
520 * and false until the transaction to resize is sent.
521 */
522 boolean mSeamlesslyRotated = false;
523
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700524 /**
Robert Carrc91d1c32017-02-15 19:37:46 -0800525 * Surface insets from the previous call to relayout(), used to track
526 * if we are changing the Surface insets.
527 */
528 final Rect mLastSurfaceInsets = new Rect();
529
530 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700531 * A flag set by the {@link WindowState} parent to indicate that the parent has examined this
532 * {@link WindowState} in its overall drawing context. This book-keeping allows the parent to
533 * make sure all children have been considered.
534 */
535 private boolean mDrawnStateEvaluated;
536
Jorim Jaggia5e10572017-11-15 14:36:26 +0100537 private final Point mSurfacePosition = new Point();
538
Bryce Leed390deb2017-06-22 13:14:28 -0700539 /**
Tiger Huang04dc4cc2019-01-17 18:41:41 +0800540 * A region inside of this window to be excluded from touch.
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800541 */
542 private TapExcludeRegionHolder mTapExcludeRegionHolder;
543
544 /**
chaviw40234662018-02-07 09:37:16 -0800545 * Used for testing because the real PowerManager is final.
546 */
547 private PowerManagerWrapper mPowerManagerWrapper;
548
549 /**
chaviwbe43ac82018-04-04 15:14:49 -0700550 * A frame number in which changes requested in this layout will be rendered.
551 */
552 private long mFrameNumber = -1;
553
chaviwc65fa582018-08-09 15:33:13 -0700554 private static final StringBuilder sTmpSB = new StringBuilder();
555
chaviwbe43ac82018-04-04 15:14:49 -0700556 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700557 * 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 -0700558 * of z-order and 1 otherwise.
559 */
Griff Hazen51d00d82016-11-22 15:39:24 -0800560 private static final Comparator<WindowState> sWindowSubLayerComparator =
561 new Comparator<WindowState>() {
562 @Override
563 public int compare(WindowState w1, WindowState w2) {
564 final int layer1 = w1.mSubLayer;
565 final int layer2 = w2.mSubLayer;
566 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
567 // We insert the child window into the list ordered by
568 // the sub-layer. For same sub-layers, the negative one
569 // should go below others; the positive one should go
570 // above others.
571 return -1;
572 }
573 return 1;
574 };
575 };
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700576
Robert Carrf59b8dd2017-10-02 18:58:36 -0700577 /**
578 * Indicates whether we have requested a Dim (in the sense of {@link Dimmer}) from our host
579 * container.
580 */
581 private boolean mIsDimming = false;
582
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200583 private @Nullable InsetsSourceProvider mInsetProvider;
584
Robert Carrf59b8dd2017-10-02 18:58:36 -0700585 private static final float DEFAULT_DIM_AMOUNT_DEAD_WINDOW = 0.5f;
586
Vishnu Nairba183352018-11-21 11:16:49 -0800587 void seamlesslyRotateIfAllowed(Transaction transaction, @Rotation int oldRotation,
588 @Rotation int rotation, boolean requested) {
Vishnu Nairddd80742018-08-21 14:12:46 -0700589 // Invisible windows and the wallpaper do not participate in the seamless rotation animation
590 if (!isVisibleNow() || mIsWallpaper) {
591 return;
592 }
Adrian Roosfaa102f2018-08-02 15:56:15 +0200593
Vishnu Nairddd80742018-08-21 14:12:46 -0700594 if (mPendingSeamlessRotate != null) {
595 oldRotation = mPendingSeamlessRotate.getOldRotation();
596 }
597
598 if (mForceSeamlesslyRotate || requested) {
599 mPendingSeamlessRotate = new SeamlessRotator(oldRotation, rotation, getDisplayInfo());
Vishnu Nairec634062018-09-20 20:16:18 -0700600 mPendingSeamlessRotate.unrotate(transaction, this);
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800601 mWmService.markForSeamlessRotation(this, true);
Vishnu Nairddd80742018-08-21 14:12:46 -0700602 }
603 }
604
Vishnu Nairba183352018-11-21 11:16:49 -0800605 void finishSeamlessRotation(boolean timeout) {
Vishnu Nairddd80742018-08-21 14:12:46 -0700606 if (mPendingSeamlessRotate != null) {
Vishnu Nairba183352018-11-21 11:16:49 -0800607 mPendingSeamlessRotate.finish(this, timeout);
Vishnu Nairddd80742018-08-21 14:12:46 -0700608 mFinishSeamlessRotateFrameNumber = getFrameNumber();
609 mPendingSeamlessRotate = null;
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800610 mWmService.markForSeamlessRotation(this, false);
Vishnu Nair83537a72018-07-19 21:27:48 -0700611 }
612 }
613
chaviw40234662018-02-07 09:37:16 -0800614 interface PowerManagerWrapper {
Michael Wrighte3001042019-02-05 00:13:14 +0000615 void wakeUp(long time, @WakeReason int reason, String details);
chaviw40234662018-02-07 09:37:16 -0800616
617 boolean isInteractive();
618
619 }
620
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800621 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
chaviw40234662018-02-07 09:37:16 -0800622 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
623 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow) {
624 this(service, s, c, token, parentWindow, appOp, seq, a, viewVisibility, ownerId,
625 ownerCanAddInternalSystemWindow, new PowerManagerWrapper() {
626 @Override
Michael Wrighte3001042019-02-05 00:13:14 +0000627 public void wakeUp(long time, @WakeReason int reason, String details) {
628 service.mPowerManager.wakeUp(time, reason, details);
chaviw40234662018-02-07 09:37:16 -0800629 }
630
631 @Override
632 public boolean isInteractive() {
633 return service.mPowerManager.isInteractive();
634 }
635 });
636 }
637
638 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
639 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
640 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow,
641 PowerManagerWrapper powerManagerWrapper) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100642 super(service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800643 mSession = s;
644 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800645 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800646 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700647 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700648 mOwnerUid = ownerId;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800649 mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200650 mWindowId = new WindowId(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800651 mAttrs.copyFrom(a);
Robert Carrb08ed042018-03-12 15:49:08 -0700652 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800653 mViewVisibility = viewVisibility;
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800654 mPolicy = mWmService.mPolicy;
655 mContext = mWmService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800656 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700657 mSeq = seq;
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 /**
Riddle Hsub398da32019-01-21 21:48:16 +0800735 * @return {@code true} if the application runs in size compatibility mode.
736 * @see android.content.res.CompatibilityInfo#supportsScreen
737 * @see ActivityRecord#inSizeCompatMode
738 */
739 boolean inSizeCompatMode() {
740 return (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0
741 || (mAppToken != null && mAppToken.inSizeCompatMode()
742 // Exclude starting window because it is not displayed by the application.
743 && mAttrs.type != TYPE_APPLICATION_STARTING);
744 }
745
746 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700747 * Returns whether this {@link WindowState} has been considered for drawing by its parent.
748 */
Bryce Lee6311c4b2017-07-06 14:09:29 -0700749 boolean getDrawnStateEvaluated() {
Bryce Leed390deb2017-06-22 13:14:28 -0700750 return mDrawnStateEvaluated;
751 }
752
753 /**
754 * Sets whether this {@link WindowState} has been considered for drawing by its parent. Should
755 * be cleared when detached from parent.
756 */
757 void setDrawnStateEvaluated(boolean evaluated) {
758 mDrawnStateEvaluated = evaluated;
759 }
760
761 @Override
Riddle Hsu3a4bb612019-01-31 00:02:22 +0800762 void onParentChanged() {
763 super.onParentChanged();
Bryce Leed390deb2017-06-22 13:14:28 -0700764 setDrawnStateEvaluated(false /*evaluated*/);
Robert Carr24be9ab2018-04-30 17:54:53 -0700765
766 getDisplayContent().reapplyMagnificationSpec();
Bryce Leed390deb2017-06-22 13:14:28 -0700767 }
768
Craig Mautnera2c77052012-03-26 12:14:43 -0700769 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800770 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800771 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800772 }
773
774 @Override
775 public String getOwningPackage() {
776 return mAttrs.packageName;
777 }
778
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800779 @Override
780 public boolean canAddInternalSystemWindow() {
781 return mOwnerCanAddInternalSystemWindow;
782 }
783
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200784 @Override
785 public boolean canAcquireSleepToken() {
786 return mSession.mCanAcquireSleepToken;
787 }
788
Jorim Jaggif5834272016-04-04 20:25:41 -0700789 /**
790 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
791 * from {@param frame}. In other words, it applies the insets that would result if
792 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700793 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
794 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700795 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700796 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
797 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
798 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
799 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
800 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700801 frame.inset(left, top, right, bottom);
802 }
803
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800804 @Override
Evan Roskyed6767f2018-10-26 17:21:06 -0700805 public Rect getDisplayedBounds() {
806 final Task task = getTask();
807 if (task != null) {
808 Rect bounds = task.getOverrideDisplayedBounds();
809 if (!bounds.isEmpty()) {
810 return bounds;
811 }
812 }
813 return super.getDisplayedBounds();
814 }
815
816 @Override
chaviw1454b392018-08-06 09:54:04 -0700817 public void computeFrameLw() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800818 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700819 // This window is being replaced and either already got information that it's being
820 // removed or we are still waiting for some information. Because of this we don't
821 // want to apply any more changes to it, so it remains in this state until new window
822 // appears.
823 return;
824 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800825 mHaveFrame = true;
826
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700827 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700828 final boolean inFullscreenContainer = inFullscreenContainer();
Robert Carre6275582016-02-29 15:45:45 -0800829 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700830 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800831
Evan Roskyed6767f2018-10-26 17:21:06 -0700832 mInsetFrame.set(getBounds());
Chong Zhangae35fef2016-03-16 15:56:55 -0700833
Jorim Jaggif5834272016-04-04 20:25:41 -0700834 // Denotes the actual frame used to calculate the insets and to perform the layout. When
835 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
836 // insets temporarily. By the notion of a task having a different layout frame, we can
837 // achieve that while still moving the task around.
838 final Rect layoutContainingFrame;
839 final Rect layoutDisplayFrame;
840
841 // The offset from the layout containing frame to the actual containing frame.
842 final int layoutXDiff;
843 final int layoutYDiff;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700844 if (inFullscreenContainer || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800845 // We use the parent frame as the containing frame for fullscreen and child windows
chaviw1454b392018-08-06 09:54:04 -0700846 mWindowFrames.mContainingFrame.set(mWindowFrames.mParentFrame);
847 layoutDisplayFrame = mWindowFrames.mDisplayFrame;
848 layoutContainingFrame = mWindowFrames.mParentFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700849 layoutXDiff = 0;
850 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800851 } else {
Evan Roskyed6767f2018-10-26 17:21:06 -0700852 mWindowFrames.mContainingFrame.set(getDisplayedBounds());
Jorim Jaggi0429f352015-12-22 16:29:16 +0100853 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
854
855 // If the bounds are frozen, we still want to translate the window freely and only
856 // freeze the size.
857 Rect frozen = mAppToken.mFrozenBounds.peek();
chaviw553b0212018-07-12 13:37:01 -0700858 mWindowFrames.mContainingFrame.right =
859 mWindowFrames.mContainingFrame.left + frozen.width();
860 mWindowFrames.mContainingFrame.bottom =
861 mWindowFrames.mContainingFrame.top + frozen.height();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100862 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800863 final WindowState imeWin = mWmService.mRoot.getCurrentInputMethodWindow();
Robert Carrfc03b2b2016-03-31 15:22:02 -0700864 // IME is up and obscuring this window. Adjust the window position so it is visible.
Robert Carr825581a2018-03-30 14:00:53 -0700865 if (imeWin != null && imeWin.isVisibleNow() && isInputMethodTarget()) {
chaviw553b0212018-07-12 13:37:01 -0700866 if (inFreeformWindowingMode() && mWindowFrames.mContainingFrame.bottom
chaviw1454b392018-08-06 09:54:04 -0700867 > mWindowFrames.mContentFrame.bottom) {
Winson Chungd73e94b2017-05-31 16:25:30 -0700868 // In freeform we want to move the top up directly.
869 // TODO: Investigate why this is contentFrame not parentFrame.
chaviw553b0212018-07-12 13:37:01 -0700870 mWindowFrames.mContainingFrame.top -= mWindowFrames.mContainingFrame.bottom
chaviw1454b392018-08-06 09:54:04 -0700871 - mWindowFrames.mContentFrame.bottom;
chaviw553b0212018-07-12 13:37:01 -0700872 } else if (!inPinnedWindowingMode() && mWindowFrames.mContainingFrame.bottom
chaviw1454b392018-08-06 09:54:04 -0700873 > mWindowFrames.mParentFrame.bottom) {
Winson Chungd73e94b2017-05-31 16:25:30 -0700874 // But in docked we want to behave like fullscreen and behave as if the task
875 // were given smaller bounds for the purposes of layout. Skip adjustments for
876 // the pinned stack, they are handled separately in the PinnedStackController.
chaviw1454b392018-08-06 09:54:04 -0700877 mWindowFrames.mContainingFrame.bottom = mWindowFrames.mParentFrame.bottom;
Winson Chungd73e94b2017-05-31 16:25:30 -0700878 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700879 }
Skuhne81c524a2015-08-12 13:34:14 -0700880
Robert Carre6275582016-02-29 15:45:45 -0800881 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700882 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
883 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800884 // "content frame" since it is allowed to be outside the visible desktop.
chaviw553b0212018-07-12 13:37:01 -0700885 if (mWindowFrames.mContainingFrame.isEmpty()) {
chaviw1454b392018-08-06 09:54:04 -0700886 mWindowFrames.mContainingFrame.set(mWindowFrames.mContentFrame);
Skuhne81c524a2015-08-12 13:34:14 -0700887 }
Doris Liu06d582d2015-06-01 13:18:43 -0700888 }
Adrian Roos604ef952018-05-15 20:13:13 +0200889
890 final TaskStack stack = getStack();
891 if (inPinnedWindowingMode() && stack != null
892 && stack.lastAnimatingBoundsWasToFullscreen()) {
893 // PIP edge case: When going from pinned to fullscreen, we apply a
894 // tempInsetFrame for the full task - but we're still at the start of the animation.
895 // To prevent a jump if there's a letterbox, restrict to the parent frame.
chaviw1454b392018-08-06 09:54:04 -0700896 mInsetFrame.intersectUnchecked(mWindowFrames.mParentFrame);
897 mWindowFrames.mContainingFrame.intersectUnchecked(mWindowFrames.mParentFrame);
Adrian Roos604ef952018-05-15 20:13:13 +0200898 }
899
chaviw1454b392018-08-06 09:54:04 -0700900 layoutDisplayFrame = new Rect(mWindowFrames.mDisplayFrame);
chaviw553b0212018-07-12 13:37:01 -0700901 mWindowFrames.mDisplayFrame.set(mWindowFrames.mContainingFrame);
Evan Roskyed6767f2018-10-26 17:21:06 -0700902 layoutXDiff = mInsetFrame.left - mWindowFrames.mContainingFrame.left;
903 layoutYDiff = mInsetFrame.top - mWindowFrames.mContainingFrame.top;
904 layoutContainingFrame = mInsetFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700905 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
chaviw1454b392018-08-06 09:54:04 -0700906 subtractInsets(mWindowFrames.mDisplayFrame, layoutContainingFrame, layoutDisplayFrame,
907 mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700908 if (!layoutInParentFrame()) {
chaviw553b0212018-07-12 13:37:01 -0700909 subtractInsets(mWindowFrames.mContainingFrame, layoutContainingFrame,
chaviw1454b392018-08-06 09:54:04 -0700910 mWindowFrames.mParentFrame, mTmpRect);
911 subtractInsets(mInsetFrame, layoutContainingFrame, mWindowFrames.mParentFrame,
chaviw553b0212018-07-12 13:37:01 -0700912 mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700913 }
Jorim Jaggif5834272016-04-04 20:25:41 -0700914 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700915 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800916
chaviw553b0212018-07-12 13:37:01 -0700917 final int pw = mWindowFrames.mContainingFrame.width();
918 final int ph = mWindowFrames.mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800919
Dianne Hackborn1743b642012-03-12 17:04:43 -0700920 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
921 mLastRequestedWidth = mRequestedWidth;
922 mLastRequestedHeight = mRequestedHeight;
chaviw1454b392018-08-06 09:54:04 -0700923 mWindowFrames.setContentChanged(true);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700924 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800925
chaviw492139a2018-07-16 16:07:35 -0700926 final int fw = mWindowFrames.mFrame.width();
927 final int fh = mWindowFrames.mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800928
Jorim Jaggif5834272016-04-04 20:25:41 -0700929 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
930
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700931 // Calculate the outsets before the content frame gets shrinked to the window frame.
chaviw1454b392018-08-06 09:54:04 -0700932 mWindowFrames.calculateOutsets();
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700933
Craig Mautnera248eee2013-05-07 11:41:27 -0700934 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800935 // final window frame.
chaviw492139a2018-07-16 16:07:35 -0700936 if (windowsAreFloating && !mWindowFrames.mFrame.isEmpty()) {
Robert Carre65a1c42017-02-28 16:52:59 -0800937 // For pinned workspace the frame isn't limited in any particular
938 // way since SystemUI controls the bounds. For freeform however
939 // we want to keep things inside the content frame.
chaviw492139a2018-07-16 16:07:35 -0700940 final Rect limitFrame = task.inPinnedWindowingMode() ? mWindowFrames.mFrame
941 : mWindowFrames.mContentFrame;
Skuhne81c524a2015-08-12 13:34:14 -0700942 // Keep the frame out of the blocked system area, limit it in size to the content area
943 // and make sure that there is always a minimum visible so that the user can drag it
944 // into a usable area..
chaviw492139a2018-07-16 16:07:35 -0700945 final int height = Math.min(mWindowFrames.mFrame.height(), limitFrame.height());
946 final int width = Math.min(limitFrame.width(), mWindowFrames.mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700947 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +0900948 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
949 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
950 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
951 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Robert Carre65a1c42017-02-28 16:52:59 -0800952 final int top = Math.max(limitFrame.top,
chaviw492139a2018-07-16 16:07:35 -0700953 Math.min( mWindowFrames.mFrame.top, limitFrame.bottom - minVisibleHeight));
Robert Carre65a1c42017-02-28 16:52:59 -0800954 final int left = Math.max(limitFrame.left + minVisibleWidth - width,
chaviw492139a2018-07-16 16:07:35 -0700955 Math.min( mWindowFrames.mFrame.left, limitFrame.right - minVisibleWidth));
956 mWindowFrames.mFrame.set(left, top, left + width, top + height);
957 mWindowFrames.mContentFrame.set( mWindowFrames.mFrame);
chaviw553b0212018-07-12 13:37:01 -0700958 mWindowFrames.mVisibleFrame.set(mWindowFrames.mContentFrame);
959 mWindowFrames.mStableFrame.set(mWindowFrames.mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700960 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
chaviw492139a2018-07-16 16:07:35 -0700961 dc.getDockedDividerController().positionDockedStackedDivider(mWindowFrames.mFrame);
962 mWindowFrames.mContentFrame.set(mWindowFrames.mFrame);
963 if (!mWindowFrames.mFrame.equals(mWindowFrames.mLastFrame)) {
Jorim Jaggi192086e2016-03-11 17:17:03 +0100964 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800965 }
Skuhne81c524a2015-08-12 13:34:14 -0700966 } else {
chaviw492139a2018-07-16 16:07:35 -0700967 mWindowFrames.mContentFrame.set(
968 Math.max(mWindowFrames.mContentFrame.left, mWindowFrames.mFrame.left),
969 Math.max(mWindowFrames.mContentFrame.top, mWindowFrames.mFrame.top),
970 Math.min(mWindowFrames.mContentFrame.right, mWindowFrames.mFrame.right),
971 Math.min(mWindowFrames.mContentFrame.bottom, mWindowFrames.mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800972
chaviw492139a2018-07-16 16:07:35 -0700973 mWindowFrames.mVisibleFrame.set(
974 Math.max(mWindowFrames.mVisibleFrame.left, mWindowFrames.mFrame.left),
975 Math.max(mWindowFrames.mVisibleFrame.top, mWindowFrames.mFrame.top),
976 Math.min(mWindowFrames.mVisibleFrame.right, mWindowFrames.mFrame.right),
977 Math.min(mWindowFrames.mVisibleFrame.bottom, mWindowFrames.mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800978
chaviw492139a2018-07-16 16:07:35 -0700979 mWindowFrames.mStableFrame.set(
980 Math.max(mWindowFrames.mStableFrame.left, mWindowFrames.mFrame.left),
981 Math.max(mWindowFrames.mStableFrame.top, mWindowFrames.mFrame.top),
982 Math.min(mWindowFrames.mStableFrame.right, mWindowFrames.mFrame.right),
983 Math.min(mWindowFrames.mStableFrame.bottom, mWindowFrames.mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700984 }
Adrian Roosfa104232014-06-20 16:10:14 -0700985
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700986 if (inFullscreenContainer && !windowsAreFloating) {
Jorim Jaggi899327f2016-02-25 20:44:18 -0500987 // Windows that are not fullscreen can be positioned outside of the display frame,
988 // but that is not a reason to provide them with overscan insets.
chaviw9c81e632018-07-31 11:17:52 -0700989 InsetUtils.insetsBetweenFrames(layoutContainingFrame, mWindowFrames.mOverscanFrame,
990 mWindowFrames.mOverscanInsets);
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800991 }
Craig Mautnereda67292013-04-28 13:50:14 -0700992
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100993 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
chaviw1454b392018-08-06 09:54:04 -0700994 final WmDisplayCutout c = mWindowFrames.mDisplayCutout.calculateRelativeTo(
chaviw553b0212018-07-12 13:37:01 -0700995 mWindowFrames.mDisplayFrame);
chaviw9c81e632018-07-31 11:17:52 -0700996 mWindowFrames.calculateDockedDividerInsets(c.getDisplayCutout().getSafeInsets());
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100997 } else {
Bryce Leef3c6a472017-11-14 14:53:06 -0800998 getDisplayContent().getBounds(mTmpRect);
chaviw9c81e632018-07-31 11:17:52 -0700999 mWindowFrames.calculateInsets(windowsAreFloating, inFullscreenContainer, mTmpRect);
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001000 }
Adrian Roosfa104232014-06-20 16:10:14 -07001001
chaviwcdba9a42018-07-19 11:36:42 -07001002 mWindowFrames.setDisplayCutout(
chaviw1454b392018-08-06 09:54:04 -07001003 mWindowFrames.mDisplayCutout.calculateRelativeTo(mWindowFrames.mFrame));
Jorim Jaggibae2b152018-04-18 17:27:27 +02001004
Jorim Jaggi656f6502016-04-11 21:08:17 -07001005 // Offset the actual frame by the amount layout frame is off.
chaviw9c81e632018-07-31 11:17:52 -07001006 mWindowFrames.offsetFrames(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -07001007
chaviw9c81e632018-07-31 11:17:52 -07001008 mWindowFrames.mCompatFrame.set(mWindowFrames.mFrame);
Riddle Hsub398da32019-01-21 21:48:16 +08001009 if (inSizeCompatMode()) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001010 // If there is a size compatibility scale being applied to the
1011 // window, we need to apply this to its insets so that they are
1012 // reported to the app in its coordinate space.
chaviw9c81e632018-07-31 11:17:52 -07001013 mWindowFrames.scaleInsets(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001014
1015 // Also the scaled frame that we report to the app needs to be
1016 // adjusted to be in its coordinate space.
chaviw9c81e632018-07-31 11:17:52 -07001017 mWindowFrames.mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001018 }
1019
chaviw492139a2018-07-16 16:07:35 -07001020 if (mIsWallpaper && (fw != mWindowFrames.mFrame.width()
1021 || fh != mWindowFrames.mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001022 final DisplayContent displayContent = getDisplayContent();
1023 if (displayContent != null) {
1024 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
chaviw553b0212018-07-12 13:37:01 -07001025 getDisplayContent().mWallpaperController.updateWallpaperOffset(this,
1026 displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001027 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001028 }
1029
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001030 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001031 "Resolving (mRequestedWidth="
1032 + mRequestedWidth + ", mRequestedheight="
1033 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
chaviw492139a2018-07-16 16:07:35 -07001034 + "): frame=" + mWindowFrames.mFrame.toShortString()
chaviw9c81e632018-07-31 11:17:52 -07001035 + " " + mWindowFrames.getInsetsInfo());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001036 }
1037
Bryce Leef3c6a472017-11-14 14:53:06 -08001038 // TODO: Look into whether this override is still necessary.
1039 @Override
1040 public Rect getBounds() {
1041 if (isInMultiWindowMode()) {
1042 return getTask().getBounds();
1043 } else if (mAppToken != null){
1044 return mAppToken.getBounds();
1045 } else {
1046 return super.getBounds();
1047 }
1048 }
1049
Craig Mautnera2c77052012-03-26 12:14:43 -07001050 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001051 public Rect getFrameLw() {
chaviw492139a2018-07-16 16:07:35 -07001052 return mWindowFrames.mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001053 }
1054
Craig Mautnera2c77052012-03-26 12:14:43 -07001055 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001056 public Rect getDisplayFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001057 return mWindowFrames.mDisplayFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001058 }
1059
Craig Mautnera2c77052012-03-26 12:14:43 -07001060 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001061 public Rect getOverscanFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001062 return mWindowFrames.mOverscanFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001063 }
1064
1065 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001066 public Rect getContentFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001067 return mWindowFrames.mContentFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001068 }
1069
Craig Mautnera2c77052012-03-26 12:14:43 -07001070 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001071 public Rect getVisibleFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001072 return mWindowFrames.mVisibleFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001073 }
1074
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001075 Rect getStableFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001076 return mWindowFrames.mStableFrame;
1077 }
1078
1079 Rect getDecorFrame() {
1080 return mWindowFrames.mDecorFrame;
1081 }
1082
1083 Rect getParentFrame() {
1084 return mWindowFrames.mParentFrame;
1085 }
1086
1087 Rect getContainingFrame() {
1088 return mWindowFrames.mContainingFrame;
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001089 }
1090
chaviwcdba9a42018-07-19 11:36:42 -07001091 WmDisplayCutout getWmDisplayCutout() {
1092 return mWindowFrames.mDisplayCutout;
1093 }
1094
chaviw9c81e632018-07-31 11:17:52 -07001095 void getCompatFrame(Rect outFrame) {
1096 outFrame.set(mWindowFrames.mCompatFrame);
1097 }
1098
1099 void getCompatFrameSize(Rect outFrame) {
1100 outFrame.set(0, 0, mWindowFrames.mCompatFrame.width(), mWindowFrames.mCompatFrame.height());
1101 }
1102
Craig Mautnera2c77052012-03-26 12:14:43 -07001103 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001104 public boolean getGivenInsetsPendingLw() {
1105 return mGivenInsetsPending;
1106 }
1107
Craig Mautnera2c77052012-03-26 12:14:43 -07001108 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001109 public Rect getGivenContentInsetsLw() {
1110 return mGivenContentInsets;
1111 }
1112
Craig Mautnera2c77052012-03-26 12:14:43 -07001113 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001114 public Rect getGivenVisibleInsetsLw() {
1115 return mGivenVisibleInsets;
1116 }
1117
Craig Mautnera2c77052012-03-26 12:14:43 -07001118 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001119 public WindowManager.LayoutParams getAttrs() {
1120 return mAttrs;
1121 }
1122
Craig Mautner812d2ca2012-09-27 15:35:34 -07001123 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001124 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001125 return getDisplayContent().getNeedsMenu(this, bottom);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001126 }
1127
Craig Mautner19d59bc2012-09-04 11:15:56 -07001128 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001129 public int getSystemUiVisibility() {
1130 return mSystemUiVisibility;
1131 }
1132
Craig Mautner19d59bc2012-09-04 11:15:56 -07001133 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001134 public int getSurfaceLayer() {
1135 return mLayer;
1136 }
1137
Craig Mautner812d2ca2012-09-27 15:35:34 -07001138 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001139 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001140 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001141 }
1142
1143 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001144 public IApplicationToken getAppToken() {
1145 return mAppToken != null ? mAppToken.appToken : null;
1146 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001147
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001148 @Override
1149 public boolean isVoiceInteraction() {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001150 return mAppToken != null && mAppToken.mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001151 }
1152
Robert Carr31aa98b2016-07-20 15:29:03 -07001153 boolean setReportResizeHints() {
chaviw9c81e632018-07-31 11:17:52 -07001154 return mWindowFrames.setReportResizeHints();
Craig Mautner4c5eb222013-11-18 12:59:05 -08001155 }
1156
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001157 /**
1158 * Adds the window to the resizing list if any of the parameters we use to track the window
1159 * dimensions or insets have changed.
1160 */
1161 void updateResizingWindowIfNeeded() {
1162 final WindowStateAnimator winAnimator = mWinAnimator;
Adrian Roos5251b1d2018-03-23 18:57:43 +01001163 if (!mHasSurface || getDisplayContent().mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001164 return;
1165 }
1166
1167 final Task task = getTask();
1168 // In the case of stack bound animations, the window frames will update (unlike other
1169 // animations which just modify various transformation properties). We don't want to
1170 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1171 // the frame may not correspond to the surface size or the onscreen area at various
1172 // phases in the animation, and the client will become sad and confused.
Winson Chung40a5f932017-04-13 16:39:36 -07001173 if (task != null && task.mStack.isAnimatingBounds()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001174 return;
1175 }
1176
chaviw9c81e632018-07-31 11:17:52 -07001177 boolean didFrameInsetsChange = setReportResizeHints();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001178 boolean configChanged = isConfigChanged();
1179 if (DEBUG_CONFIGURATION && configChanged) {
1180 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1181 }
1182
1183 final boolean dragResizingChanged = isDragResizeChanged()
1184 && !isDragResizingChangeReported();
1185
1186 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
chaviw492139a2018-07-16 16:07:35 -07001187 + " dragResizingChanged=" + dragResizingChanged
1188 + " last=" + mWindowFrames.mLastFrame + " frame=" + mWindowFrames.mFrame);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001189
1190 // We update mLastFrame always rather than in the conditional with the last inset
1191 // variables, because mFrameSizeChanged only tracks the width and height changing.
chaviw492139a2018-07-16 16:07:35 -07001192 mWindowFrames.mLastFrame.set(mWindowFrames.mFrame);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001193
chaviw9c81e632018-07-31 11:17:52 -07001194 if (didFrameInsetsChange
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001195 || winAnimator.mSurfaceResized
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001196 || configChanged
1197 || dragResizingChanged
Andrii Kulianb2e37802017-01-11 00:36:44 -08001198 || mReportOrientationChanged) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001199 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1200 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
chaviw9c81e632018-07-31 11:17:52 -07001201 + " " + mWindowFrames.getInsetsChangedInfo()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001202 + " surfaceResized=" + winAnimator.mSurfaceResized
1203 + " configChanged=" + configChanged
1204 + " dragResizingChanged=" + dragResizingChanged
chaviw9c81e632018-07-31 11:17:52 -07001205 + " reportOrientationChanged=" + mReportOrientationChanged);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001206 }
1207
1208 // If it's a dead window left on screen, and the configuration changed, there is nothing
1209 // we can do about it. Remove the window now.
1210 if (mAppToken != null && mAppDied) {
1211 mAppToken.removeDeadWindows();
1212 return;
1213 }
1214
Jorim Jaggidc9385a2017-05-13 02:00:31 +02001215 updateLastInsetValues();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001216 mWmService.makeWindowFreezingScreenIfNeededLocked(this);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001217
1218 // If the orientation is changing, or we're starting or ending a drag resizing action,
1219 // then we need to hold off on unfreezing the display until this window has been
1220 // redrawn; to do that, we need to go through the process of getting informed by the
1221 // application when it has finished drawing.
Robert Carr09286c92018-02-15 13:52:31 -08001222 if (getOrientationChanging() || dragResizingChanged) {
Robert Carre13b58e2017-08-31 14:50:44 -07001223 if (DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001224 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1225 + ", mDrawState=DRAW_PENDING in " + this
1226 + ", surfaceController " + winAnimator.mSurfaceController);
1227 }
1228 winAnimator.mDrawState = DRAW_PENDING;
1229 if (mAppToken != null) {
1230 mAppToken.clearAllDrawn();
1231 }
1232 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001233 if (!mWmService.mResizingWindows.contains(this)) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001234 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001235 mWmService.mResizingWindows.add(this);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001236 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07001237 } else if (getOrientationChanging()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001238 if (isDrawnLw()) {
1239 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1240 + this + ", surfaceController " + winAnimator.mSurfaceController);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001241 setOrientationChanging(false);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001242 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001243 - mWmService.mDisplayFreezeTime);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001244 }
1245 }
1246 }
1247
Bryce Lee8c3cf382017-07-06 19:47:10 -07001248 boolean getOrientationChanging() {
1249 // In addition to the local state flag, we must also consider the difference in the last
1250 // reported configuration vs. the current state. If the client code has not been informed of
1251 // the change, logic dependent on having finished processing the orientation, such as
1252 // unfreezing, could be improperly triggered.
1253 // TODO(b/62846907): Checking against {@link mLastReportedConfiguration} could be flaky as
1254 // this is not necessarily what the client has processed yet. Find a
1255 // better indicator consistent with the client.
Robert Carr926643f2017-08-02 12:01:12 -07001256 return (mOrientationChanging || (isVisible()
Bryce Lee2b17afd2017-09-21 10:38:20 -07001257 && getConfiguration().orientation != getLastReportedConfiguration().orientation))
Robert Carr9c1c3a02017-08-08 12:59:01 -07001258 && !mSeamlesslyRotated
1259 && !mOrientationChangeTimedOut;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001260 }
1261
1262 void setOrientationChanging(boolean changing) {
1263 mOrientationChanging = changing;
Robert Carr9c1c3a02017-08-08 12:59:01 -07001264 mOrientationChangeTimedOut = false;
1265 }
1266
1267 void orientationChangeTimedOut() {
1268 mOrientationChangeTimedOut = true;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001269 }
1270
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001271 DisplayContent getDisplayContent() {
1272 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001273 }
1274
Adrian Roos5251b1d2018-03-23 18:57:43 +01001275 @Override
1276 void onDisplayChanged(DisplayContent dc) {
1277 super.onDisplayChanged(dc);
1278 // Window was not laid out for this display yet, so make sure mLayoutSeq does not match.
1279 if (dc != null) {
1280 mLayoutSeq = dc.mLayoutSeq - 1;
Brad Stenningaf596412018-04-02 12:03:19 -07001281 mInputWindowHandle.displayId = dc.getDisplayId();
Adrian Roos5251b1d2018-03-23 18:57:43 +01001282 }
1283 }
1284
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001285 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001286 final DisplayContent displayContent = getDisplayContent();
1287 return displayContent != null ? displayContent.getDisplayInfo() : null;
1288 }
1289
Jorim Jaggife762342016-10-13 14:33:27 +02001290 @Override
1291 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001292 final DisplayContent displayContent = getDisplayContent();
1293 if (displayContent == null) {
Brad Stenningaf596412018-04-02 12:03:19 -07001294 return Display.INVALID_DISPLAY;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001295 }
1296 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001297 }
1298
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001299 Task getTask() {
Bryce Lee6d410262017-02-28 15:30:17 -08001300 return mAppToken != null ? mAppToken.getTask() : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001301 }
1302
1303 TaskStack getStack() {
1304 Task task = getTask();
1305 if (task != null) {
1306 if (task.mStack != null) {
1307 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001308 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001309 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001310 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1311 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001312 final DisplayContent dc = getDisplayContent();
1313 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001314 }
1315
Skuhnef932e562015-08-20 12:07:30 -07001316 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001317 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001318 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001319 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001320 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001321 final Task task = getTask();
1322 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001323 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001324 mTmpRect.setEmpty();
1325 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001326 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001327 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001328 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001329 } else {
1330 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001331 }
1332 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001333
chaviw553b0212018-07-12 13:37:01 -07001334 bounds.set(mWindowFrames.mVisibleFrame);
Chong Zhang9184ec62015-09-24 12:32:21 -07001335 if (intersectWithStackBounds) {
1336 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001337 }
1338
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001339 if (bounds.isEmpty()) {
chaviw492139a2018-07-16 16:07:35 -07001340 bounds.set(mWindowFrames.mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001341 if (intersectWithStackBounds) {
1342 bounds.intersect(mTmpRect);
1343 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001344 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001345 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001346 }
1347
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001348 public long getInputDispatchingTimeoutNanos() {
1349 return mAppToken != null
Wale Ogunwale72919d22016-12-08 18:58:50 -08001350 ? mAppToken.mInputDispatchingTimeoutNanos
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001351 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1352 }
1353
Craig Mautnere8552142012-11-07 13:55:47 -08001354 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001355 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001356 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001357 }
1358
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001359 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1360 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1361 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1362 if (dtdx < -.000001f || dtdx > .000001f) return false;
1363 if (dsdy < -.000001f || dsdy > .000001f) return false;
1364 return true;
1365 }
1366
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001367 void prelayout() {
Riddle Hsub398da32019-01-21 21:48:16 +08001368 if (inSizeCompatMode()) {
1369 mGlobalScale = mToken.getSizeCompatScale();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001370 mInvGlobalScale = 1 / mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001371 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001372 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001373 }
1374 }
1375
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001376 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001377 boolean hasContentToDisplay() {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001378 if (!mAppFreezing && isDrawnLw() && (mViewVisibility == View.VISIBLE
lumark588a3e82018-07-20 18:53:54 +08001379 || (isAnimating() && !getDisplayContent().mAppTransition.isTransitionSet()))) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001380 return true;
1381 }
1382
Wale Ogunwale44f21802016-09-02 12:49:48 -07001383 return super.hasContentToDisplay();
1384 }
1385
1386 @Override
1387 boolean isVisible() {
Jorim Jaggicfd6f3b2018-11-07 15:30:18 +01001388 return wouldBeVisibleIfPolicyIgnored() && mPolicyVisibility
1389 // If we don't have a provider, this window isn't used as a window generating
1390 // insets, so nobody can hide it over the inset APIs.
1391 && (mInsetProvider == null || mInsetProvider.isClientVisible());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001392 }
1393
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001394 /**
Jorim Jaggicfd6f3b2018-11-07 15:30:18 +01001395 * @return {@code true} if the window would be visible if we'd ignore policy visibility,
1396 * {@code false} otherwise.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001397 */
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001398 boolean wouldBeVisibleIfPolicyIgnored() {
Jorim Jaggi43530c92017-05-18 01:53:56 +02001399 return mHasSurface && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001400 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001401 }
1402
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001403 @Override
1404 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001405 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001406 }
1407
1408 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001409 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1410 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001411 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001412 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1413 boolean isWinVisibleLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001414 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.isSelfAnimating())
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001415 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001416 }
1417
1418 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001419 * The same as isVisible(), but follows the current hidden state of the associated app token,
1420 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001421 */
1422 boolean isVisibleNow() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001423 return (!mToken.isHidden() || mAttrs.type == TYPE_APPLICATION_STARTING)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001424 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001425 }
1426
1427 /**
1428 * Can this window possibly be a drag/drop target? The test here is
1429 * a combination of the above "visible now" with the check that the
1430 * Input Manager uses when discarding windows from input consideration.
1431 */
1432 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001433 return isVisibleNow() && !mRemoved
1434 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001435 }
1436
1437 /**
1438 * Same as isVisible(), but we also count it as visible between the
1439 * call to IWindowSession.add() and the first relayout().
1440 */
1441 boolean isVisibleOrAdding() {
1442 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001443 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001444 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001445 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001446 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001447 }
1448
1449 /**
1450 * Is this window currently on-screen? It is on-screen either if it
1451 * is visible or it is currently running an animation before no longer
1452 * being visible.
1453 */
1454 boolean isOnScreen() {
Jorim Jaggiaf221d12016-11-15 14:59:57 -08001455 if (!mHasSurface || mDestroying || !mPolicyVisibility) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001456 return false;
1457 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001458 final AppWindowToken atoken = mAppToken;
1459 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001460 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001461 || isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001462 }
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001463 return !isParentWindowHidden() || isAnimating();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001464 }
1465
1466 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001467 * Whether this window's drawn state might affect the drawn states of the app token.
1468 *
Chong Zhang8e4bda92016-05-04 15:08:18 -07001469 * @return true if the window should be considered while evaluating allDrawn flags.
1470 */
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001471 boolean mightAffectAllDrawn() {
1472 final boolean isAppType = mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1473 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION;
1474 return (isOnScreen() || isAppType) && !mAnimatingExit && !mDestroying;
Chong Zhang8e4bda92016-05-04 15:08:18 -07001475 }
1476
1477 /**
1478 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1479 * it must be drawn before allDrawn can become true.
1480 */
1481 boolean isInteresting() {
1482 return mAppToken != null && !mAppDied
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001483 && (!mAppToken.isFreezingScreen() || !mAppFreezing);
Chong Zhang8e4bda92016-05-04 15:08:18 -07001484 }
1485
1486 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001487 * Like isOnScreen(), but we don't return true if the window is part
1488 * of a transition that has not yet been started.
1489 */
1490 boolean isReadyForDisplay() {
lumark588a3e82018-07-20 18:53:54 +08001491 if (mToken.waitingToShow && getDisplayContent().mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001492 return false;
1493 }
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001494 final boolean parentAndClientVisible = !isParentWindowHidden()
1495 && mViewVisibility == View.VISIBLE && !mToken.isHidden();
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001496 return mHasSurface && mPolicyVisibility && !mDestroying
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001497 && (parentAndClientVisible || isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001498 }
1499
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001500 // TODO: Another visibility method that was added late in the release to minimize risk.
1501 @Override
1502 public boolean canAffectSystemUiFlags() {
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001503 final boolean translucent = mAttrs.alpha == 0.0f;
Jorim Jaggi72207752018-01-08 13:16:59 +01001504 if (translucent) {
1505 return false;
1506 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001507 if (mAppToken == null) {
1508 final boolean shown = mWinAnimator.getShown();
1509 final boolean exiting = mAnimatingExit || mDestroying;
Jorim Jaggi72207752018-01-08 13:16:59 +01001510 return shown && !exiting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001511 } else {
Jorim Jaggi50bf59c2018-03-09 17:29:48 +01001512 final Task task = getTask();
1513 final boolean canFromTask = task != null && task.canAffectSystemUiFlags();
1514 return canFromTask && !mAppToken.isHidden();
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001515 }
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001516 }
1517
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001518 /**
1519 * Like isOnScreen, but returns false if the surface hasn't yet
1520 * been drawn.
1521 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001522 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001523 public boolean isDisplayedLw() {
1524 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001525 return isDrawnLw() && mPolicyVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001526 && ((!isParentWindowHidden() && (atoken == null || !atoken.hiddenRequested))
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001527 || isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001528 }
1529
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001530 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001531 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001532 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001533 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001534 public boolean isAnimatingLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001535 return isAnimating();
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001536 }
1537
Craig Mautner812d2ca2012-09-27 15:35:34 -07001538 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001539 public boolean isGoneForLayoutLw() {
1540 final AppWindowToken atoken = mAppToken;
1541 return mViewVisibility == View.GONE
1542 || !mRelayoutCalled
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001543 || (atoken == null && mToken.isHidden())
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001544 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001545 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001546 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001547 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001548 }
1549
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001550 /**
1551 * Returns true if the window has a surface that it has drawn a
1552 * complete UI in to.
1553 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001554 public boolean isDrawFinishedLw() {
1555 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001556 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1557 || mWinAnimator.mDrawState == READY_TO_SHOW
1558 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001559 }
1560
1561 /**
1562 * Returns true if the window has a surface that it has drawn a
1563 * complete UI in to.
1564 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001565 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001566 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001567 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001568 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001569 }
1570
1571 /**
1572 * Return true if the window is opaque and fully drawn. This indicates
1573 * it may obscure windows behind it.
1574 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001575 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001576 // When there is keyguard, wallpaper could be placed over the secure app
1577 // window but invisible. We need to check wallpaper visibility explicitly
1578 // to determine if it's occluding apps.
1579 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1580 || (mIsWallpaper && mWallpaperVisible))
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001581 && isDrawnLw() && !isAnimating();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001582 }
1583
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001584 @Override
1585 void onMovedByResize() {
1586 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001587 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001588 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001589 }
1590
1591 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1592 boolean changed = false;
1593
1594 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001595 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001596 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1597 }
1598
1599 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1600 // Starting window that's exiting will be removed when the animation finishes.
1601 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1602 // to actually remove it.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001603 if (!visible && isVisibleNow() && mAppToken.isSelfAnimating()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001604 mAnimatingExit = true;
1605 mRemoveOnExit = true;
1606 mWindowRemovalAllowed = true;
1607 }
1608 return changed;
1609 }
1610
chaviwe390cbd2018-04-16 15:29:38 -07001611 final boolean isVisibleNow = isVisibleNow();
1612 if (visible != isVisibleNow) {
1613 // Run exit animation if:
1614 // 1. App visibility and WS visibility are different
1615 // 2. App is not running an animation
1616 // 3. WS is currently visible
1617 if (!runningAppAnimation && isVisibleNow) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001618 final AccessibilityController accessibilityController =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001619 mWmService.mAccessibilityController;
chaviwe390cbd2018-04-16 15:29:38 -07001620 final int winTransit = TRANSIT_EXIT;
1621 mWinAnimator.applyAnimationLocked(winTransit, false /* isEntrance */);
Rhed Jao02655dc2018-10-30 20:44:52 +08001622 if (accessibilityController != null) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001623 accessibilityController.onWindowTransitionLocked(this, winTransit);
1624 }
1625 }
1626 changed = true;
1627 setDisplayLayoutNeeded();
1628 }
1629
1630 return changed;
1631 }
1632
1633 boolean onSetAppExiting() {
1634 final DisplayContent displayContent = getDisplayContent();
1635 boolean changed = false;
1636
1637 if (isVisibleNow()) {
1638 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
Rhed Jao02655dc2018-10-30 20:44:52 +08001639 if (mWmService.mAccessibilityController != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001640 mWmService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001641 }
1642 changed = true;
1643 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001644 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001645 }
1646 }
1647
1648 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001649 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001650 changed |= c.onSetAppExiting();
1651 }
1652
1653 return changed;
1654 }
1655
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001656 @Override
1657 void onResize() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001658 final ArrayList<WindowState> resizingWindows = mWmService.mResizingWindows;
Andrii Kulian3dcdf642018-05-23 17:14:00 -07001659 if (mHasSurface && !isGoneForLayoutLw() && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001660 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001661 resizingWindows.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001662 }
1663 if (isGoneForLayoutLw()) {
1664 mResizedWhileGone = true;
1665 }
1666
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001667 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001668 }
1669
1670 void onUnfreezeBounds() {
1671 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001672 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001673 c.onUnfreezeBounds();
1674 }
1675
1676 if (!mHasSurface) {
1677 return;
1678 }
1679
1680 mLayoutNeeded = true;
1681 setDisplayLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001682 if (!mWmService.mResizingWindows.contains(this)) {
1683 mWmService.mResizingWindows.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001684 }
1685 }
1686
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001687 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001688 * If the window has moved due to its containing content frame changing, then notify the
1689 * listeners and optionally animate it. Simply checking a change of position is not enough,
1690 * because being move due to dock divider is not a trigger for animation.
1691 */
chaviw161ea3e2018-01-31 12:01:12 -08001692 void handleWindowMovedIfNeeded() {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001693 if (!hasMoved()) {
1694 return;
1695 }
1696
1697 // Frame has moved, containing content frame has also moved, and we're not currently
1698 // animating... let's do something.
chaviw492139a2018-07-16 16:07:35 -07001699 final int left = mWindowFrames.mFrame.left;
1700 final int top = mWindowFrames.mFrame.top;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001701 final Task task = getTask();
1702 final boolean adjustedForMinimizedDockOrIme = task != null
1703 && (task.mStack.isAdjustedForMinimizedDockedStack()
1704 || task.mStack.isAdjustedForIme());
David Stevens9440dc82017-03-16 19:00:20 -07001705 if (mToken.okToAnimate()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001706 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1707 && !isDragResizing() && !adjustedForMinimizedDockOrIme
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001708 && getWindowConfiguration().hasMovementAnimations()
Adrian Roos0e7b70a2018-06-07 15:29:34 +02001709 && !mWinAnimator.mLastHidden
1710 && !mSeamlesslyRotated) {
chaviw161ea3e2018-01-31 12:01:12 -08001711 startMoveAnimation(left, top);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001712 }
1713
1714 //TODO (multidisplay): Accessibility supported only for the default display.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001715 if (mWmService.mAccessibilityController != null
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001716 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001717 mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001718 }
1719
1720 try {
1721 mClient.moved(left, top);
1722 } catch (RemoteException e) {
1723 }
1724 mMovedByResize = false;
1725 }
1726
1727 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001728 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001729 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1730 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001731 private boolean hasMoved() {
chaviw1454b392018-08-06 09:54:04 -07001732 return mHasSurface && (mWindowFrames.hasContentChanged() || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001733 && !mAnimatingExit
chaviw492139a2018-07-16 16:07:35 -07001734 && (mWindowFrames.mFrame.top != mWindowFrames.mLastFrame.top
1735 || mWindowFrames.mFrame.left != mWindowFrames.mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001736 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001737 }
1738
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001739 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001740 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001741 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001742 return false;
1743 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001744 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001745 }
1746
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001747 boolean fillsDisplay() {
1748 final DisplayInfo displayInfo = getDisplayInfo();
chaviw492139a2018-07-16 16:07:35 -07001749 return mWindowFrames.mFrame.left <= 0 && mWindowFrames.mFrame.top <= 0
1750 && mWindowFrames.mFrame.right >= displayInfo.appWidth
1751 && mWindowFrames.mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001752 }
1753
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001754 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001755 boolean isConfigChanged() {
Bryce Lee2b17afd2017-09-21 10:38:20 -07001756 return !getLastReportedConfiguration().equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001757 }
1758
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001759 void onWindowReplacementTimeout() {
1760 if (mWillReplaceWindow) {
1761 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001762 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001763 // delays removal on certain conditions, which will leave the stale window in the
1764 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1765 //
1766 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001767 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001768 } else {
1769 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001770 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001771 c.onWindowReplacementTimeout();
1772 }
1773 }
1774 }
1775
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001776 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001777 void forceWindowsScaleableInTransaction(boolean force) {
1778 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1779 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1780 }
1781
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001782 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001783 }
1784
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001785 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001786 void removeImmediately() {
1787 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001788
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001789 if (mRemoved) {
1790 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001791 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1792 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001793 return;
1794 }
1795
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001796 mRemoved = true;
1797
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001798 mWillReplaceWindow = false;
1799 if (mReplacementWindow != null) {
1800 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1801 }
1802
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001803 final DisplayContent dc = getDisplayContent();
Robert Carr825581a2018-03-30 14:00:53 -07001804 if (isInputMethodTarget()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001805 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001806 }
1807
1808 final int type = mAttrs.type;
1809 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001810 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001811 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001812 if (mTapExcludeRegionHolder != null) {
1813 // If a tap exclude region container was initialized for this window, then it should've
1814 // also been registered in display.
1815 dc.mTapExcludeProvidingWindows.remove(this);
1816 }
Tiger Huang7c610aa2018-10-27 00:01:01 +08001817 dc.getDisplayPolicy().removeWindowLw(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001818
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001819 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001820
Craig Mautner96868332012-12-04 14:29:11 -08001821 mWinAnimator.destroyDeferredSurfaceLocked();
1822 mWinAnimator.destroySurfaceLocked();
Wale Ogunwale943002b2017-02-15 19:34:01 -08001823 mSession.windowRemovedLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001824 try {
1825 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1826 } catch (RuntimeException e) {
1827 // Ignore if it has already been removed (usually because
1828 // we are doing this as part of processing a death note.)
1829 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001830
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001831 mWmService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001832 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001833
Wale Ogunwale571771c2016-08-26 13:18:50 -07001834 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001835 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001836 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001837 removeIfPossible(false /*keepVisibleDeadWindow*/);
1838 }
1839
Wale Ogunwale571771c2016-08-26 13:18:50 -07001840 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001841 mWindowRemovalAllowed = true;
1842 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1843 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1844
1845 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1846 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1847 "Starting window removed " + this);
1848
Tiger Huang1e5b10a2018-07-30 20:19:51 +08001849 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && isFocused())
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001850 Slog.v(TAG_WM, "Remove " + this + " client="
1851 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1852 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1853 + Debug.getCallers(5));
1854
1855 final long origId = Binder.clearCallingIdentity();
1856
Peter Visontay3556a3b2017-11-01 17:23:17 +00001857 try {
1858 disposeInputChannel();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001859
Peter Visontay3556a3b2017-11-01 17:23:17 +00001860 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1861 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1862 + " mAnimatingExit=" + mAnimatingExit
1863 + " mRemoveOnExit=" + mRemoveOnExit
1864 + " mHasSurface=" + mHasSurface
1865 + " surfaceShowing=" + mWinAnimator.getShown()
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001866 + " animating=" + isAnimating()
Peter Visontay3556a3b2017-11-01 17:23:17 +00001867 + " app-animation="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001868 + (mAppToken != null ? mAppToken.isSelfAnimating() : "false")
Peter Visontay3556a3b2017-11-01 17:23:17 +00001869 + " mWillReplaceWindow=" + mWillReplaceWindow
1870 + " inPendingTransaction="
1871 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001872 + " mDisplayFrozen=" + mWmService.mDisplayFrozen
Peter Visontay3556a3b2017-11-01 17:23:17 +00001873 + " callers=" + Debug.getCallers(6));
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001874
Peter Visontay3556a3b2017-11-01 17:23:17 +00001875 // Visibility of the removed window. Will be used later to update orientation later on.
1876 boolean wasVisible = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001877
Peter Visontay3556a3b2017-11-01 17:23:17 +00001878 final int displayId = getDisplayId();
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001879
Peter Visontay3556a3b2017-11-01 17:23:17 +00001880 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1881 // window until the animation is done. If the display is frozen, just remove immediately,
1882 // since the animation wouldn't be seen.
1883 if (mHasSurface && mToken.okToAnimate()) {
1884 if (mWillReplaceWindow) {
1885 // This window is going to be replaced. We need to keep it around until the new one
1886 // gets added, then we will get rid of this one.
1887 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1888 "Preserving " + this + " until the new one is " + "added");
1889 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1890 // been removed. We probably need another flag to indicate that window removal
1891 // should be deffered vs. overloading the flag that says we are playing an exit
1892 // animation.
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001893 mAnimatingExit = true;
Peter Visontay3556a3b2017-11-01 17:23:17 +00001894 mReplacingRemoveRequested = true;
1895 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001896 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001897
Peter Visontay3556a3b2017-11-01 17:23:17 +00001898 // If we are not currently running the exit animation, we need to see about starting one
1899 wasVisible = isWinVisibleLw();
1900
1901 if (keepVisibleDeadWindow) {
1902 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1903 "Not removing " + this + " because app died while it's visible");
1904
1905 mAppDied = true;
1906 setDisplayLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001907 mWmService.mWindowPlacerLocked.performSurfacePlacement();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001908
1909 // Set up a replacement input channel since the app is now dead.
1910 // We need to catch tapping on the dead window to restart the app.
1911 openInputChannel(null);
Arthur Hung95b38a92018-07-20 18:56:12 +08001912 getDisplayContent().getInputMonitor().updateInputWindowsLw(true /*force*/);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001913 return;
1914 }
1915
1916 if (wasVisible) {
1917 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
1918
1919 // Try starting an animation.
1920 if (mWinAnimator.applyAnimationLocked(transit, false)) {
1921 mAnimatingExit = true;
Jorim Jaggif41e8822018-04-06 17:22:03 +02001922
1923 // mAnimatingExit affects canAffectSystemUiFlags(). Run layout such that
1924 // any change from that is performed immediately.
1925 setDisplayLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001926 mWmService.requestTraversal();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001927 }
Rhed Jao02655dc2018-10-30 20:44:52 +08001928 if (mWmService.mAccessibilityController != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001929 mWmService.mAccessibilityController.onWindowTransitionLocked(this, transit);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001930 }
1931 }
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001932 final boolean isAnimating = isAnimating()
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001933 && (mAppToken == null || !mAppToken.isWaitingForTransitionStart());
Peter Visontay3556a3b2017-11-01 17:23:17 +00001934 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
1935 && mAppToken.isLastWindow(this);
1936 // We delay the removal of a window if it has a showing surface that can be used to run
1937 // exit animation and it is marked as exiting.
1938 // Also, If isn't the an animating starting window that is the last window in the app.
1939 // We allow the removal of the non-animating starting window now as there is no
1940 // additional window or animation that will trigger its removal.
1941 if (mWinAnimator.getShown() && mAnimatingExit
1942 && (!lastWindowIsStartingWindow || isAnimating)) {
1943 // The exit animation is running or should run... wait for it!
1944 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1945 "Not removing " + this + " due to exit animation ");
1946 setupWindowForRemoveOnExit();
1947 if (mAppToken != null) {
1948 mAppToken.updateReportedVisibilityLocked();
1949 }
1950 return;
1951 }
1952 }
1953
1954 removeImmediately();
1955 // Removing a visible window will effect the computed orientation
1956 // So just update orientation if needed.
Riddle Hsu4e611772018-10-31 18:58:28 +08001957 if (wasVisible) {
1958 final DisplayContent displayContent = getDisplayContent();
1959 if (displayContent.updateOrientationFromAppTokens()) {
1960 displayContent.sendNewConfiguration();
1961 }
Peter Visontay3556a3b2017-11-01 17:23:17 +00001962 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001963 mWmService.updateFocusedWindowLocked(isFocused()
Tiger Huang8af6ba42018-06-07 19:24:09 +08001964 ? UPDATE_FOCUS_REMOVING_FOCUS
1965 : UPDATE_FOCUS_NORMAL,
1966 true /*updateInputWindows*/);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001967 } finally {
1968 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001969 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001970 }
1971
1972 private void setupWindowForRemoveOnExit() {
1973 mRemoveOnExit = true;
1974 setDisplayLayoutNeeded();
1975 // Request a focus update as this window's input channel is already gone. Otherwise
1976 // we could have no focused window in input manager.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001977 final boolean focusChanged = mWmService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001978 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001979 mWmService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001980 if (focusChanged) {
Arthur Hung95b38a92018-07-20 18:56:12 +08001981 getDisplayContent().getInputMonitor().updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001982 }
1983 }
1984
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001985 void setHasSurface(boolean hasSurface) {
1986 mHasSurface = hasSurface;
1987 }
1988
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001989 boolean canBeImeTarget() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08001990 if (mIsImWindow) {
1991 // IME windows can't be IME targets. IME targets are required to be below the IME
1992 // windows and that wouldn't be possible if the IME window is its own target...silly.
1993 return false;
1994 }
1995
Winson Chung3d0a74a2017-07-12 12:37:19 -07001996 final boolean windowsAreFocusable = mAppToken == null || mAppToken.windowsAreFocusable();
Winson Chungb1549342017-07-11 09:59:56 -07001997 if (!windowsAreFocusable) {
1998 // This window can't be an IME target if the app's windows should not be focusable.
1999 return false;
2000 }
2001
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002002 final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002003 final int type = mAttrs.type;
2004
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002005 // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are set or
2006 // both are cleared...and not a starting window.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002007 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
2008 && type != TYPE_APPLICATION_STARTING) {
2009 return false;
2010 }
2011
2012 if (DEBUG_INPUT_METHOD) {
2013 Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding());
2014 if (!isVisibleOrAdding()) {
2015 Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController
2016 + " relayoutCalled=" + mRelayoutCalled
2017 + " viewVis=" + mViewVisibility
2018 + " policyVis=" + mPolicyVisibility
2019 + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim
2020 + " parentHidden=" + isParentWindowHidden()
2021 + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
2022 if (mAppToken != null) {
2023 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + mAppToken.hiddenRequested);
2024 }
2025 }
2026 }
2027 return isVisibleOrAdding();
2028 }
2029
Chong Zhangacf11402015-11-04 16:23:10 -08002030 private final class DeadWindowEventReceiver extends InputEventReceiver {
2031 DeadWindowEventReceiver(InputChannel inputChannel) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002032 super(inputChannel, mWmService.mH.getLooper());
Chong Zhangacf11402015-11-04 16:23:10 -08002033 }
2034 @Override
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08002035 public void onInputEvent(InputEvent event) {
Chong Zhangacf11402015-11-04 16:23:10 -08002036 finishInputEvent(event, true);
2037 }
2038 }
2039 /**
2040 * Dummy event receiver for windows that died visible.
2041 */
2042 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2043
Chong Zhang112eb8c2015-11-02 11:17:00 -08002044 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002045 if (mInputChannel != null) {
2046 throw new IllegalStateException("Window already has an input channel.");
2047 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002048 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002049 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2050 mInputChannel = inputChannels[0];
2051 mClientChannel = inputChannels[1];
Robert Carreadae822018-10-11 19:07:03 -07002052 mInputWindowHandle.token = mClient.asBinder();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002053 if (outInputChannel != null) {
2054 mClientChannel.transferTo(outInputChannel);
2055 mClientChannel.dispose();
2056 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002057 } else {
2058 // If the window died visible, we setup a dummy input channel, so that taps
2059 // can still detected by input monitor channel, and we can relaunch the app.
2060 // Create dummy event receiver that simply reports all events as handled.
2061 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002062 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002063 mWmService.mInputManager.registerInputChannel(mInputChannel, mClient.asBinder());
Jeff Browncc4f7db2011-08-30 20:34:48 -07002064 }
2065
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002066 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002067 if (mDeadWindowEventReceiver != null) {
2068 mDeadWindowEventReceiver.dispose();
2069 mDeadWindowEventReceiver = null;
2070 }
2071
2072 // unregister server channel first otherwise it complains about broken channel
2073 if (mInputChannel != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002074 mWmService.mInputManager.unregisterInputChannel(mInputChannel);
Robert Carre0a353c2018-08-02 16:38:04 -07002075
Chong Zhangacf11402015-11-04 16:23:10 -08002076 mInputChannel.dispose();
2077 mInputChannel = null;
2078 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002079 if (mClientChannel != null) {
2080 mClientChannel.dispose();
2081 mClientChannel = null;
2082 }
Robert Carreadae822018-10-11 19:07:03 -07002083 mInputWindowHandle.token = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002084 }
2085
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002086 /** Returns true if the replacement window was removed. */
2087 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2088 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2089 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2090 removeReplacedWindow();
2091 return true;
2092 }
2093
2094 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002095 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002096 if (c.removeReplacedWindowIfNeeded(replacement)) {
2097 return true;
2098 }
2099 }
2100 return false;
2101 }
2102
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002103 private void removeReplacedWindow() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002104 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002105 mWillReplaceWindow = false;
2106 mAnimateReplacingWindow = false;
2107 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002108 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002109 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002110 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002111 }
2112 }
2113
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002114 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2115 boolean replacementSet = false;
2116
2117 if (mWillReplaceWindow && mReplacementWindow == null
2118 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2119
2120 mReplacementWindow = replacementCandidate;
2121 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2122 replacementSet = true;
2123 }
2124
2125 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002126 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002127 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2128 }
2129
2130 return replacementSet;
2131 }
2132
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002133 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002134 final DisplayContent dc = getDisplayContent();
2135 if (dc != null) {
2136 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002137 }
2138 }
2139
Chong Zhang5117e272016-05-03 12:47:34 -07002140 void applyAdjustForImeIfNeeded() {
2141 final Task task = getTask();
2142 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2143 task.mStack.applyAdjustForImeIfNeeded(task);
2144 }
2145 }
2146
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002147 @Override
2148 void switchUser() {
2149 super.switchUser();
2150 if (isHiddenFromUserLocked()) {
2151 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2152 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
2153 hideLw(false);
2154 }
2155 }
2156
Riddle Hsuff03df52018-12-05 21:43:02 +08002157 int getSurfaceTouchableRegion(Region region, int flags) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002158 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Riddle Hsub398da32019-01-21 21:48:16 +08002159 if (mAppToken != null && !mAppToken.getResolvedOverrideBounds().isEmpty()) {
2160 // There may have touchable letterboxes around the activity, so in order to let the
2161 // letterboxes are able to receive touch event and slip to activity, the activity with
2162 // compatibility bounds cannot occupy full screen touchable region.
2163 if (modal) {
2164 // A modal window uses the whole compatibility bounds.
2165 flags |= FLAG_NOT_TOUCH_MODAL;
2166 mTmpRect.set(mAppToken.getResolvedOverrideBounds());
2167 // TODO(b/112288258): Remove the forced offset when the override bounds always
2168 // starts from zero (See {@link ActivityRecord#resolveOverrideConfiguration}).
2169 mTmpRect.offsetTo(0, 0);
2170 } else {
2171 // Non-modal uses the application based frame.
2172 mTmpRect.set(mWindowFrames.mCompatFrame);
2173 }
2174 // The offset of compatibility bounds is applied to surface of {@link #AppWindowToken}
2175 // and frame, so it is unnecessary to translate twice in surface based coordinates.
2176 final int surfaceOffsetX = mAppToken.inSizeCompatMode()
2177 ? mAppToken.getBounds().left : 0;
2178 mTmpRect.offset(surfaceOffsetX - mWindowFrames.mFrame.left, -mWindowFrames.mFrame.top);
2179 region.set(mTmpRect);
2180 return flags;
2181 }
2182
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002183 if (modal && mAppToken != null) {
2184 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002185 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002186 // If this is a modal window we need to dismiss it if it's not full screen and the
2187 // touch happens outside of the frame that displays the content. This means we
2188 // need to intercept touches outside of that window. The dim layer user
2189 // associated with the window (task or stack) will give us the good bounds, as
2190 // they would be used to display the dim layer.
Robert Carrf59b8dd2017-10-02 18:58:36 -07002191 final Task task = getTask();
2192 if (task != null) {
2193 task.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002194 } else {
Robert Carrf59b8dd2017-10-02 18:58:36 -07002195 getStack().getDimBounds(mTmpRect);
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002196 }
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002197 if (inFreeformWindowingMode()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002198 // For freeform windows we the touch region to include the whole surface for the
2199 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002200 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2201 final int delta = WindowManagerService.dipToPixel(
2202 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2203 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002204 }
2205 region.set(mTmpRect);
Riddle Hsub5e960f2018-12-07 14:51:26 +08002206 cropRegionToStackBoundsIfNeeded(region);
Tiger Huang04dc4cc2019-01-17 18:41:41 +08002207 subtractTouchExcludeRegionIfNeeded(region);
2208 } else if (modal && mTapExcludeRegionHolder != null) {
2209 final Region touchExcludeRegion = Region.obtain();
2210 amendTapExcludeRegion(touchExcludeRegion);
2211 if (!touchExcludeRegion.isEmpty()) {
2212 // Remove touch modal because there are some areas that cannot be touched.
2213 flags |= FLAG_NOT_TOUCH_MODAL;
2214 // Give it a large touchable region at first because it was touch modal. The window
2215 // might be moved on the display, so the touchable region should be large enough to
2216 // ensure it covers the whole display, no matter where it is moved.
2217 getDisplayContent().getBounds(mTmpRect);
2218 final int dw = mTmpRect.width();
2219 final int dh = mTmpRect.height();
2220 region.set(-dw, -dh, dw + dw, dh + dh);
2221 // Subtract the area that cannot be touched.
2222 region.op(touchExcludeRegion, Region.Op.DIFFERENCE);
2223 }
2224 touchExcludeRegion.recycle();
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002225 } else {
2226 // Not modal or full screen modal
Riddle Hsub5e960f2018-12-07 14:51:26 +08002227 getTouchableRegion(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002228 }
Riddle Hsub5e960f2018-12-07 14:51:26 +08002229 // Translate to surface based coordinates.
2230 region.translate(-mWindowFrames.mFrame.left, -mWindowFrames.mFrame.top);
Robert Carra80ad042018-08-14 12:54:20 -07002231
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002232 return flags;
2233 }
2234
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002235 void checkPolicyVisibilityChange() {
2236 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2237 if (DEBUG_VISIBILITY) {
2238 Slog.v(TAG, "Policy visibility changing after anim in " +
2239 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2240 }
2241 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002242 if (!mPolicyVisibility) {
Jorim Jaggi2e05af22017-12-28 15:15:11 +01002243 mWinAnimator.hide("checkPolicyVisibilityChange");
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002244 if (isFocused()) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002245 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2246 "setAnimationLocked: setting mFocusMayChange true");
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002247 mWmService.mFocusMayChange = true;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002248 }
Tetsutoki Shiozawa64c5f0c2018-05-18 10:55:01 +09002249 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002250 // Window is no longer visible -- make sure if we were waiting
2251 // for it to be displayed before enabling the display, that
2252 // we allow the display to be enabled now.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002253 mWmService.enableScreenIfNeededLocked();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002254 }
2255 }
2256 }
2257
2258 void setRequestedSize(int requestedWidth, int requestedHeight) {
2259 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2260 mLayoutNeeded = true;
2261 mRequestedWidth = requestedWidth;
2262 mRequestedHeight = requestedHeight;
2263 }
2264 }
2265
Bryce Leef858b572017-06-29 14:03:33 -07002266 void prepareWindowToDisplayDuringRelayout(boolean wasVisible) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002267 // We need to turn on screen regardless of visibility.
chaviw40234662018-02-07 09:37:16 -08002268 boolean hasTurnScreenOnFlag = (mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0;
2269 boolean allowTheaterMode =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002270 mWmService.mAllowTheaterModeWakeFromLayout || Settings.Global.getInt(
2271 mWmService.mContext.getContentResolver(), Settings.Global.THEATER_MODE_ON, 0)
chaviw40234662018-02-07 09:37:16 -08002272 == 0;
2273 boolean canTurnScreenOn = mAppToken == null || mAppToken.canTurnScreenOn();
2274
2275 // The screen will turn on if the following conditions are met
2276 // 1. The window has the flag FLAG_TURN_SCREEN_ON
2277 // 2. The WMS allows theater mode.
2278 // 3. No AWT or the AWT allows the screen to be turned on. This should only be true once
2279 // per resume to prevent the screen getting getting turned on for each relayout. Set
2280 // canTurnScreenOn will be set to false so the window doesn't turn the screen on again
2281 // during this resume.
2282 // 4. When the screen is not interactive. This is because when the screen is already
2283 // interactive, the value may persist until the next animation, which could potentially
2284 // be occurring while turning off the screen. This would lead to the screen incorrectly
2285 // turning back on.
chaviw474093d2018-03-07 15:03:38 -08002286 if (hasTurnScreenOnFlag) {
2287 if (allowTheaterMode && canTurnScreenOn && !mPowerManagerWrapper.isInteractive()) {
2288 if (DEBUG_VISIBILITY || DEBUG_POWER) {
2289 Slog.v(TAG, "Relayout window turning screen on: " + this);
2290 }
2291 mPowerManagerWrapper.wakeUp(SystemClock.uptimeMillis(),
Michael Wrighte3001042019-02-05 00:13:14 +00002292 PowerManager.WAKE_REASON_APPLICATION, "android.server.wm:SCREEN_ON_FLAG");
chaviw40234662018-02-07 09:37:16 -08002293 }
chaviwb28de1f2018-03-02 10:42:36 -08002294
2295 if (mAppToken != null) {
2296 mAppToken.setCanTurnScreenOn(false);
2297 }
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002298 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002299
2300 // If we were already visible, skip rest of preparation.
2301 if (wasVisible) {
2302 if (DEBUG_VISIBILITY) Slog.v(TAG,
2303 "Already visible and does not turn on screen, skip preparing: " + this);
2304 return;
2305 }
2306
2307 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2308 == SOFT_INPUT_ADJUST_RESIZE) {
2309 mLayoutNeeded = true;
2310 }
2311
David Stevens9440dc82017-03-16 19:00:20 -07002312 if (isDrawnLw() && mToken.okToAnimate()) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002313 mWinAnimator.applyEnterAnimationLocked();
2314 }
Bryce Leef858b572017-06-29 14:03:33 -07002315 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002316
Yunfan Chen75157d72018-07-27 14:47:21 +09002317 private Configuration getProcessGlobalConfiguration() {
2318 // For child windows we want to use the pid for the parent window in case the the child
2319 // window was added from another process.
Yunfan Chen79b96062018-10-17 12:45:23 -07002320 final int pid = getParentWindow() != null ? getParentWindow().mSession.mPid : mSession.mPid;
Yunfan Chenc2ff6cf2018-12-04 16:56:21 -08002321 final Configuration processConfig =
2322 mWmService.mAtmService.getGlobalConfigurationForPid(pid);
2323 mTempConfiguration.setTo(processConfig == null
2324 ? mWmService.mRoot.getConfiguration() : processConfig);
Yunfan Chen75157d72018-07-27 14:47:21 +09002325 return mTempConfiguration;
2326 }
2327
Bryce Leef858b572017-06-29 14:03:33 -07002328 void getMergedConfiguration(MergedConfiguration outConfiguration) {
Yunfan Chen75157d72018-07-27 14:47:21 +09002329 final Configuration globalConfig = getProcessGlobalConfiguration();
Bryce Leef858b572017-06-29 14:03:33 -07002330 final Configuration overrideConfig = getMergedOverrideConfiguration();
2331 outConfiguration.setConfiguration(globalConfig, overrideConfig);
2332 }
2333
Bryce Lee2b17afd2017-09-21 10:38:20 -07002334 void setLastReportedMergedConfiguration(MergedConfiguration config) {
2335 mLastReportedConfiguration.setTo(config);
2336 }
2337
2338 void getLastReportedMergedConfiguration(MergedConfiguration config) {
2339 config.setTo(mLastReportedConfiguration);
2340 }
2341
2342 private Configuration getLastReportedConfiguration() {
2343 return mLastReportedConfiguration.getMergedConfiguration();
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002344 }
2345
2346 void adjustStartingWindowFlags() {
2347 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2348 && mAppToken.startingWindow != null) {
2349 // Special handling of starting window over the base
2350 // window of the app: propagate lock screen flags to it,
2351 // to provide the correct semantics while starting.
2352 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2353 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2354 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2355 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2356 }
2357 }
2358
2359 void setWindowScale(int requestedWidth, int requestedHeight) {
2360 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2361
2362 if (scaledWindow) {
2363 // requested{Width|Height} Surface's physical size
2364 // attrs.{width|height} Size on screen
2365 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2366 mHScale = (mAttrs.width != requestedWidth) ?
2367 (mAttrs.width / (float)requestedWidth) : 1.0f;
2368 mVScale = (mAttrs.height != requestedHeight) ?
2369 (mAttrs.height / (float)requestedHeight) : 1.0f;
2370 } else {
2371 mHScale = mVScale = 1;
2372 }
2373 }
2374
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002375 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002376 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002377 public void binderDied() {
2378 try {
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002379 boolean resetSplitScreenResizing = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002380 synchronized (mWmService.mGlobalLock) {
2381 final WindowState win = mWmService
2382 .windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002383 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002384 if (win != null) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002385 final DisplayContent dc = getDisplayContent();
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002386 if (win.mAppToken != null && win.mAppToken.findMainWindow() == win) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002387 mWmService.mTaskSnapshotController.onAppDied(win.mAppToken);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002388 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002389 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002390 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2391 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002392 // just in case they have the divider at an unstable position. Better
2393 // also reset drag resizing state, because the owner can't do it
2394 // anymore.
Wale Ogunwale61911492017-10-11 08:50:50 -07002395 final TaskStack stack =
Matthew Ng64e77cf2017-10-31 14:01:31 -07002396 dc.getSplitScreenPrimaryStackIgnoringVisibility();
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002397 if (stack != null) {
2398 stack.resetDockedStackToMiddle();
2399 }
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002400 resetSplitScreenResizing = true;
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002401 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002402 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002403 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002404 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002405 }
2406 }
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002407 if (resetSplitScreenResizing) {
2408 try {
2409 // Note: this calls into ActivityManager, so we must *not* hold the window
2410 // manager lock while calling this.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002411 mWmService.mActivityTaskManager.setSplitScreenResizing(false);
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002412 } catch (RemoteException e) {
2413 // Local call, shouldn't return RemoteException.
2414 throw e.rethrowAsRuntimeException();
2415 }
2416 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002417 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002418 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002419 }
2420 }
2421 }
2422
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002423 /**
2424 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2425 * because we want to preserve its location on screen to be re-activated later when the user
2426 * interacts with it.
2427 */
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002428 private boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwale89973222017-04-23 18:39:45 -07002429 if (!isWinVisibleLw() || mAppToken == null || mAppToken.isClientHidden()) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002430 // Not a visible app window or the app isn't dead.
2431 return false;
2432 }
2433
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002434 if (mAttrs.token != mClient.asBinder()) {
2435 // The window was add by a client using another client's app token. We don't want to
2436 // keep the dead window around for this case since this is meant for 'real' apps.
2437 return false;
2438 }
2439
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002440 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2441 // We don't keep starting windows since they were added by the window manager before
2442 // the app even launched.
2443 return false;
2444 }
2445
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002446 return getWindowConfiguration().keepVisibleDeadAppWindowOnScreen();
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002447 }
2448
Tiger Huang513d5e12018-07-16 21:49:50 +08002449 @Override
2450 public boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002451 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002452 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002453 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002454 && (mAppToken == null || mAppToken.windowsAreFocusable())
Robert Carrebdf8582018-09-04 14:50:15 -07002455 && !cantReceiveTouchInput();
Matthew Nge15352e2016-12-20 15:36:29 -08002456 }
2457
lumark31e4f8e2019-01-10 20:48:18 +08002458 @Override
2459 public boolean canShowWhenLocked() {
2460 final boolean showBecauseOfActivity =
2461 mAppToken != null && mAppToken.mActivityRecord.canShowWhenLocked();
2462 final boolean showBecauseOfWindow = (getAttrs().flags & FLAG_SHOW_WHEN_LOCKED) != 0;
2463 return showBecauseOfActivity || showBecauseOfWindow;
2464 }
2465
Robert Carrebdf8582018-09-04 14:50:15 -07002466 /** @return false if this window desires touch events. */
2467 boolean cantReceiveTouchInput() {
Bryce Lee6d410262017-02-28 15:30:17 -08002468 return mAppToken != null && mAppToken.getTask() != null
2469 && mAppToken.getTask().mStack.shouldIgnoreInput();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002470 }
2471
Craig Mautner749a7bb2012-04-02 13:49:53 -07002472 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002473 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002474 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002475 }
2476
Craig Mautner749a7bb2012-04-02 13:49:53 -07002477 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002478 public boolean showLw(boolean doAnimation) {
2479 return showLw(doAnimation, true);
2480 }
2481
2482 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002483 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002484 return false;
2485 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002486 if (!mAppOpVisibility) {
2487 // Being hidden due to app op request.
2488 return false;
2489 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002490 if (mPermanentlyHidden) {
2491 // Permanently hidden until the app exists as apps aren't prepared
2492 // to handle their windows being removed from under them.
2493 return false;
2494 }
Suprabh Shukla69c71422018-04-02 18:39:01 -07002495 if (mHiddenWhileSuspended) {
2496 // Being hidden due to owner package being suspended.
2497 return false;
2498 }
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002499 if (mForceHideNonSystemOverlayWindow) {
2500 // This is an alert window that is currently force hidden.
2501 return false;
2502 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002503 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002504 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002505 return false;
2506 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002507 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002508 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002509 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02002510 + mPolicyVisibility + " animating=" + isAnimating());
David Stevens9440dc82017-03-16 19:00:20 -07002511 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002512 doAnimation = false;
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02002513 } else if (mPolicyVisibility && !isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002514 // Check for the case where we are currently visible and
2515 // not animating; we do not want to do animation at such a
2516 // point to become visible when we already are.
2517 doAnimation = false;
2518 }
2519 }
2520 mPolicyVisibility = true;
2521 mPolicyVisibilityAfterAnim = true;
2522 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002523 mWinAnimator.applyAnimationLocked(TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002524 }
2525 if (requestAnim) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002526 mWmService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002527 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002528 if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002529 mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002530 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002531 return true;
2532 }
2533
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002534 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002535 public boolean hideLw(boolean doAnimation) {
2536 return hideLw(doAnimation, true);
2537 }
2538
2539 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2540 if (doAnimation) {
David Stevens9440dc82017-03-16 19:00:20 -07002541 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002542 doAnimation = false;
2543 }
2544 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002545 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002546 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002547 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002548 return false;
2549 }
2550 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002551 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02002552 if (!isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002553 doAnimation = false;
2554 }
2555 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002556 mPolicyVisibilityAfterAnim = false;
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002557 final boolean isFocused = isFocused();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002558 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002559 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002560 mPolicyVisibility = false;
2561 // Window is no longer visible -- make sure if we were waiting
2562 // for it to be displayed before enabling the display, that
2563 // we allow the display to be enabled now.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002564 mWmService.enableScreenIfNeededLocked();
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002565 if (isFocused) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002566 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002567 "WindowState.hideLw: setting mFocusMayChange true");
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002568 mWmService.mFocusMayChange = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002569 }
2570 }
2571 if (requestAnim) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002572 mWmService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002573 }
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002574 if (isFocused) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002575 mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002576 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002577 return true;
2578 }
2579
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002580 void setForceHideNonSystemOverlayWindowIfNeeded(boolean forceHide) {
2581 if (mOwnerCanAddInternalSystemWindow
2582 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2583 return;
2584 }
2585 if (mForceHideNonSystemOverlayWindow == forceHide) {
2586 return;
2587 }
2588 mForceHideNonSystemOverlayWindow = forceHide;
2589 if (forceHide) {
2590 hideLw(true /* doAnimation */, true /* requestAnim */);
2591 } else {
2592 showLw(true /* doAnimation */, true /* requestAnim */);
2593 }
2594 }
2595
Suprabh Shukla69c71422018-04-02 18:39:01 -07002596 void setHiddenWhileSuspended(boolean hide) {
2597 if (mOwnerCanAddInternalSystemWindow
2598 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2599 return;
2600 }
2601 if (mHiddenWhileSuspended == hide) {
2602 return;
2603 }
2604 mHiddenWhileSuspended = hide;
2605 if (hide) {
2606 hideLw(true, true);
2607 } else {
2608 showLw(true, true);
2609 }
2610 }
2611
Svet Ganovf7b47252018-02-26 11:11:27 -08002612 private void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002613 if (mAppOpVisibility != state) {
2614 mAppOpVisibility = state;
2615 if (state) {
2616 // If the policy visibility had last been to hide, then this
2617 // will incorrectly show at this point since we lost that
2618 // information. Not a big deal -- for the windows that have app
2619 // ops modifies they should only be hidden by policy due to the
2620 // lock screen, and the user won't be changing this if locked.
2621 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002622 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002623 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002624 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002625 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002626 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002627 }
2628
Svet Ganovf7b47252018-02-26 11:11:27 -08002629 void initAppOpsState() {
2630 if (mAppOp == OP_NONE || !mAppOpVisibility) {
2631 return;
2632 }
2633 // If the app op was MODE_DEFAULT we would have checked the permission
2634 // and add the window only if the permission was granted. Therefore, if
2635 // the mode is MODE_DEFAULT we want the op to succeed as the window is
2636 // shown.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002637 final int mode = mWmService.mAppOps.startOpNoThrow(mAppOp,
Svet Ganovf7b47252018-02-26 11:11:27 -08002638 getOwningUid(), getOwningPackage(), true);
2639 if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) {
2640 setAppOpVisibilityLw(false);
2641 }
2642 }
2643
2644 void resetAppOpsState() {
2645 if (mAppOp != OP_NONE && mAppOpVisibility) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002646 mWmService.mAppOps.finishOp(mAppOp, getOwningUid(), getOwningPackage());
Svet Ganovf7b47252018-02-26 11:11:27 -08002647 }
2648 }
2649
2650 void updateAppOpsState() {
2651 if (mAppOp == OP_NONE) {
2652 return;
2653 }
2654 final int uid = getOwningUid();
2655 final String packageName = getOwningPackage();
2656 if (mAppOpVisibility) {
2657 // There is a race between the check and the finish calls but this is fine
2658 // as this would mean we will get another change callback and will reconcile.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002659 int mode = mWmService.mAppOps.checkOpNoThrow(mAppOp, uid, packageName);
Svet Ganovf7b47252018-02-26 11:11:27 -08002660 if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002661 mWmService.mAppOps.finishOp(mAppOp, uid, packageName);
Svet Ganovf7b47252018-02-26 11:11:27 -08002662 setAppOpVisibilityLw(false);
2663 }
2664 } else {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002665 final int mode = mWmService.mAppOps.startOpNoThrow(mAppOp, uid, packageName, true);
Svet Ganovf7b47252018-02-26 11:11:27 -08002666 if (mode == MODE_ALLOWED || mode == MODE_DEFAULT) {
2667 setAppOpVisibilityLw(true);
2668 }
2669 }
2670 }
2671
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002672 public void hidePermanentlyLw() {
2673 if (!mPermanentlyHidden) {
2674 mPermanentlyHidden = true;
2675 hideLw(true, true);
2676 }
2677 }
2678
Jeff Brownc2932a12014-11-20 18:04:05 -08002679 public void pokeDrawLockLw(long timeout) {
2680 if (isVisibleOrAdding()) {
2681 if (mDrawLock == null) {
2682 // We want the tag name to be somewhat stable so that it is easier to correlate
2683 // in wake lock statistics. So in particular, we don't want to include the
2684 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002685 final CharSequence tag = getWindowTag();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002686 mDrawLock = mWmService.mPowerManager.newWakeLock(DRAW_WAKE_LOCK, "Window:" + tag);
Jeff Brownc2932a12014-11-20 18:04:05 -08002687 mDrawLock.setReferenceCounted(false);
2688 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2689 }
2690 // Each call to acquire resets the timeout.
2691 if (DEBUG_POWER) {
2692 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2693 + mAttrs.packageName);
2694 }
2695 mDrawLock.acquire(timeout);
2696 } else if (DEBUG_POWER) {
2697 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2698 + "owned by " + mAttrs.packageName);
2699 }
2700 }
2701
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002702 @Override
2703 public boolean isAlive() {
2704 return mClient.asBinder().isBinderAlive();
2705 }
2706
Craig Mautnera987d432012-10-11 14:07:58 -07002707 boolean isClosing() {
chaviw4ad54912018-05-30 11:05:44 -07002708 return mAnimatingExit || (mAppToken != null && mAppToken.isClosingOrEnteringPip());
Craig Mautnera987d432012-10-11 14:07:58 -07002709 }
2710
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002711 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2712 animators.add(mWinAnimator);
2713
2714 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002715 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002716 c.addWinAnimatorToList(animators);
2717 }
2718 }
2719
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002720 void sendAppVisibilityToClients() {
2721 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002722
Wale Ogunwale89973222017-04-23 18:39:45 -07002723 final boolean clientHidden = mAppToken.isClientHidden();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002724 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2725 // Don't hide the starting window.
2726 return;
2727 }
2728
Wale Ogunwale89973222017-04-23 18:39:45 -07002729 if (clientHidden) {
2730 // Once we are notifying the client that it's visibility has changed, we need to prevent
2731 // it from destroying child surfaces until the animation has finished. We do this by
2732 // detaching any surface control the client added from the client.
2733 for (int i = mChildren.size() - 1; i >= 0; --i) {
2734 final WindowState c = mChildren.get(i);
2735 c.mWinAnimator.detachChildren();
2736 }
2737
2738 mWinAnimator.detachChildren();
2739 }
2740
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002741 try {
2742 if (DEBUG_VISIBILITY) Slog.v(TAG,
2743 "Setting visibility of " + this + ": " + (!clientHidden));
2744 mClient.dispatchAppVisibility(!clientHidden);
2745 } catch (RemoteException e) {
2746 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002747 }
2748
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002749 void onStartFreezingScreen() {
2750 mAppFreezing = true;
2751 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002752 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002753 c.onStartFreezingScreen();
2754 }
2755 }
2756
2757 boolean onStopFreezingScreen() {
2758 boolean unfrozeWindows = false;
2759 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002760 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002761 unfrozeWindows |= c.onStopFreezingScreen();
2762 }
2763
2764 if (!mAppFreezing) {
2765 return unfrozeWindows;
2766 }
2767
Wale Ogunwale953171d2016-09-30 09:17:30 -07002768 mAppFreezing = false;
2769
Bryce Lee8c3cf382017-07-06 19:47:10 -07002770 if (mHasSurface && !getOrientationChanging()
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002771 && mWmService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002772 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
Bryce Lee8c3cf382017-07-06 19:47:10 -07002773 setOrientationChanging(true);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002774 mWmService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002775 }
2776 mLastFreezeDuration = 0;
2777 setDisplayLayoutNeeded();
2778 return true;
2779 }
2780
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002781 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2782 boolean destroyedSomething = false;
Jorim Jaggi59f3e922018-01-05 15:40:32 +01002783
2784 // Copying to a different list as multiple children can be removed.
2785 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
2786 for (int i = childWindows.size() - 1; i >= 0; --i) {
2787 final WindowState c = childWindows.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002788 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2789 }
2790
Robert Carrdb2f6e62017-03-01 20:17:58 -08002791 if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) {
2792 return destroyedSomething;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002793 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08002794
2795 if (appStopped || mWindowRemovalAllowed) {
2796 mWinAnimator.destroyPreservedSurfaceLocked();
2797 }
2798
2799 if (mDestroying) {
2800 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2801 + " destroySurfaces: appStopped=" + appStopped
2802 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2803 + " win.mRemoveOnExit=" + mRemoveOnExit);
2804 if (!cleanupOnResume || mRemoveOnExit) {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002805 destroySurfaceUnchecked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08002806 }
2807 if (mRemoveOnExit) {
2808 removeImmediately();
2809 }
2810 if (cleanupOnResume) {
2811 requestUpdateWallpaperIfNeeded();
2812 }
2813 mDestroying = false;
2814 destroyedSomething = true;
2815 }
2816
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002817 return destroyedSomething;
2818 }
Chris Craik3131bde2016-05-06 13:39:08 -07002819
Robert Carr89a28ab2017-04-24 15:33:11 -07002820 // Destroy or save the application surface without checking
2821 // various indicators of whether the client has released the surface.
2822 // This is in general unsafe, and most callers should use {@link #destroySurface}
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002823 void destroySurfaceUnchecked() {
2824 mWinAnimator.destroySurfaceLocked();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002825
Chong Zhang92147042016-05-09 12:47:11 -07002826 // Clear animating flags now, since the surface is now gone. (Note this is true even
2827 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2828 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002829 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002830
Craig Mautner69b08182012-09-05 13:07:13 -07002831 @Override
2832 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002833 final DisplayContent displayContent = getDisplayContent();
2834 if (displayContent == null) {
2835 // Only a window that was on a non-default display can be detached from it.
2836 return false;
2837 }
Winson Chung47a3e652014-05-21 16:03:42 -07002838 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002839 }
2840
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002841 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07002842 mShowToOwnerOnly = showToOwnerOnly;
2843 }
2844
Wale Ogunwaleea92d972016-12-08 07:33:13 -08002845 private boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002846 // Child windows are evaluated based on their parent window.
2847 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002848 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale72919d22016-12-08 18:58:50 -08002849 && win.mAppToken != null && win.mAppToken.mShowForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002850
2851 // All window frames that are fullscreen extend above status bar, but some don't extend
2852 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2853 // bottom right.
chaviw492139a2018-07-16 16:07:35 -07002854 if (win.getFrameLw().left <= win.getDisplayFrameLw().left
2855 && win.getFrameLw().top <= win.getDisplayFrameLw().top
2856 && win.getFrameLw().right >= win.getStableFrameLw().right
2857 && win.getFrameLw().bottom >= win.getStableFrameLw().bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002858 // Is a fullscreen window, like the clock alarm. Show to everyone.
2859 return false;
2860 }
2861 }
2862
Craig Mautner341220f2012-10-16 15:20:09 -07002863 return win.mShowToOwnerOnly
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002864 && !mWmService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002865 }
2866
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002867 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2868 outRegion.set(
2869 frame.left + inset.left, frame.top + inset.top,
2870 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002871 }
2872
Riddle Hsuff03df52018-12-05 21:43:02 +08002873 /** Get the touchable region in global coordinates. */
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002874 void getTouchableRegion(Region outRegion) {
chaviw492139a2018-07-16 16:07:35 -07002875 final Rect frame = mWindowFrames.mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002876 switch (mTouchableInsets) {
2877 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002878 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002879 outRegion.set(frame);
2880 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002881 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002882 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002883 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002884 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002885 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002886 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002887 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002888 outRegion.set(mGivenTouchableRegion);
Riddle Hsub5e960f2018-12-07 14:51:26 +08002889 outRegion.translate(frame.left, frame.top);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002890 break;
2891 }
2892 }
Vishnu Nairb9246322018-12-06 13:54:02 -08002893 cropRegionToStackBoundsIfNeeded(outRegion);
Tiger Huang04dc4cc2019-01-17 18:41:41 +08002894 subtractTouchExcludeRegionIfNeeded(outRegion);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002895 }
2896
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002897 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002898 final Task task = getTask();
2899 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002900 return;
2901 }
2902
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002903 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002904 if (stack == null) {
2905 return;
2906 }
2907
2908 stack.getDimBounds(mTmpRect);
2909 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002910 }
2911
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002912 /**
Tiger Huang04dc4cc2019-01-17 18:41:41 +08002913 * If this window has areas that cannot be touched, we subtract those areas from its touchable
2914 * region.
2915 */
2916 private void subtractTouchExcludeRegionIfNeeded(Region touchableRegion) {
2917 if (mTapExcludeRegionHolder == null) {
2918 return;
2919 }
2920 final Region touchExcludeRegion = Region.obtain();
2921 amendTapExcludeRegion(touchExcludeRegion);
2922 if (!touchExcludeRegion.isEmpty()) {
2923 touchableRegion.op(touchExcludeRegion, Region.Op.DIFFERENCE);
2924 }
2925 touchExcludeRegion.recycle();
2926 }
2927
2928 /**
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002929 * Report a focus change. Must be called with no locks held, and consistently
2930 * from the same serialized thread (such as dispatched from a handler).
2931 */
Tiger Huang51c5a1d2018-12-11 20:24:51 +08002932 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002933 try {
Tiger Huang51c5a1d2018-12-11 20:24:51 +08002934 mClient.windowFocusChanged(focused, inTouchMode);
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002935 } catch (RemoteException e) {
2936 }
Tiger Huang51c5a1d2018-12-11 20:24:51 +08002937 if (mFocusCallbacks != null) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002938 final int N = mFocusCallbacks.beginBroadcast();
2939 for (int i=0; i<N; i++) {
2940 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2941 try {
2942 if (focused) {
2943 obs.focusGained(mWindowId.asBinder());
2944 } else {
2945 obs.focusLost(mWindowId.asBinder());
2946 }
2947 } catch (RemoteException e) {
2948 }
2949 }
2950 mFocusCallbacks.finishBroadcast();
2951 }
2952 }
2953
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002954 @Override
2955 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002956 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002957 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002958 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002959
Yunfan Chen75157d72018-07-27 14:47:21 +09002960 // We use the process config this window is associated with as the based global config since
2961 // the process can override it config, but isn't part of the window hierarchy.
2962 final Configuration config = getProcessGlobalConfiguration();
2963 config.updateFrom(getMergedOverrideConfiguration());
2964 return config;
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002965 }
2966
Craig Mautnerdf88d732014-01-27 09:21:32 -08002967 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002968 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08002969 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002970 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
chaviw9c81e632018-07-31 11:17:52 -07002971 + ": " + mWindowFrames.mCompatFrame);
Bryce Leef858b572017-06-29 14:03:33 -07002972 final MergedConfiguration mergedConfiguration =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002973 new MergedConfiguration(mWmService.mRoot.getConfiguration(),
Bryce Leef858b572017-06-29 14:03:33 -07002974 getMergedOverrideConfiguration());
2975
Bryce Lee2b17afd2017-09-21 10:38:20 -07002976 setLastReportedMergedConfiguration(mergedConfiguration);
Bryce Leef858b572017-06-29 14:03:33 -07002977
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002978 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002979 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
2980
Riddle Hsub398da32019-01-21 21:48:16 +08002981 final Rect frame = mWindowFrames.mCompatFrame;
chaviw9c81e632018-07-31 11:17:52 -07002982 final Rect overscanInsets = mWindowFrames.mLastOverscanInsets;
2983 final Rect contentInsets = mWindowFrames.mLastContentInsets;
2984 final Rect visibleInsets = mWindowFrames.mLastVisibleInsets;
2985 final Rect stableInsets = mWindowFrames.mLastStableInsets;
2986 final Rect outsets = mWindowFrames.mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002987 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Andrii Kulianb2e37802017-01-11 00:36:44 -08002988 final boolean reportOrientation = mReportOrientationChanged;
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002989 final int displayId = getDisplayId();
chaviwcdba9a42018-07-19 11:36:42 -07002990 final DisplayCutout displayCutout = getWmDisplayCutout().getDisplayCutout();
Chet Haase8eb48d22014-09-24 07:31:29 -07002991 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
2992 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002993 // To prevent deadlock simulate one-way call if win.mClient is a local object.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002994 mWmService.mH.post(new Runnable() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002995 @Override
2996 public void run() {
2997 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002998 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07002999 stableInsets, outsets, reportDraw, mergedConfiguration,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003000 reportOrientation, displayId, displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003001 } catch (RemoteException e) {
3002 // Not a remote call, RemoteException won't be raised.
3003 }
3004 }
3005 });
3006 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003007 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003008 outsets, reportDraw, mergedConfiguration, reportOrientation, displayId,
3009 displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003010 }
Svetoslav4604abc2014-06-10 18:59:30 -07003011
3012 //TODO (multidisplay): Accessibility supported only for the default display.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003013 if (mWmService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
3014 mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07003015 }
3016
chaviw9c81e632018-07-31 11:17:52 -07003017 mWindowFrames.resetInsetsChanged();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003018 mWinAnimator.mSurfaceResized = false;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003019 mReportOrientationChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003020 } catch (RemoteException e) {
Bryce Lee8c3cf382017-07-06 19:47:10 -07003021 setOrientationChanging(false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003022 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003023 - mWmService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08003024 // We are assuming the hosting process is dead or in a zombie state.
3025 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
3026 + ", removing this window.");
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003027 mWmService.mPendingRemove.add(this);
3028 mWmService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003029 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003030 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003031 }
3032
Jorim Jaggif96c90a2018-09-26 16:55:15 +02003033 /**
3034 * Called when the insets state changed.
3035 */
3036 void notifyInsetsChanged() {
3037 try {
3038 mClient.insetsChanged(
3039 getDisplayContent().getInsetsStateController().getInsetsForDispatch(this));
3040 } catch (RemoteException e) {
3041 Slog.w(TAG, "Failed to deliver inset state change", e);
3042 }
3043 }
3044
Jorim Jaggib6030952018-10-23 18:31:52 +02003045 void notifyInsetsControlChanged() {
3046 final InsetsStateController stateController =
3047 getDisplayContent().getInsetsStateController();
3048 try {
3049 mClient.insetsControlChanged(stateController.getInsetsForDispatch(this),
3050 stateController.getControlsForDispatch(this));
3051 } catch (RemoteException e) {
3052 Slog.w(TAG, "Failed to deliver inset state change", e);
3053 }
3054 }
3055
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003056 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08003057 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
3058 // start even if we haven't received the relayout window, so that the client requests
3059 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
3060 // until the window to small size, otherwise the multithread renderer will shift last
3061 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
3062 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003063 boolean resizing = isDragResizing() || isDragResizeChanged();
Wale Ogunwale3382ab12017-07-27 08:55:03 -07003064 if (getWindowConfiguration().useWindowFrameForBackdrop() || !resizing) {
Garfield Tanfbd8ea62018-10-16 17:09:49 -07003065 // Surface position is now inherited from parent, and BackdropFrameRenderer uses
3066 // backdrop frame to position content. Thus we just keep the size of backdrop frame, and
3067 // remove the offset to avoid double offset from display origin.
3068 mTmpRect.set(frame);
3069 mTmpRect.offsetTo(0, 0);
3070 return mTmpRect;
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003071 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07003072 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003073 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003074 return mTmpRect;
3075 }
3076
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003077 private int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003078 final TaskStack stack = getStack();
3079 if (stack == null) {
3080 return INVALID_STACK_ID;
3081 }
3082 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003083 }
3084
3085 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
3086 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003087 MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId,
3088 DisplayCutout displayCutout)
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003089 throws RemoteException {
Robert Carr09286c92018-02-15 13:52:31 -08003090 final boolean forceRelayout = isDragResizeChanged() || reportOrientation;
Chong Zhangedaf3052016-04-22 15:04:31 -07003091
Jorim Jaggidc249c42015-12-15 14:57:31 -08003092 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003093 reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout,
Tiger Huang7c610aa2018-10-27 00:01:01 +08003094 getDisplayContent().getDisplayPolicy().isNavBarForcedShownLw(this), displayId,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003095 new DisplayCutout.ParcelableWrapper(displayCutout));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003096 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003097 }
3098
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003099 public void registerFocusObserver(IWindowFocusObserver observer) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003100 synchronized (mWmService.mGlobalLock) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003101 if (mFocusCallbacks == null) {
3102 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
3103 }
3104 mFocusCallbacks.register(observer);
3105 }
3106 }
3107
3108 public void unregisterFocusObserver(IWindowFocusObserver observer) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003109 synchronized (mWmService.mGlobalLock) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003110 if (mFocusCallbacks != null) {
3111 mFocusCallbacks.unregister(observer);
3112 }
3113 }
3114 }
3115
Tiger Huang1e5b10a2018-07-30 20:19:51 +08003116 boolean isFocused() {
3117 return getDisplayContent().mCurrentFocus == this;
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003118 }
3119
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003120 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07003121 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003122 final Task task = getTask();
3123 return task != null && !task.isFullscreen();
3124 }
3125
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003126 /** Is this window in a container that takes up the entire screen space? */
3127 private boolean inFullscreenContainer() {
Bryce Leef3c6a472017-11-14 14:53:06 -08003128 return mAppToken == null || (mAppToken.matchParentBounds() && !isInMultiWindowMode());
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003129 }
3130
Andrii Kulian283acd22017-08-03 04:03:51 -07003131 /** @return true when the window is in fullscreen task, but has non-fullscreen bounds set. */
3132 boolean isLetterboxedAppWindow() {
Adrian Roos865c70f2018-01-10 17:32:27 +01003133 return !isInMultiWindowMode() && mAppToken != null && !mAppToken.matchParentBounds()
3134 || isLetterboxedForDisplayCutoutLw();
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003135 }
3136
Adrian Roos865c70f2018-01-10 17:32:27 +01003137 @Override
3138 public boolean isLetterboxedForDisplayCutoutLw() {
3139 if (mAppToken == null) {
3140 // Only windows with an AppWindowToken are letterboxed.
3141 return false;
3142 }
chaviwcdba9a42018-07-19 11:36:42 -07003143 if (!mWindowFrames.parentFrameWasClippedByDisplayCutout()) {
Adrian Roos5ed644f2018-03-19 17:01:05 +01003144 // Cutout didn't make a difference, no letterbox
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003145 return false;
3146 }
Adrian Roosfa02da62018-01-15 16:01:18 +01003147 if (mAttrs.layoutInDisplayCutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003148 // Layout in cutout, no letterbox.
3149 return false;
3150 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003151 if (!mAttrs.isFullscreen()) {
3152 // Not filling the parent frame, no letterbox
3153 return false;
Adrian Roosfa02da62018-01-15 16:01:18 +01003154 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003155 // Otherwise we need a letterbox if the layout was smaller than the app window token allowed
3156 // it to be.
3157 return !frameCoversEntireAppTokenBounds();
3158 }
3159
3160 /**
3161 * @return true if this window covers the entire bounds of its app window token
3162 * @throws NullPointerException if there is no app window token for this window
3163 */
3164 private boolean frameCoversEntireAppTokenBounds() {
3165 mTmpRect.set(mAppToken.getBounds());
chaviw492139a2018-07-16 16:07:35 -07003166 mTmpRect.intersectUnchecked(mWindowFrames.mFrame);
Adrian Roos5ed644f2018-03-19 17:01:05 +01003167 return mAppToken.getBounds().equals(mTmpRect);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003168 }
3169
Adrian Roos23df3a32018-03-15 15:41:13 +01003170 @Override
3171 public boolean isLetterboxedOverlappingWith(Rect rect) {
3172 return mAppToken != null && mAppToken.isLetterboxOverlappingWith(rect);
3173 }
3174
Chong Zhang3005e752015-09-18 18:46:28 -07003175 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003176 return mDragResizing != computeDragResizing();
3177 }
3178
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003179 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003180 void setWaitingForDrawnIfResizingChanged() {
3181 if (isDragResizeChanged()) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003182 mWmService.mWaitingForDrawn.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003183 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003184 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003185 }
3186
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003187 /**
3188 * @return Whether we reported a drag resize change to the application or not already.
3189 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003190 private boolean isDragResizingChangeReported() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003191 return mDragResizingChangeReported;
3192 }
3193
3194 /**
3195 * Resets the state whether we reported a drag resize change to the app.
3196 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003197 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003198 void resetDragResizingChangeReported() {
3199 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003200 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003201 }
3202
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003203 int getResizeMode() {
3204 return mResizeMode;
3205 }
3206
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003207 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003208 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003209 if (task == null) {
3210 return false;
3211 }
Tomasz Mikolajewskiaf20b8d2017-11-20 16:11:33 +09003212 if (!inSplitScreenWindowingMode() && !inFreeformWindowingMode()) {
Winson Chung2af04b32017-01-24 16:21:13 -08003213 return false;
3214 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003215 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003216 // Floating windows never enter drag resize mode.
3217 return false;
3218 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003219 if (task.isDragResizing()) {
3220 return true;
3221 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003222
3223 // If the bounds are currently frozen, it means that the layout size that the app sees
3224 // and the bounds we clip this window to might be different. In order to avoid holes, we
3225 // simulate that we are still resizing so the app fills the hole with the resizing
3226 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003227 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003228 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003229 !task.inFreeformWindowingMode() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003230
Chong Zhang3005e752015-09-18 18:46:28 -07003231 }
3232
3233 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003234 final boolean resizing = computeDragResizing();
3235 if (resizing == mDragResizing) {
3236 return;
3237 }
3238 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003239 final Task task = getTask();
3240 if (task != null && task.isDragResizing()) {
3241 mResizeMode = task.getDragResizeMode();
3242 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003243 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003244 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3245 : DRAG_RESIZE_MODE_FREEFORM;
3246 }
Chong Zhang3005e752015-09-18 18:46:28 -07003247 }
3248
3249 boolean isDragResizing() {
3250 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003251 }
3252
Robert Carr2487ce72016-04-07 15:18:45 -07003253 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003254 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3255 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003256 }
3257
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07003258 @CallSuper
3259 @Override
Nataniel Borges023ecb52019-01-16 14:15:43 -08003260 public void writeToProto(ProtoOutputStream proto, long fieldId,
3261 @WindowTraceLogLevel int logLevel) {
3262 boolean isVisible = isVisible();
3263 if (logLevel == WindowTraceLogLevel.CRITICAL && !isVisible) {
3264 return;
3265 }
3266
Steven Timotiusaf03df62017-07-18 16:56:43 -07003267 final long token = proto.start(fieldId);
Nataniel Borges023ecb52019-01-16 14:15:43 -08003268 super.writeToProto(proto, WINDOW_CONTAINER, logLevel);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003269 writeIdentifierToProto(proto, IDENTIFIER);
3270 proto.write(DISPLAY_ID, getDisplayId());
3271 proto.write(STACK_ID, getStackId());
3272 mAttrs.writeToProto(proto, ATTRIBUTES);
3273 mGivenContentInsets.writeToProto(proto, GIVEN_CONTENT_INSETS);
chaviw553b0212018-07-12 13:37:01 -07003274 mWindowFrames.writeToProto(proto, WINDOW_FRAMES);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003275 mAttrs.surfaceInsets.writeToProto(proto, SURFACE_INSETS);
Jorim Jaggi45be1c4c2017-12-15 18:44:43 +01003276 mSurfacePosition.writeToProto(proto, SURFACE_POSITION);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003277 mWinAnimator.writeToProto(proto, ANIMATOR);
3278 proto.write(ANIMATING_EXIT, mAnimatingExit);
3279 for (int i = 0; i < mChildren.size(); i++) {
Nataniel Borges023ecb52019-01-16 14:15:43 -08003280 mChildren.get(i).writeToProto(proto, CHILD_WINDOWS, logLevel);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003281 }
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003282 proto.write(REQUESTED_WIDTH, mRequestedWidth);
3283 proto.write(REQUESTED_HEIGHT, mRequestedHeight);
3284 proto.write(VIEW_VISIBILITY, mViewVisibility);
3285 proto.write(SYSTEM_UI_VISIBILITY, mSystemUiVisibility);
3286 proto.write(HAS_SURFACE, mHasSurface);
3287 proto.write(IS_READY_FOR_DISPLAY, isReadyForDisplay());
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003288 proto.write(REMOVE_ON_EXIT, mRemoveOnExit);
3289 proto.write(DESTROYING, mDestroying);
3290 proto.write(REMOVED, mRemoved);
3291 proto.write(IS_ON_SCREEN, isOnScreen());
Nataniel Borges023ecb52019-01-16 14:15:43 -08003292 proto.write(IS_VISIBLE, isVisible);
Vishnu Nairddd80742018-08-21 14:12:46 -07003293 proto.write(PENDING_SEAMLESS_ROTATION, mPendingSeamlessRotate != null);
3294 proto.write(FINISHED_SEAMLESS_ROTATION_FRAME, mFinishSeamlessRotateFrameNumber);
3295 proto.write(FORCE_SEAMLESS_ROTATION, mForceSeamlesslyRotate);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003296 proto.end(token);
3297 }
3298
Vishnu Nair9a3e4062018-01-11 08:42:54 -08003299 @Override
3300 public void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003301 final long token = proto.start(fieldId);
3302 proto.write(HASH_CODE, System.identityHashCode(this));
3303 proto.write(USER_ID, UserHandle.getUserId(mOwnerUid));
3304 final CharSequence title = getWindowTag();
3305 if (title != null) {
3306 proto.write(TITLE, title.toString());
3307 }
3308 proto.end(token);
3309 }
3310
Jorim Jaggia5e10572017-11-15 14:36:26 +01003311 @Override
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003312 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003313 final TaskStack stack = getStack();
chaviwc65fa582018-08-09 15:33:13 -07003314 pw.print(prefix + "mDisplayId=" + getDisplayId());
3315 if (stack != null) {
3316 pw.print(" stackId=" + stack.mStackId);
3317 }
3318 pw.println(" mSession=" + mSession
3319 + " mClient=" + mClient.asBinder());
3320 pw.println(prefix + "mOwnerUid=" + mOwnerUid
3321 + " mShowToOwnerOnly=" + mShowToOwnerOnly
3322 + " package=" + mAttrs.packageName
3323 + " appop=" + AppOpsManager.opToName(mAppOp));
3324 pw.println(prefix + "mAttrs=" + mAttrs.toString(prefix));
3325 pw.println(prefix + "Requested w=" + mRequestedWidth
3326 + " h=" + mRequestedHeight
3327 + " mLayoutSeq=" + mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003328 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
chaviwc65fa582018-08-09 15:33:13 -07003329 pw.println(prefix + "LastRequested w=" + mLastRequestedWidth
3330 + " h=" + mLastRequestedHeight);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003331 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003332 if (mIsChildWindow || mLayoutAttached) {
chaviwc65fa582018-08-09 15:33:13 -07003333 pw.println(prefix + "mParentWindow=" + getParentWindow()
3334 + " mLayoutAttached=" + mLayoutAttached);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003335 }
3336 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
chaviwc65fa582018-08-09 15:33:13 -07003337 pw.println(prefix + "mIsImWindow=" + mIsImWindow
3338 + " mIsWallpaper=" + mIsWallpaper
3339 + " mIsFloatingLayer=" + mIsFloatingLayer
3340 + " mWallpaperVisible=" + mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003341 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003342 if (dumpAll) {
Jorim Jaggi35d328a2018-08-14 17:00:20 +02003343 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3344 pw.print(" mSubLayer="); pw.print(mSubLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003345 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003346 if (dumpAll) {
chaviwc65fa582018-08-09 15:33:13 -07003347 pw.println(prefix + "mToken=" + mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003348 if (mAppToken != null) {
chaviwc65fa582018-08-09 15:33:13 -07003349 pw.println(prefix + "mAppToken=" + mAppToken);
3350 pw.print(prefix + "mAppDied=" + mAppDied);
3351 pw.print(prefix + "drawnStateEvaluated=" + getDrawnStateEvaluated());
3352 pw.println(prefix + "mightAffectAllDrawn=" + mightAffectAllDrawn());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003353 }
chaviwc65fa582018-08-09 15:33:13 -07003354 pw.println(prefix + "mViewVisibility=0x" + Integer.toHexString(mViewVisibility)
3355 + " mHaveFrame=" + mHaveFrame
3356 + " mObscured=" + mObscured);
3357 pw.println(prefix + "mSeq=" + mSeq
3358 + " mSystemUiVisibility=0x" + Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003359 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003360 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
chaviwc65fa582018-08-09 15:33:13 -07003361 || isParentWindowHidden() || mPermanentlyHidden || mForceHideNonSystemOverlayWindow
Suprabh Shukla69c71422018-04-02 18:39:01 -07003362 || mHiddenWhileSuspended) {
chaviwc65fa582018-08-09 15:33:13 -07003363 pw.println(prefix + "mPolicyVisibility=" + mPolicyVisibility
3364 + " mPolicyVisibilityAfterAnim=" + mPolicyVisibilityAfterAnim
3365 + " mAppOpVisibility=" + mAppOpVisibility
3366 + " parentHidden=" + isParentWindowHidden()
3367 + " mPermanentlyHidden=" + mPermanentlyHidden
3368 + " mHiddenWhileSuspended=" + mHiddenWhileSuspended
3369 + " mForceHideNonSystemOverlayWindow=" + mForceHideNonSystemOverlayWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003370 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003371 if (!mRelayoutCalled || mLayoutNeeded) {
chaviwc65fa582018-08-09 15:33:13 -07003372 pw.println(prefix + "mRelayoutCalled=" + mRelayoutCalled
3373 + " mLayoutNeeded=" + mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003374 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003375 if (dumpAll) {
chaviwc65fa582018-08-09 15:33:13 -07003376 pw.println(prefix + "mGivenContentInsets=" + mGivenContentInsets.toShortString(sTmpSB)
3377 + " mGivenVisibleInsets=" + mGivenVisibleInsets.toShortString(sTmpSB));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003378 if (mTouchableInsets != 0 || mGivenInsetsPending) {
chaviwc65fa582018-08-09 15:33:13 -07003379 pw.println(prefix + "mTouchableInsets=" + mTouchableInsets
3380 + " mGivenInsetsPending=" + mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003381 Region region = new Region();
3382 getTouchableRegion(region);
chaviwc65fa582018-08-09 15:33:13 -07003383 pw.println(prefix + "touchable region=" + region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003384 }
chaviwc65fa582018-08-09 15:33:13 -07003385 pw.println(prefix + "mFullConfiguration=" + getConfiguration());
3386 pw.println(prefix + "mLastReportedConfiguration=" + getLastReportedConfiguration());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003387 }
chaviwc65fa582018-08-09 15:33:13 -07003388 pw.println(prefix + "mHasSurface=" + mHasSurface
3389 + " isReadyForDisplay()=" + isReadyForDisplay()
3390 + " mWindowRemovalAllowed=" + mWindowRemovalAllowed);
Riddle Hsub398da32019-01-21 21:48:16 +08003391 if (inSizeCompatMode()) {
chaviw9c81e632018-07-31 11:17:52 -07003392 pw.println(prefix + "mCompatFrame=" + mWindowFrames.mCompatFrame.toShortString(sTmpSB));
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003393 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003394 if (dumpAll) {
chaviw553b0212018-07-12 13:37:01 -07003395 mWindowFrames.dump(pw, prefix);
chaviw9c81e632018-07-31 11:17:52 -07003396 pw.println(prefix + " surface=" + mAttrs.surfaceInsets.toShortString(sTmpSB));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003397 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01003398 super.dump(pw, prefix, dumpAll);
chaviwc65fa582018-08-09 15:33:13 -07003399 pw.println(prefix + mWinAnimator + ":");
Dianne Hackborn529e7442012-11-01 14:22:28 -07003400 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003401 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
chaviwc65fa582018-08-09 15:33:13 -07003402 pw.println(prefix + "mAnimatingExit=" + mAnimatingExit
3403 + " mRemoveOnExit=" + mRemoveOnExit
3404 + " mDestroying=" + mDestroying
3405 + " mRemoved=" + mRemoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003406 }
chaviw40234662018-02-07 09:37:16 -08003407 if (getOrientationChanging() || mAppFreezing || mReportOrientationChanged) {
chaviwc65fa582018-08-09 15:33:13 -07003408 pw.println(prefix + "mOrientationChanging=" + mOrientationChanging
3409 + " configOrientationChanging="
3410 + (getLastReportedConfiguration().orientation != getConfiguration().orientation)
3411 + " mAppFreezing=" + mAppFreezing
3412 + " mReportOrientationChanged=" + mReportOrientationChanged);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003413 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003414 if (mLastFreezeDuration != 0) {
chaviwc65fa582018-08-09 15:33:13 -07003415 pw.print(prefix + "mLastFreezeDuration=");
3416 TimeUtils.formatDuration(mLastFreezeDuration, pw);
3417 pw.println();
Dianne Hackborna57c6952013-03-29 14:46:40 -07003418 }
chaviwc65fa582018-08-09 15:33:13 -07003419 pw.print(prefix + "mForceSeamlesslyRotate=" + mForceSeamlesslyRotate
3420 + " seamlesslyRotate: pending=");
Vishnu Nairddd80742018-08-21 14:12:46 -07003421 if (mPendingSeamlessRotate != null) {
3422 mPendingSeamlessRotate.dump(pw);
3423 } else {
3424 pw.print("null");
Adrian Roos27a90d22018-07-06 02:39:54 -07003425 }
chaviwc65fa582018-08-09 15:33:13 -07003426 pw.println(" finishedFrameNumber=" + mFinishSeamlessRotateFrameNumber);
Vishnu Nairddd80742018-08-21 14:12:46 -07003427
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003428 if (mHScale != 1 || mVScale != 1) {
chaviwc65fa582018-08-09 15:33:13 -07003429 pw.println(prefix + "mHScale=" + mHScale
3430 + " mVScale=" + mVScale);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003431 }
3432 if (mWallpaperX != -1 || mWallpaperY != -1) {
chaviwc65fa582018-08-09 15:33:13 -07003433 pw.println(prefix + "mWallpaperX=" + mWallpaperX
3434 + " mWallpaperY=" + mWallpaperY);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003435 }
3436 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
chaviwc65fa582018-08-09 15:33:13 -07003437 pw.println(prefix + "mWallpaperXStep=" + mWallpaperXStep
3438 + " mWallpaperYStep=" + mWallpaperYStep);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003439 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003440 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3441 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
chaviwc65fa582018-08-09 15:33:13 -07003442 pw.println(prefix + "mWallpaperDisplayOffsetX=" + mWallpaperDisplayOffsetX
3443 + " mWallpaperDisplayOffsetY=" + mWallpaperDisplayOffsetY);
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003444 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003445 if (mDrawLock != null) {
chaviwc65fa582018-08-09 15:33:13 -07003446 pw.println(prefix + "mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003447 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003448 if (isDragResizing()) {
chaviwc65fa582018-08-09 15:33:13 -07003449 pw.println(prefix + "isDragResizing=" + isDragResizing());
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003450 }
3451 if (computeDragResizing()) {
chaviwc65fa582018-08-09 15:33:13 -07003452 pw.println(prefix + "computeDragResizing=" + computeDragResizing());
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003453 }
chaviwc65fa582018-08-09 15:33:13 -07003454 pw.println(prefix + "isOnScreen=" + isOnScreen());
3455 pw.println(prefix + "isVisible=" + isVisible());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003456 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003457
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003458 @Override
3459 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003460 return Integer.toHexString(System.identityHashCode(this))
Jorim Jaggia5e10572017-11-15 14:36:26 +01003461 + " " + getWindowTag();
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003462 }
3463
Robert Carra1eb4392015-12-10 12:43:51 -08003464 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003465 CharSequence tag = mAttrs.getTitle();
3466 if (tag == null || tag.length() <= 0) {
3467 tag = mAttrs.packageName;
3468 }
3469 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003470 }
3471
3472 @Override
3473 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003474 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003475 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003476 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003477 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003478 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003479 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003480 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003481 }
3482 return mStringNameCache;
3483 }
Robert Carr58f29132015-10-29 14:19:05 -07003484
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003485 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003486 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003487 clipRect.left = (int) (clipRect.left / mHScale);
3488 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003489 }
3490 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003491 clipRect.top = (int) (clipRect.top / mVScale);
3492 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003493 }
3494 }
Robert Carr31e28482015-12-02 16:53:18 -08003495
chaviw9c81e632018-07-31 11:17:52 -07003496 private void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003497 final int pw = containingFrame.width();
3498 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003499 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003500 final boolean inNonFullscreenContainer = !inFullscreenContainer();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003501 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3502
3503 // We need to fit it to the display if either
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003504 // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen
3505 // for the taskless windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003506 // 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 -07003507 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on
3508 // screen, but SurfaceViews want to be always at a specific location so we don't fit it to
3509 // the display.
3510 final boolean fitToDisplay = (task == null || !inNonFullscreenContainer)
Robert Carr6f44db12016-07-21 14:54:43 -07003511 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003512 float x, y;
3513 int w,h;
3514
Riddle Hsub398da32019-01-21 21:48:16 +08003515 final boolean inSizeCompatMode = inSizeCompatMode();
Robert Carr31e28482015-12-02 16:53:18 -08003516 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3517 if (mAttrs.width < 0) {
3518 w = pw;
Riddle Hsub398da32019-01-21 21:48:16 +08003519 } else if (inSizeCompatMode) {
Robert Carr31e28482015-12-02 16:53:18 -08003520 w = (int)(mAttrs.width * mGlobalScale + .5f);
3521 } else {
3522 w = mAttrs.width;
3523 }
3524 if (mAttrs.height < 0) {
3525 h = ph;
Riddle Hsub398da32019-01-21 21:48:16 +08003526 } else if (inSizeCompatMode) {
Robert Carr31e28482015-12-02 16:53:18 -08003527 h = (int)(mAttrs.height * mGlobalScale + .5f);
3528 } else {
3529 h = mAttrs.height;
3530 }
3531 } else {
3532 if (mAttrs.width == MATCH_PARENT) {
3533 w = pw;
Riddle Hsub398da32019-01-21 21:48:16 +08003534 } else if (inSizeCompatMode) {
Robert Carr31e28482015-12-02 16:53:18 -08003535 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3536 } else {
3537 w = mRequestedWidth;
3538 }
3539 if (mAttrs.height == MATCH_PARENT) {
3540 h = ph;
Riddle Hsub398da32019-01-21 21:48:16 +08003541 } else if (inSizeCompatMode) {
Robert Carr31e28482015-12-02 16:53:18 -08003542 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3543 } else {
3544 h = mRequestedHeight;
3545 }
3546 }
3547
Riddle Hsub398da32019-01-21 21:48:16 +08003548 if (inSizeCompatMode) {
Robert Carr31e28482015-12-02 16:53:18 -08003549 x = mAttrs.x * mGlobalScale;
3550 y = mAttrs.y * mGlobalScale;
3551 } else {
3552 x = mAttrs.x;
3553 y = mAttrs.y;
3554 }
3555
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003556 if (inNonFullscreenContainer && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003557 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003558 // required by {@link Gravity#apply} call.
3559 w = Math.min(w, pw);
3560 h = Math.min(h, ph);
3561 }
3562
3563 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003564 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003565 (int) (x + mAttrs.horizontalMargin * pw),
chaviw492139a2018-07-16 16:07:35 -07003566 (int) (y + mAttrs.verticalMargin * ph), mWindowFrames.mFrame);
Robert Carr31e28482015-12-02 16:53:18 -08003567
3568 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003569 if (fitToDisplay) {
chaviw492139a2018-07-16 16:07:35 -07003570 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mWindowFrames.mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003571 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003572
3573 // We need to make sure we update the CompatFrame as it is used for
3574 // cropping decisions, etc, on systems where we lack a decor layer.
chaviw9c81e632018-07-31 11:17:52 -07003575 mWindowFrames.mCompatFrame.set(mWindowFrames.mFrame);
Riddle Hsub398da32019-01-21 21:48:16 +08003576 if (inSizeCompatMode) {
Robert Carr6e18c5e2016-02-29 15:57:13 -08003577 // See comparable block in computeFrameLw.
chaviw9c81e632018-07-31 11:17:52 -07003578 mWindowFrames.mCompatFrame.scale(mInvGlobalScale);
Robert Carr6e18c5e2016-02-29 15:57:13 -08003579 }
Robert Carr31e28482015-12-02 16:53:18 -08003580 }
Robert Carr51a1b872015-12-08 14:03:13 -08003581
3582 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003583 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003584 }
3585
Robert Carrf3b72c72016-03-21 18:16:39 -07003586 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003587 return mIsChildWindow
3588 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003589 }
3590
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003591 /**
3592 * Returns true if any window added by an application process that if of type
3593 * {@link android.view.WindowManager.LayoutParams#TYPE_TOAST} or that requires that requires
3594 * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when
3595 * this window is visible.
3596 */
3597 boolean hideNonSystemOverlayWindowsWhenVisible() {
Philip P. Moltmann66ce2382018-10-09 13:46:11 -07003598 return (mAttrs.privateFlags & SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != 0
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003599 && mSession.mCanHideNonSystemOverlayWindows;
3600 }
3601
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003602 /** Returns the parent window if this is a child of another window, else null. */
3603 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003604 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3605 // WindowContainer that isn't a WindowState.
3606 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003607 }
3608
3609 /** Returns the topmost parent window if this is a child of another window, else this. */
3610 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003611 WindowState current = this;
3612 WindowState topParent = current;
3613 while (current != null && current.mIsChildWindow) {
3614 current = current.getParentWindow();
3615 // Parent window can be null if the child is detached from it's parent already, but
3616 // someone still has a reference to access it. So, we return the top parent value we
3617 // already have instead of null.
3618 if (current != null) {
3619 topParent = current;
3620 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003621 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003622 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003623 }
3624
Wale Ogunwale9d147902016-07-16 11:58:55 -07003625 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003626 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003627 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003628 }
3629
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003630 void setWillReplaceWindow(boolean animate) {
3631 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003632 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003633 c.setWillReplaceWindow(animate);
3634 }
3635
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003636 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3637 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3638 // We don't set replacing on starting windows since they are added by window manager and
3639 // not the client so won't be replaced by the client.
3640 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003641 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003642
3643 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003644 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003645 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003646 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003647
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003648 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003649 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003650 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003651 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003652
3653 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003654 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003655 c.clearWillReplaceWindow();
3656 }
3657 }
3658
3659 boolean waitingForReplacement() {
3660 if (mWillReplaceWindow) {
3661 return true;
3662 }
3663
3664 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003665 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003666 if (c.waitingForReplacement()) {
3667 return true;
3668 }
3669 }
3670 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003671 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003672
Chong Zhang4d7369a2016-04-25 16:09:14 -07003673 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003674 final DisplayContent dc = getDisplayContent();
3675 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3676 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3677 dc.setLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003678 mWmService.mWindowPlacerLocked.requestTraversal();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003679 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003680
3681 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003682 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003683 c.requestUpdateWallpaperIfNeeded();
3684 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003685 }
3686
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003687 float translateToWindowX(float x) {
chaviw492139a2018-07-16 16:07:35 -07003688 float winX = x - mWindowFrames.mFrame.left;
Riddle Hsub398da32019-01-21 21:48:16 +08003689 if (inSizeCompatMode()) {
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003690 winX *= mGlobalScale;
3691 }
3692 return winX;
3693 }
3694
3695 float translateToWindowY(float y) {
chaviw492139a2018-07-16 16:07:35 -07003696 float winY = y - mWindowFrames.mFrame.top;
Riddle Hsub398da32019-01-21 21:48:16 +08003697 if (inSizeCompatMode()) {
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003698 winY *= mGlobalScale;
3699 }
3700 return winY;
3701 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003702
3703 // During activity relaunch due to resize, we sometimes use window replacement
3704 // for only child windows (as the main window is handled by window preservation)
3705 // and the big surface.
3706 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003707 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3708 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3709 // we also want to replace them at such phases, as they won't be covered by window
3710 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003711 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003712 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003713 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003714 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003715
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003716 void setWillReplaceChildWindows() {
3717 if (shouldBeReplacedWithChildren()) {
3718 setWillReplaceWindow(false /* animate */);
3719 }
3720 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003721 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003722 c.setWillReplaceChildWindows();
3723 }
3724 }
3725
3726 WindowState getReplacingWindow() {
3727 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3728 return this;
3729 }
3730 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003731 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003732 final WindowState replacing = c.getReplacingWindow();
3733 if (replacing != null) {
3734 return replacing;
3735 }
3736 }
3737 return null;
3738 }
3739
Jorim Jaggife762342016-10-13 14:33:27 +02003740 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07003741 public int getRotationAnimationHint() {
3742 if (mAppToken != null) {
3743 return mAppToken.mRotationAnimationHint;
3744 } else {
3745 return -1;
3746 }
3747 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003748
Jorim Jaggife762342016-10-13 14:33:27 +02003749 @Override
3750 public boolean isInputMethodWindow() {
3751 return mIsImWindow;
3752 }
3753
Wale Ogunwale9d147902016-07-16 11:58:55 -07003754 // This must be called while inside a transaction.
3755 boolean performShowLocked() {
3756 if (isHiddenFromUserLocked()) {
3757 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3758 hideLw(false);
3759 return false;
3760 }
3761
3762 logPerformShow("performShow on ");
3763
Jorim Jaggia50da602016-12-29 11:51:42 +01003764 final int drawState = mWinAnimator.mDrawState;
3765 if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW)
3766 && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3767 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3768 }
3769
Jorim Jaggib0d27342016-11-01 16:10:42 -07003770 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003771 return false;
3772 }
3773
3774 logPerformShow("Showing ");
3775
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003776 mWmService.enableScreenIfNeededLocked();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003777 mWinAnimator.applyEnterAnimationLocked();
3778
3779 // Force the show in the next prepareSurfaceLocked() call.
3780 mWinAnimator.mLastAlpha = -1;
Robert Carre13b58e2017-08-31 14:50:44 -07003781 if (DEBUG_ANIM) Slog.v(TAG,
Wale Ogunwale9d147902016-07-16 11:58:55 -07003782 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3783 mWinAnimator.mDrawState = HAS_DRAWN;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003784 mWmService.scheduleAnimationLocked();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003785
3786 if (mHidden) {
3787 mHidden = false;
3788 final DisplayContent displayContent = getDisplayContent();
3789
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003790 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003791 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003792 if (c.mWinAnimator.mSurfaceController != null) {
3793 c.performShowLocked();
3794 // It hadn't been shown, which means layout not performed on it, so now we
3795 // want to make sure to do a layout. If called from within the transaction
3796 // loop, this will cause it to restart with a new layout.
3797 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003798 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003799 }
3800 }
3801 }
3802 }
3803
Wale Ogunwale9d147902016-07-16 11:58:55 -07003804 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003805 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003806 }
3807
3808 return true;
3809 }
3810
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003811 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003812 if (DEBUG_VISIBILITY
Jorim Jaggie4b0f282017-05-17 15:10:29 +02003813 || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003814 Slog.v(TAG, prefix + this
3815 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07003816 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003817 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3818 + " during animation: policyVis=" + mPolicyVisibility
3819 + " parentHidden=" + isParentWindowHidden()
3820 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003821 + (mAppToken != null && mAppToken.hiddenRequested)
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003822 + " tok.hidden=" + (mAppToken != null && mAppToken.isHidden())
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02003823 + " animating=" + isAnimating()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003824 + " tok animating="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003825 + (mAppToken != null && mAppToken.isSelfAnimating())
Wale Ogunwale9d147902016-07-16 11:58:55 -07003826 + " Callers=" + Debug.getCallers(4));
3827 }
3828 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003829
3830 WindowInfo getWindowInfo() {
3831 WindowInfo windowInfo = WindowInfo.obtain();
3832 windowInfo.type = mAttrs.type;
3833 windowInfo.layer = mLayer;
3834 windowInfo.token = mClient.asBinder();
Phil Weaver5dc3ebc2017-08-16 13:04:20 -07003835 if (mAppToken != null) {
3836 windowInfo.activityToken = mAppToken.appToken.asBinder();
3837 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003838 windowInfo.title = mAttrs.accessibilityTitle;
Phil Weaverbb2f28a2017-12-22 09:44:28 -08003839 // Panel windows have no public way to set the a11y title directly. Use the
3840 // regular title as a fallback.
Phil Weaver568cf662018-04-24 17:09:26 -07003841 final boolean isPanelWindow = (mAttrs.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW)
3842 && (mAttrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW);
3843 // Accessibility overlays should have titles that work for accessibility, and can't set
3844 // the a11y title themselves.
3845 final boolean isAccessibilityOverlay =
3846 windowInfo.type == WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
3847 if (TextUtils.isEmpty(windowInfo.title) && (isPanelWindow || isAccessibilityOverlay)) {
Jackal Guo25a33cbd2018-08-01 16:08:45 +08003848 final CharSequence title = mAttrs.getTitle();
3849 windowInfo.title = TextUtils.isEmpty(title) ? null : title;
Phil Weaverbb2f28a2017-12-22 09:44:28 -08003850 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003851 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3852 windowInfo.focused = isFocused();
Phil Weaverf00cd142017-03-03 13:44:00 -08003853 Task task = getTask();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003854 windowInfo.inPictureInPicture = (task != null) && task.inPinnedWindowingMode();
Jackal Guoac2b62e2018-08-22 18:28:46 +08003855 windowInfo.hasFlagWatchOutsideTouch =
3856 (mAttrs.flags & WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH) != 0;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003857
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003858 if (mIsChildWindow) {
3859 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003860 }
3861
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003862 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003863 if (childCount > 0) {
3864 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003865 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003866 }
3867 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003868 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003869 windowInfo.childTokens.add(child.mClient.asBinder());
3870 }
3871 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003872 return windowInfo;
3873 }
3874
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003875 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003876 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003877 if (mChildren.isEmpty()) {
3878 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003879 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003880 }
3881
3882 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003883 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003884 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003885 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003886 }
3887 }
3888
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003889 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003890 // We want to consume the negative sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003891 // below the parent, then this window (the parent), and then the positive sublayer children
3892 // because they need to appear above the parent.
3893 int i = 0;
3894 final int count = mChildren.size();
3895 WindowState child = mChildren.get(i);
3896
3897 while (i < count && child.mSubLayer < 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003898 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003899 return true;
3900 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003901 i++;
3902 if (i >= count) {
3903 break;
3904 }
3905 child = mChildren.get(i);
3906 }
3907
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003908 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003909 return true;
3910 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003911
3912 while (i < count) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003913 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003914 return true;
3915 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003916 i++;
3917 if (i >= count) {
3918 break;
3919 }
3920 child = mChildren.get(i);
3921 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003922
3923 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003924 }
3925
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003926 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003927 // We want to consume the positive sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003928 // above the parent, then this window (the parent), and then the negative sublayer children
3929 // because they need to appear above the parent.
3930 int i = mChildren.size() - 1;
3931 WindowState child = mChildren.get(i);
3932
3933 while (i >= 0 && child.mSubLayer >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003934 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003935 return true;
3936 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003937 --i;
3938 if (i < 0) {
3939 break;
3940 }
3941 child = mChildren.get(i);
3942 }
3943
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003944 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003945 return true;
3946 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003947
3948 while (i >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003949 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003950 return true;
3951 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003952 --i;
3953 if (i < 0) {
3954 break;
3955 }
3956 child = mChildren.get(i);
3957 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003958
3959 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003960 }
3961
Robert Carr9785cf32018-04-25 15:06:07 -07003962 private boolean applyImeWindowsIfNeeded(ToBooleanFunction<WindowState> callback,
3963 boolean traverseTopToBottom) {
3964 // If this window is the current IME target, so we need to process the IME windows
3965 // directly above it. The exception is if we are in split screen
3966 // in which case we process the IME at the DisplayContent level to
3967 // ensure it is above the docked divider.
3968 if (isInputMethodTarget() && !inSplitScreenWindowingMode()) {
3969 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
3970 return true;
3971 }
3972 }
3973 return false;
3974 }
3975
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003976 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
3977 boolean traverseTopToBottom) {
3978 if (traverseTopToBottom) {
Robert Carr9785cf32018-04-25 15:06:07 -07003979 if (applyImeWindowsIfNeeded(callback, traverseTopToBottom)
3980 || callback.apply(this)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003981 return true;
3982 }
3983 } else {
Robert Carr9785cf32018-04-25 15:06:07 -07003984 if (callback.apply(this)
3985 || applyImeWindowsIfNeeded(callback, traverseTopToBottom)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003986 return true;
3987 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003988 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003989 return false;
3990 }
3991
Wale Ogunwaled1880962016-11-08 10:31:59 -08003992 WindowState getWindow(Predicate<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003993 if (mChildren.isEmpty()) {
3994 return callback.test(this) ? this : null;
3995 }
3996
3997 // We want to consume the positive sublayer children first because they need to appear
3998 // above the parent, then this window (the parent), and then the negative sublayer children
3999 // because they need to appear above the parent.
4000 int i = mChildren.size() - 1;
4001 WindowState child = mChildren.get(i);
4002
4003 while (i >= 0 && child.mSubLayer >= 0) {
4004 if (callback.test(child)) {
4005 return child;
4006 }
4007 --i;
4008 if (i < 0) {
4009 break;
4010 }
4011 child = mChildren.get(i);
4012 }
4013
Wale Ogunwaled1880962016-11-08 10:31:59 -08004014 if (callback.test(this)) {
4015 return this;
4016 }
Wale Ogunwale34247952017-02-19 11:57:53 -08004017
4018 while (i >= 0) {
4019 if (callback.test(child)) {
4020 return child;
4021 }
4022 --i;
4023 if (i < 0) {
4024 break;
4025 }
4026 child = mChildren.get(i);
4027 }
4028
4029 return null;
Wale Ogunwaled1880962016-11-08 10:31:59 -08004030 }
4031
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01004032 /**
4033 * @return True if we our one of our ancestors has {@link #mAnimatingExit} set to true, false
4034 * otherwise.
4035 */
4036 @VisibleForTesting
4037 boolean isSelfOrAncestorWindowAnimatingExit() {
4038 WindowState window = this;
4039 do {
4040 if (window.mAnimatingExit) {
4041 return true;
4042 }
4043 window = window.getParentWindow();
4044 } while (window != null);
4045 return false;
4046 }
4047
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004048 void onExitAnimationDone() {
4049 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
4050 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
Jorim Jaggia5e10572017-11-15 14:36:26 +01004051 + " selfAnimating=" + isSelfAnimating());
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004052
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004053 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004054 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +01004055 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004056 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004057 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004058 }
4059 }
4060
4061 if (mWinAnimator.mEnteringAnimation) {
4062 mWinAnimator.mEnteringAnimation = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004063 mWmService.requestTraversal();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004064 // System windows don't have an activity and an app token as a result, but need a way
4065 // to be informed about their entrance animation end.
4066 if (mAppToken == null) {
4067 try {
4068 mClient.dispatchWindowShown();
4069 } catch (RemoteException e) {
4070 }
4071 }
4072 }
4073
Jorim Jaggia5e10572017-11-15 14:36:26 +01004074 if (isSelfAnimating()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004075 return;
4076 }
4077
Jorim Jaggia5e10572017-11-15 14:36:26 +01004078 //TODO (multidisplay): Accessibility is supported only for the default display.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004079 if (mWmService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
4080 mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004081 }
4082
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01004083 if (!isSelfOrAncestorWindowAnimatingExit()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004084 return;
4085 }
4086
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07004087 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004088 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
4089
4090 mDestroying = true;
4091
4092 final boolean hasSurface = mWinAnimator.hasSurface();
Jorim Jaggi50575902018-04-10 17:49:30 +02004093
4094 // Use pendingTransaction here so hide is done the same transaction as the other
4095 // animations when exiting
4096 mWinAnimator.hide(getPendingTransaction(), "onExitAnimationDone");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004097
4098 // If we have an app token, we ask it to destroy the surface for us, so that it can take
4099 // care to ensure the activity has actually stopped and the surface is not still in use.
4100 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
4101 // transaction.
4102 if (mAppToken != null) {
4103 mAppToken.destroySurfaces();
4104 } else {
4105 if (hasSurface) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004106 mWmService.mDestroySurface.add(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004107 }
4108 if (mRemoveOnExit) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004109 mWmService.mPendingRemove.add(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004110 mRemoveOnExit = false;
4111 }
4112 }
4113 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07004114 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004115 }
Dan Willemsen117197f2016-07-30 13:02:59 -07004116
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004117 boolean clearAnimatingFlags() {
4118 boolean didSomething = false;
4119 // We don't want to clear it out for windows that get replaced, because the
4120 // animation depends on the flag to remove the replaced window.
4121 //
4122 // We also don't clear the mAnimatingExit flag for windows which have the
4123 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4124 // by the client. We should let animation proceed and not clear this flag or
4125 // they won't eventually be removed by WindowStateAnimator#finishExit.
4126 if (!mWillReplaceWindow && !mRemoveOnExit) {
4127 // Clear mAnimating flag together with mAnimatingExit. When animation
4128 // changes from exiting to entering, we need to clear this flag until the
4129 // new animation gets applied, so that isAnimationStarting() becomes true
4130 // until then.
4131 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4132 // placement for this window during this period, one or more frame will
4133 // show up with wrong position or scale.
4134 if (mAnimatingExit) {
4135 mAnimatingExit = false;
4136 didSomething = true;
4137 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004138 if (mDestroying) {
4139 mDestroying = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004140 mWmService.mDestroySurface.remove(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004141 didSomething = true;
4142 }
4143 }
4144
4145 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004146 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004147 }
4148
4149 return didSomething;
4150 }
4151
Winson4b4ba902016-07-27 19:45:52 -07004152 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004153 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004154 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004155
4156 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004157 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004158 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004159 c.hideWallpaperWindow(wasDeferred, reason);
4160 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004161 if (!mWinAnimator.mLastHidden || wasDeferred) {
4162 mWinAnimator.hide(reason);
Tiger Huang50d45462018-05-25 22:57:52 +08004163 getDisplayContent().mWallpaperController.mDeferredHideWallpaper = null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004164 dispatchWallpaperVisibility(false);
4165 final DisplayContent displayContent = getDisplayContent();
4166 if (displayContent != null) {
4167 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
Tiger Huang50d45462018-05-25 22:57:52 +08004168 if (DEBUG_LAYOUT_REPEATS) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004169 mWmService.mWindowPlacerLocked.debugLayoutRepeats("hideWallpaperWindow " + this,
Tiger Huang50d45462018-05-25 22:57:52 +08004170 displayContent.pendingLayoutChanges);
4171 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004172 }
4173 }
4174 }
4175
4176 /**
4177 * Check wallpaper window for visibility change and notify window if so.
4178 * @param visible Current visibility.
4179 */
4180 void dispatchWallpaperVisibility(final boolean visible) {
4181 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07004182 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004183
4184 // Only send notification if the visibility actually changed and we are not trying to hide
4185 // the wallpaper when we are deferring hiding of the wallpaper.
4186 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4187 mWallpaperVisible = visible;
4188 try {
4189 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4190 "Updating vis of wallpaper " + this
4191 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4192 mClient.dispatchAppVisibility(visible);
4193 } catch (RemoteException e) {
4194 }
4195 }
4196 }
4197
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004198 boolean hasVisibleNotDrawnWallpaper() {
4199 if (mWallpaperVisible && !isDrawnLw()) {
4200 return true;
4201 }
4202 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004203 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004204 if (c.hasVisibleNotDrawnWallpaper()) {
4205 return true;
4206 }
4207 }
4208 return false;
4209 }
4210
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004211 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4212 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004213 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004214 c.updateReportedVisibility(results);
4215 }
4216
4217 if (mAppFreezing || mViewVisibility != View.VISIBLE
4218 || mAttrs.type == TYPE_APPLICATION_STARTING
4219 || mDestroying) {
4220 return;
4221 }
4222 if (DEBUG_VISIBILITY) {
4223 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02004224 + ", animating=" + isAnimating());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004225 if (!isDrawnLw()) {
4226 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4227 + " pv=" + mPolicyVisibility
4228 + " mDrawState=" + mWinAnimator.mDrawState
4229 + " ph=" + isParentWindowHidden()
4230 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02004231 + " a=" + isAnimating());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004232 }
4233 }
4234
4235 results.numInteresting++;
4236 if (isDrawnLw()) {
4237 results.numDrawn++;
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02004238 if (!isAnimating()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004239 results.numVisible++;
4240 }
4241 results.nowGone = false;
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02004242 } else if (isAnimating()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004243 results.nowGone = false;
4244 }
4245 }
4246
Robert Carr683e05d2018-04-18 15:11:04 -07004247 private boolean skipDecorCrop() {
4248 // The decor frame is used to specify the region not covered by the system
4249 // decorations (nav bar, status bar). In case this is empty, for example with
4250 // FLAG_TRANSLUCENT_NAVIGATION, we don't need to do any cropping.
chaviw553b0212018-07-12 13:37:01 -07004251 if (mWindowFrames.mDecorFrame.isEmpty()) {
Robert Carr683e05d2018-04-18 15:11:04 -07004252 return true;
4253 }
4254
4255 // But if we have a frame, and are an application window, then we must be cropped.
4256 if (mAppToken != null) {
4257 return false;
4258 }
4259
4260 // For non application windows, we may be allowed to extend over the decor bars
4261 // depending on our type and permissions assosciated with our token.
4262 return mToken.canLayerAboveSystemBars();
4263 }
4264
Robert Carrfbbde852016-10-18 11:02:28 -07004265 /**
4266 * Calculate the window crop according to system decor policy. In general this is
4267 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4268 * special cases. This rectangle is in screen space.
4269 */
4270 void calculatePolicyCrop(Rect policyCrop) {
4271 final DisplayContent displayContent = getDisplayContent();
Robert Carrfbbde852016-10-18 11:02:28 -07004272
Riddle Hsub398da32019-01-21 21:48:16 +08004273 if (!displayContent.isDefaultDisplay && !displayContent.supportsSystemDecorations()) {
Robert Carrfbbde852016-10-18 11:02:28 -07004274 // On a different display there is no system decor. Crop the window
4275 // by the screen boundaries.
Riddle Hsub398da32019-01-21 21:48:16 +08004276 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
chaviw9c81e632018-07-31 11:17:52 -07004277 policyCrop.set(0, 0, mWindowFrames.mCompatFrame.width(),
4278 mWindowFrames.mCompatFrame.height());
4279 policyCrop.intersect(-mWindowFrames.mCompatFrame.left, -mWindowFrames.mCompatFrame.top,
4280 displayInfo.logicalWidth - mWindowFrames.mCompatFrame.left,
4281 displayInfo.logicalHeight - mWindowFrames.mCompatFrame.top);
Robert Carr683e05d2018-04-18 15:11:04 -07004282 } else if (skipDecorCrop()) {
Robert Carrfbbde852016-10-18 11:02:28 -07004283 // Windows without policy decor aren't cropped.
chaviw9c81e632018-07-31 11:17:52 -07004284 policyCrop.set(0, 0, mWindowFrames.mCompatFrame.width(),
4285 mWindowFrames.mCompatFrame.height());
Robert Carrfbbde852016-10-18 11:02:28 -07004286 } else {
4287 // Crop to the system decor specified by policy.
4288 calculateSystemDecorRect(policyCrop);
4289 }
4290 }
4291
4292 /**
4293 * The system decor rect is the region of the window which is not covered
4294 * by system decorations.
4295 */
4296 private void calculateSystemDecorRect(Rect systemDecorRect) {
chaviw553b0212018-07-12 13:37:01 -07004297 final Rect decorRect = mWindowFrames.mDecorFrame;
chaviw492139a2018-07-16 16:07:35 -07004298 final int width = mWindowFrames.mFrame.width();
4299 final int height = mWindowFrames.mFrame.height();
Robert Carrfbbde852016-10-18 11:02:28 -07004300
chaviw492139a2018-07-16 16:07:35 -07004301 final int left = mWindowFrames.mFrame.left;
4302 final int top = mWindowFrames.mFrame.top;
Robert Carrfbbde852016-10-18 11:02:28 -07004303
4304 // Initialize the decor rect to the entire frame.
4305 if (isDockedResizing()) {
4306 // If we are resizing with the divider, the task bounds might be smaller than the
4307 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4308 // want in this case in order to avoid holes.
4309 //
4310 // We take care to not shrink the width, for surfaces which are larger than
4311 // the display region. Of course this area will not eventually be visible
4312 // but if we truncate the width now, we will calculate incorrectly
4313 // when adjusting to the stack bounds.
4314 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4315 systemDecorRect.set(0, 0,
4316 Math.max(width, displayInfo.logicalWidth),
4317 Math.max(height, displayInfo.logicalHeight));
4318 } else {
4319 systemDecorRect.set(0, 0, width, height);
4320 }
4321
4322 // If a freeform window is animating from a position where it would be cutoff, it would be
4323 // cutoff during the animation. We don't want that, so for the duration of the animation
4324 // we ignore the decor cropping and depend on layering to position windows correctly.
chaviw95136622018-04-09 15:20:06 -07004325
4326 // We also ignore cropping when the window is currently being drag resized in split screen
4327 // to prevent issues with the crop for screenshot.
4328 final boolean cropToDecor =
4329 !(inFreeformWindowingMode() && isAnimatingLw()) && !isDockedResizing();
Robert Carrfbbde852016-10-18 11:02:28 -07004330 if (cropToDecor) {
4331 // Intersect with the decor rect, offsetted by window position.
4332 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
4333 decorRect.right - left, decorRect.bottom - top);
4334 }
4335
4336 // If size compatibility is being applied to the window, the
4337 // surface is scaled relative to the screen. Also apply this
4338 // scaling to the crop rect. We aren't using the standard rect
4339 // scale function because we want to round things to make the crop
4340 // always round to a larger rect to ensure we don't crop too
4341 // much and hide part of the window that should be seen.
Riddle Hsub398da32019-01-21 21:48:16 +08004342 if (inSizeCompatMode() && mInvGlobalScale != 1.0f) {
Robert Carrfbbde852016-10-18 11:02:28 -07004343 final float scale = mInvGlobalScale;
4344 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
4345 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
4346 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
4347 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
4348 }
4349
4350 }
4351
4352 /**
4353 * Expand the given rectangle by this windows surface insets. This
4354 * takes you from the 'window size' to the 'surface size'.
4355 * The surface insets are positive in each direction, so we inset by
4356 * the inverse.
4357 */
4358 void expandForSurfaceInsets(Rect r) {
4359 r.inset(-mAttrs.surfaceInsets.left,
4360 -mAttrs.surfaceInsets.top,
4361 -mAttrs.surfaceInsets.right,
4362 -mAttrs.surfaceInsets.bottom);
4363 }
4364
Robert Carrc91d1c32017-02-15 19:37:46 -08004365 boolean surfaceInsetsChanging() {
4366 return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets);
4367 }
4368
Bryce Leef858b572017-06-29 14:03:33 -07004369 int relayoutVisibleWindow(int result, int attrChanges, int oldVisibility) {
Robert Carrecc06b32017-04-18 14:25:10 -07004370 final boolean wasVisible = isVisibleLw();
4371
4372 result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0;
Robert Carr7b3d11d2018-03-15 14:34:45 -07004373
Robert Carrc91d1c32017-02-15 19:37:46 -08004374 if (mAnimatingExit) {
4375 Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit="
4376 + mRemoveOnExit + ", mDestroying=" + mDestroying);
4377
4378 mWinAnimator.cancelExitAnimationForNextAnimationLocked();
4379 mAnimatingExit = false;
4380 }
4381 if (mDestroying) {
4382 mDestroying = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004383 mWmService.mDestroySurface.remove(this);
Robert Carrc91d1c32017-02-15 19:37:46 -08004384 }
4385 if (oldVisibility == View.GONE) {
4386 mWinAnimator.mEnterAnimationPending = true;
4387 }
4388
Andrii Kulian8ee72852017-03-10 10:36:45 -08004389 mLastVisibleLayoutRotation = getDisplayContent().getRotation();
Robert Carrc91d1c32017-02-15 19:37:46 -08004390
4391 mWinAnimator.mEnteringAnimation = true;
Bryce Leeae73ba42017-05-05 09:58:25 -07004392
Bryce Leef858b572017-06-29 14:03:33 -07004393 prepareWindowToDisplayDuringRelayout(wasVisible);
Bryce Leeae73ba42017-05-05 09:58:25 -07004394
Robert Carrc91d1c32017-02-15 19:37:46 -08004395 if ((attrChanges & FORMAT_CHANGED) != 0) {
4396 // If the format can't be changed in place, preserve the old surface until the app draws
4397 // on the new one. This prevents blinking when we change elevation of freeform and
4398 // pinned windows.
4399 if (!mWinAnimator.tryChangeFormatInPlaceLocked()) {
4400 mWinAnimator.preserveSurfaceLocked();
4401 result |= RELAYOUT_RES_SURFACE_CHANGED
4402 | RELAYOUT_RES_FIRST_TIME;
4403 }
4404 }
4405
4406 // When we change the Surface size, in scenarios which may require changing
4407 // the surface position in sync with the resize, we use a preserved surface
4408 // so we can freeze it while waiting for the client to report draw on the newly
Robert Carrc6d5af52018-02-26 17:46:00 -08004409 // sized surface. At the moment this logic is only in place for switching
4410 // in and out of the big surface for split screen resize.
4411 if (isDragResizeChanged()) {
Robert Carrc91d1c32017-02-15 19:37:46 -08004412 setDragResizing();
Robert Carrc91d1c32017-02-15 19:37:46 -08004413 // We can only change top level windows to the full-screen surface when
4414 // resizing (as we only have one full-screen surface). So there is no need
4415 // to preserve and destroy windows which are attached to another, they
4416 // will keep their surface and its size may change over time.
4417 if (mHasSurface && !isChildWindow()) {
4418 mWinAnimator.preserveSurfaceLocked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08004419 result |= RELAYOUT_RES_SURFACE_CHANGED |
4420 RELAYOUT_RES_FIRST_TIME;
Robert Carrc91d1c32017-02-15 19:37:46 -08004421 }
4422 }
4423 final boolean freeformResizing = isDragResizing()
4424 && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
4425 final boolean dockedResizing = isDragResizing()
4426 && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
4427 result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0;
4428 result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004429 return result;
4430 }
4431
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004432 /**
4433 * @return True if this window has been laid out at least once; false otherwise.
4434 */
4435 boolean isLaidOut() {
4436 return mLayoutSeq != -1;
4437 }
4438
4439 /**
4440 * Updates the last inset values to the current ones.
4441 */
4442 void updateLastInsetValues() {
chaviw9c81e632018-07-31 11:17:52 -07004443 mWindowFrames.updateLastInsetValues();
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004444 }
4445
Jorim Jaggia5e10572017-11-15 14:36:26 +01004446 void startAnimation(Animation anim) {
Jorim Jaggia2759b22019-01-24 13:21:40 +01004447
4448 // If we are an inset provider, all our animations are driven by the inset client.
4449 if (mInsetProvider != null && mInsetProvider.isControllable()) {
4450 return;
4451 }
4452
Jorim Jaggia5e10572017-11-15 14:36:26 +01004453 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
chaviw492139a2018-07-16 16:07:35 -07004454 anim.initialize(mWindowFrames.mFrame.width(), mWindowFrames.mFrame.height(),
Jorim Jaggia5e10572017-11-15 14:36:26 +01004455 displayInfo.appWidth, displayInfo.appHeight);
4456 anim.restrictDuration(MAX_ANIMATION_DURATION);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004457 anim.scaleCurrentDuration(mWmService.getWindowAnimationScaleLocked());
Jorim Jaggia5e10572017-11-15 14:36:26 +01004458 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi2e3c31d2017-11-20 19:49:00 +01004459 new WindowAnimationSpec(anim, mSurfacePosition, false /* canSkipFirstFrame */),
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004460 mWmService.mSurfaceAnimationRunner);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004461 startAnimation(mPendingTransaction, adapter);
4462 commitPendingTransaction();
4463 }
4464
chaviw161ea3e2018-01-31 12:01:12 -08004465 private void startMoveAnimation(int left, int top) {
Jorim Jaggia2759b22019-01-24 13:21:40 +01004466
4467 // If we are an inset provider, all our animations are driven by the inset client.
4468 if (mInsetProvider != null && mInsetProvider.isControllable()) {
4469 return;
4470 }
4471
Jorim Jaggia5e10572017-11-15 14:36:26 +01004472 if (DEBUG_ANIM) Slog.v(TAG, "Setting move animation on " + this);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004473 final Point oldPosition = new Point();
4474 final Point newPosition = new Point();
chaviw492139a2018-07-16 16:07:35 -07004475 transformFrameToSurfacePosition(mWindowFrames.mLastFrame.left, mWindowFrames.mLastFrame.top,
4476 oldPosition);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004477 transformFrameToSurfacePosition(left, top, newPosition);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004478 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004479 new MoveAnimationSpec(oldPosition.x, oldPosition.y, newPosition.x, newPosition.y),
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004480 mWmService.mSurfaceAnimationRunner);
chaviw161ea3e2018-01-31 12:01:12 -08004481 startAnimation(getPendingTransaction(), adapter);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004482 }
4483
4484 private void startAnimation(Transaction t, AnimationAdapter adapter) {
4485 startAnimation(t, adapter, mWinAnimator.mLastHidden);
4486 }
4487
4488 @Override
4489 protected void onAnimationFinished() {
4490 mWinAnimator.onAnimationFinished();
4491 }
4492
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004493 /**
4494 * Retrieves the current transformation matrix of the window, relative to the display.
4495 *
4496 * @param float9 A temporary array of 9 floats.
4497 * @param outMatrix Matrix to fill in the transformation.
4498 */
4499 void getTransformationMatrix(float[] float9, Matrix outMatrix) {
4500 float9[Matrix.MSCALE_X] = mWinAnimator.mDsDx;
4501 float9[Matrix.MSKEW_Y] = mWinAnimator.mDtDx;
4502 float9[Matrix.MSKEW_X] = mWinAnimator.mDtDy;
4503 float9[Matrix.MSCALE_Y] = mWinAnimator.mDsDy;
Robert Carr217e7cc2018-01-31 18:08:39 -08004504 int x = mSurfacePosition.x;
4505 int y = mSurfacePosition.y;
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004506
4507 // If changed, also adjust transformFrameToSurfacePosition
4508 final WindowContainer parent = getParent();
4509 if (isChildWindow()) {
4510 final WindowState parentWindow = getParentWindow();
chaviw492139a2018-07-16 16:07:35 -07004511 x += parentWindow.mWindowFrames.mFrame.left - parentWindow.mAttrs.surfaceInsets.left;
4512 y += parentWindow.mWindowFrames.mFrame.top - parentWindow.mAttrs.surfaceInsets.top;
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004513 } else if (parent != null) {
4514 final Rect parentBounds = parent.getBounds();
4515 x += parentBounds.left;
4516 y += parentBounds.top;
4517 }
4518 float9[Matrix.MTRANS_X] = x;
4519 float9[Matrix.MTRANS_Y] = y;
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004520 float9[Matrix.MPERSP_0] = 0;
4521 float9[Matrix.MPERSP_1] = 0;
4522 float9[Matrix.MPERSP_2] = 1;
4523 outMatrix.setValues(float9);
4524 }
4525
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004526 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4527 // access to its windows children. Need to investigate re-writing
4528 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4529 static final class UpdateReportedVisibilityResults {
4530 int numInteresting;
4531 int numVisible;
4532 int numDrawn;
4533 boolean nowGone = true;
4534
4535 void reset() {
4536 numInteresting = 0;
4537 numVisible = 0;
4538 numDrawn = 0;
4539 nowGone = true;
4540 }
4541 }
Robert Carraf422a82017-04-10 18:34:33 -07004542
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004543 private static final class WindowId extends IWindowId.Stub {
4544 private final WeakReference<WindowState> mOuter;
4545
4546 private WindowId(WindowState outer) {
4547
4548 // Use a weak reference for the outer class. This is important to prevent the following
4549 // leak: Since we send this class to the client process, binder will keep it alive as
4550 // long as the client keeps it alive. Now, if the window is removed, we need to clear
4551 // out our reference so even though this class is kept alive we don't leak WindowState,
4552 // which can keep a whole lot of classes alive.
4553 mOuter = new WeakReference<>(outer);
4554 }
4555
4556 @Override
4557 public void registerFocusObserver(IWindowFocusObserver observer) {
4558 final WindowState outer = mOuter.get();
4559 if (outer != null) {
4560 outer.registerFocusObserver(observer);
4561 }
4562 }
4563 @Override
4564 public void unregisterFocusObserver(IWindowFocusObserver observer) {
4565 final WindowState outer = mOuter.get();
4566 if (outer != null) {
4567 outer.unregisterFocusObserver(observer);
4568 }
4569 }
4570 @Override
4571 public boolean isFocused() {
4572 final WindowState outer = mOuter.get();
Tiger Huang1e5b10a2018-07-30 20:19:51 +08004573 if (outer != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004574 synchronized (outer.mWmService.mGlobalLock) {
Tiger Huang1e5b10a2018-07-30 20:19:51 +08004575 return outer.isFocused();
4576 }
4577 }
4578 return false;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004579 }
4580 }
4581
Robert Carrb1579c82017-09-05 14:54:47 -07004582
4583 @Override
4584 boolean shouldMagnify() {
4585 if (mAttrs.type == TYPE_INPUT_METHOD ||
Robert Carree4d4b92017-11-22 12:21:46 -08004586 mAttrs.type == TYPE_INPUT_METHOD_DIALOG ||
4587 mAttrs.type == TYPE_MAGNIFICATION_OVERLAY ||
4588 mAttrs.type == TYPE_NAVIGATION_BAR ||
4589 // It's tempting to wonder: Have we forgotten the rounded corners overlay?
4590 // worry not: it's a fake TYPE_NAVIGATION_BAR_PANEL
Eugene Susla9552b262018-03-13 12:24:50 -07004591 mAttrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Robert Carrb1579c82017-09-05 14:54:47 -07004592 return false;
4593 }
4594 return true;
4595 }
4596
4597 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004598 SurfaceSession getSession() {
4599 if (mSession.mSurfaceSession != null) {
4600 return mSession.mSurfaceSession;
4601 } else {
4602 return getParent().getSession();
4603 }
4604 }
4605
4606 @Override
4607 boolean needsZBoost() {
lumarkff0ab692018-11-05 20:32:30 +08004608 final WindowState inputMethodTarget = getDisplayContent().mInputMethodTarget;
4609 if (mIsImWindow && inputMethodTarget != null) {
4610 final AppWindowToken appToken = inputMethodTarget.mAppToken;
Jorim Jaggib0fc8172017-11-23 17:04:08 +00004611 if (appToken != null) {
4612 return appToken.needsZBoost();
4613 }
4614 }
4615 return mWillReplaceWindow;
Robert Carrb1579c82017-09-05 14:54:47 -07004616 }
4617
Robert Carrf07ef9e2017-11-21 12:12:49 -08004618 private void applyDims(Dimmer dimmer) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07004619 if (!mAnimatingExit && mAppDied) {
4620 mIsDimming = true;
chaviw2fb06bc2018-01-19 17:09:15 -08004621 dimmer.dimAbove(getPendingTransaction(), this, DEFAULT_DIM_AMOUNT_DEAD_WINDOW);
chaviwebcbc342018-02-07 13:19:00 -08004622 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0 && isVisibleNow() && !mHidden) {
chaviw14076152018-02-02 14:51:20 -08004623 // Only show a dim behind when the following is satisfied:
4624 // 1. The window has the flag FLAG_DIM_BEHIND
4625 // 2. The WindowToken is not hidden so dims aren't shown when the window is exiting.
4626 // 3. The WS is considered visible according to the isVisible() method
chaviwebcbc342018-02-07 13:19:00 -08004627 // 4. The WS is not hidden.
Robert Carrf59b8dd2017-10-02 18:58:36 -07004628 mIsDimming = true;
chaviw2fb06bc2018-01-19 17:09:15 -08004629 dimmer.dimBelow(getPendingTransaction(), this, mAttrs.dimAmount);
Robert Carrf59b8dd2017-10-02 18:58:36 -07004630 }
Robert Carrf07ef9e2017-11-21 12:12:49 -08004631 }
4632
4633 @Override
4634 void prepareSurfaces() {
4635 final Dimmer dimmer = getDimmer();
4636 mIsDimming = false;
4637 if (dimmer != null) {
4638 applyDims(dimmer);
4639 }
chaviw2f0567b2018-01-29 16:22:02 -08004640 updateSurfacePosition();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004641
Robert Carrb1579c82017-09-05 14:54:47 -07004642 mWinAnimator.prepareSurfaceLocked(true);
4643 super.prepareSurfaces();
4644 }
4645
4646 @Override
Jorim Jaggia5e10572017-11-15 14:36:26 +01004647 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
4648 super.onAnimationLeashCreated(t, leash);
4649
4650 // Leash is now responsible for position, so set our position to 0.
4651 t.setPosition(mSurfaceControl, 0, 0);
chaviw3e751af2018-01-11 11:22:39 -08004652 mLastSurfacePosition.set(0, 0);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004653 }
4654
4655 @Override
4656 public void onAnimationLeashDestroyed(Transaction t) {
4657 super.onAnimationLeashDestroyed(t);
4658 updateSurfacePosition(t);
4659 }
4660
chaviwe07246a2017-12-12 16:18:29 -08004661 @Override
chaviw2f0567b2018-01-29 16:22:02 -08004662 void updateSurfacePosition() {
4663 updateSurfacePosition(getPendingTransaction());
4664 }
4665
Vishnu Naird8c664b2018-09-24 12:52:35 -07004666 @VisibleForTesting
4667 void updateSurfacePosition(Transaction t) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01004668 if (mSurfaceControl == null) {
4669 return;
4670 }
4671
chaviw492139a2018-07-16 16:07:35 -07004672 transformFrameToSurfacePosition(mWindowFrames.mFrame.left, mWindowFrames.mFrame.top,
4673 mSurfacePosition);
Robert Carrc6d5af52018-02-26 17:46:00 -08004674
Vishnu Nair83537a72018-07-19 21:27:48 -07004675 // Freeze position while we're unrotated, so the surface remains at the position it was
4676 // prior to the rotation.
Vishnu Nairddd80742018-08-21 14:12:46 -07004677 if (!mSurfaceAnimator.hasLeash() && mPendingSeamlessRotate == null
4678 && !mLastSurfacePosition.equals(mSurfacePosition)) {
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004679 t.setPosition(mSurfaceControl, mSurfacePosition.x, mSurfacePosition.y);
chaviw3e751af2018-01-11 11:22:39 -08004680 mLastSurfacePosition.set(mSurfacePosition.x, mSurfacePosition.y);
Robert Carrc6d5af52018-02-26 17:46:00 -08004681 if (surfaceInsetsChanging() && mWinAnimator.hasSurface()) {
4682 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
4683 t.deferTransactionUntil(mSurfaceControl,
4684 mWinAnimator.mSurfaceController.mSurfaceControl.getHandle(),
chaviwbe43ac82018-04-04 15:14:49 -07004685 getFrameNumber());
Robert Carrc6d5af52018-02-26 17:46:00 -08004686 }
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004687 }
4688 }
4689
4690 private void transformFrameToSurfacePosition(int left, int top, Point outPoint) {
4691 outPoint.set(left, top);
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004692
4693 // If changed, also adjust getTransformationMatrix
chaviwe07246a2017-12-12 16:18:29 -08004694 final WindowContainer parentWindowContainer = getParent();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004695 if (isChildWindow()) {
4696 // TODO: This probably falls apart at some point and we should
4697 // actually compute relative coordinates.
Jorim Jaggi50d3f8f2017-12-27 17:41:25 +01004698
4699 // Since the parent was outset by its surface insets, we need to undo the outsetting
4700 // with insetting by the same amount.
Jorim Jaggia5e10572017-11-15 14:36:26 +01004701 final WindowState parent = getParentWindow();
Riddle Hsub398da32019-01-21 21:48:16 +08004702 transformSurfaceInsetsPosition(mTmpPoint, parent.mAttrs.surfaceInsets);
4703 outPoint.offset(-parent.mWindowFrames.mFrame.left + mTmpPoint.x,
4704 -parent.mWindowFrames.mFrame.top + mTmpPoint.y);
chaviwe07246a2017-12-12 16:18:29 -08004705 } else if (parentWindowContainer != null) {
Evan Roskyed6767f2018-10-26 17:21:06 -07004706 final Rect parentBounds = parentWindowContainer.getDisplayedBounds();
chaviwe07246a2017-12-12 16:18:29 -08004707 outPoint.offset(-parentBounds.left, -parentBounds.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004708 }
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004709
Robert Carr32bcb102018-01-29 15:03:23 -08004710 TaskStack stack = getStack();
4711
4712 // If we have stack outsets, that means the top-left
4713 // will be outset, and we need to inset ourselves
4714 // to account for it. If we actually have shadows we will
4715 // then un-inset ourselves by the surfaceInsets.
4716 if (stack != null) {
4717 final int outset = stack.getStackOutset();
4718 outPoint.offset(outset, outset);
4719 }
4720
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004721 // Expand for surface insets. See WindowState.expandForSurfaceInsets.
Riddle Hsub398da32019-01-21 21:48:16 +08004722 transformSurfaceInsetsPosition(mTmpPoint, mAttrs.surfaceInsets);
4723 outPoint.offset(-mTmpPoint.x, -mTmpPoint.y);
4724 }
4725
4726 /**
4727 * The surface insets from layout parameter are in application coordinate. If the window is
4728 * scaled, the insets also need to be scaled for surface position in global coordinate.
4729 */
4730 private void transformSurfaceInsetsPosition(Point outPos, Rect surfaceInsets) {
4731 if (!inSizeCompatMode()) {
4732 outPos.x = surfaceInsets.left;
4733 outPos.y = surfaceInsets.top;
4734 return;
4735 }
4736 outPos.x = (int) (surfaceInsets.left * mGlobalScale + 0.5f);
4737 outPos.y = (int) (surfaceInsets.top * mGlobalScale + 0.5f);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004738 }
4739
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004740 boolean needsRelativeLayeringToIme() {
4741 // We only use the relative layering mode in split screen, as part of elevating the IME
4742 // and windows above it's target above the docked divider.
4743 if (!inSplitScreenWindowingMode()) {
4744 return false;
4745 }
4746
4747 if (isChildWindow()) {
4748 // If we are a child of the input method target we need this promotion.
4749 if (getParentWindow().isInputMethodTarget()) {
4750 return true;
4751 }
4752 } else if (mAppToken != null) {
4753 // Likewise if we share a token with the Input method target and are ordered
4754 // above it but not necessarily a child (e.g. a Dialog) then we also need
4755 // this promotion.
lumarkff0ab692018-11-05 20:32:30 +08004756 final WindowState imeTarget = getDisplayContent().mInputMethodTarget;
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004757 boolean inTokenWithAndAboveImeTarget = imeTarget != null && imeTarget != this
4758 && imeTarget.mToken == mToken && imeTarget.compareTo(this) <= 0;
4759 return inTokenWithAndAboveImeTarget;
4760 }
4761 return false;
4762 }
4763
Jorim Jaggia5e10572017-11-15 14:36:26 +01004764 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004765 void assignLayer(Transaction t, int layer) {
4766 // See comment in assignRelativeLayerForImeTargetChild
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004767 if (needsRelativeLayeringToIme()) {
4768 getDisplayContent().assignRelativeLayerForImeTargetChild(t, this);
Robert Carrb1579c82017-09-05 14:54:47 -07004769 return;
4770 }
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004771 super.assignLayer(t, layer);
Robert Carrb1579c82017-09-05 14:54:47 -07004772 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07004773
4774 @Override
4775 public boolean isDimming() {
4776 return mIsDimming;
4777 }
Robert Carr0eff1872017-12-01 14:27:04 -08004778
4779 // TODO(b/70040778): We should aim to eliminate the last user of TYPE_APPLICATION_MEDIA
4780 // then we can drop all negative layering on the windowing side and simply inherit
4781 // the default implementation here.
4782 public void assignChildLayers(Transaction t) {
4783 int layer = 1;
4784 for (int i = 0; i < mChildren.size(); i++) {
4785 final WindowState w = mChildren.get(i);
4786
4787 // APPLICATION_MEDIA_OVERLAY needs to go above APPLICATION_MEDIA
4788 // while they both need to go below the main window. However the
4789 // relative layering of multiple APPLICATION_MEDIA/OVERLAY has never
4790 // been defined and so we can use static layers and leave it that way.
4791 if (w.mAttrs.type == TYPE_APPLICATION_MEDIA) {
4792 w.assignLayer(t, -2);
4793 } else if (w.mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) {
4794 w.assignLayer(t, -1);
4795 } else {
4796 w.assignLayer(t, layer);
4797 }
4798 w.assignChildLayers(t);
4799 layer++;
4800 }
4801 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01004802
Andrii Kulian4b6599e2018-01-15 17:24:08 -08004803 /**
4804 * Update a tap exclude region with a rectangular area identified by provided id. The requested
4805 * area will be clipped to the window bounds.
4806 */
4807 void updateTapExcludeRegion(int regionId, int left, int top, int width, int height) {
4808 final DisplayContent currentDisplay = getDisplayContent();
4809 if (currentDisplay == null) {
4810 throw new IllegalStateException("Trying to update window not attached to any display.");
4811 }
4812
4813 if (mTapExcludeRegionHolder == null) {
4814 mTapExcludeRegionHolder = new TapExcludeRegionHolder();
4815
4816 // Make sure that this window is registered as one that provides a tap exclude region
4817 // for its containing display.
4818 currentDisplay.mTapExcludeProvidingWindows.add(this);
4819 }
4820
4821 mTapExcludeRegionHolder.updateRegion(regionId, left, top, width, height);
4822 // Trigger touch exclude region update on current display.
Tiger Huang1e5b10a2018-07-30 20:19:51 +08004823 currentDisplay.updateTouchExcludeRegion();
Tiger Huang04dc4cc2019-01-17 18:41:41 +08004824 // Trigger touchable region update for this window.
4825 currentDisplay.getInputMonitor().updateInputWindowsLw(true /* force */);
Andrii Kulian4b6599e2018-01-15 17:24:08 -08004826 }
4827
Tiger Huang04dc4cc2019-01-17 18:41:41 +08004828 /**
4829 * Union the region with current tap exclude region that this window provides.
4830 *
4831 * @param region The region to be amended. It is on the screen coordinates.
4832 */
Andrii Kulian4b6599e2018-01-15 17:24:08 -08004833 void amendTapExcludeRegion(Region region) {
Tiger Huang04dc4cc2019-01-17 18:41:41 +08004834 final Region tempRegion = Region.obtain();
4835 mTmpRect.set(mWindowFrames.mFrame);
4836 mTmpRect.offsetTo(0, 0);
4837 mTapExcludeRegionHolder.amendRegion(tempRegion, mTmpRect);
4838 // The region held by the holder is on the window coordinates. We need to translate it to
4839 // the screen coordinates.
4840 tempRegion.translate(mWindowFrames.mFrame.left, mWindowFrames.mFrame.top);
4841 region.op(tempRegion, Region.Op.UNION);
4842 tempRegion.recycle();
Andrii Kulian4b6599e2018-01-15 17:24:08 -08004843 }
4844
Robert Carr825581a2018-03-30 14:00:53 -07004845 @Override
4846 public boolean isInputMethodTarget() {
lumarkff0ab692018-11-05 20:32:30 +08004847 return getDisplayContent().mInputMethodTarget == this;
Robert Carr825581a2018-03-30 14:00:53 -07004848 }
4849
chaviwbe43ac82018-04-04 15:14:49 -07004850 long getFrameNumber() {
4851 return mFrameNumber;
4852 }
4853
4854 void setFrameNumber(long frameNumber) {
4855 mFrameNumber = frameNumber;
4856 }
4857
chaviw553b0212018-07-12 13:37:01 -07004858 public void getMaxVisibleBounds(Rect out) {
4859 if (out.isEmpty()) {
4860 out.set(mWindowFrames.mVisibleFrame);
4861 return;
4862 }
4863
4864 if (mWindowFrames.mVisibleFrame.left < out.left) {
4865 out.left = mWindowFrames.mVisibleFrame.left;
4866 }
4867 if (mWindowFrames.mVisibleFrame.top < out.top) {
4868 out.top = mWindowFrames.mVisibleFrame.top;
4869 }
4870 if (mWindowFrames.mVisibleFrame.right > out.right) {
4871 out.right = mWindowFrames.mVisibleFrame.right;
4872 }
4873 if (mWindowFrames.mVisibleFrame.bottom > out.bottom) {
4874 out.bottom = mWindowFrames.mVisibleFrame.bottom;
4875 }
4876 }
4877
chaviw9c81e632018-07-31 11:17:52 -07004878 /**
4879 * Copy the inset values over so they can be sent back to the client when a relayout occurs.
4880 */
4881 void getInsetsForRelayout(Rect outOverscanInsets, Rect outContentInsets, Rect outVisibleInsets,
4882 Rect outStableInsets, Rect outOutsets) {
4883 outOverscanInsets.set(mWindowFrames.mOverscanInsets);
4884 outContentInsets.set(mWindowFrames.mContentInsets);
4885 outVisibleInsets.set(mWindowFrames.mVisibleInsets);
4886 outStableInsets.set(mWindowFrames.mStableInsets);
4887 outOutsets.set(mWindowFrames.mOutsets);
4888
4889 mLastRelayoutContentInsets.set(mWindowFrames.mContentInsets);
4890 }
4891
4892 void getContentInsets(Rect outContentInsets) {
4893 outContentInsets.set(mWindowFrames.mContentInsets);
4894 }
4895
4896 Rect getContentInsets() {
4897 return mWindowFrames.mContentInsets;
4898 }
4899
4900 void getStableInsets(Rect outStableInsets) {
4901 outStableInsets.set(mWindowFrames.mStableInsets);
4902 }
4903
4904 Rect getStableInsets() {
4905 return mWindowFrames.mStableInsets;
4906 }
4907
4908 void resetLastContentInsets() {
4909 mWindowFrames.resetLastContentInsets();
4910 }
4911
4912 Rect getVisibleInsets() {
4913 return mWindowFrames.mVisibleInsets;
4914 }
4915
chaviw1454b392018-08-06 09:54:04 -07004916 @Override
4917 public WindowFrames getWindowFrames() {
4918 return mWindowFrames;
4919 }
4920
4921 void resetContentChanged() {
4922 mWindowFrames.setContentChanged(false);
4923 }
4924
Jorim Jaggif96c90a2018-09-26 16:55:15 +02004925 void setInsetProvider(InsetsSourceProvider insetProvider) {
4926 mInsetProvider = insetProvider;
4927 }
4928
4929 InsetsSourceProvider getInsetProvider() {
4930 return mInsetProvider;
4931 }
4932
Jorim Jaggia5e10572017-11-15 14:36:26 +01004933 private final class MoveAnimationSpec implements AnimationSpec {
4934
4935 private final long mDuration;
4936 private Interpolator mInterpolator;
4937 private Point mFrom = new Point();
4938 private Point mTo = new Point();
4939
4940 private MoveAnimationSpec(int fromX, int fromY, int toX, int toY) {
4941 final Animation anim = AnimationUtils.loadAnimation(mContext,
4942 com.android.internal.R.anim.window_move_from_decor);
Jorim Jaggi08f75cf2018-01-08 14:38:53 +01004943 mDuration = (long)
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004944 (anim.computeDurationHint() * mWmService.getWindowAnimationScaleLocked());
Jorim Jaggia5e10572017-11-15 14:36:26 +01004945 mInterpolator = anim.getInterpolator();
4946 mFrom.set(fromX, fromY);
4947 mTo.set(toX, toY);
4948 }
4949
4950 @Override
4951 public long getDuration() {
4952 return mDuration;
4953 }
4954
4955 @Override
4956 public void apply(Transaction t, SurfaceControl leash, long currentPlayTime) {
4957 final float fraction = (float) currentPlayTime / getDuration();
4958 final float v = mInterpolator.getInterpolation(fraction);
4959 t.setPosition(leash, mFrom.x + (mTo.x - mFrom.x) * v,
4960 mFrom.y + (mTo.y - mFrom.y) * v);
4961 }
Jorim Jaggif75d1612018-02-27 15:05:21 +01004962
4963 @Override
4964 public void dump(PrintWriter pw, String prefix) {
chaviwc65fa582018-08-09 15:33:13 -07004965 pw.println(prefix + "from=" + mFrom
4966 + " to=" + mTo
4967 + " duration=" + mDuration);
Jorim Jaggif75d1612018-02-27 15:05:21 +01004968 }
4969
4970 @Override
4971 public void writeToProtoInner(ProtoOutputStream proto) {
4972 final long token = proto.start(MOVE);
4973 mFrom.writeToProto(proto, FROM);
4974 mTo.writeToProto(proto, TO);
Kweku Adams21b8d262018-03-30 12:19:58 -07004975 proto.write(DURATION_MS, mDuration);
Jorim Jaggif75d1612018-02-27 15:05:21 +01004976 proto.end(token);
4977 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01004978 }
satokcef37fb2011-10-24 21:49:38 +09004979}