blob: 6f044f3d268908f79736e3e52181a3c9ece455c7 [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;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800146import android.app.AppOpsManager;
147import android.content.Context;
148import android.content.res.Configuration;
149import android.graphics.Matrix;
150import android.graphics.PixelFormat;
151import android.graphics.Point;
152import android.graphics.Rect;
153import android.graphics.Region;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700154import android.os.Binder;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700155import android.os.Debug;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800156import android.os.IBinder;
157import android.os.PowerManager;
158import android.os.RemoteCallbackList;
159import android.os.RemoteException;
160import android.os.SystemClock;
161import android.os.Trace;
162import android.os.UserHandle;
163import android.os.WorkSource;
chaviw40234662018-02-07 09:37:16 -0800164import android.provider.Settings;
Phil Weaverbb2f28a2017-12-22 09:44:28 -0800165import android.text.TextUtils;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800166import android.util.DisplayMetrics;
Jorim Jaggie7d2b852017-08-28 17:55:15 +0200167import android.util.MergedConfiguration;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800168import android.util.Slog;
169import android.util.TimeUtils;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700170import android.util.proto.ProtoOutputStream;
Brad Stenningaf596412018-04-02 12:03:19 -0700171import android.view.Display;
Adrian Roos5c6b6222017-11-07 17:36:10 +0100172import android.view.DisplayCutout;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800173import android.view.DisplayInfo;
174import android.view.Gravity;
175import android.view.IApplicationToken;
176import android.view.IWindow;
177import android.view.IWindowFocusObserver;
178import android.view.IWindowId;
179import android.view.InputChannel;
180import android.view.InputEvent;
181import android.view.InputEventReceiver;
Tiger Huang7c610aa2018-10-27 00:01:01 +0800182import android.view.InputWindowHandle;
Vishnu Nairba183352018-11-21 11:16:49 -0800183import android.view.Surface.Rotation;
Robert Carrb1579c82017-09-05 14:54:47 -0700184import android.view.SurfaceControl;
185import android.view.SurfaceSession;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800186import android.view.View;
187import android.view.ViewTreeObserver;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700188import android.view.WindowInfo;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800189import android.view.WindowManager;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100190import android.view.animation.Animation;
191import android.view.animation.AnimationUtils;
192import android.view.animation.Interpolator;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800193
Jorim Jaggi4876b4a2018-01-11 15:43:49 +0100194import com.android.internal.annotations.VisibleForTesting;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800195import com.android.internal.util.ToBooleanFunction;
Adrian Roose99bc052017-11-20 17:55:31 +0100196import com.android.server.policy.WindowManagerPolicy;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100197import com.android.server.wm.LocalAnimationAdapter.AnimationSpec;
chaviw9c81e632018-07-31 11:17:52 -0700198import com.android.server.wm.utils.InsetUtils;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100199import com.android.server.wm.utils.WmDisplayCutout;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800200
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800201import java.io.PrintWriter;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200202import java.lang.ref.WeakReference;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800203import java.util.ArrayList;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700204import java.util.Comparator;
Wale Ogunwaled1880962016-11-08 10:31:59 -0800205import java.util.function.Predicate;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800206
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700207/** A window in the window manager. */
208class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800209 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800210
Skuhne81c524a2015-08-12 13:34:14 -0700211 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700212 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
213 // use hard-coded min sizes for now.
214 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
215 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700216
217 // The thickness of a window resize handle outside the window bounds on the free form workspace
218 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700219 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700220
Craig Mautnere7ae2502012-03-26 17:11:19 -0700221 final WindowManagerPolicy mPolicy;
222 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800223 final Session mSession;
224 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800225 final int mAppOp;
226 // UserId and appId of the owner. Don't display windows of non-current user.
227 final int mOwnerUid;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800228 /** The owner has {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} */
229 final boolean mOwnerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200230 final WindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800231 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700232 // The same object as mToken if this is an app window and null for non-app windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800233 AppWindowToken mAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700234
235 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
236 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800237 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
238 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700239 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800240 final int mBaseLayer;
241 final int mSubLayer;
242 final boolean mLayoutAttached;
243 final boolean mIsImWindow;
244 final boolean mIsWallpaper;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700245 private final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700246 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700247 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800248 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700249 int mSystemUiVisibility;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700250 /**
251 * The visibility of the window based on policy like {@link WindowManagerPolicy}.
252 * Normally set by calling {@link #showLw} and {@link #hideLw}.
253 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800254 boolean mPolicyVisibility = true;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700255 /**
256 * What {@link #mPolicyVisibility} should be set to after a transition animation.
257 * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and
258 * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit
259 * animation is done.
260 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800261 boolean mPolicyVisibilityAfterAnim = true;
Suprabh Shukla69c71422018-04-02 18:39:01 -0700262 // overlay window is hidden because the owning app is suspended
263 private boolean mHiddenWhileSuspended;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700264 private boolean mAppOpVisibility = true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700265 boolean mPermanentlyHidden; // the window should never be shown again
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700266 // This is a non-system overlay window that is currently force hidden.
267 private boolean mForceHideNonSystemOverlayWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800268 boolean mAppFreezing;
chaviwebcbc342018-02-07 13:19:00 -0800269 boolean mHidden = true; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800270 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700271 private boolean mDragResizing;
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200272 private boolean mDragResizingChangeReported = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700273 private int mResizeMode;
Vishnu Nair83537a72018-07-19 21:27:48 -0700274 /**
275 * Special mode that is intended only for the rounded corner overlay: during rotation
276 * transition, we un-rotate the window token such that the window appears as it did before the
277 * rotation.
Vishnu Nair83537a72018-07-19 21:27:48 -0700278 */
279 final boolean mForceSeamlesslyRotate;
Vishnu Nairddd80742018-08-21 14:12:46 -0700280 SeamlessRotator mPendingSeamlessRotate;
281 long mFinishSeamlessRotateFrameNumber;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700282
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700283 private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800284
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700285 /**
286 * The window size that was requested by the application. These are in
287 * the application's coordinate space (without compatibility scale applied).
288 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800289 int mRequestedWidth;
290 int mRequestedHeight;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700291 private int mLastRequestedWidth;
292 private int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700293
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800294 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800295 boolean mHaveFrame;
296 boolean mObscured;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800297
298 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700299
Andrii Kulian9d91ca62016-09-29 22:28:09 -0700300 /**
301 * Used to store last reported to client configuration and check if we have newer available.
302 * We'll send configuration to client only if it is different from the last applied one and
303 * client won't perform unnecessary updates.
304 */
Bryce Lee2b17afd2017-09-21 10:38:20 -0700305 private final MergedConfiguration mLastReportedConfiguration = new MergedConfiguration();
Craig Mautnera2c77052012-03-26 12:14:43 -0700306
Yunfan Chen75157d72018-07-27 14:47:21 +0900307 private final Configuration mTempConfiguration = new Configuration();
308
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700309 /**
Robert Carr18f622f2017-05-08 11:20:43 -0700310 * The last content insets returned to the client in relayout. We use
311 * these in the bounds animation to ensure we only observe inset changes
312 * at the same time that a client resizes it's surface so that we may use
313 * the geometryAppliesWithResize synchronization mechanism to keep
314 * the contents in place.
315 */
316 final Rect mLastRelayoutContentInsets = new Rect();
317
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700318 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800319 * Set to true if we are waiting for this window to receive its
320 * given internal insets before laying out other windows based on it.
321 */
322 boolean mGivenInsetsPending;
323
324 /**
325 * These are the content insets that were given during layout for
326 * this window, to be applied to windows behind it.
327 */
328 final Rect mGivenContentInsets = new Rect();
329
330 /**
331 * These are the visible insets that were given during layout for
332 * this window, to be applied to windows behind it.
333 */
334 final Rect mGivenVisibleInsets = new Rect();
335
336 /**
337 * This is the given touchable area relative to the window frame, or null if none.
338 */
339 final Region mGivenTouchableRegion = new Region();
340
341 /**
342 * Flag indicating whether the touchable region should be adjusted by
343 * the visible insets; if false the area outside the visible insets is
344 * NOT touchable, so we must use those to adjust the frame during hit
345 * tests.
346 */
347 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
348
349 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400350 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700351 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800352 float mHScale=1, mVScale=1;
353 float mLastHScale=1, mLastVScale=1;
354 final Matrix mTmpMatrix = new Matrix();
355
chaviw553b0212018-07-12 13:37:01 -0700356 private final WindowFrames mWindowFrames = new WindowFrames();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700357
Jorim Jaggidc249c42015-12-15 14:57:31 -0800358 /**
359 * Usually empty. Set to the task's tempInsetFrame. See
Wale Ogunwale04d9cb52018-04-30 13:55:07 -0700360 *{@link android.app.IActivityTaskManager#resizeDockedStack}.
Jorim Jaggidc249c42015-12-15 14:57:31 -0800361 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700362 private final Rect mInsetFrame = new Rect();
Jorim Jaggidc249c42015-12-15 14:57:31 -0800363
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800364 // If a window showing a wallpaper: the requested offset for the
365 // wallpaper; if a wallpaper window: the currently applied offset.
366 float mWallpaperX = -1;
367 float mWallpaperY = -1;
368
369 // If a window showing a wallpaper: what fraction of the offset
370 // range corresponds to a full virtual screen.
371 float mWallpaperXStep = -1;
372 float mWallpaperYStep = -1;
373
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700374 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
375 // to its window; if a wallpaper window: not used.
376 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
377 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
378
Craig Mautner2268e7e2012-12-13 15:40:00 -0800379 /**
380 * This is set after IWindowSession.relayout() has been called at
381 * least once for the window. It allows us to detect the situation
382 * where we don't yet have a surface, but should have one soon, so
383 * we can give the window focus before waiting for the relayout.
384 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800385 boolean mRelayoutCalled;
386
Robert Carrfed10072016-05-26 11:48:49 -0700387 boolean mInRelayout;
388
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800389 /**
390 * If the application has called relayout() with changes that can
391 * impact its window's size, we need to perform a layout pass on it
392 * even if it is not currently visible for layout. This is set
393 * when in that case until the layout is done.
394 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800395 boolean mLayoutNeeded;
396
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800397 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800398 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800399
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800400 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800401 boolean mDestroying;
402
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800403 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800404 boolean mRemoveOnExit;
405
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800406 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800407 * Whether the app died while it was visible, if true we might need
408 * to continue to show it until it's restarted.
409 */
410 boolean mAppDied;
411
412 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800413 * Set when the orientation is changing and this window has not yet
414 * been updated for the new orientation.
415 */
Bryce Lee8c3cf382017-07-06 19:47:10 -0700416 private boolean mOrientationChanging;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800417
Dianne Hackborna57c6952013-03-29 14:46:40 -0700418 /**
Robert Carr9c1c3a02017-08-08 12:59:01 -0700419 * Sometimes in addition to the mOrientationChanging
420 * flag we report that the orientation is changing
421 * due to a mismatch in current and reported configuration.
422 *
423 * In the case of timeout we still need to make sure we
424 * leave the orientation changing state though, so we
425 * use this as a special time out escape hatch.
426 */
427 private boolean mOrientationChangeTimedOut;
428
429 /**
Robert Carr237028a2016-07-26 10:39:45 -0700430 * The orientation during the last visible call to relayout. If our
431 * current orientation is different, the window can't be ready
432 * to be shown.
433 */
434 int mLastVisibleLayoutRotation = -1;
435
436 /**
Andrii Kulianb2e37802017-01-11 00:36:44 -0800437 * Set when we need to report the orientation change to client to trigger a relayout.
438 */
439 boolean mReportOrientationChanged;
440
441 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700442 * How long we last kept the screen frozen.
443 */
444 int mLastFreezeDuration;
445
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800446 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800447 boolean mRemoved;
448
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800449 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800450 * It is save to remove the window and destroy the surface because the client requested removal
451 * or some other higher level component said so (e.g. activity manager).
452 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800453 */
Svetoslav Ganov200adfb2016-10-18 13:29:27 -0700454 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800455
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800456 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700457 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800458 InputChannel mInputChannel;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700459 private InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800460
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800461 // Used to improve performance of toString()
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700462 private String mStringNameCache;
463 private CharSequence mLastTitle;
464 private boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800465
Craig Mautnera2c77052012-03-26 12:14:43 -0700466 final WindowStateAnimator mWinAnimator;
467
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700468 boolean mHasSurface = false;
469
Craig Mautner88400d32012-09-30 12:35:45 -0700470 /** When true this window can be displayed on screens owther than mOwnerUid's */
471 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700472
Chong Zhang92147042016-05-09 12:47:11 -0700473 // Whether the window was visible when we set the app to invisible last time. WM uses
474 // this as a hint to restore the surface (if available) for early animation next time
475 // the app is brought visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700476 private boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800477
Robert Carra1eb4392015-12-10 12:43:51 -0800478 // This window will be replaced due to relaunch. This allows window manager
479 // to differentiate between simple removal of a window and replacement. In the latter case it
480 // will preserve the old window until the new one is drawn.
481 boolean mWillReplaceWindow = false;
482 // If true, the replaced window was already requested to be removed.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700483 private boolean mReplacingRemoveRequested = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800484 // Whether the replacement of the window should trigger app transition animation.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700485 private boolean mAnimateReplacingWindow = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800486 // If not null, the window that will be used to replace the old one. This is being set when
487 // the window is added and unset when this window reports its first draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700488 private WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700489 // For the new window in the replacement transition, if we have
490 // requested to replace without animation, then we should
491 // make sure we also don't apply an enter animation for
492 // the new window.
493 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800494 // Whether this window is being moved via the resize API
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700495 private boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800496
Jeff Brownc2932a12014-11-20 18:04:05 -0800497 /**
498 * Wake lock for drawing.
499 * Even though it's slightly more expensive to do so, we will use a separate wake lock
500 * for each app that is requesting to draw while dozing so that we can accurately track
501 * who is preventing the system from suspending.
502 * This lock is only acquired on first use.
503 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700504 private PowerManager.WakeLock mDrawLock;
Jeff Brownc2932a12014-11-20 18:04:05 -0800505
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700506 final private Rect mTmpRect = new Rect();
507
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800508 /**
509 * Whether the window was resized by us while it was gone for layout.
510 */
511 boolean mResizedWhileGone = false;
512
Robert Carr6da3cc02016-06-16 15:17:07 -0700513 /**
514 * During seamless rotation we have two phases, first the old window contents
515 * are rotated to look as if they didn't move in the new coordinate system. Then we
516 * have to freeze updates to this layer (to preserve the transformation) until
517 * the resize actually occurs. This is true from when the transformation is set
518 * and false until the transaction to resize is sent.
519 */
520 boolean mSeamlesslyRotated = false;
521
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700522 /**
Robert Carrc91d1c32017-02-15 19:37:46 -0800523 * Surface insets from the previous call to relayout(), used to track
524 * if we are changing the Surface insets.
525 */
526 final Rect mLastSurfaceInsets = new Rect();
527
528 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700529 * A flag set by the {@link WindowState} parent to indicate that the parent has examined this
530 * {@link WindowState} in its overall drawing context. This book-keeping allows the parent to
531 * make sure all children have been considered.
532 */
533 private boolean mDrawnStateEvaluated;
534
Jorim Jaggia5e10572017-11-15 14:36:26 +0100535 private final Point mSurfacePosition = new Point();
536
Bryce Leed390deb2017-06-22 13:14:28 -0700537 /**
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800538 * A region inside of this window to be excluded from touch-related focus switches.
539 */
540 private TapExcludeRegionHolder mTapExcludeRegionHolder;
541
542 /**
chaviw40234662018-02-07 09:37:16 -0800543 * Used for testing because the real PowerManager is final.
544 */
545 private PowerManagerWrapper mPowerManagerWrapper;
546
547 /**
chaviwbe43ac82018-04-04 15:14:49 -0700548 * A frame number in which changes requested in this layout will be rendered.
549 */
550 private long mFrameNumber = -1;
551
chaviwc65fa582018-08-09 15:33:13 -0700552 private static final StringBuilder sTmpSB = new StringBuilder();
553
chaviwbe43ac82018-04-04 15:14:49 -0700554 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700555 * 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 -0700556 * of z-order and 1 otherwise.
557 */
Griff Hazen51d00d82016-11-22 15:39:24 -0800558 private static final Comparator<WindowState> sWindowSubLayerComparator =
559 new Comparator<WindowState>() {
560 @Override
561 public int compare(WindowState w1, WindowState w2) {
562 final int layer1 = w1.mSubLayer;
563 final int layer2 = w2.mSubLayer;
564 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
565 // We insert the child window into the list ordered by
566 // the sub-layer. For same sub-layers, the negative one
567 // should go below others; the positive one should go
568 // above others.
569 return -1;
570 }
571 return 1;
572 };
573 };
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700574
Robert Carrf59b8dd2017-10-02 18:58:36 -0700575 /**
576 * Indicates whether we have requested a Dim (in the sense of {@link Dimmer}) from our host
577 * container.
578 */
579 private boolean mIsDimming = false;
580
581 private static final float DEFAULT_DIM_AMOUNT_DEAD_WINDOW = 0.5f;
582
Vishnu Nairba183352018-11-21 11:16:49 -0800583 void seamlesslyRotateIfAllowed(Transaction transaction, @Rotation int oldRotation,
584 @Rotation int rotation, boolean requested) {
Vishnu Nairddd80742018-08-21 14:12:46 -0700585 // Invisible windows and the wallpaper do not participate in the seamless rotation animation
586 if (!isVisibleNow() || mIsWallpaper) {
587 return;
588 }
Adrian Roosfaa102f2018-08-02 15:56:15 +0200589
Vishnu Nairddd80742018-08-21 14:12:46 -0700590 if (mPendingSeamlessRotate != null) {
591 oldRotation = mPendingSeamlessRotate.getOldRotation();
592 }
593
594 if (mForceSeamlesslyRotate || requested) {
595 mPendingSeamlessRotate = new SeamlessRotator(oldRotation, rotation, getDisplayInfo());
Vishnu Nairec634062018-09-20 20:16:18 -0700596 mPendingSeamlessRotate.unrotate(transaction, this);
Vishnu Nairddd80742018-08-21 14:12:46 -0700597 mService.markForSeamlessRotation(this, true);
598 }
599 }
600
Vishnu Nairba183352018-11-21 11:16:49 -0800601 void finishSeamlessRotation(boolean timeout) {
Vishnu Nairddd80742018-08-21 14:12:46 -0700602 if (mPendingSeamlessRotate != null) {
Vishnu Nairba183352018-11-21 11:16:49 -0800603 mPendingSeamlessRotate.finish(this, timeout);
Vishnu Nairddd80742018-08-21 14:12:46 -0700604 mFinishSeamlessRotateFrameNumber = getFrameNumber();
605 mPendingSeamlessRotate = null;
606 mService.markForSeamlessRotation(this, false);
Vishnu Nair83537a72018-07-19 21:27:48 -0700607 }
608 }
609
chaviw40234662018-02-07 09:37:16 -0800610 interface PowerManagerWrapper {
611 void wakeUp(long time, String reason);
612
613 boolean isInteractive();
614
615 }
616
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800617 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
chaviw40234662018-02-07 09:37:16 -0800618 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
619 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow) {
620 this(service, s, c, token, parentWindow, appOp, seq, a, viewVisibility, ownerId,
621 ownerCanAddInternalSystemWindow, new PowerManagerWrapper() {
622 @Override
623 public void wakeUp(long time, String reason) {
624 service.mPowerManager.wakeUp(time, reason);
625 }
626
627 @Override
628 public boolean isInteractive() {
629 return service.mPowerManager.isInteractive();
630 }
631 });
632 }
633
634 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
635 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
636 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow,
637 PowerManagerWrapper powerManagerWrapper) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100638 super(service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800639 mSession = s;
640 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800641 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800642 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700643 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700644 mOwnerUid = ownerId;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800645 mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200646 mWindowId = new WindowId(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800647 mAttrs.copyFrom(a);
Robert Carrb08ed042018-03-12 15:49:08 -0700648 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800649 mViewVisibility = viewVisibility;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700650 mPolicy = mService.mPolicy;
651 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800652 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700653 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700654 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
chaviw40234662018-02-07 09:37:16 -0800655 mPowerManagerWrapper = powerManagerWrapper;
Vishnu Nair83537a72018-07-19 21:27:48 -0700656 mForceSeamlesslyRotate = token.mRoundedCornerOverlay;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700657 if (localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700658 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700659 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800660 try {
661 c.asBinder().linkToDeath(deathRecipient, 0);
662 } catch (RemoteException e) {
663 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700664 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800665 mLayoutAttached = false;
666 mIsImWindow = false;
667 mIsWallpaper = false;
668 mIsFloatingLayer = false;
669 mBaseLayer = 0;
670 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700671 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700672 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800673 return;
674 }
675 mDeathRecipient = deathRecipient;
676
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700677 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800678 // The multiplier here is to reserve space for multiple
679 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800680 mBaseLayer = mPolicy.getWindowLayerLw(parentWindow)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700681 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800682 mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700683 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900684
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700685 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow);
686 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900687
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800688 mLayoutAttached = mAttrs.type !=
689 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700690 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
691 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
692 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800693 } else {
694 // The multiplier here is to reserve space for multiple
695 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800696 mBaseLayer = mPolicy.getWindowLayerLw(this)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700697 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800698 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700699 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800700 mLayoutAttached = false;
701 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
702 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
703 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800704 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700705 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800706
Wale Ogunwale72919d22016-12-08 18:58:50 -0800707 if (mAppToken != null && mAppToken.mShowForAllUsers) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700708 // Windows for apps that can show for all users should also show when the device is
709 // locked.
710 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
Craig Mautner19ab8282014-05-07 10:35:34 -0700711 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800712
Craig Mautner322e4032012-07-13 13:35:20 -0700713 mWinAnimator = new WindowStateAnimator(this);
714 mWinAnimator.mAlpha = a.alpha;
715
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800716 mRequestedWidth = 0;
717 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700718 mLastRequestedWidth = 0;
719 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800720 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800721 mInputWindowHandle = new InputWindowHandle(
Robert Carre0a353c2018-08-02 16:38:04 -0700722 mAppToken != null ? mAppToken.mInputApplicationHandle : null, c,
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800723 getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800724 }
725
726 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700727 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800728 mSession.windowAddedLocked(mAttrs.packageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800729 }
730
Bryce Leed390deb2017-06-22 13:14:28 -0700731 /**
732 * Returns whether this {@link WindowState} has been considered for drawing by its parent.
733 */
Bryce Lee6311c4b2017-07-06 14:09:29 -0700734 boolean getDrawnStateEvaluated() {
Bryce Leed390deb2017-06-22 13:14:28 -0700735 return mDrawnStateEvaluated;
736 }
737
738 /**
739 * Sets whether this {@link WindowState} has been considered for drawing by its parent. Should
740 * be cleared when detached from parent.
741 */
742 void setDrawnStateEvaluated(boolean evaluated) {
743 mDrawnStateEvaluated = evaluated;
744 }
745
746 @Override
747 void onParentSet() {
748 super.onParentSet();
749 setDrawnStateEvaluated(false /*evaluated*/);
Robert Carr24be9ab2018-04-30 17:54:53 -0700750
751 getDisplayContent().reapplyMagnificationSpec();
Bryce Leed390deb2017-06-22 13:14:28 -0700752 }
753
Craig Mautnera2c77052012-03-26 12:14:43 -0700754 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800755 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800756 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800757 }
758
759 @Override
760 public String getOwningPackage() {
761 return mAttrs.packageName;
762 }
763
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800764 @Override
765 public boolean canAddInternalSystemWindow() {
766 return mOwnerCanAddInternalSystemWindow;
767 }
768
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200769 @Override
770 public boolean canAcquireSleepToken() {
771 return mSession.mCanAcquireSleepToken;
772 }
773
Jorim Jaggif5834272016-04-04 20:25:41 -0700774 /**
775 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
776 * from {@param frame}. In other words, it applies the insets that would result if
777 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700778 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
779 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700780 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700781 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
782 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
783 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
784 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
785 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700786 frame.inset(left, top, right, bottom);
787 }
788
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800789 @Override
chaviw1454b392018-08-06 09:54:04 -0700790 public void computeFrameLw() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800791 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700792 // This window is being replaced and either already got information that it's being
793 // removed or we are still waiting for some information. Because of this we don't
794 // want to apply any more changes to it, so it remains in this state until new window
795 // appears.
796 return;
797 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800798 mHaveFrame = true;
799
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700800 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700801 final boolean inFullscreenContainer = inFullscreenContainer();
Robert Carre6275582016-02-29 15:45:45 -0800802 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700803 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800804
Chong Zhangae35fef2016-03-16 15:56:55 -0700805 // If the task has temp inset bounds set, we have to make sure all its windows uses
806 // the temp inset frame. Otherwise different display frames get applied to the main
807 // window and the child window, making them misaligned.
Adrian Roose76b2b52018-03-21 16:22:16 +0100808 // Otherwise we need to clear the inset frame, to avoid using a stale frame after leaving
809 // multi window mode.
810 if (task != null && isInMultiWindowMode()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700811 task.getTempInsetBounds(mInsetFrame);
Adrian Roose76b2b52018-03-21 16:22:16 +0100812 } else {
813 mInsetFrame.setEmpty();
Chong Zhangae35fef2016-03-16 15:56:55 -0700814 }
815
Jorim Jaggif5834272016-04-04 20:25:41 -0700816 // Denotes the actual frame used to calculate the insets and to perform the layout. When
817 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
818 // insets temporarily. By the notion of a task having a different layout frame, we can
819 // achieve that while still moving the task around.
820 final Rect layoutContainingFrame;
821 final Rect layoutDisplayFrame;
822
823 // The offset from the layout containing frame to the actual containing frame.
824 final int layoutXDiff;
825 final int layoutYDiff;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700826 if (inFullscreenContainer || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800827 // We use the parent frame as the containing frame for fullscreen and child windows
chaviw1454b392018-08-06 09:54:04 -0700828 mWindowFrames.mContainingFrame.set(mWindowFrames.mParentFrame);
829 layoutDisplayFrame = mWindowFrames.mDisplayFrame;
830 layoutContainingFrame = mWindowFrames.mParentFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700831 layoutXDiff = 0;
832 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800833 } else {
chaviw553b0212018-07-12 13:37:01 -0700834 getBounds(mWindowFrames.mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100835 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
836
837 // If the bounds are frozen, we still want to translate the window freely and only
838 // freeze the size.
839 Rect frozen = mAppToken.mFrozenBounds.peek();
chaviw553b0212018-07-12 13:37:01 -0700840 mWindowFrames.mContainingFrame.right =
841 mWindowFrames.mContainingFrame.left + frozen.width();
842 mWindowFrames.mContainingFrame.bottom =
843 mWindowFrames.mContainingFrame.top + frozen.height();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100844 }
lumark90120a82018-08-15 00:33:03 +0800845 final WindowState imeWin = mService.mRoot.getCurrentInputMethodWindow();
Robert Carrfc03b2b2016-03-31 15:22:02 -0700846 // IME is up and obscuring this window. Adjust the window position so it is visible.
Robert Carr825581a2018-03-30 14:00:53 -0700847 if (imeWin != null && imeWin.isVisibleNow() && isInputMethodTarget()) {
chaviw553b0212018-07-12 13:37:01 -0700848 if (inFreeformWindowingMode() && mWindowFrames.mContainingFrame.bottom
chaviw1454b392018-08-06 09:54:04 -0700849 > mWindowFrames.mContentFrame.bottom) {
Winson Chungd73e94b2017-05-31 16:25:30 -0700850 // In freeform we want to move the top up directly.
851 // TODO: Investigate why this is contentFrame not parentFrame.
chaviw553b0212018-07-12 13:37:01 -0700852 mWindowFrames.mContainingFrame.top -= mWindowFrames.mContainingFrame.bottom
chaviw1454b392018-08-06 09:54:04 -0700853 - mWindowFrames.mContentFrame.bottom;
chaviw553b0212018-07-12 13:37:01 -0700854 } else if (!inPinnedWindowingMode() && mWindowFrames.mContainingFrame.bottom
chaviw1454b392018-08-06 09:54:04 -0700855 > mWindowFrames.mParentFrame.bottom) {
Winson Chungd73e94b2017-05-31 16:25:30 -0700856 // But in docked we want to behave like fullscreen and behave as if the task
857 // were given smaller bounds for the purposes of layout. Skip adjustments for
858 // the pinned stack, they are handled separately in the PinnedStackController.
chaviw1454b392018-08-06 09:54:04 -0700859 mWindowFrames.mContainingFrame.bottom = mWindowFrames.mParentFrame.bottom;
Winson Chungd73e94b2017-05-31 16:25:30 -0700860 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700861 }
Skuhne81c524a2015-08-12 13:34:14 -0700862
Robert Carre6275582016-02-29 15:45:45 -0800863 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700864 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
865 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800866 // "content frame" since it is allowed to be outside the visible desktop.
chaviw553b0212018-07-12 13:37:01 -0700867 if (mWindowFrames.mContainingFrame.isEmpty()) {
chaviw1454b392018-08-06 09:54:04 -0700868 mWindowFrames.mContainingFrame.set(mWindowFrames.mContentFrame);
Skuhne81c524a2015-08-12 13:34:14 -0700869 }
Doris Liu06d582d2015-06-01 13:18:43 -0700870 }
Adrian Roos604ef952018-05-15 20:13:13 +0200871
872 final TaskStack stack = getStack();
873 if (inPinnedWindowingMode() && stack != null
874 && stack.lastAnimatingBoundsWasToFullscreen()) {
875 // PIP edge case: When going from pinned to fullscreen, we apply a
876 // tempInsetFrame for the full task - but we're still at the start of the animation.
877 // To prevent a jump if there's a letterbox, restrict to the parent frame.
chaviw1454b392018-08-06 09:54:04 -0700878 mInsetFrame.intersectUnchecked(mWindowFrames.mParentFrame);
879 mWindowFrames.mContainingFrame.intersectUnchecked(mWindowFrames.mParentFrame);
Adrian Roos604ef952018-05-15 20:13:13 +0200880 }
881
chaviw1454b392018-08-06 09:54:04 -0700882 layoutDisplayFrame = new Rect(mWindowFrames.mDisplayFrame);
chaviw553b0212018-07-12 13:37:01 -0700883 mWindowFrames.mDisplayFrame.set(mWindowFrames.mContainingFrame);
884 layoutXDiff =
885 !mInsetFrame.isEmpty() ? mInsetFrame.left - mWindowFrames.mContainingFrame.left
886 : 0;
887 layoutYDiff =
888 !mInsetFrame.isEmpty() ? mInsetFrame.top - mWindowFrames.mContainingFrame.top
889 : 0;
890 layoutContainingFrame =
891 !mInsetFrame.isEmpty() ? mInsetFrame : mWindowFrames.mContainingFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700892 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
chaviw1454b392018-08-06 09:54:04 -0700893 subtractInsets(mWindowFrames.mDisplayFrame, layoutContainingFrame, layoutDisplayFrame,
894 mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700895 if (!layoutInParentFrame()) {
chaviw553b0212018-07-12 13:37:01 -0700896 subtractInsets(mWindowFrames.mContainingFrame, layoutContainingFrame,
chaviw1454b392018-08-06 09:54:04 -0700897 mWindowFrames.mParentFrame, mTmpRect);
898 subtractInsets(mInsetFrame, layoutContainingFrame, mWindowFrames.mParentFrame,
chaviw553b0212018-07-12 13:37:01 -0700899 mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700900 }
Jorim Jaggif5834272016-04-04 20:25:41 -0700901 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700902 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800903
chaviw553b0212018-07-12 13:37:01 -0700904 final int pw = mWindowFrames.mContainingFrame.width();
905 final int ph = mWindowFrames.mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800906
Dianne Hackborn1743b642012-03-12 17:04:43 -0700907 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
908 mLastRequestedWidth = mRequestedWidth;
909 mLastRequestedHeight = mRequestedHeight;
chaviw1454b392018-08-06 09:54:04 -0700910 mWindowFrames.setContentChanged(true);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700911 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800912
chaviw492139a2018-07-16 16:07:35 -0700913 final int fw = mWindowFrames.mFrame.width();
914 final int fh = mWindowFrames.mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800915
Jorim Jaggif5834272016-04-04 20:25:41 -0700916 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
917
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700918 // Calculate the outsets before the content frame gets shrinked to the window frame.
chaviw1454b392018-08-06 09:54:04 -0700919 mWindowFrames.calculateOutsets();
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700920
Craig Mautnera248eee2013-05-07 11:41:27 -0700921 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800922 // final window frame.
chaviw492139a2018-07-16 16:07:35 -0700923 if (windowsAreFloating && !mWindowFrames.mFrame.isEmpty()) {
Robert Carre65a1c42017-02-28 16:52:59 -0800924 // For pinned workspace the frame isn't limited in any particular
925 // way since SystemUI controls the bounds. For freeform however
926 // we want to keep things inside the content frame.
chaviw492139a2018-07-16 16:07:35 -0700927 final Rect limitFrame = task.inPinnedWindowingMode() ? mWindowFrames.mFrame
928 : mWindowFrames.mContentFrame;
Skuhne81c524a2015-08-12 13:34:14 -0700929 // Keep the frame out of the blocked system area, limit it in size to the content area
930 // and make sure that there is always a minimum visible so that the user can drag it
931 // into a usable area..
chaviw492139a2018-07-16 16:07:35 -0700932 final int height = Math.min(mWindowFrames.mFrame.height(), limitFrame.height());
933 final int width = Math.min(limitFrame.width(), mWindowFrames.mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700934 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +0900935 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
936 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
937 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
938 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Robert Carre65a1c42017-02-28 16:52:59 -0800939 final int top = Math.max(limitFrame.top,
chaviw492139a2018-07-16 16:07:35 -0700940 Math.min( mWindowFrames.mFrame.top, limitFrame.bottom - minVisibleHeight));
Robert Carre65a1c42017-02-28 16:52:59 -0800941 final int left = Math.max(limitFrame.left + minVisibleWidth - width,
chaviw492139a2018-07-16 16:07:35 -0700942 Math.min( mWindowFrames.mFrame.left, limitFrame.right - minVisibleWidth));
943 mWindowFrames.mFrame.set(left, top, left + width, top + height);
944 mWindowFrames.mContentFrame.set( mWindowFrames.mFrame);
chaviw553b0212018-07-12 13:37:01 -0700945 mWindowFrames.mVisibleFrame.set(mWindowFrames.mContentFrame);
946 mWindowFrames.mStableFrame.set(mWindowFrames.mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700947 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
chaviw492139a2018-07-16 16:07:35 -0700948 dc.getDockedDividerController().positionDockedStackedDivider(mWindowFrames.mFrame);
949 mWindowFrames.mContentFrame.set(mWindowFrames.mFrame);
950 if (!mWindowFrames.mFrame.equals(mWindowFrames.mLastFrame)) {
Jorim Jaggi192086e2016-03-11 17:17:03 +0100951 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800952 }
Skuhne81c524a2015-08-12 13:34:14 -0700953 } else {
chaviw492139a2018-07-16 16:07:35 -0700954 mWindowFrames.mContentFrame.set(
955 Math.max(mWindowFrames.mContentFrame.left, mWindowFrames.mFrame.left),
956 Math.max(mWindowFrames.mContentFrame.top, mWindowFrames.mFrame.top),
957 Math.min(mWindowFrames.mContentFrame.right, mWindowFrames.mFrame.right),
958 Math.min(mWindowFrames.mContentFrame.bottom, mWindowFrames.mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800959
chaviw492139a2018-07-16 16:07:35 -0700960 mWindowFrames.mVisibleFrame.set(
961 Math.max(mWindowFrames.mVisibleFrame.left, mWindowFrames.mFrame.left),
962 Math.max(mWindowFrames.mVisibleFrame.top, mWindowFrames.mFrame.top),
963 Math.min(mWindowFrames.mVisibleFrame.right, mWindowFrames.mFrame.right),
964 Math.min(mWindowFrames.mVisibleFrame.bottom, mWindowFrames.mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800965
chaviw492139a2018-07-16 16:07:35 -0700966 mWindowFrames.mStableFrame.set(
967 Math.max(mWindowFrames.mStableFrame.left, mWindowFrames.mFrame.left),
968 Math.max(mWindowFrames.mStableFrame.top, mWindowFrames.mFrame.top),
969 Math.min(mWindowFrames.mStableFrame.right, mWindowFrames.mFrame.right),
970 Math.min(mWindowFrames.mStableFrame.bottom, mWindowFrames.mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700971 }
Adrian Roosfa104232014-06-20 16:10:14 -0700972
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700973 if (inFullscreenContainer && !windowsAreFloating) {
Jorim Jaggi899327f2016-02-25 20:44:18 -0500974 // Windows that are not fullscreen can be positioned outside of the display frame,
975 // but that is not a reason to provide them with overscan insets.
chaviw9c81e632018-07-31 11:17:52 -0700976 InsetUtils.insetsBetweenFrames(layoutContainingFrame, mWindowFrames.mOverscanFrame,
977 mWindowFrames.mOverscanInsets);
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800978 }
Craig Mautnereda67292013-04-28 13:50:14 -0700979
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100980 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
chaviw1454b392018-08-06 09:54:04 -0700981 final WmDisplayCutout c = mWindowFrames.mDisplayCutout.calculateRelativeTo(
chaviw553b0212018-07-12 13:37:01 -0700982 mWindowFrames.mDisplayFrame);
chaviw9c81e632018-07-31 11:17:52 -0700983 mWindowFrames.calculateDockedDividerInsets(c.getDisplayCutout().getSafeInsets());
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100984 } else {
Bryce Leef3c6a472017-11-14 14:53:06 -0800985 getDisplayContent().getBounds(mTmpRect);
chaviw9c81e632018-07-31 11:17:52 -0700986 mWindowFrames.calculateInsets(windowsAreFloating, inFullscreenContainer, mTmpRect);
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100987 }
Adrian Roosfa104232014-06-20 16:10:14 -0700988
chaviwcdba9a42018-07-19 11:36:42 -0700989 mWindowFrames.setDisplayCutout(
chaviw1454b392018-08-06 09:54:04 -0700990 mWindowFrames.mDisplayCutout.calculateRelativeTo(mWindowFrames.mFrame));
Jorim Jaggibae2b152018-04-18 17:27:27 +0200991
Jorim Jaggi656f6502016-04-11 21:08:17 -0700992 // Offset the actual frame by the amount layout frame is off.
chaviw9c81e632018-07-31 11:17:52 -0700993 mWindowFrames.offsetFrames(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -0700994
chaviw9c81e632018-07-31 11:17:52 -0700995 mWindowFrames.mCompatFrame.set(mWindowFrames.mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400996 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700997 // If there is a size compatibility scale being applied to the
998 // window, we need to apply this to its insets so that they are
999 // reported to the app in its coordinate space.
chaviw9c81e632018-07-31 11:17:52 -07001000 mWindowFrames.scaleInsets(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001001
1002 // Also the scaled frame that we report to the app needs to be
1003 // adjusted to be in its coordinate space.
chaviw9c81e632018-07-31 11:17:52 -07001004 mWindowFrames.mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001005 }
1006
chaviw492139a2018-07-16 16:07:35 -07001007 if (mIsWallpaper && (fw != mWindowFrames.mFrame.width()
1008 || fh != mWindowFrames.mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001009 final DisplayContent displayContent = getDisplayContent();
1010 if (displayContent != null) {
1011 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
chaviw553b0212018-07-12 13:37:01 -07001012 getDisplayContent().mWallpaperController.updateWallpaperOffset(this,
1013 displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001014 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001015 }
1016
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001017 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001018 "Resolving (mRequestedWidth="
1019 + mRequestedWidth + ", mRequestedheight="
1020 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
chaviw492139a2018-07-16 16:07:35 -07001021 + "): frame=" + mWindowFrames.mFrame.toShortString()
chaviw9c81e632018-07-31 11:17:52 -07001022 + " " + mWindowFrames.getInsetsInfo());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001023 }
1024
Bryce Leef3c6a472017-11-14 14:53:06 -08001025 // TODO: Look into whether this override is still necessary.
1026 @Override
1027 public Rect getBounds() {
1028 if (isInMultiWindowMode()) {
1029 return getTask().getBounds();
1030 } else if (mAppToken != null){
1031 return mAppToken.getBounds();
1032 } else {
1033 return super.getBounds();
1034 }
1035 }
1036
Craig Mautnera2c77052012-03-26 12:14:43 -07001037 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001038 public Rect getFrameLw() {
chaviw492139a2018-07-16 16:07:35 -07001039 return mWindowFrames.mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001040 }
1041
Craig Mautnera2c77052012-03-26 12:14:43 -07001042 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001043 public Rect getDisplayFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001044 return mWindowFrames.mDisplayFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001045 }
1046
Craig Mautnera2c77052012-03-26 12:14:43 -07001047 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001048 public Rect getOverscanFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001049 return mWindowFrames.mOverscanFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001050 }
1051
1052 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001053 public Rect getContentFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001054 return mWindowFrames.mContentFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001055 }
1056
Craig Mautnera2c77052012-03-26 12:14:43 -07001057 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001058 public Rect getVisibleFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001059 return mWindowFrames.mVisibleFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001060 }
1061
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001062 Rect getStableFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001063 return mWindowFrames.mStableFrame;
1064 }
1065
1066 Rect getDecorFrame() {
1067 return mWindowFrames.mDecorFrame;
1068 }
1069
1070 Rect getParentFrame() {
1071 return mWindowFrames.mParentFrame;
1072 }
1073
1074 Rect getContainingFrame() {
1075 return mWindowFrames.mContainingFrame;
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001076 }
1077
chaviwcdba9a42018-07-19 11:36:42 -07001078 WmDisplayCutout getWmDisplayCutout() {
1079 return mWindowFrames.mDisplayCutout;
1080 }
1081
chaviw9c81e632018-07-31 11:17:52 -07001082 void getCompatFrame(Rect outFrame) {
1083 outFrame.set(mWindowFrames.mCompatFrame);
1084 }
1085
1086 void getCompatFrameSize(Rect outFrame) {
1087 outFrame.set(0, 0, mWindowFrames.mCompatFrame.width(), mWindowFrames.mCompatFrame.height());
1088 }
1089
Craig Mautnera2c77052012-03-26 12:14:43 -07001090 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001091 public boolean getGivenInsetsPendingLw() {
1092 return mGivenInsetsPending;
1093 }
1094
Craig Mautnera2c77052012-03-26 12:14:43 -07001095 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001096 public Rect getGivenContentInsetsLw() {
1097 return mGivenContentInsets;
1098 }
1099
Craig Mautnera2c77052012-03-26 12:14:43 -07001100 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001101 public Rect getGivenVisibleInsetsLw() {
1102 return mGivenVisibleInsets;
1103 }
1104
Craig Mautnera2c77052012-03-26 12:14:43 -07001105 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001106 public WindowManager.LayoutParams getAttrs() {
1107 return mAttrs;
1108 }
1109
Craig Mautner812d2ca2012-09-27 15:35:34 -07001110 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001111 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001112 return getDisplayContent().getNeedsMenu(this, bottom);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001113 }
1114
Craig Mautner19d59bc2012-09-04 11:15:56 -07001115 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001116 public int getSystemUiVisibility() {
1117 return mSystemUiVisibility;
1118 }
1119
Craig Mautner19d59bc2012-09-04 11:15:56 -07001120 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001121 public int getSurfaceLayer() {
1122 return mLayer;
1123 }
1124
Craig Mautner812d2ca2012-09-27 15:35:34 -07001125 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001126 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001127 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001128 }
1129
1130 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001131 public IApplicationToken getAppToken() {
1132 return mAppToken != null ? mAppToken.appToken : null;
1133 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001134
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001135 @Override
1136 public boolean isVoiceInteraction() {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001137 return mAppToken != null && mAppToken.mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001138 }
1139
Robert Carr31aa98b2016-07-20 15:29:03 -07001140 boolean setReportResizeHints() {
chaviw9c81e632018-07-31 11:17:52 -07001141 return mWindowFrames.setReportResizeHints();
Craig Mautner4c5eb222013-11-18 12:59:05 -08001142 }
1143
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001144 /**
1145 * Adds the window to the resizing list if any of the parameters we use to track the window
1146 * dimensions or insets have changed.
1147 */
1148 void updateResizingWindowIfNeeded() {
1149 final WindowStateAnimator winAnimator = mWinAnimator;
Adrian Roos5251b1d2018-03-23 18:57:43 +01001150 if (!mHasSurface || getDisplayContent().mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001151 return;
1152 }
1153
1154 final Task task = getTask();
1155 // In the case of stack bound animations, the window frames will update (unlike other
1156 // animations which just modify various transformation properties). We don't want to
1157 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1158 // the frame may not correspond to the surface size or the onscreen area at various
1159 // phases in the animation, and the client will become sad and confused.
Winson Chung40a5f932017-04-13 16:39:36 -07001160 if (task != null && task.mStack.isAnimatingBounds()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001161 return;
1162 }
1163
chaviw9c81e632018-07-31 11:17:52 -07001164 boolean didFrameInsetsChange = setReportResizeHints();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001165 boolean configChanged = isConfigChanged();
1166 if (DEBUG_CONFIGURATION && configChanged) {
1167 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1168 }
1169
1170 final boolean dragResizingChanged = isDragResizeChanged()
1171 && !isDragResizingChangeReported();
1172
1173 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
chaviw492139a2018-07-16 16:07:35 -07001174 + " dragResizingChanged=" + dragResizingChanged
1175 + " last=" + mWindowFrames.mLastFrame + " frame=" + mWindowFrames.mFrame);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001176
1177 // We update mLastFrame always rather than in the conditional with the last inset
1178 // variables, because mFrameSizeChanged only tracks the width and height changing.
chaviw492139a2018-07-16 16:07:35 -07001179 mWindowFrames.mLastFrame.set(mWindowFrames.mFrame);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001180
chaviw9c81e632018-07-31 11:17:52 -07001181 if (didFrameInsetsChange
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001182 || winAnimator.mSurfaceResized
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001183 || configChanged
1184 || dragResizingChanged
Andrii Kulianb2e37802017-01-11 00:36:44 -08001185 || mReportOrientationChanged) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001186 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1187 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
chaviw9c81e632018-07-31 11:17:52 -07001188 + " " + mWindowFrames.getInsetsChangedInfo()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001189 + " surfaceResized=" + winAnimator.mSurfaceResized
1190 + " configChanged=" + configChanged
1191 + " dragResizingChanged=" + dragResizingChanged
chaviw9c81e632018-07-31 11:17:52 -07001192 + " reportOrientationChanged=" + mReportOrientationChanged);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001193 }
1194
1195 // If it's a dead window left on screen, and the configuration changed, there is nothing
1196 // we can do about it. Remove the window now.
1197 if (mAppToken != null && mAppDied) {
1198 mAppToken.removeDeadWindows();
1199 return;
1200 }
1201
Jorim Jaggidc9385a2017-05-13 02:00:31 +02001202 updateLastInsetValues();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001203 mService.makeWindowFreezingScreenIfNeededLocked(this);
1204
1205 // If the orientation is changing, or we're starting or ending a drag resizing action,
1206 // then we need to hold off on unfreezing the display until this window has been
1207 // redrawn; to do that, we need to go through the process of getting informed by the
1208 // application when it has finished drawing.
Robert Carr09286c92018-02-15 13:52:31 -08001209 if (getOrientationChanging() || dragResizingChanged) {
Robert Carre13b58e2017-08-31 14:50:44 -07001210 if (DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001211 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1212 + ", mDrawState=DRAW_PENDING in " + this
1213 + ", surfaceController " + winAnimator.mSurfaceController);
1214 }
1215 winAnimator.mDrawState = DRAW_PENDING;
1216 if (mAppToken != null) {
1217 mAppToken.clearAllDrawn();
1218 }
1219 }
1220 if (!mService.mResizingWindows.contains(this)) {
1221 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
1222 mService.mResizingWindows.add(this);
1223 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07001224 } else if (getOrientationChanging()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001225 if (isDrawnLw()) {
1226 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1227 + this + ", surfaceController " + winAnimator.mSurfaceController);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001228 setOrientationChanging(false);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001229 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1230 - mService.mDisplayFreezeTime);
1231 }
1232 }
1233 }
1234
Bryce Lee8c3cf382017-07-06 19:47:10 -07001235 boolean getOrientationChanging() {
1236 // In addition to the local state flag, we must also consider the difference in the last
1237 // reported configuration vs. the current state. If the client code has not been informed of
1238 // the change, logic dependent on having finished processing the orientation, such as
1239 // unfreezing, could be improperly triggered.
1240 // TODO(b/62846907): Checking against {@link mLastReportedConfiguration} could be flaky as
1241 // this is not necessarily what the client has processed yet. Find a
1242 // better indicator consistent with the client.
Robert Carr926643f2017-08-02 12:01:12 -07001243 return (mOrientationChanging || (isVisible()
Bryce Lee2b17afd2017-09-21 10:38:20 -07001244 && getConfiguration().orientation != getLastReportedConfiguration().orientation))
Robert Carr9c1c3a02017-08-08 12:59:01 -07001245 && !mSeamlesslyRotated
1246 && !mOrientationChangeTimedOut;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001247 }
1248
1249 void setOrientationChanging(boolean changing) {
1250 mOrientationChanging = changing;
Robert Carr9c1c3a02017-08-08 12:59:01 -07001251 mOrientationChangeTimedOut = false;
1252 }
1253
1254 void orientationChangeTimedOut() {
1255 mOrientationChangeTimedOut = true;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001256 }
1257
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001258 DisplayContent getDisplayContent() {
1259 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001260 }
1261
Adrian Roos5251b1d2018-03-23 18:57:43 +01001262 @Override
1263 void onDisplayChanged(DisplayContent dc) {
Louis Chang7501e332018-08-20 13:08:39 +08001264 updateSurfaceSize(dc);
Adrian Roos5251b1d2018-03-23 18:57:43 +01001265 super.onDisplayChanged(dc);
1266 // Window was not laid out for this display yet, so make sure mLayoutSeq does not match.
1267 if (dc != null) {
1268 mLayoutSeq = dc.mLayoutSeq - 1;
Brad Stenningaf596412018-04-02 12:03:19 -07001269 mInputWindowHandle.displayId = dc.getDisplayId();
Adrian Roos5251b1d2018-03-23 18:57:43 +01001270 }
1271 }
1272
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001273 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001274 final DisplayContent displayContent = getDisplayContent();
1275 return displayContent != null ? displayContent.getDisplayInfo() : null;
1276 }
1277
Jorim Jaggife762342016-10-13 14:33:27 +02001278 @Override
1279 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001280 final DisplayContent displayContent = getDisplayContent();
1281 if (displayContent == null) {
Brad Stenningaf596412018-04-02 12:03:19 -07001282 return Display.INVALID_DISPLAY;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001283 }
1284 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001285 }
1286
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001287 Task getTask() {
Bryce Lee6d410262017-02-28 15:30:17 -08001288 return mAppToken != null ? mAppToken.getTask() : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001289 }
1290
1291 TaskStack getStack() {
1292 Task task = getTask();
1293 if (task != null) {
1294 if (task.mStack != null) {
1295 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001296 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001297 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001298 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1299 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001300 final DisplayContent dc = getDisplayContent();
1301 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001302 }
1303
Skuhnef932e562015-08-20 12:07:30 -07001304 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001305 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001306 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001307 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001308 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001309 final Task task = getTask();
1310 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001311 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001312 mTmpRect.setEmpty();
1313 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001314 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001315 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001316 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001317 } else {
1318 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001319 }
1320 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001321
chaviw553b0212018-07-12 13:37:01 -07001322 bounds.set(mWindowFrames.mVisibleFrame);
Chong Zhang9184ec62015-09-24 12:32:21 -07001323 if (intersectWithStackBounds) {
1324 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001325 }
1326
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001327 if (bounds.isEmpty()) {
chaviw492139a2018-07-16 16:07:35 -07001328 bounds.set(mWindowFrames.mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001329 if (intersectWithStackBounds) {
1330 bounds.intersect(mTmpRect);
1331 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001332 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001333 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001334 }
1335
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001336 public long getInputDispatchingTimeoutNanos() {
1337 return mAppToken != null
Wale Ogunwale72919d22016-12-08 18:58:50 -08001338 ? mAppToken.mInputDispatchingTimeoutNanos
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001339 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1340 }
1341
Craig Mautnere8552142012-11-07 13:55:47 -08001342 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001343 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001344 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001345 }
1346
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001347 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1348 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1349 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1350 if (dtdx < -.000001f || dtdx > .000001f) return false;
1351 if (dsdy < -.000001f || dsdy > .000001f) return false;
1352 return true;
1353 }
1354
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001355 void prelayout() {
1356 if (mEnforceSizeCompat) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001357 mGlobalScale = getDisplayContent().mCompatibleScreenScale;
1358 mInvGlobalScale = 1 / mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001359 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001360 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001361 }
1362 }
1363
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001364 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001365 boolean hasContentToDisplay() {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001366 if (!mAppFreezing && isDrawnLw() && (mViewVisibility == View.VISIBLE
lumark588a3e82018-07-20 18:53:54 +08001367 || (isAnimating() && !getDisplayContent().mAppTransition.isTransitionSet()))) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001368 return true;
1369 }
1370
Wale Ogunwale44f21802016-09-02 12:49:48 -07001371 return super.hasContentToDisplay();
1372 }
1373
1374 @Override
1375 boolean isVisible() {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001376 return wouldBeVisibleIfPolicyIgnored() && mPolicyVisibility;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001377 }
1378
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001379 /**
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001380 * @return True if the window would be visible if we'd ignore policy visibility, false
1381 * otherwise.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001382 */
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001383 boolean wouldBeVisibleIfPolicyIgnored() {
Jorim Jaggi43530c92017-05-18 01:53:56 +02001384 return mHasSurface && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001385 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001386 }
1387
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001388 @Override
1389 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001390 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001391 }
1392
1393 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001394 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1395 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001396 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001397 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1398 boolean isWinVisibleLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001399 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.isSelfAnimating())
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001400 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001401 }
1402
1403 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001404 * The same as isVisible(), but follows the current hidden state of the associated app token,
1405 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001406 */
1407 boolean isVisibleNow() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001408 return (!mToken.isHidden() || mAttrs.type == TYPE_APPLICATION_STARTING)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001409 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001410 }
1411
1412 /**
1413 * Can this window possibly be a drag/drop target? The test here is
1414 * a combination of the above "visible now" with the check that the
1415 * Input Manager uses when discarding windows from input consideration.
1416 */
1417 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001418 return isVisibleNow() && !mRemoved
1419 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001420 }
1421
1422 /**
1423 * Same as isVisible(), but we also count it as visible between the
1424 * call to IWindowSession.add() and the first relayout().
1425 */
1426 boolean isVisibleOrAdding() {
1427 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001428 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001429 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001430 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001431 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001432 }
1433
1434 /**
1435 * Is this window currently on-screen? It is on-screen either if it
1436 * is visible or it is currently running an animation before no longer
1437 * being visible.
1438 */
1439 boolean isOnScreen() {
Jorim Jaggiaf221d12016-11-15 14:59:57 -08001440 if (!mHasSurface || mDestroying || !mPolicyVisibility) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001441 return false;
1442 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001443 final AppWindowToken atoken = mAppToken;
1444 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001445 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001446 || isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001447 }
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001448 return !isParentWindowHidden() || isAnimating();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001449 }
1450
1451 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001452 * Whether this window's drawn state might affect the drawn states of the app token.
1453 *
Chong Zhang8e4bda92016-05-04 15:08:18 -07001454 * @return true if the window should be considered while evaluating allDrawn flags.
1455 */
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001456 boolean mightAffectAllDrawn() {
1457 final boolean isAppType = mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1458 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION;
1459 return (isOnScreen() || isAppType) && !mAnimatingExit && !mDestroying;
Chong Zhang8e4bda92016-05-04 15:08:18 -07001460 }
1461
1462 /**
1463 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1464 * it must be drawn before allDrawn can become true.
1465 */
1466 boolean isInteresting() {
1467 return mAppToken != null && !mAppDied
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001468 && (!mAppToken.isFreezingScreen() || !mAppFreezing);
Chong Zhang8e4bda92016-05-04 15:08:18 -07001469 }
1470
1471 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001472 * Like isOnScreen(), but we don't return true if the window is part
1473 * of a transition that has not yet been started.
1474 */
1475 boolean isReadyForDisplay() {
lumark588a3e82018-07-20 18:53:54 +08001476 if (mToken.waitingToShow && getDisplayContent().mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001477 return false;
1478 }
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001479 final boolean parentAndClientVisible = !isParentWindowHidden()
1480 && mViewVisibility == View.VISIBLE && !mToken.isHidden();
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001481 return mHasSurface && mPolicyVisibility && !mDestroying
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001482 && (parentAndClientVisible || isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001483 }
1484
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001485 // TODO: Another visibility method that was added late in the release to minimize risk.
1486 @Override
1487 public boolean canAffectSystemUiFlags() {
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001488 final boolean translucent = mAttrs.alpha == 0.0f;
Jorim Jaggi72207752018-01-08 13:16:59 +01001489 if (translucent) {
1490 return false;
1491 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001492 if (mAppToken == null) {
1493 final boolean shown = mWinAnimator.getShown();
1494 final boolean exiting = mAnimatingExit || mDestroying;
Jorim Jaggi72207752018-01-08 13:16:59 +01001495 return shown && !exiting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001496 } else {
Jorim Jaggi50bf59c2018-03-09 17:29:48 +01001497 final Task task = getTask();
1498 final boolean canFromTask = task != null && task.canAffectSystemUiFlags();
1499 return canFromTask && !mAppToken.isHidden();
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001500 }
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001501 }
1502
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001503 /**
1504 * Like isOnScreen, but returns false if the surface hasn't yet
1505 * been drawn.
1506 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001507 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001508 public boolean isDisplayedLw() {
1509 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001510 return isDrawnLw() && mPolicyVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001511 && ((!isParentWindowHidden() && (atoken == null || !atoken.hiddenRequested))
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001512 || isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001513 }
1514
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001515 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001516 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001517 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001518 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001519 public boolean isAnimatingLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001520 return isAnimating();
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001521 }
1522
Craig Mautner812d2ca2012-09-27 15:35:34 -07001523 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001524 public boolean isGoneForLayoutLw() {
1525 final AppWindowToken atoken = mAppToken;
1526 return mViewVisibility == View.GONE
1527 || !mRelayoutCalled
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001528 || (atoken == null && mToken.isHidden())
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001529 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001530 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001531 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001532 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001533 }
1534
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001535 /**
1536 * Returns true if the window has a surface that it has drawn a
1537 * complete UI in to.
1538 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001539 public boolean isDrawFinishedLw() {
1540 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001541 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1542 || mWinAnimator.mDrawState == READY_TO_SHOW
1543 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001544 }
1545
1546 /**
1547 * Returns true if the window has a surface that it has drawn a
1548 * complete UI in to.
1549 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001550 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001551 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001552 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001553 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001554 }
1555
1556 /**
1557 * Return true if the window is opaque and fully drawn. This indicates
1558 * it may obscure windows behind it.
1559 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001560 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001561 // When there is keyguard, wallpaper could be placed over the secure app
1562 // window but invisible. We need to check wallpaper visibility explicitly
1563 // to determine if it's occluding apps.
1564 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1565 || (mIsWallpaper && mWallpaperVisible))
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001566 && isDrawnLw() && !isAnimating();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001567 }
1568
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001569 @Override
1570 void onMovedByResize() {
1571 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001572 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001573 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001574 }
1575
1576 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1577 boolean changed = false;
1578
1579 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001580 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001581 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1582 }
1583
1584 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1585 // Starting window that's exiting will be removed when the animation finishes.
1586 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1587 // to actually remove it.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001588 if (!visible && isVisibleNow() && mAppToken.isSelfAnimating()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001589 mAnimatingExit = true;
1590 mRemoveOnExit = true;
1591 mWindowRemovalAllowed = true;
1592 }
1593 return changed;
1594 }
1595
chaviwe390cbd2018-04-16 15:29:38 -07001596 final boolean isVisibleNow = isVisibleNow();
1597 if (visible != isVisibleNow) {
1598 // Run exit animation if:
1599 // 1. App visibility and WS visibility are different
1600 // 2. App is not running an animation
1601 // 3. WS is currently visible
1602 if (!runningAppAnimation && isVisibleNow) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001603 final AccessibilityController accessibilityController =
1604 mService.mAccessibilityController;
chaviwe390cbd2018-04-16 15:29:38 -07001605 final int winTransit = TRANSIT_EXIT;
1606 mWinAnimator.applyAnimationLocked(winTransit, false /* isEntrance */);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001607 //TODO (multidisplay): Magnification is supported only for the default
1608 if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
1609 accessibilityController.onWindowTransitionLocked(this, winTransit);
1610 }
1611 }
1612 changed = true;
1613 setDisplayLayoutNeeded();
1614 }
1615
1616 return changed;
1617 }
1618
1619 boolean onSetAppExiting() {
1620 final DisplayContent displayContent = getDisplayContent();
1621 boolean changed = false;
1622
1623 if (isVisibleNow()) {
1624 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
1625 //TODO (multidisplay): Magnification is supported only for the default
1626 if (mService.mAccessibilityController != null && isDefaultDisplay()) {
1627 mService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
1628 }
1629 changed = true;
1630 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001631 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001632 }
1633 }
1634
1635 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001636 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001637 changed |= c.onSetAppExiting();
1638 }
1639
1640 return changed;
1641 }
1642
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001643 @Override
1644 void onResize() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001645 final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
Andrii Kulian3dcdf642018-05-23 17:14:00 -07001646 if (mHasSurface && !isGoneForLayoutLw() && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001647 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001648 resizingWindows.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001649 }
1650 if (isGoneForLayoutLw()) {
1651 mResizedWhileGone = true;
1652 }
1653
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001654 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001655 }
1656
1657 void onUnfreezeBounds() {
1658 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001659 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001660 c.onUnfreezeBounds();
1661 }
1662
1663 if (!mHasSurface) {
1664 return;
1665 }
1666
1667 mLayoutNeeded = true;
1668 setDisplayLayoutNeeded();
1669 if (!mService.mResizingWindows.contains(this)) {
1670 mService.mResizingWindows.add(this);
1671 }
1672 }
1673
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001674 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001675 * If the window has moved due to its containing content frame changing, then notify the
1676 * listeners and optionally animate it. Simply checking a change of position is not enough,
1677 * because being move due to dock divider is not a trigger for animation.
1678 */
chaviw161ea3e2018-01-31 12:01:12 -08001679 void handleWindowMovedIfNeeded() {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001680 if (!hasMoved()) {
1681 return;
1682 }
1683
1684 // Frame has moved, containing content frame has also moved, and we're not currently
1685 // animating... let's do something.
chaviw492139a2018-07-16 16:07:35 -07001686 final int left = mWindowFrames.mFrame.left;
1687 final int top = mWindowFrames.mFrame.top;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001688 final Task task = getTask();
1689 final boolean adjustedForMinimizedDockOrIme = task != null
1690 && (task.mStack.isAdjustedForMinimizedDockedStack()
1691 || task.mStack.isAdjustedForIme());
David Stevens9440dc82017-03-16 19:00:20 -07001692 if (mToken.okToAnimate()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001693 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1694 && !isDragResizing() && !adjustedForMinimizedDockOrIme
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001695 && getWindowConfiguration().hasMovementAnimations()
Adrian Roos0e7b70a2018-06-07 15:29:34 +02001696 && !mWinAnimator.mLastHidden
1697 && !mSeamlesslyRotated) {
chaviw161ea3e2018-01-31 12:01:12 -08001698 startMoveAnimation(left, top);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001699 }
1700
1701 //TODO (multidisplay): Accessibility supported only for the default display.
1702 if (mService.mAccessibilityController != null
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001703 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001704 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
1705 }
1706
1707 try {
1708 mClient.moved(left, top);
1709 } catch (RemoteException e) {
1710 }
1711 mMovedByResize = false;
1712 }
1713
1714 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001715 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001716 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1717 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001718 private boolean hasMoved() {
chaviw1454b392018-08-06 09:54:04 -07001719 return mHasSurface && (mWindowFrames.hasContentChanged() || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001720 && !mAnimatingExit
chaviw492139a2018-07-16 16:07:35 -07001721 && (mWindowFrames.mFrame.top != mWindowFrames.mLastFrame.top
1722 || mWindowFrames.mFrame.left != mWindowFrames.mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001723 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001724 }
1725
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001726 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001727 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001728 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001729 return false;
1730 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001731 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001732 }
1733
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001734 boolean fillsDisplay() {
1735 final DisplayInfo displayInfo = getDisplayInfo();
chaviw492139a2018-07-16 16:07:35 -07001736 return mWindowFrames.mFrame.left <= 0 && mWindowFrames.mFrame.top <= 0
1737 && mWindowFrames.mFrame.right >= displayInfo.appWidth
1738 && mWindowFrames.mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001739 }
1740
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001741 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001742 boolean isConfigChanged() {
Bryce Lee2b17afd2017-09-21 10:38:20 -07001743 return !getLastReportedConfiguration().equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001744 }
1745
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001746 void onWindowReplacementTimeout() {
1747 if (mWillReplaceWindow) {
1748 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001749 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001750 // delays removal on certain conditions, which will leave the stale window in the
1751 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1752 //
1753 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001754 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001755 } else {
1756 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001757 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001758 c.onWindowReplacementTimeout();
1759 }
1760 }
1761 }
1762
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001763 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001764 void forceWindowsScaleableInTransaction(boolean force) {
1765 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1766 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1767 }
1768
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001769 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001770 }
1771
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001772 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001773 void removeImmediately() {
1774 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001775
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001776 if (mRemoved) {
1777 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001778 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1779 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001780 return;
1781 }
1782
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001783 mRemoved = true;
1784
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001785 mWillReplaceWindow = false;
1786 if (mReplacementWindow != null) {
1787 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1788 }
1789
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001790 final DisplayContent dc = getDisplayContent();
Robert Carr825581a2018-03-30 14:00:53 -07001791 if (isInputMethodTarget()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001792 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001793 }
1794
1795 final int type = mAttrs.type;
1796 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001797 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001798 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001799 if (mTapExcludeRegionHolder != null) {
1800 // If a tap exclude region container was initialized for this window, then it should've
1801 // also been registered in display.
1802 dc.mTapExcludeProvidingWindows.remove(this);
1803 }
Tiger Huang7c610aa2018-10-27 00:01:01 +08001804 dc.getDisplayPolicy().removeWindowLw(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001805
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001806 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001807
Craig Mautner96868332012-12-04 14:29:11 -08001808 mWinAnimator.destroyDeferredSurfaceLocked();
1809 mWinAnimator.destroySurfaceLocked();
Wale Ogunwale943002b2017-02-15 19:34:01 -08001810 mSession.windowRemovedLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001811 try {
1812 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1813 } catch (RuntimeException e) {
1814 // Ignore if it has already been removed (usually because
1815 // we are doing this as part of processing a death note.)
1816 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001817
1818 mService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001819 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001820
Wale Ogunwale571771c2016-08-26 13:18:50 -07001821 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001822 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001823 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001824 removeIfPossible(false /*keepVisibleDeadWindow*/);
1825 }
1826
Wale Ogunwale571771c2016-08-26 13:18:50 -07001827 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001828 mWindowRemovalAllowed = true;
1829 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1830 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1831
1832 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1833 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1834 "Starting window removed " + this);
1835
Tiger Huang1e5b10a2018-07-30 20:19:51 +08001836 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && isFocused())
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001837 Slog.v(TAG_WM, "Remove " + this + " client="
1838 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1839 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1840 + Debug.getCallers(5));
1841
1842 final long origId = Binder.clearCallingIdentity();
1843
Peter Visontay3556a3b2017-11-01 17:23:17 +00001844 try {
1845 disposeInputChannel();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001846
Peter Visontay3556a3b2017-11-01 17:23:17 +00001847 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1848 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1849 + " mAnimatingExit=" + mAnimatingExit
1850 + " mRemoveOnExit=" + mRemoveOnExit
1851 + " mHasSurface=" + mHasSurface
1852 + " surfaceShowing=" + mWinAnimator.getShown()
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001853 + " animating=" + isAnimating()
Peter Visontay3556a3b2017-11-01 17:23:17 +00001854 + " app-animation="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001855 + (mAppToken != null ? mAppToken.isSelfAnimating() : "false")
Peter Visontay3556a3b2017-11-01 17:23:17 +00001856 + " mWillReplaceWindow=" + mWillReplaceWindow
1857 + " inPendingTransaction="
1858 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
1859 + " mDisplayFrozen=" + mService.mDisplayFrozen
1860 + " callers=" + Debug.getCallers(6));
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001861
Peter Visontay3556a3b2017-11-01 17:23:17 +00001862 // Visibility of the removed window. Will be used later to update orientation later on.
1863 boolean wasVisible = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001864
Peter Visontay3556a3b2017-11-01 17:23:17 +00001865 final int displayId = getDisplayId();
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001866
Peter Visontay3556a3b2017-11-01 17:23:17 +00001867 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1868 // window until the animation is done. If the display is frozen, just remove immediately,
1869 // since the animation wouldn't be seen.
1870 if (mHasSurface && mToken.okToAnimate()) {
1871 if (mWillReplaceWindow) {
1872 // This window is going to be replaced. We need to keep it around until the new one
1873 // gets added, then we will get rid of this one.
1874 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1875 "Preserving " + this + " until the new one is " + "added");
1876 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1877 // been removed. We probably need another flag to indicate that window removal
1878 // should be deffered vs. overloading the flag that says we are playing an exit
1879 // animation.
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001880 mAnimatingExit = true;
Peter Visontay3556a3b2017-11-01 17:23:17 +00001881 mReplacingRemoveRequested = true;
1882 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001883 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001884
Peter Visontay3556a3b2017-11-01 17:23:17 +00001885 // If we are not currently running the exit animation, we need to see about starting one
1886 wasVisible = isWinVisibleLw();
1887
1888 if (keepVisibleDeadWindow) {
1889 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1890 "Not removing " + this + " because app died while it's visible");
1891
1892 mAppDied = true;
1893 setDisplayLayoutNeeded();
1894 mService.mWindowPlacerLocked.performSurfacePlacement();
1895
1896 // Set up a replacement input channel since the app is now dead.
1897 // We need to catch tapping on the dead window to restart the app.
1898 openInputChannel(null);
Arthur Hung95b38a92018-07-20 18:56:12 +08001899 getDisplayContent().getInputMonitor().updateInputWindowsLw(true /*force*/);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001900 return;
1901 }
1902
1903 if (wasVisible) {
1904 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
1905
1906 // Try starting an animation.
1907 if (mWinAnimator.applyAnimationLocked(transit, false)) {
1908 mAnimatingExit = true;
Jorim Jaggif41e8822018-04-06 17:22:03 +02001909
1910 // mAnimatingExit affects canAffectSystemUiFlags(). Run layout such that
1911 // any change from that is performed immediately.
1912 setDisplayLayoutNeeded();
1913 mService.requestTraversal();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001914 }
1915 //TODO (multidisplay): Magnification is supported only for the default display.
1916 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
1917 mService.mAccessibilityController.onWindowTransitionLocked(this, transit);
1918 }
1919 }
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001920 final boolean isAnimating = isAnimating()
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001921 && (mAppToken == null || !mAppToken.isWaitingForTransitionStart());
Peter Visontay3556a3b2017-11-01 17:23:17 +00001922 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
1923 && mAppToken.isLastWindow(this);
1924 // We delay the removal of a window if it has a showing surface that can be used to run
1925 // exit animation and it is marked as exiting.
1926 // Also, If isn't the an animating starting window that is the last window in the app.
1927 // We allow the removal of the non-animating starting window now as there is no
1928 // additional window or animation that will trigger its removal.
1929 if (mWinAnimator.getShown() && mAnimatingExit
1930 && (!lastWindowIsStartingWindow || isAnimating)) {
1931 // The exit animation is running or should run... wait for it!
1932 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1933 "Not removing " + this + " due to exit animation ");
1934 setupWindowForRemoveOnExit();
1935 if (mAppToken != null) {
1936 mAppToken.updateReportedVisibilityLocked();
1937 }
1938 return;
1939 }
1940 }
1941
1942 removeImmediately();
1943 // Removing a visible window will effect the computed orientation
1944 // So just update orientation if needed.
Riddle Hsu4e611772018-10-31 18:58:28 +08001945 if (wasVisible) {
1946 final DisplayContent displayContent = getDisplayContent();
1947 if (displayContent.updateOrientationFromAppTokens()) {
1948 displayContent.sendNewConfiguration();
1949 }
Peter Visontay3556a3b2017-11-01 17:23:17 +00001950 }
Tiger Huang1e5b10a2018-07-30 20:19:51 +08001951 mService.updateFocusedWindowLocked(isFocused()
Tiger Huang8af6ba42018-06-07 19:24:09 +08001952 ? UPDATE_FOCUS_REMOVING_FOCUS
1953 : UPDATE_FOCUS_NORMAL,
1954 true /*updateInputWindows*/);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001955 } finally {
1956 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001957 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001958 }
1959
1960 private void setupWindowForRemoveOnExit() {
1961 mRemoveOnExit = true;
1962 setDisplayLayoutNeeded();
1963 // Request a focus update as this window's input channel is already gone. Otherwise
1964 // we could have no focused window in input manager.
1965 final boolean focusChanged = mService.updateFocusedWindowLocked(
1966 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
1967 mService.mWindowPlacerLocked.performSurfacePlacement();
1968 if (focusChanged) {
Arthur Hung95b38a92018-07-20 18:56:12 +08001969 getDisplayContent().getInputMonitor().updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001970 }
1971 }
1972
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001973 void setHasSurface(boolean hasSurface) {
1974 mHasSurface = hasSurface;
1975 }
1976
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001977 boolean canBeImeTarget() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08001978 if (mIsImWindow) {
1979 // IME windows can't be IME targets. IME targets are required to be below the IME
1980 // windows and that wouldn't be possible if the IME window is its own target...silly.
1981 return false;
1982 }
1983
Winson Chung3d0a74a2017-07-12 12:37:19 -07001984 final boolean windowsAreFocusable = mAppToken == null || mAppToken.windowsAreFocusable();
Winson Chungb1549342017-07-11 09:59:56 -07001985 if (!windowsAreFocusable) {
1986 // This window can't be an IME target if the app's windows should not be focusable.
1987 return false;
1988 }
1989
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08001990 final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001991 final int type = mAttrs.type;
1992
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08001993 // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are set or
1994 // both are cleared...and not a starting window.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001995 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
1996 && type != TYPE_APPLICATION_STARTING) {
1997 return false;
1998 }
1999
2000 if (DEBUG_INPUT_METHOD) {
2001 Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding());
2002 if (!isVisibleOrAdding()) {
2003 Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController
2004 + " relayoutCalled=" + mRelayoutCalled
2005 + " viewVis=" + mViewVisibility
2006 + " policyVis=" + mPolicyVisibility
2007 + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim
2008 + " parentHidden=" + isParentWindowHidden()
2009 + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
2010 if (mAppToken != null) {
2011 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + mAppToken.hiddenRequested);
2012 }
2013 }
2014 }
2015 return isVisibleOrAdding();
2016 }
2017
Chong Zhangacf11402015-11-04 16:23:10 -08002018 private final class DeadWindowEventReceiver extends InputEventReceiver {
2019 DeadWindowEventReceiver(InputChannel inputChannel) {
2020 super(inputChannel, mService.mH.getLooper());
2021 }
2022 @Override
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08002023 public void onInputEvent(InputEvent event) {
Chong Zhangacf11402015-11-04 16:23:10 -08002024 finishInputEvent(event, true);
2025 }
2026 }
2027 /**
2028 * Dummy event receiver for windows that died visible.
2029 */
2030 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2031
Chong Zhang112eb8c2015-11-02 11:17:00 -08002032 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002033 if (mInputChannel != null) {
2034 throw new IllegalStateException("Window already has an input channel.");
2035 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002036 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002037 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2038 mInputChannel = inputChannels[0];
2039 mClientChannel = inputChannels[1];
2040 mInputWindowHandle.inputChannel = inputChannels[0];
2041 if (outInputChannel != null) {
2042 mClientChannel.transferTo(outInputChannel);
2043 mClientChannel.dispose();
2044 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002045 } else {
2046 // If the window died visible, we setup a dummy input channel, so that taps
2047 // can still detected by input monitor channel, and we can relaunch the app.
2048 // Create dummy event receiver that simply reports all events as handled.
2049 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002050 }
Robert Carre0a353c2018-08-02 16:38:04 -07002051 mService.mInputManager.registerInputChannel(mInputChannel, mClient.asBinder());
Jeff Browncc4f7db2011-08-30 20:34:48 -07002052 }
2053
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002054 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002055 if (mDeadWindowEventReceiver != null) {
2056 mDeadWindowEventReceiver.dispose();
2057 mDeadWindowEventReceiver = null;
2058 }
2059
2060 // unregister server channel first otherwise it complains about broken channel
2061 if (mInputChannel != null) {
2062 mService.mInputManager.unregisterInputChannel(mInputChannel);
Robert Carre0a353c2018-08-02 16:38:04 -07002063
Chong Zhangacf11402015-11-04 16:23:10 -08002064 mInputChannel.dispose();
2065 mInputChannel = null;
2066 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002067 if (mClientChannel != null) {
2068 mClientChannel.dispose();
2069 mClientChannel = null;
2070 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07002071 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002072 }
2073
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002074 /** Returns true if the replacement window was removed. */
2075 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2076 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2077 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2078 removeReplacedWindow();
2079 return true;
2080 }
2081
2082 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002083 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002084 if (c.removeReplacedWindowIfNeeded(replacement)) {
2085 return true;
2086 }
2087 }
2088 return false;
2089 }
2090
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002091 private void removeReplacedWindow() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002092 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002093 mWillReplaceWindow = false;
2094 mAnimateReplacingWindow = false;
2095 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002096 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002097 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002098 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002099 }
2100 }
2101
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002102 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2103 boolean replacementSet = false;
2104
2105 if (mWillReplaceWindow && mReplacementWindow == null
2106 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2107
2108 mReplacementWindow = replacementCandidate;
2109 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2110 replacementSet = true;
2111 }
2112
2113 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002114 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002115 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2116 }
2117
2118 return replacementSet;
2119 }
2120
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002121 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002122 final DisplayContent dc = getDisplayContent();
2123 if (dc != null) {
2124 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002125 }
2126 }
2127
Chong Zhang5117e272016-05-03 12:47:34 -07002128 void applyAdjustForImeIfNeeded() {
2129 final Task task = getTask();
2130 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2131 task.mStack.applyAdjustForImeIfNeeded(task);
2132 }
2133 }
2134
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002135 @Override
2136 void switchUser() {
2137 super.switchUser();
2138 if (isHiddenFromUserLocked()) {
2139 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2140 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
2141 hideLw(false);
2142 }
2143 }
2144
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002145 int getTouchableRegion(Region region, int flags) {
2146 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002147 if (modal && mAppToken != null) {
2148 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002149 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002150 // If this is a modal window we need to dismiss it if it's not full screen and the
2151 // touch happens outside of the frame that displays the content. This means we
2152 // need to intercept touches outside of that window. The dim layer user
2153 // associated with the window (task or stack) will give us the good bounds, as
2154 // they would be used to display the dim layer.
Robert Carrf59b8dd2017-10-02 18:58:36 -07002155 final Task task = getTask();
2156 if (task != null) {
2157 task.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002158 } else {
Robert Carrf59b8dd2017-10-02 18:58:36 -07002159 getStack().getDimBounds(mTmpRect);
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002160 }
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002161 if (inFreeformWindowingMode()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002162 // For freeform windows we the touch region to include the whole surface for the
2163 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002164 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2165 final int delta = WindowManagerService.dipToPixel(
2166 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2167 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002168 }
2169 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002170 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002171 } else {
2172 // Not modal or full screen modal
2173 getTouchableRegion(region);
2174 }
2175 return flags;
2176 }
2177
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002178 void checkPolicyVisibilityChange() {
2179 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2180 if (DEBUG_VISIBILITY) {
2181 Slog.v(TAG, "Policy visibility changing after anim in " +
2182 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2183 }
2184 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002185 if (!mPolicyVisibility) {
Jorim Jaggi2e05af22017-12-28 15:15:11 +01002186 mWinAnimator.hide("checkPolicyVisibilityChange");
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002187 if (isFocused()) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002188 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2189 "setAnimationLocked: setting mFocusMayChange true");
2190 mService.mFocusMayChange = true;
2191 }
Tetsutoki Shiozawa64c5f0c2018-05-18 10:55:01 +09002192 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002193 // Window is no longer visible -- make sure if we were waiting
2194 // for it to be displayed before enabling the display, that
2195 // we allow the display to be enabled now.
2196 mService.enableScreenIfNeededLocked();
2197 }
2198 }
2199 }
2200
2201 void setRequestedSize(int requestedWidth, int requestedHeight) {
2202 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2203 mLayoutNeeded = true;
2204 mRequestedWidth = requestedWidth;
2205 mRequestedHeight = requestedHeight;
2206 }
2207 }
2208
Bryce Leef858b572017-06-29 14:03:33 -07002209 void prepareWindowToDisplayDuringRelayout(boolean wasVisible) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002210 // We need to turn on screen regardless of visibility.
chaviw40234662018-02-07 09:37:16 -08002211 boolean hasTurnScreenOnFlag = (mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0;
2212 boolean allowTheaterMode =
2213 mService.mAllowTheaterModeWakeFromLayout || Settings.Global.getInt(
2214 mService.mContext.getContentResolver(), Settings.Global.THEATER_MODE_ON, 0)
2215 == 0;
2216 boolean canTurnScreenOn = mAppToken == null || mAppToken.canTurnScreenOn();
2217
2218 // The screen will turn on if the following conditions are met
2219 // 1. The window has the flag FLAG_TURN_SCREEN_ON
2220 // 2. The WMS allows theater mode.
2221 // 3. No AWT or the AWT allows the screen to be turned on. This should only be true once
2222 // per resume to prevent the screen getting getting turned on for each relayout. Set
2223 // canTurnScreenOn will be set to false so the window doesn't turn the screen on again
2224 // during this resume.
2225 // 4. When the screen is not interactive. This is because when the screen is already
2226 // interactive, the value may persist until the next animation, which could potentially
2227 // be occurring while turning off the screen. This would lead to the screen incorrectly
2228 // turning back on.
chaviw474093d2018-03-07 15:03:38 -08002229 if (hasTurnScreenOnFlag) {
2230 if (allowTheaterMode && canTurnScreenOn && !mPowerManagerWrapper.isInteractive()) {
2231 if (DEBUG_VISIBILITY || DEBUG_POWER) {
2232 Slog.v(TAG, "Relayout window turning screen on: " + this);
2233 }
2234 mPowerManagerWrapper.wakeUp(SystemClock.uptimeMillis(),
2235 "android.server.wm:TURN_ON");
chaviw40234662018-02-07 09:37:16 -08002236 }
chaviwb28de1f2018-03-02 10:42:36 -08002237
2238 if (mAppToken != null) {
2239 mAppToken.setCanTurnScreenOn(false);
2240 }
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002241 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002242
2243 // If we were already visible, skip rest of preparation.
2244 if (wasVisible) {
2245 if (DEBUG_VISIBILITY) Slog.v(TAG,
2246 "Already visible and does not turn on screen, skip preparing: " + this);
2247 return;
2248 }
2249
2250 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2251 == SOFT_INPUT_ADJUST_RESIZE) {
2252 mLayoutNeeded = true;
2253 }
2254
David Stevens9440dc82017-03-16 19:00:20 -07002255 if (isDrawnLw() && mToken.okToAnimate()) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002256 mWinAnimator.applyEnterAnimationLocked();
2257 }
Bryce Leef858b572017-06-29 14:03:33 -07002258 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002259
Yunfan Chen75157d72018-07-27 14:47:21 +09002260 private Configuration getProcessGlobalConfiguration() {
2261 // For child windows we want to use the pid for the parent window in case the the child
2262 // window was added from another process.
Yunfan Chen79b96062018-10-17 12:45:23 -07002263 final int pid = getParentWindow() != null ? getParentWindow().mSession.mPid : mSession.mPid;
Yunfan Chen75157d72018-07-27 14:47:21 +09002264 mTempConfiguration.setTo(mService.mProcessConfigurations.get(
2265 pid, mService.mRoot.getConfiguration()));
2266 return mTempConfiguration;
2267 }
2268
Bryce Leef858b572017-06-29 14:03:33 -07002269 void getMergedConfiguration(MergedConfiguration outConfiguration) {
Yunfan Chen75157d72018-07-27 14:47:21 +09002270 final Configuration globalConfig = getProcessGlobalConfiguration();
Bryce Leef858b572017-06-29 14:03:33 -07002271 final Configuration overrideConfig = getMergedOverrideConfiguration();
2272 outConfiguration.setConfiguration(globalConfig, overrideConfig);
2273 }
2274
Bryce Lee2b17afd2017-09-21 10:38:20 -07002275 void setLastReportedMergedConfiguration(MergedConfiguration config) {
2276 mLastReportedConfiguration.setTo(config);
2277 }
2278
2279 void getLastReportedMergedConfiguration(MergedConfiguration config) {
2280 config.setTo(mLastReportedConfiguration);
2281 }
2282
2283 private Configuration getLastReportedConfiguration() {
2284 return mLastReportedConfiguration.getMergedConfiguration();
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002285 }
2286
2287 void adjustStartingWindowFlags() {
2288 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2289 && mAppToken.startingWindow != null) {
2290 // Special handling of starting window over the base
2291 // window of the app: propagate lock screen flags to it,
2292 // to provide the correct semantics while starting.
2293 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2294 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2295 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2296 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2297 }
2298 }
2299
2300 void setWindowScale(int requestedWidth, int requestedHeight) {
2301 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2302
2303 if (scaledWindow) {
2304 // requested{Width|Height} Surface's physical size
2305 // attrs.{width|height} Size on screen
2306 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2307 mHScale = (mAttrs.width != requestedWidth) ?
2308 (mAttrs.width / (float)requestedWidth) : 1.0f;
2309 mVScale = (mAttrs.height != requestedHeight) ?
2310 (mAttrs.height / (float)requestedHeight) : 1.0f;
2311 } else {
2312 mHScale = mVScale = 1;
2313 }
2314 }
2315
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002316 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002317 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002318 public void binderDied() {
2319 try {
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002320 boolean resetSplitScreenResizing = false;
Wale Ogunwaledb485de2018-10-29 09:47:07 -07002321 synchronized (mService.mGlobalLock) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002322 final WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002323 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002324 if (win != null) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002325 final DisplayContent dc = getDisplayContent();
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002326 if (win.mAppToken != null && win.mAppToken.findMainWindow() == win) {
2327 mService.mTaskSnapshotController.onAppDied(win.mAppToken);
2328 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002329 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002330 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2331 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002332 // just in case they have the divider at an unstable position. Better
2333 // also reset drag resizing state, because the owner can't do it
2334 // anymore.
Wale Ogunwale61911492017-10-11 08:50:50 -07002335 final TaskStack stack =
Matthew Ng64e77cf2017-10-31 14:01:31 -07002336 dc.getSplitScreenPrimaryStackIgnoringVisibility();
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002337 if (stack != null) {
2338 stack.resetDockedStackToMiddle();
2339 }
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002340 resetSplitScreenResizing = true;
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002341 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002342 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002343 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002344 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002345 }
2346 }
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002347 if (resetSplitScreenResizing) {
2348 try {
2349 // Note: this calls into ActivityManager, so we must *not* hold the window
2350 // manager lock while calling this.
Wale Ogunwale04d9cb52018-04-30 13:55:07 -07002351 mService.mActivityTaskManager.setSplitScreenResizing(false);
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002352 } catch (RemoteException e) {
2353 // Local call, shouldn't return RemoteException.
2354 throw e.rethrowAsRuntimeException();
2355 }
2356 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002357 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002358 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002359 }
2360 }
2361 }
2362
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002363 /**
2364 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2365 * because we want to preserve its location on screen to be re-activated later when the user
2366 * interacts with it.
2367 */
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002368 private boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwale89973222017-04-23 18:39:45 -07002369 if (!isWinVisibleLw() || mAppToken == null || mAppToken.isClientHidden()) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002370 // Not a visible app window or the app isn't dead.
2371 return false;
2372 }
2373
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002374 if (mAttrs.token != mClient.asBinder()) {
2375 // The window was add by a client using another client's app token. We don't want to
2376 // keep the dead window around for this case since this is meant for 'real' apps.
2377 return false;
2378 }
2379
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002380 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2381 // We don't keep starting windows since they were added by the window manager before
2382 // the app even launched.
2383 return false;
2384 }
2385
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002386 return getWindowConfiguration().keepVisibleDeadAppWindowOnScreen();
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002387 }
2388
Tiger Huang513d5e12018-07-16 21:49:50 +08002389 @Override
2390 public boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002391 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002392 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002393 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002394 && (mAppToken == null || mAppToken.windowsAreFocusable())
Matthew Nge15352e2016-12-20 15:36:29 -08002395 && !canReceiveTouchInput();
2396 }
2397
2398 /** @return true if this window desires touch events. */
2399 boolean canReceiveTouchInput() {
Bryce Lee6d410262017-02-28 15:30:17 -08002400 return mAppToken != null && mAppToken.getTask() != null
2401 && mAppToken.getTask().mStack.shouldIgnoreInput();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002402 }
2403
Craig Mautner749a7bb2012-04-02 13:49:53 -07002404 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002405 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002406 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002407 }
2408
Craig Mautner749a7bb2012-04-02 13:49:53 -07002409 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002410 public boolean showLw(boolean doAnimation) {
2411 return showLw(doAnimation, true);
2412 }
2413
2414 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002415 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002416 return false;
2417 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002418 if (!mAppOpVisibility) {
2419 // Being hidden due to app op request.
2420 return false;
2421 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002422 if (mPermanentlyHidden) {
2423 // Permanently hidden until the app exists as apps aren't prepared
2424 // to handle their windows being removed from under them.
2425 return false;
2426 }
Suprabh Shukla69c71422018-04-02 18:39:01 -07002427 if (mHiddenWhileSuspended) {
2428 // Being hidden due to owner package being suspended.
2429 return false;
2430 }
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002431 if (mForceHideNonSystemOverlayWindow) {
2432 // This is an alert window that is currently force hidden.
2433 return false;
2434 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002435 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002436 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002437 return false;
2438 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002439 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002440 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002441 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02002442 + mPolicyVisibility + " animating=" + isAnimating());
David Stevens9440dc82017-03-16 19:00:20 -07002443 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002444 doAnimation = false;
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02002445 } else if (mPolicyVisibility && !isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002446 // Check for the case where we are currently visible and
2447 // not animating; we do not want to do animation at such a
2448 // point to become visible when we already are.
2449 doAnimation = false;
2450 }
2451 }
2452 mPolicyVisibility = true;
2453 mPolicyVisibilityAfterAnim = true;
2454 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002455 mWinAnimator.applyAnimationLocked(TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002456 }
2457 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002458 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002459 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002460 if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) {
2461 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2462 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002463 return true;
2464 }
2465
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002466 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002467 public boolean hideLw(boolean doAnimation) {
2468 return hideLw(doAnimation, true);
2469 }
2470
2471 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2472 if (doAnimation) {
David Stevens9440dc82017-03-16 19:00:20 -07002473 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002474 doAnimation = false;
2475 }
2476 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002477 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002478 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002479 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002480 return false;
2481 }
2482 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002483 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02002484 if (!isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002485 doAnimation = false;
2486 }
2487 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002488 mPolicyVisibilityAfterAnim = false;
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002489 final boolean isFocused = isFocused();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002490 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002491 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002492 mPolicyVisibility = false;
2493 // Window is no longer visible -- make sure if we were waiting
2494 // for it to be displayed before enabling the display, that
2495 // we allow the display to be enabled now.
2496 mService.enableScreenIfNeededLocked();
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002497 if (isFocused) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002498 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002499 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002500 mService.mFocusMayChange = true;
2501 }
2502 }
2503 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002504 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002505 }
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002506 if (isFocused) {
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002507 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2508 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002509 return true;
2510 }
2511
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002512 void setForceHideNonSystemOverlayWindowIfNeeded(boolean forceHide) {
2513 if (mOwnerCanAddInternalSystemWindow
2514 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2515 return;
2516 }
2517 if (mForceHideNonSystemOverlayWindow == forceHide) {
2518 return;
2519 }
2520 mForceHideNonSystemOverlayWindow = forceHide;
2521 if (forceHide) {
2522 hideLw(true /* doAnimation */, true /* requestAnim */);
2523 } else {
2524 showLw(true /* doAnimation */, true /* requestAnim */);
2525 }
2526 }
2527
Suprabh Shukla69c71422018-04-02 18:39:01 -07002528 void setHiddenWhileSuspended(boolean hide) {
2529 if (mOwnerCanAddInternalSystemWindow
2530 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2531 return;
2532 }
2533 if (mHiddenWhileSuspended == hide) {
2534 return;
2535 }
2536 mHiddenWhileSuspended = hide;
2537 if (hide) {
2538 hideLw(true, true);
2539 } else {
2540 showLw(true, true);
2541 }
2542 }
2543
Svet Ganovf7b47252018-02-26 11:11:27 -08002544 private void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002545 if (mAppOpVisibility != state) {
2546 mAppOpVisibility = state;
2547 if (state) {
2548 // If the policy visibility had last been to hide, then this
2549 // will incorrectly show at this point since we lost that
2550 // information. Not a big deal -- for the windows that have app
2551 // ops modifies they should only be hidden by policy due to the
2552 // lock screen, and the user won't be changing this if locked.
2553 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002554 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002555 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002556 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002557 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002558 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002559 }
2560
Svet Ganovf7b47252018-02-26 11:11:27 -08002561 void initAppOpsState() {
2562 if (mAppOp == OP_NONE || !mAppOpVisibility) {
2563 return;
2564 }
2565 // If the app op was MODE_DEFAULT we would have checked the permission
2566 // and add the window only if the permission was granted. Therefore, if
2567 // the mode is MODE_DEFAULT we want the op to succeed as the window is
2568 // shown.
2569 final int mode = mService.mAppOps.startOpNoThrow(mAppOp,
2570 getOwningUid(), getOwningPackage(), true);
2571 if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) {
2572 setAppOpVisibilityLw(false);
2573 }
2574 }
2575
2576 void resetAppOpsState() {
2577 if (mAppOp != OP_NONE && mAppOpVisibility) {
2578 mService.mAppOps.finishOp(mAppOp, getOwningUid(), getOwningPackage());
2579 }
2580 }
2581
2582 void updateAppOpsState() {
2583 if (mAppOp == OP_NONE) {
2584 return;
2585 }
2586 final int uid = getOwningUid();
2587 final String packageName = getOwningPackage();
2588 if (mAppOpVisibility) {
2589 // There is a race between the check and the finish calls but this is fine
2590 // as this would mean we will get another change callback and will reconcile.
2591 int mode = mService.mAppOps.checkOpNoThrow(mAppOp, uid, packageName);
2592 if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) {
2593 mService.mAppOps.finishOp(mAppOp, uid, packageName);
2594 setAppOpVisibilityLw(false);
2595 }
2596 } else {
Svet Ganov522ed242018-03-07 21:40:28 -08002597 final int mode = mService.mAppOps.startOpNoThrow(mAppOp, uid, packageName, true);
Svet Ganovf7b47252018-02-26 11:11:27 -08002598 if (mode == MODE_ALLOWED || mode == MODE_DEFAULT) {
2599 setAppOpVisibilityLw(true);
2600 }
2601 }
2602 }
2603
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002604 public void hidePermanentlyLw() {
2605 if (!mPermanentlyHidden) {
2606 mPermanentlyHidden = true;
2607 hideLw(true, true);
2608 }
2609 }
2610
Jeff Brownc2932a12014-11-20 18:04:05 -08002611 public void pokeDrawLockLw(long timeout) {
2612 if (isVisibleOrAdding()) {
2613 if (mDrawLock == null) {
2614 // We want the tag name to be somewhat stable so that it is easier to correlate
2615 // in wake lock statistics. So in particular, we don't want to include the
2616 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002617 final CharSequence tag = getWindowTag();
chaviw40234662018-02-07 09:37:16 -08002618 mDrawLock = mService.mPowerManager.newWakeLock(DRAW_WAKE_LOCK, "Window:" + tag);
Jeff Brownc2932a12014-11-20 18:04:05 -08002619 mDrawLock.setReferenceCounted(false);
2620 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2621 }
2622 // Each call to acquire resets the timeout.
2623 if (DEBUG_POWER) {
2624 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2625 + mAttrs.packageName);
2626 }
2627 mDrawLock.acquire(timeout);
2628 } else if (DEBUG_POWER) {
2629 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2630 + "owned by " + mAttrs.packageName);
2631 }
2632 }
2633
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002634 @Override
2635 public boolean isAlive() {
2636 return mClient.asBinder().isBinderAlive();
2637 }
2638
Craig Mautnera987d432012-10-11 14:07:58 -07002639 boolean isClosing() {
chaviw4ad54912018-05-30 11:05:44 -07002640 return mAnimatingExit || (mAppToken != null && mAppToken.isClosingOrEnteringPip());
Craig Mautnera987d432012-10-11 14:07:58 -07002641 }
2642
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002643 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2644 animators.add(mWinAnimator);
2645
2646 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002647 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002648 c.addWinAnimatorToList(animators);
2649 }
2650 }
2651
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002652 void sendAppVisibilityToClients() {
2653 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002654
Wale Ogunwale89973222017-04-23 18:39:45 -07002655 final boolean clientHidden = mAppToken.isClientHidden();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002656 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2657 // Don't hide the starting window.
2658 return;
2659 }
2660
Wale Ogunwale89973222017-04-23 18:39:45 -07002661 if (clientHidden) {
2662 // Once we are notifying the client that it's visibility has changed, we need to prevent
2663 // it from destroying child surfaces until the animation has finished. We do this by
2664 // detaching any surface control the client added from the client.
2665 for (int i = mChildren.size() - 1; i >= 0; --i) {
2666 final WindowState c = mChildren.get(i);
2667 c.mWinAnimator.detachChildren();
2668 }
2669
2670 mWinAnimator.detachChildren();
2671 }
2672
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002673 try {
2674 if (DEBUG_VISIBILITY) Slog.v(TAG,
2675 "Setting visibility of " + this + ": " + (!clientHidden));
2676 mClient.dispatchAppVisibility(!clientHidden);
2677 } catch (RemoteException e) {
2678 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002679 }
2680
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002681 void onStartFreezingScreen() {
2682 mAppFreezing = true;
2683 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002684 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002685 c.onStartFreezingScreen();
2686 }
2687 }
2688
2689 boolean onStopFreezingScreen() {
2690 boolean unfrozeWindows = false;
2691 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002692 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002693 unfrozeWindows |= c.onStopFreezingScreen();
2694 }
2695
2696 if (!mAppFreezing) {
2697 return unfrozeWindows;
2698 }
2699
Wale Ogunwale953171d2016-09-30 09:17:30 -07002700 mAppFreezing = false;
2701
Bryce Lee8c3cf382017-07-06 19:47:10 -07002702 if (mHasSurface && !getOrientationChanging()
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002703 && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
2704 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
Bryce Lee8c3cf382017-07-06 19:47:10 -07002705 setOrientationChanging(true);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002706 mService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002707 }
2708 mLastFreezeDuration = 0;
2709 setDisplayLayoutNeeded();
2710 return true;
2711 }
2712
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002713 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2714 boolean destroyedSomething = false;
Jorim Jaggi59f3e922018-01-05 15:40:32 +01002715
2716 // Copying to a different list as multiple children can be removed.
2717 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
2718 for (int i = childWindows.size() - 1; i >= 0; --i) {
2719 final WindowState c = childWindows.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002720 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2721 }
2722
Robert Carrdb2f6e62017-03-01 20:17:58 -08002723 if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) {
2724 return destroyedSomething;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002725 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08002726
2727 if (appStopped || mWindowRemovalAllowed) {
2728 mWinAnimator.destroyPreservedSurfaceLocked();
2729 }
2730
2731 if (mDestroying) {
2732 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2733 + " destroySurfaces: appStopped=" + appStopped
2734 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2735 + " win.mRemoveOnExit=" + mRemoveOnExit);
2736 if (!cleanupOnResume || mRemoveOnExit) {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002737 destroySurfaceUnchecked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08002738 }
2739 if (mRemoveOnExit) {
2740 removeImmediately();
2741 }
2742 if (cleanupOnResume) {
2743 requestUpdateWallpaperIfNeeded();
2744 }
2745 mDestroying = false;
2746 destroyedSomething = true;
2747 }
2748
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002749 return destroyedSomething;
2750 }
Chris Craik3131bde2016-05-06 13:39:08 -07002751
Robert Carr89a28ab2017-04-24 15:33:11 -07002752 // Destroy or save the application surface without checking
2753 // various indicators of whether the client has released the surface.
2754 // This is in general unsafe, and most callers should use {@link #destroySurface}
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002755 void destroySurfaceUnchecked() {
2756 mWinAnimator.destroySurfaceLocked();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002757
Chong Zhang92147042016-05-09 12:47:11 -07002758 // Clear animating flags now, since the surface is now gone. (Note this is true even
2759 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2760 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002761 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002762
Craig Mautner69b08182012-09-05 13:07:13 -07002763 @Override
2764 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002765 final DisplayContent displayContent = getDisplayContent();
2766 if (displayContent == null) {
2767 // Only a window that was on a non-default display can be detached from it.
2768 return false;
2769 }
Winson Chung47a3e652014-05-21 16:03:42 -07002770 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002771 }
2772
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002773 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07002774 mShowToOwnerOnly = showToOwnerOnly;
2775 }
2776
Wale Ogunwaleea92d972016-12-08 07:33:13 -08002777 private boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002778 // Child windows are evaluated based on their parent window.
2779 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002780 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale72919d22016-12-08 18:58:50 -08002781 && win.mAppToken != null && win.mAppToken.mShowForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002782
2783 // All window frames that are fullscreen extend above status bar, but some don't extend
2784 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2785 // bottom right.
chaviw492139a2018-07-16 16:07:35 -07002786 if (win.getFrameLw().left <= win.getDisplayFrameLw().left
2787 && win.getFrameLw().top <= win.getDisplayFrameLw().top
2788 && win.getFrameLw().right >= win.getStableFrameLw().right
2789 && win.getFrameLw().bottom >= win.getStableFrameLw().bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002790 // Is a fullscreen window, like the clock alarm. Show to everyone.
2791 return false;
2792 }
2793 }
2794
Craig Mautner341220f2012-10-16 15:20:09 -07002795 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01002796 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002797 }
2798
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002799 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2800 outRegion.set(
2801 frame.left + inset.left, frame.top + inset.top,
2802 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002803 }
2804
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002805 void getTouchableRegion(Region outRegion) {
chaviw492139a2018-07-16 16:07:35 -07002806 final Rect frame = mWindowFrames.mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002807 switch (mTouchableInsets) {
2808 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002809 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002810 outRegion.set(frame);
2811 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002812 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002813 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002814 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002815 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002816 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002817 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002818 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002819 outRegion.set(mGivenTouchableRegion);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002820 outRegion.translate(frame.left, frame.top);
2821 break;
2822 }
2823 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002824 cropRegionToStackBoundsIfNeeded(outRegion);
2825 }
2826
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002827 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002828 final Task task = getTask();
2829 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002830 return;
2831 }
2832
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002833 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002834 if (stack == null) {
2835 return;
2836 }
2837
2838 stack.getDimBounds(mTmpRect);
2839 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002840 }
2841
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002842 /**
2843 * Report a focus change. Must be called with no locks held, and consistently
2844 * from the same serialized thread (such as dispatched from a handler).
2845 */
lumark6f13d20b2018-10-19 14:38:15 +08002846 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode,
2847 boolean reportToClient) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002848 try {
lumark6f13d20b2018-10-19 14:38:15 +08002849 mClient.windowFocusChanged(focused, inTouchMode, reportToClient);
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002850 } catch (RemoteException e) {
2851 }
lumark6f13d20b2018-10-19 14:38:15 +08002852 if (mFocusCallbacks != null && reportToClient) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002853 final int N = mFocusCallbacks.beginBroadcast();
2854 for (int i=0; i<N; i++) {
2855 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2856 try {
2857 if (focused) {
2858 obs.focusGained(mWindowId.asBinder());
2859 } else {
2860 obs.focusLost(mWindowId.asBinder());
2861 }
2862 } catch (RemoteException e) {
2863 }
2864 }
2865 mFocusCallbacks.finishBroadcast();
2866 }
2867 }
2868
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002869 @Override
2870 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002871 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002872 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002873 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002874
Yunfan Chen75157d72018-07-27 14:47:21 +09002875 // We use the process config this window is associated with as the based global config since
2876 // the process can override it config, but isn't part of the window hierarchy.
2877 final Configuration config = getProcessGlobalConfiguration();
2878 config.updateFrom(getMergedOverrideConfiguration());
2879 return config;
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002880 }
2881
Craig Mautnerdf88d732014-01-27 09:21:32 -08002882 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002883 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08002884 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002885 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
chaviw9c81e632018-07-31 11:17:52 -07002886 + ": " + mWindowFrames.mCompatFrame);
Bryce Leef858b572017-06-29 14:03:33 -07002887 final MergedConfiguration mergedConfiguration =
2888 new MergedConfiguration(mService.mRoot.getConfiguration(),
2889 getMergedOverrideConfiguration());
2890
Bryce Lee2b17afd2017-09-21 10:38:20 -07002891 setLastReportedMergedConfiguration(mergedConfiguration);
Bryce Leef858b572017-06-29 14:03:33 -07002892
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002893 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002894 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
2895
chaviw492139a2018-07-16 16:07:35 -07002896 final Rect frame = mWindowFrames.mFrame;
chaviw9c81e632018-07-31 11:17:52 -07002897 final Rect overscanInsets = mWindowFrames.mLastOverscanInsets;
2898 final Rect contentInsets = mWindowFrames.mLastContentInsets;
2899 final Rect visibleInsets = mWindowFrames.mLastVisibleInsets;
2900 final Rect stableInsets = mWindowFrames.mLastStableInsets;
2901 final Rect outsets = mWindowFrames.mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002902 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Andrii Kulianb2e37802017-01-11 00:36:44 -08002903 final boolean reportOrientation = mReportOrientationChanged;
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002904 final int displayId = getDisplayId();
chaviwcdba9a42018-07-19 11:36:42 -07002905 final DisplayCutout displayCutout = getWmDisplayCutout().getDisplayCutout();
Chet Haase8eb48d22014-09-24 07:31:29 -07002906 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
2907 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002908 // To prevent deadlock simulate one-way call if win.mClient is a local object.
2909 mService.mH.post(new Runnable() {
2910 @Override
2911 public void run() {
2912 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002913 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07002914 stableInsets, outsets, reportDraw, mergedConfiguration,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002915 reportOrientation, displayId, displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002916 } catch (RemoteException e) {
2917 // Not a remote call, RemoteException won't be raised.
2918 }
2919 }
2920 });
2921 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002922 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002923 outsets, reportDraw, mergedConfiguration, reportOrientation, displayId,
2924 displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002925 }
Svetoslav4604abc2014-06-10 18:59:30 -07002926
2927 //TODO (multidisplay): Accessibility supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002928 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07002929 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07002930 }
2931
chaviw9c81e632018-07-31 11:17:52 -07002932 mWindowFrames.resetInsetsChanged();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002933 mWinAnimator.mSurfaceResized = false;
Andrii Kulianb2e37802017-01-11 00:36:44 -08002934 mReportOrientationChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08002935 } catch (RemoteException e) {
Bryce Lee8c3cf382017-07-06 19:47:10 -07002936 setOrientationChanging(false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002937 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2938 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08002939 // We are assuming the hosting process is dead or in a zombie state.
2940 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
2941 + ", removing this window.");
2942 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002943 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002944 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002945 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002946 }
2947
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002948 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08002949 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
2950 // start even if we haven't received the relayout window, so that the client requests
2951 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
2952 // until the window to small size, otherwise the multithread renderer will shift last
2953 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
2954 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002955 boolean resizing = isDragResizing() || isDragResizeChanged();
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002956 if (getWindowConfiguration().useWindowFrameForBackdrop() || !resizing) {
Garfield Tanfbd8ea62018-10-16 17:09:49 -07002957 // Surface position is now inherited from parent, and BackdropFrameRenderer uses
2958 // backdrop frame to position content. Thus we just keep the size of backdrop frame, and
2959 // remove the offset to avoid double offset from display origin.
2960 mTmpRect.set(frame);
2961 mTmpRect.offsetTo(0, 0);
2962 return mTmpRect;
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002963 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07002964 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002965 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002966 return mTmpRect;
2967 }
2968
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002969 private int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002970 final TaskStack stack = getStack();
2971 if (stack == null) {
2972 return INVALID_STACK_ID;
2973 }
2974 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002975 }
2976
2977 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
2978 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002979 MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId,
2980 DisplayCutout displayCutout)
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002981 throws RemoteException {
Robert Carr09286c92018-02-15 13:52:31 -08002982 final boolean forceRelayout = isDragResizeChanged() || reportOrientation;
Chong Zhangedaf3052016-04-22 15:04:31 -07002983
Jorim Jaggidc249c42015-12-15 14:57:31 -08002984 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Andrii Kulian44607962017-03-16 11:06:24 -07002985 reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout,
Tiger Huang7c610aa2018-10-27 00:01:01 +08002986 getDisplayContent().getDisplayPolicy().isNavBarForcedShownLw(this), displayId,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002987 new DisplayCutout.ParcelableWrapper(displayCutout));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002988 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002989 }
2990
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002991 public void registerFocusObserver(IWindowFocusObserver observer) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -07002992 synchronized (mService.mGlobalLock) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002993 if (mFocusCallbacks == null) {
2994 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
2995 }
2996 mFocusCallbacks.register(observer);
2997 }
2998 }
2999
3000 public void unregisterFocusObserver(IWindowFocusObserver observer) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -07003001 synchronized (mService.mGlobalLock) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003002 if (mFocusCallbacks != null) {
3003 mFocusCallbacks.unregister(observer);
3004 }
3005 }
3006 }
3007
Tiger Huang1e5b10a2018-07-30 20:19:51 +08003008 boolean isFocused() {
3009 return getDisplayContent().mCurrentFocus == this;
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003010 }
3011
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003012 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07003013 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003014 final Task task = getTask();
3015 return task != null && !task.isFullscreen();
3016 }
3017
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003018 /** Is this window in a container that takes up the entire screen space? */
3019 private boolean inFullscreenContainer() {
Bryce Leef3c6a472017-11-14 14:53:06 -08003020 return mAppToken == null || (mAppToken.matchParentBounds() && !isInMultiWindowMode());
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003021 }
3022
Andrii Kulian283acd22017-08-03 04:03:51 -07003023 /** @return true when the window is in fullscreen task, but has non-fullscreen bounds set. */
3024 boolean isLetterboxedAppWindow() {
Adrian Roos865c70f2018-01-10 17:32:27 +01003025 return !isInMultiWindowMode() && mAppToken != null && !mAppToken.matchParentBounds()
3026 || isLetterboxedForDisplayCutoutLw();
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003027 }
3028
Adrian Roos865c70f2018-01-10 17:32:27 +01003029 @Override
3030 public boolean isLetterboxedForDisplayCutoutLw() {
3031 if (mAppToken == null) {
3032 // Only windows with an AppWindowToken are letterboxed.
3033 return false;
3034 }
chaviwcdba9a42018-07-19 11:36:42 -07003035 if (!mWindowFrames.parentFrameWasClippedByDisplayCutout()) {
Adrian Roos5ed644f2018-03-19 17:01:05 +01003036 // Cutout didn't make a difference, no letterbox
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003037 return false;
3038 }
Adrian Roosfa02da62018-01-15 16:01:18 +01003039 if (mAttrs.layoutInDisplayCutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003040 // Layout in cutout, no letterbox.
3041 return false;
3042 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003043 if (!mAttrs.isFullscreen()) {
3044 // Not filling the parent frame, no letterbox
3045 return false;
Adrian Roosfa02da62018-01-15 16:01:18 +01003046 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003047 // Otherwise we need a letterbox if the layout was smaller than the app window token allowed
3048 // it to be.
3049 return !frameCoversEntireAppTokenBounds();
3050 }
3051
3052 /**
3053 * @return true if this window covers the entire bounds of its app window token
3054 * @throws NullPointerException if there is no app window token for this window
3055 */
3056 private boolean frameCoversEntireAppTokenBounds() {
3057 mTmpRect.set(mAppToken.getBounds());
chaviw492139a2018-07-16 16:07:35 -07003058 mTmpRect.intersectUnchecked(mWindowFrames.mFrame);
Adrian Roos5ed644f2018-03-19 17:01:05 +01003059 return mAppToken.getBounds().equals(mTmpRect);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003060 }
3061
Adrian Roos23df3a32018-03-15 15:41:13 +01003062 @Override
3063 public boolean isLetterboxedOverlappingWith(Rect rect) {
3064 return mAppToken != null && mAppToken.isLetterboxOverlappingWith(rect);
3065 }
3066
Chong Zhang3005e752015-09-18 18:46:28 -07003067 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003068 return mDragResizing != computeDragResizing();
3069 }
3070
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003071 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003072 void setWaitingForDrawnIfResizingChanged() {
3073 if (isDragResizeChanged()) {
3074 mService.mWaitingForDrawn.add(this);
3075 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003076 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003077 }
3078
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003079 /**
3080 * @return Whether we reported a drag resize change to the application or not already.
3081 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003082 private boolean isDragResizingChangeReported() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003083 return mDragResizingChangeReported;
3084 }
3085
3086 /**
3087 * Resets the state whether we reported a drag resize change to the app.
3088 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003089 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003090 void resetDragResizingChangeReported() {
3091 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003092 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003093 }
3094
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003095 int getResizeMode() {
3096 return mResizeMode;
3097 }
3098
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003099 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003100 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003101 if (task == null) {
3102 return false;
3103 }
Tomasz Mikolajewskiaf20b8d2017-11-20 16:11:33 +09003104 if (!inSplitScreenWindowingMode() && !inFreeformWindowingMode()) {
Winson Chung2af04b32017-01-24 16:21:13 -08003105 return false;
3106 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003107 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003108 // Floating windows never enter drag resize mode.
3109 return false;
3110 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003111 if (task.isDragResizing()) {
3112 return true;
3113 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003114
3115 // If the bounds are currently frozen, it means that the layout size that the app sees
3116 // and the bounds we clip this window to might be different. In order to avoid holes, we
3117 // simulate that we are still resizing so the app fills the hole with the resizing
3118 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003119 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003120 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003121 !task.inFreeformWindowingMode() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003122
Chong Zhang3005e752015-09-18 18:46:28 -07003123 }
3124
3125 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003126 final boolean resizing = computeDragResizing();
3127 if (resizing == mDragResizing) {
3128 return;
3129 }
3130 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003131 final Task task = getTask();
3132 if (task != null && task.isDragResizing()) {
3133 mResizeMode = task.getDragResizeMode();
3134 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003135 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003136 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3137 : DRAG_RESIZE_MODE_FREEFORM;
3138 }
Chong Zhang3005e752015-09-18 18:46:28 -07003139 }
3140
3141 boolean isDragResizing() {
3142 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003143 }
3144
Robert Carr2487ce72016-04-07 15:18:45 -07003145 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003146 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3147 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003148 }
3149
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07003150 @CallSuper
3151 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02003152 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003153 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02003154 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003155 writeIdentifierToProto(proto, IDENTIFIER);
3156 proto.write(DISPLAY_ID, getDisplayId());
3157 proto.write(STACK_ID, getStackId());
3158 mAttrs.writeToProto(proto, ATTRIBUTES);
3159 mGivenContentInsets.writeToProto(proto, GIVEN_CONTENT_INSETS);
chaviw553b0212018-07-12 13:37:01 -07003160 mWindowFrames.writeToProto(proto, WINDOW_FRAMES);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003161 mAttrs.surfaceInsets.writeToProto(proto, SURFACE_INSETS);
Jorim Jaggi45be1c4c2017-12-15 18:44:43 +01003162 mSurfacePosition.writeToProto(proto, SURFACE_POSITION);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003163 mWinAnimator.writeToProto(proto, ANIMATOR);
3164 proto.write(ANIMATING_EXIT, mAnimatingExit);
3165 for (int i = 0; i < mChildren.size(); i++) {
Adrian Roos4921ccf2017-09-28 16:54:06 +02003166 mChildren.get(i).writeToProto(proto, CHILD_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003167 }
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003168 proto.write(REQUESTED_WIDTH, mRequestedWidth);
3169 proto.write(REQUESTED_HEIGHT, mRequestedHeight);
3170 proto.write(VIEW_VISIBILITY, mViewVisibility);
3171 proto.write(SYSTEM_UI_VISIBILITY, mSystemUiVisibility);
3172 proto.write(HAS_SURFACE, mHasSurface);
3173 proto.write(IS_READY_FOR_DISPLAY, isReadyForDisplay());
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003174 proto.write(REMOVE_ON_EXIT, mRemoveOnExit);
3175 proto.write(DESTROYING, mDestroying);
3176 proto.write(REMOVED, mRemoved);
3177 proto.write(IS_ON_SCREEN, isOnScreen());
3178 proto.write(IS_VISIBLE, isVisible());
Vishnu Nairddd80742018-08-21 14:12:46 -07003179 proto.write(PENDING_SEAMLESS_ROTATION, mPendingSeamlessRotate != null);
3180 proto.write(FINISHED_SEAMLESS_ROTATION_FRAME, mFinishSeamlessRotateFrameNumber);
3181 proto.write(FORCE_SEAMLESS_ROTATION, mForceSeamlesslyRotate);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003182 proto.end(token);
3183 }
3184
Vishnu Nair9a3e4062018-01-11 08:42:54 -08003185 @Override
3186 public void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003187 final long token = proto.start(fieldId);
3188 proto.write(HASH_CODE, System.identityHashCode(this));
3189 proto.write(USER_ID, UserHandle.getUserId(mOwnerUid));
3190 final CharSequence title = getWindowTag();
3191 if (title != null) {
3192 proto.write(TITLE, title.toString());
3193 }
3194 proto.end(token);
3195 }
3196
Jorim Jaggia5e10572017-11-15 14:36:26 +01003197 @Override
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003198 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003199 final TaskStack stack = getStack();
chaviwc65fa582018-08-09 15:33:13 -07003200 pw.print(prefix + "mDisplayId=" + getDisplayId());
3201 if (stack != null) {
3202 pw.print(" stackId=" + stack.mStackId);
3203 }
3204 pw.println(" mSession=" + mSession
3205 + " mClient=" + mClient.asBinder());
3206 pw.println(prefix + "mOwnerUid=" + mOwnerUid
3207 + " mShowToOwnerOnly=" + mShowToOwnerOnly
3208 + " package=" + mAttrs.packageName
3209 + " appop=" + AppOpsManager.opToName(mAppOp));
3210 pw.println(prefix + "mAttrs=" + mAttrs.toString(prefix));
3211 pw.println(prefix + "Requested w=" + mRequestedWidth
3212 + " h=" + mRequestedHeight
3213 + " mLayoutSeq=" + mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003214 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
chaviwc65fa582018-08-09 15:33:13 -07003215 pw.println(prefix + "LastRequested w=" + mLastRequestedWidth
3216 + " h=" + mLastRequestedHeight);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003217 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003218 if (mIsChildWindow || mLayoutAttached) {
chaviwc65fa582018-08-09 15:33:13 -07003219 pw.println(prefix + "mParentWindow=" + getParentWindow()
3220 + " mLayoutAttached=" + mLayoutAttached);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003221 }
3222 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
chaviwc65fa582018-08-09 15:33:13 -07003223 pw.println(prefix + "mIsImWindow=" + mIsImWindow
3224 + " mIsWallpaper=" + mIsWallpaper
3225 + " mIsFloatingLayer=" + mIsFloatingLayer
3226 + " mWallpaperVisible=" + mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003227 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003228 if (dumpAll) {
Jorim Jaggi35d328a2018-08-14 17:00:20 +02003229 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3230 pw.print(" mSubLayer="); pw.print(mSubLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003231 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003232 if (dumpAll) {
chaviwc65fa582018-08-09 15:33:13 -07003233 pw.println(prefix + "mToken=" + mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003234 if (mAppToken != null) {
chaviwc65fa582018-08-09 15:33:13 -07003235 pw.println(prefix + "mAppToken=" + mAppToken);
3236 pw.print(prefix + "mAppDied=" + mAppDied);
3237 pw.print(prefix + "drawnStateEvaluated=" + getDrawnStateEvaluated());
3238 pw.println(prefix + "mightAffectAllDrawn=" + mightAffectAllDrawn());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003239 }
chaviwc65fa582018-08-09 15:33:13 -07003240 pw.println(prefix + "mViewVisibility=0x" + Integer.toHexString(mViewVisibility)
3241 + " mHaveFrame=" + mHaveFrame
3242 + " mObscured=" + mObscured);
3243 pw.println(prefix + "mSeq=" + mSeq
3244 + " mSystemUiVisibility=0x" + Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003245 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003246 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
chaviwc65fa582018-08-09 15:33:13 -07003247 || isParentWindowHidden() || mPermanentlyHidden || mForceHideNonSystemOverlayWindow
Suprabh Shukla69c71422018-04-02 18:39:01 -07003248 || mHiddenWhileSuspended) {
chaviwc65fa582018-08-09 15:33:13 -07003249 pw.println(prefix + "mPolicyVisibility=" + mPolicyVisibility
3250 + " mPolicyVisibilityAfterAnim=" + mPolicyVisibilityAfterAnim
3251 + " mAppOpVisibility=" + mAppOpVisibility
3252 + " parentHidden=" + isParentWindowHidden()
3253 + " mPermanentlyHidden=" + mPermanentlyHidden
3254 + " mHiddenWhileSuspended=" + mHiddenWhileSuspended
3255 + " mForceHideNonSystemOverlayWindow=" + mForceHideNonSystemOverlayWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003256 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003257 if (!mRelayoutCalled || mLayoutNeeded) {
chaviwc65fa582018-08-09 15:33:13 -07003258 pw.println(prefix + "mRelayoutCalled=" + mRelayoutCalled
3259 + " mLayoutNeeded=" + mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003260 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003261 if (dumpAll) {
chaviwc65fa582018-08-09 15:33:13 -07003262 pw.println(prefix + "mGivenContentInsets=" + mGivenContentInsets.toShortString(sTmpSB)
3263 + " mGivenVisibleInsets=" + mGivenVisibleInsets.toShortString(sTmpSB));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003264 if (mTouchableInsets != 0 || mGivenInsetsPending) {
chaviwc65fa582018-08-09 15:33:13 -07003265 pw.println(prefix + "mTouchableInsets=" + mTouchableInsets
3266 + " mGivenInsetsPending=" + mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003267 Region region = new Region();
3268 getTouchableRegion(region);
chaviwc65fa582018-08-09 15:33:13 -07003269 pw.println(prefix + "touchable region=" + region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003270 }
chaviwc65fa582018-08-09 15:33:13 -07003271 pw.println(prefix + "mFullConfiguration=" + getConfiguration());
3272 pw.println(prefix + "mLastReportedConfiguration=" + getLastReportedConfiguration());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003273 }
chaviwc65fa582018-08-09 15:33:13 -07003274 pw.println(prefix + "mHasSurface=" + mHasSurface
3275 + " isReadyForDisplay()=" + isReadyForDisplay()
3276 + " mWindowRemovalAllowed=" + mWindowRemovalAllowed);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003277 if (mEnforceSizeCompat) {
chaviw9c81e632018-07-31 11:17:52 -07003278 pw.println(prefix + "mCompatFrame=" + mWindowFrames.mCompatFrame.toShortString(sTmpSB));
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003279 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003280 if (dumpAll) {
chaviw553b0212018-07-12 13:37:01 -07003281 mWindowFrames.dump(pw, prefix);
chaviw9c81e632018-07-31 11:17:52 -07003282 pw.println(prefix + " surface=" + mAttrs.surfaceInsets.toShortString(sTmpSB));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003283 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01003284 super.dump(pw, prefix, dumpAll);
chaviwc65fa582018-08-09 15:33:13 -07003285 pw.println(prefix + mWinAnimator + ":");
Dianne Hackborn529e7442012-11-01 14:22:28 -07003286 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003287 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
chaviwc65fa582018-08-09 15:33:13 -07003288 pw.println(prefix + "mAnimatingExit=" + mAnimatingExit
3289 + " mRemoveOnExit=" + mRemoveOnExit
3290 + " mDestroying=" + mDestroying
3291 + " mRemoved=" + mRemoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003292 }
chaviw40234662018-02-07 09:37:16 -08003293 if (getOrientationChanging() || mAppFreezing || mReportOrientationChanged) {
chaviwc65fa582018-08-09 15:33:13 -07003294 pw.println(prefix + "mOrientationChanging=" + mOrientationChanging
3295 + " configOrientationChanging="
3296 + (getLastReportedConfiguration().orientation != getConfiguration().orientation)
3297 + " mAppFreezing=" + mAppFreezing
3298 + " mReportOrientationChanged=" + mReportOrientationChanged);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003299 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003300 if (mLastFreezeDuration != 0) {
chaviwc65fa582018-08-09 15:33:13 -07003301 pw.print(prefix + "mLastFreezeDuration=");
3302 TimeUtils.formatDuration(mLastFreezeDuration, pw);
3303 pw.println();
Dianne Hackborna57c6952013-03-29 14:46:40 -07003304 }
chaviwc65fa582018-08-09 15:33:13 -07003305 pw.print(prefix + "mForceSeamlesslyRotate=" + mForceSeamlesslyRotate
3306 + " seamlesslyRotate: pending=");
Vishnu Nairddd80742018-08-21 14:12:46 -07003307 if (mPendingSeamlessRotate != null) {
3308 mPendingSeamlessRotate.dump(pw);
3309 } else {
3310 pw.print("null");
Adrian Roos27a90d22018-07-06 02:39:54 -07003311 }
chaviwc65fa582018-08-09 15:33:13 -07003312 pw.println(" finishedFrameNumber=" + mFinishSeamlessRotateFrameNumber);
Vishnu Nairddd80742018-08-21 14:12:46 -07003313
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003314 if (mHScale != 1 || mVScale != 1) {
chaviwc65fa582018-08-09 15:33:13 -07003315 pw.println(prefix + "mHScale=" + mHScale
3316 + " mVScale=" + mVScale);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003317 }
3318 if (mWallpaperX != -1 || mWallpaperY != -1) {
chaviwc65fa582018-08-09 15:33:13 -07003319 pw.println(prefix + "mWallpaperX=" + mWallpaperX
3320 + " mWallpaperY=" + mWallpaperY);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003321 }
3322 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
chaviwc65fa582018-08-09 15:33:13 -07003323 pw.println(prefix + "mWallpaperXStep=" + mWallpaperXStep
3324 + " mWallpaperYStep=" + mWallpaperYStep);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003325 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003326 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3327 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
chaviwc65fa582018-08-09 15:33:13 -07003328 pw.println(prefix + "mWallpaperDisplayOffsetX=" + mWallpaperDisplayOffsetX
3329 + " mWallpaperDisplayOffsetY=" + mWallpaperDisplayOffsetY);
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003330 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003331 if (mDrawLock != null) {
chaviwc65fa582018-08-09 15:33:13 -07003332 pw.println(prefix + "mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003333 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003334 if (isDragResizing()) {
chaviwc65fa582018-08-09 15:33:13 -07003335 pw.println(prefix + "isDragResizing=" + isDragResizing());
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003336 }
3337 if (computeDragResizing()) {
chaviwc65fa582018-08-09 15:33:13 -07003338 pw.println(prefix + "computeDragResizing=" + computeDragResizing());
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003339 }
chaviwc65fa582018-08-09 15:33:13 -07003340 pw.println(prefix + "isOnScreen=" + isOnScreen());
3341 pw.println(prefix + "isVisible=" + isVisible());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003342 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003343
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003344 @Override
3345 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003346 return Integer.toHexString(System.identityHashCode(this))
Jorim Jaggia5e10572017-11-15 14:36:26 +01003347 + " " + getWindowTag();
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003348 }
3349
Robert Carra1eb4392015-12-10 12:43:51 -08003350 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003351 CharSequence tag = mAttrs.getTitle();
3352 if (tag == null || tag.length() <= 0) {
3353 tag = mAttrs.packageName;
3354 }
3355 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003356 }
3357
3358 @Override
3359 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003360 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003361 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003362 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003363 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003364 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003365 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003366 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003367 }
3368 return mStringNameCache;
3369 }
Robert Carr58f29132015-10-29 14:19:05 -07003370
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003371 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003372 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003373 clipRect.left = (int) (clipRect.left / mHScale);
3374 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003375 }
3376 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003377 clipRect.top = (int) (clipRect.top / mVScale);
3378 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003379 }
3380 }
Robert Carr31e28482015-12-02 16:53:18 -08003381
chaviw9c81e632018-07-31 11:17:52 -07003382 private void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003383 final int pw = containingFrame.width();
3384 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003385 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003386 final boolean inNonFullscreenContainer = !inFullscreenContainer();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003387 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3388
3389 // We need to fit it to the display if either
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003390 // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen
3391 // for the taskless windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003392 // 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 -07003393 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on
3394 // screen, but SurfaceViews want to be always at a specific location so we don't fit it to
3395 // the display.
3396 final boolean fitToDisplay = (task == null || !inNonFullscreenContainer)
Robert Carr6f44db12016-07-21 14:54:43 -07003397 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003398 float x, y;
3399 int w,h;
3400
3401 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3402 if (mAttrs.width < 0) {
3403 w = pw;
3404 } else if (mEnforceSizeCompat) {
3405 w = (int)(mAttrs.width * mGlobalScale + .5f);
3406 } else {
3407 w = mAttrs.width;
3408 }
3409 if (mAttrs.height < 0) {
3410 h = ph;
3411 } else if (mEnforceSizeCompat) {
3412 h = (int)(mAttrs.height * mGlobalScale + .5f);
3413 } else {
3414 h = mAttrs.height;
3415 }
3416 } else {
3417 if (mAttrs.width == MATCH_PARENT) {
3418 w = pw;
3419 } else if (mEnforceSizeCompat) {
3420 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3421 } else {
3422 w = mRequestedWidth;
3423 }
3424 if (mAttrs.height == MATCH_PARENT) {
3425 h = ph;
3426 } else if (mEnforceSizeCompat) {
3427 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3428 } else {
3429 h = mRequestedHeight;
3430 }
3431 }
3432
3433 if (mEnforceSizeCompat) {
3434 x = mAttrs.x * mGlobalScale;
3435 y = mAttrs.y * mGlobalScale;
3436 } else {
3437 x = mAttrs.x;
3438 y = mAttrs.y;
3439 }
3440
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003441 if (inNonFullscreenContainer && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003442 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003443 // required by {@link Gravity#apply} call.
3444 w = Math.min(w, pw);
3445 h = Math.min(h, ph);
3446 }
3447
3448 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003449 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003450 (int) (x + mAttrs.horizontalMargin * pw),
chaviw492139a2018-07-16 16:07:35 -07003451 (int) (y + mAttrs.verticalMargin * ph), mWindowFrames.mFrame);
Robert Carr31e28482015-12-02 16:53:18 -08003452
3453 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003454 if (fitToDisplay) {
chaviw492139a2018-07-16 16:07:35 -07003455 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mWindowFrames.mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003456 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003457
3458 // We need to make sure we update the CompatFrame as it is used for
3459 // cropping decisions, etc, on systems where we lack a decor layer.
chaviw9c81e632018-07-31 11:17:52 -07003460 mWindowFrames.mCompatFrame.set(mWindowFrames.mFrame);
Robert Carr6e18c5e2016-02-29 15:57:13 -08003461 if (mEnforceSizeCompat) {
3462 // See comparable block in computeFrameLw.
chaviw9c81e632018-07-31 11:17:52 -07003463 mWindowFrames.mCompatFrame.scale(mInvGlobalScale);
Robert Carr6e18c5e2016-02-29 15:57:13 -08003464 }
Robert Carr31e28482015-12-02 16:53:18 -08003465 }
Robert Carr51a1b872015-12-08 14:03:13 -08003466
3467 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003468 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003469 }
3470
Robert Carrf3b72c72016-03-21 18:16:39 -07003471 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003472 return mIsChildWindow
3473 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003474 }
3475
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003476 /**
3477 * Returns true if any window added by an application process that if of type
3478 * {@link android.view.WindowManager.LayoutParams#TYPE_TOAST} or that requires that requires
3479 * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when
3480 * this window is visible.
3481 */
3482 boolean hideNonSystemOverlayWindowsWhenVisible() {
Philip P. Moltmann66ce2382018-10-09 13:46:11 -07003483 return (mAttrs.privateFlags & SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != 0
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003484 && mSession.mCanHideNonSystemOverlayWindows;
3485 }
3486
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003487 /** Returns the parent window if this is a child of another window, else null. */
3488 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003489 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3490 // WindowContainer that isn't a WindowState.
3491 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003492 }
3493
3494 /** Returns the topmost parent window if this is a child of another window, else this. */
3495 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003496 WindowState current = this;
3497 WindowState topParent = current;
3498 while (current != null && current.mIsChildWindow) {
3499 current = current.getParentWindow();
3500 // Parent window can be null if the child is detached from it's parent already, but
3501 // someone still has a reference to access it. So, we return the top parent value we
3502 // already have instead of null.
3503 if (current != null) {
3504 topParent = current;
3505 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003506 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003507 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003508 }
3509
Wale Ogunwale9d147902016-07-16 11:58:55 -07003510 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003511 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003512 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003513 }
3514
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003515 void setWillReplaceWindow(boolean animate) {
3516 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003517 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003518 c.setWillReplaceWindow(animate);
3519 }
3520
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003521 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3522 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3523 // We don't set replacing on starting windows since they are added by window manager and
3524 // not the client so won't be replaced by the client.
3525 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003526 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003527
3528 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003529 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003530 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003531 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003532
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003533 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003534 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003535 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003536 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003537
3538 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003539 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003540 c.clearWillReplaceWindow();
3541 }
3542 }
3543
3544 boolean waitingForReplacement() {
3545 if (mWillReplaceWindow) {
3546 return true;
3547 }
3548
3549 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003550 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003551 if (c.waitingForReplacement()) {
3552 return true;
3553 }
3554 }
3555 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003556 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003557
Chong Zhang4d7369a2016-04-25 16:09:14 -07003558 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003559 final DisplayContent dc = getDisplayContent();
3560 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3561 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3562 dc.setLayoutNeeded();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003563 mService.mWindowPlacerLocked.requestTraversal();
3564 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003565
3566 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003567 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003568 c.requestUpdateWallpaperIfNeeded();
3569 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003570 }
3571
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003572 float translateToWindowX(float x) {
chaviw492139a2018-07-16 16:07:35 -07003573 float winX = x - mWindowFrames.mFrame.left;
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003574 if (mEnforceSizeCompat) {
3575 winX *= mGlobalScale;
3576 }
3577 return winX;
3578 }
3579
3580 float translateToWindowY(float y) {
chaviw492139a2018-07-16 16:07:35 -07003581 float winY = y - mWindowFrames.mFrame.top;
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003582 if (mEnforceSizeCompat) {
3583 winY *= mGlobalScale;
3584 }
3585 return winY;
3586 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003587
3588 // During activity relaunch due to resize, we sometimes use window replacement
3589 // for only child windows (as the main window is handled by window preservation)
3590 // and the big surface.
3591 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003592 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3593 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3594 // we also want to replace them at such phases, as they won't be covered by window
3595 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003596 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003597 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003598 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003599 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003600
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003601 void setWillReplaceChildWindows() {
3602 if (shouldBeReplacedWithChildren()) {
3603 setWillReplaceWindow(false /* animate */);
3604 }
3605 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003606 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003607 c.setWillReplaceChildWindows();
3608 }
3609 }
3610
3611 WindowState getReplacingWindow() {
3612 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3613 return this;
3614 }
3615 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003616 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003617 final WindowState replacing = c.getReplacingWindow();
3618 if (replacing != null) {
3619 return replacing;
3620 }
3621 }
3622 return null;
3623 }
3624
Jorim Jaggife762342016-10-13 14:33:27 +02003625 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07003626 public int getRotationAnimationHint() {
3627 if (mAppToken != null) {
3628 return mAppToken.mRotationAnimationHint;
3629 } else {
3630 return -1;
3631 }
3632 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003633
Jorim Jaggife762342016-10-13 14:33:27 +02003634 @Override
3635 public boolean isInputMethodWindow() {
3636 return mIsImWindow;
3637 }
3638
Wale Ogunwale9d147902016-07-16 11:58:55 -07003639 // This must be called while inside a transaction.
3640 boolean performShowLocked() {
3641 if (isHiddenFromUserLocked()) {
3642 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3643 hideLw(false);
3644 return false;
3645 }
3646
3647 logPerformShow("performShow on ");
3648
Jorim Jaggia50da602016-12-29 11:51:42 +01003649 final int drawState = mWinAnimator.mDrawState;
3650 if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW)
3651 && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3652 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3653 }
3654
Jorim Jaggib0d27342016-11-01 16:10:42 -07003655 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003656 return false;
3657 }
3658
3659 logPerformShow("Showing ");
3660
3661 mService.enableScreenIfNeededLocked();
3662 mWinAnimator.applyEnterAnimationLocked();
3663
3664 // Force the show in the next prepareSurfaceLocked() call.
3665 mWinAnimator.mLastAlpha = -1;
Robert Carre13b58e2017-08-31 14:50:44 -07003666 if (DEBUG_ANIM) Slog.v(TAG,
Wale Ogunwale9d147902016-07-16 11:58:55 -07003667 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3668 mWinAnimator.mDrawState = HAS_DRAWN;
3669 mService.scheduleAnimationLocked();
3670
3671 if (mHidden) {
3672 mHidden = false;
3673 final DisplayContent displayContent = getDisplayContent();
3674
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003675 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003676 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003677 if (c.mWinAnimator.mSurfaceController != null) {
3678 c.performShowLocked();
3679 // It hadn't been shown, which means layout not performed on it, so now we
3680 // want to make sure to do a layout. If called from within the transaction
3681 // loop, this will cause it to restart with a new layout.
3682 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003683 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003684 }
3685 }
3686 }
3687 }
3688
Wale Ogunwale9d147902016-07-16 11:58:55 -07003689 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003690 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003691 }
3692
3693 return true;
3694 }
3695
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003696 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003697 if (DEBUG_VISIBILITY
Jorim Jaggie4b0f282017-05-17 15:10:29 +02003698 || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003699 Slog.v(TAG, prefix + this
3700 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07003701 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003702 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3703 + " during animation: policyVis=" + mPolicyVisibility
3704 + " parentHidden=" + isParentWindowHidden()
3705 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003706 + (mAppToken != null && mAppToken.hiddenRequested)
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003707 + " tok.hidden=" + (mAppToken != null && mAppToken.isHidden())
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02003708 + " animating=" + isAnimating()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003709 + " tok animating="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003710 + (mAppToken != null && mAppToken.isSelfAnimating())
Wale Ogunwale9d147902016-07-16 11:58:55 -07003711 + " Callers=" + Debug.getCallers(4));
3712 }
3713 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003714
3715 WindowInfo getWindowInfo() {
3716 WindowInfo windowInfo = WindowInfo.obtain();
3717 windowInfo.type = mAttrs.type;
3718 windowInfo.layer = mLayer;
3719 windowInfo.token = mClient.asBinder();
Phil Weaver5dc3ebc2017-08-16 13:04:20 -07003720 if (mAppToken != null) {
3721 windowInfo.activityToken = mAppToken.appToken.asBinder();
3722 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003723 windowInfo.title = mAttrs.accessibilityTitle;
Phil Weaverbb2f28a2017-12-22 09:44:28 -08003724 // Panel windows have no public way to set the a11y title directly. Use the
3725 // regular title as a fallback.
Phil Weaver568cf662018-04-24 17:09:26 -07003726 final boolean isPanelWindow = (mAttrs.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW)
3727 && (mAttrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW);
3728 // Accessibility overlays should have titles that work for accessibility, and can't set
3729 // the a11y title themselves.
3730 final boolean isAccessibilityOverlay =
3731 windowInfo.type == WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
3732 if (TextUtils.isEmpty(windowInfo.title) && (isPanelWindow || isAccessibilityOverlay)) {
Jackal Guo25a33cbd2018-08-01 16:08:45 +08003733 final CharSequence title = mAttrs.getTitle();
3734 windowInfo.title = TextUtils.isEmpty(title) ? null : title;
Phil Weaverbb2f28a2017-12-22 09:44:28 -08003735 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003736 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3737 windowInfo.focused = isFocused();
Phil Weaverf00cd142017-03-03 13:44:00 -08003738 Task task = getTask();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003739 windowInfo.inPictureInPicture = (task != null) && task.inPinnedWindowingMode();
Jackal Guoac2b62e2018-08-22 18:28:46 +08003740 windowInfo.hasFlagWatchOutsideTouch =
3741 (mAttrs.flags & WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH) != 0;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003742
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003743 if (mIsChildWindow) {
3744 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003745 }
3746
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003747 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003748 if (childCount > 0) {
3749 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003750 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003751 }
3752 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003753 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003754 windowInfo.childTokens.add(child.mClient.asBinder());
3755 }
3756 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003757 return windowInfo;
3758 }
3759
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003760 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003761 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003762 if (mChildren.isEmpty()) {
3763 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003764 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003765 }
3766
3767 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003768 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003769 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003770 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003771 }
3772 }
3773
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003774 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003775 // We want to consume the negative sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003776 // below the parent, then this window (the parent), and then the positive sublayer children
3777 // because they need to appear above the parent.
3778 int i = 0;
3779 final int count = mChildren.size();
3780 WindowState child = mChildren.get(i);
3781
3782 while (i < count && child.mSubLayer < 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003783 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003784 return true;
3785 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003786 i++;
3787 if (i >= count) {
3788 break;
3789 }
3790 child = mChildren.get(i);
3791 }
3792
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003793 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003794 return true;
3795 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003796
3797 while (i < count) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003798 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003799 return true;
3800 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003801 i++;
3802 if (i >= count) {
3803 break;
3804 }
3805 child = mChildren.get(i);
3806 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003807
3808 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003809 }
3810
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003811 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003812 // We want to consume the positive sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003813 // above the parent, then this window (the parent), and then the negative sublayer children
3814 // because they need to appear above the parent.
3815 int i = mChildren.size() - 1;
3816 WindowState child = mChildren.get(i);
3817
3818 while (i >= 0 && child.mSubLayer >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003819 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003820 return true;
3821 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003822 --i;
3823 if (i < 0) {
3824 break;
3825 }
3826 child = mChildren.get(i);
3827 }
3828
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003829 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003830 return true;
3831 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003832
3833 while (i >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003834 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003835 return true;
3836 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003837 --i;
3838 if (i < 0) {
3839 break;
3840 }
3841 child = mChildren.get(i);
3842 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003843
3844 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003845 }
3846
Robert Carr9785cf32018-04-25 15:06:07 -07003847 private boolean applyImeWindowsIfNeeded(ToBooleanFunction<WindowState> callback,
3848 boolean traverseTopToBottom) {
3849 // If this window is the current IME target, so we need to process the IME windows
3850 // directly above it. The exception is if we are in split screen
3851 // in which case we process the IME at the DisplayContent level to
3852 // ensure it is above the docked divider.
3853 if (isInputMethodTarget() && !inSplitScreenWindowingMode()) {
3854 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
3855 return true;
3856 }
3857 }
3858 return false;
3859 }
3860
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003861 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
3862 boolean traverseTopToBottom) {
3863 if (traverseTopToBottom) {
Robert Carr9785cf32018-04-25 15:06:07 -07003864 if (applyImeWindowsIfNeeded(callback, traverseTopToBottom)
3865 || callback.apply(this)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003866 return true;
3867 }
3868 } else {
Robert Carr9785cf32018-04-25 15:06:07 -07003869 if (callback.apply(this)
3870 || applyImeWindowsIfNeeded(callback, traverseTopToBottom)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003871 return true;
3872 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003873 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003874 return false;
3875 }
3876
Wale Ogunwaled1880962016-11-08 10:31:59 -08003877 WindowState getWindow(Predicate<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003878 if (mChildren.isEmpty()) {
3879 return callback.test(this) ? this : null;
3880 }
3881
3882 // We want to consume the positive sublayer children first because they need to appear
3883 // above the parent, then this window (the parent), and then the negative sublayer children
3884 // because they need to appear above the parent.
3885 int i = mChildren.size() - 1;
3886 WindowState child = mChildren.get(i);
3887
3888 while (i >= 0 && child.mSubLayer >= 0) {
3889 if (callback.test(child)) {
3890 return child;
3891 }
3892 --i;
3893 if (i < 0) {
3894 break;
3895 }
3896 child = mChildren.get(i);
3897 }
3898
Wale Ogunwaled1880962016-11-08 10:31:59 -08003899 if (callback.test(this)) {
3900 return this;
3901 }
Wale Ogunwale34247952017-02-19 11:57:53 -08003902
3903 while (i >= 0) {
3904 if (callback.test(child)) {
3905 return child;
3906 }
3907 --i;
3908 if (i < 0) {
3909 break;
3910 }
3911 child = mChildren.get(i);
3912 }
3913
3914 return null;
Wale Ogunwaled1880962016-11-08 10:31:59 -08003915 }
3916
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01003917 /**
3918 * @return True if we our one of our ancestors has {@link #mAnimatingExit} set to true, false
3919 * otherwise.
3920 */
3921 @VisibleForTesting
3922 boolean isSelfOrAncestorWindowAnimatingExit() {
3923 WindowState window = this;
3924 do {
3925 if (window.mAnimatingExit) {
3926 return true;
3927 }
3928 window = window.getParentWindow();
3929 } while (window != null);
3930 return false;
3931 }
3932
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003933 void onExitAnimationDone() {
3934 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
3935 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
Jorim Jaggia5e10572017-11-15 14:36:26 +01003936 + " selfAnimating=" + isSelfAnimating());
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003937
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003938 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003939 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +01003940 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003941 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003942 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003943 }
3944 }
3945
3946 if (mWinAnimator.mEnteringAnimation) {
3947 mWinAnimator.mEnteringAnimation = false;
3948 mService.requestTraversal();
3949 // System windows don't have an activity and an app token as a result, but need a way
3950 // to be informed about their entrance animation end.
3951 if (mAppToken == null) {
3952 try {
3953 mClient.dispatchWindowShown();
3954 } catch (RemoteException e) {
3955 }
3956 }
3957 }
3958
Jorim Jaggia5e10572017-11-15 14:36:26 +01003959 if (isSelfAnimating()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003960 return;
3961 }
3962
Jorim Jaggia5e10572017-11-15 14:36:26 +01003963 //TODO (multidisplay): Accessibility is supported only for the default display.
3964 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
3965 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
3966 }
3967
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01003968 if (!isSelfOrAncestorWindowAnimatingExit()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003969 return;
3970 }
3971
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07003972 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003973 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
3974
3975 mDestroying = true;
3976
3977 final boolean hasSurface = mWinAnimator.hasSurface();
Jorim Jaggi50575902018-04-10 17:49:30 +02003978
3979 // Use pendingTransaction here so hide is done the same transaction as the other
3980 // animations when exiting
3981 mWinAnimator.hide(getPendingTransaction(), "onExitAnimationDone");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003982
3983 // If we have an app token, we ask it to destroy the surface for us, so that it can take
3984 // care to ensure the activity has actually stopped and the surface is not still in use.
3985 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
3986 // transaction.
3987 if (mAppToken != null) {
3988 mAppToken.destroySurfaces();
3989 } else {
3990 if (hasSurface) {
3991 mService.mDestroySurface.add(this);
3992 }
3993 if (mRemoveOnExit) {
3994 mService.mPendingRemove.add(this);
3995 mRemoveOnExit = false;
3996 }
3997 }
3998 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07003999 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004000 }
Dan Willemsen117197f2016-07-30 13:02:59 -07004001
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004002 boolean clearAnimatingFlags() {
4003 boolean didSomething = false;
4004 // We don't want to clear it out for windows that get replaced, because the
4005 // animation depends on the flag to remove the replaced window.
4006 //
4007 // We also don't clear the mAnimatingExit flag for windows which have the
4008 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4009 // by the client. We should let animation proceed and not clear this flag or
4010 // they won't eventually be removed by WindowStateAnimator#finishExit.
4011 if (!mWillReplaceWindow && !mRemoveOnExit) {
4012 // Clear mAnimating flag together with mAnimatingExit. When animation
4013 // changes from exiting to entering, we need to clear this flag until the
4014 // new animation gets applied, so that isAnimationStarting() becomes true
4015 // until then.
4016 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4017 // placement for this window during this period, one or more frame will
4018 // show up with wrong position or scale.
4019 if (mAnimatingExit) {
4020 mAnimatingExit = false;
4021 didSomething = true;
4022 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004023 if (mDestroying) {
4024 mDestroying = false;
4025 mService.mDestroySurface.remove(this);
4026 didSomething = true;
4027 }
4028 }
4029
4030 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004031 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004032 }
4033
4034 return didSomething;
4035 }
4036
Winson4b4ba902016-07-27 19:45:52 -07004037 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004038 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004039 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004040
4041 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004042 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004043 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004044 c.hideWallpaperWindow(wasDeferred, reason);
4045 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004046 if (!mWinAnimator.mLastHidden || wasDeferred) {
4047 mWinAnimator.hide(reason);
Tiger Huang50d45462018-05-25 22:57:52 +08004048 getDisplayContent().mWallpaperController.mDeferredHideWallpaper = null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004049 dispatchWallpaperVisibility(false);
4050 final DisplayContent displayContent = getDisplayContent();
4051 if (displayContent != null) {
4052 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
Tiger Huang50d45462018-05-25 22:57:52 +08004053 if (DEBUG_LAYOUT_REPEATS) {
4054 mService.mWindowPlacerLocked.debugLayoutRepeats("hideWallpaperWindow " + this,
4055 displayContent.pendingLayoutChanges);
4056 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004057 }
4058 }
4059 }
4060
4061 /**
4062 * Check wallpaper window for visibility change and notify window if so.
4063 * @param visible Current visibility.
4064 */
4065 void dispatchWallpaperVisibility(final boolean visible) {
4066 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07004067 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004068
4069 // Only send notification if the visibility actually changed and we are not trying to hide
4070 // the wallpaper when we are deferring hiding of the wallpaper.
4071 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4072 mWallpaperVisible = visible;
4073 try {
4074 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4075 "Updating vis of wallpaper " + this
4076 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4077 mClient.dispatchAppVisibility(visible);
4078 } catch (RemoteException e) {
4079 }
4080 }
4081 }
4082
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004083 boolean hasVisibleNotDrawnWallpaper() {
4084 if (mWallpaperVisible && !isDrawnLw()) {
4085 return true;
4086 }
4087 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004088 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004089 if (c.hasVisibleNotDrawnWallpaper()) {
4090 return true;
4091 }
4092 }
4093 return false;
4094 }
4095
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004096 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4097 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004098 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004099 c.updateReportedVisibility(results);
4100 }
4101
4102 if (mAppFreezing || mViewVisibility != View.VISIBLE
4103 || mAttrs.type == TYPE_APPLICATION_STARTING
4104 || mDestroying) {
4105 return;
4106 }
4107 if (DEBUG_VISIBILITY) {
4108 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02004109 + ", animating=" + isAnimating());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004110 if (!isDrawnLw()) {
4111 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4112 + " pv=" + mPolicyVisibility
4113 + " mDrawState=" + mWinAnimator.mDrawState
4114 + " ph=" + isParentWindowHidden()
4115 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02004116 + " a=" + isAnimating());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004117 }
4118 }
4119
4120 results.numInteresting++;
4121 if (isDrawnLw()) {
4122 results.numDrawn++;
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02004123 if (!isAnimating()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004124 results.numVisible++;
4125 }
4126 results.nowGone = false;
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02004127 } else if (isAnimating()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004128 results.nowGone = false;
4129 }
4130 }
4131
Robert Carr683e05d2018-04-18 15:11:04 -07004132 private boolean skipDecorCrop() {
4133 // The decor frame is used to specify the region not covered by the system
4134 // decorations (nav bar, status bar). In case this is empty, for example with
4135 // FLAG_TRANSLUCENT_NAVIGATION, we don't need to do any cropping.
chaviw553b0212018-07-12 13:37:01 -07004136 if (mWindowFrames.mDecorFrame.isEmpty()) {
Robert Carr683e05d2018-04-18 15:11:04 -07004137 return true;
4138 }
4139
4140 // But if we have a frame, and are an application window, then we must be cropped.
4141 if (mAppToken != null) {
4142 return false;
4143 }
4144
4145 // For non application windows, we may be allowed to extend over the decor bars
4146 // depending on our type and permissions assosciated with our token.
4147 return mToken.canLayerAboveSystemBars();
4148 }
4149
Robert Carrfbbde852016-10-18 11:02:28 -07004150 /**
4151 * Calculate the window crop according to system decor policy. In general this is
4152 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4153 * special cases. This rectangle is in screen space.
4154 */
4155 void calculatePolicyCrop(Rect policyCrop) {
4156 final DisplayContent displayContent = getDisplayContent();
4157 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
4158
4159 if (!isDefaultDisplay()) {
4160 // On a different display there is no system decor. Crop the window
4161 // by the screen boundaries.
4162 // TODO(multi-display)
chaviw9c81e632018-07-31 11:17:52 -07004163 policyCrop.set(0, 0, mWindowFrames.mCompatFrame.width(),
4164 mWindowFrames.mCompatFrame.height());
4165 policyCrop.intersect(-mWindowFrames.mCompatFrame.left, -mWindowFrames.mCompatFrame.top,
4166 displayInfo.logicalWidth - mWindowFrames.mCompatFrame.left,
4167 displayInfo.logicalHeight - mWindowFrames.mCompatFrame.top);
Robert Carr683e05d2018-04-18 15:11:04 -07004168 } else if (skipDecorCrop()) {
Robert Carrfbbde852016-10-18 11:02:28 -07004169 // Windows without policy decor aren't cropped.
chaviw9c81e632018-07-31 11:17:52 -07004170 policyCrop.set(0, 0, mWindowFrames.mCompatFrame.width(),
4171 mWindowFrames.mCompatFrame.height());
Robert Carrfbbde852016-10-18 11:02:28 -07004172 } else {
4173 // Crop to the system decor specified by policy.
4174 calculateSystemDecorRect(policyCrop);
4175 }
4176 }
4177
4178 /**
4179 * The system decor rect is the region of the window which is not covered
4180 * by system decorations.
4181 */
4182 private void calculateSystemDecorRect(Rect systemDecorRect) {
chaviw553b0212018-07-12 13:37:01 -07004183 final Rect decorRect = mWindowFrames.mDecorFrame;
chaviw492139a2018-07-16 16:07:35 -07004184 final int width = mWindowFrames.mFrame.width();
4185 final int height = mWindowFrames.mFrame.height();
Robert Carrfbbde852016-10-18 11:02:28 -07004186
chaviw492139a2018-07-16 16:07:35 -07004187 final int left = mWindowFrames.mFrame.left;
4188 final int top = mWindowFrames.mFrame.top;
Robert Carrfbbde852016-10-18 11:02:28 -07004189
4190 // Initialize the decor rect to the entire frame.
4191 if (isDockedResizing()) {
4192 // If we are resizing with the divider, the task bounds might be smaller than the
4193 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4194 // want in this case in order to avoid holes.
4195 //
4196 // We take care to not shrink the width, for surfaces which are larger than
4197 // the display region. Of course this area will not eventually be visible
4198 // but if we truncate the width now, we will calculate incorrectly
4199 // when adjusting to the stack bounds.
4200 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4201 systemDecorRect.set(0, 0,
4202 Math.max(width, displayInfo.logicalWidth),
4203 Math.max(height, displayInfo.logicalHeight));
4204 } else {
4205 systemDecorRect.set(0, 0, width, height);
4206 }
4207
4208 // If a freeform window is animating from a position where it would be cutoff, it would be
4209 // cutoff during the animation. We don't want that, so for the duration of the animation
4210 // we ignore the decor cropping and depend on layering to position windows correctly.
chaviw95136622018-04-09 15:20:06 -07004211
4212 // We also ignore cropping when the window is currently being drag resized in split screen
4213 // to prevent issues with the crop for screenshot.
4214 final boolean cropToDecor =
4215 !(inFreeformWindowingMode() && isAnimatingLw()) && !isDockedResizing();
Robert Carrfbbde852016-10-18 11:02:28 -07004216 if (cropToDecor) {
4217 // Intersect with the decor rect, offsetted by window position.
4218 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
4219 decorRect.right - left, decorRect.bottom - top);
4220 }
4221
4222 // If size compatibility is being applied to the window, the
4223 // surface is scaled relative to the screen. Also apply this
4224 // scaling to the crop rect. We aren't using the standard rect
4225 // scale function because we want to round things to make the crop
4226 // always round to a larger rect to ensure we don't crop too
4227 // much and hide part of the window that should be seen.
4228 if (mEnforceSizeCompat && mInvGlobalScale != 1.0f) {
4229 final float scale = mInvGlobalScale;
4230 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
4231 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
4232 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
4233 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
4234 }
4235
4236 }
4237
4238 /**
4239 * Expand the given rectangle by this windows surface insets. This
4240 * takes you from the 'window size' to the 'surface size'.
4241 * The surface insets are positive in each direction, so we inset by
4242 * the inverse.
4243 */
4244 void expandForSurfaceInsets(Rect r) {
4245 r.inset(-mAttrs.surfaceInsets.left,
4246 -mAttrs.surfaceInsets.top,
4247 -mAttrs.surfaceInsets.right,
4248 -mAttrs.surfaceInsets.bottom);
4249 }
4250
Robert Carrc91d1c32017-02-15 19:37:46 -08004251 boolean surfaceInsetsChanging() {
4252 return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets);
4253 }
4254
Bryce Leef858b572017-06-29 14:03:33 -07004255 int relayoutVisibleWindow(int result, int attrChanges, int oldVisibility) {
Robert Carrecc06b32017-04-18 14:25:10 -07004256 final boolean wasVisible = isVisibleLw();
4257
4258 result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0;
Robert Carr7b3d11d2018-03-15 14:34:45 -07004259
Robert Carrc91d1c32017-02-15 19:37:46 -08004260 if (mAnimatingExit) {
4261 Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit="
4262 + mRemoveOnExit + ", mDestroying=" + mDestroying);
4263
4264 mWinAnimator.cancelExitAnimationForNextAnimationLocked();
4265 mAnimatingExit = false;
4266 }
4267 if (mDestroying) {
4268 mDestroying = false;
4269 mService.mDestroySurface.remove(this);
4270 }
4271 if (oldVisibility == View.GONE) {
4272 mWinAnimator.mEnterAnimationPending = true;
4273 }
4274
Andrii Kulian8ee72852017-03-10 10:36:45 -08004275 mLastVisibleLayoutRotation = getDisplayContent().getRotation();
Robert Carrc91d1c32017-02-15 19:37:46 -08004276
4277 mWinAnimator.mEnteringAnimation = true;
Bryce Leeae73ba42017-05-05 09:58:25 -07004278
Bryce Leef858b572017-06-29 14:03:33 -07004279 prepareWindowToDisplayDuringRelayout(wasVisible);
Bryce Leeae73ba42017-05-05 09:58:25 -07004280
Robert Carrc91d1c32017-02-15 19:37:46 -08004281 if ((attrChanges & FORMAT_CHANGED) != 0) {
4282 // If the format can't be changed in place, preserve the old surface until the app draws
4283 // on the new one. This prevents blinking when we change elevation of freeform and
4284 // pinned windows.
4285 if (!mWinAnimator.tryChangeFormatInPlaceLocked()) {
4286 mWinAnimator.preserveSurfaceLocked();
4287 result |= RELAYOUT_RES_SURFACE_CHANGED
4288 | RELAYOUT_RES_FIRST_TIME;
4289 }
4290 }
4291
4292 // When we change the Surface size, in scenarios which may require changing
4293 // the surface position in sync with the resize, we use a preserved surface
4294 // so we can freeze it while waiting for the client to report draw on the newly
Robert Carrc6d5af52018-02-26 17:46:00 -08004295 // sized surface. At the moment this logic is only in place for switching
4296 // in and out of the big surface for split screen resize.
4297 if (isDragResizeChanged()) {
Robert Carrc91d1c32017-02-15 19:37:46 -08004298 setDragResizing();
Robert Carrc91d1c32017-02-15 19:37:46 -08004299 // We can only change top level windows to the full-screen surface when
4300 // resizing (as we only have one full-screen surface). So there is no need
4301 // to preserve and destroy windows which are attached to another, they
4302 // will keep their surface and its size may change over time.
4303 if (mHasSurface && !isChildWindow()) {
4304 mWinAnimator.preserveSurfaceLocked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08004305 result |= RELAYOUT_RES_SURFACE_CHANGED |
4306 RELAYOUT_RES_FIRST_TIME;
Robert Carrc91d1c32017-02-15 19:37:46 -08004307 }
4308 }
4309 final boolean freeformResizing = isDragResizing()
4310 && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
4311 final boolean dockedResizing = isDragResizing()
4312 && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
4313 result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0;
4314 result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004315 return result;
4316 }
4317
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004318 /**
4319 * @return True if this window has been laid out at least once; false otherwise.
4320 */
4321 boolean isLaidOut() {
4322 return mLayoutSeq != -1;
4323 }
4324
4325 /**
4326 * Updates the last inset values to the current ones.
4327 */
4328 void updateLastInsetValues() {
chaviw9c81e632018-07-31 11:17:52 -07004329 mWindowFrames.updateLastInsetValues();
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004330 }
4331
Jorim Jaggia5e10572017-11-15 14:36:26 +01004332 void startAnimation(Animation anim) {
4333 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
chaviw492139a2018-07-16 16:07:35 -07004334 anim.initialize(mWindowFrames.mFrame.width(), mWindowFrames.mFrame.height(),
Jorim Jaggia5e10572017-11-15 14:36:26 +01004335 displayInfo.appWidth, displayInfo.appHeight);
4336 anim.restrictDuration(MAX_ANIMATION_DURATION);
4337 anim.scaleCurrentDuration(mService.getWindowAnimationScaleLocked());
4338 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi2e3c31d2017-11-20 19:49:00 +01004339 new WindowAnimationSpec(anim, mSurfacePosition, false /* canSkipFirstFrame */),
4340 mService.mSurfaceAnimationRunner);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004341 startAnimation(mPendingTransaction, adapter);
4342 commitPendingTransaction();
4343 }
4344
chaviw161ea3e2018-01-31 12:01:12 -08004345 private void startMoveAnimation(int left, int top) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01004346 if (DEBUG_ANIM) Slog.v(TAG, "Setting move animation on " + this);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004347 final Point oldPosition = new Point();
4348 final Point newPosition = new Point();
chaviw492139a2018-07-16 16:07:35 -07004349 transformFrameToSurfacePosition(mWindowFrames.mLastFrame.left, mWindowFrames.mLastFrame.top,
4350 oldPosition);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004351 transformFrameToSurfacePosition(left, top, newPosition);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004352 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004353 new MoveAnimationSpec(oldPosition.x, oldPosition.y, newPosition.x, newPosition.y),
Jorim Jaggia5e10572017-11-15 14:36:26 +01004354 mService.mSurfaceAnimationRunner);
chaviw161ea3e2018-01-31 12:01:12 -08004355 startAnimation(getPendingTransaction(), adapter);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004356 }
4357
4358 private void startAnimation(Transaction t, AnimationAdapter adapter) {
4359 startAnimation(t, adapter, mWinAnimator.mLastHidden);
4360 }
4361
4362 @Override
4363 protected void onAnimationFinished() {
4364 mWinAnimator.onAnimationFinished();
4365 }
4366
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004367 /**
4368 * Retrieves the current transformation matrix of the window, relative to the display.
4369 *
4370 * @param float9 A temporary array of 9 floats.
4371 * @param outMatrix Matrix to fill in the transformation.
4372 */
4373 void getTransformationMatrix(float[] float9, Matrix outMatrix) {
4374 float9[Matrix.MSCALE_X] = mWinAnimator.mDsDx;
4375 float9[Matrix.MSKEW_Y] = mWinAnimator.mDtDx;
4376 float9[Matrix.MSKEW_X] = mWinAnimator.mDtDy;
4377 float9[Matrix.MSCALE_Y] = mWinAnimator.mDsDy;
Robert Carr217e7cc2018-01-31 18:08:39 -08004378 int x = mSurfacePosition.x;
4379 int y = mSurfacePosition.y;
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004380
4381 // If changed, also adjust transformFrameToSurfacePosition
4382 final WindowContainer parent = getParent();
4383 if (isChildWindow()) {
4384 final WindowState parentWindow = getParentWindow();
chaviw492139a2018-07-16 16:07:35 -07004385 x += parentWindow.mWindowFrames.mFrame.left - parentWindow.mAttrs.surfaceInsets.left;
4386 y += parentWindow.mWindowFrames.mFrame.top - parentWindow.mAttrs.surfaceInsets.top;
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004387 } else if (parent != null) {
4388 final Rect parentBounds = parent.getBounds();
4389 x += parentBounds.left;
4390 y += parentBounds.top;
4391 }
4392 float9[Matrix.MTRANS_X] = x;
4393 float9[Matrix.MTRANS_Y] = y;
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004394 float9[Matrix.MPERSP_0] = 0;
4395 float9[Matrix.MPERSP_1] = 0;
4396 float9[Matrix.MPERSP_2] = 1;
4397 outMatrix.setValues(float9);
4398 }
4399
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004400 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4401 // access to its windows children. Need to investigate re-writing
4402 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4403 static final class UpdateReportedVisibilityResults {
4404 int numInteresting;
4405 int numVisible;
4406 int numDrawn;
4407 boolean nowGone = true;
4408
4409 void reset() {
4410 numInteresting = 0;
4411 numVisible = 0;
4412 numDrawn = 0;
4413 nowGone = true;
4414 }
4415 }
Robert Carraf422a82017-04-10 18:34:33 -07004416
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004417 private static final class WindowId extends IWindowId.Stub {
4418 private final WeakReference<WindowState> mOuter;
4419
4420 private WindowId(WindowState outer) {
4421
4422 // Use a weak reference for the outer class. This is important to prevent the following
4423 // leak: Since we send this class to the client process, binder will keep it alive as
4424 // long as the client keeps it alive. Now, if the window is removed, we need to clear
4425 // out our reference so even though this class is kept alive we don't leak WindowState,
4426 // which can keep a whole lot of classes alive.
4427 mOuter = new WeakReference<>(outer);
4428 }
4429
4430 @Override
4431 public void registerFocusObserver(IWindowFocusObserver observer) {
4432 final WindowState outer = mOuter.get();
4433 if (outer != null) {
4434 outer.registerFocusObserver(observer);
4435 }
4436 }
4437 @Override
4438 public void unregisterFocusObserver(IWindowFocusObserver observer) {
4439 final WindowState outer = mOuter.get();
4440 if (outer != null) {
4441 outer.unregisterFocusObserver(observer);
4442 }
4443 }
4444 @Override
4445 public boolean isFocused() {
4446 final WindowState outer = mOuter.get();
Tiger Huang1e5b10a2018-07-30 20:19:51 +08004447 if (outer != null) {
Wale Ogunwaledb485de2018-10-29 09:47:07 -07004448 synchronized (outer.mService.mGlobalLock) {
Tiger Huang1e5b10a2018-07-30 20:19:51 +08004449 return outer.isFocused();
4450 }
4451 }
4452 return false;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004453 }
4454 }
4455
Robert Carrb1579c82017-09-05 14:54:47 -07004456
4457 @Override
4458 boolean shouldMagnify() {
4459 if (mAttrs.type == TYPE_INPUT_METHOD ||
Robert Carree4d4b92017-11-22 12:21:46 -08004460 mAttrs.type == TYPE_INPUT_METHOD_DIALOG ||
4461 mAttrs.type == TYPE_MAGNIFICATION_OVERLAY ||
4462 mAttrs.type == TYPE_NAVIGATION_BAR ||
4463 // It's tempting to wonder: Have we forgotten the rounded corners overlay?
4464 // worry not: it's a fake TYPE_NAVIGATION_BAR_PANEL
Eugene Susla9552b262018-03-13 12:24:50 -07004465 mAttrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Robert Carrb1579c82017-09-05 14:54:47 -07004466 return false;
4467 }
4468 return true;
4469 }
4470
4471 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004472 SurfaceSession getSession() {
4473 if (mSession.mSurfaceSession != null) {
4474 return mSession.mSurfaceSession;
4475 } else {
4476 return getParent().getSession();
4477 }
4478 }
4479
4480 @Override
4481 boolean needsZBoost() {
lumarkff0ab692018-11-05 20:32:30 +08004482 final WindowState inputMethodTarget = getDisplayContent().mInputMethodTarget;
4483 if (mIsImWindow && inputMethodTarget != null) {
4484 final AppWindowToken appToken = inputMethodTarget.mAppToken;
Jorim Jaggib0fc8172017-11-23 17:04:08 +00004485 if (appToken != null) {
4486 return appToken.needsZBoost();
4487 }
4488 }
4489 return mWillReplaceWindow;
Robert Carrb1579c82017-09-05 14:54:47 -07004490 }
4491
Robert Carrf07ef9e2017-11-21 12:12:49 -08004492 private void applyDims(Dimmer dimmer) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07004493 if (!mAnimatingExit && mAppDied) {
4494 mIsDimming = true;
chaviw2fb06bc2018-01-19 17:09:15 -08004495 dimmer.dimAbove(getPendingTransaction(), this, DEFAULT_DIM_AMOUNT_DEAD_WINDOW);
chaviwebcbc342018-02-07 13:19:00 -08004496 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0 && isVisibleNow() && !mHidden) {
chaviw14076152018-02-02 14:51:20 -08004497 // Only show a dim behind when the following is satisfied:
4498 // 1. The window has the flag FLAG_DIM_BEHIND
4499 // 2. The WindowToken is not hidden so dims aren't shown when the window is exiting.
4500 // 3. The WS is considered visible according to the isVisible() method
chaviwebcbc342018-02-07 13:19:00 -08004501 // 4. The WS is not hidden.
Robert Carrf59b8dd2017-10-02 18:58:36 -07004502 mIsDimming = true;
chaviw2fb06bc2018-01-19 17:09:15 -08004503 dimmer.dimBelow(getPendingTransaction(), this, mAttrs.dimAmount);
Robert Carrf59b8dd2017-10-02 18:58:36 -07004504 }
Robert Carrf07ef9e2017-11-21 12:12:49 -08004505 }
4506
4507 @Override
4508 void prepareSurfaces() {
4509 final Dimmer dimmer = getDimmer();
4510 mIsDimming = false;
4511 if (dimmer != null) {
4512 applyDims(dimmer);
4513 }
chaviw2f0567b2018-01-29 16:22:02 -08004514 updateSurfacePosition();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004515
Robert Carrb1579c82017-09-05 14:54:47 -07004516 mWinAnimator.prepareSurfaceLocked(true);
4517 super.prepareSurfaces();
4518 }
4519
4520 @Override
Jorim Jaggia5e10572017-11-15 14:36:26 +01004521 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
4522 super.onAnimationLeashCreated(t, leash);
4523
4524 // Leash is now responsible for position, so set our position to 0.
4525 t.setPosition(mSurfaceControl, 0, 0);
chaviw3e751af2018-01-11 11:22:39 -08004526 mLastSurfacePosition.set(0, 0);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004527 }
4528
4529 @Override
4530 public void onAnimationLeashDestroyed(Transaction t) {
4531 super.onAnimationLeashDestroyed(t);
4532 updateSurfacePosition(t);
4533 }
4534
chaviwe07246a2017-12-12 16:18:29 -08004535 @Override
chaviw2f0567b2018-01-29 16:22:02 -08004536 void updateSurfacePosition() {
4537 updateSurfacePosition(getPendingTransaction());
4538 }
4539
Vishnu Naird8c664b2018-09-24 12:52:35 -07004540 @VisibleForTesting
4541 void updateSurfacePosition(Transaction t) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01004542 if (mSurfaceControl == null) {
4543 return;
4544 }
4545
chaviw492139a2018-07-16 16:07:35 -07004546 transformFrameToSurfacePosition(mWindowFrames.mFrame.left, mWindowFrames.mFrame.top,
4547 mSurfacePosition);
Robert Carrc6d5af52018-02-26 17:46:00 -08004548
Vishnu Nair83537a72018-07-19 21:27:48 -07004549 // Freeze position while we're unrotated, so the surface remains at the position it was
4550 // prior to the rotation.
Vishnu Nairddd80742018-08-21 14:12:46 -07004551 if (!mSurfaceAnimator.hasLeash() && mPendingSeamlessRotate == null
4552 && !mLastSurfacePosition.equals(mSurfacePosition)) {
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004553 t.setPosition(mSurfaceControl, mSurfacePosition.x, mSurfacePosition.y);
chaviw3e751af2018-01-11 11:22:39 -08004554 mLastSurfacePosition.set(mSurfacePosition.x, mSurfacePosition.y);
Robert Carrc6d5af52018-02-26 17:46:00 -08004555 if (surfaceInsetsChanging() && mWinAnimator.hasSurface()) {
4556 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
4557 t.deferTransactionUntil(mSurfaceControl,
4558 mWinAnimator.mSurfaceController.mSurfaceControl.getHandle(),
chaviwbe43ac82018-04-04 15:14:49 -07004559 getFrameNumber());
Robert Carrc6d5af52018-02-26 17:46:00 -08004560 }
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004561 }
4562 }
4563
4564 private void transformFrameToSurfacePosition(int left, int top, Point outPoint) {
4565 outPoint.set(left, top);
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004566
4567 // If changed, also adjust getTransformationMatrix
chaviwe07246a2017-12-12 16:18:29 -08004568 final WindowContainer parentWindowContainer = getParent();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004569 if (isChildWindow()) {
4570 // TODO: This probably falls apart at some point and we should
4571 // actually compute relative coordinates.
Jorim Jaggi50d3f8f2017-12-27 17:41:25 +01004572
4573 // Since the parent was outset by its surface insets, we need to undo the outsetting
4574 // with insetting by the same amount.
Jorim Jaggia5e10572017-11-15 14:36:26 +01004575 final WindowState parent = getParentWindow();
chaviw492139a2018-07-16 16:07:35 -07004576 outPoint.offset(-parent.mWindowFrames.mFrame.left + parent.mAttrs.surfaceInsets.left,
4577 -parent.mWindowFrames.mFrame.top + parent.mAttrs.surfaceInsets.top);
chaviwe07246a2017-12-12 16:18:29 -08004578 } else if (parentWindowContainer != null) {
4579 final Rect parentBounds = parentWindowContainer.getBounds();
4580 outPoint.offset(-parentBounds.left, -parentBounds.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004581 }
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004582
Robert Carr32bcb102018-01-29 15:03:23 -08004583 TaskStack stack = getStack();
4584
4585 // If we have stack outsets, that means the top-left
4586 // will be outset, and we need to inset ourselves
4587 // to account for it. If we actually have shadows we will
4588 // then un-inset ourselves by the surfaceInsets.
4589 if (stack != null) {
4590 final int outset = stack.getStackOutset();
4591 outPoint.offset(outset, outset);
4592 }
4593
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004594 // Expand for surface insets. See WindowState.expandForSurfaceInsets.
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004595 outPoint.offset(-mAttrs.surfaceInsets.left, -mAttrs.surfaceInsets.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004596 }
4597
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004598 boolean needsRelativeLayeringToIme() {
4599 // We only use the relative layering mode in split screen, as part of elevating the IME
4600 // and windows above it's target above the docked divider.
4601 if (!inSplitScreenWindowingMode()) {
4602 return false;
4603 }
4604
4605 if (isChildWindow()) {
4606 // If we are a child of the input method target we need this promotion.
4607 if (getParentWindow().isInputMethodTarget()) {
4608 return true;
4609 }
4610 } else if (mAppToken != null) {
4611 // Likewise if we share a token with the Input method target and are ordered
4612 // above it but not necessarily a child (e.g. a Dialog) then we also need
4613 // this promotion.
lumarkff0ab692018-11-05 20:32:30 +08004614 final WindowState imeTarget = getDisplayContent().mInputMethodTarget;
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004615 boolean inTokenWithAndAboveImeTarget = imeTarget != null && imeTarget != this
4616 && imeTarget.mToken == mToken && imeTarget.compareTo(this) <= 0;
4617 return inTokenWithAndAboveImeTarget;
4618 }
4619 return false;
4620 }
4621
Jorim Jaggia5e10572017-11-15 14:36:26 +01004622 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004623 void assignLayer(Transaction t, int layer) {
4624 // See comment in assignRelativeLayerForImeTargetChild
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004625 if (needsRelativeLayeringToIme()) {
4626 getDisplayContent().assignRelativeLayerForImeTargetChild(t, this);
Robert Carrb1579c82017-09-05 14:54:47 -07004627 return;
4628 }
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004629 super.assignLayer(t, layer);
Robert Carrb1579c82017-09-05 14:54:47 -07004630 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07004631
4632 @Override
4633 public boolean isDimming() {
4634 return mIsDimming;
4635 }
Robert Carr0eff1872017-12-01 14:27:04 -08004636
4637 // TODO(b/70040778): We should aim to eliminate the last user of TYPE_APPLICATION_MEDIA
4638 // then we can drop all negative layering on the windowing side and simply inherit
4639 // the default implementation here.
4640 public void assignChildLayers(Transaction t) {
4641 int layer = 1;
4642 for (int i = 0; i < mChildren.size(); i++) {
4643 final WindowState w = mChildren.get(i);
4644
4645 // APPLICATION_MEDIA_OVERLAY needs to go above APPLICATION_MEDIA
4646 // while they both need to go below the main window. However the
4647 // relative layering of multiple APPLICATION_MEDIA/OVERLAY has never
4648 // been defined and so we can use static layers and leave it that way.
4649 if (w.mAttrs.type == TYPE_APPLICATION_MEDIA) {
4650 w.assignLayer(t, -2);
4651 } else if (w.mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) {
4652 w.assignLayer(t, -1);
4653 } else {
4654 w.assignLayer(t, layer);
4655 }
4656 w.assignChildLayers(t);
4657 layer++;
4658 }
4659 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01004660
Andrii Kulian4b6599e2018-01-15 17:24:08 -08004661 /**
4662 * Update a tap exclude region with a rectangular area identified by provided id. The requested
4663 * area will be clipped to the window bounds.
4664 */
4665 void updateTapExcludeRegion(int regionId, int left, int top, int width, int height) {
4666 final DisplayContent currentDisplay = getDisplayContent();
4667 if (currentDisplay == null) {
4668 throw new IllegalStateException("Trying to update window not attached to any display.");
4669 }
4670
4671 if (mTapExcludeRegionHolder == null) {
4672 mTapExcludeRegionHolder = new TapExcludeRegionHolder();
4673
4674 // Make sure that this window is registered as one that provides a tap exclude region
4675 // for its containing display.
4676 currentDisplay.mTapExcludeProvidingWindows.add(this);
4677 }
4678
4679 mTapExcludeRegionHolder.updateRegion(regionId, left, top, width, height);
4680 // Trigger touch exclude region update on current display.
Tiger Huang1e5b10a2018-07-30 20:19:51 +08004681 currentDisplay.updateTouchExcludeRegion();
Andrii Kulian4b6599e2018-01-15 17:24:08 -08004682 }
4683
4684 /** Union the region with current tap exclude region that this window provides. */
4685 void amendTapExcludeRegion(Region region) {
4686 mTapExcludeRegionHolder.amendRegion(region, getBounds());
4687 }
4688
Robert Carr825581a2018-03-30 14:00:53 -07004689 @Override
4690 public boolean isInputMethodTarget() {
lumarkff0ab692018-11-05 20:32:30 +08004691 return getDisplayContent().mInputMethodTarget == this;
Robert Carr825581a2018-03-30 14:00:53 -07004692 }
4693
chaviwbe43ac82018-04-04 15:14:49 -07004694 long getFrameNumber() {
4695 return mFrameNumber;
4696 }
4697
4698 void setFrameNumber(long frameNumber) {
4699 mFrameNumber = frameNumber;
4700 }
4701
chaviw553b0212018-07-12 13:37:01 -07004702 public void getMaxVisibleBounds(Rect out) {
4703 if (out.isEmpty()) {
4704 out.set(mWindowFrames.mVisibleFrame);
4705 return;
4706 }
4707
4708 if (mWindowFrames.mVisibleFrame.left < out.left) {
4709 out.left = mWindowFrames.mVisibleFrame.left;
4710 }
4711 if (mWindowFrames.mVisibleFrame.top < out.top) {
4712 out.top = mWindowFrames.mVisibleFrame.top;
4713 }
4714 if (mWindowFrames.mVisibleFrame.right > out.right) {
4715 out.right = mWindowFrames.mVisibleFrame.right;
4716 }
4717 if (mWindowFrames.mVisibleFrame.bottom > out.bottom) {
4718 out.bottom = mWindowFrames.mVisibleFrame.bottom;
4719 }
4720 }
4721
chaviw9c81e632018-07-31 11:17:52 -07004722 /**
4723 * Copy the inset values over so they can be sent back to the client when a relayout occurs.
4724 */
4725 void getInsetsForRelayout(Rect outOverscanInsets, Rect outContentInsets, Rect outVisibleInsets,
4726 Rect outStableInsets, Rect outOutsets) {
4727 outOverscanInsets.set(mWindowFrames.mOverscanInsets);
4728 outContentInsets.set(mWindowFrames.mContentInsets);
4729 outVisibleInsets.set(mWindowFrames.mVisibleInsets);
4730 outStableInsets.set(mWindowFrames.mStableInsets);
4731 outOutsets.set(mWindowFrames.mOutsets);
4732
4733 mLastRelayoutContentInsets.set(mWindowFrames.mContentInsets);
4734 }
4735
4736 void getContentInsets(Rect outContentInsets) {
4737 outContentInsets.set(mWindowFrames.mContentInsets);
4738 }
4739
4740 Rect getContentInsets() {
4741 return mWindowFrames.mContentInsets;
4742 }
4743
4744 void getStableInsets(Rect outStableInsets) {
4745 outStableInsets.set(mWindowFrames.mStableInsets);
4746 }
4747
4748 Rect getStableInsets() {
4749 return mWindowFrames.mStableInsets;
4750 }
4751
4752 void resetLastContentInsets() {
4753 mWindowFrames.resetLastContentInsets();
4754 }
4755
4756 Rect getVisibleInsets() {
4757 return mWindowFrames.mVisibleInsets;
4758 }
4759
chaviw1454b392018-08-06 09:54:04 -07004760 @Override
4761 public WindowFrames getWindowFrames() {
4762 return mWindowFrames;
4763 }
4764
4765 void resetContentChanged() {
4766 mWindowFrames.setContentChanged(false);
4767 }
4768
Jorim Jaggia5e10572017-11-15 14:36:26 +01004769 private final class MoveAnimationSpec implements AnimationSpec {
4770
4771 private final long mDuration;
4772 private Interpolator mInterpolator;
4773 private Point mFrom = new Point();
4774 private Point mTo = new Point();
4775
4776 private MoveAnimationSpec(int fromX, int fromY, int toX, int toY) {
4777 final Animation anim = AnimationUtils.loadAnimation(mContext,
4778 com.android.internal.R.anim.window_move_from_decor);
Jorim Jaggi08f75cf2018-01-08 14:38:53 +01004779 mDuration = (long)
4780 (anim.computeDurationHint() * mService.getWindowAnimationScaleLocked());
Jorim Jaggia5e10572017-11-15 14:36:26 +01004781 mInterpolator = anim.getInterpolator();
4782 mFrom.set(fromX, fromY);
4783 mTo.set(toX, toY);
4784 }
4785
4786 @Override
4787 public long getDuration() {
4788 return mDuration;
4789 }
4790
4791 @Override
4792 public void apply(Transaction t, SurfaceControl leash, long currentPlayTime) {
4793 final float fraction = (float) currentPlayTime / getDuration();
4794 final float v = mInterpolator.getInterpolation(fraction);
4795 t.setPosition(leash, mFrom.x + (mTo.x - mFrom.x) * v,
4796 mFrom.y + (mTo.y - mFrom.y) * v);
4797 }
Jorim Jaggif75d1612018-02-27 15:05:21 +01004798
4799 @Override
4800 public void dump(PrintWriter pw, String prefix) {
chaviwc65fa582018-08-09 15:33:13 -07004801 pw.println(prefix + "from=" + mFrom
4802 + " to=" + mTo
4803 + " duration=" + mDuration);
Jorim Jaggif75d1612018-02-27 15:05:21 +01004804 }
4805
4806 @Override
4807 public void writeToProtoInner(ProtoOutputStream proto) {
4808 final long token = proto.start(MOVE);
4809 mFrom.writeToProto(proto, FROM);
4810 mTo.writeToProto(proto, TO);
Kweku Adams21b8d262018-03-30 12:19:58 -07004811 proto.write(DURATION_MS, mDuration);
Jorim Jaggif75d1612018-02-27 15:05:21 +01004812 proto.end(token);
4813 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01004814 }
satokcef37fb2011-10-24 21:49:38 +09004815}