blob: bee70a0119459f62e45d309ecf0751ed06b706cd [file] [log] [blame]
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wm;
18
Jorim Jaggi02886a82016-12-06 09:10:06 -080019import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
Svet Ganovf7b47252018-02-26 11:11:27 -080020import static android.app.AppOpsManager.MODE_ALLOWED;
21import static android.app.AppOpsManager.MODE_DEFAULT;
22import static android.app.AppOpsManager.OP_NONE;
chaviw40234662018-02-07 09:37:16 -080023import static android.os.PowerManager.DRAW_WAKE_LOCK;
Jorim Jaggi02886a82016-12-06 09:10:06 -080024import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
25import static android.view.Display.DEFAULT_DISPLAY;
Jorim Jaggia5e10572017-11-15 14:36:26 +010026import static android.view.SurfaceControl.Transaction;
Jorim Jaggi02886a82016-12-06 09:10:06 -080027import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
28import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
29import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
30import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
31import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
32import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW;
33import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
34import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
35import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
36import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
37import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
38import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
39import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
40import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080041import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
42import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
43import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Robert Carrc91d1c32017-02-15 19:37:46 -080044import static android.view.WindowManager.LayoutParams.FORMAT_CHANGED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080045import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
Adrian Roosfa02da62018-01-15 16:01:18 +010046import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Jorim Jaggi02886a82016-12-06 09:10:06 -080047import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
48import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070049import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Jorim Jaggi02886a82016-12-06 09:10:06 -080050import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
51import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
52import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
53import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
54import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
55import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Robert Carr0eff1872017-12-01 14:27:04 -080056import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;
Vishnu Nair1d0fa072018-01-04 07:53:00 -080057import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080058import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
59import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
60import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
61import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
62import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
63import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Robert Carrb1579c82017-09-05 14:54:47 -070064import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY;
65import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
Robert Carree4d4b92017-11-22 12:21:46 -080066import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070067import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Jorim Jaggi02886a82016-12-06 09:10:06 -080068import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070069import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType;
Robert Carrc91d1c32017-02-15 19:37:46 -080070import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED;
71import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM;
72import static android.view.WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME;
73import static android.view.WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED;
Adrian Roose99bc052017-11-20 17:55:31 +010074import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
75import static com.android.server.policy.WindowManagerPolicy.TRANSIT_ENTER;
76import static com.android.server.policy.WindowManagerPolicy.TRANSIT_EXIT;
77import static com.android.server.policy.WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
Jorim Jaggi02886a82016-12-06 09:10:06 -080078import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
79import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
80import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
81import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
82import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
83import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
84import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
85import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
86import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Jorim Jaggi02886a82016-12-06 09:10:06 -080087import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
88import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
89import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
90import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
91import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020092import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Jorim Jaggi02886a82016-12-06 09:10:06 -080093import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080094import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
95import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
96import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
97import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
Jorim Jaggia5e10572017-11-15 14:36:26 +010098import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
Jorim Jaggi02886a82016-12-06 09:10:06 -080099import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
100import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
101import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
102import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
103import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
104import static com.android.server.wm.WindowManagerService.localLOGV;
105import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING;
106import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
107import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN;
108import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700109import static com.android.server.wm.IdentifierProto.HASH_CODE;
110import static com.android.server.wm.IdentifierProto.TITLE;
111import static com.android.server.wm.IdentifierProto.USER_ID;
112import static com.android.server.wm.AnimationSpecProto.MOVE;
Kweku Adams21b8d262018-03-30 12:19:58 -0700113import static com.android.server.wm.MoveAnimationSpecProto.DURATION_MS;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700114import static com.android.server.wm.MoveAnimationSpecProto.FROM;
115import static com.android.server.wm.MoveAnimationSpecProto.TO;
116import static com.android.server.wm.WindowStateProto.ANIMATING_EXIT;
117import static com.android.server.wm.WindowStateProto.ANIMATOR;
118import static com.android.server.wm.WindowStateProto.ATTRIBUTES;
119import static com.android.server.wm.WindowStateProto.CHILD_WINDOWS;
120import static com.android.server.wm.WindowStateProto.CONTAINING_FRAME;
121import static com.android.server.wm.WindowStateProto.CONTENT_FRAME;
122import static com.android.server.wm.WindowStateProto.CONTENT_INSETS;
123import static com.android.server.wm.WindowStateProto.CUTOUT;
124import static com.android.server.wm.WindowStateProto.DECOR_FRAME;
125import static com.android.server.wm.WindowStateProto.DESTROYING;
126import static com.android.server.wm.WindowStateProto.DISPLAY_FRAME;
127import static com.android.server.wm.WindowStateProto.DISPLAY_ID;
128import static com.android.server.wm.WindowStateProto.FRAME;
129import static com.android.server.wm.WindowStateProto.GIVEN_CONTENT_INSETS;
130import static com.android.server.wm.WindowStateProto.HAS_SURFACE;
131import static com.android.server.wm.WindowStateProto.IDENTIFIER;
132import static com.android.server.wm.WindowStateProto.IS_ON_SCREEN;
133import static com.android.server.wm.WindowStateProto.IS_READY_FOR_DISPLAY;
134import static com.android.server.wm.WindowStateProto.IS_VISIBLE;
135import static com.android.server.wm.WindowStateProto.OUTSETS;
136import static com.android.server.wm.WindowStateProto.OUTSET_FRAME;
137import static com.android.server.wm.WindowStateProto.OVERSCAN_FRAME;
138import static com.android.server.wm.WindowStateProto.OVERSCAN_INSETS;
139import static com.android.server.wm.WindowStateProto.PARENT_FRAME;
140import static com.android.server.wm.WindowStateProto.REMOVED;
141import static com.android.server.wm.WindowStateProto.REMOVE_ON_EXIT;
142import static com.android.server.wm.WindowStateProto.REQUESTED_HEIGHT;
143import static com.android.server.wm.WindowStateProto.REQUESTED_WIDTH;
144import static com.android.server.wm.WindowStateProto.STABLE_INSETS;
145import static com.android.server.wm.WindowStateProto.STACK_ID;
146import static com.android.server.wm.WindowStateProto.SURFACE_INSETS;
147import static com.android.server.wm.WindowStateProto.SURFACE_POSITION;
148import static com.android.server.wm.WindowStateProto.SYSTEM_UI_VISIBILITY;
149import static com.android.server.wm.WindowStateProto.VIEW_VISIBILITY;
150import static com.android.server.wm.WindowStateProto.VISIBLE_FRAME;
151import static com.android.server.wm.WindowStateProto.VISIBLE_INSETS;
152import static com.android.server.wm.WindowStateProto.WINDOW_CONTAINER;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800153
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700154import android.annotation.CallSuper;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800155import android.app.AppOpsManager;
156import android.content.Context;
157import android.content.res.Configuration;
158import android.graphics.Matrix;
159import android.graphics.PixelFormat;
160import android.graphics.Point;
161import android.graphics.Rect;
162import android.graphics.Region;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700163import android.os.Binder;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700164import android.os.Debug;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800165import android.os.IBinder;
166import android.os.PowerManager;
167import android.os.RemoteCallbackList;
168import android.os.RemoteException;
169import android.os.SystemClock;
170import android.os.Trace;
171import android.os.UserHandle;
172import android.os.WorkSource;
chaviw40234662018-02-07 09:37:16 -0800173import android.provider.Settings;
Phil Weaverbb2f28a2017-12-22 09:44:28 -0800174import android.text.TextUtils;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800175import android.util.DisplayMetrics;
Jorim Jaggie7d2b852017-08-28 17:55:15 +0200176import android.util.MergedConfiguration;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800177import android.util.Slog;
178import android.util.TimeUtils;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700179import android.util.proto.ProtoOutputStream;
Brad Stenningaf596412018-04-02 12:03:19 -0700180import android.view.Display;
Adrian Roos5c6b6222017-11-07 17:36:10 +0100181import android.view.DisplayCutout;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800182import android.view.DisplayInfo;
183import android.view.Gravity;
184import android.view.IApplicationToken;
185import android.view.IWindow;
186import android.view.IWindowFocusObserver;
187import android.view.IWindowId;
188import android.view.InputChannel;
189import android.view.InputEvent;
190import android.view.InputEventReceiver;
Robert Carrb1579c82017-09-05 14:54:47 -0700191import android.view.SurfaceControl;
192import android.view.SurfaceSession;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800193import android.view.View;
194import android.view.ViewTreeObserver;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700195import android.view.WindowInfo;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800196import android.view.WindowManager;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100197import android.view.animation.Animation;
198import android.view.animation.AnimationUtils;
199import android.view.animation.Interpolator;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800200
Jorim Jaggi4876b4a2018-01-11 15:43:49 +0100201import com.android.internal.annotations.VisibleForTesting;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800202import com.android.internal.util.ToBooleanFunction;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800203import com.android.server.input.InputWindowHandle;
Adrian Roose99bc052017-11-20 17:55:31 +0100204import com.android.server.policy.WindowManagerPolicy;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100205import com.android.server.wm.LocalAnimationAdapter.AnimationSpec;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100206import com.android.server.wm.utils.WmDisplayCutout;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800207
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800208import java.io.PrintWriter;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200209import java.lang.ref.WeakReference;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800210import java.util.ArrayList;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700211import java.util.Comparator;
Wale Ogunwaled1880962016-11-08 10:31:59 -0800212import java.util.function.Predicate;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800213
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700214/** A window in the window manager. */
215class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800216 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800217
Skuhne81c524a2015-08-12 13:34:14 -0700218 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700219 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
220 // use hard-coded min sizes for now.
221 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
222 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700223
224 // The thickness of a window resize handle outside the window bounds on the free form workspace
225 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700226 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700227
Craig Mautnere7ae2502012-03-26 17:11:19 -0700228 final WindowManagerPolicy mPolicy;
229 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800230 final Session mSession;
231 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800232 final int mAppOp;
233 // UserId and appId of the owner. Don't display windows of non-current user.
234 final int mOwnerUid;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800235 /** The owner has {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} */
236 final boolean mOwnerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200237 final WindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800238 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700239 // The same object as mToken if this is an app window and null for non-app windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800240 AppWindowToken mAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700241
242 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
243 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800244 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
245 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700246 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800247 final int mBaseLayer;
248 final int mSubLayer;
249 final boolean mLayoutAttached;
250 final boolean mIsImWindow;
251 final boolean mIsWallpaper;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700252 private final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700253 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700254 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800255 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700256 int mSystemUiVisibility;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700257 /**
258 * The visibility of the window based on policy like {@link WindowManagerPolicy}.
259 * Normally set by calling {@link #showLw} and {@link #hideLw}.
260 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800261 boolean mPolicyVisibility = true;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700262 /**
263 * What {@link #mPolicyVisibility} should be set to after a transition animation.
264 * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and
265 * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit
266 * animation is done.
267 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800268 boolean mPolicyVisibilityAfterAnim = true;
Suprabh Shukla69c71422018-04-02 18:39:01 -0700269 // overlay window is hidden because the owning app is suspended
270 private boolean mHiddenWhileSuspended;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700271 private boolean mAppOpVisibility = true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700272 boolean mPermanentlyHidden; // the window should never be shown again
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700273 // This is a non-system overlay window that is currently force hidden.
274 private boolean mForceHideNonSystemOverlayWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800275 boolean mAppFreezing;
chaviwebcbc342018-02-07 13:19:00 -0800276 boolean mHidden = true; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800277 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700278 private boolean mDragResizing;
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200279 private boolean mDragResizingChangeReported = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700280 private int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700281
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700282 private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800283
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700284 /**
285 * The window size that was requested by the application. These are in
286 * the application's coordinate space (without compatibility scale applied).
287 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800288 int mRequestedWidth;
289 int mRequestedHeight;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700290 private int mLastRequestedWidth;
291 private int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700292
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800293 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800294 boolean mHaveFrame;
295 boolean mObscured;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800296
297 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700298
Andrii Kulian9d91ca62016-09-29 22:28:09 -0700299 /**
300 * Used to store last reported to client configuration and check if we have newer available.
301 * We'll send configuration to client only if it is different from the last applied one and
302 * client won't perform unnecessary updates.
303 */
Bryce Lee2b17afd2017-09-21 10:38:20 -0700304 private final MergedConfiguration mLastReportedConfiguration = new MergedConfiguration();
Craig Mautnera2c77052012-03-26 12:14:43 -0700305
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700306 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700307 * Insets that determine the actually visible area. These are in the application's
308 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800309 */
310 final Rect mVisibleInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700311 private final Rect mLastVisibleInsets = new Rect();
312 private boolean mVisibleInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800313
314 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700315 * Insets that are covered by system windows (such as the status bar) and
316 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700317 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800318 */
319 final Rect mContentInsets = new Rect();
320 final Rect mLastContentInsets = new Rect();
Robert Carr18f622f2017-05-08 11:20:43 -0700321
322 /**
323 * The last content insets returned to the client in relayout. We use
324 * these in the bounds animation to ensure we only observe inset changes
325 * at the same time that a client resizes it's surface so that we may use
326 * the geometryAppliesWithResize synchronization mechanism to keep
327 * the contents in place.
328 */
329 final Rect mLastRelayoutContentInsets = new Rect();
330
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700331 private boolean mContentInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800332
333 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800334 * Insets that determine the area covered by the display overscan region. These are in the
335 * application's coordinate space (without compatibility scale applied).
336 */
337 final Rect mOverscanInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700338 private final Rect mLastOverscanInsets = new Rect();
339 private boolean mOverscanInsetsChanged;
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800340
341 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700342 * Insets that determine the area covered by the stable system windows. These are in the
343 * application's coordinate space (without compatibility scale applied).
344 */
345 final Rect mStableInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700346 private final Rect mLastStableInsets = new Rect();
347 private boolean mStableInsetsChanged;
Adrian Roosfa104232014-06-20 16:10:14 -0700348
349 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700350 * Outsets determine the area outside of the surface where we want to pretend that it's possible
351 * to draw anyway.
352 */
353 final Rect mOutsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700354 private final Rect mLastOutsets = new Rect();
355 private boolean mOutsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700356
Adrian Roos5c6b6222017-11-07 17:36:10 +0100357 /** Part of the display that has been cut away. See {@link DisplayCutout}. */
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100358 WmDisplayCutout mDisplayCutout = WmDisplayCutout.NO_CUTOUT;
359 private WmDisplayCutout mLastDisplayCutout = WmDisplayCutout.NO_CUTOUT;
Adrian Roos5c6b6222017-11-07 17:36:10 +0100360 private boolean mDisplayCutoutChanged;
361
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700362 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800363 * Set to true if we are waiting for this window to receive its
364 * given internal insets before laying out other windows based on it.
365 */
366 boolean mGivenInsetsPending;
367
368 /**
369 * These are the content insets that were given during layout for
370 * this window, to be applied to windows behind it.
371 */
372 final Rect mGivenContentInsets = new Rect();
373
374 /**
375 * These are the visible insets that were given during layout for
376 * this window, to be applied to windows behind it.
377 */
378 final Rect mGivenVisibleInsets = new Rect();
379
380 /**
381 * This is the given touchable area relative to the window frame, or null if none.
382 */
383 final Region mGivenTouchableRegion = new Region();
384
385 /**
386 * Flag indicating whether the touchable region should be adjusted by
387 * the visible insets; if false the area outside the visible insets is
388 * NOT touchable, so we must use those to adjust the frame during hit
389 * tests.
390 */
391 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
392
393 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400394 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700395 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800396 float mHScale=1, mVScale=1;
397 float mLastHScale=1, mLastVScale=1;
398 final Matrix mTmpMatrix = new Matrix();
399
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700400 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800401 final Rect mFrame = new Rect();
402 final Rect mLastFrame = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700403 private boolean mFrameSizeChanged = false;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700404 // Frame that is scaled to the application's coordinate space when in
405 // screen size compatibility mode.
406 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800407
408 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700409
Adrian Roos604ef952018-05-15 20:13:13 +0200410 final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700411
Adrian Roos5ed644f2018-03-19 17:01:05 +0100412 /** Whether the parent frame would have been different if there was no display cutout. */
413 private boolean mParentFrameWasClippedByDisplayCutout;
414
Wale Ogunwale94596652015-02-06 19:27:34 -0800415 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
416 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700417 final Rect mDisplayFrame = new Rect();
418
419 // The region of the display frame that the display type supports displaying content on. This
420 // is mostly a special case for TV where some displays don’t have the entire display usable.
421 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
422 // window display contents to extend into the overscan region.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700423 private final Rect mOverscanFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700424
425 // The display frame minus the stable insets. This value is always constant regardless of if
426 // the status bar or navigation bar is visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700427 private final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800428
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700429 // The area not occupied by the status and navigation bars. So, if both status and navigation
430 // bars are visible, the decor frame is equal to the stable frame.
431 final Rect mDecorFrame = new Rect();
432
433 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
434 // minus the area occupied by the IME if the IME is present.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700435 private final Rect mContentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700436
437 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
438 // displays hint text.
439 final Rect mVisibleFrame = new Rect();
440
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700441 // Frame that includes dead area outside of the surface but where we want to pretend that it's
442 // possible to draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700443 private final Rect mOutsetFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700444
Jorim Jaggidc249c42015-12-15 14:57:31 -0800445 /**
446 * Usually empty. Set to the task's tempInsetFrame. See
447 *{@link android.app.IActivityManager#resizeDockedStack}.
448 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700449 private final Rect mInsetFrame = new Rect();
Jorim Jaggidc249c42015-12-15 14:57:31 -0800450
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800451 boolean mContentChanged;
452
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800453 // If a window showing a wallpaper: the requested offset for the
454 // wallpaper; if a wallpaper window: the currently applied offset.
455 float mWallpaperX = -1;
456 float mWallpaperY = -1;
457
458 // If a window showing a wallpaper: what fraction of the offset
459 // range corresponds to a full virtual screen.
460 float mWallpaperXStep = -1;
461 float mWallpaperYStep = -1;
462
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700463 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
464 // to its window; if a wallpaper window: not used.
465 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
466 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
467
Craig Mautner2268e7e2012-12-13 15:40:00 -0800468 /**
469 * This is set after IWindowSession.relayout() has been called at
470 * least once for the window. It allows us to detect the situation
471 * where we don't yet have a surface, but should have one soon, so
472 * we can give the window focus before waiting for the relayout.
473 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800474 boolean mRelayoutCalled;
475
Robert Carrfed10072016-05-26 11:48:49 -0700476 boolean mInRelayout;
477
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800478 /**
479 * If the application has called relayout() with changes that can
480 * impact its window's size, we need to perform a layout pass on it
481 * even if it is not currently visible for layout. This is set
482 * when in that case until the layout is done.
483 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800484 boolean mLayoutNeeded;
485
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800486 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800487 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800488
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800489 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800490 boolean mDestroying;
491
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800492 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800493 boolean mRemoveOnExit;
494
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800495 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800496 * Whether the app died while it was visible, if true we might need
497 * to continue to show it until it's restarted.
498 */
499 boolean mAppDied;
500
501 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800502 * Set when the orientation is changing and this window has not yet
503 * been updated for the new orientation.
504 */
Bryce Lee8c3cf382017-07-06 19:47:10 -0700505 private boolean mOrientationChanging;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800506
Dianne Hackborna57c6952013-03-29 14:46:40 -0700507 /**
Robert Carr9c1c3a02017-08-08 12:59:01 -0700508 * Sometimes in addition to the mOrientationChanging
509 * flag we report that the orientation is changing
510 * due to a mismatch in current and reported configuration.
511 *
512 * In the case of timeout we still need to make sure we
513 * leave the orientation changing state though, so we
514 * use this as a special time out escape hatch.
515 */
516 private boolean mOrientationChangeTimedOut;
517
518 /**
Robert Carr237028a2016-07-26 10:39:45 -0700519 * The orientation during the last visible call to relayout. If our
520 * current orientation is different, the window can't be ready
521 * to be shown.
522 */
523 int mLastVisibleLayoutRotation = -1;
524
525 /**
Andrii Kulianb2e37802017-01-11 00:36:44 -0800526 * Set when we need to report the orientation change to client to trigger a relayout.
527 */
528 boolean mReportOrientationChanged;
529
530 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700531 * How long we last kept the screen frozen.
532 */
533 int mLastFreezeDuration;
534
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800535 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800536 boolean mRemoved;
537
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800538 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800539 * It is save to remove the window and destroy the surface because the client requested removal
540 * or some other higher level component said so (e.g. activity manager).
541 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800542 */
Svetoslav Ganov200adfb2016-10-18 13:29:27 -0700543 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800544
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800545 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700546 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800547 InputChannel mInputChannel;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700548 private InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800549
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800550 // Used to improve performance of toString()
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700551 private String mStringNameCache;
552 private CharSequence mLastTitle;
553 private boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800554
Craig Mautnera2c77052012-03-26 12:14:43 -0700555 final WindowStateAnimator mWinAnimator;
556
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700557 boolean mHasSurface = false;
558
Craig Mautner88400d32012-09-30 12:35:45 -0700559 /** When true this window can be displayed on screens owther than mOwnerUid's */
560 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700561
Chong Zhang92147042016-05-09 12:47:11 -0700562 // Whether the window was visible when we set the app to invisible last time. WM uses
563 // this as a hint to restore the surface (if available) for early animation next time
564 // the app is brought visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700565 private boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800566
Robert Carra1eb4392015-12-10 12:43:51 -0800567 // This window will be replaced due to relaunch. This allows window manager
568 // to differentiate between simple removal of a window and replacement. In the latter case it
569 // will preserve the old window until the new one is drawn.
570 boolean mWillReplaceWindow = false;
571 // If true, the replaced window was already requested to be removed.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700572 private boolean mReplacingRemoveRequested = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800573 // Whether the replacement of the window should trigger app transition animation.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700574 private boolean mAnimateReplacingWindow = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800575 // If not null, the window that will be used to replace the old one. This is being set when
576 // the window is added and unset when this window reports its first draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700577 private WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700578 // For the new window in the replacement transition, if we have
579 // requested to replace without animation, then we should
580 // make sure we also don't apply an enter animation for
581 // the new window.
582 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800583 // Whether this window is being moved via the resize API
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700584 private boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800585
Jeff Brownc2932a12014-11-20 18:04:05 -0800586 /**
587 * Wake lock for drawing.
588 * Even though it's slightly more expensive to do so, we will use a separate wake lock
589 * for each app that is requesting to draw while dozing so that we can accurately track
590 * who is preventing the system from suspending.
591 * This lock is only acquired on first use.
592 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700593 private PowerManager.WakeLock mDrawLock;
Jeff Brownc2932a12014-11-20 18:04:05 -0800594
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700595 final private Rect mTmpRect = new Rect();
596
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800597 /**
598 * Whether the window was resized by us while it was gone for layout.
599 */
600 boolean mResizedWhileGone = false;
601
Robert Carr6da3cc02016-06-16 15:17:07 -0700602 /**
603 * During seamless rotation we have two phases, first the old window contents
604 * are rotated to look as if they didn't move in the new coordinate system. Then we
605 * have to freeze updates to this layer (to preserve the transformation) until
606 * the resize actually occurs. This is true from when the transformation is set
607 * and false until the transaction to resize is sent.
608 */
609 boolean mSeamlesslyRotated = false;
610
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700611 /**
Robert Carrc91d1c32017-02-15 19:37:46 -0800612 * Surface insets from the previous call to relayout(), used to track
613 * if we are changing the Surface insets.
614 */
615 final Rect mLastSurfaceInsets = new Rect();
616
617 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700618 * A flag set by the {@link WindowState} parent to indicate that the parent has examined this
619 * {@link WindowState} in its overall drawing context. This book-keeping allows the parent to
620 * make sure all children have been considered.
621 */
622 private boolean mDrawnStateEvaluated;
623
Jorim Jaggia5e10572017-11-15 14:36:26 +0100624 private final Point mSurfacePosition = new Point();
625
Bryce Leed390deb2017-06-22 13:14:28 -0700626 /**
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800627 * A region inside of this window to be excluded from touch-related focus switches.
628 */
629 private TapExcludeRegionHolder mTapExcludeRegionHolder;
630
631 /**
chaviw40234662018-02-07 09:37:16 -0800632 * Used for testing because the real PowerManager is final.
633 */
634 private PowerManagerWrapper mPowerManagerWrapper;
635
636 /**
chaviwbe43ac82018-04-04 15:14:49 -0700637 * A frame number in which changes requested in this layout will be rendered.
638 */
639 private long mFrameNumber = -1;
640
641 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700642 * 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 -0700643 * of z-order and 1 otherwise.
644 */
Griff Hazen51d00d82016-11-22 15:39:24 -0800645 private static final Comparator<WindowState> sWindowSubLayerComparator =
646 new Comparator<WindowState>() {
647 @Override
648 public int compare(WindowState w1, WindowState w2) {
649 final int layer1 = w1.mSubLayer;
650 final int layer2 = w2.mSubLayer;
651 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
652 // We insert the child window into the list ordered by
653 // the sub-layer. For same sub-layers, the negative one
654 // should go below others; the positive one should go
655 // above others.
656 return -1;
657 }
658 return 1;
659 };
660 };
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700661
Robert Carrf59b8dd2017-10-02 18:58:36 -0700662 /**
663 * Indicates whether we have requested a Dim (in the sense of {@link Dimmer}) from our host
664 * container.
665 */
666 private boolean mIsDimming = false;
667
668 private static final float DEFAULT_DIM_AMOUNT_DEAD_WINDOW = 0.5f;
669
chaviw40234662018-02-07 09:37:16 -0800670 interface PowerManagerWrapper {
671 void wakeUp(long time, String reason);
672
673 boolean isInteractive();
674
675 }
676
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800677 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
chaviw40234662018-02-07 09:37:16 -0800678 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
679 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow) {
680 this(service, s, c, token, parentWindow, appOp, seq, a, viewVisibility, ownerId,
681 ownerCanAddInternalSystemWindow, new PowerManagerWrapper() {
682 @Override
683 public void wakeUp(long time, String reason) {
684 service.mPowerManager.wakeUp(time, reason);
685 }
686
687 @Override
688 public boolean isInteractive() {
689 return service.mPowerManager.isInteractive();
690 }
691 });
692 }
693
694 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
695 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
696 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow,
697 PowerManagerWrapper powerManagerWrapper) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100698 super(service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800699 mSession = s;
700 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800701 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800702 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700703 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700704 mOwnerUid = ownerId;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800705 mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200706 mWindowId = new WindowId(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800707 mAttrs.copyFrom(a);
Robert Carrb08ed042018-03-12 15:49:08 -0700708 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800709 mViewVisibility = viewVisibility;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700710 mPolicy = mService.mPolicy;
711 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800712 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700713 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700714 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
chaviw40234662018-02-07 09:37:16 -0800715 mPowerManagerWrapper = powerManagerWrapper;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700716 if (localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700717 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700718 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800719 try {
720 c.asBinder().linkToDeath(deathRecipient, 0);
721 } catch (RemoteException e) {
722 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700723 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800724 mLayoutAttached = false;
725 mIsImWindow = false;
726 mIsWallpaper = false;
727 mIsFloatingLayer = false;
728 mBaseLayer = 0;
729 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700730 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700731 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800732 return;
733 }
734 mDeathRecipient = deathRecipient;
735
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700736 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800737 // The multiplier here is to reserve space for multiple
738 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800739 mBaseLayer = mPolicy.getWindowLayerLw(parentWindow)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700740 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800741 mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700742 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900743
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700744 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow);
745 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900746
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800747 mLayoutAttached = mAttrs.type !=
748 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700749 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
750 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
751 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800752 } else {
753 // The multiplier here is to reserve space for multiple
754 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800755 mBaseLayer = mPolicy.getWindowLayerLw(this)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700756 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800757 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700758 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800759 mLayoutAttached = false;
760 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
761 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
762 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800763 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700764 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800765
Wale Ogunwale72919d22016-12-08 18:58:50 -0800766 if (mAppToken != null && mAppToken.mShowForAllUsers) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700767 // Windows for apps that can show for all users should also show when the device is
768 // locked.
769 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
Craig Mautner19ab8282014-05-07 10:35:34 -0700770 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800771
Craig Mautner322e4032012-07-13 13:35:20 -0700772 mWinAnimator = new WindowStateAnimator(this);
773 mWinAnimator.mAlpha = a.alpha;
774
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800775 mRequestedWidth = 0;
776 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700777 mLastRequestedWidth = 0;
778 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800779 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800780 mInputWindowHandle = new InputWindowHandle(
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800781 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this, c,
782 getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800783 }
784
785 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700786 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800787 mSession.windowAddedLocked(mAttrs.packageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800788 }
789
Bryce Leed390deb2017-06-22 13:14:28 -0700790 /**
791 * Returns whether this {@link WindowState} has been considered for drawing by its parent.
792 */
Bryce Lee6311c4b2017-07-06 14:09:29 -0700793 boolean getDrawnStateEvaluated() {
Bryce Leed390deb2017-06-22 13:14:28 -0700794 return mDrawnStateEvaluated;
795 }
796
797 /**
798 * Sets whether this {@link WindowState} has been considered for drawing by its parent. Should
799 * be cleared when detached from parent.
800 */
801 void setDrawnStateEvaluated(boolean evaluated) {
802 mDrawnStateEvaluated = evaluated;
803 }
804
805 @Override
806 void onParentSet() {
807 super.onParentSet();
808 setDrawnStateEvaluated(false /*evaluated*/);
Robert Carr24be9ab2018-04-30 17:54:53 -0700809
810 getDisplayContent().reapplyMagnificationSpec();
Bryce Leed390deb2017-06-22 13:14:28 -0700811 }
812
Craig Mautnera2c77052012-03-26 12:14:43 -0700813 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800814 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800815 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800816 }
817
818 @Override
819 public String getOwningPackage() {
820 return mAttrs.packageName;
821 }
822
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800823 @Override
824 public boolean canAddInternalSystemWindow() {
825 return mOwnerCanAddInternalSystemWindow;
826 }
827
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200828 @Override
829 public boolean canAcquireSleepToken() {
830 return mSession.mCanAcquireSleepToken;
831 }
832
Jorim Jaggif5834272016-04-04 20:25:41 -0700833 /**
834 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
835 * from {@param frame}. In other words, it applies the insets that would result if
836 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700837 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
838 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700839 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700840 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
841 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
842 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
843 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
844 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700845 frame.inset(left, top, right, bottom);
846 }
847
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800848 @Override
Robert Carr43521762016-10-28 13:15:04 -0700849 public void computeFrameLw(Rect parentFrame, Rect displayFrame, Rect overscanFrame,
850 Rect contentFrame, Rect visibleFrame, Rect decorFrame, Rect stableFrame,
Adrian Roos5ed644f2018-03-19 17:01:05 +0100851 Rect outsetFrame, WmDisplayCutout displayCutout,
852 boolean parentFrameWasClippedByDisplayCutout) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800853 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700854 // This window is being replaced and either already got information that it's being
855 // removed or we are still waiting for some information. Because of this we don't
856 // want to apply any more changes to it, so it remains in this state until new window
857 // appears.
858 return;
859 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800860 mHaveFrame = true;
Adrian Roos5ed644f2018-03-19 17:01:05 +0100861 mParentFrameWasClippedByDisplayCutout = parentFrameWasClippedByDisplayCutout;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800862
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700863 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700864 final boolean inFullscreenContainer = inFullscreenContainer();
Robert Carre6275582016-02-29 15:45:45 -0800865 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700866 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800867
Chong Zhangae35fef2016-03-16 15:56:55 -0700868 // If the task has temp inset bounds set, we have to make sure all its windows uses
869 // the temp inset frame. Otherwise different display frames get applied to the main
870 // window and the child window, making them misaligned.
Adrian Roose76b2b52018-03-21 16:22:16 +0100871 // Otherwise we need to clear the inset frame, to avoid using a stale frame after leaving
872 // multi window mode.
873 if (task != null && isInMultiWindowMode()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700874 task.getTempInsetBounds(mInsetFrame);
Adrian Roose76b2b52018-03-21 16:22:16 +0100875 } else {
876 mInsetFrame.setEmpty();
Chong Zhangae35fef2016-03-16 15:56:55 -0700877 }
878
Jorim Jaggif5834272016-04-04 20:25:41 -0700879 // Denotes the actual frame used to calculate the insets and to perform the layout. When
880 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
881 // insets temporarily. By the notion of a task having a different layout frame, we can
882 // achieve that while still moving the task around.
883 final Rect layoutContainingFrame;
884 final Rect layoutDisplayFrame;
885
886 // The offset from the layout containing frame to the actual containing frame.
887 final int layoutXDiff;
888 final int layoutYDiff;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700889 if (inFullscreenContainer || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800890 // We use the parent frame as the containing frame for fullscreen and child windows
Robert Carr43521762016-10-28 13:15:04 -0700891 mContainingFrame.set(parentFrame);
892 mDisplayFrame.set(displayFrame);
893 layoutDisplayFrame = displayFrame;
894 layoutContainingFrame = parentFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700895 layoutXDiff = 0;
896 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800897 } else {
Bryce Leef3c6a472017-11-14 14:53:06 -0800898 getBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100899 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
900
901 // If the bounds are frozen, we still want to translate the window freely and only
902 // freeze the size.
903 Rect frozen = mAppToken.mFrozenBounds.peek();
904 mContainingFrame.right = mContainingFrame.left + frozen.width();
905 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
906 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800907 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700908 // IME is up and obscuring this window. Adjust the window position so it is visible.
Robert Carr825581a2018-03-30 14:00:53 -0700909 if (imeWin != null && imeWin.isVisibleNow() && isInputMethodTarget()) {
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700910 if (inFreeformWindowingMode()
Winson Chungd73e94b2017-05-31 16:25:30 -0700911 && mContainingFrame.bottom > contentFrame.bottom) {
912 // In freeform we want to move the top up directly.
913 // TODO: Investigate why this is contentFrame not parentFrame.
914 mContainingFrame.top -= mContainingFrame.bottom - contentFrame.bottom;
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700915 } else if (!inPinnedWindowingMode()
Winson Chungd73e94b2017-05-31 16:25:30 -0700916 && mContainingFrame.bottom > parentFrame.bottom) {
917 // But in docked we want to behave like fullscreen and behave as if the task
918 // were given smaller bounds for the purposes of layout. Skip adjustments for
919 // the pinned stack, they are handled separately in the PinnedStackController.
920 mContainingFrame.bottom = parentFrame.bottom;
921 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700922 }
Skuhne81c524a2015-08-12 13:34:14 -0700923
Robert Carre6275582016-02-29 15:45:45 -0800924 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700925 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
926 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800927 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700928 if (mContainingFrame.isEmpty()) {
Robert Carr43521762016-10-28 13:15:04 -0700929 mContainingFrame.set(contentFrame);
Skuhne81c524a2015-08-12 13:34:14 -0700930 }
Doris Liu06d582d2015-06-01 13:18:43 -0700931 }
Adrian Roos604ef952018-05-15 20:13:13 +0200932
933 final TaskStack stack = getStack();
934 if (inPinnedWindowingMode() && stack != null
935 && stack.lastAnimatingBoundsWasToFullscreen()) {
936 // PIP edge case: When going from pinned to fullscreen, we apply a
937 // tempInsetFrame for the full task - but we're still at the start of the animation.
938 // To prevent a jump if there's a letterbox, restrict to the parent frame.
939 mInsetFrame.intersectUnchecked(parentFrame);
940 mContainingFrame.intersectUnchecked(parentFrame);
941 }
942
Wale Ogunwale94596652015-02-06 19:27:34 -0800943 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700944 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
945 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
946 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700947 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
Robert Carr43521762016-10-28 13:15:04 -0700948 subtractInsets(mDisplayFrame, layoutContainingFrame, displayFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700949 if (!layoutInParentFrame()) {
Robert Carr43521762016-10-28 13:15:04 -0700950 subtractInsets(mContainingFrame, layoutContainingFrame, parentFrame, mTmpRect);
951 subtractInsets(mInsetFrame, layoutContainingFrame, parentFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700952 }
Robert Carr43521762016-10-28 13:15:04 -0700953 layoutDisplayFrame = displayFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700954 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700955 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800956
Craig Mautner967212c2013-04-13 21:10:58 -0700957 final int pw = mContainingFrame.width();
958 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800959
Robert Carr43521762016-10-28 13:15:04 -0700960 if (!mParentFrame.equals(parentFrame)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800961 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Robert Carr43521762016-10-28 13:15:04 -0700962 // + " to " + parentFrame);
963 mParentFrame.set(parentFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800964 mContentChanged = true;
965 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700966 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
967 mLastRequestedWidth = mRequestedWidth;
968 mLastRequestedHeight = mRequestedHeight;
969 mContentChanged = true;
970 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800971
Robert Carr43521762016-10-28 13:15:04 -0700972 mOverscanFrame.set(overscanFrame);
973 mContentFrame.set(contentFrame);
974 mVisibleFrame.set(visibleFrame);
975 mDecorFrame.set(decorFrame);
976 mStableFrame.set(stableFrame);
977 final boolean hasOutsets = outsetFrame != null;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700978 if (hasOutsets) {
Robert Carr43521762016-10-28 13:15:04 -0700979 mOutsetFrame.set(outsetFrame);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700980 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800981
Craig Mautnereda67292013-04-28 13:50:14 -0700982 final int fw = mFrame.width();
983 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800984
Jorim Jaggif5834272016-04-04 20:25:41 -0700985 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
986
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700987 // Calculate the outsets before the content frame gets shrinked to the window frame.
988 if (hasOutsets) {
989 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
990 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
991 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
992 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
993 } else {
994 mOutsets.set(0, 0, 0, 0);
995 }
996
Craig Mautnera248eee2013-05-07 11:41:27 -0700997 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800998 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -0800999 if (windowsAreFloating && !mFrame.isEmpty()) {
Robert Carre65a1c42017-02-28 16:52:59 -08001000 // For pinned workspace the frame isn't limited in any particular
1001 // way since SystemUI controls the bounds. For freeform however
1002 // we want to keep things inside the content frame.
Wale Ogunwale44f036f2017-09-29 05:09:09 -07001003 final Rect limitFrame = task.inPinnedWindowingMode() ? mFrame : mContentFrame;
Skuhne81c524a2015-08-12 13:34:14 -07001004 // Keep the frame out of the blocked system area, limit it in size to the content area
1005 // and make sure that there is always a minimum visible so that the user can drag it
1006 // into a usable area..
Robert Carre65a1c42017-02-28 16:52:59 -08001007 final int height = Math.min(mFrame.height(), limitFrame.height());
1008 final int width = Math.min(limitFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -07001009 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +09001010 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
1011 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
1012 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
1013 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Robert Carre65a1c42017-02-28 16:52:59 -08001014 final int top = Math.max(limitFrame.top,
1015 Math.min(mFrame.top, limitFrame.bottom - minVisibleHeight));
1016 final int left = Math.max(limitFrame.left + minVisibleWidth - width,
1017 Math.min(mFrame.left, limitFrame.right - minVisibleWidth));
Skuhne81c524a2015-08-12 13:34:14 -07001018 mFrame.set(left, top, left + width, top + height);
1019 mContentFrame.set(mFrame);
1020 mVisibleFrame.set(mContentFrame);
1021 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -07001022 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001023 dc.getDockedDividerController().positionDockedStackedDivider(mFrame);
Jorim Jaggi192086e2016-03-11 17:17:03 +01001024 mContentFrame.set(mFrame);
1025 if (!mFrame.equals(mLastFrame)) {
1026 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -08001027 }
Skuhne81c524a2015-08-12 13:34:14 -07001028 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -07001029 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
1030 Math.max(mContentFrame.top, mFrame.top),
1031 Math.min(mContentFrame.right, mFrame.right),
1032 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001033
Jorim Jaggi656f6502016-04-11 21:08:17 -07001034 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
1035 Math.max(mVisibleFrame.top, mFrame.top),
1036 Math.min(mVisibleFrame.right, mFrame.right),
1037 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001038
Jorim Jaggi656f6502016-04-11 21:08:17 -07001039 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
1040 Math.max(mStableFrame.top, mFrame.top),
1041 Math.min(mStableFrame.right, mFrame.right),
1042 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -07001043 }
Adrian Roosfa104232014-06-20 16:10:14 -07001044
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07001045 if (inFullscreenContainer && !windowsAreFloating) {
Jorim Jaggi899327f2016-02-25 20:44:18 -05001046 // Windows that are not fullscreen can be positioned outside of the display frame,
1047 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -07001048 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
1049 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
1050 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
1051 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -08001052 }
Craig Mautnereda67292013-04-28 13:50:14 -07001053
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001054 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001055 // For the docked divider, we calculate the stable insets like a full-screen window
1056 // so it can use it to calculate the snap positions.
Adrian Roos7377f582018-03-20 16:56:22 +01001057 final WmDisplayCutout c = displayCutout.calculateRelativeTo(mDisplayFrame);
1058 mTmpRect.set(mDisplayFrame);
1059 mTmpRect.inset(c.getDisplayCutout().getSafeInsets());
1060 mTmpRect.intersectUnchecked(mStableFrame);
1061
1062 mStableInsets.set(Math.max(mTmpRect.left - mDisplayFrame.left, 0),
1063 Math.max(mTmpRect.top - mDisplayFrame.top, 0),
1064 Math.max(mDisplayFrame.right - mTmpRect.right, 0),
1065 Math.max(mDisplayFrame.bottom - mTmpRect.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -08001066
1067 // The divider doesn't care about insets in any case, so set it to empty so we don't
1068 // trigger a relayout when moving it.
1069 mContentInsets.setEmpty();
1070 mVisibleInsets.setEmpty();
Adrian Roos7377f582018-03-20 16:56:22 +01001071 displayCutout = WmDisplayCutout.NO_CUTOUT;
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001072 } else {
Bryce Leef3c6a472017-11-14 14:53:06 -08001073 getDisplayContent().getBounds(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -07001074 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
1075 // non-fullscreen mode.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07001076 boolean overrideRightInset = !windowsAreFloating && !inFullscreenContainer
1077 && mFrame.right > mTmpRect.right;
1078 boolean overrideBottomInset = !windowsAreFloating && !inFullscreenContainer
1079 && mFrame.bottom > mTmpRect.bottom;
Jorim Jaggi656f6502016-04-11 21:08:17 -07001080 mContentInsets.set(mContentFrame.left - mFrame.left,
1081 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -07001082 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -07001083 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -07001084 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -07001085 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -08001086
Jorim Jaggi656f6502016-04-11 21:08:17 -07001087 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
1088 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -07001089 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -07001090 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -07001091 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -07001092 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -08001093
Jorim Jaggi656f6502016-04-11 21:08:17 -07001094 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
1095 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -07001096 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -07001097 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -07001098 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -07001099 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001100 }
Adrian Roosfa104232014-06-20 16:10:14 -07001101
Jorim Jaggibae2b152018-04-18 17:27:27 +02001102 mDisplayCutout = displayCutout.calculateRelativeTo(mFrame);
1103
Jorim Jaggi656f6502016-04-11 21:08:17 -07001104 // Offset the actual frame by the amount layout frame is off.
1105 mFrame.offset(-layoutXDiff, -layoutYDiff);
1106 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -07001107 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
1108 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
1109 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
1110
Craig Mautnereda67292013-04-28 13:50:14 -07001111 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001112 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001113 // If there is a size compatibility scale being applied to the
1114 // window, we need to apply this to its insets so that they are
1115 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -07001116 mOverscanInsets.scale(mInvGlobalScale);
1117 mContentInsets.scale(mInvGlobalScale);
1118 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -07001119 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001120 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001121
1122 // Also the scaled frame that we report to the app needs to be
1123 // adjusted to be in its coordinate space.
1124 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001125 }
1126
Craig Mautnereda67292013-04-28 13:50:14 -07001127 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001128 final DisplayContent displayContent = getDisplayContent();
1129 if (displayContent != null) {
1130 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwale0303c572016-10-20 10:16:29 -07001131 getDisplayContent().mWallpaperController.updateWallpaperOffset(
Wale Ogunwalee8069dc2015-08-18 09:52:01 -07001132 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001133 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001134 }
1135
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001136 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001137 "Resolving (mRequestedWidth="
1138 + mRequestedWidth + ", mRequestedheight="
1139 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
1140 + "): frame=" + mFrame.toShortString()
1141 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07001142 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -07001143 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001144 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001145 }
1146
Bryce Leef3c6a472017-11-14 14:53:06 -08001147 // TODO: Look into whether this override is still necessary.
1148 @Override
1149 public Rect getBounds() {
1150 if (isInMultiWindowMode()) {
1151 return getTask().getBounds();
1152 } else if (mAppToken != null){
1153 return mAppToken.getBounds();
1154 } else {
1155 return super.getBounds();
1156 }
1157 }
1158
Craig Mautnera2c77052012-03-26 12:14:43 -07001159 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001160 public Rect getFrameLw() {
1161 return mFrame;
1162 }
1163
Craig Mautnera2c77052012-03-26 12:14:43 -07001164 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001165 public Rect getDisplayFrameLw() {
1166 return mDisplayFrame;
1167 }
1168
Craig Mautnera2c77052012-03-26 12:14:43 -07001169 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001170 public Rect getOverscanFrameLw() {
1171 return mOverscanFrame;
1172 }
1173
1174 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001175 public Rect getContentFrameLw() {
1176 return mContentFrame;
1177 }
1178
Craig Mautnera2c77052012-03-26 12:14:43 -07001179 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001180 public Rect getVisibleFrameLw() {
1181 return mVisibleFrame;
1182 }
1183
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001184 Rect getStableFrameLw() {
1185 return mStableFrame;
1186 }
1187
Craig Mautnera2c77052012-03-26 12:14:43 -07001188 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001189 public boolean getGivenInsetsPendingLw() {
1190 return mGivenInsetsPending;
1191 }
1192
Craig Mautnera2c77052012-03-26 12:14:43 -07001193 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001194 public Rect getGivenContentInsetsLw() {
1195 return mGivenContentInsets;
1196 }
1197
Craig Mautnera2c77052012-03-26 12:14:43 -07001198 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001199 public Rect getGivenVisibleInsetsLw() {
1200 return mGivenVisibleInsets;
1201 }
1202
Craig Mautnera2c77052012-03-26 12:14:43 -07001203 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001204 public WindowManager.LayoutParams getAttrs() {
1205 return mAttrs;
1206 }
1207
Craig Mautner812d2ca2012-09-27 15:35:34 -07001208 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001209 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001210 return getDisplayContent().getNeedsMenu(this, bottom);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001211 }
1212
Craig Mautner19d59bc2012-09-04 11:15:56 -07001213 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001214 public int getSystemUiVisibility() {
1215 return mSystemUiVisibility;
1216 }
1217
Craig Mautner19d59bc2012-09-04 11:15:56 -07001218 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001219 public int getSurfaceLayer() {
1220 return mLayer;
1221 }
1222
Craig Mautner812d2ca2012-09-27 15:35:34 -07001223 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001224 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001225 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001226 }
1227
1228 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001229 public IApplicationToken getAppToken() {
1230 return mAppToken != null ? mAppToken.appToken : null;
1231 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001232
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001233 @Override
1234 public boolean isVoiceInteraction() {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001235 return mAppToken != null && mAppToken.mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001236 }
1237
Robert Carr31aa98b2016-07-20 15:29:03 -07001238 boolean setReportResizeHints() {
Craig Mautner4c5eb222013-11-18 12:59:05 -08001239 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1240 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1241 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001242 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001243 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
Robert Carr31aa98b2016-07-20 15:29:03 -07001244 mFrameSizeChanged |= (mLastFrame.width() != mFrame.width()) ||
1245 (mLastFrame.height() != mFrame.height());
Adrian Roos5c6b6222017-11-07 17:36:10 +01001246 mDisplayCutoutChanged |= !mLastDisplayCutout.equals(mDisplayCutout);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001247 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
Adrian Roos5c6b6222017-11-07 17:36:10 +01001248 || mOutsetsChanged || mFrameSizeChanged || mDisplayCutoutChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001249 }
1250
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001251 /**
1252 * Adds the window to the resizing list if any of the parameters we use to track the window
1253 * dimensions or insets have changed.
1254 */
1255 void updateResizingWindowIfNeeded() {
1256 final WindowStateAnimator winAnimator = mWinAnimator;
Adrian Roos5251b1d2018-03-23 18:57:43 +01001257 if (!mHasSurface || getDisplayContent().mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001258 return;
1259 }
1260
1261 final Task task = getTask();
1262 // In the case of stack bound animations, the window frames will update (unlike other
1263 // animations which just modify various transformation properties). We don't want to
1264 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1265 // the frame may not correspond to the surface size or the onscreen area at various
1266 // phases in the animation, and the client will become sad and confused.
Winson Chung40a5f932017-04-13 16:39:36 -07001267 if (task != null && task.mStack.isAnimatingBounds()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001268 return;
1269 }
1270
1271 setReportResizeHints();
1272 boolean configChanged = isConfigChanged();
1273 if (DEBUG_CONFIGURATION && configChanged) {
1274 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1275 }
1276
1277 final boolean dragResizingChanged = isDragResizeChanged()
1278 && !isDragResizingChangeReported();
1279
1280 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
1281 + " dragResizingChanged=" + dragResizingChanged + " last=" + mLastFrame
1282 + " frame=" + mFrame);
1283
1284 // We update mLastFrame always rather than in the conditional with the last inset
1285 // variables, because mFrameSizeChanged only tracks the width and height changing.
1286 mLastFrame.set(mFrame);
1287
1288 if (mContentInsetsChanged
1289 || mVisibleInsetsChanged
Adrian Rooscb938492018-04-16 17:10:32 +02001290 || mStableInsetsChanged
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001291 || winAnimator.mSurfaceResized
1292 || mOutsetsChanged
1293 || mFrameSizeChanged
Adrian Roos5c6b6222017-11-07 17:36:10 +01001294 || mDisplayCutoutChanged
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001295 || configChanged
1296 || dragResizingChanged
Andrii Kulianb2e37802017-01-11 00:36:44 -08001297 || mReportOrientationChanged) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001298 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1299 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
1300 + " contentInsetsChanged=" + mContentInsetsChanged
1301 + " " + mContentInsets.toShortString()
1302 + " visibleInsetsChanged=" + mVisibleInsetsChanged
1303 + " " + mVisibleInsets.toShortString()
1304 + " stableInsetsChanged=" + mStableInsetsChanged
1305 + " " + mStableInsets.toShortString()
1306 + " outsetsChanged=" + mOutsetsChanged
1307 + " " + mOutsets.toShortString()
1308 + " surfaceResized=" + winAnimator.mSurfaceResized
1309 + " configChanged=" + configChanged
1310 + " dragResizingChanged=" + dragResizingChanged
Adrian Roos5c6b6222017-11-07 17:36:10 +01001311 + " reportOrientationChanged=" + mReportOrientationChanged
1312 + " displayCutoutChanged=" + mDisplayCutoutChanged);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001313 }
1314
1315 // If it's a dead window left on screen, and the configuration changed, there is nothing
1316 // we can do about it. Remove the window now.
1317 if (mAppToken != null && mAppDied) {
1318 mAppToken.removeDeadWindows();
1319 return;
1320 }
1321
Jorim Jaggidc9385a2017-05-13 02:00:31 +02001322 updateLastInsetValues();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001323 mService.makeWindowFreezingScreenIfNeededLocked(this);
1324
1325 // If the orientation is changing, or we're starting or ending a drag resizing action,
1326 // then we need to hold off on unfreezing the display until this window has been
1327 // redrawn; to do that, we need to go through the process of getting informed by the
1328 // application when it has finished drawing.
Robert Carr09286c92018-02-15 13:52:31 -08001329 if (getOrientationChanging() || dragResizingChanged) {
Robert Carre13b58e2017-08-31 14:50:44 -07001330 if (DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001331 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1332 + ", mDrawState=DRAW_PENDING in " + this
1333 + ", surfaceController " + winAnimator.mSurfaceController);
1334 }
1335 winAnimator.mDrawState = DRAW_PENDING;
1336 if (mAppToken != null) {
1337 mAppToken.clearAllDrawn();
1338 }
1339 }
1340 if (!mService.mResizingWindows.contains(this)) {
1341 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
1342 mService.mResizingWindows.add(this);
1343 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07001344 } else if (getOrientationChanging()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001345 if (isDrawnLw()) {
1346 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1347 + this + ", surfaceController " + winAnimator.mSurfaceController);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001348 setOrientationChanging(false);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001349 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1350 - mService.mDisplayFreezeTime);
1351 }
1352 }
1353 }
1354
Bryce Lee8c3cf382017-07-06 19:47:10 -07001355 boolean getOrientationChanging() {
1356 // In addition to the local state flag, we must also consider the difference in the last
1357 // reported configuration vs. the current state. If the client code has not been informed of
1358 // the change, logic dependent on having finished processing the orientation, such as
1359 // unfreezing, could be improperly triggered.
1360 // TODO(b/62846907): Checking against {@link mLastReportedConfiguration} could be flaky as
1361 // this is not necessarily what the client has processed yet. Find a
1362 // better indicator consistent with the client.
Robert Carr926643f2017-08-02 12:01:12 -07001363 return (mOrientationChanging || (isVisible()
Bryce Lee2b17afd2017-09-21 10:38:20 -07001364 && getConfiguration().orientation != getLastReportedConfiguration().orientation))
Robert Carr9c1c3a02017-08-08 12:59:01 -07001365 && !mSeamlesslyRotated
1366 && !mOrientationChangeTimedOut;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001367 }
1368
1369 void setOrientationChanging(boolean changing) {
1370 mOrientationChanging = changing;
Robert Carr9c1c3a02017-08-08 12:59:01 -07001371 mOrientationChangeTimedOut = false;
1372 }
1373
1374 void orientationChangeTimedOut() {
1375 mOrientationChangeTimedOut = true;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001376 }
1377
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001378 DisplayContent getDisplayContent() {
1379 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001380 }
1381
Adrian Roos5251b1d2018-03-23 18:57:43 +01001382 @Override
1383 void onDisplayChanged(DisplayContent dc) {
1384 super.onDisplayChanged(dc);
1385 // Window was not laid out for this display yet, so make sure mLayoutSeq does not match.
1386 if (dc != null) {
1387 mLayoutSeq = dc.mLayoutSeq - 1;
Brad Stenningaf596412018-04-02 12:03:19 -07001388 mInputWindowHandle.displayId = dc.getDisplayId();
Adrian Roos5251b1d2018-03-23 18:57:43 +01001389 }
1390 }
1391
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001392 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001393 final DisplayContent displayContent = getDisplayContent();
1394 return displayContent != null ? displayContent.getDisplayInfo() : null;
1395 }
1396
Jorim Jaggife762342016-10-13 14:33:27 +02001397 @Override
1398 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001399 final DisplayContent displayContent = getDisplayContent();
1400 if (displayContent == null) {
Brad Stenningaf596412018-04-02 12:03:19 -07001401 return Display.INVALID_DISPLAY;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001402 }
1403 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001404 }
1405
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001406 Task getTask() {
Bryce Lee6d410262017-02-28 15:30:17 -08001407 return mAppToken != null ? mAppToken.getTask() : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001408 }
1409
1410 TaskStack getStack() {
1411 Task task = getTask();
1412 if (task != null) {
1413 if (task.mStack != null) {
1414 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001415 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001416 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001417 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1418 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001419 final DisplayContent dc = getDisplayContent();
1420 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001421 }
1422
Skuhnef932e562015-08-20 12:07:30 -07001423 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001424 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001425 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001426 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001427 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001428 final Task task = getTask();
1429 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001430 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001431 mTmpRect.setEmpty();
1432 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001433 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001434 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001435 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001436 } else {
1437 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001438 }
1439 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001440
Chong Zhang9184ec62015-09-24 12:32:21 -07001441 bounds.set(mVisibleFrame);
1442 if (intersectWithStackBounds) {
1443 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001444 }
1445
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001446 if (bounds.isEmpty()) {
1447 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001448 if (intersectWithStackBounds) {
1449 bounds.intersect(mTmpRect);
1450 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001451 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001452 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001453 }
1454
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001455 public long getInputDispatchingTimeoutNanos() {
1456 return mAppToken != null
Wale Ogunwale72919d22016-12-08 18:58:50 -08001457 ? mAppToken.mInputDispatchingTimeoutNanos
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001458 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1459 }
1460
Craig Mautnere8552142012-11-07 13:55:47 -08001461 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001462 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001463 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001464 }
1465
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001466 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1467 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1468 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1469 if (dtdx < -.000001f || dtdx > .000001f) return false;
1470 if (dsdy < -.000001f || dsdy > .000001f) return false;
1471 return true;
1472 }
1473
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001474 void prelayout() {
1475 if (mEnforceSizeCompat) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001476 mGlobalScale = getDisplayContent().mCompatibleScreenScale;
1477 mInvGlobalScale = 1 / mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001478 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001479 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001480 }
1481 }
1482
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001483 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001484 boolean hasContentToDisplay() {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001485 if (!mAppFreezing && isDrawnLw() && (mViewVisibility == View.VISIBLE
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001486 || (mWinAnimator.isAnimationSet() && !mService.mAppTransition.isTransitionSet()))) {
1487 return true;
1488 }
1489
Wale Ogunwale44f21802016-09-02 12:49:48 -07001490 return super.hasContentToDisplay();
1491 }
1492
1493 @Override
1494 boolean isVisible() {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001495 return wouldBeVisibleIfPolicyIgnored() && mPolicyVisibility;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001496 }
1497
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001498 /**
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001499 * @return True if the window would be visible if we'd ignore policy visibility, false
1500 * otherwise.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001501 */
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001502 boolean wouldBeVisibleIfPolicyIgnored() {
Jorim Jaggi43530c92017-05-18 01:53:56 +02001503 return mHasSurface && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001504 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001505 }
1506
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001507 @Override
1508 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001509 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001510 }
1511
1512 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001513 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1514 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001515 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001516 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1517 boolean isWinVisibleLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001518 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.isSelfAnimating())
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001519 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001520 }
1521
1522 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001523 * The same as isVisible(), but follows the current hidden state of the associated app token,
1524 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001525 */
1526 boolean isVisibleNow() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001527 return (!mToken.isHidden() || mAttrs.type == TYPE_APPLICATION_STARTING)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001528 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001529 }
1530
1531 /**
1532 * Can this window possibly be a drag/drop target? The test here is
1533 * a combination of the above "visible now" with the check that the
1534 * Input Manager uses when discarding windows from input consideration.
1535 */
1536 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001537 return isVisibleNow() && !mRemoved
1538 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001539 }
1540
1541 /**
1542 * Same as isVisible(), but we also count it as visible between the
1543 * call to IWindowSession.add() and the first relayout().
1544 */
1545 boolean isVisibleOrAdding() {
1546 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001547 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001548 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001549 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001550 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001551 }
1552
1553 /**
1554 * Is this window currently on-screen? It is on-screen either if it
1555 * is visible or it is currently running an animation before no longer
1556 * being visible.
1557 */
1558 boolean isOnScreen() {
Jorim Jaggiaf221d12016-11-15 14:59:57 -08001559 if (!mHasSurface || mDestroying || !mPolicyVisibility) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001560 return false;
1561 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001562 final AppWindowToken atoken = mAppToken;
1563 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001564 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001565 || mWinAnimator.isAnimationSet());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001566 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01001567 return !isParentWindowHidden() || mWinAnimator.isAnimationSet();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001568 }
1569
1570 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001571 * Whether this window's drawn state might affect the drawn states of the app token.
1572 *
Chong Zhang8e4bda92016-05-04 15:08:18 -07001573 * @return true if the window should be considered while evaluating allDrawn flags.
1574 */
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001575 boolean mightAffectAllDrawn() {
1576 final boolean isAppType = mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1577 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION;
1578 return (isOnScreen() || isAppType) && !mAnimatingExit && !mDestroying;
Chong Zhang8e4bda92016-05-04 15:08:18 -07001579 }
1580
1581 /**
1582 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1583 * it must be drawn before allDrawn can become true.
1584 */
1585 boolean isInteresting() {
1586 return mAppToken != null && !mAppDied
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001587 && (!mAppToken.isFreezingScreen() || !mAppFreezing);
Chong Zhang8e4bda92016-05-04 15:08:18 -07001588 }
1589
1590 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001591 * Like isOnScreen(), but we don't return true if the window is part
1592 * of a transition that has not yet been started.
1593 */
1594 boolean isReadyForDisplay() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001595 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001596 return false;
1597 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001598 return mHasSurface && mPolicyVisibility && !mDestroying
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001599 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.isHidden())
1600 || mWinAnimator.isAnimationSet());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001601 }
1602
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001603 // TODO: Another visibility method that was added late in the release to minimize risk.
1604 @Override
1605 public boolean canAffectSystemUiFlags() {
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001606 final boolean translucent = mAttrs.alpha == 0.0f;
Jorim Jaggi72207752018-01-08 13:16:59 +01001607 if (translucent) {
1608 return false;
1609 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001610 if (mAppToken == null) {
1611 final boolean shown = mWinAnimator.getShown();
1612 final boolean exiting = mAnimatingExit || mDestroying;
Jorim Jaggi72207752018-01-08 13:16:59 +01001613 return shown && !exiting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001614 } else {
Jorim Jaggi50bf59c2018-03-09 17:29:48 +01001615 final Task task = getTask();
1616 final boolean canFromTask = task != null && task.canAffectSystemUiFlags();
1617 return canFromTask && !mAppToken.isHidden();
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001618 }
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001619 }
1620
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001621 /**
1622 * Like isOnScreen, but returns false if the surface hasn't yet
1623 * been drawn.
1624 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001625 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001626 public boolean isDisplayedLw() {
1627 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001628 return isDrawnLw() && mPolicyVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001629 && ((!isParentWindowHidden() && (atoken == null || !atoken.hiddenRequested))
1630 || mWinAnimator.isAnimationSet());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001631 }
1632
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001633 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001634 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001635 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001636 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001637 public boolean isAnimatingLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001638 return isAnimating();
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001639 }
1640
Craig Mautner812d2ca2012-09-27 15:35:34 -07001641 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001642 public boolean isGoneForLayoutLw() {
1643 final AppWindowToken atoken = mAppToken;
1644 return mViewVisibility == View.GONE
1645 || !mRelayoutCalled
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001646 || (atoken == null && mToken.isHidden())
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001647 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001648 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001649 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001650 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001651 }
1652
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001653 /**
1654 * Returns true if the window has a surface that it has drawn a
1655 * complete UI in to.
1656 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001657 public boolean isDrawFinishedLw() {
1658 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001659 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1660 || mWinAnimator.mDrawState == READY_TO_SHOW
1661 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001662 }
1663
1664 /**
1665 * Returns true if the window has a surface that it has drawn a
1666 * complete UI in to.
1667 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001668 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001669 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001670 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001671 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001672 }
1673
1674 /**
1675 * Return true if the window is opaque and fully drawn. This indicates
1676 * it may obscure windows behind it.
1677 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001678 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001679 // When there is keyguard, wallpaper could be placed over the secure app
1680 // window but invisible. We need to check wallpaper visibility explicitly
1681 // to determine if it's occluding apps.
1682 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1683 || (mIsWallpaper && mWallpaperVisible))
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001684 && isDrawnLw() && !mWinAnimator.isAnimationSet();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001685 }
1686
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001687 @Override
1688 void onMovedByResize() {
1689 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001690 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001691 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001692 }
1693
1694 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1695 boolean changed = false;
1696
1697 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001698 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001699 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1700 }
1701
1702 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1703 // Starting window that's exiting will be removed when the animation finishes.
1704 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1705 // to actually remove it.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001706 if (!visible && isVisibleNow() && mAppToken.isSelfAnimating()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001707 mAnimatingExit = true;
1708 mRemoveOnExit = true;
1709 mWindowRemovalAllowed = true;
1710 }
1711 return changed;
1712 }
1713
chaviwe390cbd2018-04-16 15:29:38 -07001714 final boolean isVisibleNow = isVisibleNow();
1715 if (visible != isVisibleNow) {
1716 // Run exit animation if:
1717 // 1. App visibility and WS visibility are different
1718 // 2. App is not running an animation
1719 // 3. WS is currently visible
1720 if (!runningAppAnimation && isVisibleNow) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001721 final AccessibilityController accessibilityController =
1722 mService.mAccessibilityController;
chaviwe390cbd2018-04-16 15:29:38 -07001723 final int winTransit = TRANSIT_EXIT;
1724 mWinAnimator.applyAnimationLocked(winTransit, false /* isEntrance */);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001725 //TODO (multidisplay): Magnification is supported only for the default
1726 if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
1727 accessibilityController.onWindowTransitionLocked(this, winTransit);
1728 }
1729 }
1730 changed = true;
1731 setDisplayLayoutNeeded();
1732 }
1733
1734 return changed;
1735 }
1736
1737 boolean onSetAppExiting() {
1738 final DisplayContent displayContent = getDisplayContent();
1739 boolean changed = false;
1740
1741 if (isVisibleNow()) {
1742 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
1743 //TODO (multidisplay): Magnification is supported only for the default
1744 if (mService.mAccessibilityController != null && isDefaultDisplay()) {
1745 mService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
1746 }
1747 changed = true;
1748 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001749 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001750 }
1751 }
1752
1753 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001754 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001755 changed |= c.onSetAppExiting();
1756 }
1757
1758 return changed;
1759 }
1760
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001761 @Override
1762 void onResize() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001763 final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
Andrii Kulian3dcdf642018-05-23 17:14:00 -07001764 if (mHasSurface && !isGoneForLayoutLw() && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001765 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001766 resizingWindows.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001767 }
1768 if (isGoneForLayoutLw()) {
1769 mResizedWhileGone = true;
1770 }
1771
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001772 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001773 }
1774
1775 void onUnfreezeBounds() {
1776 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001777 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001778 c.onUnfreezeBounds();
1779 }
1780
1781 if (!mHasSurface) {
1782 return;
1783 }
1784
1785 mLayoutNeeded = true;
1786 setDisplayLayoutNeeded();
1787 if (!mService.mResizingWindows.contains(this)) {
1788 mService.mResizingWindows.add(this);
1789 }
1790 }
1791
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001792 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001793 * If the window has moved due to its containing content frame changing, then notify the
1794 * listeners and optionally animate it. Simply checking a change of position is not enough,
1795 * because being move due to dock divider is not a trigger for animation.
1796 */
chaviw161ea3e2018-01-31 12:01:12 -08001797 void handleWindowMovedIfNeeded() {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001798 if (!hasMoved()) {
1799 return;
1800 }
1801
1802 // Frame has moved, containing content frame has also moved, and we're not currently
1803 // animating... let's do something.
1804 final int left = mFrame.left;
1805 final int top = mFrame.top;
1806 final Task task = getTask();
1807 final boolean adjustedForMinimizedDockOrIme = task != null
1808 && (task.mStack.isAdjustedForMinimizedDockedStack()
1809 || task.mStack.isAdjustedForIme());
David Stevens9440dc82017-03-16 19:00:20 -07001810 if (mToken.okToAnimate()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001811 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1812 && !isDragResizing() && !adjustedForMinimizedDockOrIme
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001813 && getWindowConfiguration().hasMovementAnimations()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001814 && !mWinAnimator.mLastHidden) {
chaviw161ea3e2018-01-31 12:01:12 -08001815 startMoveAnimation(left, top);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001816 }
1817
1818 //TODO (multidisplay): Accessibility supported only for the default display.
1819 if (mService.mAccessibilityController != null
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001820 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001821 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
1822 }
1823
1824 try {
1825 mClient.moved(left, top);
1826 } catch (RemoteException e) {
1827 }
1828 mMovedByResize = false;
1829 }
1830
1831 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001832 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001833 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1834 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001835 private boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001836 return mHasSurface && (mContentChanged || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001837 && !mAnimatingExit
Chong Zhangbd0d9372015-12-28 15:18:29 -08001838 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001839 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001840 }
1841
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001842 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001843 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001844 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001845 return false;
1846 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001847 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001848 }
1849
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001850 boolean fillsDisplay() {
1851 final DisplayInfo displayInfo = getDisplayInfo();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001852 return mFrame.left <= 0 && mFrame.top <= 0
1853 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001854 }
1855
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001856 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001857 boolean isConfigChanged() {
Bryce Lee2b17afd2017-09-21 10:38:20 -07001858 return !getLastReportedConfiguration().equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001859 }
1860
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001861 void onWindowReplacementTimeout() {
1862 if (mWillReplaceWindow) {
1863 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001864 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001865 // delays removal on certain conditions, which will leave the stale window in the
1866 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1867 //
1868 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001869 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001870 } else {
1871 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001872 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001873 c.onWindowReplacementTimeout();
1874 }
1875 }
1876 }
1877
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001878 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001879 void forceWindowsScaleableInTransaction(boolean force) {
1880 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1881 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1882 }
1883
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001884 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001885 }
1886
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001887 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001888 void removeImmediately() {
1889 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001890
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001891 if (mRemoved) {
1892 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001893 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1894 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001895 return;
1896 }
1897
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001898 mRemoved = true;
1899
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001900 mWillReplaceWindow = false;
1901 if (mReplacementWindow != null) {
1902 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1903 }
1904
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001905 final DisplayContent dc = getDisplayContent();
Robert Carr825581a2018-03-30 14:00:53 -07001906 if (isInputMethodTarget()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001907 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001908 }
1909
1910 final int type = mAttrs.type;
1911 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001912 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001913 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001914 if (mTapExcludeRegionHolder != null) {
1915 // If a tap exclude region container was initialized for this window, then it should've
1916 // also been registered in display.
1917 dc.mTapExcludeProvidingWindows.remove(this);
1918 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001919 mPolicy.removeWindowLw(this);
1920
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001921 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001922
Craig Mautner96868332012-12-04 14:29:11 -08001923 mWinAnimator.destroyDeferredSurfaceLocked();
1924 mWinAnimator.destroySurfaceLocked();
Wale Ogunwale943002b2017-02-15 19:34:01 -08001925 mSession.windowRemovedLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001926 try {
1927 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1928 } catch (RuntimeException e) {
1929 // Ignore if it has already been removed (usually because
1930 // we are doing this as part of processing a death note.)
1931 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001932
1933 mService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001934 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001935
Wale Ogunwale571771c2016-08-26 13:18:50 -07001936 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001937 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001938 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001939 removeIfPossible(false /*keepVisibleDeadWindow*/);
1940 }
1941
Wale Ogunwale571771c2016-08-26 13:18:50 -07001942 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001943 mWindowRemovalAllowed = true;
1944 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1945 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1946
1947 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1948 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1949 "Starting window removed " + this);
1950
1951 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && this == mService.mCurrentFocus)
1952 Slog.v(TAG_WM, "Remove " + this + " client="
1953 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1954 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1955 + Debug.getCallers(5));
1956
1957 final long origId = Binder.clearCallingIdentity();
1958
Peter Visontay3556a3b2017-11-01 17:23:17 +00001959 try {
1960 disposeInputChannel();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001961
Peter Visontay3556a3b2017-11-01 17:23:17 +00001962 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1963 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1964 + " mAnimatingExit=" + mAnimatingExit
1965 + " mRemoveOnExit=" + mRemoveOnExit
1966 + " mHasSurface=" + mHasSurface
1967 + " surfaceShowing=" + mWinAnimator.getShown()
1968 + " isAnimationSet=" + mWinAnimator.isAnimationSet()
1969 + " app-animation="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001970 + (mAppToken != null ? mAppToken.isSelfAnimating() : "false")
Peter Visontay3556a3b2017-11-01 17:23:17 +00001971 + " mWillReplaceWindow=" + mWillReplaceWindow
1972 + " inPendingTransaction="
1973 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
1974 + " mDisplayFrozen=" + mService.mDisplayFrozen
1975 + " callers=" + Debug.getCallers(6));
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001976
Peter Visontay3556a3b2017-11-01 17:23:17 +00001977 // Visibility of the removed window. Will be used later to update orientation later on.
1978 boolean wasVisible = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001979
Peter Visontay3556a3b2017-11-01 17:23:17 +00001980 final int displayId = getDisplayId();
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001981
Peter Visontay3556a3b2017-11-01 17:23:17 +00001982 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1983 // window until the animation is done. If the display is frozen, just remove immediately,
1984 // since the animation wouldn't be seen.
1985 if (mHasSurface && mToken.okToAnimate()) {
1986 if (mWillReplaceWindow) {
1987 // This window is going to be replaced. We need to keep it around until the new one
1988 // gets added, then we will get rid of this one.
1989 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1990 "Preserving " + this + " until the new one is " + "added");
1991 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1992 // been removed. We probably need another flag to indicate that window removal
1993 // should be deffered vs. overloading the flag that says we are playing an exit
1994 // animation.
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001995 mAnimatingExit = true;
Peter Visontay3556a3b2017-11-01 17:23:17 +00001996 mReplacingRemoveRequested = true;
1997 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001998 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001999
Peter Visontay3556a3b2017-11-01 17:23:17 +00002000 // If we are not currently running the exit animation, we need to see about starting one
2001 wasVisible = isWinVisibleLw();
2002
2003 if (keepVisibleDeadWindow) {
2004 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
2005 "Not removing " + this + " because app died while it's visible");
2006
2007 mAppDied = true;
2008 setDisplayLayoutNeeded();
2009 mService.mWindowPlacerLocked.performSurfacePlacement();
2010
2011 // Set up a replacement input channel since the app is now dead.
2012 // We need to catch tapping on the dead window to restart the app.
2013 openInputChannel(null);
2014 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
2015 return;
2016 }
2017
2018 if (wasVisible) {
2019 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
2020
2021 // Try starting an animation.
2022 if (mWinAnimator.applyAnimationLocked(transit, false)) {
2023 mAnimatingExit = true;
Jorim Jaggif41e8822018-04-06 17:22:03 +02002024
2025 // mAnimatingExit affects canAffectSystemUiFlags(). Run layout such that
2026 // any change from that is performed immediately.
2027 setDisplayLayoutNeeded();
2028 mService.requestTraversal();
Peter Visontay3556a3b2017-11-01 17:23:17 +00002029 }
2030 //TODO (multidisplay): Magnification is supported only for the default display.
2031 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
2032 mService.mAccessibilityController.onWindowTransitionLocked(this, transit);
2033 }
2034 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002035 final boolean isAnimating = mWinAnimator.isAnimationSet()
2036 && (mAppToken == null || !mAppToken.isWaitingForTransitionStart());
Peter Visontay3556a3b2017-11-01 17:23:17 +00002037 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
2038 && mAppToken.isLastWindow(this);
2039 // We delay the removal of a window if it has a showing surface that can be used to run
2040 // exit animation and it is marked as exiting.
2041 // Also, If isn't the an animating starting window that is the last window in the app.
2042 // We allow the removal of the non-animating starting window now as there is no
2043 // additional window or animation that will trigger its removal.
2044 if (mWinAnimator.getShown() && mAnimatingExit
2045 && (!lastWindowIsStartingWindow || isAnimating)) {
2046 // The exit animation is running or should run... wait for it!
2047 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
2048 "Not removing " + this + " due to exit animation ");
2049 setupWindowForRemoveOnExit();
2050 if (mAppToken != null) {
2051 mAppToken.updateReportedVisibilityLocked();
2052 }
2053 return;
2054 }
2055 }
2056
2057 removeImmediately();
2058 // Removing a visible window will effect the computed orientation
2059 // So just update orientation if needed.
Robert Carrae606b42018-02-15 15:36:23 -08002060 if (wasVisible && mService.updateOrientationFromAppTokensLocked(displayId)) {
Peter Visontay3556a3b2017-11-01 17:23:17 +00002061 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
2062 }
2063 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
2064 } finally {
2065 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002066 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002067 }
2068
2069 private void setupWindowForRemoveOnExit() {
2070 mRemoveOnExit = true;
2071 setDisplayLayoutNeeded();
2072 // Request a focus update as this window's input channel is already gone. Otherwise
2073 // we could have no focused window in input manager.
2074 final boolean focusChanged = mService.updateFocusedWindowLocked(
2075 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
2076 mService.mWindowPlacerLocked.performSurfacePlacement();
2077 if (focusChanged) {
2078 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2079 }
2080 }
2081
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08002082 void setHasSurface(boolean hasSurface) {
2083 mHasSurface = hasSurface;
2084 }
2085
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002086 boolean canBeImeTarget() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002087 if (mIsImWindow) {
2088 // IME windows can't be IME targets. IME targets are required to be below the IME
2089 // windows and that wouldn't be possible if the IME window is its own target...silly.
2090 return false;
2091 }
2092
Winson Chung3d0a74a2017-07-12 12:37:19 -07002093 final boolean windowsAreFocusable = mAppToken == null || mAppToken.windowsAreFocusable();
Winson Chungb1549342017-07-11 09:59:56 -07002094 if (!windowsAreFocusable) {
2095 // This window can't be an IME target if the app's windows should not be focusable.
2096 return false;
2097 }
2098
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002099 final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002100 final int type = mAttrs.type;
2101
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002102 // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are set or
2103 // both are cleared...and not a starting window.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002104 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
2105 && type != TYPE_APPLICATION_STARTING) {
2106 return false;
2107 }
2108
2109 if (DEBUG_INPUT_METHOD) {
2110 Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding());
2111 if (!isVisibleOrAdding()) {
2112 Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController
2113 + " relayoutCalled=" + mRelayoutCalled
2114 + " viewVis=" + mViewVisibility
2115 + " policyVis=" + mPolicyVisibility
2116 + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim
2117 + " parentHidden=" + isParentWindowHidden()
2118 + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
2119 if (mAppToken != null) {
2120 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + mAppToken.hiddenRequested);
2121 }
2122 }
2123 }
2124 return isVisibleOrAdding();
2125 }
2126
Chong Zhangacf11402015-11-04 16:23:10 -08002127 private final class DeadWindowEventReceiver extends InputEventReceiver {
2128 DeadWindowEventReceiver(InputChannel inputChannel) {
2129 super(inputChannel, mService.mH.getLooper());
2130 }
2131 @Override
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -07002132 public void onInputEvent(InputEvent event, int displayId) {
Chong Zhangacf11402015-11-04 16:23:10 -08002133 finishInputEvent(event, true);
2134 }
2135 }
2136 /**
2137 * Dummy event receiver for windows that died visible.
2138 */
2139 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2140
Chong Zhang112eb8c2015-11-02 11:17:00 -08002141 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002142 if (mInputChannel != null) {
2143 throw new IllegalStateException("Window already has an input channel.");
2144 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002145 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002146 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2147 mInputChannel = inputChannels[0];
2148 mClientChannel = inputChannels[1];
2149 mInputWindowHandle.inputChannel = inputChannels[0];
2150 if (outInputChannel != null) {
2151 mClientChannel.transferTo(outInputChannel);
2152 mClientChannel.dispose();
2153 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002154 } else {
2155 // If the window died visible, we setup a dummy input channel, so that taps
2156 // can still detected by input monitor channel, and we can relaunch the app.
2157 // Create dummy event receiver that simply reports all events as handled.
2158 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002159 }
2160 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002161 }
2162
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002163 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002164 if (mDeadWindowEventReceiver != null) {
2165 mDeadWindowEventReceiver.dispose();
2166 mDeadWindowEventReceiver = null;
2167 }
2168
2169 // unregister server channel first otherwise it complains about broken channel
2170 if (mInputChannel != null) {
2171 mService.mInputManager.unregisterInputChannel(mInputChannel);
2172 mInputChannel.dispose();
2173 mInputChannel = null;
2174 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002175 if (mClientChannel != null) {
2176 mClientChannel.dispose();
2177 mClientChannel = null;
2178 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07002179 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002180 }
2181
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002182 /** Returns true if the replacement window was removed. */
2183 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2184 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2185 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2186 removeReplacedWindow();
2187 return true;
2188 }
2189
2190 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002191 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002192 if (c.removeReplacedWindowIfNeeded(replacement)) {
2193 return true;
2194 }
2195 }
2196 return false;
2197 }
2198
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002199 private void removeReplacedWindow() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002200 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002201 mWillReplaceWindow = false;
2202 mAnimateReplacingWindow = false;
2203 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002204 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002205 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002206 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002207 }
2208 }
2209
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002210 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2211 boolean replacementSet = false;
2212
2213 if (mWillReplaceWindow && mReplacementWindow == null
2214 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2215
2216 mReplacementWindow = replacementCandidate;
2217 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2218 replacementSet = true;
2219 }
2220
2221 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002222 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002223 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2224 }
2225
2226 return replacementSet;
2227 }
2228
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002229 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002230 final DisplayContent dc = getDisplayContent();
2231 if (dc != null) {
2232 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002233 }
2234 }
2235
Chong Zhang5117e272016-05-03 12:47:34 -07002236 void applyAdjustForImeIfNeeded() {
2237 final Task task = getTask();
2238 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2239 task.mStack.applyAdjustForImeIfNeeded(task);
2240 }
2241 }
2242
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002243 @Override
2244 void switchUser() {
2245 super.switchUser();
2246 if (isHiddenFromUserLocked()) {
2247 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2248 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
2249 hideLw(false);
2250 }
2251 }
2252
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002253 int getTouchableRegion(Region region, int flags) {
2254 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002255 if (modal && mAppToken != null) {
2256 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002257 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002258 // If this is a modal window we need to dismiss it if it's not full screen and the
2259 // touch happens outside of the frame that displays the content. This means we
2260 // need to intercept touches outside of that window. The dim layer user
2261 // associated with the window (task or stack) will give us the good bounds, as
2262 // they would be used to display the dim layer.
Robert Carrf59b8dd2017-10-02 18:58:36 -07002263 final Task task = getTask();
2264 if (task != null) {
2265 task.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002266 } else {
Robert Carrf59b8dd2017-10-02 18:58:36 -07002267 getStack().getDimBounds(mTmpRect);
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002268 }
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002269 if (inFreeformWindowingMode()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002270 // For freeform windows we the touch region to include the whole surface for the
2271 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002272 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2273 final int delta = WindowManagerService.dipToPixel(
2274 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2275 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002276 }
2277 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002278 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002279 } else {
2280 // Not modal or full screen modal
2281 getTouchableRegion(region);
2282 }
2283 return flags;
2284 }
2285
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002286 void checkPolicyVisibilityChange() {
2287 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2288 if (DEBUG_VISIBILITY) {
2289 Slog.v(TAG, "Policy visibility changing after anim in " +
2290 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2291 }
2292 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002293 if (!mPolicyVisibility) {
Jorim Jaggi2e05af22017-12-28 15:15:11 +01002294 mWinAnimator.hide("checkPolicyVisibilityChange");
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002295 if (mService.mCurrentFocus == this) {
2296 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2297 "setAnimationLocked: setting mFocusMayChange true");
2298 mService.mFocusMayChange = true;
2299 }
Tetsutoki Shiozawa64c5f0c2018-05-18 10:55:01 +09002300 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002301 // Window is no longer visible -- make sure if we were waiting
2302 // for it to be displayed before enabling the display, that
2303 // we allow the display to be enabled now.
2304 mService.enableScreenIfNeededLocked();
2305 }
2306 }
2307 }
2308
2309 void setRequestedSize(int requestedWidth, int requestedHeight) {
2310 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2311 mLayoutNeeded = true;
2312 mRequestedWidth = requestedWidth;
2313 mRequestedHeight = requestedHeight;
2314 }
2315 }
2316
Bryce Leef858b572017-06-29 14:03:33 -07002317 void prepareWindowToDisplayDuringRelayout(boolean wasVisible) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002318 // We need to turn on screen regardless of visibility.
chaviw40234662018-02-07 09:37:16 -08002319 boolean hasTurnScreenOnFlag = (mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0;
2320 boolean allowTheaterMode =
2321 mService.mAllowTheaterModeWakeFromLayout || Settings.Global.getInt(
2322 mService.mContext.getContentResolver(), Settings.Global.THEATER_MODE_ON, 0)
2323 == 0;
2324 boolean canTurnScreenOn = mAppToken == null || mAppToken.canTurnScreenOn();
2325
2326 // The screen will turn on if the following conditions are met
2327 // 1. The window has the flag FLAG_TURN_SCREEN_ON
2328 // 2. The WMS allows theater mode.
2329 // 3. No AWT or the AWT allows the screen to be turned on. This should only be true once
2330 // per resume to prevent the screen getting getting turned on for each relayout. Set
2331 // canTurnScreenOn will be set to false so the window doesn't turn the screen on again
2332 // during this resume.
2333 // 4. When the screen is not interactive. This is because when the screen is already
2334 // interactive, the value may persist until the next animation, which could potentially
2335 // be occurring while turning off the screen. This would lead to the screen incorrectly
2336 // turning back on.
chaviw474093d2018-03-07 15:03:38 -08002337 if (hasTurnScreenOnFlag) {
2338 if (allowTheaterMode && canTurnScreenOn && !mPowerManagerWrapper.isInteractive()) {
2339 if (DEBUG_VISIBILITY || DEBUG_POWER) {
2340 Slog.v(TAG, "Relayout window turning screen on: " + this);
2341 }
2342 mPowerManagerWrapper.wakeUp(SystemClock.uptimeMillis(),
2343 "android.server.wm:TURN_ON");
chaviw40234662018-02-07 09:37:16 -08002344 }
chaviwb28de1f2018-03-02 10:42:36 -08002345
2346 if (mAppToken != null) {
2347 mAppToken.setCanTurnScreenOn(false);
2348 }
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002349 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002350
2351 // If we were already visible, skip rest of preparation.
2352 if (wasVisible) {
2353 if (DEBUG_VISIBILITY) Slog.v(TAG,
2354 "Already visible and does not turn on screen, skip preparing: " + this);
2355 return;
2356 }
2357
2358 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2359 == SOFT_INPUT_ADJUST_RESIZE) {
2360 mLayoutNeeded = true;
2361 }
2362
David Stevens9440dc82017-03-16 19:00:20 -07002363 if (isDrawnLw() && mToken.okToAnimate()) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002364 mWinAnimator.applyEnterAnimationLocked();
2365 }
Bryce Leef858b572017-06-29 14:03:33 -07002366 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002367
Bryce Leef858b572017-06-29 14:03:33 -07002368 void getMergedConfiguration(MergedConfiguration outConfiguration) {
2369 final Configuration globalConfig = mService.mRoot.getConfiguration();
2370 final Configuration overrideConfig = getMergedOverrideConfiguration();
2371 outConfiguration.setConfiguration(globalConfig, overrideConfig);
2372 }
2373
Bryce Lee2b17afd2017-09-21 10:38:20 -07002374 void setLastReportedMergedConfiguration(MergedConfiguration config) {
2375 mLastReportedConfiguration.setTo(config);
2376 }
2377
2378 void getLastReportedMergedConfiguration(MergedConfiguration config) {
2379 config.setTo(mLastReportedConfiguration);
2380 }
2381
2382 private Configuration getLastReportedConfiguration() {
2383 return mLastReportedConfiguration.getMergedConfiguration();
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002384 }
2385
2386 void adjustStartingWindowFlags() {
2387 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2388 && mAppToken.startingWindow != null) {
2389 // Special handling of starting window over the base
2390 // window of the app: propagate lock screen flags to it,
2391 // to provide the correct semantics while starting.
2392 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2393 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2394 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2395 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2396 }
2397 }
2398
2399 void setWindowScale(int requestedWidth, int requestedHeight) {
2400 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2401
2402 if (scaledWindow) {
2403 // requested{Width|Height} Surface's physical size
2404 // attrs.{width|height} Size on screen
2405 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2406 mHScale = (mAttrs.width != requestedWidth) ?
2407 (mAttrs.width / (float)requestedWidth) : 1.0f;
2408 mVScale = (mAttrs.height != requestedHeight) ?
2409 (mAttrs.height / (float)requestedHeight) : 1.0f;
2410 } else {
2411 mHScale = mVScale = 1;
2412 }
2413 }
2414
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002415 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002416 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002417 public void binderDied() {
2418 try {
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002419 boolean resetSplitScreenResizing = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002420 synchronized(mService.mWindowMap) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002421 final WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002422 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002423 if (win != null) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002424 final DisplayContent dc = getDisplayContent();
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002425 if (win.mAppToken != null && win.mAppToken.findMainWindow() == win) {
2426 mService.mTaskSnapshotController.onAppDied(win.mAppToken);
2427 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002428 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002429 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2430 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002431 // just in case they have the divider at an unstable position. Better
2432 // also reset drag resizing state, because the owner can't do it
2433 // anymore.
Wale Ogunwale61911492017-10-11 08:50:50 -07002434 final TaskStack stack =
Matthew Ng64e77cf2017-10-31 14:01:31 -07002435 dc.getSplitScreenPrimaryStackIgnoringVisibility();
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002436 if (stack != null) {
2437 stack.resetDockedStackToMiddle();
2438 }
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002439 resetSplitScreenResizing = true;
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002440 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002441 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002442 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002443 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002444 }
2445 }
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002446 if (resetSplitScreenResizing) {
2447 try {
2448 // Note: this calls into ActivityManager, so we must *not* hold the window
2449 // manager lock while calling this.
2450 mService.mActivityManager.setSplitScreenResizing(false);
2451 } catch (RemoteException e) {
2452 // Local call, shouldn't return RemoteException.
2453 throw e.rethrowAsRuntimeException();
2454 }
2455 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002456 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002457 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002458 }
2459 }
2460 }
2461
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002462 /**
2463 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2464 * because we want to preserve its location on screen to be re-activated later when the user
2465 * interacts with it.
2466 */
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002467 private boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwale89973222017-04-23 18:39:45 -07002468 if (!isWinVisibleLw() || mAppToken == null || mAppToken.isClientHidden()) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002469 // Not a visible app window or the app isn't dead.
2470 return false;
2471 }
2472
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002473 if (mAttrs.token != mClient.asBinder()) {
2474 // The window was add by a client using another client's app token. We don't want to
2475 // keep the dead window around for this case since this is meant for 'real' apps.
2476 return false;
2477 }
2478
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002479 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2480 // We don't keep starting windows since they were added by the window manager before
2481 // the app even launched.
2482 return false;
2483 }
2484
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002485 return getWindowConfiguration().keepVisibleDeadAppWindowOnScreen();
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002486 }
2487
Wale Ogunwaled045c822015-12-02 09:14:28 -08002488 /** @return true if this window desires key events. */
2489 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002490 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002491 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002492 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002493 && (mAppToken == null || mAppToken.windowsAreFocusable())
Matthew Nge15352e2016-12-20 15:36:29 -08002494 && !canReceiveTouchInput();
2495 }
2496
2497 /** @return true if this window desires touch events. */
2498 boolean canReceiveTouchInput() {
Bryce Lee6d410262017-02-28 15:30:17 -08002499 return mAppToken != null && mAppToken.getTask() != null
2500 && mAppToken.getTask().mStack.shouldIgnoreInput();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002501 }
2502
Craig Mautner749a7bb2012-04-02 13:49:53 -07002503 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002504 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002505 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002506 }
2507
Craig Mautner749a7bb2012-04-02 13:49:53 -07002508 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002509 public boolean showLw(boolean doAnimation) {
2510 return showLw(doAnimation, true);
2511 }
2512
2513 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002514 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002515 return false;
2516 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002517 if (!mAppOpVisibility) {
2518 // Being hidden due to app op request.
2519 return false;
2520 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002521 if (mPermanentlyHidden) {
2522 // Permanently hidden until the app exists as apps aren't prepared
2523 // to handle their windows being removed from under them.
2524 return false;
2525 }
Suprabh Shukla69c71422018-04-02 18:39:01 -07002526 if (mHiddenWhileSuspended) {
2527 // Being hidden due to owner package being suspended.
2528 return false;
2529 }
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002530 if (mForceHideNonSystemOverlayWindow) {
2531 // This is an alert window that is currently force hidden.
2532 return false;
2533 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002534 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002535 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002536 return false;
2537 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002538 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002539 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002540 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Jorim Jaggia5e10572017-11-15 14:36:26 +01002541 + mPolicyVisibility + " isAnimationSet=" + mWinAnimator.isAnimationSet());
David Stevens9440dc82017-03-16 19:00:20 -07002542 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002543 doAnimation = false;
Jorim Jaggia5e10572017-11-15 14:36:26 +01002544 } else if (mPolicyVisibility && !mWinAnimator.isAnimationSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002545 // Check for the case where we are currently visible and
2546 // not animating; we do not want to do animation at such a
2547 // point to become visible when we already are.
2548 doAnimation = false;
2549 }
2550 }
2551 mPolicyVisibility = true;
2552 mPolicyVisibilityAfterAnim = true;
2553 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002554 mWinAnimator.applyAnimationLocked(TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002555 }
2556 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002557 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002558 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002559 if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) {
2560 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2561 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002562 return true;
2563 }
2564
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002565 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002566 public boolean hideLw(boolean doAnimation) {
2567 return hideLw(doAnimation, true);
2568 }
2569
2570 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2571 if (doAnimation) {
David Stevens9440dc82017-03-16 19:00:20 -07002572 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002573 doAnimation = false;
2574 }
2575 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002576 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002577 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002578 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002579 return false;
2580 }
2581 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002582 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
Jorim Jaggia5e10572017-11-15 14:36:26 +01002583 if (!mWinAnimator.isAnimationSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002584 doAnimation = false;
2585 }
2586 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002587 mPolicyVisibilityAfterAnim = false;
2588 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002589 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002590 mPolicyVisibility = false;
2591 // Window is no longer visible -- make sure if we were waiting
2592 // for it to be displayed before enabling the display, that
2593 // we allow the display to be enabled now.
2594 mService.enableScreenIfNeededLocked();
2595 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002596 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002597 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002598 mService.mFocusMayChange = true;
2599 }
2600 }
2601 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002602 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002603 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002604 if (mService.mCurrentFocus == this) {
2605 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2606 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002607 return true;
2608 }
2609
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002610 void setForceHideNonSystemOverlayWindowIfNeeded(boolean forceHide) {
2611 if (mOwnerCanAddInternalSystemWindow
2612 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2613 return;
2614 }
2615 if (mForceHideNonSystemOverlayWindow == forceHide) {
2616 return;
2617 }
2618 mForceHideNonSystemOverlayWindow = forceHide;
2619 if (forceHide) {
2620 hideLw(true /* doAnimation */, true /* requestAnim */);
2621 } else {
2622 showLw(true /* doAnimation */, true /* requestAnim */);
2623 }
2624 }
2625
Suprabh Shukla69c71422018-04-02 18:39:01 -07002626 void setHiddenWhileSuspended(boolean hide) {
2627 if (mOwnerCanAddInternalSystemWindow
2628 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2629 return;
2630 }
2631 if (mHiddenWhileSuspended == hide) {
2632 return;
2633 }
2634 mHiddenWhileSuspended = hide;
2635 if (hide) {
2636 hideLw(true, true);
2637 } else {
2638 showLw(true, true);
2639 }
2640 }
2641
Svet Ganovf7b47252018-02-26 11:11:27 -08002642 private void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002643 if (mAppOpVisibility != state) {
2644 mAppOpVisibility = state;
2645 if (state) {
2646 // If the policy visibility had last been to hide, then this
2647 // will incorrectly show at this point since we lost that
2648 // information. Not a big deal -- for the windows that have app
2649 // ops modifies they should only be hidden by policy due to the
2650 // lock screen, and the user won't be changing this if locked.
2651 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002652 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002653 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002654 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002655 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002656 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002657 }
2658
Svet Ganovf7b47252018-02-26 11:11:27 -08002659 void initAppOpsState() {
2660 if (mAppOp == OP_NONE || !mAppOpVisibility) {
2661 return;
2662 }
2663 // If the app op was MODE_DEFAULT we would have checked the permission
2664 // and add the window only if the permission was granted. Therefore, if
2665 // the mode is MODE_DEFAULT we want the op to succeed as the window is
2666 // shown.
2667 final int mode = mService.mAppOps.startOpNoThrow(mAppOp,
2668 getOwningUid(), getOwningPackage(), true);
2669 if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) {
2670 setAppOpVisibilityLw(false);
2671 }
2672 }
2673
2674 void resetAppOpsState() {
2675 if (mAppOp != OP_NONE && mAppOpVisibility) {
2676 mService.mAppOps.finishOp(mAppOp, getOwningUid(), getOwningPackage());
2677 }
2678 }
2679
2680 void updateAppOpsState() {
2681 if (mAppOp == OP_NONE) {
2682 return;
2683 }
2684 final int uid = getOwningUid();
2685 final String packageName = getOwningPackage();
2686 if (mAppOpVisibility) {
2687 // There is a race between the check and the finish calls but this is fine
2688 // as this would mean we will get another change callback and will reconcile.
2689 int mode = mService.mAppOps.checkOpNoThrow(mAppOp, uid, packageName);
2690 if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) {
2691 mService.mAppOps.finishOp(mAppOp, uid, packageName);
2692 setAppOpVisibilityLw(false);
2693 }
2694 } else {
Svet Ganov522ed242018-03-07 21:40:28 -08002695 final int mode = mService.mAppOps.startOpNoThrow(mAppOp, uid, packageName, true);
Svet Ganovf7b47252018-02-26 11:11:27 -08002696 if (mode == MODE_ALLOWED || mode == MODE_DEFAULT) {
2697 setAppOpVisibilityLw(true);
2698 }
2699 }
2700 }
2701
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002702 public void hidePermanentlyLw() {
2703 if (!mPermanentlyHidden) {
2704 mPermanentlyHidden = true;
2705 hideLw(true, true);
2706 }
2707 }
2708
Jeff Brownc2932a12014-11-20 18:04:05 -08002709 public void pokeDrawLockLw(long timeout) {
2710 if (isVisibleOrAdding()) {
2711 if (mDrawLock == null) {
2712 // We want the tag name to be somewhat stable so that it is easier to correlate
2713 // in wake lock statistics. So in particular, we don't want to include the
2714 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002715 final CharSequence tag = getWindowTag();
chaviw40234662018-02-07 09:37:16 -08002716 mDrawLock = mService.mPowerManager.newWakeLock(DRAW_WAKE_LOCK, "Window:" + tag);
Jeff Brownc2932a12014-11-20 18:04:05 -08002717 mDrawLock.setReferenceCounted(false);
2718 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2719 }
2720 // Each call to acquire resets the timeout.
2721 if (DEBUG_POWER) {
2722 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2723 + mAttrs.packageName);
2724 }
2725 mDrawLock.acquire(timeout);
2726 } else if (DEBUG_POWER) {
2727 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2728 + "owned by " + mAttrs.packageName);
2729 }
2730 }
2731
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002732 @Override
2733 public boolean isAlive() {
2734 return mClient.asBinder().isBinderAlive();
2735 }
2736
Craig Mautnera987d432012-10-11 14:07:58 -07002737 boolean isClosing() {
chaviw4ad54912018-05-30 11:05:44 -07002738 return mAnimatingExit || (mAppToken != null && mAppToken.isClosingOrEnteringPip());
Craig Mautnera987d432012-10-11 14:07:58 -07002739 }
2740
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002741 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2742 animators.add(mWinAnimator);
2743
2744 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002745 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002746 c.addWinAnimatorToList(animators);
2747 }
2748 }
2749
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002750 void sendAppVisibilityToClients() {
2751 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002752
Wale Ogunwale89973222017-04-23 18:39:45 -07002753 final boolean clientHidden = mAppToken.isClientHidden();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002754 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2755 // Don't hide the starting window.
2756 return;
2757 }
2758
Wale Ogunwale89973222017-04-23 18:39:45 -07002759 if (clientHidden) {
2760 // Once we are notifying the client that it's visibility has changed, we need to prevent
2761 // it from destroying child surfaces until the animation has finished. We do this by
2762 // detaching any surface control the client added from the client.
2763 for (int i = mChildren.size() - 1; i >= 0; --i) {
2764 final WindowState c = mChildren.get(i);
2765 c.mWinAnimator.detachChildren();
2766 }
2767
2768 mWinAnimator.detachChildren();
2769 }
2770
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002771 try {
2772 if (DEBUG_VISIBILITY) Slog.v(TAG,
2773 "Setting visibility of " + this + ": " + (!clientHidden));
2774 mClient.dispatchAppVisibility(!clientHidden);
2775 } catch (RemoteException e) {
2776 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002777 }
2778
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002779 void onStartFreezingScreen() {
2780 mAppFreezing = true;
2781 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002782 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002783 c.onStartFreezingScreen();
2784 }
2785 }
2786
2787 boolean onStopFreezingScreen() {
2788 boolean unfrozeWindows = false;
2789 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002790 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002791 unfrozeWindows |= c.onStopFreezingScreen();
2792 }
2793
2794 if (!mAppFreezing) {
2795 return unfrozeWindows;
2796 }
2797
Wale Ogunwale953171d2016-09-30 09:17:30 -07002798 mAppFreezing = false;
2799
Bryce Lee8c3cf382017-07-06 19:47:10 -07002800 if (mHasSurface && !getOrientationChanging()
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002801 && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
2802 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
Bryce Lee8c3cf382017-07-06 19:47:10 -07002803 setOrientationChanging(true);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002804 mService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002805 }
2806 mLastFreezeDuration = 0;
2807 setDisplayLayoutNeeded();
2808 return true;
2809 }
2810
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002811 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2812 boolean destroyedSomething = false;
Jorim Jaggi59f3e922018-01-05 15:40:32 +01002813
2814 // Copying to a different list as multiple children can be removed.
2815 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
2816 for (int i = childWindows.size() - 1; i >= 0; --i) {
2817 final WindowState c = childWindows.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002818 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2819 }
2820
Robert Carrdb2f6e62017-03-01 20:17:58 -08002821 if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) {
2822 return destroyedSomething;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002823 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08002824
2825 if (appStopped || mWindowRemovalAllowed) {
2826 mWinAnimator.destroyPreservedSurfaceLocked();
2827 }
2828
2829 if (mDestroying) {
2830 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2831 + " destroySurfaces: appStopped=" + appStopped
2832 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2833 + " win.mRemoveOnExit=" + mRemoveOnExit);
2834 if (!cleanupOnResume || mRemoveOnExit) {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002835 destroySurfaceUnchecked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08002836 }
2837 if (mRemoveOnExit) {
2838 removeImmediately();
2839 }
2840 if (cleanupOnResume) {
2841 requestUpdateWallpaperIfNeeded();
2842 }
2843 mDestroying = false;
2844 destroyedSomething = true;
2845 }
2846
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002847 return destroyedSomething;
2848 }
Chris Craik3131bde2016-05-06 13:39:08 -07002849
Robert Carr89a28ab2017-04-24 15:33:11 -07002850 // Destroy or save the application surface without checking
2851 // various indicators of whether the client has released the surface.
2852 // This is in general unsafe, and most callers should use {@link #destroySurface}
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002853 void destroySurfaceUnchecked() {
2854 mWinAnimator.destroySurfaceLocked();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002855
Chong Zhang92147042016-05-09 12:47:11 -07002856 // Clear animating flags now, since the surface is now gone. (Note this is true even
2857 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2858 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002859 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002860
Craig Mautner69b08182012-09-05 13:07:13 -07002861 @Override
2862 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002863 final DisplayContent displayContent = getDisplayContent();
2864 if (displayContent == null) {
2865 // Only a window that was on a non-default display can be detached from it.
2866 return false;
2867 }
Winson Chung47a3e652014-05-21 16:03:42 -07002868 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002869 }
2870
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002871 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07002872 mShowToOwnerOnly = showToOwnerOnly;
2873 }
2874
Wale Ogunwaleea92d972016-12-08 07:33:13 -08002875 private boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002876 // Child windows are evaluated based on their parent window.
2877 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002878 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale72919d22016-12-08 18:58:50 -08002879 && win.mAppToken != null && win.mAppToken.mShowForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002880
2881 // All window frames that are fullscreen extend above status bar, but some don't extend
2882 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2883 // bottom right.
2884 if (win.mFrame.left <= win.mDisplayFrame.left
2885 && win.mFrame.top <= win.mDisplayFrame.top
2886 && win.mFrame.right >= win.mStableFrame.right
2887 && win.mFrame.bottom >= win.mStableFrame.bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002888 // Is a fullscreen window, like the clock alarm. Show to everyone.
2889 return false;
2890 }
2891 }
2892
Craig Mautner341220f2012-10-16 15:20:09 -07002893 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01002894 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002895 }
2896
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002897 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2898 outRegion.set(
2899 frame.left + inset.left, frame.top + inset.top,
2900 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002901 }
2902
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002903 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002904 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002905 switch (mTouchableInsets) {
2906 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002907 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002908 outRegion.set(frame);
2909 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002910 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002911 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002912 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002913 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002914 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002915 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002916 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002917 outRegion.set(mGivenTouchableRegion);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002918 outRegion.translate(frame.left, frame.top);
2919 break;
2920 }
2921 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002922 cropRegionToStackBoundsIfNeeded(outRegion);
2923 }
2924
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002925 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002926 final Task task = getTask();
2927 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002928 return;
2929 }
2930
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002931 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002932 if (stack == null) {
2933 return;
2934 }
2935
2936 stack.getDimBounds(mTmpRect);
2937 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002938 }
2939
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002940 /**
2941 * Report a focus change. Must be called with no locks held, and consistently
2942 * from the same serialized thread (such as dispatched from a handler).
2943 */
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07002944 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002945 try {
2946 mClient.windowFocusChanged(focused, inTouchMode);
2947 } catch (RemoteException e) {
2948 }
2949 if (mFocusCallbacks != null) {
2950 final int N = mFocusCallbacks.beginBroadcast();
2951 for (int i=0; i<N; i++) {
2952 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2953 try {
2954 if (focused) {
2955 obs.focusGained(mWindowId.asBinder());
2956 } else {
2957 obs.focusLost(mWindowId.asBinder());
2958 }
2959 } catch (RemoteException e) {
2960 }
2961 }
2962 mFocusCallbacks.finishBroadcast();
2963 }
2964 }
2965
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002966 @Override
2967 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002968 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002969 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002970 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002971
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002972 return super.getConfiguration();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002973 }
2974
Craig Mautnerdf88d732014-01-27 09:21:32 -08002975 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002976 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08002977 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002978 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
2979 + ": " + mCompatFrame);
Bryce Leef858b572017-06-29 14:03:33 -07002980 final MergedConfiguration mergedConfiguration =
2981 new MergedConfiguration(mService.mRoot.getConfiguration(),
2982 getMergedOverrideConfiguration());
2983
Bryce Lee2b17afd2017-09-21 10:38:20 -07002984 setLastReportedMergedConfiguration(mergedConfiguration);
Bryce Leef858b572017-06-29 14:03:33 -07002985
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002986 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002987 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
2988
Craig Mautnerdf88d732014-01-27 09:21:32 -08002989 final Rect frame = mFrame;
2990 final Rect overscanInsets = mLastOverscanInsets;
2991 final Rect contentInsets = mLastContentInsets;
2992 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07002993 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002994 final Rect outsets = mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002995 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Andrii Kulianb2e37802017-01-11 00:36:44 -08002996 final boolean reportOrientation = mReportOrientationChanged;
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002997 final int displayId = getDisplayId();
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01002998 final DisplayCutout displayCutout = mDisplayCutout.getDisplayCutout();
Chet Haase8eb48d22014-09-24 07:31:29 -07002999 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
3000 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08003001 // To prevent deadlock simulate one-way call if win.mClient is a local object.
3002 mService.mH.post(new Runnable() {
3003 @Override
3004 public void run() {
3005 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003006 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003007 stableInsets, outsets, reportDraw, mergedConfiguration,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003008 reportOrientation, displayId, displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003009 } catch (RemoteException e) {
3010 // Not a remote call, RemoteException won't be raised.
3011 }
3012 }
3013 });
3014 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003015 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003016 outsets, reportDraw, mergedConfiguration, reportOrientation, displayId,
3017 displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003018 }
Svetoslav4604abc2014-06-10 18:59:30 -07003019
3020 //TODO (multidisplay): Accessibility supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07003021 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07003022 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07003023 }
3024
Craig Mautnerdf88d732014-01-27 09:21:32 -08003025 mOverscanInsetsChanged = false;
3026 mContentInsetsChanged = false;
3027 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07003028 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003029 mOutsetsChanged = false;
Robert Carr31aa98b2016-07-20 15:29:03 -07003030 mFrameSizeChanged = false;
Adrian Roos5c6b6222017-11-07 17:36:10 +01003031 mDisplayCutoutChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003032 mWinAnimator.mSurfaceResized = false;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003033 mReportOrientationChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003034 } catch (RemoteException e) {
Bryce Lee8c3cf382017-07-06 19:47:10 -07003035 setOrientationChanging(false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003036 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
3037 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08003038 // We are assuming the hosting process is dead or in a zombie state.
3039 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
3040 + ", removing this window.");
3041 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07003042 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003043 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003044 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003045 }
3046
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003047 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08003048 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
3049 // start even if we haven't received the relayout window, so that the client requests
3050 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
3051 // until the window to small size, otherwise the multithread renderer will shift last
3052 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
3053 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003054 boolean resizing = isDragResizing() || isDragResizeChanged();
Wale Ogunwale3382ab12017-07-27 08:55:03 -07003055 if (getWindowConfiguration().useWindowFrameForBackdrop() || !resizing) {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003056 return frame;
3057 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07003058 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003059 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003060 return mTmpRect;
3061 }
3062
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003063 private int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003064 final TaskStack stack = getStack();
3065 if (stack == null) {
3066 return INVALID_STACK_ID;
3067 }
3068 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003069 }
3070
3071 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
3072 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003073 MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId,
3074 DisplayCutout displayCutout)
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003075 throws RemoteException {
Robert Carr09286c92018-02-15 13:52:31 -08003076 final boolean forceRelayout = isDragResizeChanged() || reportOrientation;
Chong Zhangedaf3052016-04-22 15:04:31 -07003077
Jorim Jaggidc249c42015-12-15 14:57:31 -08003078 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003079 reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003080 mPolicy.isNavBarForcedShownLw(this), displayId,
3081 new DisplayCutout.ParcelableWrapper(displayCutout));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003082 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003083 }
3084
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003085 public void registerFocusObserver(IWindowFocusObserver observer) {
3086 synchronized(mService.mWindowMap) {
3087 if (mFocusCallbacks == null) {
3088 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
3089 }
3090 mFocusCallbacks.register(observer);
3091 }
3092 }
3093
3094 public void unregisterFocusObserver(IWindowFocusObserver observer) {
3095 synchronized(mService.mWindowMap) {
3096 if (mFocusCallbacks != null) {
3097 mFocusCallbacks.unregister(observer);
3098 }
3099 }
3100 }
3101
3102 public boolean isFocused() {
3103 synchronized(mService.mWindowMap) {
3104 return mService.mCurrentFocus == this;
3105 }
3106 }
3107
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003108 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07003109 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003110 final Task task = getTask();
3111 return task != null && !task.isFullscreen();
3112 }
3113
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003114 /** Is this window in a container that takes up the entire screen space? */
3115 private boolean inFullscreenContainer() {
Bryce Leef3c6a472017-11-14 14:53:06 -08003116 return mAppToken == null || (mAppToken.matchParentBounds() && !isInMultiWindowMode());
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003117 }
3118
Andrii Kulian283acd22017-08-03 04:03:51 -07003119 /** @return true when the window is in fullscreen task, but has non-fullscreen bounds set. */
3120 boolean isLetterboxedAppWindow() {
Adrian Roos865c70f2018-01-10 17:32:27 +01003121 return !isInMultiWindowMode() && mAppToken != null && !mAppToken.matchParentBounds()
3122 || isLetterboxedForDisplayCutoutLw();
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003123 }
3124
Adrian Roos865c70f2018-01-10 17:32:27 +01003125 @Override
3126 public boolean isLetterboxedForDisplayCutoutLw() {
3127 if (mAppToken == null) {
3128 // Only windows with an AppWindowToken are letterboxed.
3129 return false;
3130 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003131 if (!mParentFrameWasClippedByDisplayCutout) {
3132 // Cutout didn't make a difference, no letterbox
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003133 return false;
3134 }
Adrian Roosfa02da62018-01-15 16:01:18 +01003135 if (mAttrs.layoutInDisplayCutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003136 // Layout in cutout, no letterbox.
3137 return false;
3138 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003139 if (!mAttrs.isFullscreen()) {
3140 // Not filling the parent frame, no letterbox
3141 return false;
Adrian Roosfa02da62018-01-15 16:01:18 +01003142 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003143 // Otherwise we need a letterbox if the layout was smaller than the app window token allowed
3144 // it to be.
3145 return !frameCoversEntireAppTokenBounds();
3146 }
3147
3148 /**
3149 * @return true if this window covers the entire bounds of its app window token
3150 * @throws NullPointerException if there is no app window token for this window
3151 */
3152 private boolean frameCoversEntireAppTokenBounds() {
3153 mTmpRect.set(mAppToken.getBounds());
3154 mTmpRect.intersectUnchecked(mFrame);
3155 return mAppToken.getBounds().equals(mTmpRect);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003156 }
3157
Adrian Roos23df3a32018-03-15 15:41:13 +01003158 @Override
3159 public boolean isLetterboxedOverlappingWith(Rect rect) {
3160 return mAppToken != null && mAppToken.isLetterboxOverlappingWith(rect);
3161 }
3162
Chong Zhang3005e752015-09-18 18:46:28 -07003163 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003164 return mDragResizing != computeDragResizing();
3165 }
3166
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003167 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003168 void setWaitingForDrawnIfResizingChanged() {
3169 if (isDragResizeChanged()) {
3170 mService.mWaitingForDrawn.add(this);
3171 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003172 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003173 }
3174
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003175 /**
3176 * @return Whether we reported a drag resize change to the application or not already.
3177 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003178 private boolean isDragResizingChangeReported() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003179 return mDragResizingChangeReported;
3180 }
3181
3182 /**
3183 * Resets the state whether we reported a drag resize change to the app.
3184 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003185 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003186 void resetDragResizingChangeReported() {
3187 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003188 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003189 }
3190
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003191 int getResizeMode() {
3192 return mResizeMode;
3193 }
3194
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003195 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003196 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003197 if (task == null) {
3198 return false;
3199 }
Tomasz Mikolajewskiaf20b8d2017-11-20 16:11:33 +09003200 if (!inSplitScreenWindowingMode() && !inFreeformWindowingMode()) {
Winson Chung2af04b32017-01-24 16:21:13 -08003201 return false;
3202 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003203 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003204 // Floating windows never enter drag resize mode.
3205 return false;
3206 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003207 if (task.isDragResizing()) {
3208 return true;
3209 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003210
3211 // If the bounds are currently frozen, it means that the layout size that the app sees
3212 // and the bounds we clip this window to might be different. In order to avoid holes, we
3213 // simulate that we are still resizing so the app fills the hole with the resizing
3214 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003215 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003216 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003217 !task.inFreeformWindowingMode() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003218
Chong Zhang3005e752015-09-18 18:46:28 -07003219 }
3220
3221 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003222 final boolean resizing = computeDragResizing();
3223 if (resizing == mDragResizing) {
3224 return;
3225 }
3226 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003227 final Task task = getTask();
3228 if (task != null && task.isDragResizing()) {
3229 mResizeMode = task.getDragResizeMode();
3230 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003231 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003232 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3233 : DRAG_RESIZE_MODE_FREEFORM;
3234 }
Chong Zhang3005e752015-09-18 18:46:28 -07003235 }
3236
3237 boolean isDragResizing() {
3238 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003239 }
3240
Robert Carr2487ce72016-04-07 15:18:45 -07003241 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003242 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3243 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003244 }
3245
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07003246 @CallSuper
3247 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02003248 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003249 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02003250 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003251 writeIdentifierToProto(proto, IDENTIFIER);
3252 proto.write(DISPLAY_ID, getDisplayId());
3253 proto.write(STACK_ID, getStackId());
3254 mAttrs.writeToProto(proto, ATTRIBUTES);
3255 mGivenContentInsets.writeToProto(proto, GIVEN_CONTENT_INSETS);
3256 mFrame.writeToProto(proto, FRAME);
3257 mContainingFrame.writeToProto(proto, CONTAINING_FRAME);
3258 mParentFrame.writeToProto(proto, PARENT_FRAME);
3259 mContentFrame.writeToProto(proto, CONTENT_FRAME);
3260 mContentInsets.writeToProto(proto, CONTENT_INSETS);
3261 mAttrs.surfaceInsets.writeToProto(proto, SURFACE_INSETS);
Jorim Jaggi45be1c4c2017-12-15 18:44:43 +01003262 mSurfacePosition.writeToProto(proto, SURFACE_POSITION);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003263 mWinAnimator.writeToProto(proto, ANIMATOR);
3264 proto.write(ANIMATING_EXIT, mAnimatingExit);
3265 for (int i = 0; i < mChildren.size(); i++) {
Adrian Roos4921ccf2017-09-28 16:54:06 +02003266 mChildren.get(i).writeToProto(proto, CHILD_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003267 }
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003268 proto.write(REQUESTED_WIDTH, mRequestedWidth);
3269 proto.write(REQUESTED_HEIGHT, mRequestedHeight);
3270 proto.write(VIEW_VISIBILITY, mViewVisibility);
3271 proto.write(SYSTEM_UI_VISIBILITY, mSystemUiVisibility);
3272 proto.write(HAS_SURFACE, mHasSurface);
3273 proto.write(IS_READY_FOR_DISPLAY, isReadyForDisplay());
3274 mDisplayFrame.writeToProto(proto, DISPLAY_FRAME);
3275 mOverscanFrame.writeToProto(proto, OVERSCAN_FRAME);
3276 mVisibleFrame.writeToProto(proto, VISIBLE_FRAME);
3277 mDecorFrame.writeToProto(proto, DECOR_FRAME);
3278 mOutsetFrame.writeToProto(proto, OUTSET_FRAME);
3279 mOverscanInsets.writeToProto(proto, OVERSCAN_INSETS);
3280 mVisibleInsets.writeToProto(proto, VISIBLE_INSETS);
3281 mStableInsets.writeToProto(proto, STABLE_INSETS);
3282 mOutsets.writeToProto(proto, OUTSETS);
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01003283 mDisplayCutout.getDisplayCutout().writeToProto(proto, CUTOUT);
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003284 proto.write(REMOVE_ON_EXIT, mRemoveOnExit);
3285 proto.write(DESTROYING, mDestroying);
3286 proto.write(REMOVED, mRemoved);
3287 proto.write(IS_ON_SCREEN, isOnScreen());
3288 proto.write(IS_VISIBLE, isVisible());
Steven Timotiusaf03df62017-07-18 16:56:43 -07003289 proto.end(token);
3290 }
3291
Vishnu Nair9a3e4062018-01-11 08:42:54 -08003292 @Override
3293 public void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003294 final long token = proto.start(fieldId);
3295 proto.write(HASH_CODE, System.identityHashCode(this));
3296 proto.write(USER_ID, UserHandle.getUserId(mOwnerUid));
3297 final CharSequence title = getWindowTag();
3298 if (title != null) {
3299 proto.write(TITLE, title.toString());
3300 }
3301 proto.end(token);
3302 }
3303
Jorim Jaggia5e10572017-11-15 14:36:26 +01003304 @Override
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003305 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003306 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003307 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003308 if (stack != null) {
3309 pw.print(" stackId="); pw.print(stack.mStackId);
3310 }
Craig Mautner59c00972012-07-30 12:10:24 -07003311 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003312 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07003313 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08003314 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
3315 pw.print(" package="); pw.print(mAttrs.packageName);
3316 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Jorim Jaggi484851b2017-09-22 16:03:27 +02003317 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs.toString(prefix));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003318 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
3319 pw.print(" h="); pw.print(mRequestedHeight);
3320 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003321 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
3322 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
3323 pw.print(" h="); pw.println(mLastRequestedHeight);
3324 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003325 if (mIsChildWindow || mLayoutAttached) {
3326 pw.print(prefix); pw.print("mParentWindow="); pw.print(getParentWindow());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003327 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
3328 }
3329 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
3330 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
3331 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
3332 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
3333 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
3334 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003335 if (dumpAll) {
3336 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3337 pw.print(" mSubLayer="); pw.print(mSubLayer);
3338 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautnerc2f9be02012-03-27 17:32:29 -07003339 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
3340 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003341 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003342 if (dumpAll) {
3343 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003344 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003345 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
3346 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Bryce Lee6311c4b2017-07-06 14:09:29 -07003347 pw.print(" mAppDied=");pw.print(mAppDied);
3348 pw.print(prefix); pw.print("drawnStateEvaluated=");
3349 pw.print(getDrawnStateEvaluated());
3350 pw.print(prefix); pw.print("mightAffectAllDrawn=");
Jorim Jaggie7d2b852017-08-28 17:55:15 +02003351 pw.println(mightAffectAllDrawn());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003352 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003353 pw.print(prefix); pw.print("mViewVisibility=0x");
3354 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003355 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
3356 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07003357 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
3358 pw.print(" mSystemUiVisibility=0x");
3359 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003360 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003361 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
Suprabh Shukla69c71422018-04-02 18:39:01 -07003362 || isParentWindowHidden()|| mPermanentlyHidden || mForceHideNonSystemOverlayWindow
3363 || mHiddenWhileSuspended) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003364 pw.print(prefix); pw.print("mPolicyVisibility=");
3365 pw.print(mPolicyVisibility);
3366 pw.print(" mPolicyVisibilityAfterAnim=");
3367 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003368 pw.print(" mAppOpVisibility=");
3369 pw.print(mAppOpVisibility);
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003370 pw.print(" parentHidden="); pw.print(isParentWindowHidden());
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003371 pw.print(" mPermanentlyHidden="); pw.print(mPermanentlyHidden);
Suprabh Shukla69c71422018-04-02 18:39:01 -07003372 pw.print(" mHiddenWhileSuspended="); pw.print(mHiddenWhileSuspended);
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003373 pw.print(" mForceHideNonSystemOverlayWindow="); pw.println(
3374 mForceHideNonSystemOverlayWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003375 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003376 if (!mRelayoutCalled || mLayoutNeeded) {
3377 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
3378 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003379 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003380 if (dumpAll) {
3381 pw.print(prefix); pw.print("mGivenContentInsets=");
3382 mGivenContentInsets.printShortString(pw);
3383 pw.print(" mGivenVisibleInsets=");
3384 mGivenVisibleInsets.printShortString(pw);
3385 pw.println();
3386 if (mTouchableInsets != 0 || mGivenInsetsPending) {
3387 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
3388 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003389 Region region = new Region();
3390 getTouchableRegion(region);
3391 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003392 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003393 pw.print(prefix); pw.print("mFullConfiguration="); pw.println(getConfiguration());
3394 pw.print(prefix); pw.print("mLastReportedConfiguration=");
Bryce Lee2b17afd2017-09-21 10:38:20 -07003395 pw.println(getLastReportedConfiguration());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003396 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07003397 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Chong Zhanga8975bd2016-01-28 17:13:47 -08003398 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08003399 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003400 if (dumpAll) {
3401 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
3402 pw.print(" last="); mLastFrame.printShortString(pw);
3403 pw.println();
3404 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003405 if (mEnforceSizeCompat) {
3406 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003407 pw.println();
3408 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003409 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003410 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003411 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003412 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003413 pw.println();
3414 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
3415 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003416 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003417 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003418 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003419 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04003420 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
3421 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003422 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
3423 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003424 pw.print(prefix); pw.print("Cur insets: overscan=");
3425 mOverscanInsets.printShortString(pw);
3426 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003427 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003428 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003429 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003430 pw.print(" outsets="); mOutsets.printShortString(pw);
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01003431 pw.print(" cutout=" + mDisplayCutout.getDisplayCutout());
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003432 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003433 pw.print(prefix); pw.print("Lst insets: overscan=");
3434 mLastOverscanInsets.printShortString(pw);
3435 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003436 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003437 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003438 pw.print(" physical="); mLastOutsets.printShortString(pw);
3439 pw.print(" outset="); mLastOutsets.printShortString(pw);
Adrian Roos5c6b6222017-11-07 17:36:10 +01003440 pw.print(" cutout=" + mLastDisplayCutout);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003441 pw.println();
3442 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01003443 super.dump(pw, prefix, dumpAll);
Dianne Hackborn529e7442012-11-01 14:22:28 -07003444 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
3445 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003446 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
3447 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003448 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
3449 pw.print(" mDestroying="); pw.print(mDestroying);
3450 pw.print(" mRemoved="); pw.println(mRemoved);
3451 }
chaviw40234662018-02-07 09:37:16 -08003452 if (getOrientationChanging() || mAppFreezing || mReportOrientationChanged) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003453 pw.print(prefix); pw.print("mOrientationChanging=");
3454 pw.print(mOrientationChanging);
Bryce Lee8c3cf382017-07-06 19:47:10 -07003455 pw.print(" configOrientationChanging=");
Bryce Lee2b17afd2017-09-21 10:38:20 -07003456 pw.print(getLastReportedConfiguration().orientation
Bryce Lee8c3cf382017-07-06 19:47:10 -07003457 != getConfiguration().orientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003458 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
Andrii Kulianb2e37802017-01-11 00:36:44 -08003459 pw.print(" mReportOrientationChanged="); pw.println(mReportOrientationChanged);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003460 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003461 if (mLastFreezeDuration != 0) {
3462 pw.print(prefix); pw.print("mLastFreezeDuration=");
3463 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
3464 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003465 if (mHScale != 1 || mVScale != 1) {
3466 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
3467 pw.print(" mVScale="); pw.println(mVScale);
3468 }
3469 if (mWallpaperX != -1 || mWallpaperY != -1) {
3470 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
3471 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
3472 }
3473 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
3474 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
3475 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
3476 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003477 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3478 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
3479 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
3480 pw.print(mWallpaperDisplayOffsetX);
3481 pw.print(" mWallpaperDisplayOffsetY=");
3482 pw.println(mWallpaperDisplayOffsetY);
3483 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003484 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07003485 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003486 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003487 if (isDragResizing()) {
3488 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
3489 }
3490 if (computeDragResizing()) {
3491 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
3492 }
Bryce Lee6311c4b2017-07-06 14:09:29 -07003493 pw.print(prefix); pw.println("isOnScreen=" + isOnScreen());
3494 pw.print(prefix); pw.println("isVisible=" + isVisible());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003495 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003496
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003497 @Override
3498 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003499 return Integer.toHexString(System.identityHashCode(this))
Jorim Jaggia5e10572017-11-15 14:36:26 +01003500 + " " + getWindowTag();
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003501 }
3502
Robert Carra1eb4392015-12-10 12:43:51 -08003503 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003504 CharSequence tag = mAttrs.getTitle();
3505 if (tag == null || tag.length() <= 0) {
3506 tag = mAttrs.packageName;
3507 }
3508 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003509 }
3510
3511 @Override
3512 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003513 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003514 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003515 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003516 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003517 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003518 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003519 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003520 }
3521 return mStringNameCache;
3522 }
Robert Carr58f29132015-10-29 14:19:05 -07003523
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003524 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003525 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003526 clipRect.left = (int) (clipRect.left / mHScale);
3527 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003528 }
3529 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003530 clipRect.top = (int) (clipRect.top / mVScale);
3531 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003532 }
3533 }
Robert Carr31e28482015-12-02 16:53:18 -08003534
Jorim Jaggif5834272016-04-04 20:25:41 -07003535 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
3536 final int pw = containingFrame.width();
3537 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003538 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003539 final boolean inNonFullscreenContainer = !inFullscreenContainer();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003540 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3541
3542 // We need to fit it to the display if either
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003543 // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen
3544 // for the taskless windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003545 // 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 -07003546 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on
3547 // screen, but SurfaceViews want to be always at a specific location so we don't fit it to
3548 // the display.
3549 final boolean fitToDisplay = (task == null || !inNonFullscreenContainer)
Robert Carr6f44db12016-07-21 14:54:43 -07003550 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003551 float x, y;
3552 int w,h;
3553
3554 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3555 if (mAttrs.width < 0) {
3556 w = pw;
3557 } else if (mEnforceSizeCompat) {
3558 w = (int)(mAttrs.width * mGlobalScale + .5f);
3559 } else {
3560 w = mAttrs.width;
3561 }
3562 if (mAttrs.height < 0) {
3563 h = ph;
3564 } else if (mEnforceSizeCompat) {
3565 h = (int)(mAttrs.height * mGlobalScale + .5f);
3566 } else {
3567 h = mAttrs.height;
3568 }
3569 } else {
3570 if (mAttrs.width == MATCH_PARENT) {
3571 w = pw;
3572 } else if (mEnforceSizeCompat) {
3573 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3574 } else {
3575 w = mRequestedWidth;
3576 }
3577 if (mAttrs.height == MATCH_PARENT) {
3578 h = ph;
3579 } else if (mEnforceSizeCompat) {
3580 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3581 } else {
3582 h = mRequestedHeight;
3583 }
3584 }
3585
3586 if (mEnforceSizeCompat) {
3587 x = mAttrs.x * mGlobalScale;
3588 y = mAttrs.y * mGlobalScale;
3589 } else {
3590 x = mAttrs.x;
3591 y = mAttrs.y;
3592 }
3593
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003594 if (inNonFullscreenContainer && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003595 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003596 // required by {@link Gravity#apply} call.
3597 w = Math.min(w, pw);
3598 h = Math.min(h, ph);
3599 }
3600
3601 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003602 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003603 (int) (x + mAttrs.horizontalMargin * pw),
3604 (int) (y + mAttrs.verticalMargin * ph), mFrame);
3605
3606 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003607 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003608 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003609 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003610
3611 // We need to make sure we update the CompatFrame as it is used for
3612 // cropping decisions, etc, on systems where we lack a decor layer.
3613 mCompatFrame.set(mFrame);
3614 if (mEnforceSizeCompat) {
3615 // See comparable block in computeFrameLw.
3616 mCompatFrame.scale(mInvGlobalScale);
3617 }
Robert Carr31e28482015-12-02 16:53:18 -08003618 }
Robert Carr51a1b872015-12-08 14:03:13 -08003619
3620 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003621 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003622 }
3623
Robert Carrf3b72c72016-03-21 18:16:39 -07003624 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003625 return mIsChildWindow
3626 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003627 }
3628
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003629 /**
3630 * Returns true if any window added by an application process that if of type
3631 * {@link android.view.WindowManager.LayoutParams#TYPE_TOAST} or that requires that requires
3632 * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when
3633 * this window is visible.
3634 */
3635 boolean hideNonSystemOverlayWindowsWhenVisible() {
3636 return (mAttrs.privateFlags & PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != 0
3637 && mSession.mCanHideNonSystemOverlayWindows;
3638 }
3639
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003640 /** Returns the parent window if this is a child of another window, else null. */
3641 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003642 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3643 // WindowContainer that isn't a WindowState.
3644 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003645 }
3646
3647 /** Returns the topmost parent window if this is a child of another window, else this. */
3648 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003649 WindowState current = this;
3650 WindowState topParent = current;
3651 while (current != null && current.mIsChildWindow) {
3652 current = current.getParentWindow();
3653 // Parent window can be null if the child is detached from it's parent already, but
3654 // someone still has a reference to access it. So, we return the top parent value we
3655 // already have instead of null.
3656 if (current != null) {
3657 topParent = current;
3658 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003659 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003660 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003661 }
3662
Wale Ogunwale9d147902016-07-16 11:58:55 -07003663 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003664 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003665 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003666 }
3667
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003668 void setWillReplaceWindow(boolean animate) {
3669 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003670 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003671 c.setWillReplaceWindow(animate);
3672 }
3673
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003674 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3675 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3676 // We don't set replacing on starting windows since they are added by window manager and
3677 // not the client so won't be replaced by the client.
3678 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003679 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003680
3681 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003682 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003683 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003684 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003685
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003686 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003687 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003688 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003689 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003690
3691 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003692 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003693 c.clearWillReplaceWindow();
3694 }
3695 }
3696
3697 boolean waitingForReplacement() {
3698 if (mWillReplaceWindow) {
3699 return true;
3700 }
3701
3702 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003703 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003704 if (c.waitingForReplacement()) {
3705 return true;
3706 }
3707 }
3708 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003709 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003710
Chong Zhang4d7369a2016-04-25 16:09:14 -07003711 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003712 final DisplayContent dc = getDisplayContent();
3713 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3714 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3715 dc.setLayoutNeeded();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003716 mService.mWindowPlacerLocked.requestTraversal();
3717 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003718
3719 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003720 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003721 c.requestUpdateWallpaperIfNeeded();
3722 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003723 }
3724
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003725 float translateToWindowX(float x) {
3726 float winX = x - mFrame.left;
3727 if (mEnforceSizeCompat) {
3728 winX *= mGlobalScale;
3729 }
3730 return winX;
3731 }
3732
3733 float translateToWindowY(float y) {
3734 float winY = y - mFrame.top;
3735 if (mEnforceSizeCompat) {
3736 winY *= mGlobalScale;
3737 }
3738 return winY;
3739 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003740
3741 // During activity relaunch due to resize, we sometimes use window replacement
3742 // for only child windows (as the main window is handled by window preservation)
3743 // and the big surface.
3744 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003745 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3746 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3747 // we also want to replace them at such phases, as they won't be covered by window
3748 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003749 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003750 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003751 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003752 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003753
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003754 void setWillReplaceChildWindows() {
3755 if (shouldBeReplacedWithChildren()) {
3756 setWillReplaceWindow(false /* animate */);
3757 }
3758 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003759 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003760 c.setWillReplaceChildWindows();
3761 }
3762 }
3763
3764 WindowState getReplacingWindow() {
3765 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3766 return this;
3767 }
3768 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003769 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003770 final WindowState replacing = c.getReplacingWindow();
3771 if (replacing != null) {
3772 return replacing;
3773 }
3774 }
3775 return null;
3776 }
3777
Jorim Jaggife762342016-10-13 14:33:27 +02003778 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07003779 public int getRotationAnimationHint() {
3780 if (mAppToken != null) {
3781 return mAppToken.mRotationAnimationHint;
3782 } else {
3783 return -1;
3784 }
3785 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003786
Jorim Jaggife762342016-10-13 14:33:27 +02003787 @Override
3788 public boolean isInputMethodWindow() {
3789 return mIsImWindow;
3790 }
3791
Wale Ogunwale9d147902016-07-16 11:58:55 -07003792 // This must be called while inside a transaction.
3793 boolean performShowLocked() {
3794 if (isHiddenFromUserLocked()) {
3795 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3796 hideLw(false);
3797 return false;
3798 }
3799
3800 logPerformShow("performShow on ");
3801
Jorim Jaggia50da602016-12-29 11:51:42 +01003802 final int drawState = mWinAnimator.mDrawState;
3803 if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW)
3804 && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3805 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3806 }
3807
Jorim Jaggib0d27342016-11-01 16:10:42 -07003808 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003809 return false;
3810 }
3811
3812 logPerformShow("Showing ");
3813
3814 mService.enableScreenIfNeededLocked();
3815 mWinAnimator.applyEnterAnimationLocked();
3816
3817 // Force the show in the next prepareSurfaceLocked() call.
3818 mWinAnimator.mLastAlpha = -1;
Robert Carre13b58e2017-08-31 14:50:44 -07003819 if (DEBUG_ANIM) Slog.v(TAG,
Wale Ogunwale9d147902016-07-16 11:58:55 -07003820 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3821 mWinAnimator.mDrawState = HAS_DRAWN;
3822 mService.scheduleAnimationLocked();
3823
3824 if (mHidden) {
3825 mHidden = false;
3826 final DisplayContent displayContent = getDisplayContent();
3827
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003828 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003829 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003830 if (c.mWinAnimator.mSurfaceController != null) {
3831 c.performShowLocked();
3832 // It hadn't been shown, which means layout not performed on it, so now we
3833 // want to make sure to do a layout. If called from within the transaction
3834 // loop, this will cause it to restart with a new layout.
3835 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003836 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003837 }
3838 }
3839 }
3840 }
3841
Wale Ogunwale9d147902016-07-16 11:58:55 -07003842 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003843 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003844 }
3845
3846 return true;
3847 }
3848
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003849 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003850 if (DEBUG_VISIBILITY
Jorim Jaggie4b0f282017-05-17 15:10:29 +02003851 || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003852 Slog.v(TAG, prefix + this
3853 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07003854 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003855 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3856 + " during animation: policyVis=" + mPolicyVisibility
3857 + " parentHidden=" + isParentWindowHidden()
3858 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003859 + (mAppToken != null && mAppToken.hiddenRequested)
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003860 + " tok.hidden=" + (mAppToken != null && mAppToken.isHidden())
Jorim Jaggia5e10572017-11-15 14:36:26 +01003861 + " animationSet=" + mWinAnimator.isAnimationSet()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003862 + " tok animating="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003863 + (mAppToken != null && mAppToken.isSelfAnimating())
Wale Ogunwale9d147902016-07-16 11:58:55 -07003864 + " Callers=" + Debug.getCallers(4));
3865 }
3866 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003867
3868 WindowInfo getWindowInfo() {
3869 WindowInfo windowInfo = WindowInfo.obtain();
3870 windowInfo.type = mAttrs.type;
3871 windowInfo.layer = mLayer;
3872 windowInfo.token = mClient.asBinder();
Phil Weaver5dc3ebc2017-08-16 13:04:20 -07003873 if (mAppToken != null) {
3874 windowInfo.activityToken = mAppToken.appToken.asBinder();
3875 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003876 windowInfo.title = mAttrs.accessibilityTitle;
Phil Weaverbb2f28a2017-12-22 09:44:28 -08003877 // Panel windows have no public way to set the a11y title directly. Use the
3878 // regular title as a fallback.
Phil Weaver568cf662018-04-24 17:09:26 -07003879 final boolean isPanelWindow = (mAttrs.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW)
3880 && (mAttrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW);
3881 // Accessibility overlays should have titles that work for accessibility, and can't set
3882 // the a11y title themselves.
3883 final boolean isAccessibilityOverlay =
3884 windowInfo.type == WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
3885 if (TextUtils.isEmpty(windowInfo.title) && (isPanelWindow || isAccessibilityOverlay)) {
Phil Weaverbb2f28a2017-12-22 09:44:28 -08003886 windowInfo.title = mAttrs.getTitle();
3887 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003888 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3889 windowInfo.focused = isFocused();
Phil Weaverf00cd142017-03-03 13:44:00 -08003890 Task task = getTask();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003891 windowInfo.inPictureInPicture = (task != null) && task.inPinnedWindowingMode();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003892
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003893 if (mIsChildWindow) {
3894 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003895 }
3896
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003897 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003898 if (childCount > 0) {
3899 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003900 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003901 }
3902 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003903 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003904 windowInfo.childTokens.add(child.mClient.asBinder());
3905 }
3906 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003907 return windowInfo;
3908 }
3909
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003910 int getHighestAnimLayer() {
3911 int highest = mWinAnimator.mAnimLayer;
3912 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003913 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003914 final int childLayer = c.getHighestAnimLayer();
3915 if (childLayer > highest) {
3916 highest = childLayer;
3917 }
3918 }
3919 return highest;
3920 }
3921
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003922 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003923 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003924 if (mChildren.isEmpty()) {
3925 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003926 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003927 }
3928
3929 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003930 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003931 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003932 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003933 }
3934 }
3935
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003936 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003937 // We want to consume the negative sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003938 // below the parent, then this window (the parent), and then the positive sublayer children
3939 // because they need to appear above the parent.
3940 int i = 0;
3941 final int count = mChildren.size();
3942 WindowState child = mChildren.get(i);
3943
3944 while (i < count && child.mSubLayer < 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003945 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003946 return true;
3947 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003948 i++;
3949 if (i >= count) {
3950 break;
3951 }
3952 child = mChildren.get(i);
3953 }
3954
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003955 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003956 return true;
3957 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003958
3959 while (i < count) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003960 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003961 return true;
3962 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003963 i++;
3964 if (i >= count) {
3965 break;
3966 }
3967 child = mChildren.get(i);
3968 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003969
3970 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003971 }
3972
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003973 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003974 // We want to consume the positive sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003975 // above the parent, then this window (the parent), and then the negative sublayer children
3976 // because they need to appear above the parent.
3977 int i = mChildren.size() - 1;
3978 WindowState child = mChildren.get(i);
3979
3980 while (i >= 0 && child.mSubLayer >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003981 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003982 return true;
3983 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003984 --i;
3985 if (i < 0) {
3986 break;
3987 }
3988 child = mChildren.get(i);
3989 }
3990
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003991 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003992 return true;
3993 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003994
3995 while (i >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003996 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003997 return true;
3998 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003999 --i;
4000 if (i < 0) {
4001 break;
4002 }
4003 child = mChildren.get(i);
4004 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004005
4006 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004007 }
4008
Robert Carr9785cf32018-04-25 15:06:07 -07004009 private boolean applyImeWindowsIfNeeded(ToBooleanFunction<WindowState> callback,
4010 boolean traverseTopToBottom) {
4011 // If this window is the current IME target, so we need to process the IME windows
4012 // directly above it. The exception is if we are in split screen
4013 // in which case we process the IME at the DisplayContent level to
4014 // ensure it is above the docked divider.
4015 if (isInputMethodTarget() && !inSplitScreenWindowingMode()) {
4016 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
4017 return true;
4018 }
4019 }
4020 return false;
4021 }
4022
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004023 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
4024 boolean traverseTopToBottom) {
4025 if (traverseTopToBottom) {
Robert Carr9785cf32018-04-25 15:06:07 -07004026 if (applyImeWindowsIfNeeded(callback, traverseTopToBottom)
4027 || callback.apply(this)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004028 return true;
4029 }
4030 } else {
Robert Carr9785cf32018-04-25 15:06:07 -07004031 if (callback.apply(this)
4032 || applyImeWindowsIfNeeded(callback, traverseTopToBottom)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004033 return true;
4034 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004035 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004036 return false;
4037 }
4038
Wale Ogunwaled1880962016-11-08 10:31:59 -08004039 WindowState getWindow(Predicate<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004040 if (mChildren.isEmpty()) {
4041 return callback.test(this) ? this : null;
4042 }
4043
4044 // We want to consume the positive sublayer children first because they need to appear
4045 // above the parent, then this window (the parent), and then the negative sublayer children
4046 // because they need to appear above the parent.
4047 int i = mChildren.size() - 1;
4048 WindowState child = mChildren.get(i);
4049
4050 while (i >= 0 && child.mSubLayer >= 0) {
4051 if (callback.test(child)) {
4052 return child;
4053 }
4054 --i;
4055 if (i < 0) {
4056 break;
4057 }
4058 child = mChildren.get(i);
4059 }
4060
Wale Ogunwaled1880962016-11-08 10:31:59 -08004061 if (callback.test(this)) {
4062 return this;
4063 }
Wale Ogunwale34247952017-02-19 11:57:53 -08004064
4065 while (i >= 0) {
4066 if (callback.test(child)) {
4067 return child;
4068 }
4069 --i;
4070 if (i < 0) {
4071 break;
4072 }
4073 child = mChildren.get(i);
4074 }
4075
4076 return null;
Wale Ogunwaled1880962016-11-08 10:31:59 -08004077 }
4078
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01004079 /**
4080 * @return True if we our one of our ancestors has {@link #mAnimatingExit} set to true, false
4081 * otherwise.
4082 */
4083 @VisibleForTesting
4084 boolean isSelfOrAncestorWindowAnimatingExit() {
4085 WindowState window = this;
4086 do {
4087 if (window.mAnimatingExit) {
4088 return true;
4089 }
4090 window = window.getParentWindow();
4091 } while (window != null);
4092 return false;
4093 }
4094
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004095 void onExitAnimationDone() {
4096 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
4097 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
Jorim Jaggia5e10572017-11-15 14:36:26 +01004098 + " selfAnimating=" + isSelfAnimating());
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004099
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004100 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004101 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +01004102 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004103 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004104 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004105 }
4106 }
4107
4108 if (mWinAnimator.mEnteringAnimation) {
4109 mWinAnimator.mEnteringAnimation = false;
4110 mService.requestTraversal();
4111 // System windows don't have an activity and an app token as a result, but need a way
4112 // to be informed about their entrance animation end.
4113 if (mAppToken == null) {
4114 try {
4115 mClient.dispatchWindowShown();
4116 } catch (RemoteException e) {
4117 }
4118 }
4119 }
4120
Jorim Jaggia5e10572017-11-15 14:36:26 +01004121 if (isSelfAnimating()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004122 return;
4123 }
4124
Jorim Jaggia5e10572017-11-15 14:36:26 +01004125 //TODO (multidisplay): Accessibility is supported only for the default display.
4126 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
4127 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
4128 }
4129
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01004130 if (!isSelfOrAncestorWindowAnimatingExit()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004131 return;
4132 }
4133
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07004134 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004135 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
4136
4137 mDestroying = true;
4138
4139 final boolean hasSurface = mWinAnimator.hasSurface();
Jorim Jaggi50575902018-04-10 17:49:30 +02004140
4141 // Use pendingTransaction here so hide is done the same transaction as the other
4142 // animations when exiting
4143 mWinAnimator.hide(getPendingTransaction(), "onExitAnimationDone");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004144
4145 // If we have an app token, we ask it to destroy the surface for us, so that it can take
4146 // care to ensure the activity has actually stopped and the surface is not still in use.
4147 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
4148 // transaction.
4149 if (mAppToken != null) {
4150 mAppToken.destroySurfaces();
4151 } else {
4152 if (hasSurface) {
4153 mService.mDestroySurface.add(this);
4154 }
4155 if (mRemoveOnExit) {
4156 mService.mPendingRemove.add(this);
4157 mRemoveOnExit = false;
4158 }
4159 }
4160 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07004161 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004162 }
Dan Willemsen117197f2016-07-30 13:02:59 -07004163
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004164 boolean clearAnimatingFlags() {
4165 boolean didSomething = false;
4166 // We don't want to clear it out for windows that get replaced, because the
4167 // animation depends on the flag to remove the replaced window.
4168 //
4169 // We also don't clear the mAnimatingExit flag for windows which have the
4170 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4171 // by the client. We should let animation proceed and not clear this flag or
4172 // they won't eventually be removed by WindowStateAnimator#finishExit.
4173 if (!mWillReplaceWindow && !mRemoveOnExit) {
4174 // Clear mAnimating flag together with mAnimatingExit. When animation
4175 // changes from exiting to entering, we need to clear this flag until the
4176 // new animation gets applied, so that isAnimationStarting() becomes true
4177 // until then.
4178 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4179 // placement for this window during this period, one or more frame will
4180 // show up with wrong position or scale.
4181 if (mAnimatingExit) {
4182 mAnimatingExit = false;
4183 didSomething = true;
4184 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004185 if (mDestroying) {
4186 mDestroying = false;
4187 mService.mDestroySurface.remove(this);
4188 didSomething = true;
4189 }
4190 }
4191
4192 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004193 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004194 }
4195
4196 return didSomething;
4197 }
4198
Winson4b4ba902016-07-27 19:45:52 -07004199 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004200 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004201 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004202
4203 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004204 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004205 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004206 c.hideWallpaperWindow(wasDeferred, reason);
4207 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004208 if (!mWinAnimator.mLastHidden || wasDeferred) {
4209 mWinAnimator.hide(reason);
4210 dispatchWallpaperVisibility(false);
4211 final DisplayContent displayContent = getDisplayContent();
4212 if (displayContent != null) {
4213 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
4214 }
4215 }
4216 }
4217
4218 /**
4219 * Check wallpaper window for visibility change and notify window if so.
4220 * @param visible Current visibility.
4221 */
4222 void dispatchWallpaperVisibility(final boolean visible) {
4223 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07004224 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004225
4226 // Only send notification if the visibility actually changed and we are not trying to hide
4227 // the wallpaper when we are deferring hiding of the wallpaper.
4228 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4229 mWallpaperVisible = visible;
4230 try {
4231 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4232 "Updating vis of wallpaper " + this
4233 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4234 mClient.dispatchAppVisibility(visible);
4235 } catch (RemoteException e) {
4236 }
4237 }
4238 }
4239
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004240 boolean hasVisibleNotDrawnWallpaper() {
4241 if (mWallpaperVisible && !isDrawnLw()) {
4242 return true;
4243 }
4244 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004245 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004246 if (c.hasVisibleNotDrawnWallpaper()) {
4247 return true;
4248 }
4249 }
4250 return false;
4251 }
4252
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004253 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4254 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004255 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004256 c.updateReportedVisibility(results);
4257 }
4258
4259 if (mAppFreezing || mViewVisibility != View.VISIBLE
4260 || mAttrs.type == TYPE_APPLICATION_STARTING
4261 || mDestroying) {
4262 return;
4263 }
4264 if (DEBUG_VISIBILITY) {
4265 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
4266 + ", isAnimationSet=" + mWinAnimator.isAnimationSet());
4267 if (!isDrawnLw()) {
4268 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4269 + " pv=" + mPolicyVisibility
4270 + " mDrawState=" + mWinAnimator.mDrawState
4271 + " ph=" + isParentWindowHidden()
4272 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
Jorim Jaggia5e10572017-11-15 14:36:26 +01004273 + " a=" + mWinAnimator.isAnimationSet());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004274 }
4275 }
4276
4277 results.numInteresting++;
4278 if (isDrawnLw()) {
4279 results.numDrawn++;
4280 if (!mWinAnimator.isAnimationSet()) {
4281 results.numVisible++;
4282 }
4283 results.nowGone = false;
4284 } else if (mWinAnimator.isAnimationSet()) {
4285 results.nowGone = false;
4286 }
4287 }
4288
Robert Carr683e05d2018-04-18 15:11:04 -07004289 private boolean skipDecorCrop() {
4290 // The decor frame is used to specify the region not covered by the system
4291 // decorations (nav bar, status bar). In case this is empty, for example with
4292 // FLAG_TRANSLUCENT_NAVIGATION, we don't need to do any cropping.
4293 if (mDecorFrame.isEmpty()) {
4294 return true;
4295 }
4296
4297 // But if we have a frame, and are an application window, then we must be cropped.
4298 if (mAppToken != null) {
4299 return false;
4300 }
4301
4302 // For non application windows, we may be allowed to extend over the decor bars
4303 // depending on our type and permissions assosciated with our token.
4304 return mToken.canLayerAboveSystemBars();
4305 }
4306
Robert Carrfbbde852016-10-18 11:02:28 -07004307 /**
4308 * Calculate the window crop according to system decor policy. In general this is
4309 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4310 * special cases. This rectangle is in screen space.
4311 */
4312 void calculatePolicyCrop(Rect policyCrop) {
4313 final DisplayContent displayContent = getDisplayContent();
4314 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
4315
4316 if (!isDefaultDisplay()) {
4317 // On a different display there is no system decor. Crop the window
4318 // by the screen boundaries.
4319 // TODO(multi-display)
4320 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4321 policyCrop.intersect(-mCompatFrame.left, -mCompatFrame.top,
4322 displayInfo.logicalWidth - mCompatFrame.left,
4323 displayInfo.logicalHeight - mCompatFrame.top);
Robert Carr683e05d2018-04-18 15:11:04 -07004324 } else if (skipDecorCrop()) {
Robert Carrfbbde852016-10-18 11:02:28 -07004325 // Windows without policy decor aren't cropped.
4326 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4327 } else {
4328 // Crop to the system decor specified by policy.
4329 calculateSystemDecorRect(policyCrop);
4330 }
4331 }
4332
4333 /**
4334 * The system decor rect is the region of the window which is not covered
4335 * by system decorations.
4336 */
4337 private void calculateSystemDecorRect(Rect systemDecorRect) {
4338 final Rect decorRect = mDecorFrame;
4339 final int width = mFrame.width();
4340 final int height = mFrame.height();
4341
Robert Carr217e7cc2018-01-31 18:08:39 -08004342 final int left = mFrame.left;
4343 final int top = mFrame.top;
Robert Carrfbbde852016-10-18 11:02:28 -07004344
4345 // Initialize the decor rect to the entire frame.
4346 if (isDockedResizing()) {
4347 // If we are resizing with the divider, the task bounds might be smaller than the
4348 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4349 // want in this case in order to avoid holes.
4350 //
4351 // We take care to not shrink the width, for surfaces which are larger than
4352 // the display region. Of course this area will not eventually be visible
4353 // but if we truncate the width now, we will calculate incorrectly
4354 // when adjusting to the stack bounds.
4355 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4356 systemDecorRect.set(0, 0,
4357 Math.max(width, displayInfo.logicalWidth),
4358 Math.max(height, displayInfo.logicalHeight));
4359 } else {
4360 systemDecorRect.set(0, 0, width, height);
4361 }
4362
4363 // If a freeform window is animating from a position where it would be cutoff, it would be
4364 // cutoff during the animation. We don't want that, so for the duration of the animation
4365 // we ignore the decor cropping and depend on layering to position windows correctly.
chaviw95136622018-04-09 15:20:06 -07004366
4367 // We also ignore cropping when the window is currently being drag resized in split screen
4368 // to prevent issues with the crop for screenshot.
4369 final boolean cropToDecor =
4370 !(inFreeformWindowingMode() && isAnimatingLw()) && !isDockedResizing();
Robert Carrfbbde852016-10-18 11:02:28 -07004371 if (cropToDecor) {
4372 // Intersect with the decor rect, offsetted by window position.
4373 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
4374 decorRect.right - left, decorRect.bottom - top);
4375 }
4376
4377 // If size compatibility is being applied to the window, the
4378 // surface is scaled relative to the screen. Also apply this
4379 // scaling to the crop rect. We aren't using the standard rect
4380 // scale function because we want to round things to make the crop
4381 // always round to a larger rect to ensure we don't crop too
4382 // much and hide part of the window that should be seen.
4383 if (mEnforceSizeCompat && mInvGlobalScale != 1.0f) {
4384 final float scale = mInvGlobalScale;
4385 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
4386 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
4387 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
4388 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
4389 }
4390
4391 }
4392
4393 /**
4394 * Expand the given rectangle by this windows surface insets. This
4395 * takes you from the 'window size' to the 'surface size'.
4396 * The surface insets are positive in each direction, so we inset by
4397 * the inverse.
4398 */
4399 void expandForSurfaceInsets(Rect r) {
4400 r.inset(-mAttrs.surfaceInsets.left,
4401 -mAttrs.surfaceInsets.top,
4402 -mAttrs.surfaceInsets.right,
4403 -mAttrs.surfaceInsets.bottom);
4404 }
4405
Robert Carrc91d1c32017-02-15 19:37:46 -08004406 boolean surfaceInsetsChanging() {
4407 return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets);
4408 }
4409
Bryce Leef858b572017-06-29 14:03:33 -07004410 int relayoutVisibleWindow(int result, int attrChanges, int oldVisibility) {
Robert Carrecc06b32017-04-18 14:25:10 -07004411 final boolean wasVisible = isVisibleLw();
4412
4413 result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0;
Robert Carr7b3d11d2018-03-15 14:34:45 -07004414
Robert Carrc91d1c32017-02-15 19:37:46 -08004415 if (mAnimatingExit) {
4416 Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit="
4417 + mRemoveOnExit + ", mDestroying=" + mDestroying);
4418
4419 mWinAnimator.cancelExitAnimationForNextAnimationLocked();
4420 mAnimatingExit = false;
4421 }
4422 if (mDestroying) {
4423 mDestroying = false;
4424 mService.mDestroySurface.remove(this);
4425 }
4426 if (oldVisibility == View.GONE) {
4427 mWinAnimator.mEnterAnimationPending = true;
4428 }
4429
Andrii Kulian8ee72852017-03-10 10:36:45 -08004430 mLastVisibleLayoutRotation = getDisplayContent().getRotation();
Robert Carrc91d1c32017-02-15 19:37:46 -08004431
4432 mWinAnimator.mEnteringAnimation = true;
Bryce Leeae73ba42017-05-05 09:58:25 -07004433
Bryce Leef858b572017-06-29 14:03:33 -07004434 prepareWindowToDisplayDuringRelayout(wasVisible);
Bryce Leeae73ba42017-05-05 09:58:25 -07004435
Robert Carrc91d1c32017-02-15 19:37:46 -08004436 if ((attrChanges & FORMAT_CHANGED) != 0) {
4437 // If the format can't be changed in place, preserve the old surface until the app draws
4438 // on the new one. This prevents blinking when we change elevation of freeform and
4439 // pinned windows.
4440 if (!mWinAnimator.tryChangeFormatInPlaceLocked()) {
4441 mWinAnimator.preserveSurfaceLocked();
4442 result |= RELAYOUT_RES_SURFACE_CHANGED
4443 | RELAYOUT_RES_FIRST_TIME;
4444 }
4445 }
4446
4447 // When we change the Surface size, in scenarios which may require changing
4448 // the surface position in sync with the resize, we use a preserved surface
4449 // so we can freeze it while waiting for the client to report draw on the newly
Robert Carrc6d5af52018-02-26 17:46:00 -08004450 // sized surface. At the moment this logic is only in place for switching
4451 // in and out of the big surface for split screen resize.
4452 if (isDragResizeChanged()) {
Robert Carrc91d1c32017-02-15 19:37:46 -08004453 setDragResizing();
Robert Carrc91d1c32017-02-15 19:37:46 -08004454 // We can only change top level windows to the full-screen surface when
4455 // resizing (as we only have one full-screen surface). So there is no need
4456 // to preserve and destroy windows which are attached to another, they
4457 // will keep their surface and its size may change over time.
4458 if (mHasSurface && !isChildWindow()) {
4459 mWinAnimator.preserveSurfaceLocked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08004460 result |= RELAYOUT_RES_SURFACE_CHANGED |
4461 RELAYOUT_RES_FIRST_TIME;
Robert Carrc91d1c32017-02-15 19:37:46 -08004462 }
4463 }
4464 final boolean freeformResizing = isDragResizing()
4465 && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
4466 final boolean dockedResizing = isDragResizing()
4467 && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
4468 result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0;
4469 result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004470 return result;
4471 }
4472
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004473 /**
4474 * @return True if this window has been laid out at least once; false otherwise.
4475 */
4476 boolean isLaidOut() {
4477 return mLayoutSeq != -1;
4478 }
4479
4480 /**
4481 * Updates the last inset values to the current ones.
4482 */
4483 void updateLastInsetValues() {
4484 mLastOverscanInsets.set(mOverscanInsets);
4485 mLastContentInsets.set(mContentInsets);
4486 mLastVisibleInsets.set(mVisibleInsets);
4487 mLastStableInsets.set(mStableInsets);
4488 mLastOutsets.set(mOutsets);
Adrian Roos5c6b6222017-11-07 17:36:10 +01004489 mLastDisplayCutout = mDisplayCutout;
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004490 }
4491
Jorim Jaggia5e10572017-11-15 14:36:26 +01004492 void startAnimation(Animation anim) {
4493 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4494 anim.initialize(mFrame.width(), mFrame.height(),
4495 displayInfo.appWidth, displayInfo.appHeight);
4496 anim.restrictDuration(MAX_ANIMATION_DURATION);
4497 anim.scaleCurrentDuration(mService.getWindowAnimationScaleLocked());
4498 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi2e3c31d2017-11-20 19:49:00 +01004499 new WindowAnimationSpec(anim, mSurfacePosition, false /* canSkipFirstFrame */),
4500 mService.mSurfaceAnimationRunner);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004501 startAnimation(mPendingTransaction, adapter);
4502 commitPendingTransaction();
4503 }
4504
chaviw161ea3e2018-01-31 12:01:12 -08004505 private void startMoveAnimation(int left, int top) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01004506 if (DEBUG_ANIM) Slog.v(TAG, "Setting move animation on " + this);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004507 final Point oldPosition = new Point();
4508 final Point newPosition = new Point();
4509 transformFrameToSurfacePosition(mLastFrame.left, mLastFrame.top, oldPosition);
4510 transformFrameToSurfacePosition(left, top, newPosition);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004511 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004512 new MoveAnimationSpec(oldPosition.x, oldPosition.y, newPosition.x, newPosition.y),
Jorim Jaggia5e10572017-11-15 14:36:26 +01004513 mService.mSurfaceAnimationRunner);
chaviw161ea3e2018-01-31 12:01:12 -08004514 startAnimation(getPendingTransaction(), adapter);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004515 }
4516
4517 private void startAnimation(Transaction t, AnimationAdapter adapter) {
4518 startAnimation(t, adapter, mWinAnimator.mLastHidden);
4519 }
4520
4521 @Override
4522 protected void onAnimationFinished() {
4523 mWinAnimator.onAnimationFinished();
4524 }
4525
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004526 /**
4527 * Retrieves the current transformation matrix of the window, relative to the display.
4528 *
4529 * @param float9 A temporary array of 9 floats.
4530 * @param outMatrix Matrix to fill in the transformation.
4531 */
4532 void getTransformationMatrix(float[] float9, Matrix outMatrix) {
4533 float9[Matrix.MSCALE_X] = mWinAnimator.mDsDx;
4534 float9[Matrix.MSKEW_Y] = mWinAnimator.mDtDx;
4535 float9[Matrix.MSKEW_X] = mWinAnimator.mDtDy;
4536 float9[Matrix.MSCALE_Y] = mWinAnimator.mDsDy;
Robert Carr217e7cc2018-01-31 18:08:39 -08004537 int x = mSurfacePosition.x;
4538 int y = mSurfacePosition.y;
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004539
4540 // If changed, also adjust transformFrameToSurfacePosition
4541 final WindowContainer parent = getParent();
4542 if (isChildWindow()) {
4543 final WindowState parentWindow = getParentWindow();
4544 x += parentWindow.mFrame.left - parentWindow.mAttrs.surfaceInsets.left;
4545 y += parentWindow.mFrame.top - parentWindow.mAttrs.surfaceInsets.top;
4546 } else if (parent != null) {
4547 final Rect parentBounds = parent.getBounds();
4548 x += parentBounds.left;
4549 y += parentBounds.top;
4550 }
4551 float9[Matrix.MTRANS_X] = x;
4552 float9[Matrix.MTRANS_Y] = y;
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004553 float9[Matrix.MPERSP_0] = 0;
4554 float9[Matrix.MPERSP_1] = 0;
4555 float9[Matrix.MPERSP_2] = 1;
4556 outMatrix.setValues(float9);
4557 }
4558
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004559 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4560 // access to its windows children. Need to investigate re-writing
4561 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4562 static final class UpdateReportedVisibilityResults {
4563 int numInteresting;
4564 int numVisible;
4565 int numDrawn;
4566 boolean nowGone = true;
4567
4568 void reset() {
4569 numInteresting = 0;
4570 numVisible = 0;
4571 numDrawn = 0;
4572 nowGone = true;
4573 }
4574 }
Robert Carraf422a82017-04-10 18:34:33 -07004575
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004576 private static final class WindowId extends IWindowId.Stub {
4577 private final WeakReference<WindowState> mOuter;
4578
4579 private WindowId(WindowState outer) {
4580
4581 // Use a weak reference for the outer class. This is important to prevent the following
4582 // leak: Since we send this class to the client process, binder will keep it alive as
4583 // long as the client keeps it alive. Now, if the window is removed, we need to clear
4584 // out our reference so even though this class is kept alive we don't leak WindowState,
4585 // which can keep a whole lot of classes alive.
4586 mOuter = new WeakReference<>(outer);
4587 }
4588
4589 @Override
4590 public void registerFocusObserver(IWindowFocusObserver observer) {
4591 final WindowState outer = mOuter.get();
4592 if (outer != null) {
4593 outer.registerFocusObserver(observer);
4594 }
4595 }
4596 @Override
4597 public void unregisterFocusObserver(IWindowFocusObserver observer) {
4598 final WindowState outer = mOuter.get();
4599 if (outer != null) {
4600 outer.unregisterFocusObserver(observer);
4601 }
4602 }
4603 @Override
4604 public boolean isFocused() {
4605 final WindowState outer = mOuter.get();
4606 return outer != null && outer.isFocused();
4607 }
4608 }
4609
Robert Carrb1579c82017-09-05 14:54:47 -07004610
4611 @Override
4612 boolean shouldMagnify() {
4613 if (mAttrs.type == TYPE_INPUT_METHOD ||
Robert Carree4d4b92017-11-22 12:21:46 -08004614 mAttrs.type == TYPE_INPUT_METHOD_DIALOG ||
4615 mAttrs.type == TYPE_MAGNIFICATION_OVERLAY ||
4616 mAttrs.type == TYPE_NAVIGATION_BAR ||
4617 // It's tempting to wonder: Have we forgotten the rounded corners overlay?
4618 // worry not: it's a fake TYPE_NAVIGATION_BAR_PANEL
Eugene Susla31e3bb92018-03-13 12:24:50 -07004619 mAttrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Robert Carrb1579c82017-09-05 14:54:47 -07004620 return false;
4621 }
4622 return true;
4623 }
4624
4625 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004626 SurfaceSession getSession() {
4627 if (mSession.mSurfaceSession != null) {
4628 return mSession.mSurfaceSession;
4629 } else {
4630 return getParent().getSession();
4631 }
4632 }
4633
4634 @Override
4635 boolean needsZBoost() {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00004636 if (mIsImWindow && mService.mInputMethodTarget != null) {
4637 final AppWindowToken appToken = mService.mInputMethodTarget.mAppToken;
4638 if (appToken != null) {
4639 return appToken.needsZBoost();
4640 }
4641 }
4642 return mWillReplaceWindow;
Robert Carrb1579c82017-09-05 14:54:47 -07004643 }
4644
Robert Carrf07ef9e2017-11-21 12:12:49 -08004645 private void applyDims(Dimmer dimmer) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07004646 if (!mAnimatingExit && mAppDied) {
4647 mIsDimming = true;
chaviw2fb06bc2018-01-19 17:09:15 -08004648 dimmer.dimAbove(getPendingTransaction(), this, DEFAULT_DIM_AMOUNT_DEAD_WINDOW);
chaviwebcbc342018-02-07 13:19:00 -08004649 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0 && isVisibleNow() && !mHidden) {
chaviw14076152018-02-02 14:51:20 -08004650 // Only show a dim behind when the following is satisfied:
4651 // 1. The window has the flag FLAG_DIM_BEHIND
4652 // 2. The WindowToken is not hidden so dims aren't shown when the window is exiting.
4653 // 3. The WS is considered visible according to the isVisible() method
chaviwebcbc342018-02-07 13:19:00 -08004654 // 4. The WS is not hidden.
Robert Carrf59b8dd2017-10-02 18:58:36 -07004655 mIsDimming = true;
chaviw2fb06bc2018-01-19 17:09:15 -08004656 dimmer.dimBelow(getPendingTransaction(), this, mAttrs.dimAmount);
Robert Carrf59b8dd2017-10-02 18:58:36 -07004657 }
Robert Carrf07ef9e2017-11-21 12:12:49 -08004658 }
4659
4660 @Override
4661 void prepareSurfaces() {
4662 final Dimmer dimmer = getDimmer();
4663 mIsDimming = false;
4664 if (dimmer != null) {
4665 applyDims(dimmer);
4666 }
chaviw2f0567b2018-01-29 16:22:02 -08004667 updateSurfacePosition();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004668
Robert Carrb1579c82017-09-05 14:54:47 -07004669 mWinAnimator.prepareSurfaceLocked(true);
4670 super.prepareSurfaces();
4671 }
4672
4673 @Override
Jorim Jaggia5e10572017-11-15 14:36:26 +01004674 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
4675 super.onAnimationLeashCreated(t, leash);
4676
4677 // Leash is now responsible for position, so set our position to 0.
4678 t.setPosition(mSurfaceControl, 0, 0);
chaviw3e751af2018-01-11 11:22:39 -08004679 mLastSurfacePosition.set(0, 0);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004680 }
4681
4682 @Override
4683 public void onAnimationLeashDestroyed(Transaction t) {
4684 super.onAnimationLeashDestroyed(t);
4685 updateSurfacePosition(t);
4686 }
4687
chaviwe07246a2017-12-12 16:18:29 -08004688 @Override
chaviw2f0567b2018-01-29 16:22:02 -08004689 void updateSurfacePosition() {
4690 updateSurfacePosition(getPendingTransaction());
4691 }
4692
4693 private void updateSurfacePosition(Transaction t) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01004694 if (mSurfaceControl == null) {
4695 return;
4696 }
4697
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004698 transformFrameToSurfacePosition(mFrame.left, mFrame.top, mSurfacePosition);
Robert Carrc6d5af52018-02-26 17:46:00 -08004699
chaviw3e751af2018-01-11 11:22:39 -08004700 if (!mSurfaceAnimator.hasLeash() && !mLastSurfacePosition.equals(mSurfacePosition)) {
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004701 t.setPosition(mSurfaceControl, mSurfacePosition.x, mSurfacePosition.y);
chaviw3e751af2018-01-11 11:22:39 -08004702 mLastSurfacePosition.set(mSurfacePosition.x, mSurfacePosition.y);
Robert Carrc6d5af52018-02-26 17:46:00 -08004703 if (surfaceInsetsChanging() && mWinAnimator.hasSurface()) {
4704 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
4705 t.deferTransactionUntil(mSurfaceControl,
4706 mWinAnimator.mSurfaceController.mSurfaceControl.getHandle(),
chaviwbe43ac82018-04-04 15:14:49 -07004707 getFrameNumber());
Robert Carrc6d5af52018-02-26 17:46:00 -08004708 }
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004709 }
4710 }
4711
4712 private void transformFrameToSurfacePosition(int left, int top, Point outPoint) {
4713 outPoint.set(left, top);
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004714
4715 // If changed, also adjust getTransformationMatrix
chaviwe07246a2017-12-12 16:18:29 -08004716 final WindowContainer parentWindowContainer = getParent();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004717 if (isChildWindow()) {
4718 // TODO: This probably falls apart at some point and we should
4719 // actually compute relative coordinates.
Jorim Jaggi50d3f8f2017-12-27 17:41:25 +01004720
4721 // Since the parent was outset by its surface insets, we need to undo the outsetting
4722 // with insetting by the same amount.
Jorim Jaggia5e10572017-11-15 14:36:26 +01004723 final WindowState parent = getParentWindow();
Jorim Jaggi50d3f8f2017-12-27 17:41:25 +01004724 outPoint.offset(-parent.mFrame.left + parent.mAttrs.surfaceInsets.left,
4725 -parent.mFrame.top + parent.mAttrs.surfaceInsets.top);
chaviwe07246a2017-12-12 16:18:29 -08004726 } else if (parentWindowContainer != null) {
4727 final Rect parentBounds = parentWindowContainer.getBounds();
4728 outPoint.offset(-parentBounds.left, -parentBounds.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004729 }
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004730
Robert Carr32bcb102018-01-29 15:03:23 -08004731 TaskStack stack = getStack();
4732
4733 // If we have stack outsets, that means the top-left
4734 // will be outset, and we need to inset ourselves
4735 // to account for it. If we actually have shadows we will
4736 // then un-inset ourselves by the surfaceInsets.
4737 if (stack != null) {
4738 final int outset = stack.getStackOutset();
4739 outPoint.offset(outset, outset);
4740 }
4741
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004742 // Expand for surface insets. See WindowState.expandForSurfaceInsets.
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004743 outPoint.offset(-mAttrs.surfaceInsets.left, -mAttrs.surfaceInsets.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004744 }
4745
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004746 boolean needsRelativeLayeringToIme() {
4747 // We only use the relative layering mode in split screen, as part of elevating the IME
4748 // and windows above it's target above the docked divider.
4749 if (!inSplitScreenWindowingMode()) {
4750 return false;
4751 }
4752
4753 if (isChildWindow()) {
4754 // If we are a child of the input method target we need this promotion.
4755 if (getParentWindow().isInputMethodTarget()) {
4756 return true;
4757 }
4758 } else if (mAppToken != null) {
4759 // Likewise if we share a token with the Input method target and are ordered
4760 // above it but not necessarily a child (e.g. a Dialog) then we also need
4761 // this promotion.
4762 final WindowState imeTarget = mService.mInputMethodTarget;
4763 boolean inTokenWithAndAboveImeTarget = imeTarget != null && imeTarget != this
4764 && imeTarget.mToken == mToken && imeTarget.compareTo(this) <= 0;
4765 return inTokenWithAndAboveImeTarget;
4766 }
4767 return false;
4768 }
4769
Jorim Jaggia5e10572017-11-15 14:36:26 +01004770 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004771 void assignLayer(Transaction t, int layer) {
4772 // See comment in assignRelativeLayerForImeTargetChild
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004773 if (needsRelativeLayeringToIme()) {
4774 getDisplayContent().assignRelativeLayerForImeTargetChild(t, this);
Robert Carrb1579c82017-09-05 14:54:47 -07004775 return;
4776 }
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004777 super.assignLayer(t, layer);
Robert Carrb1579c82017-09-05 14:54:47 -07004778 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07004779
4780 @Override
4781 public boolean isDimming() {
4782 return mIsDimming;
4783 }
Robert Carr0eff1872017-12-01 14:27:04 -08004784
4785 // TODO(b/70040778): We should aim to eliminate the last user of TYPE_APPLICATION_MEDIA
4786 // then we can drop all negative layering on the windowing side and simply inherit
4787 // the default implementation here.
4788 public void assignChildLayers(Transaction t) {
4789 int layer = 1;
4790 for (int i = 0; i < mChildren.size(); i++) {
4791 final WindowState w = mChildren.get(i);
4792
4793 // APPLICATION_MEDIA_OVERLAY needs to go above APPLICATION_MEDIA
4794 // while they both need to go below the main window. However the
4795 // relative layering of multiple APPLICATION_MEDIA/OVERLAY has never
4796 // been defined and so we can use static layers and leave it that way.
4797 if (w.mAttrs.type == TYPE_APPLICATION_MEDIA) {
4798 w.assignLayer(t, -2);
4799 } else if (w.mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) {
4800 w.assignLayer(t, -1);
4801 } else {
4802 w.assignLayer(t, layer);
4803 }
4804 w.assignChildLayers(t);
4805 layer++;
4806 }
4807 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01004808
Andrii Kulian4b6599e2018-01-15 17:24:08 -08004809 /**
4810 * Update a tap exclude region with a rectangular area identified by provided id. The requested
4811 * area will be clipped to the window bounds.
4812 */
4813 void updateTapExcludeRegion(int regionId, int left, int top, int width, int height) {
4814 final DisplayContent currentDisplay = getDisplayContent();
4815 if (currentDisplay == null) {
4816 throw new IllegalStateException("Trying to update window not attached to any display.");
4817 }
4818
4819 if (mTapExcludeRegionHolder == null) {
4820 mTapExcludeRegionHolder = new TapExcludeRegionHolder();
4821
4822 // Make sure that this window is registered as one that provides a tap exclude region
4823 // for its containing display.
4824 currentDisplay.mTapExcludeProvidingWindows.add(this);
4825 }
4826
4827 mTapExcludeRegionHolder.updateRegion(regionId, left, top, width, height);
4828 // Trigger touch exclude region update on current display.
4829 final boolean isAppFocusedOnDisplay = mService.mFocusedApp != null
4830 && mService.mFocusedApp.getDisplayContent() == currentDisplay;
4831 currentDisplay.setTouchExcludeRegion(isAppFocusedOnDisplay ? mService.mFocusedApp.getTask()
4832 : null);
4833 }
4834
4835 /** Union the region with current tap exclude region that this window provides. */
4836 void amendTapExcludeRegion(Region region) {
4837 mTapExcludeRegionHolder.amendRegion(region, getBounds());
4838 }
4839
Robert Carr825581a2018-03-30 14:00:53 -07004840 @Override
4841 public boolean isInputMethodTarget() {
4842 return mService.mInputMethodTarget == this;
4843 }
4844
chaviwbe43ac82018-04-04 15:14:49 -07004845 long getFrameNumber() {
4846 return mFrameNumber;
4847 }
4848
4849 void setFrameNumber(long frameNumber) {
4850 mFrameNumber = frameNumber;
4851 }
4852
Jorim Jaggia5e10572017-11-15 14:36:26 +01004853 private final class MoveAnimationSpec implements AnimationSpec {
4854
4855 private final long mDuration;
4856 private Interpolator mInterpolator;
4857 private Point mFrom = new Point();
4858 private Point mTo = new Point();
4859
4860 private MoveAnimationSpec(int fromX, int fromY, int toX, int toY) {
4861 final Animation anim = AnimationUtils.loadAnimation(mContext,
4862 com.android.internal.R.anim.window_move_from_decor);
Jorim Jaggi08f75cf2018-01-08 14:38:53 +01004863 mDuration = (long)
4864 (anim.computeDurationHint() * mService.getWindowAnimationScaleLocked());
Jorim Jaggia5e10572017-11-15 14:36:26 +01004865 mInterpolator = anim.getInterpolator();
4866 mFrom.set(fromX, fromY);
4867 mTo.set(toX, toY);
4868 }
4869
4870 @Override
4871 public long getDuration() {
4872 return mDuration;
4873 }
4874
4875 @Override
4876 public void apply(Transaction t, SurfaceControl leash, long currentPlayTime) {
4877 final float fraction = (float) currentPlayTime / getDuration();
4878 final float v = mInterpolator.getInterpolation(fraction);
4879 t.setPosition(leash, mFrom.x + (mTo.x - mFrom.x) * v,
4880 mFrom.y + (mTo.y - mFrom.y) * v);
4881 }
Jorim Jaggif75d1612018-02-27 15:05:21 +01004882
4883 @Override
4884 public void dump(PrintWriter pw, String prefix) {
4885 pw.print(prefix); pw.print("from="); pw.print(mFrom);
4886 pw.print(" to="); pw.print(mTo);
4887 pw.print(" duration="); pw.println(mDuration);
4888 }
4889
4890 @Override
4891 public void writeToProtoInner(ProtoOutputStream proto) {
4892 final long token = proto.start(MOVE);
4893 mFrom.writeToProto(proto, FROM);
4894 mTo.writeToProto(proto, TO);
Kweku Adams21b8d262018-03-30 12:19:58 -07004895 proto.write(DURATION_MS, mDuration);
Jorim Jaggif75d1612018-02-27 15:05:21 +01004896 proto.end(token);
4897 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01004898 }
satokcef37fb2011-10-24 21:49:38 +09004899}