blob: 1ae680f793cab0e1006b2a9e0c08a7bcbfad2387 [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;
Adrian Roos2cadc5c2018-07-06 02:39:54 -0700128import static com.android.server.wm.WindowStateProto.FINISHED_FORCED_SEAMLESS_ROTATION_FRAME;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700129import static com.android.server.wm.WindowStateProto.FRAME;
130import static com.android.server.wm.WindowStateProto.GIVEN_CONTENT_INSETS;
131import static com.android.server.wm.WindowStateProto.HAS_SURFACE;
132import static com.android.server.wm.WindowStateProto.IDENTIFIER;
133import static com.android.server.wm.WindowStateProto.IS_ON_SCREEN;
134import static com.android.server.wm.WindowStateProto.IS_READY_FOR_DISPLAY;
135import static com.android.server.wm.WindowStateProto.IS_VISIBLE;
136import static com.android.server.wm.WindowStateProto.OUTSETS;
137import static com.android.server.wm.WindowStateProto.OUTSET_FRAME;
138import static com.android.server.wm.WindowStateProto.OVERSCAN_FRAME;
139import static com.android.server.wm.WindowStateProto.OVERSCAN_INSETS;
140import static com.android.server.wm.WindowStateProto.PARENT_FRAME;
Adrian Roos2cadc5c2018-07-06 02:39:54 -0700141import static com.android.server.wm.WindowStateProto.PENDING_FORCED_SEAMLESS_ROTATION;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700142import static com.android.server.wm.WindowStateProto.REMOVED;
143import static com.android.server.wm.WindowStateProto.REMOVE_ON_EXIT;
144import static com.android.server.wm.WindowStateProto.REQUESTED_HEIGHT;
145import static com.android.server.wm.WindowStateProto.REQUESTED_WIDTH;
146import static com.android.server.wm.WindowStateProto.STABLE_INSETS;
147import static com.android.server.wm.WindowStateProto.STACK_ID;
148import static com.android.server.wm.WindowStateProto.SURFACE_INSETS;
149import static com.android.server.wm.WindowStateProto.SURFACE_POSITION;
150import static com.android.server.wm.WindowStateProto.SYSTEM_UI_VISIBILITY;
151import static com.android.server.wm.WindowStateProto.VIEW_VISIBILITY;
152import static com.android.server.wm.WindowStateProto.VISIBLE_FRAME;
153import static com.android.server.wm.WindowStateProto.VISIBLE_INSETS;
154import static com.android.server.wm.WindowStateProto.WINDOW_CONTAINER;
Adrian Roos41f7e9d2018-06-07 15:29:34 +0200155import static com.android.server.wm.utils.CoordinateTransforms.transformRect;
156import static com.android.server.wm.utils.CoordinateTransforms.transformToRotation;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800157
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700158import android.annotation.CallSuper;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800159import android.app.AppOpsManager;
160import android.content.Context;
161import android.content.res.Configuration;
162import android.graphics.Matrix;
163import android.graphics.PixelFormat;
164import android.graphics.Point;
165import android.graphics.Rect;
166import android.graphics.Region;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700167import android.os.Binder;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700168import android.os.Debug;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800169import android.os.IBinder;
170import android.os.PowerManager;
171import android.os.RemoteCallbackList;
172import android.os.RemoteException;
173import android.os.SystemClock;
174import android.os.Trace;
175import android.os.UserHandle;
176import android.os.WorkSource;
chaviw40234662018-02-07 09:37:16 -0800177import android.provider.Settings;
Phil Weaverbb2f28a2017-12-22 09:44:28 -0800178import android.text.TextUtils;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800179import android.util.DisplayMetrics;
Jorim Jaggie7d2b852017-08-28 17:55:15 +0200180import android.util.MergedConfiguration;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800181import android.util.Slog;
182import android.util.TimeUtils;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700183import android.util.proto.ProtoOutputStream;
Brad Stenningaf596412018-04-02 12:03:19 -0700184import android.view.Display;
Adrian Roos5c6b6222017-11-07 17:36:10 +0100185import android.view.DisplayCutout;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800186import android.view.DisplayInfo;
187import android.view.Gravity;
188import android.view.IApplicationToken;
189import android.view.IWindow;
190import android.view.IWindowFocusObserver;
191import android.view.IWindowId;
192import android.view.InputChannel;
193import android.view.InputEvent;
194import android.view.InputEventReceiver;
Robert Carrb1579c82017-09-05 14:54:47 -0700195import android.view.SurfaceControl;
196import android.view.SurfaceSession;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800197import android.view.View;
198import android.view.ViewTreeObserver;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700199import android.view.WindowInfo;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800200import android.view.WindowManager;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100201import android.view.animation.Animation;
202import android.view.animation.AnimationUtils;
203import android.view.animation.Interpolator;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800204
Jorim Jaggi4876b4a2018-01-11 15:43:49 +0100205import com.android.internal.annotations.VisibleForTesting;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800206import com.android.internal.util.ToBooleanFunction;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800207import com.android.server.input.InputWindowHandle;
Adrian Roose99bc052017-11-20 17:55:31 +0100208import com.android.server.policy.WindowManagerPolicy;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100209import com.android.server.wm.LocalAnimationAdapter.AnimationSpec;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100210import com.android.server.wm.utils.WmDisplayCutout;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800211
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800212import java.io.PrintWriter;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200213import java.lang.ref.WeakReference;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800214import java.util.ArrayList;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700215import java.util.Comparator;
Wale Ogunwaled1880962016-11-08 10:31:59 -0800216import java.util.function.Predicate;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800217
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700218/** A window in the window manager. */
219class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800220 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800221
Skuhne81c524a2015-08-12 13:34:14 -0700222 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700223 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
224 // use hard-coded min sizes for now.
225 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
226 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700227
228 // The thickness of a window resize handle outside the window bounds on the free form workspace
229 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700230 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700231
Craig Mautnere7ae2502012-03-26 17:11:19 -0700232 final WindowManagerPolicy mPolicy;
233 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800234 final Session mSession;
235 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800236 final int mAppOp;
237 // UserId and appId of the owner. Don't display windows of non-current user.
238 final int mOwnerUid;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800239 /** The owner has {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} */
240 final boolean mOwnerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200241 final WindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800242 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700243 // The same object as mToken if this is an app window and null for non-app windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800244 AppWindowToken mAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700245
246 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
247 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800248 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
249 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700250 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800251 final int mBaseLayer;
252 final int mSubLayer;
253 final boolean mLayoutAttached;
254 final boolean mIsImWindow;
255 final boolean mIsWallpaper;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700256 private final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700257 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700258 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800259 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700260 int mSystemUiVisibility;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700261 /**
262 * The visibility of the window based on policy like {@link WindowManagerPolicy}.
263 * Normally set by calling {@link #showLw} and {@link #hideLw}.
264 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800265 boolean mPolicyVisibility = true;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700266 /**
267 * What {@link #mPolicyVisibility} should be set to after a transition animation.
268 * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and
269 * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit
270 * animation is done.
271 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800272 boolean mPolicyVisibilityAfterAnim = true;
Suprabh Shukla69c71422018-04-02 18:39:01 -0700273 // overlay window is hidden because the owning app is suspended
274 private boolean mHiddenWhileSuspended;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700275 private boolean mAppOpVisibility = true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700276 boolean mPermanentlyHidden; // the window should never be shown again
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700277 // This is a non-system overlay window that is currently force hidden.
278 private boolean mForceHideNonSystemOverlayWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800279 boolean mAppFreezing;
chaviwebcbc342018-02-07 13:19:00 -0800280 boolean mHidden = true; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800281 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700282 private boolean mDragResizing;
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200283 private boolean mDragResizingChangeReported = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700284 private int mResizeMode;
Adrian Roos28c25e22018-05-31 18:07:28 +0200285 /**
286 * Special mode that is intended only for the rounded corner overlay: during rotation
287 * transition, we un-rotate the window token such that the window appears as it did before the
288 * rotation.
289 */
290 final boolean mForceSeamlesslyRotate;
291 ForcedSeamlessRotator mPendingForcedSeamlessRotate;
Adrian Roos2cadc5c2018-07-06 02:39:54 -0700292 long mFinishForcedSeamlessRotateFrameNumber;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700293
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700294 private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800295
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700296 /**
297 * The window size that was requested by the application. These are in
298 * the application's coordinate space (without compatibility scale applied).
299 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800300 int mRequestedWidth;
301 int mRequestedHeight;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700302 private int mLastRequestedWidth;
303 private int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700304
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800305 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800306 boolean mHaveFrame;
307 boolean mObscured;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800308
309 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700310
Andrii Kulian9d91ca62016-09-29 22:28:09 -0700311 /**
312 * Used to store last reported to client configuration and check if we have newer available.
313 * We'll send configuration to client only if it is different from the last applied one and
314 * client won't perform unnecessary updates.
315 */
Bryce Lee2b17afd2017-09-21 10:38:20 -0700316 private final MergedConfiguration mLastReportedConfiguration = new MergedConfiguration();
Craig Mautnera2c77052012-03-26 12:14:43 -0700317
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700318 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700319 * Insets that determine the actually visible area. These are in the application's
320 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800321 */
322 final Rect mVisibleInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700323 private final Rect mLastVisibleInsets = new Rect();
324 private boolean mVisibleInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800325
326 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700327 * Insets that are covered by system windows (such as the status bar) and
328 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700329 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800330 */
331 final Rect mContentInsets = new Rect();
332 final Rect mLastContentInsets = new Rect();
Robert Carr18f622f2017-05-08 11:20:43 -0700333
334 /**
335 * The last content insets returned to the client in relayout. We use
336 * these in the bounds animation to ensure we only observe inset changes
337 * at the same time that a client resizes it's surface so that we may use
338 * the geometryAppliesWithResize synchronization mechanism to keep
339 * the contents in place.
340 */
341 final Rect mLastRelayoutContentInsets = new Rect();
342
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700343 private boolean mContentInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800344
345 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800346 * Insets that determine the area covered by the display overscan region. These are in the
347 * application's coordinate space (without compatibility scale applied).
348 */
349 final Rect mOverscanInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700350 private final Rect mLastOverscanInsets = new Rect();
351 private boolean mOverscanInsetsChanged;
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800352
353 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700354 * Insets that determine the area covered by the stable system windows. These are in the
355 * application's coordinate space (without compatibility scale applied).
356 */
357 final Rect mStableInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700358 private final Rect mLastStableInsets = new Rect();
359 private boolean mStableInsetsChanged;
Adrian Roosfa104232014-06-20 16:10:14 -0700360
361 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700362 * Outsets determine the area outside of the surface where we want to pretend that it's possible
363 * to draw anyway.
364 */
365 final Rect mOutsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700366 private final Rect mLastOutsets = new Rect();
367 private boolean mOutsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700368
Adrian Roos5c6b6222017-11-07 17:36:10 +0100369 /** Part of the display that has been cut away. See {@link DisplayCutout}. */
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100370 WmDisplayCutout mDisplayCutout = WmDisplayCutout.NO_CUTOUT;
371 private WmDisplayCutout mLastDisplayCutout = WmDisplayCutout.NO_CUTOUT;
Adrian Roos5c6b6222017-11-07 17:36:10 +0100372 private boolean mDisplayCutoutChanged;
373
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700374 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800375 * Set to true if we are waiting for this window to receive its
376 * given internal insets before laying out other windows based on it.
377 */
378 boolean mGivenInsetsPending;
379
380 /**
381 * These are the content insets that were given during layout for
382 * this window, to be applied to windows behind it.
383 */
384 final Rect mGivenContentInsets = new Rect();
385
386 /**
387 * These are the visible insets that were given during layout for
388 * this window, to be applied to windows behind it.
389 */
390 final Rect mGivenVisibleInsets = new Rect();
391
392 /**
393 * This is the given touchable area relative to the window frame, or null if none.
394 */
395 final Region mGivenTouchableRegion = new Region();
396
397 /**
398 * Flag indicating whether the touchable region should be adjusted by
399 * the visible insets; if false the area outside the visible insets is
400 * NOT touchable, so we must use those to adjust the frame during hit
401 * tests.
402 */
403 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
404
405 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400406 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700407 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800408 float mHScale=1, mVScale=1;
409 float mLastHScale=1, mLastVScale=1;
410 final Matrix mTmpMatrix = new Matrix();
411
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700412 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800413 final Rect mFrame = new Rect();
414 final Rect mLastFrame = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700415 private boolean mFrameSizeChanged = false;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700416 // Frame that is scaled to the application's coordinate space when in
417 // screen size compatibility mode.
418 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800419
420 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700421
Adrian Roos604ef952018-05-15 20:13:13 +0200422 final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700423
Adrian Roos5ed644f2018-03-19 17:01:05 +0100424 /** Whether the parent frame would have been different if there was no display cutout. */
425 private boolean mParentFrameWasClippedByDisplayCutout;
426
Wale Ogunwale94596652015-02-06 19:27:34 -0800427 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
428 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700429 final Rect mDisplayFrame = new Rect();
430
431 // The region of the display frame that the display type supports displaying content on. This
432 // is mostly a special case for TV where some displays don’t have the entire display usable.
433 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
434 // window display contents to extend into the overscan region.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700435 private final Rect mOverscanFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700436
437 // The display frame minus the stable insets. This value is always constant regardless of if
438 // the status bar or navigation bar is visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700439 private final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800440
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700441 // The area not occupied by the status and navigation bars. So, if both status and navigation
442 // bars are visible, the decor frame is equal to the stable frame.
443 final Rect mDecorFrame = new Rect();
444
445 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
446 // minus the area occupied by the IME if the IME is present.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700447 private final Rect mContentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700448
449 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
450 // displays hint text.
451 final Rect mVisibleFrame = new Rect();
452
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700453 // Frame that includes dead area outside of the surface but where we want to pretend that it's
454 // possible to draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700455 private final Rect mOutsetFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700456
Jorim Jaggidc249c42015-12-15 14:57:31 -0800457 /**
458 * Usually empty. Set to the task's tempInsetFrame. See
459 *{@link android.app.IActivityManager#resizeDockedStack}.
460 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700461 private final Rect mInsetFrame = new Rect();
Jorim Jaggidc249c42015-12-15 14:57:31 -0800462
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800463 boolean mContentChanged;
464
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800465 // If a window showing a wallpaper: the requested offset for the
466 // wallpaper; if a wallpaper window: the currently applied offset.
467 float mWallpaperX = -1;
468 float mWallpaperY = -1;
469
470 // If a window showing a wallpaper: what fraction of the offset
471 // range corresponds to a full virtual screen.
472 float mWallpaperXStep = -1;
473 float mWallpaperYStep = -1;
474
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700475 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
476 // to its window; if a wallpaper window: not used.
477 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
478 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
479
Craig Mautner2268e7e2012-12-13 15:40:00 -0800480 /**
481 * This is set after IWindowSession.relayout() has been called at
482 * least once for the window. It allows us to detect the situation
483 * where we don't yet have a surface, but should have one soon, so
484 * we can give the window focus before waiting for the relayout.
485 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800486 boolean mRelayoutCalled;
487
Robert Carrfed10072016-05-26 11:48:49 -0700488 boolean mInRelayout;
489
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800490 /**
491 * If the application has called relayout() with changes that can
492 * impact its window's size, we need to perform a layout pass on it
493 * even if it is not currently visible for layout. This is set
494 * when in that case until the layout is done.
495 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800496 boolean mLayoutNeeded;
497
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800498 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800499 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800500
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800501 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800502 boolean mDestroying;
503
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800504 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800505 boolean mRemoveOnExit;
506
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800507 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800508 * Whether the app died while it was visible, if true we might need
509 * to continue to show it until it's restarted.
510 */
511 boolean mAppDied;
512
513 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800514 * Set when the orientation is changing and this window has not yet
515 * been updated for the new orientation.
516 */
Bryce Lee8c3cf382017-07-06 19:47:10 -0700517 private boolean mOrientationChanging;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800518
Dianne Hackborna57c6952013-03-29 14:46:40 -0700519 /**
Robert Carr9c1c3a02017-08-08 12:59:01 -0700520 * Sometimes in addition to the mOrientationChanging
521 * flag we report that the orientation is changing
522 * due to a mismatch in current and reported configuration.
523 *
524 * In the case of timeout we still need to make sure we
525 * leave the orientation changing state though, so we
526 * use this as a special time out escape hatch.
527 */
528 private boolean mOrientationChangeTimedOut;
529
530 /**
Robert Carr237028a2016-07-26 10:39:45 -0700531 * The orientation during the last visible call to relayout. If our
532 * current orientation is different, the window can't be ready
533 * to be shown.
534 */
535 int mLastVisibleLayoutRotation = -1;
536
537 /**
Andrii Kulianb2e37802017-01-11 00:36:44 -0800538 * Set when we need to report the orientation change to client to trigger a relayout.
539 */
540 boolean mReportOrientationChanged;
541
542 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700543 * How long we last kept the screen frozen.
544 */
545 int mLastFreezeDuration;
546
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800547 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800548 boolean mRemoved;
549
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800550 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800551 * It is save to remove the window and destroy the surface because the client requested removal
552 * or some other higher level component said so (e.g. activity manager).
553 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800554 */
Svetoslav Ganov200adfb2016-10-18 13:29:27 -0700555 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800556
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800557 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700558 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800559 InputChannel mInputChannel;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700560 private InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800561
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800562 // Used to improve performance of toString()
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700563 private String mStringNameCache;
564 private CharSequence mLastTitle;
565 private boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800566
Craig Mautnera2c77052012-03-26 12:14:43 -0700567 final WindowStateAnimator mWinAnimator;
568
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700569 boolean mHasSurface = false;
570
Craig Mautner88400d32012-09-30 12:35:45 -0700571 /** When true this window can be displayed on screens owther than mOwnerUid's */
572 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700573
Chong Zhang92147042016-05-09 12:47:11 -0700574 // Whether the window was visible when we set the app to invisible last time. WM uses
575 // this as a hint to restore the surface (if available) for early animation next time
576 // the app is brought visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700577 private boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800578
Robert Carra1eb4392015-12-10 12:43:51 -0800579 // This window will be replaced due to relaunch. This allows window manager
580 // to differentiate between simple removal of a window and replacement. In the latter case it
581 // will preserve the old window until the new one is drawn.
582 boolean mWillReplaceWindow = false;
583 // If true, the replaced window was already requested to be removed.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700584 private boolean mReplacingRemoveRequested = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800585 // Whether the replacement of the window should trigger app transition animation.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700586 private boolean mAnimateReplacingWindow = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800587 // If not null, the window that will be used to replace the old one. This is being set when
588 // the window is added and unset when this window reports its first draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700589 private WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700590 // For the new window in the replacement transition, if we have
591 // requested to replace without animation, then we should
592 // make sure we also don't apply an enter animation for
593 // the new window.
594 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800595 // Whether this window is being moved via the resize API
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700596 private boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800597
Jeff Brownc2932a12014-11-20 18:04:05 -0800598 /**
599 * Wake lock for drawing.
600 * Even though it's slightly more expensive to do so, we will use a separate wake lock
601 * for each app that is requesting to draw while dozing so that we can accurately track
602 * who is preventing the system from suspending.
603 * This lock is only acquired on first use.
604 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700605 private PowerManager.WakeLock mDrawLock;
Jeff Brownc2932a12014-11-20 18:04:05 -0800606
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700607 final private Rect mTmpRect = new Rect();
608
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800609 /**
610 * Whether the window was resized by us while it was gone for layout.
611 */
612 boolean mResizedWhileGone = false;
613
Robert Carr6da3cc02016-06-16 15:17:07 -0700614 /**
615 * During seamless rotation we have two phases, first the old window contents
616 * are rotated to look as if they didn't move in the new coordinate system. Then we
617 * have to freeze updates to this layer (to preserve the transformation) until
618 * the resize actually occurs. This is true from when the transformation is set
619 * and false until the transaction to resize is sent.
620 */
621 boolean mSeamlesslyRotated = false;
622
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700623 /**
Robert Carrc91d1c32017-02-15 19:37:46 -0800624 * Surface insets from the previous call to relayout(), used to track
625 * if we are changing the Surface insets.
626 */
627 final Rect mLastSurfaceInsets = new Rect();
628
629 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700630 * A flag set by the {@link WindowState} parent to indicate that the parent has examined this
631 * {@link WindowState} in its overall drawing context. This book-keeping allows the parent to
632 * make sure all children have been considered.
633 */
634 private boolean mDrawnStateEvaluated;
635
Jorim Jaggia5e10572017-11-15 14:36:26 +0100636 private final Point mSurfacePosition = new Point();
637
Bryce Leed390deb2017-06-22 13:14:28 -0700638 /**
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800639 * A region inside of this window to be excluded from touch-related focus switches.
640 */
641 private TapExcludeRegionHolder mTapExcludeRegionHolder;
642
643 /**
chaviw40234662018-02-07 09:37:16 -0800644 * Used for testing because the real PowerManager is final.
645 */
646 private PowerManagerWrapper mPowerManagerWrapper;
647
648 /**
chaviwbe43ac82018-04-04 15:14:49 -0700649 * A frame number in which changes requested in this layout will be rendered.
650 */
651 private long mFrameNumber = -1;
652
653 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700654 * 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 -0700655 * of z-order and 1 otherwise.
656 */
Griff Hazen51d00d82016-11-22 15:39:24 -0800657 private static final Comparator<WindowState> sWindowSubLayerComparator =
658 new Comparator<WindowState>() {
659 @Override
660 public int compare(WindowState w1, WindowState w2) {
661 final int layer1 = w1.mSubLayer;
662 final int layer2 = w2.mSubLayer;
663 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
664 // We insert the child window into the list ordered by
665 // the sub-layer. For same sub-layers, the negative one
666 // should go below others; the positive one should go
667 // above others.
668 return -1;
669 }
670 return 1;
671 };
672 };
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700673
Robert Carrf59b8dd2017-10-02 18:58:36 -0700674 /**
675 * Indicates whether we have requested a Dim (in the sense of {@link Dimmer}) from our host
676 * container.
677 */
678 private boolean mIsDimming = false;
679
680 private static final float DEFAULT_DIM_AMOUNT_DEAD_WINDOW = 0.5f;
681
Adrian Roos28c25e22018-05-31 18:07:28 +0200682 void forceSeamlesslyRotateIfAllowed(int oldRotation, int rotation) {
683 if (mForceSeamlesslyRotate) {
Adrian Roos73ab97c2018-08-02 15:56:15 +0200684 if (mPendingForcedSeamlessRotate != null) {
685 oldRotation = mPendingForcedSeamlessRotate.getOldRotation();
686 }
687
Adrian Roos28c25e22018-05-31 18:07:28 +0200688 mPendingForcedSeamlessRotate = new ForcedSeamlessRotator(
689 oldRotation, rotation, getDisplayInfo());
690 mPendingForcedSeamlessRotate.unrotate(this.mToken);
691 }
692 }
693
chaviw40234662018-02-07 09:37:16 -0800694 interface PowerManagerWrapper {
695 void wakeUp(long time, String reason);
696
697 boolean isInteractive();
698
699 }
700
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800701 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
chaviw40234662018-02-07 09:37:16 -0800702 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
703 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow) {
704 this(service, s, c, token, parentWindow, appOp, seq, a, viewVisibility, ownerId,
705 ownerCanAddInternalSystemWindow, new PowerManagerWrapper() {
706 @Override
707 public void wakeUp(long time, String reason) {
708 service.mPowerManager.wakeUp(time, reason);
709 }
710
711 @Override
712 public boolean isInteractive() {
713 return service.mPowerManager.isInteractive();
714 }
715 });
716 }
717
718 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
719 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
720 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow,
721 PowerManagerWrapper powerManagerWrapper) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100722 super(service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800723 mSession = s;
724 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800725 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800726 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700727 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700728 mOwnerUid = ownerId;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800729 mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200730 mWindowId = new WindowId(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800731 mAttrs.copyFrom(a);
Robert Carrb08ed042018-03-12 15:49:08 -0700732 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800733 mViewVisibility = viewVisibility;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700734 mPolicy = mService.mPolicy;
735 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800736 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700737 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700738 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
chaviw40234662018-02-07 09:37:16 -0800739 mPowerManagerWrapper = powerManagerWrapper;
Adrian Roos28c25e22018-05-31 18:07:28 +0200740 mForceSeamlesslyRotate = token.mRoundedCornerOverlay;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700741 if (localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700742 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700743 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800744 try {
745 c.asBinder().linkToDeath(deathRecipient, 0);
746 } catch (RemoteException e) {
747 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700748 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800749 mLayoutAttached = false;
750 mIsImWindow = false;
751 mIsWallpaper = false;
752 mIsFloatingLayer = false;
753 mBaseLayer = 0;
754 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700755 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700756 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800757 return;
758 }
759 mDeathRecipient = deathRecipient;
760
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700761 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800762 // The multiplier here is to reserve space for multiple
763 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800764 mBaseLayer = mPolicy.getWindowLayerLw(parentWindow)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700765 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800766 mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700767 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900768
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700769 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow);
770 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900771
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800772 mLayoutAttached = mAttrs.type !=
773 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700774 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
775 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
776 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800777 } else {
778 // The multiplier here is to reserve space for multiple
779 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800780 mBaseLayer = mPolicy.getWindowLayerLw(this)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700781 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800782 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700783 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800784 mLayoutAttached = false;
785 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
786 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
787 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800788 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700789 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800790
Wale Ogunwale72919d22016-12-08 18:58:50 -0800791 if (mAppToken != null && mAppToken.mShowForAllUsers) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700792 // Windows for apps that can show for all users should also show when the device is
793 // locked.
794 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
Craig Mautner19ab8282014-05-07 10:35:34 -0700795 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800796
Craig Mautner322e4032012-07-13 13:35:20 -0700797 mWinAnimator = new WindowStateAnimator(this);
798 mWinAnimator.mAlpha = a.alpha;
799
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800800 mRequestedWidth = 0;
801 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700802 mLastRequestedWidth = 0;
803 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800804 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800805 mInputWindowHandle = new InputWindowHandle(
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800806 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this, c,
807 getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800808 }
809
810 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700811 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800812 mSession.windowAddedLocked(mAttrs.packageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800813 }
814
Bryce Leed390deb2017-06-22 13:14:28 -0700815 /**
816 * Returns whether this {@link WindowState} has been considered for drawing by its parent.
817 */
Bryce Lee6311c4b2017-07-06 14:09:29 -0700818 boolean getDrawnStateEvaluated() {
Bryce Leed390deb2017-06-22 13:14:28 -0700819 return mDrawnStateEvaluated;
820 }
821
822 /**
823 * Sets whether this {@link WindowState} has been considered for drawing by its parent. Should
824 * be cleared when detached from parent.
825 */
826 void setDrawnStateEvaluated(boolean evaluated) {
827 mDrawnStateEvaluated = evaluated;
828 }
829
830 @Override
831 void onParentSet() {
832 super.onParentSet();
833 setDrawnStateEvaluated(false /*evaluated*/);
Robert Carr24be9ab2018-04-30 17:54:53 -0700834
835 getDisplayContent().reapplyMagnificationSpec();
Bryce Leed390deb2017-06-22 13:14:28 -0700836 }
837
Craig Mautnera2c77052012-03-26 12:14:43 -0700838 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800839 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800840 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800841 }
842
843 @Override
844 public String getOwningPackage() {
845 return mAttrs.packageName;
846 }
847
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800848 @Override
849 public boolean canAddInternalSystemWindow() {
850 return mOwnerCanAddInternalSystemWindow;
851 }
852
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200853 @Override
854 public boolean canAcquireSleepToken() {
855 return mSession.mCanAcquireSleepToken;
856 }
857
Jorim Jaggif5834272016-04-04 20:25:41 -0700858 /**
859 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
860 * from {@param frame}. In other words, it applies the insets that would result if
861 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700862 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
863 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700864 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700865 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
866 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
867 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
868 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
869 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700870 frame.inset(left, top, right, bottom);
871 }
872
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800873 @Override
Robert Carr43521762016-10-28 13:15:04 -0700874 public void computeFrameLw(Rect parentFrame, Rect displayFrame, Rect overscanFrame,
875 Rect contentFrame, Rect visibleFrame, Rect decorFrame, Rect stableFrame,
Adrian Roos5ed644f2018-03-19 17:01:05 +0100876 Rect outsetFrame, WmDisplayCutout displayCutout,
877 boolean parentFrameWasClippedByDisplayCutout) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800878 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700879 // This window is being replaced and either already got information that it's being
880 // removed or we are still waiting for some information. Because of this we don't
881 // want to apply any more changes to it, so it remains in this state until new window
882 // appears.
883 return;
884 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800885 mHaveFrame = true;
Adrian Roos5ed644f2018-03-19 17:01:05 +0100886 mParentFrameWasClippedByDisplayCutout = parentFrameWasClippedByDisplayCutout;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800887
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700888 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700889 final boolean inFullscreenContainer = inFullscreenContainer();
Robert Carre6275582016-02-29 15:45:45 -0800890 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700891 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800892
Chong Zhangae35fef2016-03-16 15:56:55 -0700893 // If the task has temp inset bounds set, we have to make sure all its windows uses
894 // the temp inset frame. Otherwise different display frames get applied to the main
895 // window and the child window, making them misaligned.
Adrian Roose76b2b52018-03-21 16:22:16 +0100896 // Otherwise we need to clear the inset frame, to avoid using a stale frame after leaving
897 // multi window mode.
898 if (task != null && isInMultiWindowMode()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700899 task.getTempInsetBounds(mInsetFrame);
Adrian Roose76b2b52018-03-21 16:22:16 +0100900 } else {
901 mInsetFrame.setEmpty();
Chong Zhangae35fef2016-03-16 15:56:55 -0700902 }
903
Jorim Jaggif5834272016-04-04 20:25:41 -0700904 // Denotes the actual frame used to calculate the insets and to perform the layout. When
905 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
906 // insets temporarily. By the notion of a task having a different layout frame, we can
907 // achieve that while still moving the task around.
908 final Rect layoutContainingFrame;
909 final Rect layoutDisplayFrame;
910
911 // The offset from the layout containing frame to the actual containing frame.
912 final int layoutXDiff;
913 final int layoutYDiff;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700914 if (inFullscreenContainer || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800915 // We use the parent frame as the containing frame for fullscreen and child windows
Robert Carr43521762016-10-28 13:15:04 -0700916 mContainingFrame.set(parentFrame);
917 mDisplayFrame.set(displayFrame);
918 layoutDisplayFrame = displayFrame;
919 layoutContainingFrame = parentFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700920 layoutXDiff = 0;
921 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800922 } else {
Bryce Leef3c6a472017-11-14 14:53:06 -0800923 getBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100924 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
925
926 // If the bounds are frozen, we still want to translate the window freely and only
927 // freeze the size.
928 Rect frozen = mAppToken.mFrozenBounds.peek();
929 mContainingFrame.right = mContainingFrame.left + frozen.width();
930 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
931 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800932 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700933 // IME is up and obscuring this window. Adjust the window position so it is visible.
Robert Carr825581a2018-03-30 14:00:53 -0700934 if (imeWin != null && imeWin.isVisibleNow() && isInputMethodTarget()) {
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700935 if (inFreeformWindowingMode()
Winson Chungd73e94b2017-05-31 16:25:30 -0700936 && mContainingFrame.bottom > contentFrame.bottom) {
937 // In freeform we want to move the top up directly.
938 // TODO: Investigate why this is contentFrame not parentFrame.
939 mContainingFrame.top -= mContainingFrame.bottom - contentFrame.bottom;
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700940 } else if (!inPinnedWindowingMode()
Winson Chungd73e94b2017-05-31 16:25:30 -0700941 && mContainingFrame.bottom > parentFrame.bottom) {
942 // But in docked we want to behave like fullscreen and behave as if the task
943 // were given smaller bounds for the purposes of layout. Skip adjustments for
944 // the pinned stack, they are handled separately in the PinnedStackController.
945 mContainingFrame.bottom = parentFrame.bottom;
946 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700947 }
Skuhne81c524a2015-08-12 13:34:14 -0700948
Robert Carre6275582016-02-29 15:45:45 -0800949 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700950 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
951 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800952 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700953 if (mContainingFrame.isEmpty()) {
Robert Carr43521762016-10-28 13:15:04 -0700954 mContainingFrame.set(contentFrame);
Skuhne81c524a2015-08-12 13:34:14 -0700955 }
Doris Liu06d582d2015-06-01 13:18:43 -0700956 }
Adrian Roos604ef952018-05-15 20:13:13 +0200957
958 final TaskStack stack = getStack();
959 if (inPinnedWindowingMode() && stack != null
960 && stack.lastAnimatingBoundsWasToFullscreen()) {
961 // PIP edge case: When going from pinned to fullscreen, we apply a
962 // tempInsetFrame for the full task - but we're still at the start of the animation.
963 // To prevent a jump if there's a letterbox, restrict to the parent frame.
964 mInsetFrame.intersectUnchecked(parentFrame);
965 mContainingFrame.intersectUnchecked(parentFrame);
966 }
967
Wale Ogunwale94596652015-02-06 19:27:34 -0800968 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700969 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
970 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
971 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700972 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
Robert Carr43521762016-10-28 13:15:04 -0700973 subtractInsets(mDisplayFrame, layoutContainingFrame, displayFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700974 if (!layoutInParentFrame()) {
Robert Carr43521762016-10-28 13:15:04 -0700975 subtractInsets(mContainingFrame, layoutContainingFrame, parentFrame, mTmpRect);
976 subtractInsets(mInsetFrame, layoutContainingFrame, parentFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700977 }
Robert Carr43521762016-10-28 13:15:04 -0700978 layoutDisplayFrame = displayFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700979 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700980 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800981
Craig Mautner967212c2013-04-13 21:10:58 -0700982 final int pw = mContainingFrame.width();
983 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800984
Robert Carr43521762016-10-28 13:15:04 -0700985 if (!mParentFrame.equals(parentFrame)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800986 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Robert Carr43521762016-10-28 13:15:04 -0700987 // + " to " + parentFrame);
988 mParentFrame.set(parentFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800989 mContentChanged = true;
990 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700991 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
992 mLastRequestedWidth = mRequestedWidth;
993 mLastRequestedHeight = mRequestedHeight;
994 mContentChanged = true;
995 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800996
Robert Carr43521762016-10-28 13:15:04 -0700997 mOverscanFrame.set(overscanFrame);
998 mContentFrame.set(contentFrame);
999 mVisibleFrame.set(visibleFrame);
1000 mDecorFrame.set(decorFrame);
1001 mStableFrame.set(stableFrame);
1002 final boolean hasOutsets = outsetFrame != null;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001003 if (hasOutsets) {
Robert Carr43521762016-10-28 13:15:04 -07001004 mOutsetFrame.set(outsetFrame);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001005 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001006
Craig Mautnereda67292013-04-28 13:50:14 -07001007 final int fw = mFrame.width();
1008 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001009
Jorim Jaggif5834272016-04-04 20:25:41 -07001010 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
1011
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -07001012 // Calculate the outsets before the content frame gets shrinked to the window frame.
1013 if (hasOutsets) {
1014 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
1015 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
1016 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
1017 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
1018 } else {
1019 mOutsets.set(0, 0, 0, 0);
1020 }
1021
Craig Mautnera248eee2013-05-07 11:41:27 -07001022 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001023 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -08001024 if (windowsAreFloating && !mFrame.isEmpty()) {
Robert Carre65a1c42017-02-28 16:52:59 -08001025 // For pinned workspace the frame isn't limited in any particular
1026 // way since SystemUI controls the bounds. For freeform however
1027 // we want to keep things inside the content frame.
Wale Ogunwale44f036f2017-09-29 05:09:09 -07001028 final Rect limitFrame = task.inPinnedWindowingMode() ? mFrame : mContentFrame;
Skuhne81c524a2015-08-12 13:34:14 -07001029 // Keep the frame out of the blocked system area, limit it in size to the content area
1030 // and make sure that there is always a minimum visible so that the user can drag it
1031 // into a usable area..
Robert Carre65a1c42017-02-28 16:52:59 -08001032 final int height = Math.min(mFrame.height(), limitFrame.height());
1033 final int width = Math.min(limitFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -07001034 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +09001035 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
1036 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
1037 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
1038 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Robert Carre65a1c42017-02-28 16:52:59 -08001039 final int top = Math.max(limitFrame.top,
1040 Math.min(mFrame.top, limitFrame.bottom - minVisibleHeight));
1041 final int left = Math.max(limitFrame.left + minVisibleWidth - width,
1042 Math.min(mFrame.left, limitFrame.right - minVisibleWidth));
Skuhne81c524a2015-08-12 13:34:14 -07001043 mFrame.set(left, top, left + width, top + height);
1044 mContentFrame.set(mFrame);
1045 mVisibleFrame.set(mContentFrame);
1046 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -07001047 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001048 dc.getDockedDividerController().positionDockedStackedDivider(mFrame);
Jorim Jaggi192086e2016-03-11 17:17:03 +01001049 mContentFrame.set(mFrame);
1050 if (!mFrame.equals(mLastFrame)) {
1051 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -08001052 }
Skuhne81c524a2015-08-12 13:34:14 -07001053 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -07001054 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
1055 Math.max(mContentFrame.top, mFrame.top),
1056 Math.min(mContentFrame.right, mFrame.right),
1057 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001058
Jorim Jaggi656f6502016-04-11 21:08:17 -07001059 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
1060 Math.max(mVisibleFrame.top, mFrame.top),
1061 Math.min(mVisibleFrame.right, mFrame.right),
1062 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001063
Jorim Jaggi656f6502016-04-11 21:08:17 -07001064 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
1065 Math.max(mStableFrame.top, mFrame.top),
1066 Math.min(mStableFrame.right, mFrame.right),
1067 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -07001068 }
Adrian Roosfa104232014-06-20 16:10:14 -07001069
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07001070 if (inFullscreenContainer && !windowsAreFloating) {
Jorim Jaggi899327f2016-02-25 20:44:18 -05001071 // Windows that are not fullscreen can be positioned outside of the display frame,
1072 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -07001073 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
1074 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
1075 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
1076 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -08001077 }
Craig Mautnereda67292013-04-28 13:50:14 -07001078
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001079 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001080 // For the docked divider, we calculate the stable insets like a full-screen window
1081 // so it can use it to calculate the snap positions.
Adrian Roos7377f582018-03-20 16:56:22 +01001082 final WmDisplayCutout c = displayCutout.calculateRelativeTo(mDisplayFrame);
1083 mTmpRect.set(mDisplayFrame);
1084 mTmpRect.inset(c.getDisplayCutout().getSafeInsets());
1085 mTmpRect.intersectUnchecked(mStableFrame);
1086
1087 mStableInsets.set(Math.max(mTmpRect.left - mDisplayFrame.left, 0),
1088 Math.max(mTmpRect.top - mDisplayFrame.top, 0),
1089 Math.max(mDisplayFrame.right - mTmpRect.right, 0),
1090 Math.max(mDisplayFrame.bottom - mTmpRect.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -08001091
1092 // The divider doesn't care about insets in any case, so set it to empty so we don't
1093 // trigger a relayout when moving it.
1094 mContentInsets.setEmpty();
1095 mVisibleInsets.setEmpty();
Adrian Roos7377f582018-03-20 16:56:22 +01001096 displayCutout = WmDisplayCutout.NO_CUTOUT;
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001097 } else {
Bryce Leef3c6a472017-11-14 14:53:06 -08001098 getDisplayContent().getBounds(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -07001099 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
1100 // non-fullscreen mode.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07001101 boolean overrideRightInset = !windowsAreFloating && !inFullscreenContainer
1102 && mFrame.right > mTmpRect.right;
1103 boolean overrideBottomInset = !windowsAreFloating && !inFullscreenContainer
1104 && mFrame.bottom > mTmpRect.bottom;
Jorim Jaggi656f6502016-04-11 21:08:17 -07001105 mContentInsets.set(mContentFrame.left - mFrame.left,
1106 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -07001107 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -07001108 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -07001109 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -07001110 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -08001111
Jorim Jaggi656f6502016-04-11 21:08:17 -07001112 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
1113 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -07001114 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -07001115 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -07001116 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -07001117 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -08001118
Jorim Jaggi656f6502016-04-11 21:08:17 -07001119 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
1120 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -07001121 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -07001122 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -07001123 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -07001124 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001125 }
Adrian Roosfa104232014-06-20 16:10:14 -07001126
Jorim Jaggibae2b152018-04-18 17:27:27 +02001127 mDisplayCutout = displayCutout.calculateRelativeTo(mFrame);
1128
Jorim Jaggi656f6502016-04-11 21:08:17 -07001129 // Offset the actual frame by the amount layout frame is off.
1130 mFrame.offset(-layoutXDiff, -layoutYDiff);
1131 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -07001132 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
1133 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
1134 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
1135
Craig Mautnereda67292013-04-28 13:50:14 -07001136 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001137 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001138 // If there is a size compatibility scale being applied to the
1139 // window, we need to apply this to its insets so that they are
1140 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -07001141 mOverscanInsets.scale(mInvGlobalScale);
1142 mContentInsets.scale(mInvGlobalScale);
1143 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -07001144 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001145 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001146
1147 // Also the scaled frame that we report to the app needs to be
1148 // adjusted to be in its coordinate space.
1149 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001150 }
1151
Craig Mautnereda67292013-04-28 13:50:14 -07001152 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001153 final DisplayContent displayContent = getDisplayContent();
1154 if (displayContent != null) {
1155 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwale0303c572016-10-20 10:16:29 -07001156 getDisplayContent().mWallpaperController.updateWallpaperOffset(
Wale Ogunwalee8069dc2015-08-18 09:52:01 -07001157 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001158 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001159 }
1160
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001161 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001162 "Resolving (mRequestedWidth="
1163 + mRequestedWidth + ", mRequestedheight="
1164 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
1165 + "): frame=" + mFrame.toShortString()
1166 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07001167 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -07001168 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001169 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001170 }
1171
Bryce Leef3c6a472017-11-14 14:53:06 -08001172 // TODO: Look into whether this override is still necessary.
1173 @Override
1174 public Rect getBounds() {
1175 if (isInMultiWindowMode()) {
1176 return getTask().getBounds();
1177 } else if (mAppToken != null){
1178 return mAppToken.getBounds();
1179 } else {
1180 return super.getBounds();
1181 }
1182 }
1183
Craig Mautnera2c77052012-03-26 12:14:43 -07001184 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001185 public Rect getFrameLw() {
1186 return mFrame;
1187 }
1188
Craig Mautnera2c77052012-03-26 12:14:43 -07001189 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001190 public Rect getDisplayFrameLw() {
1191 return mDisplayFrame;
1192 }
1193
Craig Mautnera2c77052012-03-26 12:14:43 -07001194 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001195 public Rect getOverscanFrameLw() {
1196 return mOverscanFrame;
1197 }
1198
1199 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001200 public Rect getContentFrameLw() {
1201 return mContentFrame;
1202 }
1203
Craig Mautnera2c77052012-03-26 12:14:43 -07001204 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001205 public Rect getVisibleFrameLw() {
1206 return mVisibleFrame;
1207 }
1208
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001209 Rect getStableFrameLw() {
1210 return mStableFrame;
1211 }
1212
Craig Mautnera2c77052012-03-26 12:14:43 -07001213 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001214 public boolean getGivenInsetsPendingLw() {
1215 return mGivenInsetsPending;
1216 }
1217
Craig Mautnera2c77052012-03-26 12:14:43 -07001218 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001219 public Rect getGivenContentInsetsLw() {
1220 return mGivenContentInsets;
1221 }
1222
Craig Mautnera2c77052012-03-26 12:14:43 -07001223 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001224 public Rect getGivenVisibleInsetsLw() {
1225 return mGivenVisibleInsets;
1226 }
1227
Craig Mautnera2c77052012-03-26 12:14:43 -07001228 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001229 public WindowManager.LayoutParams getAttrs() {
1230 return mAttrs;
1231 }
1232
Craig Mautner812d2ca2012-09-27 15:35:34 -07001233 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001234 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001235 return getDisplayContent().getNeedsMenu(this, bottom);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001236 }
1237
Craig Mautner19d59bc2012-09-04 11:15:56 -07001238 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001239 public int getSystemUiVisibility() {
1240 return mSystemUiVisibility;
1241 }
1242
Craig Mautner19d59bc2012-09-04 11:15:56 -07001243 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001244 public int getSurfaceLayer() {
1245 return mLayer;
1246 }
1247
Craig Mautner812d2ca2012-09-27 15:35:34 -07001248 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001249 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001250 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001251 }
1252
1253 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001254 public IApplicationToken getAppToken() {
1255 return mAppToken != null ? mAppToken.appToken : null;
1256 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001257
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001258 @Override
1259 public boolean isVoiceInteraction() {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001260 return mAppToken != null && mAppToken.mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001261 }
1262
Robert Carr31aa98b2016-07-20 15:29:03 -07001263 boolean setReportResizeHints() {
Craig Mautner4c5eb222013-11-18 12:59:05 -08001264 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1265 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1266 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001267 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001268 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
Robert Carr31aa98b2016-07-20 15:29:03 -07001269 mFrameSizeChanged |= (mLastFrame.width() != mFrame.width()) ||
1270 (mLastFrame.height() != mFrame.height());
Adrian Roos5c6b6222017-11-07 17:36:10 +01001271 mDisplayCutoutChanged |= !mLastDisplayCutout.equals(mDisplayCutout);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001272 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
Adrian Roos5c6b6222017-11-07 17:36:10 +01001273 || mOutsetsChanged || mFrameSizeChanged || mDisplayCutoutChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001274 }
1275
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001276 /**
1277 * Adds the window to the resizing list if any of the parameters we use to track the window
1278 * dimensions or insets have changed.
1279 */
1280 void updateResizingWindowIfNeeded() {
1281 final WindowStateAnimator winAnimator = mWinAnimator;
Adrian Roos5251b1d2018-03-23 18:57:43 +01001282 if (!mHasSurface || getDisplayContent().mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001283 return;
1284 }
1285
1286 final Task task = getTask();
1287 // In the case of stack bound animations, the window frames will update (unlike other
1288 // animations which just modify various transformation properties). We don't want to
1289 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1290 // the frame may not correspond to the surface size or the onscreen area at various
1291 // phases in the animation, and the client will become sad and confused.
Winson Chung40a5f932017-04-13 16:39:36 -07001292 if (task != null && task.mStack.isAnimatingBounds()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001293 return;
1294 }
1295
1296 setReportResizeHints();
1297 boolean configChanged = isConfigChanged();
1298 if (DEBUG_CONFIGURATION && configChanged) {
1299 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1300 }
1301
1302 final boolean dragResizingChanged = isDragResizeChanged()
1303 && !isDragResizingChangeReported();
1304
1305 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
1306 + " dragResizingChanged=" + dragResizingChanged + " last=" + mLastFrame
1307 + " frame=" + mFrame);
1308
1309 // We update mLastFrame always rather than in the conditional with the last inset
1310 // variables, because mFrameSizeChanged only tracks the width and height changing.
1311 mLastFrame.set(mFrame);
1312
1313 if (mContentInsetsChanged
1314 || mVisibleInsetsChanged
Adrian Rooscb938492018-04-16 17:10:32 +02001315 || mStableInsetsChanged
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001316 || winAnimator.mSurfaceResized
1317 || mOutsetsChanged
1318 || mFrameSizeChanged
Adrian Roos5c6b6222017-11-07 17:36:10 +01001319 || mDisplayCutoutChanged
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001320 || configChanged
1321 || dragResizingChanged
Andrii Kulianb2e37802017-01-11 00:36:44 -08001322 || mReportOrientationChanged) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001323 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1324 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
1325 + " contentInsetsChanged=" + mContentInsetsChanged
1326 + " " + mContentInsets.toShortString()
1327 + " visibleInsetsChanged=" + mVisibleInsetsChanged
1328 + " " + mVisibleInsets.toShortString()
1329 + " stableInsetsChanged=" + mStableInsetsChanged
1330 + " " + mStableInsets.toShortString()
1331 + " outsetsChanged=" + mOutsetsChanged
1332 + " " + mOutsets.toShortString()
1333 + " surfaceResized=" + winAnimator.mSurfaceResized
1334 + " configChanged=" + configChanged
1335 + " dragResizingChanged=" + dragResizingChanged
Adrian Roos5c6b6222017-11-07 17:36:10 +01001336 + " reportOrientationChanged=" + mReportOrientationChanged
1337 + " displayCutoutChanged=" + mDisplayCutoutChanged);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001338 }
1339
1340 // If it's a dead window left on screen, and the configuration changed, there is nothing
1341 // we can do about it. Remove the window now.
1342 if (mAppToken != null && mAppDied) {
1343 mAppToken.removeDeadWindows();
1344 return;
1345 }
1346
Jorim Jaggidc9385a2017-05-13 02:00:31 +02001347 updateLastInsetValues();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001348 mService.makeWindowFreezingScreenIfNeededLocked(this);
1349
1350 // If the orientation is changing, or we're starting or ending a drag resizing action,
1351 // then we need to hold off on unfreezing the display until this window has been
1352 // redrawn; to do that, we need to go through the process of getting informed by the
1353 // application when it has finished drawing.
Robert Carr09286c92018-02-15 13:52:31 -08001354 if (getOrientationChanging() || dragResizingChanged) {
Robert Carre13b58e2017-08-31 14:50:44 -07001355 if (DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001356 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1357 + ", mDrawState=DRAW_PENDING in " + this
1358 + ", surfaceController " + winAnimator.mSurfaceController);
1359 }
1360 winAnimator.mDrawState = DRAW_PENDING;
1361 if (mAppToken != null) {
1362 mAppToken.clearAllDrawn();
1363 }
1364 }
1365 if (!mService.mResizingWindows.contains(this)) {
1366 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
1367 mService.mResizingWindows.add(this);
1368 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07001369 } else if (getOrientationChanging()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001370 if (isDrawnLw()) {
1371 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1372 + this + ", surfaceController " + winAnimator.mSurfaceController);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001373 setOrientationChanging(false);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001374 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1375 - mService.mDisplayFreezeTime);
1376 }
1377 }
1378 }
1379
Bryce Lee8c3cf382017-07-06 19:47:10 -07001380 boolean getOrientationChanging() {
1381 // In addition to the local state flag, we must also consider the difference in the last
1382 // reported configuration vs. the current state. If the client code has not been informed of
1383 // the change, logic dependent on having finished processing the orientation, such as
1384 // unfreezing, could be improperly triggered.
1385 // TODO(b/62846907): Checking against {@link mLastReportedConfiguration} could be flaky as
1386 // this is not necessarily what the client has processed yet. Find a
1387 // better indicator consistent with the client.
Robert Carr926643f2017-08-02 12:01:12 -07001388 return (mOrientationChanging || (isVisible()
Bryce Lee2b17afd2017-09-21 10:38:20 -07001389 && getConfiguration().orientation != getLastReportedConfiguration().orientation))
Robert Carr9c1c3a02017-08-08 12:59:01 -07001390 && !mSeamlesslyRotated
1391 && !mOrientationChangeTimedOut;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001392 }
1393
1394 void setOrientationChanging(boolean changing) {
1395 mOrientationChanging = changing;
Robert Carr9c1c3a02017-08-08 12:59:01 -07001396 mOrientationChangeTimedOut = false;
1397 }
1398
1399 void orientationChangeTimedOut() {
1400 mOrientationChangeTimedOut = true;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001401 }
1402
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001403 DisplayContent getDisplayContent() {
1404 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001405 }
1406
Adrian Roos5251b1d2018-03-23 18:57:43 +01001407 @Override
1408 void onDisplayChanged(DisplayContent dc) {
1409 super.onDisplayChanged(dc);
1410 // Window was not laid out for this display yet, so make sure mLayoutSeq does not match.
1411 if (dc != null) {
1412 mLayoutSeq = dc.mLayoutSeq - 1;
Brad Stenningaf596412018-04-02 12:03:19 -07001413 mInputWindowHandle.displayId = dc.getDisplayId();
Adrian Roos5251b1d2018-03-23 18:57:43 +01001414 }
1415 }
1416
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001417 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001418 final DisplayContent displayContent = getDisplayContent();
1419 return displayContent != null ? displayContent.getDisplayInfo() : null;
1420 }
1421
Jorim Jaggife762342016-10-13 14:33:27 +02001422 @Override
1423 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001424 final DisplayContent displayContent = getDisplayContent();
1425 if (displayContent == null) {
Brad Stenningaf596412018-04-02 12:03:19 -07001426 return Display.INVALID_DISPLAY;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001427 }
1428 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001429 }
1430
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001431 Task getTask() {
Bryce Lee6d410262017-02-28 15:30:17 -08001432 return mAppToken != null ? mAppToken.getTask() : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001433 }
1434
1435 TaskStack getStack() {
1436 Task task = getTask();
1437 if (task != null) {
1438 if (task.mStack != null) {
1439 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001440 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001441 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001442 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1443 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001444 final DisplayContent dc = getDisplayContent();
1445 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001446 }
1447
Skuhnef932e562015-08-20 12:07:30 -07001448 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001449 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001450 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001451 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001452 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001453 final Task task = getTask();
1454 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001455 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001456 mTmpRect.setEmpty();
1457 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001458 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001459 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001460 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001461 } else {
1462 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001463 }
1464 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001465
Chong Zhang9184ec62015-09-24 12:32:21 -07001466 bounds.set(mVisibleFrame);
1467 if (intersectWithStackBounds) {
1468 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001469 }
1470
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001471 if (bounds.isEmpty()) {
1472 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001473 if (intersectWithStackBounds) {
1474 bounds.intersect(mTmpRect);
1475 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001476 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001477 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001478 }
1479
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001480 public long getInputDispatchingTimeoutNanos() {
1481 return mAppToken != null
Wale Ogunwale72919d22016-12-08 18:58:50 -08001482 ? mAppToken.mInputDispatchingTimeoutNanos
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001483 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1484 }
1485
Craig Mautnere8552142012-11-07 13:55:47 -08001486 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001487 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001488 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001489 }
1490
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001491 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1492 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1493 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1494 if (dtdx < -.000001f || dtdx > .000001f) return false;
1495 if (dsdy < -.000001f || dsdy > .000001f) return false;
1496 return true;
1497 }
1498
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001499 void prelayout() {
1500 if (mEnforceSizeCompat) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001501 mGlobalScale = getDisplayContent().mCompatibleScreenScale;
1502 mInvGlobalScale = 1 / mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001503 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001504 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001505 }
1506 }
1507
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001508 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001509 boolean hasContentToDisplay() {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001510 if (!mAppFreezing && isDrawnLw() && (mViewVisibility == View.VISIBLE
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001511 || (mWinAnimator.isAnimationSet() && !mService.mAppTransition.isTransitionSet()))) {
1512 return true;
1513 }
1514
Wale Ogunwale44f21802016-09-02 12:49:48 -07001515 return super.hasContentToDisplay();
1516 }
1517
1518 @Override
1519 boolean isVisible() {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001520 return wouldBeVisibleIfPolicyIgnored() && mPolicyVisibility;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001521 }
1522
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001523 /**
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001524 * @return True if the window would be visible if we'd ignore policy visibility, false
1525 * otherwise.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001526 */
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001527 boolean wouldBeVisibleIfPolicyIgnored() {
Jorim Jaggi43530c92017-05-18 01:53:56 +02001528 return mHasSurface && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001529 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001530 }
1531
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001532 @Override
1533 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001534 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001535 }
1536
1537 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001538 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1539 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001540 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001541 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1542 boolean isWinVisibleLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001543 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.isSelfAnimating())
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001544 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001545 }
1546
1547 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001548 * The same as isVisible(), but follows the current hidden state of the associated app token,
1549 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001550 */
1551 boolean isVisibleNow() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001552 return (!mToken.isHidden() || mAttrs.type == TYPE_APPLICATION_STARTING)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001553 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001554 }
1555
1556 /**
1557 * Can this window possibly be a drag/drop target? The test here is
1558 * a combination of the above "visible now" with the check that the
1559 * Input Manager uses when discarding windows from input consideration.
1560 */
1561 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001562 return isVisibleNow() && !mRemoved
1563 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001564 }
1565
1566 /**
1567 * Same as isVisible(), but we also count it as visible between the
1568 * call to IWindowSession.add() and the first relayout().
1569 */
1570 boolean isVisibleOrAdding() {
1571 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001572 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001573 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001574 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001575 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001576 }
1577
1578 /**
1579 * Is this window currently on-screen? It is on-screen either if it
1580 * is visible or it is currently running an animation before no longer
1581 * being visible.
1582 */
1583 boolean isOnScreen() {
Jorim Jaggiaf221d12016-11-15 14:59:57 -08001584 if (!mHasSurface || mDestroying || !mPolicyVisibility) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001585 return false;
1586 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001587 final AppWindowToken atoken = mAppToken;
1588 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001589 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001590 || mWinAnimator.isAnimationSet());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001591 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01001592 return !isParentWindowHidden() || mWinAnimator.isAnimationSet();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001593 }
1594
1595 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001596 * Whether this window's drawn state might affect the drawn states of the app token.
1597 *
Chong Zhang8e4bda92016-05-04 15:08:18 -07001598 * @return true if the window should be considered while evaluating allDrawn flags.
1599 */
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001600 boolean mightAffectAllDrawn() {
1601 final boolean isAppType = mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1602 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION;
1603 return (isOnScreen() || isAppType) && !mAnimatingExit && !mDestroying;
Chong Zhang8e4bda92016-05-04 15:08:18 -07001604 }
1605
1606 /**
1607 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1608 * it must be drawn before allDrawn can become true.
1609 */
1610 boolean isInteresting() {
1611 return mAppToken != null && !mAppDied
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001612 && (!mAppToken.isFreezingScreen() || !mAppFreezing);
Chong Zhang8e4bda92016-05-04 15:08:18 -07001613 }
1614
1615 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001616 * Like isOnScreen(), but we don't return true if the window is part
1617 * of a transition that has not yet been started.
1618 */
1619 boolean isReadyForDisplay() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001620 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001621 return false;
1622 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001623 return mHasSurface && mPolicyVisibility && !mDestroying
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001624 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.isHidden())
1625 || mWinAnimator.isAnimationSet());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001626 }
1627
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001628 // TODO: Another visibility method that was added late in the release to minimize risk.
1629 @Override
1630 public boolean canAffectSystemUiFlags() {
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001631 final boolean translucent = mAttrs.alpha == 0.0f;
Jorim Jaggi72207752018-01-08 13:16:59 +01001632 if (translucent) {
1633 return false;
1634 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001635 if (mAppToken == null) {
1636 final boolean shown = mWinAnimator.getShown();
1637 final boolean exiting = mAnimatingExit || mDestroying;
Jorim Jaggi72207752018-01-08 13:16:59 +01001638 return shown && !exiting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001639 } else {
Jorim Jaggi50bf59c2018-03-09 17:29:48 +01001640 final Task task = getTask();
1641 final boolean canFromTask = task != null && task.canAffectSystemUiFlags();
1642 return canFromTask && !mAppToken.isHidden();
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001643 }
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001644 }
1645
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001646 /**
1647 * Like isOnScreen, but returns false if the surface hasn't yet
1648 * been drawn.
1649 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001650 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001651 public boolean isDisplayedLw() {
1652 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001653 return isDrawnLw() && mPolicyVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001654 && ((!isParentWindowHidden() && (atoken == null || !atoken.hiddenRequested))
1655 || mWinAnimator.isAnimationSet());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001656 }
1657
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001658 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001659 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001660 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001661 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001662 public boolean isAnimatingLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001663 return isAnimating();
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001664 }
1665
Craig Mautner812d2ca2012-09-27 15:35:34 -07001666 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001667 public boolean isGoneForLayoutLw() {
1668 final AppWindowToken atoken = mAppToken;
1669 return mViewVisibility == View.GONE
1670 || !mRelayoutCalled
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001671 || (atoken == null && mToken.isHidden())
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001672 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001673 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001674 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001675 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001676 }
1677
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001678 /**
1679 * Returns true if the window has a surface that it has drawn a
1680 * complete UI in to.
1681 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001682 public boolean isDrawFinishedLw() {
1683 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001684 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1685 || mWinAnimator.mDrawState == READY_TO_SHOW
1686 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001687 }
1688
1689 /**
1690 * Returns true if the window has a surface that it has drawn a
1691 * complete UI in to.
1692 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001693 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001694 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001695 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001696 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001697 }
1698
1699 /**
1700 * Return true if the window is opaque and fully drawn. This indicates
1701 * it may obscure windows behind it.
1702 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001703 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001704 // When there is keyguard, wallpaper could be placed over the secure app
1705 // window but invisible. We need to check wallpaper visibility explicitly
1706 // to determine if it's occluding apps.
1707 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1708 || (mIsWallpaper && mWallpaperVisible))
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001709 && isDrawnLw() && !mWinAnimator.isAnimationSet();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001710 }
1711
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001712 @Override
1713 void onMovedByResize() {
1714 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001715 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001716 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001717 }
1718
1719 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1720 boolean changed = false;
1721
1722 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001723 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001724 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1725 }
1726
1727 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1728 // Starting window that's exiting will be removed when the animation finishes.
1729 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1730 // to actually remove it.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001731 if (!visible && isVisibleNow() && mAppToken.isSelfAnimating()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001732 mAnimatingExit = true;
1733 mRemoveOnExit = true;
1734 mWindowRemovalAllowed = true;
1735 }
1736 return changed;
1737 }
1738
chaviwe390cbd2018-04-16 15:29:38 -07001739 final boolean isVisibleNow = isVisibleNow();
1740 if (visible != isVisibleNow) {
1741 // Run exit animation if:
1742 // 1. App visibility and WS visibility are different
1743 // 2. App is not running an animation
1744 // 3. WS is currently visible
1745 if (!runningAppAnimation && isVisibleNow) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001746 final AccessibilityController accessibilityController =
1747 mService.mAccessibilityController;
chaviwe390cbd2018-04-16 15:29:38 -07001748 final int winTransit = TRANSIT_EXIT;
1749 mWinAnimator.applyAnimationLocked(winTransit, false /* isEntrance */);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001750 //TODO (multidisplay): Magnification is supported only for the default
1751 if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
1752 accessibilityController.onWindowTransitionLocked(this, winTransit);
1753 }
1754 }
1755 changed = true;
1756 setDisplayLayoutNeeded();
1757 }
1758
1759 return changed;
1760 }
1761
1762 boolean onSetAppExiting() {
1763 final DisplayContent displayContent = getDisplayContent();
1764 boolean changed = false;
1765
1766 if (isVisibleNow()) {
1767 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
1768 //TODO (multidisplay): Magnification is supported only for the default
1769 if (mService.mAccessibilityController != null && isDefaultDisplay()) {
1770 mService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
1771 }
1772 changed = true;
1773 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001774 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001775 }
1776 }
1777
1778 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001779 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001780 changed |= c.onSetAppExiting();
1781 }
1782
1783 return changed;
1784 }
1785
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001786 @Override
1787 void onResize() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001788 final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
Andrii Kulian3dcdf642018-05-23 17:14:00 -07001789 if (mHasSurface && !isGoneForLayoutLw() && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001790 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001791 resizingWindows.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001792 }
1793 if (isGoneForLayoutLw()) {
1794 mResizedWhileGone = true;
1795 }
1796
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001797 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001798 }
1799
1800 void onUnfreezeBounds() {
1801 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001802 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001803 c.onUnfreezeBounds();
1804 }
1805
1806 if (!mHasSurface) {
1807 return;
1808 }
1809
1810 mLayoutNeeded = true;
1811 setDisplayLayoutNeeded();
1812 if (!mService.mResizingWindows.contains(this)) {
1813 mService.mResizingWindows.add(this);
1814 }
1815 }
1816
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001817 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001818 * If the window has moved due to its containing content frame changing, then notify the
1819 * listeners and optionally animate it. Simply checking a change of position is not enough,
1820 * because being move due to dock divider is not a trigger for animation.
1821 */
chaviw161ea3e2018-01-31 12:01:12 -08001822 void handleWindowMovedIfNeeded() {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001823 if (!hasMoved()) {
1824 return;
1825 }
1826
1827 // Frame has moved, containing content frame has also moved, and we're not currently
1828 // animating... let's do something.
1829 final int left = mFrame.left;
1830 final int top = mFrame.top;
1831 final Task task = getTask();
1832 final boolean adjustedForMinimizedDockOrIme = task != null
1833 && (task.mStack.isAdjustedForMinimizedDockedStack()
1834 || task.mStack.isAdjustedForIme());
David Stevens9440dc82017-03-16 19:00:20 -07001835 if (mToken.okToAnimate()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001836 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1837 && !isDragResizing() && !adjustedForMinimizedDockOrIme
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001838 && getWindowConfiguration().hasMovementAnimations()
Adrian Roos41f7e9d2018-06-07 15:29:34 +02001839 && !mWinAnimator.mLastHidden
1840 && !mSeamlesslyRotated) {
chaviw161ea3e2018-01-31 12:01:12 -08001841 startMoveAnimation(left, top);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001842 }
1843
1844 //TODO (multidisplay): Accessibility supported only for the default display.
1845 if (mService.mAccessibilityController != null
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001846 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001847 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
1848 }
1849
1850 try {
1851 mClient.moved(left, top);
1852 } catch (RemoteException e) {
1853 }
1854 mMovedByResize = false;
1855 }
1856
1857 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001858 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001859 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1860 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001861 private boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001862 return mHasSurface && (mContentChanged || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001863 && !mAnimatingExit
Chong Zhangbd0d9372015-12-28 15:18:29 -08001864 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001865 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001866 }
1867
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001868 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001869 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001870 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001871 return false;
1872 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001873 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001874 }
1875
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001876 boolean fillsDisplay() {
1877 final DisplayInfo displayInfo = getDisplayInfo();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001878 return mFrame.left <= 0 && mFrame.top <= 0
1879 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001880 }
1881
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001882 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001883 boolean isConfigChanged() {
Bryce Lee2b17afd2017-09-21 10:38:20 -07001884 return !getLastReportedConfiguration().equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001885 }
1886
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001887 void onWindowReplacementTimeout() {
1888 if (mWillReplaceWindow) {
1889 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001890 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001891 // delays removal on certain conditions, which will leave the stale window in the
1892 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1893 //
1894 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001895 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001896 } else {
1897 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001898 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001899 c.onWindowReplacementTimeout();
1900 }
1901 }
1902 }
1903
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001904 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001905 void forceWindowsScaleableInTransaction(boolean force) {
1906 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1907 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1908 }
1909
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001910 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001911 }
1912
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001913 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001914 void removeImmediately() {
1915 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001916
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001917 if (mRemoved) {
1918 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001919 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1920 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001921 return;
1922 }
1923
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001924 mRemoved = true;
1925
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001926 mWillReplaceWindow = false;
1927 if (mReplacementWindow != null) {
1928 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1929 }
1930
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001931 final DisplayContent dc = getDisplayContent();
Robert Carr825581a2018-03-30 14:00:53 -07001932 if (isInputMethodTarget()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001933 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001934 }
1935
1936 final int type = mAttrs.type;
1937 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001938 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001939 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001940 if (mTapExcludeRegionHolder != null) {
1941 // If a tap exclude region container was initialized for this window, then it should've
1942 // also been registered in display.
1943 dc.mTapExcludeProvidingWindows.remove(this);
1944 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001945 mPolicy.removeWindowLw(this);
1946
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001947 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001948
Craig Mautner96868332012-12-04 14:29:11 -08001949 mWinAnimator.destroyDeferredSurfaceLocked();
1950 mWinAnimator.destroySurfaceLocked();
Wale Ogunwale943002b2017-02-15 19:34:01 -08001951 mSession.windowRemovedLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001952 try {
1953 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1954 } catch (RuntimeException e) {
1955 // Ignore if it has already been removed (usually because
1956 // we are doing this as part of processing a death note.)
1957 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001958
1959 mService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001960 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001961
Wale Ogunwale571771c2016-08-26 13:18:50 -07001962 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001963 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001964 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001965 removeIfPossible(false /*keepVisibleDeadWindow*/);
1966 }
1967
Wale Ogunwale571771c2016-08-26 13:18:50 -07001968 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001969 mWindowRemovalAllowed = true;
1970 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1971 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1972
1973 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1974 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1975 "Starting window removed " + this);
1976
1977 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && this == mService.mCurrentFocus)
1978 Slog.v(TAG_WM, "Remove " + this + " client="
1979 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1980 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1981 + Debug.getCallers(5));
1982
1983 final long origId = Binder.clearCallingIdentity();
1984
Peter Visontay3556a3b2017-11-01 17:23:17 +00001985 try {
1986 disposeInputChannel();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001987
Peter Visontay3556a3b2017-11-01 17:23:17 +00001988 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1989 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1990 + " mAnimatingExit=" + mAnimatingExit
1991 + " mRemoveOnExit=" + mRemoveOnExit
1992 + " mHasSurface=" + mHasSurface
1993 + " surfaceShowing=" + mWinAnimator.getShown()
1994 + " isAnimationSet=" + mWinAnimator.isAnimationSet()
1995 + " app-animation="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001996 + (mAppToken != null ? mAppToken.isSelfAnimating() : "false")
Peter Visontay3556a3b2017-11-01 17:23:17 +00001997 + " mWillReplaceWindow=" + mWillReplaceWindow
1998 + " inPendingTransaction="
1999 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
2000 + " mDisplayFrozen=" + mService.mDisplayFrozen
2001 + " callers=" + Debug.getCallers(6));
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002002
Peter Visontay3556a3b2017-11-01 17:23:17 +00002003 // Visibility of the removed window. Will be used later to update orientation later on.
2004 boolean wasVisible = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002005
Peter Visontay3556a3b2017-11-01 17:23:17 +00002006 final int displayId = getDisplayId();
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002007
Peter Visontay3556a3b2017-11-01 17:23:17 +00002008 // First, see if we need to run an animation. If we do, we have to hold off on removing the
2009 // window until the animation is done. If the display is frozen, just remove immediately,
2010 // since the animation wouldn't be seen.
2011 if (mHasSurface && mToken.okToAnimate()) {
2012 if (mWillReplaceWindow) {
2013 // This window is going to be replaced. We need to keep it around until the new one
2014 // gets added, then we will get rid of this one.
2015 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
2016 "Preserving " + this + " until the new one is " + "added");
2017 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
2018 // been removed. We probably need another flag to indicate that window removal
2019 // should be deffered vs. overloading the flag that says we are playing an exit
2020 // animation.
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002021 mAnimatingExit = true;
Peter Visontay3556a3b2017-11-01 17:23:17 +00002022 mReplacingRemoveRequested = true;
2023 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002024 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002025
Peter Visontay3556a3b2017-11-01 17:23:17 +00002026 // If we are not currently running the exit animation, we need to see about starting one
2027 wasVisible = isWinVisibleLw();
2028
2029 if (keepVisibleDeadWindow) {
2030 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
2031 "Not removing " + this + " because app died while it's visible");
2032
2033 mAppDied = true;
2034 setDisplayLayoutNeeded();
2035 mService.mWindowPlacerLocked.performSurfacePlacement();
2036
2037 // Set up a replacement input channel since the app is now dead.
2038 // We need to catch tapping on the dead window to restart the app.
2039 openInputChannel(null);
2040 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
2041 return;
2042 }
2043
2044 if (wasVisible) {
2045 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
2046
2047 // Try starting an animation.
2048 if (mWinAnimator.applyAnimationLocked(transit, false)) {
2049 mAnimatingExit = true;
Jorim Jaggif41e8822018-04-06 17:22:03 +02002050
2051 // mAnimatingExit affects canAffectSystemUiFlags(). Run layout such that
2052 // any change from that is performed immediately.
2053 setDisplayLayoutNeeded();
2054 mService.requestTraversal();
Peter Visontay3556a3b2017-11-01 17:23:17 +00002055 }
2056 //TODO (multidisplay): Magnification is supported only for the default display.
2057 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
2058 mService.mAccessibilityController.onWindowTransitionLocked(this, transit);
2059 }
2060 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002061 final boolean isAnimating = mWinAnimator.isAnimationSet()
2062 && (mAppToken == null || !mAppToken.isWaitingForTransitionStart());
Peter Visontay3556a3b2017-11-01 17:23:17 +00002063 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
2064 && mAppToken.isLastWindow(this);
2065 // We delay the removal of a window if it has a showing surface that can be used to run
2066 // exit animation and it is marked as exiting.
2067 // Also, If isn't the an animating starting window that is the last window in the app.
2068 // We allow the removal of the non-animating starting window now as there is no
2069 // additional window or animation that will trigger its removal.
2070 if (mWinAnimator.getShown() && mAnimatingExit
2071 && (!lastWindowIsStartingWindow || isAnimating)) {
2072 // The exit animation is running or should run... wait for it!
2073 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
2074 "Not removing " + this + " due to exit animation ");
2075 setupWindowForRemoveOnExit();
2076 if (mAppToken != null) {
2077 mAppToken.updateReportedVisibilityLocked();
2078 }
2079 return;
2080 }
2081 }
2082
2083 removeImmediately();
2084 // Removing a visible window will effect the computed orientation
2085 // So just update orientation if needed.
Robert Carrae606b42018-02-15 15:36:23 -08002086 if (wasVisible && mService.updateOrientationFromAppTokensLocked(displayId)) {
Peter Visontay3556a3b2017-11-01 17:23:17 +00002087 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
2088 }
2089 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
2090 } finally {
2091 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002092 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002093 }
2094
2095 private void setupWindowForRemoveOnExit() {
2096 mRemoveOnExit = true;
2097 setDisplayLayoutNeeded();
2098 // Request a focus update as this window's input channel is already gone. Otherwise
2099 // we could have no focused window in input manager.
2100 final boolean focusChanged = mService.updateFocusedWindowLocked(
2101 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
2102 mService.mWindowPlacerLocked.performSurfacePlacement();
2103 if (focusChanged) {
2104 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2105 }
2106 }
2107
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08002108 void setHasSurface(boolean hasSurface) {
2109 mHasSurface = hasSurface;
2110 }
2111
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002112 boolean canBeImeTarget() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002113 if (mIsImWindow) {
2114 // IME windows can't be IME targets. IME targets are required to be below the IME
2115 // windows and that wouldn't be possible if the IME window is its own target...silly.
2116 return false;
2117 }
2118
Winson Chung3d0a74a2017-07-12 12:37:19 -07002119 final boolean windowsAreFocusable = mAppToken == null || mAppToken.windowsAreFocusable();
Winson Chungb1549342017-07-11 09:59:56 -07002120 if (!windowsAreFocusable) {
2121 // This window can't be an IME target if the app's windows should not be focusable.
2122 return false;
2123 }
2124
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002125 final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002126 final int type = mAttrs.type;
2127
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002128 // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are set or
2129 // both are cleared...and not a starting window.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002130 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
2131 && type != TYPE_APPLICATION_STARTING) {
2132 return false;
2133 }
2134
2135 if (DEBUG_INPUT_METHOD) {
2136 Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding());
2137 if (!isVisibleOrAdding()) {
2138 Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController
2139 + " relayoutCalled=" + mRelayoutCalled
2140 + " viewVis=" + mViewVisibility
2141 + " policyVis=" + mPolicyVisibility
2142 + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim
2143 + " parentHidden=" + isParentWindowHidden()
2144 + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
2145 if (mAppToken != null) {
2146 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + mAppToken.hiddenRequested);
2147 }
2148 }
2149 }
2150 return isVisibleOrAdding();
2151 }
2152
Chong Zhangacf11402015-11-04 16:23:10 -08002153 private final class DeadWindowEventReceiver extends InputEventReceiver {
2154 DeadWindowEventReceiver(InputChannel inputChannel) {
2155 super(inputChannel, mService.mH.getLooper());
2156 }
2157 @Override
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -07002158 public void onInputEvent(InputEvent event, int displayId) {
Chong Zhangacf11402015-11-04 16:23:10 -08002159 finishInputEvent(event, true);
2160 }
2161 }
2162 /**
2163 * Dummy event receiver for windows that died visible.
2164 */
2165 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2166
Chong Zhang112eb8c2015-11-02 11:17:00 -08002167 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002168 if (mInputChannel != null) {
2169 throw new IllegalStateException("Window already has an input channel.");
2170 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002171 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002172 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2173 mInputChannel = inputChannels[0];
2174 mClientChannel = inputChannels[1];
2175 mInputWindowHandle.inputChannel = inputChannels[0];
2176 if (outInputChannel != null) {
2177 mClientChannel.transferTo(outInputChannel);
2178 mClientChannel.dispose();
2179 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002180 } else {
2181 // If the window died visible, we setup a dummy input channel, so that taps
2182 // can still detected by input monitor channel, and we can relaunch the app.
2183 // Create dummy event receiver that simply reports all events as handled.
2184 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002185 }
2186 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002187 }
2188
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002189 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002190 if (mDeadWindowEventReceiver != null) {
2191 mDeadWindowEventReceiver.dispose();
2192 mDeadWindowEventReceiver = null;
2193 }
2194
2195 // unregister server channel first otherwise it complains about broken channel
2196 if (mInputChannel != null) {
2197 mService.mInputManager.unregisterInputChannel(mInputChannel);
2198 mInputChannel.dispose();
2199 mInputChannel = null;
2200 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002201 if (mClientChannel != null) {
2202 mClientChannel.dispose();
2203 mClientChannel = null;
2204 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07002205 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002206 }
2207
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002208 /** Returns true if the replacement window was removed. */
2209 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2210 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2211 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2212 removeReplacedWindow();
2213 return true;
2214 }
2215
2216 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002217 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002218 if (c.removeReplacedWindowIfNeeded(replacement)) {
2219 return true;
2220 }
2221 }
2222 return false;
2223 }
2224
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002225 private void removeReplacedWindow() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002226 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002227 mWillReplaceWindow = false;
2228 mAnimateReplacingWindow = false;
2229 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002230 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002231 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002232 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002233 }
2234 }
2235
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002236 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2237 boolean replacementSet = false;
2238
2239 if (mWillReplaceWindow && mReplacementWindow == null
2240 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2241
2242 mReplacementWindow = replacementCandidate;
2243 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2244 replacementSet = true;
2245 }
2246
2247 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002248 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002249 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2250 }
2251
2252 return replacementSet;
2253 }
2254
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002255 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002256 final DisplayContent dc = getDisplayContent();
2257 if (dc != null) {
2258 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002259 }
2260 }
2261
Chong Zhang5117e272016-05-03 12:47:34 -07002262 void applyAdjustForImeIfNeeded() {
2263 final Task task = getTask();
2264 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2265 task.mStack.applyAdjustForImeIfNeeded(task);
2266 }
2267 }
2268
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002269 @Override
2270 void switchUser() {
2271 super.switchUser();
2272 if (isHiddenFromUserLocked()) {
2273 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2274 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
2275 hideLw(false);
2276 }
2277 }
2278
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002279 int getTouchableRegion(Region region, int flags) {
2280 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002281 if (modal && mAppToken != null) {
2282 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002283 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002284 // If this is a modal window we need to dismiss it if it's not full screen and the
2285 // touch happens outside of the frame that displays the content. This means we
2286 // need to intercept touches outside of that window. The dim layer user
2287 // associated with the window (task or stack) will give us the good bounds, as
2288 // they would be used to display the dim layer.
Robert Carrf59b8dd2017-10-02 18:58:36 -07002289 final Task task = getTask();
2290 if (task != null) {
2291 task.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002292 } else {
Robert Carrf59b8dd2017-10-02 18:58:36 -07002293 getStack().getDimBounds(mTmpRect);
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002294 }
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002295 if (inFreeformWindowingMode()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002296 // For freeform windows we the touch region to include the whole surface for the
2297 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002298 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2299 final int delta = WindowManagerService.dipToPixel(
2300 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2301 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002302 }
2303 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002304 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002305 } else {
2306 // Not modal or full screen modal
2307 getTouchableRegion(region);
2308 }
2309 return flags;
2310 }
2311
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002312 void checkPolicyVisibilityChange() {
2313 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2314 if (DEBUG_VISIBILITY) {
2315 Slog.v(TAG, "Policy visibility changing after anim in " +
2316 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2317 }
2318 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002319 if (!mPolicyVisibility) {
Jorim Jaggi2e05af22017-12-28 15:15:11 +01002320 mWinAnimator.hide("checkPolicyVisibilityChange");
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002321 if (mService.mCurrentFocus == this) {
2322 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2323 "setAnimationLocked: setting mFocusMayChange true");
2324 mService.mFocusMayChange = true;
2325 }
Tetsutoki Shiozawa64c5f0c2018-05-18 10:55:01 +09002326 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002327 // Window is no longer visible -- make sure if we were waiting
2328 // for it to be displayed before enabling the display, that
2329 // we allow the display to be enabled now.
2330 mService.enableScreenIfNeededLocked();
2331 }
2332 }
2333 }
2334
2335 void setRequestedSize(int requestedWidth, int requestedHeight) {
2336 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2337 mLayoutNeeded = true;
2338 mRequestedWidth = requestedWidth;
2339 mRequestedHeight = requestedHeight;
2340 }
2341 }
2342
Bryce Leef858b572017-06-29 14:03:33 -07002343 void prepareWindowToDisplayDuringRelayout(boolean wasVisible) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002344 // We need to turn on screen regardless of visibility.
chaviw40234662018-02-07 09:37:16 -08002345 boolean hasTurnScreenOnFlag = (mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0;
2346 boolean allowTheaterMode =
2347 mService.mAllowTheaterModeWakeFromLayout || Settings.Global.getInt(
2348 mService.mContext.getContentResolver(), Settings.Global.THEATER_MODE_ON, 0)
2349 == 0;
2350 boolean canTurnScreenOn = mAppToken == null || mAppToken.canTurnScreenOn();
2351
2352 // The screen will turn on if the following conditions are met
2353 // 1. The window has the flag FLAG_TURN_SCREEN_ON
2354 // 2. The WMS allows theater mode.
2355 // 3. No AWT or the AWT allows the screen to be turned on. This should only be true once
2356 // per resume to prevent the screen getting getting turned on for each relayout. Set
2357 // canTurnScreenOn will be set to false so the window doesn't turn the screen on again
2358 // during this resume.
2359 // 4. When the screen is not interactive. This is because when the screen is already
2360 // interactive, the value may persist until the next animation, which could potentially
2361 // be occurring while turning off the screen. This would lead to the screen incorrectly
2362 // turning back on.
chaviw474093d2018-03-07 15:03:38 -08002363 if (hasTurnScreenOnFlag) {
2364 if (allowTheaterMode && canTurnScreenOn && !mPowerManagerWrapper.isInteractive()) {
2365 if (DEBUG_VISIBILITY || DEBUG_POWER) {
2366 Slog.v(TAG, "Relayout window turning screen on: " + this);
2367 }
2368 mPowerManagerWrapper.wakeUp(SystemClock.uptimeMillis(),
2369 "android.server.wm:TURN_ON");
chaviw40234662018-02-07 09:37:16 -08002370 }
chaviwb28de1f2018-03-02 10:42:36 -08002371
2372 if (mAppToken != null) {
2373 mAppToken.setCanTurnScreenOn(false);
2374 }
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002375 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002376
2377 // If we were already visible, skip rest of preparation.
2378 if (wasVisible) {
2379 if (DEBUG_VISIBILITY) Slog.v(TAG,
2380 "Already visible and does not turn on screen, skip preparing: " + this);
2381 return;
2382 }
2383
2384 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2385 == SOFT_INPUT_ADJUST_RESIZE) {
2386 mLayoutNeeded = true;
2387 }
2388
David Stevens9440dc82017-03-16 19:00:20 -07002389 if (isDrawnLw() && mToken.okToAnimate()) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002390 mWinAnimator.applyEnterAnimationLocked();
2391 }
Bryce Leef858b572017-06-29 14:03:33 -07002392 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002393
Bryce Leef858b572017-06-29 14:03:33 -07002394 void getMergedConfiguration(MergedConfiguration outConfiguration) {
2395 final Configuration globalConfig = mService.mRoot.getConfiguration();
2396 final Configuration overrideConfig = getMergedOverrideConfiguration();
2397 outConfiguration.setConfiguration(globalConfig, overrideConfig);
2398 }
2399
Bryce Lee2b17afd2017-09-21 10:38:20 -07002400 void setLastReportedMergedConfiguration(MergedConfiguration config) {
2401 mLastReportedConfiguration.setTo(config);
2402 }
2403
2404 void getLastReportedMergedConfiguration(MergedConfiguration config) {
2405 config.setTo(mLastReportedConfiguration);
2406 }
2407
2408 private Configuration getLastReportedConfiguration() {
2409 return mLastReportedConfiguration.getMergedConfiguration();
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002410 }
2411
2412 void adjustStartingWindowFlags() {
2413 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2414 && mAppToken.startingWindow != null) {
2415 // Special handling of starting window over the base
2416 // window of the app: propagate lock screen flags to it,
2417 // to provide the correct semantics while starting.
2418 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2419 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2420 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2421 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2422 }
2423 }
2424
2425 void setWindowScale(int requestedWidth, int requestedHeight) {
2426 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2427
2428 if (scaledWindow) {
2429 // requested{Width|Height} Surface's physical size
2430 // attrs.{width|height} Size on screen
2431 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2432 mHScale = (mAttrs.width != requestedWidth) ?
2433 (mAttrs.width / (float)requestedWidth) : 1.0f;
2434 mVScale = (mAttrs.height != requestedHeight) ?
2435 (mAttrs.height / (float)requestedHeight) : 1.0f;
2436 } else {
2437 mHScale = mVScale = 1;
2438 }
2439 }
2440
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002441 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002442 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002443 public void binderDied() {
2444 try {
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002445 boolean resetSplitScreenResizing = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002446 synchronized(mService.mWindowMap) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002447 final WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002448 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002449 if (win != null) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002450 final DisplayContent dc = getDisplayContent();
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002451 if (win.mAppToken != null && win.mAppToken.findMainWindow() == win) {
2452 mService.mTaskSnapshotController.onAppDied(win.mAppToken);
2453 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002454 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002455 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2456 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002457 // just in case they have the divider at an unstable position. Better
2458 // also reset drag resizing state, because the owner can't do it
2459 // anymore.
Wale Ogunwale61911492017-10-11 08:50:50 -07002460 final TaskStack stack =
Matthew Ng64e77cf2017-10-31 14:01:31 -07002461 dc.getSplitScreenPrimaryStackIgnoringVisibility();
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002462 if (stack != null) {
2463 stack.resetDockedStackToMiddle();
2464 }
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002465 resetSplitScreenResizing = true;
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002466 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002467 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002468 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002469 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002470 }
2471 }
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002472 if (resetSplitScreenResizing) {
2473 try {
2474 // Note: this calls into ActivityManager, so we must *not* hold the window
2475 // manager lock while calling this.
2476 mService.mActivityManager.setSplitScreenResizing(false);
2477 } catch (RemoteException e) {
2478 // Local call, shouldn't return RemoteException.
2479 throw e.rethrowAsRuntimeException();
2480 }
2481 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002482 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002483 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002484 }
2485 }
2486 }
2487
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002488 /**
2489 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2490 * because we want to preserve its location on screen to be re-activated later when the user
2491 * interacts with it.
2492 */
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002493 private boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwale89973222017-04-23 18:39:45 -07002494 if (!isWinVisibleLw() || mAppToken == null || mAppToken.isClientHidden()) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002495 // Not a visible app window or the app isn't dead.
2496 return false;
2497 }
2498
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002499 if (mAttrs.token != mClient.asBinder()) {
2500 // The window was add by a client using another client's app token. We don't want to
2501 // keep the dead window around for this case since this is meant for 'real' apps.
2502 return false;
2503 }
2504
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002505 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2506 // We don't keep starting windows since they were added by the window manager before
2507 // the app even launched.
2508 return false;
2509 }
2510
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002511 return getWindowConfiguration().keepVisibleDeadAppWindowOnScreen();
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002512 }
2513
Wale Ogunwaled045c822015-12-02 09:14:28 -08002514 /** @return true if this window desires key events. */
2515 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002516 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002517 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002518 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002519 && (mAppToken == null || mAppToken.windowsAreFocusable())
Matthew Nge15352e2016-12-20 15:36:29 -08002520 && !canReceiveTouchInput();
2521 }
2522
2523 /** @return true if this window desires touch events. */
2524 boolean canReceiveTouchInput() {
Bryce Lee6d410262017-02-28 15:30:17 -08002525 return mAppToken != null && mAppToken.getTask() != null
2526 && mAppToken.getTask().mStack.shouldIgnoreInput();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002527 }
2528
Craig Mautner749a7bb2012-04-02 13:49:53 -07002529 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002530 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002531 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002532 }
2533
Craig Mautner749a7bb2012-04-02 13:49:53 -07002534 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002535 public boolean showLw(boolean doAnimation) {
2536 return showLw(doAnimation, true);
2537 }
2538
2539 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002540 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002541 return false;
2542 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002543 if (!mAppOpVisibility) {
2544 // Being hidden due to app op request.
2545 return false;
2546 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002547 if (mPermanentlyHidden) {
2548 // Permanently hidden until the app exists as apps aren't prepared
2549 // to handle their windows being removed from under them.
2550 return false;
2551 }
Suprabh Shukla69c71422018-04-02 18:39:01 -07002552 if (mHiddenWhileSuspended) {
2553 // Being hidden due to owner package being suspended.
2554 return false;
2555 }
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002556 if (mForceHideNonSystemOverlayWindow) {
2557 // This is an alert window that is currently force hidden.
2558 return false;
2559 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002560 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002561 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002562 return false;
2563 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002564 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002565 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002566 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Jorim Jaggia5e10572017-11-15 14:36:26 +01002567 + mPolicyVisibility + " isAnimationSet=" + mWinAnimator.isAnimationSet());
David Stevens9440dc82017-03-16 19:00:20 -07002568 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002569 doAnimation = false;
Jorim Jaggia5e10572017-11-15 14:36:26 +01002570 } else if (mPolicyVisibility && !mWinAnimator.isAnimationSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002571 // Check for the case where we are currently visible and
2572 // not animating; we do not want to do animation at such a
2573 // point to become visible when we already are.
2574 doAnimation = false;
2575 }
2576 }
2577 mPolicyVisibility = true;
2578 mPolicyVisibilityAfterAnim = true;
2579 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002580 mWinAnimator.applyAnimationLocked(TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002581 }
2582 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002583 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002584 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002585 if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) {
2586 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2587 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002588 return true;
2589 }
2590
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002591 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002592 public boolean hideLw(boolean doAnimation) {
2593 return hideLw(doAnimation, true);
2594 }
2595
2596 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2597 if (doAnimation) {
David Stevens9440dc82017-03-16 19:00:20 -07002598 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002599 doAnimation = false;
2600 }
2601 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002602 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002603 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002604 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002605 return false;
2606 }
2607 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002608 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
Jorim Jaggia5e10572017-11-15 14:36:26 +01002609 if (!mWinAnimator.isAnimationSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002610 doAnimation = false;
2611 }
2612 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002613 mPolicyVisibilityAfterAnim = false;
2614 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002615 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002616 mPolicyVisibility = false;
2617 // Window is no longer visible -- make sure if we were waiting
2618 // for it to be displayed before enabling the display, that
2619 // we allow the display to be enabled now.
2620 mService.enableScreenIfNeededLocked();
2621 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002622 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002623 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002624 mService.mFocusMayChange = true;
2625 }
2626 }
2627 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002628 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002629 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002630 if (mService.mCurrentFocus == this) {
2631 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2632 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002633 return true;
2634 }
2635
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002636 void setForceHideNonSystemOverlayWindowIfNeeded(boolean forceHide) {
2637 if (mOwnerCanAddInternalSystemWindow
2638 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2639 return;
2640 }
2641 if (mForceHideNonSystemOverlayWindow == forceHide) {
2642 return;
2643 }
2644 mForceHideNonSystemOverlayWindow = forceHide;
2645 if (forceHide) {
2646 hideLw(true /* doAnimation */, true /* requestAnim */);
2647 } else {
2648 showLw(true /* doAnimation */, true /* requestAnim */);
2649 }
2650 }
2651
Suprabh Shukla69c71422018-04-02 18:39:01 -07002652 void setHiddenWhileSuspended(boolean hide) {
2653 if (mOwnerCanAddInternalSystemWindow
2654 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2655 return;
2656 }
2657 if (mHiddenWhileSuspended == hide) {
2658 return;
2659 }
2660 mHiddenWhileSuspended = hide;
2661 if (hide) {
2662 hideLw(true, true);
2663 } else {
2664 showLw(true, true);
2665 }
2666 }
2667
Svet Ganovf7b47252018-02-26 11:11:27 -08002668 private void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002669 if (mAppOpVisibility != state) {
2670 mAppOpVisibility = state;
2671 if (state) {
2672 // If the policy visibility had last been to hide, then this
2673 // will incorrectly show at this point since we lost that
2674 // information. Not a big deal -- for the windows that have app
2675 // ops modifies they should only be hidden by policy due to the
2676 // lock screen, and the user won't be changing this if locked.
2677 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002678 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002679 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002680 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002681 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002682 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002683 }
2684
Svet Ganovf7b47252018-02-26 11:11:27 -08002685 void initAppOpsState() {
2686 if (mAppOp == OP_NONE || !mAppOpVisibility) {
2687 return;
2688 }
2689 // If the app op was MODE_DEFAULT we would have checked the permission
2690 // and add the window only if the permission was granted. Therefore, if
2691 // the mode is MODE_DEFAULT we want the op to succeed as the window is
2692 // shown.
2693 final int mode = mService.mAppOps.startOpNoThrow(mAppOp,
2694 getOwningUid(), getOwningPackage(), true);
2695 if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) {
2696 setAppOpVisibilityLw(false);
2697 }
2698 }
2699
2700 void resetAppOpsState() {
2701 if (mAppOp != OP_NONE && mAppOpVisibility) {
2702 mService.mAppOps.finishOp(mAppOp, getOwningUid(), getOwningPackage());
2703 }
2704 }
2705
2706 void updateAppOpsState() {
2707 if (mAppOp == OP_NONE) {
2708 return;
2709 }
2710 final int uid = getOwningUid();
2711 final String packageName = getOwningPackage();
2712 if (mAppOpVisibility) {
2713 // There is a race between the check and the finish calls but this is fine
2714 // as this would mean we will get another change callback and will reconcile.
2715 int mode = mService.mAppOps.checkOpNoThrow(mAppOp, uid, packageName);
2716 if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) {
2717 mService.mAppOps.finishOp(mAppOp, uid, packageName);
2718 setAppOpVisibilityLw(false);
2719 }
2720 } else {
Svet Ganov522ed242018-03-07 21:40:28 -08002721 final int mode = mService.mAppOps.startOpNoThrow(mAppOp, uid, packageName, true);
Svet Ganovf7b47252018-02-26 11:11:27 -08002722 if (mode == MODE_ALLOWED || mode == MODE_DEFAULT) {
2723 setAppOpVisibilityLw(true);
2724 }
2725 }
2726 }
2727
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002728 public void hidePermanentlyLw() {
2729 if (!mPermanentlyHidden) {
2730 mPermanentlyHidden = true;
2731 hideLw(true, true);
2732 }
2733 }
2734
Jeff Brownc2932a12014-11-20 18:04:05 -08002735 public void pokeDrawLockLw(long timeout) {
2736 if (isVisibleOrAdding()) {
2737 if (mDrawLock == null) {
2738 // We want the tag name to be somewhat stable so that it is easier to correlate
2739 // in wake lock statistics. So in particular, we don't want to include the
2740 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002741 final CharSequence tag = getWindowTag();
chaviw40234662018-02-07 09:37:16 -08002742 mDrawLock = mService.mPowerManager.newWakeLock(DRAW_WAKE_LOCK, "Window:" + tag);
Jeff Brownc2932a12014-11-20 18:04:05 -08002743 mDrawLock.setReferenceCounted(false);
2744 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2745 }
2746 // Each call to acquire resets the timeout.
2747 if (DEBUG_POWER) {
2748 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2749 + mAttrs.packageName);
2750 }
2751 mDrawLock.acquire(timeout);
2752 } else if (DEBUG_POWER) {
2753 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2754 + "owned by " + mAttrs.packageName);
2755 }
2756 }
2757
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002758 @Override
2759 public boolean isAlive() {
2760 return mClient.asBinder().isBinderAlive();
2761 }
2762
Craig Mautnera987d432012-10-11 14:07:58 -07002763 boolean isClosing() {
chaviw4ad54912018-05-30 11:05:44 -07002764 return mAnimatingExit || (mAppToken != null && mAppToken.isClosingOrEnteringPip());
Craig Mautnera987d432012-10-11 14:07:58 -07002765 }
2766
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002767 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2768 animators.add(mWinAnimator);
2769
2770 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002771 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002772 c.addWinAnimatorToList(animators);
2773 }
2774 }
2775
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002776 void sendAppVisibilityToClients() {
2777 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002778
Wale Ogunwale89973222017-04-23 18:39:45 -07002779 final boolean clientHidden = mAppToken.isClientHidden();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002780 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2781 // Don't hide the starting window.
2782 return;
2783 }
2784
Wale Ogunwale89973222017-04-23 18:39:45 -07002785 if (clientHidden) {
2786 // Once we are notifying the client that it's visibility has changed, we need to prevent
2787 // it from destroying child surfaces until the animation has finished. We do this by
2788 // detaching any surface control the client added from the client.
2789 for (int i = mChildren.size() - 1; i >= 0; --i) {
2790 final WindowState c = mChildren.get(i);
2791 c.mWinAnimator.detachChildren();
2792 }
2793
2794 mWinAnimator.detachChildren();
2795 }
2796
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002797 try {
2798 if (DEBUG_VISIBILITY) Slog.v(TAG,
2799 "Setting visibility of " + this + ": " + (!clientHidden));
2800 mClient.dispatchAppVisibility(!clientHidden);
2801 } catch (RemoteException e) {
2802 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002803 }
2804
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002805 void onStartFreezingScreen() {
2806 mAppFreezing = true;
2807 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002808 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002809 c.onStartFreezingScreen();
2810 }
2811 }
2812
2813 boolean onStopFreezingScreen() {
2814 boolean unfrozeWindows = false;
2815 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002816 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002817 unfrozeWindows |= c.onStopFreezingScreen();
2818 }
2819
2820 if (!mAppFreezing) {
2821 return unfrozeWindows;
2822 }
2823
Wale Ogunwale953171d2016-09-30 09:17:30 -07002824 mAppFreezing = false;
2825
Bryce Lee8c3cf382017-07-06 19:47:10 -07002826 if (mHasSurface && !getOrientationChanging()
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002827 && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
2828 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
Bryce Lee8c3cf382017-07-06 19:47:10 -07002829 setOrientationChanging(true);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002830 mService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002831 }
2832 mLastFreezeDuration = 0;
2833 setDisplayLayoutNeeded();
2834 return true;
2835 }
2836
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002837 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2838 boolean destroyedSomething = false;
Jorim Jaggi59f3e922018-01-05 15:40:32 +01002839
2840 // Copying to a different list as multiple children can be removed.
2841 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
2842 for (int i = childWindows.size() - 1; i >= 0; --i) {
2843 final WindowState c = childWindows.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002844 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2845 }
2846
Robert Carrdb2f6e62017-03-01 20:17:58 -08002847 if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) {
2848 return destroyedSomething;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002849 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08002850
2851 if (appStopped || mWindowRemovalAllowed) {
2852 mWinAnimator.destroyPreservedSurfaceLocked();
2853 }
2854
2855 if (mDestroying) {
2856 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2857 + " destroySurfaces: appStopped=" + appStopped
2858 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2859 + " win.mRemoveOnExit=" + mRemoveOnExit);
2860 if (!cleanupOnResume || mRemoveOnExit) {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002861 destroySurfaceUnchecked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08002862 }
2863 if (mRemoveOnExit) {
2864 removeImmediately();
2865 }
2866 if (cleanupOnResume) {
2867 requestUpdateWallpaperIfNeeded();
2868 }
2869 mDestroying = false;
2870 destroyedSomething = true;
2871 }
2872
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002873 return destroyedSomething;
2874 }
Chris Craik3131bde2016-05-06 13:39:08 -07002875
Robert Carr89a28ab2017-04-24 15:33:11 -07002876 // Destroy or save the application surface without checking
2877 // various indicators of whether the client has released the surface.
2878 // This is in general unsafe, and most callers should use {@link #destroySurface}
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002879 void destroySurfaceUnchecked() {
2880 mWinAnimator.destroySurfaceLocked();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002881
Chong Zhang92147042016-05-09 12:47:11 -07002882 // Clear animating flags now, since the surface is now gone. (Note this is true even
2883 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2884 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002885 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002886
Craig Mautner69b08182012-09-05 13:07:13 -07002887 @Override
2888 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002889 final DisplayContent displayContent = getDisplayContent();
2890 if (displayContent == null) {
2891 // Only a window that was on a non-default display can be detached from it.
2892 return false;
2893 }
Winson Chung47a3e652014-05-21 16:03:42 -07002894 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002895 }
2896
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002897 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07002898 mShowToOwnerOnly = showToOwnerOnly;
2899 }
2900
Wale Ogunwaleea92d972016-12-08 07:33:13 -08002901 private boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002902 // Child windows are evaluated based on their parent window.
2903 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002904 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale72919d22016-12-08 18:58:50 -08002905 && win.mAppToken != null && win.mAppToken.mShowForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002906
2907 // All window frames that are fullscreen extend above status bar, but some don't extend
2908 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2909 // bottom right.
2910 if (win.mFrame.left <= win.mDisplayFrame.left
2911 && win.mFrame.top <= win.mDisplayFrame.top
2912 && win.mFrame.right >= win.mStableFrame.right
2913 && win.mFrame.bottom >= win.mStableFrame.bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002914 // Is a fullscreen window, like the clock alarm. Show to everyone.
2915 return false;
2916 }
2917 }
2918
Craig Mautner341220f2012-10-16 15:20:09 -07002919 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01002920 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002921 }
2922
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002923 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2924 outRegion.set(
2925 frame.left + inset.left, frame.top + inset.top,
2926 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002927 }
2928
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002929 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002930 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002931 switch (mTouchableInsets) {
2932 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002933 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002934 outRegion.set(frame);
2935 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002936 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002937 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002938 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002939 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002940 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002941 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002942 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002943 outRegion.set(mGivenTouchableRegion);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002944 outRegion.translate(frame.left, frame.top);
2945 break;
2946 }
2947 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002948 cropRegionToStackBoundsIfNeeded(outRegion);
2949 }
2950
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002951 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002952 final Task task = getTask();
2953 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002954 return;
2955 }
2956
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002957 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002958 if (stack == null) {
2959 return;
2960 }
2961
2962 stack.getDimBounds(mTmpRect);
2963 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002964 }
2965
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002966 /**
2967 * Report a focus change. Must be called with no locks held, and consistently
2968 * from the same serialized thread (such as dispatched from a handler).
2969 */
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07002970 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002971 try {
2972 mClient.windowFocusChanged(focused, inTouchMode);
2973 } catch (RemoteException e) {
2974 }
2975 if (mFocusCallbacks != null) {
2976 final int N = mFocusCallbacks.beginBroadcast();
2977 for (int i=0; i<N; i++) {
2978 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2979 try {
2980 if (focused) {
2981 obs.focusGained(mWindowId.asBinder());
2982 } else {
2983 obs.focusLost(mWindowId.asBinder());
2984 }
2985 } catch (RemoteException e) {
2986 }
2987 }
2988 mFocusCallbacks.finishBroadcast();
2989 }
2990 }
2991
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002992 @Override
2993 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002994 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002995 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002996 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002997
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002998 return super.getConfiguration();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002999 }
3000
Craig Mautnerdf88d732014-01-27 09:21:32 -08003001 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003002 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08003003 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003004 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
3005 + ": " + mCompatFrame);
Bryce Leef858b572017-06-29 14:03:33 -07003006 final MergedConfiguration mergedConfiguration =
3007 new MergedConfiguration(mService.mRoot.getConfiguration(),
3008 getMergedOverrideConfiguration());
3009
Bryce Lee2b17afd2017-09-21 10:38:20 -07003010 setLastReportedMergedConfiguration(mergedConfiguration);
Bryce Leef858b572017-06-29 14:03:33 -07003011
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003012 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003013 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
3014
Craig Mautnerdf88d732014-01-27 09:21:32 -08003015 final Rect frame = mFrame;
3016 final Rect overscanInsets = mLastOverscanInsets;
3017 final Rect contentInsets = mLastContentInsets;
3018 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07003019 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003020 final Rect outsets = mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003021 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003022 final boolean reportOrientation = mReportOrientationChanged;
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003023 final int displayId = getDisplayId();
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01003024 final DisplayCutout displayCutout = mDisplayCutout.getDisplayCutout();
Chet Haase8eb48d22014-09-24 07:31:29 -07003025 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
3026 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08003027 // To prevent deadlock simulate one-way call if win.mClient is a local object.
3028 mService.mH.post(new Runnable() {
3029 @Override
3030 public void run() {
3031 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003032 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003033 stableInsets, outsets, reportDraw, mergedConfiguration,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003034 reportOrientation, displayId, displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003035 } catch (RemoteException e) {
3036 // Not a remote call, RemoteException won't be raised.
3037 }
3038 }
3039 });
3040 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003041 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003042 outsets, reportDraw, mergedConfiguration, reportOrientation, displayId,
3043 displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003044 }
Svetoslav4604abc2014-06-10 18:59:30 -07003045
3046 //TODO (multidisplay): Accessibility supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07003047 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07003048 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07003049 }
3050
Craig Mautnerdf88d732014-01-27 09:21:32 -08003051 mOverscanInsetsChanged = false;
3052 mContentInsetsChanged = false;
3053 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07003054 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003055 mOutsetsChanged = false;
Robert Carr31aa98b2016-07-20 15:29:03 -07003056 mFrameSizeChanged = false;
Adrian Roos5c6b6222017-11-07 17:36:10 +01003057 mDisplayCutoutChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003058 mWinAnimator.mSurfaceResized = false;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003059 mReportOrientationChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003060 } catch (RemoteException e) {
Bryce Lee8c3cf382017-07-06 19:47:10 -07003061 setOrientationChanging(false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003062 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
3063 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08003064 // We are assuming the hosting process is dead or in a zombie state.
3065 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
3066 + ", removing this window.");
3067 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07003068 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003069 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003070 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003071 }
3072
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003073 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08003074 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
3075 // start even if we haven't received the relayout window, so that the client requests
3076 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
3077 // until the window to small size, otherwise the multithread renderer will shift last
3078 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
3079 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003080 boolean resizing = isDragResizing() || isDragResizeChanged();
Wale Ogunwale3382ab12017-07-27 08:55:03 -07003081 if (getWindowConfiguration().useWindowFrameForBackdrop() || !resizing) {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003082 return frame;
3083 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07003084 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003085 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003086 return mTmpRect;
3087 }
3088
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003089 private int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003090 final TaskStack stack = getStack();
3091 if (stack == null) {
3092 return INVALID_STACK_ID;
3093 }
3094 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003095 }
3096
3097 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
3098 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003099 MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId,
3100 DisplayCutout displayCutout)
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003101 throws RemoteException {
Robert Carr09286c92018-02-15 13:52:31 -08003102 final boolean forceRelayout = isDragResizeChanged() || reportOrientation;
Chong Zhangedaf3052016-04-22 15:04:31 -07003103
Jorim Jaggidc249c42015-12-15 14:57:31 -08003104 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003105 reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003106 mPolicy.isNavBarForcedShownLw(this), displayId,
3107 new DisplayCutout.ParcelableWrapper(displayCutout));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003108 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003109 }
3110
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003111 public void registerFocusObserver(IWindowFocusObserver observer) {
3112 synchronized(mService.mWindowMap) {
3113 if (mFocusCallbacks == null) {
3114 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
3115 }
3116 mFocusCallbacks.register(observer);
3117 }
3118 }
3119
3120 public void unregisterFocusObserver(IWindowFocusObserver observer) {
3121 synchronized(mService.mWindowMap) {
3122 if (mFocusCallbacks != null) {
3123 mFocusCallbacks.unregister(observer);
3124 }
3125 }
3126 }
3127
3128 public boolean isFocused() {
3129 synchronized(mService.mWindowMap) {
3130 return mService.mCurrentFocus == this;
3131 }
3132 }
3133
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003134 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07003135 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003136 final Task task = getTask();
3137 return task != null && !task.isFullscreen();
3138 }
3139
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003140 /** Is this window in a container that takes up the entire screen space? */
3141 private boolean inFullscreenContainer() {
Bryce Leef3c6a472017-11-14 14:53:06 -08003142 return mAppToken == null || (mAppToken.matchParentBounds() && !isInMultiWindowMode());
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003143 }
3144
Andrii Kulian283acd22017-08-03 04:03:51 -07003145 /** @return true when the window is in fullscreen task, but has non-fullscreen bounds set. */
3146 boolean isLetterboxedAppWindow() {
Adrian Roos865c70f2018-01-10 17:32:27 +01003147 return !isInMultiWindowMode() && mAppToken != null && !mAppToken.matchParentBounds()
3148 || isLetterboxedForDisplayCutoutLw();
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003149 }
3150
Adrian Roos865c70f2018-01-10 17:32:27 +01003151 @Override
3152 public boolean isLetterboxedForDisplayCutoutLw() {
3153 if (mAppToken == null) {
3154 // Only windows with an AppWindowToken are letterboxed.
3155 return false;
3156 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003157 if (!mParentFrameWasClippedByDisplayCutout) {
3158 // Cutout didn't make a difference, no letterbox
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003159 return false;
3160 }
Adrian Roosfa02da62018-01-15 16:01:18 +01003161 if (mAttrs.layoutInDisplayCutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003162 // Layout in cutout, no letterbox.
3163 return false;
3164 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003165 if (!mAttrs.isFullscreen()) {
3166 // Not filling the parent frame, no letterbox
3167 return false;
Adrian Roosfa02da62018-01-15 16:01:18 +01003168 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003169 // Otherwise we need a letterbox if the layout was smaller than the app window token allowed
3170 // it to be.
3171 return !frameCoversEntireAppTokenBounds();
3172 }
3173
3174 /**
3175 * @return true if this window covers the entire bounds of its app window token
3176 * @throws NullPointerException if there is no app window token for this window
3177 */
3178 private boolean frameCoversEntireAppTokenBounds() {
3179 mTmpRect.set(mAppToken.getBounds());
3180 mTmpRect.intersectUnchecked(mFrame);
3181 return mAppToken.getBounds().equals(mTmpRect);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003182 }
3183
Adrian Roos23df3a32018-03-15 15:41:13 +01003184 @Override
3185 public boolean isLetterboxedOverlappingWith(Rect rect) {
3186 return mAppToken != null && mAppToken.isLetterboxOverlappingWith(rect);
3187 }
3188
Chong Zhang3005e752015-09-18 18:46:28 -07003189 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003190 return mDragResizing != computeDragResizing();
3191 }
3192
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003193 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003194 void setWaitingForDrawnIfResizingChanged() {
3195 if (isDragResizeChanged()) {
3196 mService.mWaitingForDrawn.add(this);
3197 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003198 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003199 }
3200
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003201 /**
3202 * @return Whether we reported a drag resize change to the application or not already.
3203 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003204 private boolean isDragResizingChangeReported() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003205 return mDragResizingChangeReported;
3206 }
3207
3208 /**
3209 * Resets the state whether we reported a drag resize change to the app.
3210 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003211 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003212 void resetDragResizingChangeReported() {
3213 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003214 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003215 }
3216
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003217 int getResizeMode() {
3218 return mResizeMode;
3219 }
3220
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003221 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003222 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003223 if (task == null) {
3224 return false;
3225 }
Tomasz Mikolajewskiaf20b8d2017-11-20 16:11:33 +09003226 if (!inSplitScreenWindowingMode() && !inFreeformWindowingMode()) {
Winson Chung2af04b32017-01-24 16:21:13 -08003227 return false;
3228 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003229 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003230 // Floating windows never enter drag resize mode.
3231 return false;
3232 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003233 if (task.isDragResizing()) {
3234 return true;
3235 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003236
3237 // If the bounds are currently frozen, it means that the layout size that the app sees
3238 // and the bounds we clip this window to might be different. In order to avoid holes, we
3239 // simulate that we are still resizing so the app fills the hole with the resizing
3240 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003241 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003242 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003243 !task.inFreeformWindowingMode() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003244
Chong Zhang3005e752015-09-18 18:46:28 -07003245 }
3246
3247 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003248 final boolean resizing = computeDragResizing();
3249 if (resizing == mDragResizing) {
3250 return;
3251 }
3252 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003253 final Task task = getTask();
3254 if (task != null && task.isDragResizing()) {
3255 mResizeMode = task.getDragResizeMode();
3256 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003257 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003258 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3259 : DRAG_RESIZE_MODE_FREEFORM;
3260 }
Chong Zhang3005e752015-09-18 18:46:28 -07003261 }
3262
3263 boolean isDragResizing() {
3264 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003265 }
3266
Robert Carr2487ce72016-04-07 15:18:45 -07003267 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003268 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3269 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003270 }
3271
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07003272 @CallSuper
3273 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02003274 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003275 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02003276 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003277 writeIdentifierToProto(proto, IDENTIFIER);
3278 proto.write(DISPLAY_ID, getDisplayId());
3279 proto.write(STACK_ID, getStackId());
3280 mAttrs.writeToProto(proto, ATTRIBUTES);
3281 mGivenContentInsets.writeToProto(proto, GIVEN_CONTENT_INSETS);
3282 mFrame.writeToProto(proto, FRAME);
3283 mContainingFrame.writeToProto(proto, CONTAINING_FRAME);
3284 mParentFrame.writeToProto(proto, PARENT_FRAME);
3285 mContentFrame.writeToProto(proto, CONTENT_FRAME);
3286 mContentInsets.writeToProto(proto, CONTENT_INSETS);
3287 mAttrs.surfaceInsets.writeToProto(proto, SURFACE_INSETS);
Jorim Jaggi45be1c4c2017-12-15 18:44:43 +01003288 mSurfacePosition.writeToProto(proto, SURFACE_POSITION);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003289 mWinAnimator.writeToProto(proto, ANIMATOR);
3290 proto.write(ANIMATING_EXIT, mAnimatingExit);
3291 for (int i = 0; i < mChildren.size(); i++) {
Adrian Roos4921ccf2017-09-28 16:54:06 +02003292 mChildren.get(i).writeToProto(proto, CHILD_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003293 }
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003294 proto.write(REQUESTED_WIDTH, mRequestedWidth);
3295 proto.write(REQUESTED_HEIGHT, mRequestedHeight);
3296 proto.write(VIEW_VISIBILITY, mViewVisibility);
3297 proto.write(SYSTEM_UI_VISIBILITY, mSystemUiVisibility);
3298 proto.write(HAS_SURFACE, mHasSurface);
3299 proto.write(IS_READY_FOR_DISPLAY, isReadyForDisplay());
3300 mDisplayFrame.writeToProto(proto, DISPLAY_FRAME);
3301 mOverscanFrame.writeToProto(proto, OVERSCAN_FRAME);
3302 mVisibleFrame.writeToProto(proto, VISIBLE_FRAME);
3303 mDecorFrame.writeToProto(proto, DECOR_FRAME);
3304 mOutsetFrame.writeToProto(proto, OUTSET_FRAME);
3305 mOverscanInsets.writeToProto(proto, OVERSCAN_INSETS);
3306 mVisibleInsets.writeToProto(proto, VISIBLE_INSETS);
3307 mStableInsets.writeToProto(proto, STABLE_INSETS);
3308 mOutsets.writeToProto(proto, OUTSETS);
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01003309 mDisplayCutout.getDisplayCutout().writeToProto(proto, CUTOUT);
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003310 proto.write(REMOVE_ON_EXIT, mRemoveOnExit);
3311 proto.write(DESTROYING, mDestroying);
3312 proto.write(REMOVED, mRemoved);
3313 proto.write(IS_ON_SCREEN, isOnScreen());
3314 proto.write(IS_VISIBLE, isVisible());
Adrian Roos2cadc5c2018-07-06 02:39:54 -07003315 if (mForceSeamlesslyRotate) {
3316 proto.write(PENDING_FORCED_SEAMLESS_ROTATION, mPendingForcedSeamlessRotate != null);
3317 proto.write(FINISHED_FORCED_SEAMLESS_ROTATION_FRAME,
3318 mFinishForcedSeamlessRotateFrameNumber);
3319 }
Steven Timotiusaf03df62017-07-18 16:56:43 -07003320 proto.end(token);
3321 }
3322
Vishnu Nair9a3e4062018-01-11 08:42:54 -08003323 @Override
3324 public void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003325 final long token = proto.start(fieldId);
3326 proto.write(HASH_CODE, System.identityHashCode(this));
3327 proto.write(USER_ID, UserHandle.getUserId(mOwnerUid));
3328 final CharSequence title = getWindowTag();
3329 if (title != null) {
3330 proto.write(TITLE, title.toString());
3331 }
3332 proto.end(token);
3333 }
3334
Jorim Jaggia5e10572017-11-15 14:36:26 +01003335 @Override
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003336 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003337 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003338 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003339 if (stack != null) {
3340 pw.print(" stackId="); pw.print(stack.mStackId);
3341 }
Craig Mautner59c00972012-07-30 12:10:24 -07003342 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003343 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07003344 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08003345 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
3346 pw.print(" package="); pw.print(mAttrs.packageName);
3347 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Jorim Jaggi484851b2017-09-22 16:03:27 +02003348 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs.toString(prefix));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003349 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
3350 pw.print(" h="); pw.print(mRequestedHeight);
3351 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003352 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
3353 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
3354 pw.print(" h="); pw.println(mLastRequestedHeight);
3355 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003356 if (mIsChildWindow || mLayoutAttached) {
3357 pw.print(prefix); pw.print("mParentWindow="); pw.print(getParentWindow());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003358 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
3359 }
3360 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
3361 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
3362 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
3363 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
3364 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
3365 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003366 if (dumpAll) {
3367 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3368 pw.print(" mSubLayer="); pw.print(mSubLayer);
3369 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautnerc2f9be02012-03-27 17:32:29 -07003370 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
3371 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003372 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003373 if (dumpAll) {
3374 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003375 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003376 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
3377 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Bryce Lee6311c4b2017-07-06 14:09:29 -07003378 pw.print(" mAppDied=");pw.print(mAppDied);
3379 pw.print(prefix); pw.print("drawnStateEvaluated=");
3380 pw.print(getDrawnStateEvaluated());
3381 pw.print(prefix); pw.print("mightAffectAllDrawn=");
Jorim Jaggie7d2b852017-08-28 17:55:15 +02003382 pw.println(mightAffectAllDrawn());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003383 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003384 pw.print(prefix); pw.print("mViewVisibility=0x");
3385 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003386 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
3387 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07003388 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
3389 pw.print(" mSystemUiVisibility=0x");
3390 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003391 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003392 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
Suprabh Shukla69c71422018-04-02 18:39:01 -07003393 || isParentWindowHidden()|| mPermanentlyHidden || mForceHideNonSystemOverlayWindow
3394 || mHiddenWhileSuspended) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003395 pw.print(prefix); pw.print("mPolicyVisibility=");
3396 pw.print(mPolicyVisibility);
3397 pw.print(" mPolicyVisibilityAfterAnim=");
3398 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003399 pw.print(" mAppOpVisibility=");
3400 pw.print(mAppOpVisibility);
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003401 pw.print(" parentHidden="); pw.print(isParentWindowHidden());
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003402 pw.print(" mPermanentlyHidden="); pw.print(mPermanentlyHidden);
Suprabh Shukla69c71422018-04-02 18:39:01 -07003403 pw.print(" mHiddenWhileSuspended="); pw.print(mHiddenWhileSuspended);
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003404 pw.print(" mForceHideNonSystemOverlayWindow="); pw.println(
3405 mForceHideNonSystemOverlayWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003406 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003407 if (!mRelayoutCalled || mLayoutNeeded) {
3408 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
3409 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003410 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003411 if (dumpAll) {
3412 pw.print(prefix); pw.print("mGivenContentInsets=");
3413 mGivenContentInsets.printShortString(pw);
3414 pw.print(" mGivenVisibleInsets=");
3415 mGivenVisibleInsets.printShortString(pw);
3416 pw.println();
3417 if (mTouchableInsets != 0 || mGivenInsetsPending) {
3418 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
3419 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003420 Region region = new Region();
3421 getTouchableRegion(region);
3422 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003423 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003424 pw.print(prefix); pw.print("mFullConfiguration="); pw.println(getConfiguration());
3425 pw.print(prefix); pw.print("mLastReportedConfiguration=");
Bryce Lee2b17afd2017-09-21 10:38:20 -07003426 pw.println(getLastReportedConfiguration());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003427 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07003428 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Chong Zhanga8975bd2016-01-28 17:13:47 -08003429 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08003430 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003431 if (dumpAll) {
3432 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
3433 pw.print(" last="); mLastFrame.printShortString(pw);
3434 pw.println();
3435 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003436 if (mEnforceSizeCompat) {
3437 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003438 pw.println();
3439 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003440 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003441 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003442 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003443 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003444 pw.println();
3445 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
3446 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003447 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003448 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003449 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003450 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04003451 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
3452 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003453 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
3454 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003455 pw.print(prefix); pw.print("Cur insets: overscan=");
3456 mOverscanInsets.printShortString(pw);
3457 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003458 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003459 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003460 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003461 pw.print(" outsets="); mOutsets.printShortString(pw);
Adrian Roos6a4fa0e2018-03-05 19:50:16 +01003462 pw.print(" cutout=" + mDisplayCutout.getDisplayCutout());
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003463 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003464 pw.print(prefix); pw.print("Lst insets: overscan=");
3465 mLastOverscanInsets.printShortString(pw);
3466 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003467 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003468 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003469 pw.print(" physical="); mLastOutsets.printShortString(pw);
3470 pw.print(" outset="); mLastOutsets.printShortString(pw);
Adrian Roos5c6b6222017-11-07 17:36:10 +01003471 pw.print(" cutout=" + mLastDisplayCutout);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003472 pw.println();
3473 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01003474 super.dump(pw, prefix, dumpAll);
Dianne Hackborn529e7442012-11-01 14:22:28 -07003475 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
3476 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003477 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
3478 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003479 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
3480 pw.print(" mDestroying="); pw.print(mDestroying);
3481 pw.print(" mRemoved="); pw.println(mRemoved);
3482 }
chaviw40234662018-02-07 09:37:16 -08003483 if (getOrientationChanging() || mAppFreezing || mReportOrientationChanged) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003484 pw.print(prefix); pw.print("mOrientationChanging=");
3485 pw.print(mOrientationChanging);
Bryce Lee8c3cf382017-07-06 19:47:10 -07003486 pw.print(" configOrientationChanging=");
Bryce Lee2b17afd2017-09-21 10:38:20 -07003487 pw.print(getLastReportedConfiguration().orientation
Bryce Lee8c3cf382017-07-06 19:47:10 -07003488 != getConfiguration().orientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003489 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
Andrii Kulianb2e37802017-01-11 00:36:44 -08003490 pw.print(" mReportOrientationChanged="); pw.println(mReportOrientationChanged);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003491 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003492 if (mLastFreezeDuration != 0) {
3493 pw.print(prefix); pw.print("mLastFreezeDuration=");
3494 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
3495 }
Adrian Roos2cadc5c2018-07-06 02:39:54 -07003496 if (mForceSeamlesslyRotate) {
3497 pw.print(prefix); pw.print("forceSeamlesslyRotate: pending=");
3498 if (mPendingForcedSeamlessRotate != null) {
3499 mPendingForcedSeamlessRotate.dump(pw);
3500 } else {
3501 pw.print("null");
3502 }
3503 pw.print(" finishedFrameNumber="); pw.print(mFinishForcedSeamlessRotateFrameNumber);
3504 pw.println();
3505 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003506 if (mHScale != 1 || mVScale != 1) {
3507 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
3508 pw.print(" mVScale="); pw.println(mVScale);
3509 }
3510 if (mWallpaperX != -1 || mWallpaperY != -1) {
3511 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
3512 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
3513 }
3514 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
3515 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
3516 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
3517 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003518 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3519 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
3520 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
3521 pw.print(mWallpaperDisplayOffsetX);
3522 pw.print(" mWallpaperDisplayOffsetY=");
3523 pw.println(mWallpaperDisplayOffsetY);
3524 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003525 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07003526 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003527 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003528 if (isDragResizing()) {
3529 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
3530 }
3531 if (computeDragResizing()) {
3532 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
3533 }
Bryce Lee6311c4b2017-07-06 14:09:29 -07003534 pw.print(prefix); pw.println("isOnScreen=" + isOnScreen());
3535 pw.print(prefix); pw.println("isVisible=" + isVisible());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003536 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003537
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003538 @Override
3539 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003540 return Integer.toHexString(System.identityHashCode(this))
Jorim Jaggia5e10572017-11-15 14:36:26 +01003541 + " " + getWindowTag();
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003542 }
3543
Robert Carra1eb4392015-12-10 12:43:51 -08003544 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003545 CharSequence tag = mAttrs.getTitle();
3546 if (tag == null || tag.length() <= 0) {
3547 tag = mAttrs.packageName;
3548 }
3549 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003550 }
3551
3552 @Override
3553 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003554 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003555 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003556 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003557 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003558 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003559 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003560 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003561 }
3562 return mStringNameCache;
3563 }
Robert Carr58f29132015-10-29 14:19:05 -07003564
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003565 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003566 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003567 clipRect.left = (int) (clipRect.left / mHScale);
3568 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003569 }
3570 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003571 clipRect.top = (int) (clipRect.top / mVScale);
3572 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003573 }
3574 }
Robert Carr31e28482015-12-02 16:53:18 -08003575
Jorim Jaggif5834272016-04-04 20:25:41 -07003576 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
3577 final int pw = containingFrame.width();
3578 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003579 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003580 final boolean inNonFullscreenContainer = !inFullscreenContainer();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003581 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3582
3583 // We need to fit it to the display if either
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003584 // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen
3585 // for the taskless windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003586 // 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 -07003587 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on
3588 // screen, but SurfaceViews want to be always at a specific location so we don't fit it to
3589 // the display.
3590 final boolean fitToDisplay = (task == null || !inNonFullscreenContainer)
Robert Carr6f44db12016-07-21 14:54:43 -07003591 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003592 float x, y;
3593 int w,h;
3594
3595 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3596 if (mAttrs.width < 0) {
3597 w = pw;
3598 } else if (mEnforceSizeCompat) {
3599 w = (int)(mAttrs.width * mGlobalScale + .5f);
3600 } else {
3601 w = mAttrs.width;
3602 }
3603 if (mAttrs.height < 0) {
3604 h = ph;
3605 } else if (mEnforceSizeCompat) {
3606 h = (int)(mAttrs.height * mGlobalScale + .5f);
3607 } else {
3608 h = mAttrs.height;
3609 }
3610 } else {
3611 if (mAttrs.width == MATCH_PARENT) {
3612 w = pw;
3613 } else if (mEnforceSizeCompat) {
3614 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3615 } else {
3616 w = mRequestedWidth;
3617 }
3618 if (mAttrs.height == MATCH_PARENT) {
3619 h = ph;
3620 } else if (mEnforceSizeCompat) {
3621 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3622 } else {
3623 h = mRequestedHeight;
3624 }
3625 }
3626
3627 if (mEnforceSizeCompat) {
3628 x = mAttrs.x * mGlobalScale;
3629 y = mAttrs.y * mGlobalScale;
3630 } else {
3631 x = mAttrs.x;
3632 y = mAttrs.y;
3633 }
3634
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003635 if (inNonFullscreenContainer && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003636 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003637 // required by {@link Gravity#apply} call.
3638 w = Math.min(w, pw);
3639 h = Math.min(h, ph);
3640 }
3641
3642 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003643 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003644 (int) (x + mAttrs.horizontalMargin * pw),
3645 (int) (y + mAttrs.verticalMargin * ph), mFrame);
3646
3647 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003648 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003649 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003650 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003651
3652 // We need to make sure we update the CompatFrame as it is used for
3653 // cropping decisions, etc, on systems where we lack a decor layer.
3654 mCompatFrame.set(mFrame);
3655 if (mEnforceSizeCompat) {
3656 // See comparable block in computeFrameLw.
3657 mCompatFrame.scale(mInvGlobalScale);
3658 }
Robert Carr31e28482015-12-02 16:53:18 -08003659 }
Robert Carr51a1b872015-12-08 14:03:13 -08003660
3661 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003662 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003663 }
3664
Robert Carrf3b72c72016-03-21 18:16:39 -07003665 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003666 return mIsChildWindow
3667 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003668 }
3669
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003670 /**
3671 * Returns true if any window added by an application process that if of type
3672 * {@link android.view.WindowManager.LayoutParams#TYPE_TOAST} or that requires that requires
3673 * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when
3674 * this window is visible.
3675 */
3676 boolean hideNonSystemOverlayWindowsWhenVisible() {
3677 return (mAttrs.privateFlags & PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != 0
3678 && mSession.mCanHideNonSystemOverlayWindows;
3679 }
3680
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003681 /** Returns the parent window if this is a child of another window, else null. */
3682 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003683 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3684 // WindowContainer that isn't a WindowState.
3685 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003686 }
3687
3688 /** Returns the topmost parent window if this is a child of another window, else this. */
3689 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003690 WindowState current = this;
3691 WindowState topParent = current;
3692 while (current != null && current.mIsChildWindow) {
3693 current = current.getParentWindow();
3694 // Parent window can be null if the child is detached from it's parent already, but
3695 // someone still has a reference to access it. So, we return the top parent value we
3696 // already have instead of null.
3697 if (current != null) {
3698 topParent = current;
3699 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003700 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003701 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003702 }
3703
Wale Ogunwale9d147902016-07-16 11:58:55 -07003704 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003705 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003706 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003707 }
3708
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003709 void setWillReplaceWindow(boolean animate) {
3710 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003711 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003712 c.setWillReplaceWindow(animate);
3713 }
3714
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003715 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3716 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3717 // We don't set replacing on starting windows since they are added by window manager and
3718 // not the client so won't be replaced by the client.
3719 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003720 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003721
3722 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003723 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003724 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003725 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003726
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003727 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003728 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003729 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003730 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003731
3732 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003733 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003734 c.clearWillReplaceWindow();
3735 }
3736 }
3737
3738 boolean waitingForReplacement() {
3739 if (mWillReplaceWindow) {
3740 return true;
3741 }
3742
3743 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003744 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003745 if (c.waitingForReplacement()) {
3746 return true;
3747 }
3748 }
3749 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003750 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003751
Chong Zhang4d7369a2016-04-25 16:09:14 -07003752 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003753 final DisplayContent dc = getDisplayContent();
3754 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3755 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3756 dc.setLayoutNeeded();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003757 mService.mWindowPlacerLocked.requestTraversal();
3758 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003759
3760 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003761 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003762 c.requestUpdateWallpaperIfNeeded();
3763 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003764 }
3765
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003766 float translateToWindowX(float x) {
3767 float winX = x - mFrame.left;
3768 if (mEnforceSizeCompat) {
3769 winX *= mGlobalScale;
3770 }
3771 return winX;
3772 }
3773
3774 float translateToWindowY(float y) {
3775 float winY = y - mFrame.top;
3776 if (mEnforceSizeCompat) {
3777 winY *= mGlobalScale;
3778 }
3779 return winY;
3780 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003781
3782 // During activity relaunch due to resize, we sometimes use window replacement
3783 // for only child windows (as the main window is handled by window preservation)
3784 // and the big surface.
3785 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003786 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3787 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3788 // we also want to replace them at such phases, as they won't be covered by window
3789 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003790 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003791 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003792 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003793 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003794
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003795 void setWillReplaceChildWindows() {
3796 if (shouldBeReplacedWithChildren()) {
3797 setWillReplaceWindow(false /* animate */);
3798 }
3799 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003800 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003801 c.setWillReplaceChildWindows();
3802 }
3803 }
3804
3805 WindowState getReplacingWindow() {
3806 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3807 return this;
3808 }
3809 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003810 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003811 final WindowState replacing = c.getReplacingWindow();
3812 if (replacing != null) {
3813 return replacing;
3814 }
3815 }
3816 return null;
3817 }
3818
Jorim Jaggife762342016-10-13 14:33:27 +02003819 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07003820 public int getRotationAnimationHint() {
3821 if (mAppToken != null) {
3822 return mAppToken.mRotationAnimationHint;
3823 } else {
3824 return -1;
3825 }
3826 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003827
Jorim Jaggife762342016-10-13 14:33:27 +02003828 @Override
3829 public boolean isInputMethodWindow() {
3830 return mIsImWindow;
3831 }
3832
Wale Ogunwale9d147902016-07-16 11:58:55 -07003833 // This must be called while inside a transaction.
3834 boolean performShowLocked() {
3835 if (isHiddenFromUserLocked()) {
3836 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3837 hideLw(false);
3838 return false;
3839 }
3840
3841 logPerformShow("performShow on ");
3842
Jorim Jaggia50da602016-12-29 11:51:42 +01003843 final int drawState = mWinAnimator.mDrawState;
3844 if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW)
3845 && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3846 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3847 }
3848
Jorim Jaggib0d27342016-11-01 16:10:42 -07003849 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003850 return false;
3851 }
3852
3853 logPerformShow("Showing ");
3854
3855 mService.enableScreenIfNeededLocked();
3856 mWinAnimator.applyEnterAnimationLocked();
3857
3858 // Force the show in the next prepareSurfaceLocked() call.
3859 mWinAnimator.mLastAlpha = -1;
Robert Carre13b58e2017-08-31 14:50:44 -07003860 if (DEBUG_ANIM) Slog.v(TAG,
Wale Ogunwale9d147902016-07-16 11:58:55 -07003861 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3862 mWinAnimator.mDrawState = HAS_DRAWN;
3863 mService.scheduleAnimationLocked();
3864
3865 if (mHidden) {
3866 mHidden = false;
3867 final DisplayContent displayContent = getDisplayContent();
3868
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003869 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003870 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003871 if (c.mWinAnimator.mSurfaceController != null) {
3872 c.performShowLocked();
3873 // It hadn't been shown, which means layout not performed on it, so now we
3874 // want to make sure to do a layout. If called from within the transaction
3875 // loop, this will cause it to restart with a new layout.
3876 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003877 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003878 }
3879 }
3880 }
3881 }
3882
Wale Ogunwale9d147902016-07-16 11:58:55 -07003883 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003884 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003885 }
3886
3887 return true;
3888 }
3889
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003890 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003891 if (DEBUG_VISIBILITY
Jorim Jaggie4b0f282017-05-17 15:10:29 +02003892 || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003893 Slog.v(TAG, prefix + this
3894 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07003895 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003896 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3897 + " during animation: policyVis=" + mPolicyVisibility
3898 + " parentHidden=" + isParentWindowHidden()
3899 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003900 + (mAppToken != null && mAppToken.hiddenRequested)
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003901 + " tok.hidden=" + (mAppToken != null && mAppToken.isHidden())
Jorim Jaggia5e10572017-11-15 14:36:26 +01003902 + " animationSet=" + mWinAnimator.isAnimationSet()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003903 + " tok animating="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003904 + (mAppToken != null && mAppToken.isSelfAnimating())
Wale Ogunwale9d147902016-07-16 11:58:55 -07003905 + " Callers=" + Debug.getCallers(4));
3906 }
3907 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003908
3909 WindowInfo getWindowInfo() {
3910 WindowInfo windowInfo = WindowInfo.obtain();
3911 windowInfo.type = mAttrs.type;
3912 windowInfo.layer = mLayer;
3913 windowInfo.token = mClient.asBinder();
Phil Weaver5dc3ebc2017-08-16 13:04:20 -07003914 if (mAppToken != null) {
3915 windowInfo.activityToken = mAppToken.appToken.asBinder();
3916 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003917 windowInfo.title = mAttrs.accessibilityTitle;
Phil Weaverbb2f28a2017-12-22 09:44:28 -08003918 // Panel windows have no public way to set the a11y title directly. Use the
3919 // regular title as a fallback.
Phil Weaver568cf662018-04-24 17:09:26 -07003920 final boolean isPanelWindow = (mAttrs.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW)
3921 && (mAttrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW);
3922 // Accessibility overlays should have titles that work for accessibility, and can't set
3923 // the a11y title themselves.
3924 final boolean isAccessibilityOverlay =
3925 windowInfo.type == WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
3926 if (TextUtils.isEmpty(windowInfo.title) && (isPanelWindow || isAccessibilityOverlay)) {
Phil Weaverbb2f28a2017-12-22 09:44:28 -08003927 windowInfo.title = mAttrs.getTitle();
3928 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003929 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3930 windowInfo.focused = isFocused();
Phil Weaverf00cd142017-03-03 13:44:00 -08003931 Task task = getTask();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003932 windowInfo.inPictureInPicture = (task != null) && task.inPinnedWindowingMode();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003933
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003934 if (mIsChildWindow) {
3935 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003936 }
3937
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003938 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003939 if (childCount > 0) {
3940 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003941 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003942 }
3943 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003944 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003945 windowInfo.childTokens.add(child.mClient.asBinder());
3946 }
3947 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003948 return windowInfo;
3949 }
3950
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003951 int getHighestAnimLayer() {
3952 int highest = mWinAnimator.mAnimLayer;
3953 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003954 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003955 final int childLayer = c.getHighestAnimLayer();
3956 if (childLayer > highest) {
3957 highest = childLayer;
3958 }
3959 }
3960 return highest;
3961 }
3962
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003963 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003964 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003965 if (mChildren.isEmpty()) {
3966 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003967 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003968 }
3969
3970 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003971 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003972 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003973 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003974 }
3975 }
3976
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003977 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003978 // We want to consume the negative sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003979 // below the parent, then this window (the parent), and then the positive sublayer children
3980 // because they need to appear above the parent.
3981 int i = 0;
3982 final int count = mChildren.size();
3983 WindowState child = mChildren.get(i);
3984
3985 while (i < count && child.mSubLayer < 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003986 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003987 return true;
3988 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003989 i++;
3990 if (i >= count) {
3991 break;
3992 }
3993 child = mChildren.get(i);
3994 }
3995
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003996 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003997 return true;
3998 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003999
4000 while (i < count) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004001 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004002 return true;
4003 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004004 i++;
4005 if (i >= count) {
4006 break;
4007 }
4008 child = mChildren.get(i);
4009 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004010
4011 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004012 }
4013
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004014 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004015 // We want to consume the positive sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004016 // above the parent, then this window (the parent), and then the negative sublayer children
4017 // because they need to appear above the parent.
4018 int i = mChildren.size() - 1;
4019 WindowState child = mChildren.get(i);
4020
4021 while (i >= 0 && child.mSubLayer >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004022 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004023 return true;
4024 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004025 --i;
4026 if (i < 0) {
4027 break;
4028 }
4029 child = mChildren.get(i);
4030 }
4031
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004032 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004033 return true;
4034 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004035
4036 while (i >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004037 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004038 return true;
4039 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004040 --i;
4041 if (i < 0) {
4042 break;
4043 }
4044 child = mChildren.get(i);
4045 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08004046
4047 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07004048 }
4049
Robert Carr9785cf32018-04-25 15:06:07 -07004050 private boolean applyImeWindowsIfNeeded(ToBooleanFunction<WindowState> callback,
4051 boolean traverseTopToBottom) {
4052 // If this window is the current IME target, so we need to process the IME windows
4053 // directly above it. The exception is if we are in split screen
4054 // in which case we process the IME at the DisplayContent level to
4055 // ensure it is above the docked divider.
4056 if (isInputMethodTarget() && !inSplitScreenWindowingMode()) {
4057 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
4058 return true;
4059 }
4060 }
4061 return false;
4062 }
4063
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004064 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
4065 boolean traverseTopToBottom) {
4066 if (traverseTopToBottom) {
Robert Carr9785cf32018-04-25 15:06:07 -07004067 if (applyImeWindowsIfNeeded(callback, traverseTopToBottom)
4068 || callback.apply(this)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004069 return true;
4070 }
4071 } else {
Robert Carr9785cf32018-04-25 15:06:07 -07004072 if (callback.apply(this)
4073 || applyImeWindowsIfNeeded(callback, traverseTopToBottom)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004074 return true;
4075 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004076 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004077 return false;
4078 }
4079
Wale Ogunwaled1880962016-11-08 10:31:59 -08004080 WindowState getWindow(Predicate<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004081 if (mChildren.isEmpty()) {
4082 return callback.test(this) ? this : null;
4083 }
4084
4085 // We want to consume the positive sublayer children first because they need to appear
4086 // above the parent, then this window (the parent), and then the negative sublayer children
4087 // because they need to appear above the parent.
4088 int i = mChildren.size() - 1;
4089 WindowState child = mChildren.get(i);
4090
4091 while (i >= 0 && child.mSubLayer >= 0) {
4092 if (callback.test(child)) {
4093 return child;
4094 }
4095 --i;
4096 if (i < 0) {
4097 break;
4098 }
4099 child = mChildren.get(i);
4100 }
4101
Wale Ogunwaled1880962016-11-08 10:31:59 -08004102 if (callback.test(this)) {
4103 return this;
4104 }
Wale Ogunwale34247952017-02-19 11:57:53 -08004105
4106 while (i >= 0) {
4107 if (callback.test(child)) {
4108 return child;
4109 }
4110 --i;
4111 if (i < 0) {
4112 break;
4113 }
4114 child = mChildren.get(i);
4115 }
4116
4117 return null;
Wale Ogunwaled1880962016-11-08 10:31:59 -08004118 }
4119
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01004120 /**
4121 * @return True if we our one of our ancestors has {@link #mAnimatingExit} set to true, false
4122 * otherwise.
4123 */
4124 @VisibleForTesting
4125 boolean isSelfOrAncestorWindowAnimatingExit() {
4126 WindowState window = this;
4127 do {
4128 if (window.mAnimatingExit) {
4129 return true;
4130 }
4131 window = window.getParentWindow();
4132 } while (window != null);
4133 return false;
4134 }
4135
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004136 void onExitAnimationDone() {
4137 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
4138 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
Jorim Jaggia5e10572017-11-15 14:36:26 +01004139 + " selfAnimating=" + isSelfAnimating());
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004140
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004141 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004142 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +01004143 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004144 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004145 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004146 }
4147 }
4148
4149 if (mWinAnimator.mEnteringAnimation) {
4150 mWinAnimator.mEnteringAnimation = false;
4151 mService.requestTraversal();
4152 // System windows don't have an activity and an app token as a result, but need a way
4153 // to be informed about their entrance animation end.
4154 if (mAppToken == null) {
4155 try {
4156 mClient.dispatchWindowShown();
4157 } catch (RemoteException e) {
4158 }
4159 }
4160 }
4161
Jorim Jaggia5e10572017-11-15 14:36:26 +01004162 if (isSelfAnimating()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004163 return;
4164 }
4165
Jorim Jaggia5e10572017-11-15 14:36:26 +01004166 //TODO (multidisplay): Accessibility is supported only for the default display.
4167 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
4168 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
4169 }
4170
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01004171 if (!isSelfOrAncestorWindowAnimatingExit()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004172 return;
4173 }
4174
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07004175 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004176 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
4177
4178 mDestroying = true;
4179
4180 final boolean hasSurface = mWinAnimator.hasSurface();
Jorim Jaggi50575902018-04-10 17:49:30 +02004181
4182 // Use pendingTransaction here so hide is done the same transaction as the other
4183 // animations when exiting
4184 mWinAnimator.hide(getPendingTransaction(), "onExitAnimationDone");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004185
4186 // If we have an app token, we ask it to destroy the surface for us, so that it can take
4187 // care to ensure the activity has actually stopped and the surface is not still in use.
4188 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
4189 // transaction.
4190 if (mAppToken != null) {
4191 mAppToken.destroySurfaces();
4192 } else {
4193 if (hasSurface) {
4194 mService.mDestroySurface.add(this);
4195 }
4196 if (mRemoveOnExit) {
4197 mService.mPendingRemove.add(this);
4198 mRemoveOnExit = false;
4199 }
4200 }
4201 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07004202 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004203 }
Dan Willemsen117197f2016-07-30 13:02:59 -07004204
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004205 boolean clearAnimatingFlags() {
4206 boolean didSomething = false;
4207 // We don't want to clear it out for windows that get replaced, because the
4208 // animation depends on the flag to remove the replaced window.
4209 //
4210 // We also don't clear the mAnimatingExit flag for windows which have the
4211 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4212 // by the client. We should let animation proceed and not clear this flag or
4213 // they won't eventually be removed by WindowStateAnimator#finishExit.
4214 if (!mWillReplaceWindow && !mRemoveOnExit) {
4215 // Clear mAnimating flag together with mAnimatingExit. When animation
4216 // changes from exiting to entering, we need to clear this flag until the
4217 // new animation gets applied, so that isAnimationStarting() becomes true
4218 // until then.
4219 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4220 // placement for this window during this period, one or more frame will
4221 // show up with wrong position or scale.
4222 if (mAnimatingExit) {
4223 mAnimatingExit = false;
4224 didSomething = true;
4225 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004226 if (mDestroying) {
4227 mDestroying = false;
4228 mService.mDestroySurface.remove(this);
4229 didSomething = true;
4230 }
4231 }
4232
4233 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004234 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004235 }
4236
4237 return didSomething;
4238 }
4239
Winson4b4ba902016-07-27 19:45:52 -07004240 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004241 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004242 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004243
4244 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004245 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004246 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004247 c.hideWallpaperWindow(wasDeferred, reason);
4248 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004249 if (!mWinAnimator.mLastHidden || wasDeferred) {
4250 mWinAnimator.hide(reason);
4251 dispatchWallpaperVisibility(false);
4252 final DisplayContent displayContent = getDisplayContent();
4253 if (displayContent != null) {
4254 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
4255 }
4256 }
4257 }
4258
4259 /**
4260 * Check wallpaper window for visibility change and notify window if so.
4261 * @param visible Current visibility.
4262 */
4263 void dispatchWallpaperVisibility(final boolean visible) {
4264 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07004265 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004266
4267 // Only send notification if the visibility actually changed and we are not trying to hide
4268 // the wallpaper when we are deferring hiding of the wallpaper.
4269 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4270 mWallpaperVisible = visible;
4271 try {
4272 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4273 "Updating vis of wallpaper " + this
4274 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4275 mClient.dispatchAppVisibility(visible);
4276 } catch (RemoteException e) {
4277 }
4278 }
4279 }
4280
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004281 boolean hasVisibleNotDrawnWallpaper() {
4282 if (mWallpaperVisible && !isDrawnLw()) {
4283 return true;
4284 }
4285 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004286 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004287 if (c.hasVisibleNotDrawnWallpaper()) {
4288 return true;
4289 }
4290 }
4291 return false;
4292 }
4293
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004294 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4295 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004296 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004297 c.updateReportedVisibility(results);
4298 }
4299
4300 if (mAppFreezing || mViewVisibility != View.VISIBLE
4301 || mAttrs.type == TYPE_APPLICATION_STARTING
4302 || mDestroying) {
4303 return;
4304 }
4305 if (DEBUG_VISIBILITY) {
4306 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
4307 + ", isAnimationSet=" + mWinAnimator.isAnimationSet());
4308 if (!isDrawnLw()) {
4309 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4310 + " pv=" + mPolicyVisibility
4311 + " mDrawState=" + mWinAnimator.mDrawState
4312 + " ph=" + isParentWindowHidden()
4313 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
Jorim Jaggia5e10572017-11-15 14:36:26 +01004314 + " a=" + mWinAnimator.isAnimationSet());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004315 }
4316 }
4317
4318 results.numInteresting++;
4319 if (isDrawnLw()) {
4320 results.numDrawn++;
4321 if (!mWinAnimator.isAnimationSet()) {
4322 results.numVisible++;
4323 }
4324 results.nowGone = false;
4325 } else if (mWinAnimator.isAnimationSet()) {
4326 results.nowGone = false;
4327 }
4328 }
4329
Robert Carr683e05d2018-04-18 15:11:04 -07004330 private boolean skipDecorCrop() {
4331 // The decor frame is used to specify the region not covered by the system
4332 // decorations (nav bar, status bar). In case this is empty, for example with
4333 // FLAG_TRANSLUCENT_NAVIGATION, we don't need to do any cropping.
4334 if (mDecorFrame.isEmpty()) {
4335 return true;
4336 }
4337
4338 // But if we have a frame, and are an application window, then we must be cropped.
4339 if (mAppToken != null) {
4340 return false;
4341 }
4342
4343 // For non application windows, we may be allowed to extend over the decor bars
4344 // depending on our type and permissions assosciated with our token.
4345 return mToken.canLayerAboveSystemBars();
4346 }
4347
Robert Carrfbbde852016-10-18 11:02:28 -07004348 /**
4349 * Calculate the window crop according to system decor policy. In general this is
4350 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4351 * special cases. This rectangle is in screen space.
4352 */
4353 void calculatePolicyCrop(Rect policyCrop) {
4354 final DisplayContent displayContent = getDisplayContent();
4355 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
4356
4357 if (!isDefaultDisplay()) {
4358 // On a different display there is no system decor. Crop the window
4359 // by the screen boundaries.
4360 // TODO(multi-display)
4361 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4362 policyCrop.intersect(-mCompatFrame.left, -mCompatFrame.top,
4363 displayInfo.logicalWidth - mCompatFrame.left,
4364 displayInfo.logicalHeight - mCompatFrame.top);
Robert Carr683e05d2018-04-18 15:11:04 -07004365 } else if (skipDecorCrop()) {
Robert Carrfbbde852016-10-18 11:02:28 -07004366 // Windows without policy decor aren't cropped.
4367 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4368 } else {
4369 // Crop to the system decor specified by policy.
4370 calculateSystemDecorRect(policyCrop);
4371 }
4372 }
4373
4374 /**
4375 * The system decor rect is the region of the window which is not covered
4376 * by system decorations.
4377 */
4378 private void calculateSystemDecorRect(Rect systemDecorRect) {
4379 final Rect decorRect = mDecorFrame;
4380 final int width = mFrame.width();
4381 final int height = mFrame.height();
4382
Robert Carr217e7cc2018-01-31 18:08:39 -08004383 final int left = mFrame.left;
4384 final int top = mFrame.top;
Robert Carrfbbde852016-10-18 11:02:28 -07004385
4386 // Initialize the decor rect to the entire frame.
4387 if (isDockedResizing()) {
4388 // If we are resizing with the divider, the task bounds might be smaller than the
4389 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4390 // want in this case in order to avoid holes.
4391 //
4392 // We take care to not shrink the width, for surfaces which are larger than
4393 // the display region. Of course this area will not eventually be visible
4394 // but if we truncate the width now, we will calculate incorrectly
4395 // when adjusting to the stack bounds.
4396 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4397 systemDecorRect.set(0, 0,
4398 Math.max(width, displayInfo.logicalWidth),
4399 Math.max(height, displayInfo.logicalHeight));
4400 } else {
4401 systemDecorRect.set(0, 0, width, height);
4402 }
4403
4404 // If a freeform window is animating from a position where it would be cutoff, it would be
4405 // cutoff during the animation. We don't want that, so for the duration of the animation
4406 // we ignore the decor cropping and depend on layering to position windows correctly.
chaviw95136622018-04-09 15:20:06 -07004407
4408 // We also ignore cropping when the window is currently being drag resized in split screen
4409 // to prevent issues with the crop for screenshot.
4410 final boolean cropToDecor =
4411 !(inFreeformWindowingMode() && isAnimatingLw()) && !isDockedResizing();
Robert Carrfbbde852016-10-18 11:02:28 -07004412 if (cropToDecor) {
4413 // Intersect with the decor rect, offsetted by window position.
4414 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
4415 decorRect.right - left, decorRect.bottom - top);
4416 }
4417
4418 // If size compatibility is being applied to the window, the
4419 // surface is scaled relative to the screen. Also apply this
4420 // scaling to the crop rect. We aren't using the standard rect
4421 // scale function because we want to round things to make the crop
4422 // always round to a larger rect to ensure we don't crop too
4423 // much and hide part of the window that should be seen.
4424 if (mEnforceSizeCompat && mInvGlobalScale != 1.0f) {
4425 final float scale = mInvGlobalScale;
4426 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
4427 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
4428 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
4429 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
4430 }
4431
4432 }
4433
4434 /**
4435 * Expand the given rectangle by this windows surface insets. This
4436 * takes you from the 'window size' to the 'surface size'.
4437 * The surface insets are positive in each direction, so we inset by
4438 * the inverse.
4439 */
4440 void expandForSurfaceInsets(Rect r) {
4441 r.inset(-mAttrs.surfaceInsets.left,
4442 -mAttrs.surfaceInsets.top,
4443 -mAttrs.surfaceInsets.right,
4444 -mAttrs.surfaceInsets.bottom);
4445 }
4446
Robert Carrc91d1c32017-02-15 19:37:46 -08004447 boolean surfaceInsetsChanging() {
4448 return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets);
4449 }
4450
Bryce Leef858b572017-06-29 14:03:33 -07004451 int relayoutVisibleWindow(int result, int attrChanges, int oldVisibility) {
Robert Carrecc06b32017-04-18 14:25:10 -07004452 final boolean wasVisible = isVisibleLw();
4453
4454 result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0;
Robert Carr7b3d11d2018-03-15 14:34:45 -07004455
Robert Carrc91d1c32017-02-15 19:37:46 -08004456 if (mAnimatingExit) {
4457 Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit="
4458 + mRemoveOnExit + ", mDestroying=" + mDestroying);
4459
4460 mWinAnimator.cancelExitAnimationForNextAnimationLocked();
4461 mAnimatingExit = false;
4462 }
4463 if (mDestroying) {
4464 mDestroying = false;
4465 mService.mDestroySurface.remove(this);
4466 }
4467 if (oldVisibility == View.GONE) {
4468 mWinAnimator.mEnterAnimationPending = true;
4469 }
4470
Andrii Kulian8ee72852017-03-10 10:36:45 -08004471 mLastVisibleLayoutRotation = getDisplayContent().getRotation();
Robert Carrc91d1c32017-02-15 19:37:46 -08004472
4473 mWinAnimator.mEnteringAnimation = true;
Bryce Leeae73ba42017-05-05 09:58:25 -07004474
Bryce Leef858b572017-06-29 14:03:33 -07004475 prepareWindowToDisplayDuringRelayout(wasVisible);
Bryce Leeae73ba42017-05-05 09:58:25 -07004476
Robert Carrc91d1c32017-02-15 19:37:46 -08004477 if ((attrChanges & FORMAT_CHANGED) != 0) {
4478 // If the format can't be changed in place, preserve the old surface until the app draws
4479 // on the new one. This prevents blinking when we change elevation of freeform and
4480 // pinned windows.
4481 if (!mWinAnimator.tryChangeFormatInPlaceLocked()) {
4482 mWinAnimator.preserveSurfaceLocked();
4483 result |= RELAYOUT_RES_SURFACE_CHANGED
4484 | RELAYOUT_RES_FIRST_TIME;
4485 }
4486 }
4487
4488 // When we change the Surface size, in scenarios which may require changing
4489 // the surface position in sync with the resize, we use a preserved surface
4490 // so we can freeze it while waiting for the client to report draw on the newly
Robert Carrc6d5af52018-02-26 17:46:00 -08004491 // sized surface. At the moment this logic is only in place for switching
4492 // in and out of the big surface for split screen resize.
4493 if (isDragResizeChanged()) {
Robert Carrc91d1c32017-02-15 19:37:46 -08004494 setDragResizing();
Robert Carrc91d1c32017-02-15 19:37:46 -08004495 // We can only change top level windows to the full-screen surface when
4496 // resizing (as we only have one full-screen surface). So there is no need
4497 // to preserve and destroy windows which are attached to another, they
4498 // will keep their surface and its size may change over time.
4499 if (mHasSurface && !isChildWindow()) {
4500 mWinAnimator.preserveSurfaceLocked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08004501 result |= RELAYOUT_RES_SURFACE_CHANGED |
4502 RELAYOUT_RES_FIRST_TIME;
Robert Carrc91d1c32017-02-15 19:37:46 -08004503 }
4504 }
4505 final boolean freeformResizing = isDragResizing()
4506 && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
4507 final boolean dockedResizing = isDragResizing()
4508 && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
4509 result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0;
4510 result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004511 return result;
4512 }
4513
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004514 /**
4515 * @return True if this window has been laid out at least once; false otherwise.
4516 */
4517 boolean isLaidOut() {
4518 return mLayoutSeq != -1;
4519 }
4520
4521 /**
4522 * Updates the last inset values to the current ones.
4523 */
4524 void updateLastInsetValues() {
4525 mLastOverscanInsets.set(mOverscanInsets);
4526 mLastContentInsets.set(mContentInsets);
4527 mLastVisibleInsets.set(mVisibleInsets);
4528 mLastStableInsets.set(mStableInsets);
4529 mLastOutsets.set(mOutsets);
Adrian Roos5c6b6222017-11-07 17:36:10 +01004530 mLastDisplayCutout = mDisplayCutout;
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004531 }
4532
Jorim Jaggia5e10572017-11-15 14:36:26 +01004533 void startAnimation(Animation anim) {
4534 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4535 anim.initialize(mFrame.width(), mFrame.height(),
4536 displayInfo.appWidth, displayInfo.appHeight);
4537 anim.restrictDuration(MAX_ANIMATION_DURATION);
4538 anim.scaleCurrentDuration(mService.getWindowAnimationScaleLocked());
4539 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi2e3c31d2017-11-20 19:49:00 +01004540 new WindowAnimationSpec(anim, mSurfacePosition, false /* canSkipFirstFrame */),
4541 mService.mSurfaceAnimationRunner);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004542 startAnimation(mPendingTransaction, adapter);
4543 commitPendingTransaction();
4544 }
4545
chaviw161ea3e2018-01-31 12:01:12 -08004546 private void startMoveAnimation(int left, int top) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01004547 if (DEBUG_ANIM) Slog.v(TAG, "Setting move animation on " + this);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004548 final Point oldPosition = new Point();
4549 final Point newPosition = new Point();
4550 transformFrameToSurfacePosition(mLastFrame.left, mLastFrame.top, oldPosition);
4551 transformFrameToSurfacePosition(left, top, newPosition);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004552 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004553 new MoveAnimationSpec(oldPosition.x, oldPosition.y, newPosition.x, newPosition.y),
Jorim Jaggia5e10572017-11-15 14:36:26 +01004554 mService.mSurfaceAnimationRunner);
chaviw161ea3e2018-01-31 12:01:12 -08004555 startAnimation(getPendingTransaction(), adapter);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004556 }
4557
4558 private void startAnimation(Transaction t, AnimationAdapter adapter) {
4559 startAnimation(t, adapter, mWinAnimator.mLastHidden);
4560 }
4561
4562 @Override
4563 protected void onAnimationFinished() {
4564 mWinAnimator.onAnimationFinished();
4565 }
4566
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004567 /**
4568 * Retrieves the current transformation matrix of the window, relative to the display.
4569 *
4570 * @param float9 A temporary array of 9 floats.
4571 * @param outMatrix Matrix to fill in the transformation.
4572 */
4573 void getTransformationMatrix(float[] float9, Matrix outMatrix) {
4574 float9[Matrix.MSCALE_X] = mWinAnimator.mDsDx;
4575 float9[Matrix.MSKEW_Y] = mWinAnimator.mDtDx;
4576 float9[Matrix.MSKEW_X] = mWinAnimator.mDtDy;
4577 float9[Matrix.MSCALE_Y] = mWinAnimator.mDsDy;
Robert Carr217e7cc2018-01-31 18:08:39 -08004578 int x = mSurfacePosition.x;
4579 int y = mSurfacePosition.y;
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004580
4581 // If changed, also adjust transformFrameToSurfacePosition
4582 final WindowContainer parent = getParent();
4583 if (isChildWindow()) {
4584 final WindowState parentWindow = getParentWindow();
4585 x += parentWindow.mFrame.left - parentWindow.mAttrs.surfaceInsets.left;
4586 y += parentWindow.mFrame.top - parentWindow.mAttrs.surfaceInsets.top;
4587 } else if (parent != null) {
4588 final Rect parentBounds = parent.getBounds();
4589 x += parentBounds.left;
4590 y += parentBounds.top;
4591 }
4592 float9[Matrix.MTRANS_X] = x;
4593 float9[Matrix.MTRANS_Y] = y;
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004594 float9[Matrix.MPERSP_0] = 0;
4595 float9[Matrix.MPERSP_1] = 0;
4596 float9[Matrix.MPERSP_2] = 1;
4597 outMatrix.setValues(float9);
4598 }
4599
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004600 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4601 // access to its windows children. Need to investigate re-writing
4602 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4603 static final class UpdateReportedVisibilityResults {
4604 int numInteresting;
4605 int numVisible;
4606 int numDrawn;
4607 boolean nowGone = true;
4608
4609 void reset() {
4610 numInteresting = 0;
4611 numVisible = 0;
4612 numDrawn = 0;
4613 nowGone = true;
4614 }
4615 }
Robert Carraf422a82017-04-10 18:34:33 -07004616
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004617 private static final class WindowId extends IWindowId.Stub {
4618 private final WeakReference<WindowState> mOuter;
4619
4620 private WindowId(WindowState outer) {
4621
4622 // Use a weak reference for the outer class. This is important to prevent the following
4623 // leak: Since we send this class to the client process, binder will keep it alive as
4624 // long as the client keeps it alive. Now, if the window is removed, we need to clear
4625 // out our reference so even though this class is kept alive we don't leak WindowState,
4626 // which can keep a whole lot of classes alive.
4627 mOuter = new WeakReference<>(outer);
4628 }
4629
4630 @Override
4631 public void registerFocusObserver(IWindowFocusObserver observer) {
4632 final WindowState outer = mOuter.get();
4633 if (outer != null) {
4634 outer.registerFocusObserver(observer);
4635 }
4636 }
4637 @Override
4638 public void unregisterFocusObserver(IWindowFocusObserver observer) {
4639 final WindowState outer = mOuter.get();
4640 if (outer != null) {
4641 outer.unregisterFocusObserver(observer);
4642 }
4643 }
4644 @Override
4645 public boolean isFocused() {
4646 final WindowState outer = mOuter.get();
4647 return outer != null && outer.isFocused();
4648 }
4649 }
4650
Robert Carrb1579c82017-09-05 14:54:47 -07004651
4652 @Override
4653 boolean shouldMagnify() {
4654 if (mAttrs.type == TYPE_INPUT_METHOD ||
Robert Carree4d4b92017-11-22 12:21:46 -08004655 mAttrs.type == TYPE_INPUT_METHOD_DIALOG ||
4656 mAttrs.type == TYPE_MAGNIFICATION_OVERLAY ||
4657 mAttrs.type == TYPE_NAVIGATION_BAR ||
4658 // It's tempting to wonder: Have we forgotten the rounded corners overlay?
4659 // worry not: it's a fake TYPE_NAVIGATION_BAR_PANEL
Eugene Susla31e3bb92018-03-13 12:24:50 -07004660 mAttrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Robert Carrb1579c82017-09-05 14:54:47 -07004661 return false;
4662 }
4663 return true;
4664 }
4665
4666 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004667 SurfaceSession getSession() {
4668 if (mSession.mSurfaceSession != null) {
4669 return mSession.mSurfaceSession;
4670 } else {
4671 return getParent().getSession();
4672 }
4673 }
4674
4675 @Override
4676 boolean needsZBoost() {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00004677 if (mIsImWindow && mService.mInputMethodTarget != null) {
4678 final AppWindowToken appToken = mService.mInputMethodTarget.mAppToken;
4679 if (appToken != null) {
4680 return appToken.needsZBoost();
4681 }
4682 }
4683 return mWillReplaceWindow;
Robert Carrb1579c82017-09-05 14:54:47 -07004684 }
4685
Robert Carrf07ef9e2017-11-21 12:12:49 -08004686 private void applyDims(Dimmer dimmer) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07004687 if (!mAnimatingExit && mAppDied) {
4688 mIsDimming = true;
chaviw2fb06bc2018-01-19 17:09:15 -08004689 dimmer.dimAbove(getPendingTransaction(), this, DEFAULT_DIM_AMOUNT_DEAD_WINDOW);
chaviwebcbc342018-02-07 13:19:00 -08004690 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0 && isVisibleNow() && !mHidden) {
chaviw14076152018-02-02 14:51:20 -08004691 // Only show a dim behind when the following is satisfied:
4692 // 1. The window has the flag FLAG_DIM_BEHIND
4693 // 2. The WindowToken is not hidden so dims aren't shown when the window is exiting.
4694 // 3. The WS is considered visible according to the isVisible() method
chaviwebcbc342018-02-07 13:19:00 -08004695 // 4. The WS is not hidden.
Robert Carrf59b8dd2017-10-02 18:58:36 -07004696 mIsDimming = true;
chaviw2fb06bc2018-01-19 17:09:15 -08004697 dimmer.dimBelow(getPendingTransaction(), this, mAttrs.dimAmount);
Robert Carrf59b8dd2017-10-02 18:58:36 -07004698 }
Robert Carrf07ef9e2017-11-21 12:12:49 -08004699 }
4700
4701 @Override
4702 void prepareSurfaces() {
4703 final Dimmer dimmer = getDimmer();
4704 mIsDimming = false;
4705 if (dimmer != null) {
4706 applyDims(dimmer);
4707 }
chaviw2f0567b2018-01-29 16:22:02 -08004708 updateSurfacePosition();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004709
Robert Carrb1579c82017-09-05 14:54:47 -07004710 mWinAnimator.prepareSurfaceLocked(true);
4711 super.prepareSurfaces();
4712 }
4713
4714 @Override
Jorim Jaggia5e10572017-11-15 14:36:26 +01004715 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
4716 super.onAnimationLeashCreated(t, leash);
4717
4718 // Leash is now responsible for position, so set our position to 0.
4719 t.setPosition(mSurfaceControl, 0, 0);
chaviw3e751af2018-01-11 11:22:39 -08004720 mLastSurfacePosition.set(0, 0);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004721 }
4722
4723 @Override
4724 public void onAnimationLeashDestroyed(Transaction t) {
4725 super.onAnimationLeashDestroyed(t);
4726 updateSurfacePosition(t);
4727 }
4728
chaviwe07246a2017-12-12 16:18:29 -08004729 @Override
chaviw2f0567b2018-01-29 16:22:02 -08004730 void updateSurfacePosition() {
4731 updateSurfacePosition(getPendingTransaction());
4732 }
4733
4734 private void updateSurfacePosition(Transaction t) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01004735 if (mSurfaceControl == null) {
4736 return;
4737 }
4738
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004739 transformFrameToSurfacePosition(mFrame.left, mFrame.top, mSurfacePosition);
Robert Carrc6d5af52018-02-26 17:46:00 -08004740
Adrian Roos28c25e22018-05-31 18:07:28 +02004741 // Freeze position while we're unrotated, so the surface remains at the position it was
4742 // prior to the rotation.
4743 if (!mSurfaceAnimator.hasLeash() && mPendingForcedSeamlessRotate == null &&
4744 !mLastSurfacePosition.equals(mSurfacePosition)) {
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004745 t.setPosition(mSurfaceControl, mSurfacePosition.x, mSurfacePosition.y);
chaviw3e751af2018-01-11 11:22:39 -08004746 mLastSurfacePosition.set(mSurfacePosition.x, mSurfacePosition.y);
Robert Carrc6d5af52018-02-26 17:46:00 -08004747 if (surfaceInsetsChanging() && mWinAnimator.hasSurface()) {
4748 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
4749 t.deferTransactionUntil(mSurfaceControl,
4750 mWinAnimator.mSurfaceController.mSurfaceControl.getHandle(),
chaviwbe43ac82018-04-04 15:14:49 -07004751 getFrameNumber());
Robert Carrc6d5af52018-02-26 17:46:00 -08004752 }
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004753 }
4754 }
4755
4756 private void transformFrameToSurfacePosition(int left, int top, Point outPoint) {
4757 outPoint.set(left, top);
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004758
4759 // If changed, also adjust getTransformationMatrix
chaviwe07246a2017-12-12 16:18:29 -08004760 final WindowContainer parentWindowContainer = getParent();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004761 if (isChildWindow()) {
4762 // TODO: This probably falls apart at some point and we should
4763 // actually compute relative coordinates.
Jorim Jaggi50d3f8f2017-12-27 17:41:25 +01004764
4765 // Since the parent was outset by its surface insets, we need to undo the outsetting
4766 // with insetting by the same amount.
Jorim Jaggia5e10572017-11-15 14:36:26 +01004767 final WindowState parent = getParentWindow();
Jorim Jaggi50d3f8f2017-12-27 17:41:25 +01004768 outPoint.offset(-parent.mFrame.left + parent.mAttrs.surfaceInsets.left,
4769 -parent.mFrame.top + parent.mAttrs.surfaceInsets.top);
chaviwe07246a2017-12-12 16:18:29 -08004770 } else if (parentWindowContainer != null) {
4771 final Rect parentBounds = parentWindowContainer.getBounds();
4772 outPoint.offset(-parentBounds.left, -parentBounds.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004773 }
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004774
Robert Carr32bcb102018-01-29 15:03:23 -08004775 TaskStack stack = getStack();
4776
4777 // If we have stack outsets, that means the top-left
4778 // will be outset, and we need to inset ourselves
4779 // to account for it. If we actually have shadows we will
4780 // then un-inset ourselves by the surfaceInsets.
4781 if (stack != null) {
4782 final int outset = stack.getStackOutset();
4783 outPoint.offset(outset, outset);
4784 }
4785
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004786 // Expand for surface insets. See WindowState.expandForSurfaceInsets.
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004787 outPoint.offset(-mAttrs.surfaceInsets.left, -mAttrs.surfaceInsets.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004788 }
4789
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004790 boolean needsRelativeLayeringToIme() {
4791 // We only use the relative layering mode in split screen, as part of elevating the IME
4792 // and windows above it's target above the docked divider.
4793 if (!inSplitScreenWindowingMode()) {
4794 return false;
4795 }
4796
4797 if (isChildWindow()) {
4798 // If we are a child of the input method target we need this promotion.
4799 if (getParentWindow().isInputMethodTarget()) {
4800 return true;
4801 }
4802 } else if (mAppToken != null) {
4803 // Likewise if we share a token with the Input method target and are ordered
4804 // above it but not necessarily a child (e.g. a Dialog) then we also need
4805 // this promotion.
4806 final WindowState imeTarget = mService.mInputMethodTarget;
4807 boolean inTokenWithAndAboveImeTarget = imeTarget != null && imeTarget != this
4808 && imeTarget.mToken == mToken && imeTarget.compareTo(this) <= 0;
4809 return inTokenWithAndAboveImeTarget;
4810 }
4811 return false;
4812 }
4813
Jorim Jaggia5e10572017-11-15 14:36:26 +01004814 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004815 void assignLayer(Transaction t, int layer) {
4816 // See comment in assignRelativeLayerForImeTargetChild
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004817 if (needsRelativeLayeringToIme()) {
4818 getDisplayContent().assignRelativeLayerForImeTargetChild(t, this);
Robert Carrb1579c82017-09-05 14:54:47 -07004819 return;
4820 }
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004821 super.assignLayer(t, layer);
Robert Carrb1579c82017-09-05 14:54:47 -07004822 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07004823
4824 @Override
4825 public boolean isDimming() {
4826 return mIsDimming;
4827 }
Robert Carr0eff1872017-12-01 14:27:04 -08004828
4829 // TODO(b/70040778): We should aim to eliminate the last user of TYPE_APPLICATION_MEDIA
4830 // then we can drop all negative layering on the windowing side and simply inherit
4831 // the default implementation here.
4832 public void assignChildLayers(Transaction t) {
4833 int layer = 1;
4834 for (int i = 0; i < mChildren.size(); i++) {
4835 final WindowState w = mChildren.get(i);
4836
4837 // APPLICATION_MEDIA_OVERLAY needs to go above APPLICATION_MEDIA
4838 // while they both need to go below the main window. However the
4839 // relative layering of multiple APPLICATION_MEDIA/OVERLAY has never
4840 // been defined and so we can use static layers and leave it that way.
4841 if (w.mAttrs.type == TYPE_APPLICATION_MEDIA) {
4842 w.assignLayer(t, -2);
4843 } else if (w.mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) {
4844 w.assignLayer(t, -1);
4845 } else {
4846 w.assignLayer(t, layer);
4847 }
4848 w.assignChildLayers(t);
4849 layer++;
4850 }
4851 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01004852
Andrii Kulian4b6599e2018-01-15 17:24:08 -08004853 /**
4854 * Update a tap exclude region with a rectangular area identified by provided id. The requested
4855 * area will be clipped to the window bounds.
4856 */
4857 void updateTapExcludeRegion(int regionId, int left, int top, int width, int height) {
4858 final DisplayContent currentDisplay = getDisplayContent();
4859 if (currentDisplay == null) {
4860 throw new IllegalStateException("Trying to update window not attached to any display.");
4861 }
4862
4863 if (mTapExcludeRegionHolder == null) {
4864 mTapExcludeRegionHolder = new TapExcludeRegionHolder();
4865
4866 // Make sure that this window is registered as one that provides a tap exclude region
4867 // for its containing display.
4868 currentDisplay.mTapExcludeProvidingWindows.add(this);
4869 }
4870
4871 mTapExcludeRegionHolder.updateRegion(regionId, left, top, width, height);
4872 // Trigger touch exclude region update on current display.
4873 final boolean isAppFocusedOnDisplay = mService.mFocusedApp != null
4874 && mService.mFocusedApp.getDisplayContent() == currentDisplay;
4875 currentDisplay.setTouchExcludeRegion(isAppFocusedOnDisplay ? mService.mFocusedApp.getTask()
4876 : null);
4877 }
4878
4879 /** Union the region with current tap exclude region that this window provides. */
4880 void amendTapExcludeRegion(Region region) {
4881 mTapExcludeRegionHolder.amendRegion(region, getBounds());
4882 }
4883
Robert Carr825581a2018-03-30 14:00:53 -07004884 @Override
4885 public boolean isInputMethodTarget() {
4886 return mService.mInputMethodTarget == this;
4887 }
4888
chaviwbe43ac82018-04-04 15:14:49 -07004889 long getFrameNumber() {
4890 return mFrameNumber;
4891 }
4892
4893 void setFrameNumber(long frameNumber) {
4894 mFrameNumber = frameNumber;
4895 }
4896
Adrian Roos41f7e9d2018-06-07 15:29:34 +02004897 @Override
4898 void seamlesslyRotate(Transaction t, int oldRotation, int newRotation) {
Adrian Roos28c25e22018-05-31 18:07:28 +02004899 // Invisible windows, the wallpaper, and force seamlessly rotated windows do not participate
4900 // in the regular seamless rotation animation.
4901 if (!isVisibleNow() || mIsWallpaper || mForceSeamlesslyRotate) {
Adrian Roos41f7e9d2018-06-07 15:29:34 +02004902 return;
4903 }
4904 final Matrix transform = mTmpMatrix;
4905
4906 mService.markForSeamlessRotation(this, true);
4907
4908 // We rotated the screen, but have not performed a new layout pass yet. In the mean time,
4909 // we recompute the coordinates of mFrame in the new orientation, so the surface can be
4910 // properly placed.
4911 transformToRotation(oldRotation, newRotation, getDisplayInfo(), transform);
4912 transformRect(transform, mFrame, null /* tmpRectF */);
4913
4914 updateSurfacePosition(t);
4915 mWinAnimator.seamlesslyRotate(t, oldRotation, newRotation);
4916
4917 // Dispatch to children only after mFrame has been updated, as it's needed in the
4918 // child's updateSurfacePosition.
4919 super.seamlesslyRotate(t, oldRotation, newRotation);
4920 }
4921
Jorim Jaggia5e10572017-11-15 14:36:26 +01004922 private final class MoveAnimationSpec implements AnimationSpec {
4923
4924 private final long mDuration;
4925 private Interpolator mInterpolator;
4926 private Point mFrom = new Point();
4927 private Point mTo = new Point();
4928
4929 private MoveAnimationSpec(int fromX, int fromY, int toX, int toY) {
4930 final Animation anim = AnimationUtils.loadAnimation(mContext,
4931 com.android.internal.R.anim.window_move_from_decor);
Jorim Jaggi08f75cf2018-01-08 14:38:53 +01004932 mDuration = (long)
4933 (anim.computeDurationHint() * mService.getWindowAnimationScaleLocked());
Jorim Jaggia5e10572017-11-15 14:36:26 +01004934 mInterpolator = anim.getInterpolator();
4935 mFrom.set(fromX, fromY);
4936 mTo.set(toX, toY);
4937 }
4938
4939 @Override
4940 public long getDuration() {
4941 return mDuration;
4942 }
4943
4944 @Override
4945 public void apply(Transaction t, SurfaceControl leash, long currentPlayTime) {
4946 final float fraction = (float) currentPlayTime / getDuration();
4947 final float v = mInterpolator.getInterpolation(fraction);
4948 t.setPosition(leash, mFrom.x + (mTo.x - mFrom.x) * v,
4949 mFrom.y + (mTo.y - mFrom.y) * v);
4950 }
Jorim Jaggif75d1612018-02-27 15:05:21 +01004951
4952 @Override
4953 public void dump(PrintWriter pw, String prefix) {
4954 pw.print(prefix); pw.print("from="); pw.print(mFrom);
4955 pw.print(" to="); pw.print(mTo);
4956 pw.print(" duration="); pw.println(mDuration);
4957 }
4958
4959 @Override
4960 public void writeToProtoInner(ProtoOutputStream proto) {
4961 final long token = proto.start(MOVE);
4962 mFrom.writeToProto(proto, FROM);
4963 mTo.writeToProto(proto, TO);
Kweku Adams21b8d262018-03-30 12:19:58 -07004964 proto.write(DURATION_MS, mDuration);
Jorim Jaggif75d1612018-02-27 15:05:21 +01004965 proto.end(token);
4966 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01004967 }
satokcef37fb2011-10-24 21:49:38 +09004968}