blob: 3a818955c6149c321f30ef163527ebd5bb682227 [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;
chaviw40234662018-02-07 09:37:16 -080020import static android.os.PowerManager.DRAW_WAKE_LOCK;
Jorim Jaggi02886a82016-12-06 09:10:06 -080021import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
22import static android.view.Display.DEFAULT_DISPLAY;
Jorim Jaggia5e10572017-11-15 14:36:26 +010023import static android.view.SurfaceControl.Transaction;
Adrian Roos4d18a2e2017-12-19 19:08:05 +010024import static android.view.View.SYSTEM_UI_FLAG_FULLSCREEN;
Jorim Jaggi02886a82016-12-06 09:10:06 -080025import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
26import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
27import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
28import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
29import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
30import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW;
31import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
32import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
33import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
34import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Adrian Roos4d18a2e2017-12-19 19:08:05 +010035import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN;
Jorim Jaggi02886a82016-12-06 09:10:06 -080036import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
37import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
38import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
39import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080040import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
41import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
42import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Robert Carrc91d1c32017-02-15 19:37:46 -080043import static android.view.WindowManager.LayoutParams.FORMAT_CHANGED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080044import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
Adrian Roosfa02da62018-01-15 16:01:18 +010045import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
46import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
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;
Robert Carrb1579c82017-09-05 14:54:47 -070067import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070068import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Jorim Jaggi02886a82016-12-06 09:10:06 -080069import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070070import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType;
Robert Carrc91d1c32017-02-15 19:37:46 -080071import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED;
72import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM;
73import static android.view.WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME;
74import static android.view.WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED;
Adrian Roose99bc052017-11-20 17:55:31 +010075import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
76import static com.android.server.policy.WindowManagerPolicy.TRANSIT_ENTER;
77import static com.android.server.policy.WindowManagerPolicy.TRANSIT_EXIT;
78import static com.android.server.policy.WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
Jorim Jaggi02886a82016-12-06 09:10:06 -080079import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
80import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
81import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
82import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
83import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
84import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
85import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
86import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
87import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Jorim Jaggi02886a82016-12-06 09:10:06 -080088import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
89import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
90import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
91import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
92import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020093import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Jorim Jaggi02886a82016-12-06 09:10:06 -080094import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080095import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
96import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
97import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
98import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
Jorim Jaggia5e10572017-11-15 14:36:26 +010099import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800100import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
101import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
102import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
103import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
104import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
105import static com.android.server.wm.WindowManagerService.localLOGV;
106import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING;
107import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
108import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN;
109import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700110import static com.android.server.wm.proto.IdentifierProto.HASH_CODE;
111import static com.android.server.wm.proto.IdentifierProto.TITLE;
112import static com.android.server.wm.proto.IdentifierProto.USER_ID;
113import static com.android.server.wm.proto.WindowStateProto.ANIMATING_EXIT;
114import static com.android.server.wm.proto.WindowStateProto.ANIMATOR;
115import static com.android.server.wm.proto.WindowStateProto.ATTRIBUTES;
116import static com.android.server.wm.proto.WindowStateProto.CHILD_WINDOWS;
117import static com.android.server.wm.proto.WindowStateProto.CONTAINING_FRAME;
118import static com.android.server.wm.proto.WindowStateProto.CONTENT_FRAME;
119import static com.android.server.wm.proto.WindowStateProto.CONTENT_INSETS;
Vishnu Nair1d0fa072018-01-04 07:53:00 -0800120import static com.android.server.wm.proto.WindowStateProto.CUTOUT;
121import static com.android.server.wm.proto.WindowStateProto.DECOR_FRAME;
122import static com.android.server.wm.proto.WindowStateProto.DESTROYING;
123import static com.android.server.wm.proto.WindowStateProto.DISPLAY_FRAME;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700124import static com.android.server.wm.proto.WindowStateProto.DISPLAY_ID;
125import static com.android.server.wm.proto.WindowStateProto.FRAME;
126import static com.android.server.wm.proto.WindowStateProto.GIVEN_CONTENT_INSETS;
Vishnu Nair1d0fa072018-01-04 07:53:00 -0800127import static com.android.server.wm.proto.WindowStateProto.HAS_SURFACE;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700128import static com.android.server.wm.proto.WindowStateProto.IDENTIFIER;
Vishnu Nair1d0fa072018-01-04 07:53:00 -0800129import static com.android.server.wm.proto.WindowStateProto.IS_ON_SCREEN;
130import static com.android.server.wm.proto.WindowStateProto.IS_READY_FOR_DISPLAY;
131import static com.android.server.wm.proto.WindowStateProto.IS_VISIBLE;
132import static com.android.server.wm.proto.WindowStateProto.OUTSETS;
133import static com.android.server.wm.proto.WindowStateProto.OUTSET_FRAME;
134import static com.android.server.wm.proto.WindowStateProto.OVERSCAN_FRAME;
135import static com.android.server.wm.proto.WindowStateProto.OVERSCAN_INSETS;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700136import static com.android.server.wm.proto.WindowStateProto.PARENT_FRAME;
Vishnu Nair1d0fa072018-01-04 07:53:00 -0800137import static com.android.server.wm.proto.WindowStateProto.REMOVED;
138import static com.android.server.wm.proto.WindowStateProto.REMOVE_ON_EXIT;
139import static com.android.server.wm.proto.WindowStateProto.REQUESTED_HEIGHT;
140import static com.android.server.wm.proto.WindowStateProto.REQUESTED_WIDTH;
Rob Carr06be6bb2018-02-06 16:26:06 +0000141import static com.android.server.wm.proto.WindowStateProto.SHOWN_POSITION;
Vishnu Nair1d0fa072018-01-04 07:53:00 -0800142import static com.android.server.wm.proto.WindowStateProto.STABLE_INSETS;
143import static com.android.server.wm.proto.WindowStateProto.STACK_ID;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700144import static com.android.server.wm.proto.WindowStateProto.SURFACE_INSETS;
Jorim Jaggi45be1c4c2017-12-15 18:44:43 +0100145import static com.android.server.wm.proto.WindowStateProto.SURFACE_POSITION;
Vishnu Nair1d0fa072018-01-04 07:53:00 -0800146import static com.android.server.wm.proto.WindowStateProto.SYSTEM_UI_VISIBILITY;
147import static com.android.server.wm.proto.WindowStateProto.VIEW_VISIBILITY;
148import static com.android.server.wm.proto.WindowStateProto.VISIBLE_FRAME;
149import static com.android.server.wm.proto.WindowStateProto.VISIBLE_INSETS;
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700150import static com.android.server.wm.proto.WindowStateProto.WINDOW_CONTAINER;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800151
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700152import android.annotation.CallSuper;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800153import android.app.AppOpsManager;
154import android.content.Context;
155import android.content.res.Configuration;
156import android.graphics.Matrix;
157import android.graphics.PixelFormat;
158import android.graphics.Point;
159import android.graphics.Rect;
160import android.graphics.Region;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700161import android.os.Binder;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700162import android.os.Debug;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800163import android.os.IBinder;
164import android.os.PowerManager;
165import android.os.RemoteCallbackList;
166import android.os.RemoteException;
167import android.os.SystemClock;
168import android.os.Trace;
169import android.os.UserHandle;
170import android.os.WorkSource;
chaviw40234662018-02-07 09:37:16 -0800171import android.provider.Settings;
Phil Weaverbb2f28a2017-12-22 09:44:28 -0800172import android.text.TextUtils;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800173import android.util.DisplayMetrics;
Jorim Jaggie7d2b852017-08-28 17:55:15 +0200174import android.util.MergedConfiguration;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800175import android.util.Slog;
176import android.util.TimeUtils;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700177import android.util.proto.ProtoOutputStream;
Adrian Roos5c6b6222017-11-07 17:36:10 +0100178import android.view.DisplayCutout;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800179import android.view.DisplayInfo;
180import android.view.Gravity;
181import android.view.IApplicationToken;
182import android.view.IWindow;
183import android.view.IWindowFocusObserver;
184import android.view.IWindowId;
185import android.view.InputChannel;
186import android.view.InputEvent;
187import android.view.InputEventReceiver;
Robert Carrb1579c82017-09-05 14:54:47 -0700188import android.view.SurfaceControl;
189import android.view.SurfaceSession;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800190import android.view.View;
191import android.view.ViewTreeObserver;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700192import android.view.WindowInfo;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800193import android.view.WindowManager;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100194import android.view.animation.Animation;
195import android.view.animation.AnimationUtils;
196import android.view.animation.Interpolator;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800197
Jorim Jaggi4876b4a2018-01-11 15:43:49 +0100198import com.android.internal.annotations.VisibleForTesting;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800199import com.android.internal.util.ToBooleanFunction;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800200import com.android.server.input.InputWindowHandle;
Adrian Roose99bc052017-11-20 17:55:31 +0100201import com.android.server.policy.WindowManagerPolicy;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100202import com.android.server.wm.LocalAnimationAdapter.AnimationSpec;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800203
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800204import java.io.PrintWriter;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200205import java.lang.ref.WeakReference;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800206import java.util.ArrayList;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700207import java.util.Comparator;
Wale Ogunwaled1880962016-11-08 10:31:59 -0800208import java.util.function.Predicate;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800209
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700210/** A window in the window manager. */
211class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800212 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800213
Skuhne81c524a2015-08-12 13:34:14 -0700214 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700215 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
216 // use hard-coded min sizes for now.
217 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
218 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700219
220 // The thickness of a window resize handle outside the window bounds on the free form workspace
221 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700222 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700223
Craig Mautnere7ae2502012-03-26 17:11:19 -0700224 final WindowManagerPolicy mPolicy;
225 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800226 final Session mSession;
227 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800228 final int mAppOp;
229 // UserId and appId of the owner. Don't display windows of non-current user.
230 final int mOwnerUid;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800231 /** The owner has {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} */
232 final boolean mOwnerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200233 final WindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800234 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700235 // The same object as mToken if this is an app window and null for non-app windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800236 AppWindowToken mAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700237
238 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
239 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800240 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
241 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700242 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800243 final int mBaseLayer;
244 final int mSubLayer;
245 final boolean mLayoutAttached;
246 final boolean mIsImWindow;
247 final boolean mIsWallpaper;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700248 private final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700249 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700250 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800251 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700252 int mSystemUiVisibility;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700253 /**
254 * The visibility of the window based on policy like {@link WindowManagerPolicy}.
255 * Normally set by calling {@link #showLw} and {@link #hideLw}.
256 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800257 boolean mPolicyVisibility = true;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700258 /**
259 * What {@link #mPolicyVisibility} should be set to after a transition animation.
260 * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and
261 * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit
262 * animation is done.
263 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800264 boolean mPolicyVisibilityAfterAnim = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700265 private boolean mAppOpVisibility = true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700266 boolean mPermanentlyHidden; // the window should never be shown again
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700267 // This is a non-system overlay window that is currently force hidden.
268 private boolean mForceHideNonSystemOverlayWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800269 boolean mAppFreezing;
chaviwebcbc342018-02-07 13:19:00 -0800270 boolean mHidden = true; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800271 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700272 private boolean mDragResizing;
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200273 private boolean mDragResizingChangeReported = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700274 private int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700275
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700276 private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800277
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700278 /**
279 * The window size that was requested by the application. These are in
280 * the application's coordinate space (without compatibility scale applied).
281 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800282 int mRequestedWidth;
283 int mRequestedHeight;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700284 private int mLastRequestedWidth;
285 private int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700286
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800287 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800288 boolean mHaveFrame;
289 boolean mObscured;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800290
291 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700292
Andrii Kulian9d91ca62016-09-29 22:28:09 -0700293 /**
294 * Used to store last reported to client configuration and check if we have newer available.
295 * We'll send configuration to client only if it is different from the last applied one and
296 * client won't perform unnecessary updates.
297 */
Bryce Lee2b17afd2017-09-21 10:38:20 -0700298 private final MergedConfiguration mLastReportedConfiguration = new MergedConfiguration();
Craig Mautnera2c77052012-03-26 12:14:43 -0700299
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700300 /**
Rob Carr06be6bb2018-02-06 16:26:06 +0000301 * Actual position of the surface shown on-screen (may be modified by animation). These are
302 * in the screen's coordinate space (WITH the compatibility scale applied).
303 */
304 final Point mShownPosition = new Point();
305
306 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700307 * Insets that determine the actually visible area. These are in the application's
308 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800309 */
310 final Rect mVisibleInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700311 private final Rect mLastVisibleInsets = new Rect();
312 private boolean mVisibleInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800313
314 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700315 * Insets that are covered by system windows (such as the status bar) and
316 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700317 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800318 */
319 final Rect mContentInsets = new Rect();
320 final Rect mLastContentInsets = new Rect();
Robert Carr18f622f2017-05-08 11:20:43 -0700321
322 /**
323 * The last content insets returned to the client in relayout. We use
324 * these in the bounds animation to ensure we only observe inset changes
325 * at the same time that a client resizes it's surface so that we may use
326 * the geometryAppliesWithResize synchronization mechanism to keep
327 * the contents in place.
328 */
329 final Rect mLastRelayoutContentInsets = new Rect();
330
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700331 private boolean mContentInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800332
333 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800334 * Insets that determine the area covered by the display overscan region. These are in the
335 * application's coordinate space (without compatibility scale applied).
336 */
337 final Rect mOverscanInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700338 private final Rect mLastOverscanInsets = new Rect();
339 private boolean mOverscanInsetsChanged;
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800340
341 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700342 * Insets that determine the area covered by the stable system windows. These are in the
343 * application's coordinate space (without compatibility scale applied).
344 */
345 final Rect mStableInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700346 private final Rect mLastStableInsets = new Rect();
347 private boolean mStableInsetsChanged;
Adrian Roosfa104232014-06-20 16:10:14 -0700348
349 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700350 * Outsets determine the area outside of the surface where we want to pretend that it's possible
351 * to draw anyway.
352 */
353 final Rect mOutsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700354 private final Rect mLastOutsets = new Rect();
355 private boolean mOutsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700356
Adrian Roos5c6b6222017-11-07 17:36:10 +0100357 /** Part of the display that has been cut away. See {@link DisplayCutout}. */
358 DisplayCutout mDisplayCutout = DisplayCutout.NO_CUTOUT;
359 private DisplayCutout mLastDisplayCutout = DisplayCutout.NO_CUTOUT;
360 private boolean mDisplayCutoutChanged;
361
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700362 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800363 * Set to true if we are waiting for this window to receive its
364 * given internal insets before laying out other windows based on it.
365 */
366 boolean mGivenInsetsPending;
367
368 /**
369 * These are the content insets that were given during layout for
370 * this window, to be applied to windows behind it.
371 */
372 final Rect mGivenContentInsets = new Rect();
373
374 /**
375 * These are the visible insets that were given during layout for
376 * this window, to be applied to windows behind it.
377 */
378 final Rect mGivenVisibleInsets = new Rect();
379
380 /**
381 * This is the given touchable area relative to the window frame, or null if none.
382 */
383 final Region mGivenTouchableRegion = new Region();
384
385 /**
386 * Flag indicating whether the touchable region should be adjusted by
387 * the visible insets; if false the area outside the visible insets is
388 * NOT touchable, so we must use those to adjust the frame during hit
389 * tests.
390 */
391 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
392
393 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400394 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700395 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800396 float mHScale=1, mVScale=1;
397 float mLastHScale=1, mLastVScale=1;
398 final Matrix mTmpMatrix = new Matrix();
399
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700400 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800401 final Rect mFrame = new Rect();
402 final Rect mLastFrame = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700403 private boolean mFrameSizeChanged = false;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700404 // Frame that is scaled to the application's coordinate space when in
405 // screen size compatibility mode.
406 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800407
408 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700409
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700410 private final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700411
Wale Ogunwale94596652015-02-06 19:27:34 -0800412 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
413 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700414 final Rect mDisplayFrame = new Rect();
415
416 // The region of the display frame that the display type supports displaying content on. This
417 // is mostly a special case for TV where some displays don’t have the entire display usable.
418 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
419 // window display contents to extend into the overscan region.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700420 private final Rect mOverscanFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700421
422 // The display frame minus the stable insets. This value is always constant regardless of if
423 // the status bar or navigation bar is visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700424 private final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800425
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700426 // The area not occupied by the status and navigation bars. So, if both status and navigation
427 // bars are visible, the decor frame is equal to the stable frame.
428 final Rect mDecorFrame = new Rect();
429
430 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
431 // minus the area occupied by the IME if the IME is present.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700432 private final Rect mContentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700433
434 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
435 // displays hint text.
436 final Rect mVisibleFrame = new Rect();
437
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700438 // Frame that includes dead area outside of the surface but where we want to pretend that it's
439 // possible to draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700440 private final Rect mOutsetFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700441
Jorim Jaggidc249c42015-12-15 14:57:31 -0800442 /**
443 * Usually empty. Set to the task's tempInsetFrame. See
444 *{@link android.app.IActivityManager#resizeDockedStack}.
445 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700446 private final Rect mInsetFrame = new Rect();
Jorim Jaggidc249c42015-12-15 14:57:31 -0800447
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800448 boolean mContentChanged;
449
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800450 // If a window showing a wallpaper: the requested offset for the
451 // wallpaper; if a wallpaper window: the currently applied offset.
452 float mWallpaperX = -1;
453 float mWallpaperY = -1;
454
455 // If a window showing a wallpaper: what fraction of the offset
456 // range corresponds to a full virtual screen.
457 float mWallpaperXStep = -1;
458 float mWallpaperYStep = -1;
459
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700460 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
461 // to its window; if a wallpaper window: not used.
462 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
463 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
464
Rob Carr06be6bb2018-02-06 16:26:06 +0000465 // Wallpaper windows: pixels offset based on above variables.
466 int mXOffset;
467 int mYOffset;
468
Craig Mautner2268e7e2012-12-13 15:40:00 -0800469 /**
470 * This is set after IWindowSession.relayout() has been called at
471 * least once for the window. It allows us to detect the situation
472 * where we don't yet have a surface, but should have one soon, so
473 * we can give the window focus before waiting for the relayout.
474 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800475 boolean mRelayoutCalled;
476
Robert Carrfed10072016-05-26 11:48:49 -0700477 boolean mInRelayout;
478
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800479 /**
480 * If the application has called relayout() with changes that can
481 * impact its window's size, we need to perform a layout pass on it
482 * even if it is not currently visible for layout. This is set
483 * when in that case until the layout is done.
484 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800485 boolean mLayoutNeeded;
486
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800487 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800488 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800489
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800490 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800491 boolean mDestroying;
492
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800493 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800494 boolean mRemoveOnExit;
495
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800496 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800497 * Whether the app died while it was visible, if true we might need
498 * to continue to show it until it's restarted.
499 */
500 boolean mAppDied;
501
502 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800503 * Set when the orientation is changing and this window has not yet
504 * been updated for the new orientation.
505 */
Bryce Lee8c3cf382017-07-06 19:47:10 -0700506 private boolean mOrientationChanging;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800507
Dianne Hackborna57c6952013-03-29 14:46:40 -0700508 /**
Robert Carr9c1c3a02017-08-08 12:59:01 -0700509 * Sometimes in addition to the mOrientationChanging
510 * flag we report that the orientation is changing
511 * due to a mismatch in current and reported configuration.
512 *
513 * In the case of timeout we still need to make sure we
514 * leave the orientation changing state though, so we
515 * use this as a special time out escape hatch.
516 */
517 private boolean mOrientationChangeTimedOut;
518
519 /**
Robert Carr237028a2016-07-26 10:39:45 -0700520 * The orientation during the last visible call to relayout. If our
521 * current orientation is different, the window can't be ready
522 * to be shown.
523 */
524 int mLastVisibleLayoutRotation = -1;
525
526 /**
Andrii Kulianb2e37802017-01-11 00:36:44 -0800527 * Set when we need to report the orientation change to client to trigger a relayout.
528 */
529 boolean mReportOrientationChanged;
530
531 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700532 * How long we last kept the screen frozen.
533 */
534 int mLastFreezeDuration;
535
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800536 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800537 boolean mRemoved;
538
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800539 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800540 * It is save to remove the window and destroy the surface because the client requested removal
541 * or some other higher level component said so (e.g. activity manager).
542 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800543 */
Svetoslav Ganov200adfb2016-10-18 13:29:27 -0700544 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800545
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800546 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700547 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800548 InputChannel mInputChannel;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700549 private InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800550
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800551 // Used to improve performance of toString()
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700552 private String mStringNameCache;
553 private CharSequence mLastTitle;
554 private boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800555
Craig Mautnera2c77052012-03-26 12:14:43 -0700556 final WindowStateAnimator mWinAnimator;
557
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700558 boolean mHasSurface = false;
559
Craig Mautner88400d32012-09-30 12:35:45 -0700560 /** When true this window can be displayed on screens owther than mOwnerUid's */
561 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700562
Chong Zhang92147042016-05-09 12:47:11 -0700563 // Whether the window was visible when we set the app to invisible last time. WM uses
564 // this as a hint to restore the surface (if available) for early animation next time
565 // the app is brought visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700566 private boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800567
Robert Carra1eb4392015-12-10 12:43:51 -0800568 // This window will be replaced due to relaunch. This allows window manager
569 // to differentiate between simple removal of a window and replacement. In the latter case it
570 // will preserve the old window until the new one is drawn.
571 boolean mWillReplaceWindow = false;
572 // If true, the replaced window was already requested to be removed.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700573 private boolean mReplacingRemoveRequested = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800574 // Whether the replacement of the window should trigger app transition animation.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700575 private boolean mAnimateReplacingWindow = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800576 // If not null, the window that will be used to replace the old one. This is being set when
577 // the window is added and unset when this window reports its first draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700578 private WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700579 // For the new window in the replacement transition, if we have
580 // requested to replace without animation, then we should
581 // make sure we also don't apply an enter animation for
582 // the new window.
583 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800584 // Whether this window is being moved via the resize API
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700585 private boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800586
Jeff Brownc2932a12014-11-20 18:04:05 -0800587 /**
588 * Wake lock for drawing.
589 * Even though it's slightly more expensive to do so, we will use a separate wake lock
590 * for each app that is requesting to draw while dozing so that we can accurately track
591 * who is preventing the system from suspending.
592 * This lock is only acquired on first use.
593 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700594 private PowerManager.WakeLock mDrawLock;
Jeff Brownc2932a12014-11-20 18:04:05 -0800595
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700596 final private Rect mTmpRect = new Rect();
597
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800598 /**
599 * Whether the window was resized by us while it was gone for layout.
600 */
601 boolean mResizedWhileGone = false;
602
Robert Carr6da3cc02016-06-16 15:17:07 -0700603 /**
604 * During seamless rotation we have two phases, first the old window contents
605 * are rotated to look as if they didn't move in the new coordinate system. Then we
606 * have to freeze updates to this layer (to preserve the transformation) until
607 * the resize actually occurs. This is true from when the transformation is set
608 * and false until the transaction to resize is sent.
609 */
610 boolean mSeamlesslyRotated = false;
611
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700612 /**
Robert Carrc91d1c32017-02-15 19:37:46 -0800613 * Surface insets from the previous call to relayout(), used to track
614 * if we are changing the Surface insets.
615 */
616 final Rect mLastSurfaceInsets = new Rect();
617
618 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700619 * A flag set by the {@link WindowState} parent to indicate that the parent has examined this
620 * {@link WindowState} in its overall drawing context. This book-keeping allows the parent to
621 * make sure all children have been considered.
622 */
623 private boolean mDrawnStateEvaluated;
624
Jorim Jaggia5e10572017-11-15 14:36:26 +0100625 private final Point mSurfacePosition = new Point();
626
Bryce Leed390deb2017-06-22 13:14:28 -0700627 /**
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800628 * A region inside of this window to be excluded from touch-related focus switches.
629 */
630 private TapExcludeRegionHolder mTapExcludeRegionHolder;
631
632 /**
chaviw40234662018-02-07 09:37:16 -0800633 * Used for testing because the real PowerManager is final.
634 */
635 private PowerManagerWrapper mPowerManagerWrapper;
636
637 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700638 * 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 -0700639 * of z-order and 1 otherwise.
640 */
Griff Hazen51d00d82016-11-22 15:39:24 -0800641 private static final Comparator<WindowState> sWindowSubLayerComparator =
642 new Comparator<WindowState>() {
643 @Override
644 public int compare(WindowState w1, WindowState w2) {
645 final int layer1 = w1.mSubLayer;
646 final int layer2 = w2.mSubLayer;
647 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
648 // We insert the child window into the list ordered by
649 // the sub-layer. For same sub-layers, the negative one
650 // should go below others; the positive one should go
651 // above others.
652 return -1;
653 }
654 return 1;
655 };
656 };
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700657
Robert Carrf59b8dd2017-10-02 18:58:36 -0700658 /**
659 * Indicates whether we have requested a Dim (in the sense of {@link Dimmer}) from our host
660 * container.
661 */
662 private boolean mIsDimming = false;
663
664 private static final float DEFAULT_DIM_AMOUNT_DEAD_WINDOW = 0.5f;
665
chaviw40234662018-02-07 09:37:16 -0800666 interface PowerManagerWrapper {
667 void wakeUp(long time, String reason);
668
669 boolean isInteractive();
670
671 }
672
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800673 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
chaviw40234662018-02-07 09:37:16 -0800674 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
675 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow) {
676 this(service, s, c, token, parentWindow, appOp, seq, a, viewVisibility, ownerId,
677 ownerCanAddInternalSystemWindow, new PowerManagerWrapper() {
678 @Override
679 public void wakeUp(long time, String reason) {
680 service.mPowerManager.wakeUp(time, reason);
681 }
682
683 @Override
684 public boolean isInteractive() {
685 return service.mPowerManager.isInteractive();
686 }
687 });
688 }
689
690 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
691 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
692 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow,
693 PowerManagerWrapper powerManagerWrapper) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100694 super(service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800695 mSession = s;
696 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800697 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800698 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700699 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700700 mOwnerUid = ownerId;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800701 mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200702 mWindowId = new WindowId(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800703 mAttrs.copyFrom(a);
704 mViewVisibility = viewVisibility;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700705 mPolicy = mService.mPolicy;
706 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800707 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700708 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700709 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
chaviw40234662018-02-07 09:37:16 -0800710 mPowerManagerWrapper = powerManagerWrapper;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700711 if (localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700712 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700713 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800714 try {
715 c.asBinder().linkToDeath(deathRecipient, 0);
716 } catch (RemoteException e) {
717 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700718 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800719 mLayoutAttached = false;
720 mIsImWindow = false;
721 mIsWallpaper = false;
722 mIsFloatingLayer = false;
723 mBaseLayer = 0;
724 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700725 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700726 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800727 return;
728 }
729 mDeathRecipient = deathRecipient;
730
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700731 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800732 // The multiplier here is to reserve space for multiple
733 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800734 mBaseLayer = mPolicy.getWindowLayerLw(parentWindow)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700735 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800736 mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700737 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900738
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700739 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow);
740 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900741
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800742 mLayoutAttached = mAttrs.type !=
743 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700744 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
745 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
746 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800747 } else {
748 // The multiplier here is to reserve space for multiple
749 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800750 mBaseLayer = mPolicy.getWindowLayerLw(this)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700751 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800752 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700753 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800754 mLayoutAttached = false;
755 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
756 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
757 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800758 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700759 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800760
Wale Ogunwale72919d22016-12-08 18:58:50 -0800761 if (mAppToken != null && mAppToken.mShowForAllUsers) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700762 // Windows for apps that can show for all users should also show when the device is
763 // locked.
764 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
Craig Mautner19ab8282014-05-07 10:35:34 -0700765 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800766
Craig Mautner322e4032012-07-13 13:35:20 -0700767 mWinAnimator = new WindowStateAnimator(this);
768 mWinAnimator.mAlpha = a.alpha;
769
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800770 mRequestedWidth = 0;
771 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700772 mLastRequestedWidth = 0;
773 mLastRequestedHeight = 0;
Rob Carr06be6bb2018-02-06 16:26:06 +0000774 mXOffset = 0;
775 mYOffset = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800776 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800777 mInputWindowHandle = new InputWindowHandle(
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800778 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this, c,
779 getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800780 }
781
782 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700783 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800784 mSession.windowAddedLocked(mAttrs.packageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800785 }
786
Bryce Leed390deb2017-06-22 13:14:28 -0700787 /**
788 * Returns whether this {@link WindowState} has been considered for drawing by its parent.
789 */
Bryce Lee6311c4b2017-07-06 14:09:29 -0700790 boolean getDrawnStateEvaluated() {
Bryce Leed390deb2017-06-22 13:14:28 -0700791 return mDrawnStateEvaluated;
792 }
793
794 /**
795 * Sets whether this {@link WindowState} has been considered for drawing by its parent. Should
796 * be cleared when detached from parent.
797 */
798 void setDrawnStateEvaluated(boolean evaluated) {
799 mDrawnStateEvaluated = evaluated;
800 }
801
802 @Override
803 void onParentSet() {
804 super.onParentSet();
805 setDrawnStateEvaluated(false /*evaluated*/);
806 }
807
Craig Mautnera2c77052012-03-26 12:14:43 -0700808 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800809 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800810 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800811 }
812
813 @Override
814 public String getOwningPackage() {
815 return mAttrs.packageName;
816 }
817
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800818 @Override
819 public boolean canAddInternalSystemWindow() {
820 return mOwnerCanAddInternalSystemWindow;
821 }
822
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200823 @Override
824 public boolean canAcquireSleepToken() {
825 return mSession.mCanAcquireSleepToken;
826 }
827
Jorim Jaggif5834272016-04-04 20:25:41 -0700828 /**
829 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
830 * from {@param frame}. In other words, it applies the insets that would result if
831 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700832 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
833 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700834 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700835 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
836 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
837 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
838 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
839 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700840 frame.inset(left, top, right, bottom);
841 }
842
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800843 @Override
Robert Carr43521762016-10-28 13:15:04 -0700844 public void computeFrameLw(Rect parentFrame, Rect displayFrame, Rect overscanFrame,
845 Rect contentFrame, Rect visibleFrame, Rect decorFrame, Rect stableFrame,
Adrian Roos5c6b6222017-11-07 17:36:10 +0100846 Rect outsetFrame, DisplayCutout displayCutout) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800847 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700848 // This window is being replaced and either already got information that it's being
849 // removed or we are still waiting for some information. Because of this we don't
850 // want to apply any more changes to it, so it remains in this state until new window
851 // appears.
852 return;
853 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800854 mHaveFrame = true;
855
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700856 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700857 final boolean inFullscreenContainer = inFullscreenContainer();
Robert Carre6275582016-02-29 15:45:45 -0800858 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700859 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800860
Chong Zhangae35fef2016-03-16 15:56:55 -0700861 // If the task has temp inset bounds set, we have to make sure all its windows uses
862 // the temp inset frame. Otherwise different display frames get applied to the main
863 // window and the child window, making them misaligned.
Andrii Kulianc24f3732017-08-08 19:35:17 -0700864 if (inFullscreenContainer || isLetterboxedAppWindow()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700865 mInsetFrame.setEmpty();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700866 } else if (task != null && isInMultiWindowMode()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700867 task.getTempInsetBounds(mInsetFrame);
868 }
869
Jorim Jaggif5834272016-04-04 20:25:41 -0700870 // Denotes the actual frame used to calculate the insets and to perform the layout. When
871 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
872 // insets temporarily. By the notion of a task having a different layout frame, we can
873 // achieve that while still moving the task around.
874 final Rect layoutContainingFrame;
875 final Rect layoutDisplayFrame;
876
877 // The offset from the layout containing frame to the actual containing frame.
878 final int layoutXDiff;
879 final int layoutYDiff;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700880 if (inFullscreenContainer || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800881 // We use the parent frame as the containing frame for fullscreen and child windows
Robert Carr43521762016-10-28 13:15:04 -0700882 mContainingFrame.set(parentFrame);
883 mDisplayFrame.set(displayFrame);
884 layoutDisplayFrame = displayFrame;
885 layoutContainingFrame = parentFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700886 layoutXDiff = 0;
887 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800888 } else {
Bryce Leef3c6a472017-11-14 14:53:06 -0800889 getBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100890 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
891
892 // If the bounds are frozen, we still want to translate the window freely and only
893 // freeze the size.
894 Rect frozen = mAppToken.mFrozenBounds.peek();
895 mContainingFrame.right = mContainingFrame.left + frozen.width();
896 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
897 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800898 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700899 // IME is up and obscuring this window. Adjust the window position so it is visible.
900 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this) {
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700901 if (inFreeformWindowingMode()
Winson Chungd73e94b2017-05-31 16:25:30 -0700902 && mContainingFrame.bottom > contentFrame.bottom) {
903 // In freeform we want to move the top up directly.
904 // TODO: Investigate why this is contentFrame not parentFrame.
905 mContainingFrame.top -= mContainingFrame.bottom - contentFrame.bottom;
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700906 } else if (!inPinnedWindowingMode()
Winson Chungd73e94b2017-05-31 16:25:30 -0700907 && mContainingFrame.bottom > parentFrame.bottom) {
908 // But in docked we want to behave like fullscreen and behave as if the task
909 // were given smaller bounds for the purposes of layout. Skip adjustments for
910 // the pinned stack, they are handled separately in the PinnedStackController.
911 mContainingFrame.bottom = parentFrame.bottom;
912 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700913 }
Skuhne81c524a2015-08-12 13:34:14 -0700914
Robert Carre6275582016-02-29 15:45:45 -0800915 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700916 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
917 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800918 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700919 if (mContainingFrame.isEmpty()) {
Robert Carr43521762016-10-28 13:15:04 -0700920 mContainingFrame.set(contentFrame);
Skuhne81c524a2015-08-12 13:34:14 -0700921 }
Doris Liu06d582d2015-06-01 13:18:43 -0700922 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800923 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700924 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
925 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
926 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700927 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
Robert Carr43521762016-10-28 13:15:04 -0700928 subtractInsets(mDisplayFrame, layoutContainingFrame, displayFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700929 if (!layoutInParentFrame()) {
Robert Carr43521762016-10-28 13:15:04 -0700930 subtractInsets(mContainingFrame, layoutContainingFrame, parentFrame, mTmpRect);
931 subtractInsets(mInsetFrame, layoutContainingFrame, parentFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700932 }
Robert Carr43521762016-10-28 13:15:04 -0700933 layoutDisplayFrame = displayFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700934 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700935 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800936
Craig Mautner967212c2013-04-13 21:10:58 -0700937 final int pw = mContainingFrame.width();
938 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800939
Robert Carr43521762016-10-28 13:15:04 -0700940 if (!mParentFrame.equals(parentFrame)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800941 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Robert Carr43521762016-10-28 13:15:04 -0700942 // + " to " + parentFrame);
943 mParentFrame.set(parentFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800944 mContentChanged = true;
945 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700946 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
947 mLastRequestedWidth = mRequestedWidth;
948 mLastRequestedHeight = mRequestedHeight;
949 mContentChanged = true;
950 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800951
Robert Carr43521762016-10-28 13:15:04 -0700952 mOverscanFrame.set(overscanFrame);
953 mContentFrame.set(contentFrame);
954 mVisibleFrame.set(visibleFrame);
955 mDecorFrame.set(decorFrame);
956 mStableFrame.set(stableFrame);
957 final boolean hasOutsets = outsetFrame != null;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700958 if (hasOutsets) {
Robert Carr43521762016-10-28 13:15:04 -0700959 mOutsetFrame.set(outsetFrame);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700960 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800961
Craig Mautnereda67292013-04-28 13:50:14 -0700962 final int fw = mFrame.width();
963 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800964
Jorim Jaggif5834272016-04-04 20:25:41 -0700965 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
966
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700967 // Calculate the outsets before the content frame gets shrinked to the window frame.
968 if (hasOutsets) {
969 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
970 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
971 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
972 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
973 } else {
974 mOutsets.set(0, 0, 0, 0);
975 }
976
Craig Mautnera248eee2013-05-07 11:41:27 -0700977 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800978 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -0800979 if (windowsAreFloating && !mFrame.isEmpty()) {
Robert Carre65a1c42017-02-28 16:52:59 -0800980 // For pinned workspace the frame isn't limited in any particular
981 // way since SystemUI controls the bounds. For freeform however
982 // we want to keep things inside the content frame.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700983 final Rect limitFrame = task.inPinnedWindowingMode() ? mFrame : mContentFrame;
Skuhne81c524a2015-08-12 13:34:14 -0700984 // Keep the frame out of the blocked system area, limit it in size to the content area
985 // and make sure that there is always a minimum visible so that the user can drag it
986 // into a usable area..
Robert Carre65a1c42017-02-28 16:52:59 -0800987 final int height = Math.min(mFrame.height(), limitFrame.height());
988 final int width = Math.min(limitFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700989 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +0900990 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
991 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
992 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
993 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Robert Carre65a1c42017-02-28 16:52:59 -0800994 final int top = Math.max(limitFrame.top,
995 Math.min(mFrame.top, limitFrame.bottom - minVisibleHeight));
996 final int left = Math.max(limitFrame.left + minVisibleWidth - width,
997 Math.min(mFrame.left, limitFrame.right - minVisibleWidth));
Skuhne81c524a2015-08-12 13:34:14 -0700998 mFrame.set(left, top, left + width, top + height);
999 mContentFrame.set(mFrame);
1000 mVisibleFrame.set(mContentFrame);
1001 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -07001002 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001003 dc.getDockedDividerController().positionDockedStackedDivider(mFrame);
Jorim Jaggi192086e2016-03-11 17:17:03 +01001004 mContentFrame.set(mFrame);
1005 if (!mFrame.equals(mLastFrame)) {
1006 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -08001007 }
Skuhne81c524a2015-08-12 13:34:14 -07001008 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -07001009 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
1010 Math.max(mContentFrame.top, mFrame.top),
1011 Math.min(mContentFrame.right, mFrame.right),
1012 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001013
Jorim Jaggi656f6502016-04-11 21:08:17 -07001014 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
1015 Math.max(mVisibleFrame.top, mFrame.top),
1016 Math.min(mVisibleFrame.right, mFrame.right),
1017 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001018
Jorim Jaggi656f6502016-04-11 21:08:17 -07001019 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
1020 Math.max(mStableFrame.top, mFrame.top),
1021 Math.min(mStableFrame.right, mFrame.right),
1022 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -07001023 }
Adrian Roosfa104232014-06-20 16:10:14 -07001024
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07001025 if (inFullscreenContainer && !windowsAreFloating) {
Jorim Jaggi899327f2016-02-25 20:44:18 -05001026 // Windows that are not fullscreen can be positioned outside of the display frame,
1027 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -07001028 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
1029 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
1030 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
1031 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -08001032 }
Craig Mautnereda67292013-04-28 13:50:14 -07001033
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001034 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001035 // For the docked divider, we calculate the stable insets like a full-screen window
1036 // so it can use it to calculate the snap positions.
1037 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
1038 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
1039 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
1040 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -08001041
1042 // The divider doesn't care about insets in any case, so set it to empty so we don't
1043 // trigger a relayout when moving it.
1044 mContentInsets.setEmpty();
1045 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001046 } else {
Bryce Leef3c6a472017-11-14 14:53:06 -08001047 getDisplayContent().getBounds(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -07001048 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
1049 // non-fullscreen mode.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07001050 boolean overrideRightInset = !windowsAreFloating && !inFullscreenContainer
1051 && mFrame.right > mTmpRect.right;
1052 boolean overrideBottomInset = !windowsAreFloating && !inFullscreenContainer
1053 && mFrame.bottom > mTmpRect.bottom;
Jorim Jaggi656f6502016-04-11 21:08:17 -07001054 mContentInsets.set(mContentFrame.left - mFrame.left,
1055 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -07001056 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -07001057 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -07001058 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -07001059 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -08001060
Jorim Jaggi656f6502016-04-11 21:08:17 -07001061 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
1062 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -07001063 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -07001064 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -07001065 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -07001066 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -08001067
Jorim Jaggi656f6502016-04-11 21:08:17 -07001068 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
1069 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -07001070 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -07001071 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -07001072 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -07001073 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001074 }
Adrian Roosfa104232014-06-20 16:10:14 -07001075
Jorim Jaggi656f6502016-04-11 21:08:17 -07001076 // Offset the actual frame by the amount layout frame is off.
1077 mFrame.offset(-layoutXDiff, -layoutYDiff);
1078 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -07001079 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
1080 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
1081 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
1082
Adrian Roos5c6b6222017-11-07 17:36:10 +01001083 // TODO(roosa): Figure out what frame exactly this needs to be calculated with.
1084 mDisplayCutout = displayCutout.calculateRelativeTo(mFrame);
1085
1086
Craig Mautnereda67292013-04-28 13:50:14 -07001087 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001088 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001089 // If there is a size compatibility scale being applied to the
1090 // window, we need to apply this to its insets so that they are
1091 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -07001092 mOverscanInsets.scale(mInvGlobalScale);
1093 mContentInsets.scale(mInvGlobalScale);
1094 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -07001095 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001096 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001097
1098 // Also the scaled frame that we report to the app needs to be
1099 // adjusted to be in its coordinate space.
1100 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001101 }
1102
Craig Mautnereda67292013-04-28 13:50:14 -07001103 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001104 final DisplayContent displayContent = getDisplayContent();
1105 if (displayContent != null) {
1106 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwale0303c572016-10-20 10:16:29 -07001107 getDisplayContent().mWallpaperController.updateWallpaperOffset(
Wale Ogunwalee8069dc2015-08-18 09:52:01 -07001108 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001109 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001110 }
1111
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001112 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001113 "Resolving (mRequestedWidth="
1114 + mRequestedWidth + ", mRequestedheight="
1115 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
1116 + "): frame=" + mFrame.toShortString()
1117 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07001118 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -07001119 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001120 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001121 }
1122
Bryce Leef3c6a472017-11-14 14:53:06 -08001123 // TODO: Look into whether this override is still necessary.
1124 @Override
1125 public Rect getBounds() {
1126 if (isInMultiWindowMode()) {
1127 return getTask().getBounds();
1128 } else if (mAppToken != null){
1129 return mAppToken.getBounds();
1130 } else {
1131 return super.getBounds();
1132 }
1133 }
1134
Craig Mautnera2c77052012-03-26 12:14:43 -07001135 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001136 public Rect getFrameLw() {
1137 return mFrame;
1138 }
1139
Craig Mautnera2c77052012-03-26 12:14:43 -07001140 @Override
Rob Carr06be6bb2018-02-06 16:26:06 +00001141 public Point getShownPositionLw() {
1142 return mShownPosition;
1143 }
1144
1145 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001146 public Rect getDisplayFrameLw() {
1147 return mDisplayFrame;
1148 }
1149
Craig Mautnera2c77052012-03-26 12:14:43 -07001150 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001151 public Rect getOverscanFrameLw() {
1152 return mOverscanFrame;
1153 }
1154
1155 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001156 public Rect getContentFrameLw() {
1157 return mContentFrame;
1158 }
1159
Craig Mautnera2c77052012-03-26 12:14:43 -07001160 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001161 public Rect getVisibleFrameLw() {
1162 return mVisibleFrame;
1163 }
1164
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001165 Rect getStableFrameLw() {
1166 return mStableFrame;
1167 }
1168
Craig Mautnera2c77052012-03-26 12:14:43 -07001169 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001170 public boolean getGivenInsetsPendingLw() {
1171 return mGivenInsetsPending;
1172 }
1173
Craig Mautnera2c77052012-03-26 12:14:43 -07001174 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001175 public Rect getGivenContentInsetsLw() {
1176 return mGivenContentInsets;
1177 }
1178
Craig Mautnera2c77052012-03-26 12:14:43 -07001179 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001180 public Rect getGivenVisibleInsetsLw() {
1181 return mGivenVisibleInsets;
1182 }
1183
Craig Mautnera2c77052012-03-26 12:14:43 -07001184 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001185 public WindowManager.LayoutParams getAttrs() {
1186 return mAttrs;
1187 }
1188
Craig Mautner812d2ca2012-09-27 15:35:34 -07001189 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001190 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001191 return getDisplayContent().getNeedsMenu(this, bottom);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001192 }
1193
Craig Mautner19d59bc2012-09-04 11:15:56 -07001194 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001195 public int getSystemUiVisibility() {
1196 return mSystemUiVisibility;
1197 }
1198
Craig Mautner19d59bc2012-09-04 11:15:56 -07001199 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001200 public int getSurfaceLayer() {
1201 return mLayer;
1202 }
1203
Craig Mautner812d2ca2012-09-27 15:35:34 -07001204 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001205 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001206 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001207 }
1208
1209 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001210 public IApplicationToken getAppToken() {
1211 return mAppToken != null ? mAppToken.appToken : null;
1212 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001213
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001214 @Override
1215 public boolean isVoiceInteraction() {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001216 return mAppToken != null && mAppToken.mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001217 }
1218
Robert Carr31aa98b2016-07-20 15:29:03 -07001219 boolean setReportResizeHints() {
Craig Mautner4c5eb222013-11-18 12:59:05 -08001220 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1221 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1222 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001223 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001224 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
Robert Carr31aa98b2016-07-20 15:29:03 -07001225 mFrameSizeChanged |= (mLastFrame.width() != mFrame.width()) ||
1226 (mLastFrame.height() != mFrame.height());
Adrian Roos5c6b6222017-11-07 17:36:10 +01001227 mDisplayCutoutChanged |= !mLastDisplayCutout.equals(mDisplayCutout);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001228 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
Adrian Roos5c6b6222017-11-07 17:36:10 +01001229 || mOutsetsChanged || mFrameSizeChanged || mDisplayCutoutChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001230 }
1231
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001232 /**
1233 * Adds the window to the resizing list if any of the parameters we use to track the window
1234 * dimensions or insets have changed.
1235 */
1236 void updateResizingWindowIfNeeded() {
1237 final WindowStateAnimator winAnimator = mWinAnimator;
1238 if (!mHasSurface || mService.mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
1239 return;
1240 }
1241
1242 final Task task = getTask();
1243 // In the case of stack bound animations, the window frames will update (unlike other
1244 // animations which just modify various transformation properties). We don't want to
1245 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1246 // the frame may not correspond to the surface size or the onscreen area at various
1247 // phases in the animation, and the client will become sad and confused.
Winson Chung40a5f932017-04-13 16:39:36 -07001248 if (task != null && task.mStack.isAnimatingBounds()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001249 return;
1250 }
1251
1252 setReportResizeHints();
1253 boolean configChanged = isConfigChanged();
1254 if (DEBUG_CONFIGURATION && configChanged) {
1255 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1256 }
1257
1258 final boolean dragResizingChanged = isDragResizeChanged()
1259 && !isDragResizingChangeReported();
1260
1261 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
1262 + " dragResizingChanged=" + dragResizingChanged + " last=" + mLastFrame
1263 + " frame=" + mFrame);
1264
1265 // We update mLastFrame always rather than in the conditional with the last inset
1266 // variables, because mFrameSizeChanged only tracks the width and height changing.
1267 mLastFrame.set(mFrame);
1268
1269 if (mContentInsetsChanged
1270 || mVisibleInsetsChanged
1271 || winAnimator.mSurfaceResized
1272 || mOutsetsChanged
1273 || mFrameSizeChanged
Adrian Roos5c6b6222017-11-07 17:36:10 +01001274 || mDisplayCutoutChanged
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001275 || configChanged
1276 || dragResizingChanged
Andrii Kulianb2e37802017-01-11 00:36:44 -08001277 || mReportOrientationChanged) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001278 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1279 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
1280 + " contentInsetsChanged=" + mContentInsetsChanged
1281 + " " + mContentInsets.toShortString()
1282 + " visibleInsetsChanged=" + mVisibleInsetsChanged
1283 + " " + mVisibleInsets.toShortString()
1284 + " stableInsetsChanged=" + mStableInsetsChanged
1285 + " " + mStableInsets.toShortString()
1286 + " outsetsChanged=" + mOutsetsChanged
1287 + " " + mOutsets.toShortString()
1288 + " surfaceResized=" + winAnimator.mSurfaceResized
1289 + " configChanged=" + configChanged
1290 + " dragResizingChanged=" + dragResizingChanged
Adrian Roos5c6b6222017-11-07 17:36:10 +01001291 + " reportOrientationChanged=" + mReportOrientationChanged
1292 + " displayCutoutChanged=" + mDisplayCutoutChanged);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001293 }
1294
1295 // If it's a dead window left on screen, and the configuration changed, there is nothing
1296 // we can do about it. Remove the window now.
1297 if (mAppToken != null && mAppDied) {
1298 mAppToken.removeDeadWindows();
1299 return;
1300 }
1301
Jorim Jaggidc9385a2017-05-13 02:00:31 +02001302 updateLastInsetValues();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001303 mService.makeWindowFreezingScreenIfNeededLocked(this);
1304
1305 // If the orientation is changing, or we're starting or ending a drag resizing action,
1306 // then we need to hold off on unfreezing the display until this window has been
1307 // redrawn; to do that, we need to go through the process of getting informed by the
1308 // application when it has finished drawing.
Robert Carr09286c92018-02-15 13:52:31 -08001309 if (getOrientationChanging() || dragResizingChanged) {
Robert Carre13b58e2017-08-31 14:50:44 -07001310 if (DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001311 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1312 + ", mDrawState=DRAW_PENDING in " + this
1313 + ", surfaceController " + winAnimator.mSurfaceController);
1314 }
1315 winAnimator.mDrawState = DRAW_PENDING;
1316 if (mAppToken != null) {
1317 mAppToken.clearAllDrawn();
1318 }
1319 }
1320 if (!mService.mResizingWindows.contains(this)) {
1321 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
1322 mService.mResizingWindows.add(this);
1323 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07001324 } else if (getOrientationChanging()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001325 if (isDrawnLw()) {
1326 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1327 + this + ", surfaceController " + winAnimator.mSurfaceController);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001328 setOrientationChanging(false);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001329 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1330 - mService.mDisplayFreezeTime);
1331 }
1332 }
1333 }
1334
Bryce Lee8c3cf382017-07-06 19:47:10 -07001335 boolean getOrientationChanging() {
1336 // In addition to the local state flag, we must also consider the difference in the last
1337 // reported configuration vs. the current state. If the client code has not been informed of
1338 // the change, logic dependent on having finished processing the orientation, such as
1339 // unfreezing, could be improperly triggered.
1340 // TODO(b/62846907): Checking against {@link mLastReportedConfiguration} could be flaky as
1341 // this is not necessarily what the client has processed yet. Find a
1342 // better indicator consistent with the client.
Robert Carr926643f2017-08-02 12:01:12 -07001343 return (mOrientationChanging || (isVisible()
Bryce Lee2b17afd2017-09-21 10:38:20 -07001344 && getConfiguration().orientation != getLastReportedConfiguration().orientation))
Robert Carr9c1c3a02017-08-08 12:59:01 -07001345 && !mSeamlesslyRotated
1346 && !mOrientationChangeTimedOut;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001347 }
1348
1349 void setOrientationChanging(boolean changing) {
1350 mOrientationChanging = changing;
Robert Carr9c1c3a02017-08-08 12:59:01 -07001351 mOrientationChangeTimedOut = false;
1352 }
1353
1354 void orientationChangeTimedOut() {
1355 mOrientationChangeTimedOut = true;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001356 }
1357
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001358 DisplayContent getDisplayContent() {
1359 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001360 }
1361
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001362 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001363 final DisplayContent displayContent = getDisplayContent();
1364 return displayContent != null ? displayContent.getDisplayInfo() : null;
1365 }
1366
Jorim Jaggife762342016-10-13 14:33:27 +02001367 @Override
1368 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001369 final DisplayContent displayContent = getDisplayContent();
1370 if (displayContent == null) {
1371 return -1;
1372 }
1373 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001374 }
1375
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001376 Task getTask() {
Bryce Lee6d410262017-02-28 15:30:17 -08001377 return mAppToken != null ? mAppToken.getTask() : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001378 }
1379
1380 TaskStack getStack() {
1381 Task task = getTask();
1382 if (task != null) {
1383 if (task.mStack != null) {
1384 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001385 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001386 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001387 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1388 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001389 final DisplayContent dc = getDisplayContent();
1390 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001391 }
1392
Skuhnef932e562015-08-20 12:07:30 -07001393 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001394 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001395 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001396 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001397 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001398 final Task task = getTask();
1399 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001400 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001401 mTmpRect.setEmpty();
1402 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001403 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001404 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001405 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001406 } else {
1407 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001408 }
1409 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001410
Chong Zhang9184ec62015-09-24 12:32:21 -07001411 bounds.set(mVisibleFrame);
1412 if (intersectWithStackBounds) {
1413 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001414 }
1415
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001416 if (bounds.isEmpty()) {
1417 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001418 if (intersectWithStackBounds) {
1419 bounds.intersect(mTmpRect);
1420 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001421 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001422 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001423 }
1424
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001425 public long getInputDispatchingTimeoutNanos() {
1426 return mAppToken != null
Wale Ogunwale72919d22016-12-08 18:58:50 -08001427 ? mAppToken.mInputDispatchingTimeoutNanos
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001428 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1429 }
1430
Craig Mautnere8552142012-11-07 13:55:47 -08001431 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001432 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001433 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001434 }
1435
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001436 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1437 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1438 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1439 if (dtdx < -.000001f || dtdx > .000001f) return false;
1440 if (dsdy < -.000001f || dsdy > .000001f) return false;
1441 return true;
1442 }
1443
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001444 void prelayout() {
1445 if (mEnforceSizeCompat) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001446 mGlobalScale = getDisplayContent().mCompatibleScreenScale;
1447 mInvGlobalScale = 1 / mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001448 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001449 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001450 }
1451 }
1452
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001453 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001454 boolean hasContentToDisplay() {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001455 if (!mAppFreezing && isDrawnLw() && (mViewVisibility == View.VISIBLE
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001456 || (mWinAnimator.isAnimationSet() && !mService.mAppTransition.isTransitionSet()))) {
1457 return true;
1458 }
1459
Wale Ogunwale44f21802016-09-02 12:49:48 -07001460 return super.hasContentToDisplay();
1461 }
1462
1463 @Override
1464 boolean isVisible() {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001465 return wouldBeVisibleIfPolicyIgnored() && mPolicyVisibility;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001466 }
1467
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001468 /**
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001469 * @return True if the window would be visible if we'd ignore policy visibility, false
1470 * otherwise.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001471 */
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001472 boolean wouldBeVisibleIfPolicyIgnored() {
Jorim Jaggi43530c92017-05-18 01:53:56 +02001473 return mHasSurface && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001474 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001475 }
1476
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001477 @Override
1478 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001479 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001480 }
1481
1482 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001483 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1484 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001485 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001486 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1487 boolean isWinVisibleLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001488 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.isSelfAnimating())
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001489 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001490 }
1491
1492 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001493 * The same as isVisible(), but follows the current hidden state of the associated app token,
1494 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001495 */
1496 boolean isVisibleNow() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001497 return (!mToken.isHidden() || mAttrs.type == TYPE_APPLICATION_STARTING)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001498 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001499 }
1500
1501 /**
1502 * Can this window possibly be a drag/drop target? The test here is
1503 * a combination of the above "visible now" with the check that the
1504 * Input Manager uses when discarding windows from input consideration.
1505 */
1506 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001507 return isVisibleNow() && !mRemoved
1508 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001509 }
1510
1511 /**
1512 * Same as isVisible(), but we also count it as visible between the
1513 * call to IWindowSession.add() and the first relayout().
1514 */
1515 boolean isVisibleOrAdding() {
1516 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001517 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001518 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001519 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001520 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001521 }
1522
1523 /**
1524 * Is this window currently on-screen? It is on-screen either if it
1525 * is visible or it is currently running an animation before no longer
1526 * being visible.
1527 */
1528 boolean isOnScreen() {
Jorim Jaggiaf221d12016-11-15 14:59:57 -08001529 if (!mHasSurface || mDestroying || !mPolicyVisibility) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001530 return false;
1531 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001532 final AppWindowToken atoken = mAppToken;
1533 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001534 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001535 || mWinAnimator.isAnimationSet());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001536 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01001537 return !isParentWindowHidden() || mWinAnimator.isAnimationSet();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001538 }
1539
1540 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001541 * Whether this window's drawn state might affect the drawn states of the app token.
1542 *
Chong Zhang8e4bda92016-05-04 15:08:18 -07001543 * @return true if the window should be considered while evaluating allDrawn flags.
1544 */
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001545 boolean mightAffectAllDrawn() {
1546 final boolean isAppType = mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1547 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION;
1548 return (isOnScreen() || isAppType) && !mAnimatingExit && !mDestroying;
Chong Zhang8e4bda92016-05-04 15:08:18 -07001549 }
1550
1551 /**
1552 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1553 * it must be drawn before allDrawn can become true.
1554 */
1555 boolean isInteresting() {
1556 return mAppToken != null && !mAppDied
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001557 && (!mAppToken.isFreezingScreen() || !mAppFreezing);
Chong Zhang8e4bda92016-05-04 15:08:18 -07001558 }
1559
1560 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001561 * Like isOnScreen(), but we don't return true if the window is part
1562 * of a transition that has not yet been started.
1563 */
1564 boolean isReadyForDisplay() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001565 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001566 return false;
1567 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001568 return mHasSurface && mPolicyVisibility && !mDestroying
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001569 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.isHidden())
1570 || mWinAnimator.isAnimationSet());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001571 }
1572
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001573 // TODO: Another visibility method that was added late in the release to minimize risk.
1574 @Override
1575 public boolean canAffectSystemUiFlags() {
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001576 final boolean translucent = mAttrs.alpha == 0.0f;
Jorim Jaggi72207752018-01-08 13:16:59 +01001577 if (translucent) {
1578 return false;
1579 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001580 if (mAppToken == null) {
1581 final boolean shown = mWinAnimator.getShown();
1582 final boolean exiting = mAnimatingExit || mDestroying;
Jorim Jaggi72207752018-01-08 13:16:59 +01001583 return shown && !exiting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001584 } else {
1585 return !mAppToken.isHidden();
1586 }
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001587 }
1588
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001589 /**
1590 * Like isOnScreen, but returns false if the surface hasn't yet
1591 * been drawn.
1592 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001593 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001594 public boolean isDisplayedLw() {
1595 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001596 return isDrawnLw() && mPolicyVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001597 && ((!isParentWindowHidden() && (atoken == null || !atoken.hiddenRequested))
1598 || mWinAnimator.isAnimationSet());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001599 }
1600
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001601 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001602 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001603 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001604 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001605 public boolean isAnimatingLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001606 return isAnimating();
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001607 }
1608
Craig Mautner812d2ca2012-09-27 15:35:34 -07001609 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001610 public boolean isGoneForLayoutLw() {
1611 final AppWindowToken atoken = mAppToken;
1612 return mViewVisibility == View.GONE
1613 || !mRelayoutCalled
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001614 || (atoken == null && mToken.isHidden())
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001615 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001616 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001617 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001618 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001619 }
1620
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001621 /**
1622 * Returns true if the window has a surface that it has drawn a
1623 * complete UI in to.
1624 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001625 public boolean isDrawFinishedLw() {
1626 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001627 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1628 || mWinAnimator.mDrawState == READY_TO_SHOW
1629 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001630 }
1631
1632 /**
1633 * Returns true if the window has a surface that it has drawn a
1634 * complete UI in to.
1635 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001636 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001637 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001638 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001639 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001640 }
1641
1642 /**
1643 * Return true if the window is opaque and fully drawn. This indicates
1644 * it may obscure windows behind it.
1645 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001646 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001647 // When there is keyguard, wallpaper could be placed over the secure app
1648 // window but invisible. We need to check wallpaper visibility explicitly
1649 // to determine if it's occluding apps.
1650 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1651 || (mIsWallpaper && mWallpaperVisible))
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001652 && isDrawnLw() && !mWinAnimator.isAnimationSet();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001653 }
1654
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001655 @Override
1656 void onMovedByResize() {
1657 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001658 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001659 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001660 }
1661
1662 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1663 boolean changed = false;
1664
1665 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001666 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001667 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1668 }
1669
1670 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1671 // Starting window that's exiting will be removed when the animation finishes.
1672 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1673 // to actually remove it.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001674 if (!visible && isVisibleNow() && mAppToken.isSelfAnimating()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001675 mAnimatingExit = true;
1676 mRemoveOnExit = true;
1677 mWindowRemovalAllowed = true;
1678 }
1679 return changed;
1680 }
1681
Robert Carrd5c7dd62017-03-08 10:39:30 -08001682 // Next up we will notify the client that it's visibility has changed.
1683 // We need to prevent it from destroying child surfaces until
1684 // the animation has finished.
1685 if (!visible && isVisibleNow()) {
1686 mWinAnimator.detachChildren();
1687 }
1688
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001689 if (visible != isVisibleNow()) {
1690 if (!runningAppAnimation) {
1691 final AccessibilityController accessibilityController =
1692 mService.mAccessibilityController;
1693 final int winTransit = visible ? TRANSIT_ENTER : TRANSIT_EXIT;
1694 mWinAnimator.applyAnimationLocked(winTransit, visible);
1695 //TODO (multidisplay): Magnification is supported only for the default
1696 if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
1697 accessibilityController.onWindowTransitionLocked(this, winTransit);
1698 }
1699 }
1700 changed = true;
1701 setDisplayLayoutNeeded();
1702 }
1703
1704 return changed;
1705 }
1706
1707 boolean onSetAppExiting() {
1708 final DisplayContent displayContent = getDisplayContent();
1709 boolean changed = false;
1710
1711 if (isVisibleNow()) {
1712 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
1713 //TODO (multidisplay): Magnification is supported only for the default
1714 if (mService.mAccessibilityController != null && isDefaultDisplay()) {
1715 mService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
1716 }
1717 changed = true;
1718 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001719 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001720 }
1721 }
1722
1723 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001724 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001725 changed |= c.onSetAppExiting();
1726 }
1727
1728 return changed;
1729 }
1730
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001731 @Override
1732 void onResize() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001733 final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
1734 if (mHasSurface && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001735 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001736 resizingWindows.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001737 }
1738 if (isGoneForLayoutLw()) {
1739 mResizedWhileGone = true;
1740 }
1741
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001742 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001743 }
1744
1745 void onUnfreezeBounds() {
1746 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001747 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001748 c.onUnfreezeBounds();
1749 }
1750
1751 if (!mHasSurface) {
1752 return;
1753 }
1754
1755 mLayoutNeeded = true;
1756 setDisplayLayoutNeeded();
1757 if (!mService.mResizingWindows.contains(this)) {
1758 mService.mResizingWindows.add(this);
1759 }
1760 }
1761
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001762 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001763 * If the window has moved due to its containing content frame changing, then notify the
1764 * listeners and optionally animate it. Simply checking a change of position is not enough,
1765 * because being move due to dock divider is not a trigger for animation.
1766 */
chaviw161ea3e2018-01-31 12:01:12 -08001767 void handleWindowMovedIfNeeded() {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001768 if (!hasMoved()) {
1769 return;
1770 }
1771
1772 // Frame has moved, containing content frame has also moved, and we're not currently
1773 // animating... let's do something.
1774 final int left = mFrame.left;
1775 final int top = mFrame.top;
1776 final Task task = getTask();
1777 final boolean adjustedForMinimizedDockOrIme = task != null
1778 && (task.mStack.isAdjustedForMinimizedDockedStack()
1779 || task.mStack.isAdjustedForIme());
David Stevens9440dc82017-03-16 19:00:20 -07001780 if (mToken.okToAnimate()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001781 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1782 && !isDragResizing() && !adjustedForMinimizedDockOrIme
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001783 && getWindowConfiguration().hasMovementAnimations()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001784 && !mWinAnimator.mLastHidden) {
chaviw161ea3e2018-01-31 12:01:12 -08001785 startMoveAnimation(left, top);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001786 }
1787
1788 //TODO (multidisplay): Accessibility supported only for the default display.
1789 if (mService.mAccessibilityController != null
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001790 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001791 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
1792 }
1793
1794 try {
1795 mClient.moved(left, top);
1796 } catch (RemoteException e) {
1797 }
1798 mMovedByResize = false;
1799 }
1800
1801 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001802 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001803 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1804 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001805 private boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001806 return mHasSurface && (mContentChanged || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001807 && !mAnimatingExit
Chong Zhangbd0d9372015-12-28 15:18:29 -08001808 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001809 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001810 }
1811
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001812 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001813 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001814 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001815 return false;
1816 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001817 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001818 }
1819
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001820 boolean fillsDisplay() {
1821 final DisplayInfo displayInfo = getDisplayInfo();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001822 return mFrame.left <= 0 && mFrame.top <= 0
1823 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001824 }
1825
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001826 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001827 boolean isConfigChanged() {
Bryce Lee2b17afd2017-09-21 10:38:20 -07001828 return !getLastReportedConfiguration().equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001829 }
1830
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001831 void onWindowReplacementTimeout() {
1832 if (mWillReplaceWindow) {
1833 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001834 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001835 // delays removal on certain conditions, which will leave the stale window in the
1836 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1837 //
1838 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001839 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001840 } else {
1841 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001842 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001843 c.onWindowReplacementTimeout();
1844 }
1845 }
1846 }
1847
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001848 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001849 void forceWindowsScaleableInTransaction(boolean force) {
1850 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1851 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1852 }
1853
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001854 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001855 }
1856
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001857 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001858 void removeImmediately() {
1859 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001860
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001861 if (mRemoved) {
1862 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001863 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1864 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001865 return;
1866 }
1867
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001868 mRemoved = true;
1869
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001870 mWillReplaceWindow = false;
1871 if (mReplacementWindow != null) {
1872 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1873 }
1874
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001875 final DisplayContent dc = getDisplayContent();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001876 if (mService.mInputMethodTarget == this) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001877 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001878 }
1879
1880 final int type = mAttrs.type;
1881 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001882 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001883 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001884 if (mTapExcludeRegionHolder != null) {
1885 // If a tap exclude region container was initialized for this window, then it should've
1886 // also been registered in display.
1887 dc.mTapExcludeProvidingWindows.remove(this);
1888 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001889 mPolicy.removeWindowLw(this);
1890
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001891 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001892
Craig Mautner96868332012-12-04 14:29:11 -08001893 mWinAnimator.destroyDeferredSurfaceLocked();
1894 mWinAnimator.destroySurfaceLocked();
Wale Ogunwale943002b2017-02-15 19:34:01 -08001895 mSession.windowRemovedLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001896 try {
1897 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1898 } catch (RuntimeException e) {
1899 // Ignore if it has already been removed (usually because
1900 // we are doing this as part of processing a death note.)
1901 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001902
1903 mService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001904 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001905
Wale Ogunwale571771c2016-08-26 13:18:50 -07001906 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001907 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001908 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001909 removeIfPossible(false /*keepVisibleDeadWindow*/);
1910 }
1911
Wale Ogunwale571771c2016-08-26 13:18:50 -07001912 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001913 mWindowRemovalAllowed = true;
1914 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1915 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1916
1917 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1918 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1919 "Starting window removed " + this);
1920
1921 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && this == mService.mCurrentFocus)
1922 Slog.v(TAG_WM, "Remove " + this + " client="
1923 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1924 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1925 + Debug.getCallers(5));
1926
1927 final long origId = Binder.clearCallingIdentity();
1928
Peter Visontay3556a3b2017-11-01 17:23:17 +00001929 try {
1930 disposeInputChannel();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001931
Peter Visontay3556a3b2017-11-01 17:23:17 +00001932 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1933 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1934 + " mAnimatingExit=" + mAnimatingExit
1935 + " mRemoveOnExit=" + mRemoveOnExit
1936 + " mHasSurface=" + mHasSurface
1937 + " surfaceShowing=" + mWinAnimator.getShown()
1938 + " isAnimationSet=" + mWinAnimator.isAnimationSet()
1939 + " app-animation="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001940 + (mAppToken != null ? mAppToken.isSelfAnimating() : "false")
Peter Visontay3556a3b2017-11-01 17:23:17 +00001941 + " mWillReplaceWindow=" + mWillReplaceWindow
1942 + " inPendingTransaction="
1943 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
1944 + " mDisplayFrozen=" + mService.mDisplayFrozen
1945 + " callers=" + Debug.getCallers(6));
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001946
Peter Visontay3556a3b2017-11-01 17:23:17 +00001947 // Visibility of the removed window. Will be used later to update orientation later on.
1948 boolean wasVisible = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001949
Peter Visontay3556a3b2017-11-01 17:23:17 +00001950 final int displayId = getDisplayId();
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001951
Peter Visontay3556a3b2017-11-01 17:23:17 +00001952 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1953 // window until the animation is done. If the display is frozen, just remove immediately,
1954 // since the animation wouldn't be seen.
1955 if (mHasSurface && mToken.okToAnimate()) {
1956 if (mWillReplaceWindow) {
1957 // This window is going to be replaced. We need to keep it around until the new one
1958 // gets added, then we will get rid of this one.
1959 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1960 "Preserving " + this + " until the new one is " + "added");
1961 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1962 // been removed. We probably need another flag to indicate that window removal
1963 // should be deffered vs. overloading the flag that says we are playing an exit
1964 // animation.
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001965 mAnimatingExit = true;
Peter Visontay3556a3b2017-11-01 17:23:17 +00001966 mReplacingRemoveRequested = true;
1967 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001968 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001969
Peter Visontay3556a3b2017-11-01 17:23:17 +00001970 // If we are not currently running the exit animation, we need to see about starting one
1971 wasVisible = isWinVisibleLw();
1972
1973 if (keepVisibleDeadWindow) {
1974 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1975 "Not removing " + this + " because app died while it's visible");
1976
1977 mAppDied = true;
1978 setDisplayLayoutNeeded();
1979 mService.mWindowPlacerLocked.performSurfacePlacement();
1980
1981 // Set up a replacement input channel since the app is now dead.
1982 // We need to catch tapping on the dead window to restart the app.
1983 openInputChannel(null);
1984 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
1985 return;
1986 }
1987
1988 if (wasVisible) {
1989 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
1990
1991 // Try starting an animation.
1992 if (mWinAnimator.applyAnimationLocked(transit, false)) {
1993 mAnimatingExit = true;
1994 }
1995 //TODO (multidisplay): Magnification is supported only for the default display.
1996 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
1997 mService.mAccessibilityController.onWindowTransitionLocked(this, transit);
1998 }
1999 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02002000 final boolean isAnimating = mWinAnimator.isAnimationSet()
2001 && (mAppToken == null || !mAppToken.isWaitingForTransitionStart());
Peter Visontay3556a3b2017-11-01 17:23:17 +00002002 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
2003 && mAppToken.isLastWindow(this);
2004 // We delay the removal of a window if it has a showing surface that can be used to run
2005 // exit animation and it is marked as exiting.
2006 // Also, If isn't the an animating starting window that is the last window in the app.
2007 // We allow the removal of the non-animating starting window now as there is no
2008 // additional window or animation that will trigger its removal.
2009 if (mWinAnimator.getShown() && mAnimatingExit
2010 && (!lastWindowIsStartingWindow || isAnimating)) {
2011 // The exit animation is running or should run... wait for it!
2012 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
2013 "Not removing " + this + " due to exit animation ");
2014 setupWindowForRemoveOnExit();
2015 if (mAppToken != null) {
2016 mAppToken.updateReportedVisibilityLocked();
2017 }
2018 return;
2019 }
2020 }
2021
2022 removeImmediately();
2023 // Removing a visible window will effect the computed orientation
2024 // So just update orientation if needed.
2025 if (wasVisible && mService.updateOrientationFromAppTokensLocked(false, displayId)) {
2026 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
2027 }
2028 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
2029 } finally {
2030 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002031 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002032 }
2033
2034 private void setupWindowForRemoveOnExit() {
2035 mRemoveOnExit = true;
2036 setDisplayLayoutNeeded();
2037 // Request a focus update as this window's input channel is already gone. Otherwise
2038 // we could have no focused window in input manager.
2039 final boolean focusChanged = mService.updateFocusedWindowLocked(
2040 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
2041 mService.mWindowPlacerLocked.performSurfacePlacement();
2042 if (focusChanged) {
2043 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2044 }
2045 }
2046
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08002047 void setHasSurface(boolean hasSurface) {
2048 mHasSurface = hasSurface;
2049 }
2050
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002051 boolean canBeImeTarget() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002052 if (mIsImWindow) {
2053 // IME windows can't be IME targets. IME targets are required to be below the IME
2054 // windows and that wouldn't be possible if the IME window is its own target...silly.
2055 return false;
2056 }
2057
Winson Chung3d0a74a2017-07-12 12:37:19 -07002058 final boolean windowsAreFocusable = mAppToken == null || mAppToken.windowsAreFocusable();
Winson Chungb1549342017-07-11 09:59:56 -07002059 if (!windowsAreFocusable) {
2060 // This window can't be an IME target if the app's windows should not be focusable.
2061 return false;
2062 }
2063
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002064 final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002065 final int type = mAttrs.type;
2066
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002067 // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are set or
2068 // both are cleared...and not a starting window.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002069 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
2070 && type != TYPE_APPLICATION_STARTING) {
2071 return false;
2072 }
2073
2074 if (DEBUG_INPUT_METHOD) {
2075 Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding());
2076 if (!isVisibleOrAdding()) {
2077 Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController
2078 + " relayoutCalled=" + mRelayoutCalled
2079 + " viewVis=" + mViewVisibility
2080 + " policyVis=" + mPolicyVisibility
2081 + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim
2082 + " parentHidden=" + isParentWindowHidden()
2083 + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
2084 if (mAppToken != null) {
2085 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + mAppToken.hiddenRequested);
2086 }
2087 }
2088 }
2089 return isVisibleOrAdding();
2090 }
2091
Chong Zhangacf11402015-11-04 16:23:10 -08002092 private final class DeadWindowEventReceiver extends InputEventReceiver {
2093 DeadWindowEventReceiver(InputChannel inputChannel) {
2094 super(inputChannel, mService.mH.getLooper());
2095 }
2096 @Override
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -07002097 public void onInputEvent(InputEvent event, int displayId) {
Chong Zhangacf11402015-11-04 16:23:10 -08002098 finishInputEvent(event, true);
2099 }
2100 }
2101 /**
2102 * Dummy event receiver for windows that died visible.
2103 */
2104 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2105
Chong Zhang112eb8c2015-11-02 11:17:00 -08002106 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002107 if (mInputChannel != null) {
2108 throw new IllegalStateException("Window already has an input channel.");
2109 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002110 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002111 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2112 mInputChannel = inputChannels[0];
2113 mClientChannel = inputChannels[1];
2114 mInputWindowHandle.inputChannel = inputChannels[0];
2115 if (outInputChannel != null) {
2116 mClientChannel.transferTo(outInputChannel);
2117 mClientChannel.dispose();
2118 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002119 } else {
2120 // If the window died visible, we setup a dummy input channel, so that taps
2121 // can still detected by input monitor channel, and we can relaunch the app.
2122 // Create dummy event receiver that simply reports all events as handled.
2123 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002124 }
2125 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002126 }
2127
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002128 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002129 if (mDeadWindowEventReceiver != null) {
2130 mDeadWindowEventReceiver.dispose();
2131 mDeadWindowEventReceiver = null;
2132 }
2133
2134 // unregister server channel first otherwise it complains about broken channel
2135 if (mInputChannel != null) {
2136 mService.mInputManager.unregisterInputChannel(mInputChannel);
2137 mInputChannel.dispose();
2138 mInputChannel = null;
2139 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002140 if (mClientChannel != null) {
2141 mClientChannel.dispose();
2142 mClientChannel = null;
2143 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07002144 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002145 }
2146
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002147 /** Returns true if the replacement window was removed. */
2148 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2149 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2150 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2151 removeReplacedWindow();
2152 return true;
2153 }
2154
2155 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002156 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002157 if (c.removeReplacedWindowIfNeeded(replacement)) {
2158 return true;
2159 }
2160 }
2161 return false;
2162 }
2163
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002164 private void removeReplacedWindow() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002165 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002166 mWillReplaceWindow = false;
2167 mAnimateReplacingWindow = false;
2168 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002169 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002170 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002171 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002172 }
2173 }
2174
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002175 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2176 boolean replacementSet = false;
2177
2178 if (mWillReplaceWindow && mReplacementWindow == null
2179 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2180
2181 mReplacementWindow = replacementCandidate;
2182 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2183 replacementSet = true;
2184 }
2185
2186 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002187 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002188 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2189 }
2190
2191 return replacementSet;
2192 }
2193
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002194 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002195 final DisplayContent dc = getDisplayContent();
2196 if (dc != null) {
2197 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002198 }
2199 }
2200
Chong Zhang5117e272016-05-03 12:47:34 -07002201 void applyAdjustForImeIfNeeded() {
2202 final Task task = getTask();
2203 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2204 task.mStack.applyAdjustForImeIfNeeded(task);
2205 }
2206 }
2207
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002208 @Override
2209 void switchUser() {
2210 super.switchUser();
2211 if (isHiddenFromUserLocked()) {
2212 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2213 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
2214 hideLw(false);
2215 }
2216 }
2217
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002218 int getTouchableRegion(Region region, int flags) {
2219 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002220 if (modal && mAppToken != null) {
2221 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002222 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002223 // If this is a modal window we need to dismiss it if it's not full screen and the
2224 // touch happens outside of the frame that displays the content. This means we
2225 // need to intercept touches outside of that window. The dim layer user
2226 // associated with the window (task or stack) will give us the good bounds, as
2227 // they would be used to display the dim layer.
Robert Carrf59b8dd2017-10-02 18:58:36 -07002228 final Task task = getTask();
2229 if (task != null) {
2230 task.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002231 } else {
Robert Carrf59b8dd2017-10-02 18:58:36 -07002232 getStack().getDimBounds(mTmpRect);
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002233 }
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002234 if (inFreeformWindowingMode()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002235 // For freeform windows we the touch region to include the whole surface for the
2236 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002237 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2238 final int delta = WindowManagerService.dipToPixel(
2239 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2240 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002241 }
2242 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002243 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002244 } else {
2245 // Not modal or full screen modal
2246 getTouchableRegion(region);
2247 }
2248 return flags;
2249 }
2250
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002251 void checkPolicyVisibilityChange() {
2252 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2253 if (DEBUG_VISIBILITY) {
2254 Slog.v(TAG, "Policy visibility changing after anim in " +
2255 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2256 }
2257 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002258 if (!mPolicyVisibility) {
Jorim Jaggi2e05af22017-12-28 15:15:11 +01002259 mWinAnimator.hide("checkPolicyVisibilityChange");
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002260 if (mService.mCurrentFocus == this) {
2261 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2262 "setAnimationLocked: setting mFocusMayChange true");
2263 mService.mFocusMayChange = true;
Jorim Jaggi2e05af22017-12-28 15:15:11 +01002264 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002265 }
2266 // Window is no longer visible -- make sure if we were waiting
2267 // for it to be displayed before enabling the display, that
2268 // we allow the display to be enabled now.
2269 mService.enableScreenIfNeededLocked();
2270 }
2271 }
2272 }
2273
2274 void setRequestedSize(int requestedWidth, int requestedHeight) {
2275 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2276 mLayoutNeeded = true;
2277 mRequestedWidth = requestedWidth;
2278 mRequestedHeight = requestedHeight;
2279 }
2280 }
2281
Bryce Leef858b572017-06-29 14:03:33 -07002282 void prepareWindowToDisplayDuringRelayout(boolean wasVisible) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002283 // We need to turn on screen regardless of visibility.
chaviw40234662018-02-07 09:37:16 -08002284 boolean hasTurnScreenOnFlag = (mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0;
2285 boolean allowTheaterMode =
2286 mService.mAllowTheaterModeWakeFromLayout || Settings.Global.getInt(
2287 mService.mContext.getContentResolver(), Settings.Global.THEATER_MODE_ON, 0)
2288 == 0;
2289 boolean canTurnScreenOn = mAppToken == null || mAppToken.canTurnScreenOn();
2290
2291 // The screen will turn on if the following conditions are met
2292 // 1. The window has the flag FLAG_TURN_SCREEN_ON
2293 // 2. The WMS allows theater mode.
2294 // 3. No AWT or the AWT allows the screen to be turned on. This should only be true once
2295 // per resume to prevent the screen getting getting turned on for each relayout. Set
2296 // canTurnScreenOn will be set to false so the window doesn't turn the screen on again
2297 // during this resume.
2298 // 4. When the screen is not interactive. This is because when the screen is already
2299 // interactive, the value may persist until the next animation, which could potentially
2300 // be occurring while turning off the screen. This would lead to the screen incorrectly
2301 // turning back on.
2302 if (hasTurnScreenOnFlag && allowTheaterMode && canTurnScreenOn
2303 && !mPowerManagerWrapper.isInteractive()) {
2304 if (DEBUG_VISIBILITY || DEBUG_POWER) {
2305 Slog.v(TAG, "Relayout window turning screen on: " + this);
2306 }
2307 mPowerManagerWrapper.wakeUp(SystemClock.uptimeMillis(),
2308 "android.server.wm:TURN_ON");
2309 }
2310 if (mAppToken != null) {
2311 mAppToken.setCanTurnScreenOn(false);
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002312 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002313
2314 // If we were already visible, skip rest of preparation.
2315 if (wasVisible) {
2316 if (DEBUG_VISIBILITY) Slog.v(TAG,
2317 "Already visible and does not turn on screen, skip preparing: " + this);
2318 return;
2319 }
2320
2321 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2322 == SOFT_INPUT_ADJUST_RESIZE) {
2323 mLayoutNeeded = true;
2324 }
2325
David Stevens9440dc82017-03-16 19:00:20 -07002326 if (isDrawnLw() && mToken.okToAnimate()) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002327 mWinAnimator.applyEnterAnimationLocked();
2328 }
Bryce Leef858b572017-06-29 14:03:33 -07002329 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002330
Bryce Leef858b572017-06-29 14:03:33 -07002331 void getMergedConfiguration(MergedConfiguration outConfiguration) {
2332 final Configuration globalConfig = mService.mRoot.getConfiguration();
2333 final Configuration overrideConfig = getMergedOverrideConfiguration();
2334 outConfiguration.setConfiguration(globalConfig, overrideConfig);
2335 }
2336
Bryce Lee2b17afd2017-09-21 10:38:20 -07002337 void setLastReportedMergedConfiguration(MergedConfiguration config) {
2338 mLastReportedConfiguration.setTo(config);
2339 }
2340
2341 void getLastReportedMergedConfiguration(MergedConfiguration config) {
2342 config.setTo(mLastReportedConfiguration);
2343 }
2344
2345 private Configuration getLastReportedConfiguration() {
2346 return mLastReportedConfiguration.getMergedConfiguration();
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002347 }
2348
2349 void adjustStartingWindowFlags() {
2350 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2351 && mAppToken.startingWindow != null) {
2352 // Special handling of starting window over the base
2353 // window of the app: propagate lock screen flags to it,
2354 // to provide the correct semantics while starting.
2355 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2356 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2357 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2358 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2359 }
2360 }
2361
2362 void setWindowScale(int requestedWidth, int requestedHeight) {
2363 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2364
2365 if (scaledWindow) {
2366 // requested{Width|Height} Surface's physical size
2367 // attrs.{width|height} Size on screen
2368 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2369 mHScale = (mAttrs.width != requestedWidth) ?
2370 (mAttrs.width / (float)requestedWidth) : 1.0f;
2371 mVScale = (mAttrs.height != requestedHeight) ?
2372 (mAttrs.height / (float)requestedHeight) : 1.0f;
2373 } else {
2374 mHScale = mVScale = 1;
2375 }
2376 }
2377
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002378 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002379 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002380 public void binderDied() {
2381 try {
2382 synchronized(mService.mWindowMap) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002383 final WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002384 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002385 if (win != null) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002386 final DisplayContent dc = getDisplayContent();
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002387 if (win.mAppToken != null && win.mAppToken.findMainWindow() == win) {
2388 mService.mTaskSnapshotController.onAppDied(win.mAppToken);
2389 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002390 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002391 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2392 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002393 // just in case they have the divider at an unstable position. Better
2394 // also reset drag resizing state, because the owner can't do it
2395 // anymore.
Wale Ogunwale61911492017-10-11 08:50:50 -07002396 final TaskStack stack =
Matthew Ng64e77cf2017-10-31 14:01:31 -07002397 dc.getSplitScreenPrimaryStackIgnoringVisibility();
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002398 if (stack != null) {
2399 stack.resetDockedStackToMiddle();
2400 }
Jorim Jaggidcb68142016-02-09 21:51:30 -08002401 mService.setDockedStackResizing(false);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002402 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002403 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002404 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002405 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002406 }
2407 }
2408 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002409 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002410 }
2411 }
2412 }
2413
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002414 /**
2415 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2416 * because we want to preserve its location on screen to be re-activated later when the user
2417 * interacts with it.
2418 */
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002419 private boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwale89973222017-04-23 18:39:45 -07002420 if (!isWinVisibleLw() || mAppToken == null || mAppToken.isClientHidden()) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002421 // Not a visible app window or the app isn't dead.
2422 return false;
2423 }
2424
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002425 if (mAttrs.token != mClient.asBinder()) {
2426 // The window was add by a client using another client's app token. We don't want to
2427 // keep the dead window around for this case since this is meant for 'real' apps.
2428 return false;
2429 }
2430
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002431 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2432 // We don't keep starting windows since they were added by the window manager before
2433 // the app even launched.
2434 return false;
2435 }
2436
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002437 return getWindowConfiguration().keepVisibleDeadAppWindowOnScreen();
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002438 }
2439
Wale Ogunwaled045c822015-12-02 09:14:28 -08002440 /** @return true if this window desires key events. */
2441 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002442 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002443 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002444 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002445 && (mAppToken == null || mAppToken.windowsAreFocusable())
Matthew Nge15352e2016-12-20 15:36:29 -08002446 && !canReceiveTouchInput();
2447 }
2448
2449 /** @return true if this window desires touch events. */
2450 boolean canReceiveTouchInput() {
Bryce Lee6d410262017-02-28 15:30:17 -08002451 return mAppToken != null && mAppToken.getTask() != null
2452 && mAppToken.getTask().mStack.shouldIgnoreInput();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002453 }
2454
Craig Mautner749a7bb2012-04-02 13:49:53 -07002455 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002456 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002457 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002458 }
2459
Craig Mautner749a7bb2012-04-02 13:49:53 -07002460 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002461 public boolean showLw(boolean doAnimation) {
2462 return showLw(doAnimation, true);
2463 }
2464
2465 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002466 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002467 return false;
2468 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002469 if (!mAppOpVisibility) {
2470 // Being hidden due to app op request.
2471 return false;
2472 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002473 if (mPermanentlyHidden) {
2474 // Permanently hidden until the app exists as apps aren't prepared
2475 // to handle their windows being removed from under them.
2476 return false;
2477 }
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002478 if (mForceHideNonSystemOverlayWindow) {
2479 // This is an alert window that is currently force hidden.
2480 return false;
2481 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002482 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002483 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002484 return false;
2485 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002486 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002487 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002488 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Jorim Jaggia5e10572017-11-15 14:36:26 +01002489 + mPolicyVisibility + " isAnimationSet=" + mWinAnimator.isAnimationSet());
David Stevens9440dc82017-03-16 19:00:20 -07002490 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002491 doAnimation = false;
Jorim Jaggia5e10572017-11-15 14:36:26 +01002492 } else if (mPolicyVisibility && !mWinAnimator.isAnimationSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002493 // Check for the case where we are currently visible and
2494 // not animating; we do not want to do animation at such a
2495 // point to become visible when we already are.
2496 doAnimation = false;
2497 }
2498 }
2499 mPolicyVisibility = true;
2500 mPolicyVisibilityAfterAnim = true;
2501 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002502 mWinAnimator.applyAnimationLocked(TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002503 }
2504 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002505 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002506 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002507 if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) {
2508 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2509 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002510 return true;
2511 }
2512
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002513 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002514 public boolean hideLw(boolean doAnimation) {
2515 return hideLw(doAnimation, true);
2516 }
2517
2518 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2519 if (doAnimation) {
David Stevens9440dc82017-03-16 19:00:20 -07002520 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002521 doAnimation = false;
2522 }
2523 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002524 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002525 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002526 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002527 return false;
2528 }
2529 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002530 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
Jorim Jaggia5e10572017-11-15 14:36:26 +01002531 if (!mWinAnimator.isAnimationSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002532 doAnimation = false;
2533 }
2534 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002535 mPolicyVisibilityAfterAnim = false;
2536 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002537 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002538 mPolicyVisibility = false;
2539 // Window is no longer visible -- make sure if we were waiting
2540 // for it to be displayed before enabling the display, that
2541 // we allow the display to be enabled now.
2542 mService.enableScreenIfNeededLocked();
2543 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002544 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002545 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002546 mService.mFocusMayChange = true;
2547 }
2548 }
2549 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002550 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002551 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002552 if (mService.mCurrentFocus == this) {
2553 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2554 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002555 return true;
2556 }
2557
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002558 void setForceHideNonSystemOverlayWindowIfNeeded(boolean forceHide) {
2559 if (mOwnerCanAddInternalSystemWindow
2560 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2561 return;
2562 }
2563 if (mForceHideNonSystemOverlayWindow == forceHide) {
2564 return;
2565 }
2566 mForceHideNonSystemOverlayWindow = forceHide;
2567 if (forceHide) {
2568 hideLw(true /* doAnimation */, true /* requestAnim */);
2569 } else {
2570 showLw(true /* doAnimation */, true /* requestAnim */);
2571 }
2572 }
2573
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002574 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002575 if (mAppOpVisibility != state) {
2576 mAppOpVisibility = state;
2577 if (state) {
2578 // If the policy visibility had last been to hide, then this
2579 // will incorrectly show at this point since we lost that
2580 // information. Not a big deal -- for the windows that have app
2581 // ops modifies they should only be hidden by policy due to the
2582 // lock screen, and the user won't be changing this if locked.
2583 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002584 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002585 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002586 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002587 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002588 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002589 }
2590
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002591 public void hidePermanentlyLw() {
2592 if (!mPermanentlyHidden) {
2593 mPermanentlyHidden = true;
2594 hideLw(true, true);
2595 }
2596 }
2597
Jeff Brownc2932a12014-11-20 18:04:05 -08002598 public void pokeDrawLockLw(long timeout) {
2599 if (isVisibleOrAdding()) {
2600 if (mDrawLock == null) {
2601 // We want the tag name to be somewhat stable so that it is easier to correlate
2602 // in wake lock statistics. So in particular, we don't want to include the
2603 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002604 final CharSequence tag = getWindowTag();
chaviw40234662018-02-07 09:37:16 -08002605 mDrawLock = mService.mPowerManager.newWakeLock(DRAW_WAKE_LOCK, "Window:" + tag);
Jeff Brownc2932a12014-11-20 18:04:05 -08002606 mDrawLock.setReferenceCounted(false);
2607 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2608 }
2609 // Each call to acquire resets the timeout.
2610 if (DEBUG_POWER) {
2611 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2612 + mAttrs.packageName);
2613 }
2614 mDrawLock.acquire(timeout);
2615 } else if (DEBUG_POWER) {
2616 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2617 + "owned by " + mAttrs.packageName);
2618 }
2619 }
2620
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002621 @Override
2622 public boolean isAlive() {
2623 return mClient.asBinder().isBinderAlive();
2624 }
2625
Craig Mautnera987d432012-10-11 14:07:58 -07002626 boolean isClosing() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002627 return mAnimatingExit || (mService.mClosingApps.contains(mAppToken));
Craig Mautnera987d432012-10-11 14:07:58 -07002628 }
2629
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002630 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2631 animators.add(mWinAnimator);
2632
2633 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002634 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002635 c.addWinAnimatorToList(animators);
2636 }
2637 }
2638
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002639 void sendAppVisibilityToClients() {
2640 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002641
Wale Ogunwale89973222017-04-23 18:39:45 -07002642 final boolean clientHidden = mAppToken.isClientHidden();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002643 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2644 // Don't hide the starting window.
2645 return;
2646 }
2647
Wale Ogunwale89973222017-04-23 18:39:45 -07002648 if (clientHidden) {
2649 // Once we are notifying the client that it's visibility has changed, we need to prevent
2650 // it from destroying child surfaces until the animation has finished. We do this by
2651 // detaching any surface control the client added from the client.
2652 for (int i = mChildren.size() - 1; i >= 0; --i) {
2653 final WindowState c = mChildren.get(i);
2654 c.mWinAnimator.detachChildren();
2655 }
2656
2657 mWinAnimator.detachChildren();
2658 }
2659
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002660 try {
2661 if (DEBUG_VISIBILITY) Slog.v(TAG,
2662 "Setting visibility of " + this + ": " + (!clientHidden));
2663 mClient.dispatchAppVisibility(!clientHidden);
2664 } catch (RemoteException e) {
2665 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002666 }
2667
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002668 void onStartFreezingScreen() {
2669 mAppFreezing = true;
2670 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002671 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002672 c.onStartFreezingScreen();
2673 }
2674 }
2675
2676 boolean onStopFreezingScreen() {
2677 boolean unfrozeWindows = false;
2678 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002679 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002680 unfrozeWindows |= c.onStopFreezingScreen();
2681 }
2682
2683 if (!mAppFreezing) {
2684 return unfrozeWindows;
2685 }
2686
Wale Ogunwale953171d2016-09-30 09:17:30 -07002687 mAppFreezing = false;
2688
Bryce Lee8c3cf382017-07-06 19:47:10 -07002689 if (mHasSurface && !getOrientationChanging()
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002690 && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
2691 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
Bryce Lee8c3cf382017-07-06 19:47:10 -07002692 setOrientationChanging(true);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002693 mService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002694 }
2695 mLastFreezeDuration = 0;
2696 setDisplayLayoutNeeded();
2697 return true;
2698 }
2699
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002700 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2701 boolean destroyedSomething = false;
Jorim Jaggi59f3e922018-01-05 15:40:32 +01002702
2703 // Copying to a different list as multiple children can be removed.
2704 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
2705 for (int i = childWindows.size() - 1; i >= 0; --i) {
2706 final WindowState c = childWindows.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002707 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2708 }
2709
Robert Carrdb2f6e62017-03-01 20:17:58 -08002710 if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) {
2711 return destroyedSomething;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002712 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08002713
2714 if (appStopped || mWindowRemovalAllowed) {
2715 mWinAnimator.destroyPreservedSurfaceLocked();
2716 }
2717
2718 if (mDestroying) {
2719 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2720 + " destroySurfaces: appStopped=" + appStopped
2721 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2722 + " win.mRemoveOnExit=" + mRemoveOnExit);
2723 if (!cleanupOnResume || mRemoveOnExit) {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002724 destroySurfaceUnchecked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08002725 }
2726 if (mRemoveOnExit) {
2727 removeImmediately();
2728 }
2729 if (cleanupOnResume) {
2730 requestUpdateWallpaperIfNeeded();
2731 }
2732 mDestroying = false;
2733 destroyedSomething = true;
2734 }
2735
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002736 return destroyedSomething;
2737 }
Chris Craik3131bde2016-05-06 13:39:08 -07002738
Robert Carr89a28ab2017-04-24 15:33:11 -07002739 // Destroy or save the application surface without checking
2740 // various indicators of whether the client has released the surface.
2741 // This is in general unsafe, and most callers should use {@link #destroySurface}
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002742 void destroySurfaceUnchecked() {
2743 mWinAnimator.destroySurfaceLocked();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002744
Chong Zhang92147042016-05-09 12:47:11 -07002745 // Clear animating flags now, since the surface is now gone. (Note this is true even
2746 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2747 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002748 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002749
Craig Mautner69b08182012-09-05 13:07:13 -07002750 @Override
2751 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002752 final DisplayContent displayContent = getDisplayContent();
2753 if (displayContent == null) {
2754 // Only a window that was on a non-default display can be detached from it.
2755 return false;
2756 }
Winson Chung47a3e652014-05-21 16:03:42 -07002757 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002758 }
2759
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002760 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07002761 mShowToOwnerOnly = showToOwnerOnly;
2762 }
2763
Wale Ogunwaleea92d972016-12-08 07:33:13 -08002764 private boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002765 // Child windows are evaluated based on their parent window.
2766 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002767 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale72919d22016-12-08 18:58:50 -08002768 && win.mAppToken != null && win.mAppToken.mShowForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002769
2770 // All window frames that are fullscreen extend above status bar, but some don't extend
2771 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2772 // bottom right.
2773 if (win.mFrame.left <= win.mDisplayFrame.left
2774 && win.mFrame.top <= win.mDisplayFrame.top
2775 && win.mFrame.right >= win.mStableFrame.right
2776 && win.mFrame.bottom >= win.mStableFrame.bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002777 // Is a fullscreen window, like the clock alarm. Show to everyone.
2778 return false;
2779 }
2780 }
2781
Craig Mautner341220f2012-10-16 15:20:09 -07002782 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01002783 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002784 }
2785
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002786 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2787 outRegion.set(
2788 frame.left + inset.left, frame.top + inset.top,
2789 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002790 }
2791
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002792 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002793 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002794 switch (mTouchableInsets) {
2795 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002796 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002797 outRegion.set(frame);
2798 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002799 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002800 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002801 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002802 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002803 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002804 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002805 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002806 outRegion.set(mGivenTouchableRegion);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002807 outRegion.translate(frame.left, frame.top);
2808 break;
2809 }
2810 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002811 cropRegionToStackBoundsIfNeeded(outRegion);
2812 }
2813
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002814 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002815 final Task task = getTask();
2816 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002817 return;
2818 }
2819
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002820 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002821 if (stack == null) {
2822 return;
2823 }
2824
2825 stack.getDimBounds(mTmpRect);
2826 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002827 }
2828
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002829 /**
2830 * Report a focus change. Must be called with no locks held, and consistently
2831 * from the same serialized thread (such as dispatched from a handler).
2832 */
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07002833 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002834 try {
2835 mClient.windowFocusChanged(focused, inTouchMode);
2836 } catch (RemoteException e) {
2837 }
2838 if (mFocusCallbacks != null) {
2839 final int N = mFocusCallbacks.beginBroadcast();
2840 for (int i=0; i<N; i++) {
2841 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2842 try {
2843 if (focused) {
2844 obs.focusGained(mWindowId.asBinder());
2845 } else {
2846 obs.focusLost(mWindowId.asBinder());
2847 }
2848 } catch (RemoteException e) {
2849 }
2850 }
2851 mFocusCallbacks.finishBroadcast();
2852 }
2853 }
2854
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002855 @Override
2856 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002857 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002858 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002859 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002860
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002861 return super.getConfiguration();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002862 }
2863
Craig Mautnerdf88d732014-01-27 09:21:32 -08002864 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002865 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08002866 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002867 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
2868 + ": " + mCompatFrame);
Bryce Leef858b572017-06-29 14:03:33 -07002869 final MergedConfiguration mergedConfiguration =
2870 new MergedConfiguration(mService.mRoot.getConfiguration(),
2871 getMergedOverrideConfiguration());
2872
Bryce Lee2b17afd2017-09-21 10:38:20 -07002873 setLastReportedMergedConfiguration(mergedConfiguration);
Bryce Leef858b572017-06-29 14:03:33 -07002874
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002875 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002876 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
2877
Craig Mautnerdf88d732014-01-27 09:21:32 -08002878 final Rect frame = mFrame;
2879 final Rect overscanInsets = mLastOverscanInsets;
2880 final Rect contentInsets = mLastContentInsets;
2881 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07002882 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002883 final Rect outsets = mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002884 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Andrii Kulianb2e37802017-01-11 00:36:44 -08002885 final boolean reportOrientation = mReportOrientationChanged;
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002886 final int displayId = getDisplayId();
Adrian Roos5c6b6222017-11-07 17:36:10 +01002887 final DisplayCutout displayCutout = mDisplayCutout;
Chet Haase8eb48d22014-09-24 07:31:29 -07002888 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
2889 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002890 // To prevent deadlock simulate one-way call if win.mClient is a local object.
2891 mService.mH.post(new Runnable() {
2892 @Override
2893 public void run() {
2894 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002895 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07002896 stableInsets, outsets, reportDraw, mergedConfiguration,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002897 reportOrientation, displayId, displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002898 } catch (RemoteException e) {
2899 // Not a remote call, RemoteException won't be raised.
2900 }
2901 }
2902 });
2903 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002904 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002905 outsets, reportDraw, mergedConfiguration, reportOrientation, displayId,
2906 displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002907 }
Svetoslav4604abc2014-06-10 18:59:30 -07002908
2909 //TODO (multidisplay): Accessibility supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002910 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07002911 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07002912 }
2913
Craig Mautnerdf88d732014-01-27 09:21:32 -08002914 mOverscanInsetsChanged = false;
2915 mContentInsetsChanged = false;
2916 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07002917 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002918 mOutsetsChanged = false;
Robert Carr31aa98b2016-07-20 15:29:03 -07002919 mFrameSizeChanged = false;
Adrian Roos5c6b6222017-11-07 17:36:10 +01002920 mDisplayCutoutChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08002921 mWinAnimator.mSurfaceResized = false;
Andrii Kulianb2e37802017-01-11 00:36:44 -08002922 mReportOrientationChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08002923 } catch (RemoteException e) {
Bryce Lee8c3cf382017-07-06 19:47:10 -07002924 setOrientationChanging(false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002925 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2926 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08002927 // We are assuming the hosting process is dead or in a zombie state.
2928 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
2929 + ", removing this window.");
2930 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002931 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002932 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002933 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002934 }
2935
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002936 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08002937 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
2938 // start even if we haven't received the relayout window, so that the client requests
2939 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
2940 // until the window to small size, otherwise the multithread renderer will shift last
2941 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
2942 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002943 boolean resizing = isDragResizing() || isDragResizeChanged();
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002944 if (getWindowConfiguration().useWindowFrameForBackdrop() || !resizing) {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002945 return frame;
2946 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07002947 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002948 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002949 return mTmpRect;
2950 }
2951
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002952 private int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002953 final TaskStack stack = getStack();
2954 if (stack == null) {
2955 return INVALID_STACK_ID;
2956 }
2957 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002958 }
2959
2960 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
2961 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002962 MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId,
2963 DisplayCutout displayCutout)
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002964 throws RemoteException {
Robert Carr09286c92018-02-15 13:52:31 -08002965 final boolean forceRelayout = isDragResizeChanged() || reportOrientation;
Chong Zhangedaf3052016-04-22 15:04:31 -07002966
Jorim Jaggidc249c42015-12-15 14:57:31 -08002967 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Andrii Kulian44607962017-03-16 11:06:24 -07002968 reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002969 mPolicy.isNavBarForcedShownLw(this), displayId,
2970 new DisplayCutout.ParcelableWrapper(displayCutout));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002971 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002972 }
2973
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002974 public void registerFocusObserver(IWindowFocusObserver observer) {
2975 synchronized(mService.mWindowMap) {
2976 if (mFocusCallbacks == null) {
2977 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
2978 }
2979 mFocusCallbacks.register(observer);
2980 }
2981 }
2982
2983 public void unregisterFocusObserver(IWindowFocusObserver observer) {
2984 synchronized(mService.mWindowMap) {
2985 if (mFocusCallbacks != null) {
2986 mFocusCallbacks.unregister(observer);
2987 }
2988 }
2989 }
2990
2991 public boolean isFocused() {
2992 synchronized(mService.mWindowMap) {
2993 return mService.mCurrentFocus == this;
2994 }
2995 }
2996
Wale Ogunwale9185fb02016-03-11 18:06:14 -08002997 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07002998 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08002999 final Task task = getTask();
3000 return task != null && !task.isFullscreen();
3001 }
3002
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003003 /** Is this window in a container that takes up the entire screen space? */
3004 private boolean inFullscreenContainer() {
Bryce Leef3c6a472017-11-14 14:53:06 -08003005 return mAppToken == null || (mAppToken.matchParentBounds() && !isInMultiWindowMode());
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003006 }
3007
Andrii Kulian283acd22017-08-03 04:03:51 -07003008 /** @return true when the window is in fullscreen task, but has non-fullscreen bounds set. */
3009 boolean isLetterboxedAppWindow() {
Adrian Roos865c70f2018-01-10 17:32:27 +01003010 return !isInMultiWindowMode() && mAppToken != null && !mAppToken.matchParentBounds()
3011 || isLetterboxedForDisplayCutoutLw();
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003012 }
3013
Adrian Roos865c70f2018-01-10 17:32:27 +01003014 @Override
3015 public boolean isLetterboxedForDisplayCutoutLw() {
3016 if (mAppToken == null) {
3017 // Only windows with an AppWindowToken are letterboxed.
3018 return false;
3019 }
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003020 if (getDisplayContent().getDisplayInfo().displayCutout == null) {
3021 // No cutout, no letterbox.
3022 return false;
3023 }
Adrian Roosfa02da62018-01-15 16:01:18 +01003024 if (mAttrs.layoutInDisplayCutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003025 // Layout in cutout, no letterbox.
3026 return false;
3027 }
3028 // TODO: handle dialogs and other non-filling windows
Adrian Roosfa02da62018-01-15 16:01:18 +01003029 if (mAttrs.layoutInDisplayCutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER) {
3030 // Never layout in cutout, always letterbox.
3031 return true;
3032 }
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003033 // Letterbox if any fullscreen mode is set.
3034 final int fl = mAttrs.flags;
3035 final int sysui = mSystemUiVisibility;
Adrian Roos2dfb7852018-01-15 13:41:37 +01003036 return (fl & FLAG_FULLSCREEN) != 0 || (sysui & (SYSTEM_UI_FLAG_FULLSCREEN)) != 0;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003037 }
3038
Chong Zhang3005e752015-09-18 18:46:28 -07003039 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003040 return mDragResizing != computeDragResizing();
3041 }
3042
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003043 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003044 void setWaitingForDrawnIfResizingChanged() {
3045 if (isDragResizeChanged()) {
3046 mService.mWaitingForDrawn.add(this);
3047 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003048 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003049 }
3050
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003051 /**
3052 * @return Whether we reported a drag resize change to the application or not already.
3053 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003054 private boolean isDragResizingChangeReported() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003055 return mDragResizingChangeReported;
3056 }
3057
3058 /**
3059 * Resets the state whether we reported a drag resize change to the app.
3060 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003061 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003062 void resetDragResizingChangeReported() {
3063 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003064 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003065 }
3066
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003067 int getResizeMode() {
3068 return mResizeMode;
3069 }
3070
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003071 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003072 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003073 if (task == null) {
3074 return false;
3075 }
Tomasz Mikolajewskiaf20b8d2017-11-20 16:11:33 +09003076 if (!inSplitScreenWindowingMode() && !inFreeformWindowingMode()) {
Winson Chung2af04b32017-01-24 16:21:13 -08003077 return false;
3078 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003079 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003080 // Floating windows never enter drag resize mode.
3081 return false;
3082 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003083 if (task.isDragResizing()) {
3084 return true;
3085 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003086
3087 // If the bounds are currently frozen, it means that the layout size that the app sees
3088 // and the bounds we clip this window to might be different. In order to avoid holes, we
3089 // simulate that we are still resizing so the app fills the hole with the resizing
3090 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003091 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003092 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003093 !task.inFreeformWindowingMode() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003094
Chong Zhang3005e752015-09-18 18:46:28 -07003095 }
3096
3097 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003098 final boolean resizing = computeDragResizing();
3099 if (resizing == mDragResizing) {
3100 return;
3101 }
3102 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003103 final Task task = getTask();
3104 if (task != null && task.isDragResizing()) {
3105 mResizeMode = task.getDragResizeMode();
3106 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003107 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003108 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3109 : DRAG_RESIZE_MODE_FREEFORM;
3110 }
Chong Zhang3005e752015-09-18 18:46:28 -07003111 }
3112
3113 boolean isDragResizing() {
3114 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003115 }
3116
Robert Carr2487ce72016-04-07 15:18:45 -07003117 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003118 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3119 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003120 }
3121
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07003122 @CallSuper
3123 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02003124 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003125 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02003126 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003127 writeIdentifierToProto(proto, IDENTIFIER);
3128 proto.write(DISPLAY_ID, getDisplayId());
3129 proto.write(STACK_ID, getStackId());
3130 mAttrs.writeToProto(proto, ATTRIBUTES);
3131 mGivenContentInsets.writeToProto(proto, GIVEN_CONTENT_INSETS);
3132 mFrame.writeToProto(proto, FRAME);
3133 mContainingFrame.writeToProto(proto, CONTAINING_FRAME);
3134 mParentFrame.writeToProto(proto, PARENT_FRAME);
3135 mContentFrame.writeToProto(proto, CONTENT_FRAME);
3136 mContentInsets.writeToProto(proto, CONTENT_INSETS);
3137 mAttrs.surfaceInsets.writeToProto(proto, SURFACE_INSETS);
Jorim Jaggi45be1c4c2017-12-15 18:44:43 +01003138 mSurfacePosition.writeToProto(proto, SURFACE_POSITION);
Rob Carr06be6bb2018-02-06 16:26:06 +00003139 mShownPosition.writeToProto(proto, SHOWN_POSITION);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003140 mWinAnimator.writeToProto(proto, ANIMATOR);
3141 proto.write(ANIMATING_EXIT, mAnimatingExit);
3142 for (int i = 0; i < mChildren.size(); i++) {
Adrian Roos4921ccf2017-09-28 16:54:06 +02003143 mChildren.get(i).writeToProto(proto, CHILD_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003144 }
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003145 proto.write(REQUESTED_WIDTH, mRequestedWidth);
3146 proto.write(REQUESTED_HEIGHT, mRequestedHeight);
3147 proto.write(VIEW_VISIBILITY, mViewVisibility);
3148 proto.write(SYSTEM_UI_VISIBILITY, mSystemUiVisibility);
3149 proto.write(HAS_SURFACE, mHasSurface);
3150 proto.write(IS_READY_FOR_DISPLAY, isReadyForDisplay());
3151 mDisplayFrame.writeToProto(proto, DISPLAY_FRAME);
3152 mOverscanFrame.writeToProto(proto, OVERSCAN_FRAME);
3153 mVisibleFrame.writeToProto(proto, VISIBLE_FRAME);
3154 mDecorFrame.writeToProto(proto, DECOR_FRAME);
3155 mOutsetFrame.writeToProto(proto, OUTSET_FRAME);
3156 mOverscanInsets.writeToProto(proto, OVERSCAN_INSETS);
3157 mVisibleInsets.writeToProto(proto, VISIBLE_INSETS);
3158 mStableInsets.writeToProto(proto, STABLE_INSETS);
3159 mOutsets.writeToProto(proto, OUTSETS);
3160 mDisplayCutout.writeToProto(proto, CUTOUT);
3161 proto.write(REMOVE_ON_EXIT, mRemoveOnExit);
3162 proto.write(DESTROYING, mDestroying);
3163 proto.write(REMOVED, mRemoved);
3164 proto.write(IS_ON_SCREEN, isOnScreen());
3165 proto.write(IS_VISIBLE, isVisible());
Steven Timotiusaf03df62017-07-18 16:56:43 -07003166 proto.end(token);
3167 }
3168
Vishnu Nair9a3e4062018-01-11 08:42:54 -08003169 @Override
3170 public void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003171 final long token = proto.start(fieldId);
3172 proto.write(HASH_CODE, System.identityHashCode(this));
3173 proto.write(USER_ID, UserHandle.getUserId(mOwnerUid));
3174 final CharSequence title = getWindowTag();
3175 if (title != null) {
3176 proto.write(TITLE, title.toString());
3177 }
3178 proto.end(token);
3179 }
3180
Jorim Jaggia5e10572017-11-15 14:36:26 +01003181 @Override
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003182 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003183 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003184 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003185 if (stack != null) {
3186 pw.print(" stackId="); pw.print(stack.mStackId);
3187 }
Craig Mautner59c00972012-07-30 12:10:24 -07003188 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003189 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07003190 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08003191 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
3192 pw.print(" package="); pw.print(mAttrs.packageName);
3193 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Jorim Jaggi484851b2017-09-22 16:03:27 +02003194 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs.toString(prefix));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003195 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
3196 pw.print(" h="); pw.print(mRequestedHeight);
3197 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003198 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
3199 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
3200 pw.print(" h="); pw.println(mLastRequestedHeight);
3201 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003202 if (mIsChildWindow || mLayoutAttached) {
3203 pw.print(prefix); pw.print("mParentWindow="); pw.print(getParentWindow());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003204 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
3205 }
3206 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
3207 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
3208 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
3209 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
3210 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
3211 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003212 if (dumpAll) {
3213 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3214 pw.print(" mSubLayer="); pw.print(mSubLayer);
3215 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautnerc2f9be02012-03-27 17:32:29 -07003216 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
3217 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003218 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003219 if (dumpAll) {
3220 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003221 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003222 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
3223 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Bryce Lee6311c4b2017-07-06 14:09:29 -07003224 pw.print(" mAppDied=");pw.print(mAppDied);
3225 pw.print(prefix); pw.print("drawnStateEvaluated=");
3226 pw.print(getDrawnStateEvaluated());
3227 pw.print(prefix); pw.print("mightAffectAllDrawn=");
Jorim Jaggie7d2b852017-08-28 17:55:15 +02003228 pw.println(mightAffectAllDrawn());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003229 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003230 pw.print(prefix); pw.print("mViewVisibility=0x");
3231 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003232 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
3233 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07003234 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
3235 pw.print(" mSystemUiVisibility=0x");
3236 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003237 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003238 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003239 || isParentWindowHidden()|| mPermanentlyHidden || mForceHideNonSystemOverlayWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003240 pw.print(prefix); pw.print("mPolicyVisibility=");
3241 pw.print(mPolicyVisibility);
3242 pw.print(" mPolicyVisibilityAfterAnim=");
3243 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003244 pw.print(" mAppOpVisibility=");
3245 pw.print(mAppOpVisibility);
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003246 pw.print(" parentHidden="); pw.print(isParentWindowHidden());
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003247 pw.print(" mPermanentlyHidden="); pw.print(mPermanentlyHidden);
3248 pw.print(" mForceHideNonSystemOverlayWindow="); pw.println(
3249 mForceHideNonSystemOverlayWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003250 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003251 if (!mRelayoutCalled || mLayoutNeeded) {
3252 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
3253 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003254 }
Rob Carr06be6bb2018-02-06 16:26:06 +00003255 if (mXOffset != 0 || mYOffset != 0) {
3256 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
3257 pw.print(" y="); pw.println(mYOffset);
3258 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003259 if (dumpAll) {
3260 pw.print(prefix); pw.print("mGivenContentInsets=");
3261 mGivenContentInsets.printShortString(pw);
3262 pw.print(" mGivenVisibleInsets=");
3263 mGivenVisibleInsets.printShortString(pw);
3264 pw.println();
3265 if (mTouchableInsets != 0 || mGivenInsetsPending) {
3266 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
3267 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003268 Region region = new Region();
3269 getTouchableRegion(region);
3270 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003271 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003272 pw.print(prefix); pw.print("mFullConfiguration="); pw.println(getConfiguration());
3273 pw.print(prefix); pw.print("mLastReportedConfiguration=");
Bryce Lee2b17afd2017-09-21 10:38:20 -07003274 pw.println(getLastReportedConfiguration());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003275 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07003276 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Rob Carr06be6bb2018-02-06 16:26:06 +00003277 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Chong Zhanga8975bd2016-01-28 17:13:47 -08003278 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08003279 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003280 if (dumpAll) {
3281 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
3282 pw.print(" last="); mLastFrame.printShortString(pw);
3283 pw.println();
3284 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003285 if (mEnforceSizeCompat) {
3286 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003287 pw.println();
3288 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003289 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003290 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003291 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003292 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003293 pw.println();
3294 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
3295 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003296 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003297 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003298 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003299 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04003300 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
3301 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003302 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
3303 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003304 pw.print(prefix); pw.print("Cur insets: overscan=");
3305 mOverscanInsets.printShortString(pw);
3306 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003307 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003308 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003309 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003310 pw.print(" outsets="); mOutsets.printShortString(pw);
Adrian Roos5c6b6222017-11-07 17:36:10 +01003311 pw.print(" cutout=" + mDisplayCutout);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003312 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003313 pw.print(prefix); pw.print("Lst insets: overscan=");
3314 mLastOverscanInsets.printShortString(pw);
3315 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003316 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003317 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003318 pw.print(" physical="); mLastOutsets.printShortString(pw);
3319 pw.print(" outset="); mLastOutsets.printShortString(pw);
Adrian Roos5c6b6222017-11-07 17:36:10 +01003320 pw.print(" cutout=" + mLastDisplayCutout);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003321 pw.println();
3322 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01003323 super.dump(pw, prefix, dumpAll);
Dianne Hackborn529e7442012-11-01 14:22:28 -07003324 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
3325 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003326 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
3327 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003328 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
3329 pw.print(" mDestroying="); pw.print(mDestroying);
3330 pw.print(" mRemoved="); pw.println(mRemoved);
3331 }
chaviw40234662018-02-07 09:37:16 -08003332 if (getOrientationChanging() || mAppFreezing || mReportOrientationChanged) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003333 pw.print(prefix); pw.print("mOrientationChanging=");
3334 pw.print(mOrientationChanging);
Bryce Lee8c3cf382017-07-06 19:47:10 -07003335 pw.print(" configOrientationChanging=");
Bryce Lee2b17afd2017-09-21 10:38:20 -07003336 pw.print(getLastReportedConfiguration().orientation
Bryce Lee8c3cf382017-07-06 19:47:10 -07003337 != getConfiguration().orientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003338 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
Andrii Kulianb2e37802017-01-11 00:36:44 -08003339 pw.print(" mReportOrientationChanged="); pw.println(mReportOrientationChanged);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003340 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003341 if (mLastFreezeDuration != 0) {
3342 pw.print(prefix); pw.print("mLastFreezeDuration=");
3343 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
3344 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003345 if (mHScale != 1 || mVScale != 1) {
3346 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
3347 pw.print(" mVScale="); pw.println(mVScale);
3348 }
3349 if (mWallpaperX != -1 || mWallpaperY != -1) {
3350 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
3351 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
3352 }
3353 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
3354 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
3355 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
3356 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003357 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3358 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
3359 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
3360 pw.print(mWallpaperDisplayOffsetX);
3361 pw.print(" mWallpaperDisplayOffsetY=");
3362 pw.println(mWallpaperDisplayOffsetY);
3363 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003364 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07003365 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003366 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003367 if (isDragResizing()) {
3368 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
3369 }
3370 if (computeDragResizing()) {
3371 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
3372 }
Bryce Lee6311c4b2017-07-06 14:09:29 -07003373 pw.print(prefix); pw.println("isOnScreen=" + isOnScreen());
3374 pw.print(prefix); pw.println("isVisible=" + isVisible());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003375 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003376
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003377 @Override
3378 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003379 return Integer.toHexString(System.identityHashCode(this))
Jorim Jaggia5e10572017-11-15 14:36:26 +01003380 + " " + getWindowTag();
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003381 }
3382
Robert Carra1eb4392015-12-10 12:43:51 -08003383 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003384 CharSequence tag = mAttrs.getTitle();
3385 if (tag == null || tag.length() <= 0) {
3386 tag = mAttrs.packageName;
3387 }
3388 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003389 }
3390
3391 @Override
3392 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003393 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003394 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003395 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003396 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003397 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003398 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003399 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003400 }
3401 return mStringNameCache;
3402 }
Robert Carr58f29132015-10-29 14:19:05 -07003403
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003404 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003405 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003406 clipRect.left = (int) (clipRect.left / mHScale);
3407 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003408 }
3409 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003410 clipRect.top = (int) (clipRect.top / mVScale);
3411 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003412 }
3413 }
Robert Carr31e28482015-12-02 16:53:18 -08003414
Jorim Jaggif5834272016-04-04 20:25:41 -07003415 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
3416 final int pw = containingFrame.width();
3417 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003418 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003419 final boolean inNonFullscreenContainer = !inFullscreenContainer();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003420 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3421
3422 // We need to fit it to the display if either
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003423 // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen
3424 // for the taskless windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003425 // 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 -07003426 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on
3427 // screen, but SurfaceViews want to be always at a specific location so we don't fit it to
3428 // the display.
3429 final boolean fitToDisplay = (task == null || !inNonFullscreenContainer)
Robert Carr6f44db12016-07-21 14:54:43 -07003430 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003431 float x, y;
3432 int w,h;
3433
3434 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3435 if (mAttrs.width < 0) {
3436 w = pw;
3437 } else if (mEnforceSizeCompat) {
3438 w = (int)(mAttrs.width * mGlobalScale + .5f);
3439 } else {
3440 w = mAttrs.width;
3441 }
3442 if (mAttrs.height < 0) {
3443 h = ph;
3444 } else if (mEnforceSizeCompat) {
3445 h = (int)(mAttrs.height * mGlobalScale + .5f);
3446 } else {
3447 h = mAttrs.height;
3448 }
3449 } else {
3450 if (mAttrs.width == MATCH_PARENT) {
3451 w = pw;
3452 } else if (mEnforceSizeCompat) {
3453 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3454 } else {
3455 w = mRequestedWidth;
3456 }
3457 if (mAttrs.height == MATCH_PARENT) {
3458 h = ph;
3459 } else if (mEnforceSizeCompat) {
3460 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3461 } else {
3462 h = mRequestedHeight;
3463 }
3464 }
3465
3466 if (mEnforceSizeCompat) {
3467 x = mAttrs.x * mGlobalScale;
3468 y = mAttrs.y * mGlobalScale;
3469 } else {
3470 x = mAttrs.x;
3471 y = mAttrs.y;
3472 }
3473
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003474 if (inNonFullscreenContainer && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003475 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003476 // required by {@link Gravity#apply} call.
3477 w = Math.min(w, pw);
3478 h = Math.min(h, ph);
3479 }
3480
3481 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003482 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003483 (int) (x + mAttrs.horizontalMargin * pw),
3484 (int) (y + mAttrs.verticalMargin * ph), mFrame);
3485
3486 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003487 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003488 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003489 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003490
3491 // We need to make sure we update the CompatFrame as it is used for
3492 // cropping decisions, etc, on systems where we lack a decor layer.
3493 mCompatFrame.set(mFrame);
3494 if (mEnforceSizeCompat) {
3495 // See comparable block in computeFrameLw.
3496 mCompatFrame.scale(mInvGlobalScale);
3497 }
Robert Carr31e28482015-12-02 16:53:18 -08003498 }
Robert Carr51a1b872015-12-08 14:03:13 -08003499
3500 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003501 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003502 }
3503
Robert Carrf3b72c72016-03-21 18:16:39 -07003504 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003505 return mIsChildWindow
3506 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003507 }
3508
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003509 /**
3510 * Returns true if any window added by an application process that if of type
3511 * {@link android.view.WindowManager.LayoutParams#TYPE_TOAST} or that requires that requires
3512 * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when
3513 * this window is visible.
3514 */
3515 boolean hideNonSystemOverlayWindowsWhenVisible() {
3516 return (mAttrs.privateFlags & PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != 0
3517 && mSession.mCanHideNonSystemOverlayWindows;
3518 }
3519
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003520 /** Returns the parent window if this is a child of another window, else null. */
3521 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003522 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3523 // WindowContainer that isn't a WindowState.
3524 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003525 }
3526
3527 /** Returns the topmost parent window if this is a child of another window, else this. */
3528 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003529 WindowState current = this;
3530 WindowState topParent = current;
3531 while (current != null && current.mIsChildWindow) {
3532 current = current.getParentWindow();
3533 // Parent window can be null if the child is detached from it's parent already, but
3534 // someone still has a reference to access it. So, we return the top parent value we
3535 // already have instead of null.
3536 if (current != null) {
3537 topParent = current;
3538 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003539 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003540 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003541 }
3542
Wale Ogunwale9d147902016-07-16 11:58:55 -07003543 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003544 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003545 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003546 }
3547
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003548 void setWillReplaceWindow(boolean animate) {
3549 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003550 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003551 c.setWillReplaceWindow(animate);
3552 }
3553
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003554 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3555 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3556 // We don't set replacing on starting windows since they are added by window manager and
3557 // not the client so won't be replaced by the client.
3558 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003559 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003560
3561 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003562 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003563 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003564 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003565
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003566 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003567 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003568 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003569 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003570
3571 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003572 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003573 c.clearWillReplaceWindow();
3574 }
3575 }
3576
3577 boolean waitingForReplacement() {
3578 if (mWillReplaceWindow) {
3579 return true;
3580 }
3581
3582 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003583 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003584 if (c.waitingForReplacement()) {
3585 return true;
3586 }
3587 }
3588 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003589 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003590
Chong Zhang4d7369a2016-04-25 16:09:14 -07003591 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003592 final DisplayContent dc = getDisplayContent();
3593 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3594 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3595 dc.setLayoutNeeded();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003596 mService.mWindowPlacerLocked.requestTraversal();
3597 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003598
3599 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003600 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003601 c.requestUpdateWallpaperIfNeeded();
3602 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003603 }
3604
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003605 float translateToWindowX(float x) {
3606 float winX = x - mFrame.left;
3607 if (mEnforceSizeCompat) {
3608 winX *= mGlobalScale;
3609 }
3610 return winX;
3611 }
3612
3613 float translateToWindowY(float y) {
3614 float winY = y - mFrame.top;
3615 if (mEnforceSizeCompat) {
3616 winY *= mGlobalScale;
3617 }
3618 return winY;
3619 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003620
3621 // During activity relaunch due to resize, we sometimes use window replacement
3622 // for only child windows (as the main window is handled by window preservation)
3623 // and the big surface.
3624 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003625 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3626 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3627 // we also want to replace them at such phases, as they won't be covered by window
3628 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003629 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003630 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003631 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003632 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003633
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003634 void setWillReplaceChildWindows() {
3635 if (shouldBeReplacedWithChildren()) {
3636 setWillReplaceWindow(false /* animate */);
3637 }
3638 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003639 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003640 c.setWillReplaceChildWindows();
3641 }
3642 }
3643
3644 WindowState getReplacingWindow() {
3645 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3646 return this;
3647 }
3648 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003649 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003650 final WindowState replacing = c.getReplacingWindow();
3651 if (replacing != null) {
3652 return replacing;
3653 }
3654 }
3655 return null;
3656 }
3657
Jorim Jaggife762342016-10-13 14:33:27 +02003658 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07003659 public int getRotationAnimationHint() {
3660 if (mAppToken != null) {
3661 return mAppToken.mRotationAnimationHint;
3662 } else {
3663 return -1;
3664 }
3665 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003666
Jorim Jaggife762342016-10-13 14:33:27 +02003667 @Override
3668 public boolean isInputMethodWindow() {
3669 return mIsImWindow;
3670 }
3671
Wale Ogunwale9d147902016-07-16 11:58:55 -07003672 // This must be called while inside a transaction.
3673 boolean performShowLocked() {
3674 if (isHiddenFromUserLocked()) {
3675 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3676 hideLw(false);
3677 return false;
3678 }
3679
3680 logPerformShow("performShow on ");
3681
Jorim Jaggia50da602016-12-29 11:51:42 +01003682 final int drawState = mWinAnimator.mDrawState;
3683 if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW)
3684 && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3685 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3686 }
3687
Jorim Jaggib0d27342016-11-01 16:10:42 -07003688 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003689 return false;
3690 }
3691
3692 logPerformShow("Showing ");
3693
3694 mService.enableScreenIfNeededLocked();
3695 mWinAnimator.applyEnterAnimationLocked();
3696
3697 // Force the show in the next prepareSurfaceLocked() call.
3698 mWinAnimator.mLastAlpha = -1;
Robert Carre13b58e2017-08-31 14:50:44 -07003699 if (DEBUG_ANIM) Slog.v(TAG,
Wale Ogunwale9d147902016-07-16 11:58:55 -07003700 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3701 mWinAnimator.mDrawState = HAS_DRAWN;
3702 mService.scheduleAnimationLocked();
3703
3704 if (mHidden) {
3705 mHidden = false;
3706 final DisplayContent displayContent = getDisplayContent();
3707
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003708 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003709 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003710 if (c.mWinAnimator.mSurfaceController != null) {
3711 c.performShowLocked();
3712 // It hadn't been shown, which means layout not performed on it, so now we
3713 // want to make sure to do a layout. If called from within the transaction
3714 // loop, this will cause it to restart with a new layout.
3715 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003716 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003717 }
3718 }
3719 }
3720 }
3721
Wale Ogunwale9d147902016-07-16 11:58:55 -07003722 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003723 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003724 }
3725
3726 return true;
3727 }
3728
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003729 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003730 if (DEBUG_VISIBILITY
Jorim Jaggie4b0f282017-05-17 15:10:29 +02003731 || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003732 Slog.v(TAG, prefix + this
3733 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07003734 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003735 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3736 + " during animation: policyVis=" + mPolicyVisibility
3737 + " parentHidden=" + isParentWindowHidden()
3738 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003739 + (mAppToken != null && mAppToken.hiddenRequested)
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003740 + " tok.hidden=" + (mAppToken != null && mAppToken.isHidden())
Jorim Jaggia5e10572017-11-15 14:36:26 +01003741 + " animationSet=" + mWinAnimator.isAnimationSet()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003742 + " tok animating="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003743 + (mAppToken != null && mAppToken.isSelfAnimating())
Wale Ogunwale9d147902016-07-16 11:58:55 -07003744 + " Callers=" + Debug.getCallers(4));
3745 }
3746 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003747
3748 WindowInfo getWindowInfo() {
3749 WindowInfo windowInfo = WindowInfo.obtain();
3750 windowInfo.type = mAttrs.type;
3751 windowInfo.layer = mLayer;
3752 windowInfo.token = mClient.asBinder();
Phil Weaver5dc3ebc2017-08-16 13:04:20 -07003753 if (mAppToken != null) {
3754 windowInfo.activityToken = mAppToken.appToken.asBinder();
3755 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003756 windowInfo.title = mAttrs.accessibilityTitle;
Phil Weaverbb2f28a2017-12-22 09:44:28 -08003757 // Panel windows have no public way to set the a11y title directly. Use the
3758 // regular title as a fallback.
3759 if (TextUtils.isEmpty(windowInfo.title)
3760 && (mAttrs.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW)
3761 && (mAttrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW)) {
3762 windowInfo.title = mAttrs.getTitle();
3763 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003764 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3765 windowInfo.focused = isFocused();
Phil Weaverf00cd142017-03-03 13:44:00 -08003766 Task task = getTask();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003767 windowInfo.inPictureInPicture = (task != null) && task.inPinnedWindowingMode();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003768
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003769 if (mIsChildWindow) {
3770 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003771 }
3772
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003773 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003774 if (childCount > 0) {
3775 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003776 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003777 }
3778 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003779 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003780 windowInfo.childTokens.add(child.mClient.asBinder());
3781 }
3782 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003783 return windowInfo;
3784 }
3785
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003786 int getHighestAnimLayer() {
3787 int highest = mWinAnimator.mAnimLayer;
3788 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003789 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003790 final int childLayer = c.getHighestAnimLayer();
3791 if (childLayer > highest) {
3792 highest = childLayer;
3793 }
3794 }
3795 return highest;
3796 }
3797
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003798 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003799 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003800 if (mChildren.isEmpty()) {
3801 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003802 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003803 }
3804
3805 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003806 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003807 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003808 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003809 }
3810 }
3811
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003812 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003813 // We want to consume the negative sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003814 // below the parent, then this window (the parent), and then the positive sublayer children
3815 // because they need to appear above the parent.
3816 int i = 0;
3817 final int count = mChildren.size();
3818 WindowState child = mChildren.get(i);
3819
3820 while (i < count && child.mSubLayer < 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003821 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003822 return true;
3823 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003824 i++;
3825 if (i >= count) {
3826 break;
3827 }
3828 child = mChildren.get(i);
3829 }
3830
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003831 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003832 return true;
3833 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003834
3835 while (i < count) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003836 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003837 return true;
3838 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003839 i++;
3840 if (i >= count) {
3841 break;
3842 }
3843 child = mChildren.get(i);
3844 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003845
3846 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003847 }
3848
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003849 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003850 // We want to consume the positive sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003851 // above the parent, then this window (the parent), and then the negative sublayer children
3852 // because they need to appear above the parent.
3853 int i = mChildren.size() - 1;
3854 WindowState child = mChildren.get(i);
3855
3856 while (i >= 0 && child.mSubLayer >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003857 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003858 return true;
3859 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003860 --i;
3861 if (i < 0) {
3862 break;
3863 }
3864 child = mChildren.get(i);
3865 }
3866
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003867 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003868 return true;
3869 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003870
3871 while (i >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003872 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003873 return true;
3874 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003875 --i;
3876 if (i < 0) {
3877 break;
3878 }
3879 child = mChildren.get(i);
3880 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003881
3882 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003883 }
3884
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003885 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
3886 boolean traverseTopToBottom) {
3887 if (traverseTopToBottom) {
3888 if (mService.mInputMethodTarget == this) {
3889 // This window is the current IME target, so we need to process the IME windows
3890 // directly above it.
3891 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
3892 return true;
3893 }
3894 }
3895 if (callback.apply(this)) {
3896 return true;
3897 }
3898 } else {
3899 if (callback.apply(this)) {
3900 return true;
3901 }
3902 if (mService.mInputMethodTarget == this) {
3903 // This window is the current IME target, so we need to process the IME windows
3904 // directly above it.
3905 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
3906 return true;
3907 }
3908 }
3909 }
3910
3911 return false;
3912 }
3913
Wale Ogunwaled1880962016-11-08 10:31:59 -08003914 WindowState getWindow(Predicate<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003915 if (mChildren.isEmpty()) {
3916 return callback.test(this) ? this : null;
3917 }
3918
3919 // We want to consume the positive sublayer children first because they need to appear
3920 // above the parent, then this window (the parent), and then the negative sublayer children
3921 // because they need to appear above the parent.
3922 int i = mChildren.size() - 1;
3923 WindowState child = mChildren.get(i);
3924
3925 while (i >= 0 && child.mSubLayer >= 0) {
3926 if (callback.test(child)) {
3927 return child;
3928 }
3929 --i;
3930 if (i < 0) {
3931 break;
3932 }
3933 child = mChildren.get(i);
3934 }
3935
Wale Ogunwaled1880962016-11-08 10:31:59 -08003936 if (callback.test(this)) {
3937 return this;
3938 }
Wale Ogunwale34247952017-02-19 11:57:53 -08003939
3940 while (i >= 0) {
3941 if (callback.test(child)) {
3942 return child;
3943 }
3944 --i;
3945 if (i < 0) {
3946 break;
3947 }
3948 child = mChildren.get(i);
3949 }
3950
3951 return null;
Wale Ogunwaled1880962016-11-08 10:31:59 -08003952 }
3953
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01003954 /**
3955 * @return True if we our one of our ancestors has {@link #mAnimatingExit} set to true, false
3956 * otherwise.
3957 */
3958 @VisibleForTesting
3959 boolean isSelfOrAncestorWindowAnimatingExit() {
3960 WindowState window = this;
3961 do {
3962 if (window.mAnimatingExit) {
3963 return true;
3964 }
3965 window = window.getParentWindow();
3966 } while (window != null);
3967 return false;
3968 }
3969
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003970 void onExitAnimationDone() {
3971 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
3972 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
Jorim Jaggia5e10572017-11-15 14:36:26 +01003973 + " selfAnimating=" + isSelfAnimating());
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003974
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003975 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003976 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +01003977 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003978 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003979 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003980 }
3981 }
3982
3983 if (mWinAnimator.mEnteringAnimation) {
3984 mWinAnimator.mEnteringAnimation = false;
3985 mService.requestTraversal();
3986 // System windows don't have an activity and an app token as a result, but need a way
3987 // to be informed about their entrance animation end.
3988 if (mAppToken == null) {
3989 try {
3990 mClient.dispatchWindowShown();
3991 } catch (RemoteException e) {
3992 }
3993 }
3994 }
3995
Jorim Jaggia5e10572017-11-15 14:36:26 +01003996 if (isSelfAnimating()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003997 return;
3998 }
3999
Jorim Jaggia5e10572017-11-15 14:36:26 +01004000 //TODO (multidisplay): Accessibility is supported only for the default display.
4001 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
4002 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
4003 }
4004
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01004005 if (!isSelfOrAncestorWindowAnimatingExit()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004006 return;
4007 }
4008
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07004009 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004010 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
4011
4012 mDestroying = true;
4013
4014 final boolean hasSurface = mWinAnimator.hasSurface();
4015 if (hasSurface) {
chaviw1aa12752018-02-06 17:15:36 -08004016 // Use pendingTransaction here so hide is done the same transaction as the other
4017 // animations when exiting
4018 mWinAnimator.hide(getPendingTransaction(), "onExitAnimationDone");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004019 }
4020
4021 // If we have an app token, we ask it to destroy the surface for us, so that it can take
4022 // care to ensure the activity has actually stopped and the surface is not still in use.
4023 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
4024 // transaction.
4025 if (mAppToken != null) {
4026 mAppToken.destroySurfaces();
4027 } else {
4028 if (hasSurface) {
4029 mService.mDestroySurface.add(this);
4030 }
4031 if (mRemoveOnExit) {
4032 mService.mPendingRemove.add(this);
4033 mRemoveOnExit = false;
4034 }
4035 }
4036 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07004037 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004038 }
Dan Willemsen117197f2016-07-30 13:02:59 -07004039
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004040 boolean clearAnimatingFlags() {
4041 boolean didSomething = false;
4042 // We don't want to clear it out for windows that get replaced, because the
4043 // animation depends on the flag to remove the replaced window.
4044 //
4045 // We also don't clear the mAnimatingExit flag for windows which have the
4046 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4047 // by the client. We should let animation proceed and not clear this flag or
4048 // they won't eventually be removed by WindowStateAnimator#finishExit.
4049 if (!mWillReplaceWindow && !mRemoveOnExit) {
4050 // Clear mAnimating flag together with mAnimatingExit. When animation
4051 // changes from exiting to entering, we need to clear this flag until the
4052 // new animation gets applied, so that isAnimationStarting() becomes true
4053 // until then.
4054 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4055 // placement for this window during this period, one or more frame will
4056 // show up with wrong position or scale.
4057 if (mAnimatingExit) {
4058 mAnimatingExit = false;
4059 didSomething = true;
4060 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004061 if (mDestroying) {
4062 mDestroying = false;
4063 mService.mDestroySurface.remove(this);
4064 didSomething = true;
4065 }
4066 }
4067
4068 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004069 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004070 }
4071
4072 return didSomething;
4073 }
4074
Winson4b4ba902016-07-27 19:45:52 -07004075 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004076 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004077 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004078
4079 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004080 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004081 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004082 c.hideWallpaperWindow(wasDeferred, reason);
4083 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004084 if (!mWinAnimator.mLastHidden || wasDeferred) {
4085 mWinAnimator.hide(reason);
4086 dispatchWallpaperVisibility(false);
4087 final DisplayContent displayContent = getDisplayContent();
4088 if (displayContent != null) {
4089 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
4090 }
4091 }
4092 }
4093
4094 /**
4095 * Check wallpaper window for visibility change and notify window if so.
4096 * @param visible Current visibility.
4097 */
4098 void dispatchWallpaperVisibility(final boolean visible) {
4099 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07004100 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004101
4102 // Only send notification if the visibility actually changed and we are not trying to hide
4103 // the wallpaper when we are deferring hiding of the wallpaper.
4104 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4105 mWallpaperVisible = visible;
4106 try {
4107 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4108 "Updating vis of wallpaper " + this
4109 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4110 mClient.dispatchAppVisibility(visible);
4111 } catch (RemoteException e) {
4112 }
4113 }
4114 }
4115
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004116 boolean hasVisibleNotDrawnWallpaper() {
4117 if (mWallpaperVisible && !isDrawnLw()) {
4118 return true;
4119 }
4120 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004121 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004122 if (c.hasVisibleNotDrawnWallpaper()) {
4123 return true;
4124 }
4125 }
4126 return false;
4127 }
4128
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004129 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4130 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004131 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004132 c.updateReportedVisibility(results);
4133 }
4134
4135 if (mAppFreezing || mViewVisibility != View.VISIBLE
4136 || mAttrs.type == TYPE_APPLICATION_STARTING
4137 || mDestroying) {
4138 return;
4139 }
4140 if (DEBUG_VISIBILITY) {
4141 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
4142 + ", isAnimationSet=" + mWinAnimator.isAnimationSet());
4143 if (!isDrawnLw()) {
4144 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4145 + " pv=" + mPolicyVisibility
4146 + " mDrawState=" + mWinAnimator.mDrawState
4147 + " ph=" + isParentWindowHidden()
4148 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
Jorim Jaggia5e10572017-11-15 14:36:26 +01004149 + " a=" + mWinAnimator.isAnimationSet());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004150 }
4151 }
4152
4153 results.numInteresting++;
4154 if (isDrawnLw()) {
4155 results.numDrawn++;
4156 if (!mWinAnimator.isAnimationSet()) {
4157 results.numVisible++;
4158 }
4159 results.nowGone = false;
4160 } else if (mWinAnimator.isAnimationSet()) {
4161 results.nowGone = false;
4162 }
4163 }
4164
Robert Carrfbbde852016-10-18 11:02:28 -07004165 /**
4166 * Calculate the window crop according to system decor policy. In general this is
4167 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4168 * special cases. This rectangle is in screen space.
4169 */
4170 void calculatePolicyCrop(Rect policyCrop) {
4171 final DisplayContent displayContent = getDisplayContent();
4172 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
4173
4174 if (!isDefaultDisplay()) {
4175 // On a different display there is no system decor. Crop the window
4176 // by the screen boundaries.
4177 // TODO(multi-display)
4178 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4179 policyCrop.intersect(-mCompatFrame.left, -mCompatFrame.top,
4180 displayInfo.logicalWidth - mCompatFrame.left,
4181 displayInfo.logicalHeight - mCompatFrame.top);
Robert Carrfbbde852016-10-18 11:02:28 -07004182 } else if (mDecorFrame.isEmpty()) {
4183 // Windows without policy decor aren't cropped.
4184 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4185 } else {
4186 // Crop to the system decor specified by policy.
4187 calculateSystemDecorRect(policyCrop);
4188 }
4189 }
4190
4191 /**
4192 * The system decor rect is the region of the window which is not covered
4193 * by system decorations.
4194 */
4195 private void calculateSystemDecorRect(Rect systemDecorRect) {
4196 final Rect decorRect = mDecorFrame;
4197 final int width = mFrame.width();
4198 final int height = mFrame.height();
4199
Rob Carr06be6bb2018-02-06 16:26:06 +00004200 // Compute the offset of the window in relation to the decor rect.
4201 final int left = mXOffset + mFrame.left;
4202 final int top = mYOffset + mFrame.top;
Robert Carrfbbde852016-10-18 11:02:28 -07004203
4204 // Initialize the decor rect to the entire frame.
4205 if (isDockedResizing()) {
4206 // If we are resizing with the divider, the task bounds might be smaller than the
4207 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4208 // want in this case in order to avoid holes.
4209 //
4210 // We take care to not shrink the width, for surfaces which are larger than
4211 // the display region. Of course this area will not eventually be visible
4212 // but if we truncate the width now, we will calculate incorrectly
4213 // when adjusting to the stack bounds.
4214 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4215 systemDecorRect.set(0, 0,
4216 Math.max(width, displayInfo.logicalWidth),
4217 Math.max(height, displayInfo.logicalHeight));
4218 } else {
4219 systemDecorRect.set(0, 0, width, height);
4220 }
4221
4222 // If a freeform window is animating from a position where it would be cutoff, it would be
4223 // cutoff during the animation. We don't want that, so for the duration of the animation
4224 // we ignore the decor cropping and depend on layering to position windows correctly.
Wale Ogunwale44f036f2017-09-29 05:09:09 -07004225 final boolean cropToDecor = !(inFreeformWindowingMode() && isAnimatingLw());
Robert Carrfbbde852016-10-18 11:02:28 -07004226 if (cropToDecor) {
4227 // Intersect with the decor rect, offsetted by window position.
4228 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
4229 decorRect.right - left, decorRect.bottom - top);
4230 }
4231
4232 // If size compatibility is being applied to the window, the
4233 // surface is scaled relative to the screen. Also apply this
4234 // scaling to the crop rect. We aren't using the standard rect
4235 // scale function because we want to round things to make the crop
4236 // always round to a larger rect to ensure we don't crop too
4237 // much and hide part of the window that should be seen.
4238 if (mEnforceSizeCompat && mInvGlobalScale != 1.0f) {
4239 final float scale = mInvGlobalScale;
4240 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
4241 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
4242 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
4243 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
4244 }
4245
4246 }
4247
4248 /**
4249 * Expand the given rectangle by this windows surface insets. This
4250 * takes you from the 'window size' to the 'surface size'.
4251 * The surface insets are positive in each direction, so we inset by
4252 * the inverse.
4253 */
4254 void expandForSurfaceInsets(Rect r) {
4255 r.inset(-mAttrs.surfaceInsets.left,
4256 -mAttrs.surfaceInsets.top,
4257 -mAttrs.surfaceInsets.right,
4258 -mAttrs.surfaceInsets.bottom);
4259 }
4260
Robert Carrc91d1c32017-02-15 19:37:46 -08004261 boolean surfaceInsetsChanging() {
4262 return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets);
4263 }
4264
Bryce Leef858b572017-06-29 14:03:33 -07004265 int relayoutVisibleWindow(int result, int attrChanges, int oldVisibility) {
Robert Carrecc06b32017-04-18 14:25:10 -07004266 final boolean wasVisible = isVisibleLw();
4267
4268 result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004269 if (mAnimatingExit) {
4270 Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit="
4271 + mRemoveOnExit + ", mDestroying=" + mDestroying);
4272
4273 mWinAnimator.cancelExitAnimationForNextAnimationLocked();
4274 mAnimatingExit = false;
4275 }
4276 if (mDestroying) {
4277 mDestroying = false;
4278 mService.mDestroySurface.remove(this);
4279 }
4280 if (oldVisibility == View.GONE) {
4281 mWinAnimator.mEnterAnimationPending = true;
4282 }
4283
Andrii Kulian8ee72852017-03-10 10:36:45 -08004284 mLastVisibleLayoutRotation = getDisplayContent().getRotation();
Robert Carrc91d1c32017-02-15 19:37:46 -08004285
4286 mWinAnimator.mEnteringAnimation = true;
Bryce Leeae73ba42017-05-05 09:58:25 -07004287
Bryce Leef858b572017-06-29 14:03:33 -07004288 prepareWindowToDisplayDuringRelayout(wasVisible);
Bryce Leeae73ba42017-05-05 09:58:25 -07004289
Robert Carrc91d1c32017-02-15 19:37:46 -08004290 if ((attrChanges & FORMAT_CHANGED) != 0) {
4291 // If the format can't be changed in place, preserve the old surface until the app draws
4292 // on the new one. This prevents blinking when we change elevation of freeform and
4293 // pinned windows.
4294 if (!mWinAnimator.tryChangeFormatInPlaceLocked()) {
4295 mWinAnimator.preserveSurfaceLocked();
4296 result |= RELAYOUT_RES_SURFACE_CHANGED
4297 | RELAYOUT_RES_FIRST_TIME;
4298 }
4299 }
4300
4301 // When we change the Surface size, in scenarios which may require changing
4302 // the surface position in sync with the resize, we use a preserved surface
4303 // so we can freeze it while waiting for the client to report draw on the newly
Winson Chung8bca9e42017-04-16 15:59:43 -07004304 // sized surface. Don't preserve surfaces if the insets change while animating the pinned
4305 // stack since it can lead to issues if a new surface is created while calculating the
4306 // scale for the animation using the source hint rect
4307 // (see WindowStateAnimator#setSurfaceBoundariesLocked()).
Robert Carr09286c92018-02-15 13:52:31 -08004308 if (isDragResizeChanged()
Wale Ogunwale44f036f2017-09-29 05:09:09 -07004309 || (surfaceInsetsChanging() && !inPinnedWindowingMode())) {
Robert Carrc91d1c32017-02-15 19:37:46 -08004310 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
4311
4312 setDragResizing();
Robert Carrc91d1c32017-02-15 19:37:46 -08004313 // We can only change top level windows to the full-screen surface when
4314 // resizing (as we only have one full-screen surface). So there is no need
4315 // to preserve and destroy windows which are attached to another, they
4316 // will keep their surface and its size may change over time.
4317 if (mHasSurface && !isChildWindow()) {
4318 mWinAnimator.preserveSurfaceLocked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08004319 result |= RELAYOUT_RES_SURFACE_CHANGED |
4320 RELAYOUT_RES_FIRST_TIME;
Robert Carrc91d1c32017-02-15 19:37:46 -08004321 }
4322 }
4323 final boolean freeformResizing = isDragResizing()
4324 && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
4325 final boolean dockedResizing = isDragResizing()
4326 && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
4327 result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0;
4328 result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004329 return result;
4330 }
4331
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004332 /**
4333 * @return True if this window has been laid out at least once; false otherwise.
4334 */
4335 boolean isLaidOut() {
4336 return mLayoutSeq != -1;
4337 }
4338
4339 /**
4340 * Updates the last inset values to the current ones.
4341 */
4342 void updateLastInsetValues() {
4343 mLastOverscanInsets.set(mOverscanInsets);
4344 mLastContentInsets.set(mContentInsets);
4345 mLastVisibleInsets.set(mVisibleInsets);
4346 mLastStableInsets.set(mStableInsets);
4347 mLastOutsets.set(mOutsets);
Adrian Roos5c6b6222017-11-07 17:36:10 +01004348 mLastDisplayCutout = mDisplayCutout;
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004349 }
4350
Jorim Jaggia5e10572017-11-15 14:36:26 +01004351 void startAnimation(Animation anim) {
4352 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4353 anim.initialize(mFrame.width(), mFrame.height(),
4354 displayInfo.appWidth, displayInfo.appHeight);
4355 anim.restrictDuration(MAX_ANIMATION_DURATION);
4356 anim.scaleCurrentDuration(mService.getWindowAnimationScaleLocked());
4357 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi2e3c31d2017-11-20 19:49:00 +01004358 new WindowAnimationSpec(anim, mSurfacePosition, false /* canSkipFirstFrame */),
4359 mService.mSurfaceAnimationRunner);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004360 startAnimation(mPendingTransaction, adapter);
4361 commitPendingTransaction();
4362 }
4363
chaviw161ea3e2018-01-31 12:01:12 -08004364 private void startMoveAnimation(int left, int top) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01004365 if (DEBUG_ANIM) Slog.v(TAG, "Setting move animation on " + this);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004366 final Point oldPosition = new Point();
4367 final Point newPosition = new Point();
4368 transformFrameToSurfacePosition(mLastFrame.left, mLastFrame.top, oldPosition);
4369 transformFrameToSurfacePosition(left, top, newPosition);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004370 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004371 new MoveAnimationSpec(oldPosition.x, oldPosition.y, newPosition.x, newPosition.y),
Jorim Jaggia5e10572017-11-15 14:36:26 +01004372 mService.mSurfaceAnimationRunner);
chaviw161ea3e2018-01-31 12:01:12 -08004373 startAnimation(getPendingTransaction(), adapter);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004374 }
4375
4376 private void startAnimation(Transaction t, AnimationAdapter adapter) {
4377 startAnimation(t, adapter, mWinAnimator.mLastHidden);
4378 }
4379
4380 @Override
4381 protected void onAnimationFinished() {
4382 mWinAnimator.onAnimationFinished();
4383 }
4384
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004385 /**
4386 * Retrieves the current transformation matrix of the window, relative to the display.
4387 *
4388 * @param float9 A temporary array of 9 floats.
4389 * @param outMatrix Matrix to fill in the transformation.
4390 */
4391 void getTransformationMatrix(float[] float9, Matrix outMatrix) {
4392 float9[Matrix.MSCALE_X] = mWinAnimator.mDsDx;
4393 float9[Matrix.MSKEW_Y] = mWinAnimator.mDtDx;
4394 float9[Matrix.MSKEW_X] = mWinAnimator.mDtDy;
4395 float9[Matrix.MSCALE_Y] = mWinAnimator.mDsDy;
Rob Carr06be6bb2018-02-06 16:26:06 +00004396 int x = mSurfacePosition.x + mShownPosition.x;
4397 int y = mSurfacePosition.y + mShownPosition.y;
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004398
4399 // If changed, also adjust transformFrameToSurfacePosition
4400 final WindowContainer parent = getParent();
4401 if (isChildWindow()) {
4402 final WindowState parentWindow = getParentWindow();
4403 x += parentWindow.mFrame.left - parentWindow.mAttrs.surfaceInsets.left;
4404 y += parentWindow.mFrame.top - parentWindow.mAttrs.surfaceInsets.top;
4405 } else if (parent != null) {
4406 final Rect parentBounds = parent.getBounds();
4407 x += parentBounds.left;
4408 y += parentBounds.top;
4409 }
4410 float9[Matrix.MTRANS_X] = x;
4411 float9[Matrix.MTRANS_Y] = y;
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004412 float9[Matrix.MPERSP_0] = 0;
4413 float9[Matrix.MPERSP_1] = 0;
4414 float9[Matrix.MPERSP_2] = 1;
4415 outMatrix.setValues(float9);
4416 }
4417
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004418 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4419 // access to its windows children. Need to investigate re-writing
4420 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4421 static final class UpdateReportedVisibilityResults {
4422 int numInteresting;
4423 int numVisible;
4424 int numDrawn;
4425 boolean nowGone = true;
4426
4427 void reset() {
4428 numInteresting = 0;
4429 numVisible = 0;
4430 numDrawn = 0;
4431 nowGone = true;
4432 }
4433 }
Robert Carraf422a82017-04-10 18:34:33 -07004434
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004435 private static final class WindowId extends IWindowId.Stub {
4436 private final WeakReference<WindowState> mOuter;
4437
4438 private WindowId(WindowState outer) {
4439
4440 // Use a weak reference for the outer class. This is important to prevent the following
4441 // leak: Since we send this class to the client process, binder will keep it alive as
4442 // long as the client keeps it alive. Now, if the window is removed, we need to clear
4443 // out our reference so even though this class is kept alive we don't leak WindowState,
4444 // which can keep a whole lot of classes alive.
4445 mOuter = new WeakReference<>(outer);
4446 }
4447
4448 @Override
4449 public void registerFocusObserver(IWindowFocusObserver observer) {
4450 final WindowState outer = mOuter.get();
4451 if (outer != null) {
4452 outer.registerFocusObserver(observer);
4453 }
4454 }
4455 @Override
4456 public void unregisterFocusObserver(IWindowFocusObserver observer) {
4457 final WindowState outer = mOuter.get();
4458 if (outer != null) {
4459 outer.unregisterFocusObserver(observer);
4460 }
4461 }
4462 @Override
4463 public boolean isFocused() {
4464 final WindowState outer = mOuter.get();
4465 return outer != null && outer.isFocused();
4466 }
4467 }
4468
Robert Carrb1579c82017-09-05 14:54:47 -07004469
4470 @Override
4471 boolean shouldMagnify() {
4472 if (mAttrs.type == TYPE_INPUT_METHOD ||
Robert Carree4d4b92017-11-22 12:21:46 -08004473 mAttrs.type == TYPE_INPUT_METHOD_DIALOG ||
4474 mAttrs.type == TYPE_MAGNIFICATION_OVERLAY ||
4475 mAttrs.type == TYPE_NAVIGATION_BAR ||
4476 // It's tempting to wonder: Have we forgotten the rounded corners overlay?
4477 // worry not: it's a fake TYPE_NAVIGATION_BAR_PANEL
4478 mAttrs.type == TYPE_NAVIGATION_BAR_PANEL ||
4479 mAttrs.type == TYPE_STATUS_BAR) {
Robert Carrb1579c82017-09-05 14:54:47 -07004480 return false;
4481 }
4482 return true;
4483 }
4484
4485 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004486 SurfaceSession getSession() {
4487 if (mSession.mSurfaceSession != null) {
4488 return mSession.mSurfaceSession;
4489 } else {
4490 return getParent().getSession();
4491 }
4492 }
4493
4494 @Override
4495 boolean needsZBoost() {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00004496 if (mIsImWindow && mService.mInputMethodTarget != null) {
4497 final AppWindowToken appToken = mService.mInputMethodTarget.mAppToken;
4498 if (appToken != null) {
4499 return appToken.needsZBoost();
4500 }
4501 }
4502 return mWillReplaceWindow;
Robert Carrb1579c82017-09-05 14:54:47 -07004503 }
4504
Robert Carrf07ef9e2017-11-21 12:12:49 -08004505 private void applyDims(Dimmer dimmer) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07004506 if (!mAnimatingExit && mAppDied) {
4507 mIsDimming = true;
chaviw2fb06bc2018-01-19 17:09:15 -08004508 dimmer.dimAbove(getPendingTransaction(), this, DEFAULT_DIM_AMOUNT_DEAD_WINDOW);
chaviwebcbc342018-02-07 13:19:00 -08004509 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0 && isVisibleNow() && !mHidden) {
chaviw14076152018-02-02 14:51:20 -08004510 // Only show a dim behind when the following is satisfied:
4511 // 1. The window has the flag FLAG_DIM_BEHIND
4512 // 2. The WindowToken is not hidden so dims aren't shown when the window is exiting.
4513 // 3. The WS is considered visible according to the isVisible() method
chaviwebcbc342018-02-07 13:19:00 -08004514 // 4. The WS is not hidden.
Robert Carrf59b8dd2017-10-02 18:58:36 -07004515 mIsDimming = true;
chaviw2fb06bc2018-01-19 17:09:15 -08004516 dimmer.dimBelow(getPendingTransaction(), this, mAttrs.dimAmount);
Robert Carrf59b8dd2017-10-02 18:58:36 -07004517 }
Robert Carrf07ef9e2017-11-21 12:12:49 -08004518 }
4519
4520 @Override
4521 void prepareSurfaces() {
4522 final Dimmer dimmer = getDimmer();
4523 mIsDimming = false;
4524 if (dimmer != null) {
4525 applyDims(dimmer);
4526 }
chaviw2f0567b2018-01-29 16:22:02 -08004527 updateSurfacePosition();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004528
Robert Carrb1579c82017-09-05 14:54:47 -07004529 mWinAnimator.prepareSurfaceLocked(true);
4530 super.prepareSurfaces();
4531 }
4532
4533 @Override
Jorim Jaggia5e10572017-11-15 14:36:26 +01004534 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
4535 super.onAnimationLeashCreated(t, leash);
4536
4537 // Leash is now responsible for position, so set our position to 0.
4538 t.setPosition(mSurfaceControl, 0, 0);
chaviw3e751af2018-01-11 11:22:39 -08004539 mLastSurfacePosition.set(0, 0);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004540 }
4541
4542 @Override
4543 public void onAnimationLeashDestroyed(Transaction t) {
4544 super.onAnimationLeashDestroyed(t);
4545 updateSurfacePosition(t);
4546 }
4547
chaviwe07246a2017-12-12 16:18:29 -08004548 @Override
chaviw2f0567b2018-01-29 16:22:02 -08004549 void updateSurfacePosition() {
4550 updateSurfacePosition(getPendingTransaction());
4551 }
4552
4553 private void updateSurfacePosition(Transaction t) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01004554 if (mSurfaceControl == null) {
4555 return;
4556 }
4557
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004558 transformFrameToSurfacePosition(mFrame.left, mFrame.top, mSurfacePosition);
chaviw3e751af2018-01-11 11:22:39 -08004559 if (!mSurfaceAnimator.hasLeash() && !mLastSurfacePosition.equals(mSurfacePosition)) {
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004560 t.setPosition(mSurfaceControl, mSurfacePosition.x, mSurfacePosition.y);
chaviw3e751af2018-01-11 11:22:39 -08004561 mLastSurfacePosition.set(mSurfacePosition.x, mSurfacePosition.y);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004562 }
4563 }
4564
4565 private void transformFrameToSurfacePosition(int left, int top, Point outPoint) {
4566 outPoint.set(left, top);
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004567
4568 // If changed, also adjust getTransformationMatrix
chaviwe07246a2017-12-12 16:18:29 -08004569 final WindowContainer parentWindowContainer = getParent();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004570 if (isChildWindow()) {
4571 // TODO: This probably falls apart at some point and we should
4572 // actually compute relative coordinates.
Jorim Jaggi50d3f8f2017-12-27 17:41:25 +01004573
4574 // Since the parent was outset by its surface insets, we need to undo the outsetting
4575 // with insetting by the same amount.
Jorim Jaggia5e10572017-11-15 14:36:26 +01004576 final WindowState parent = getParentWindow();
Jorim Jaggi50d3f8f2017-12-27 17:41:25 +01004577 outPoint.offset(-parent.mFrame.left + parent.mAttrs.surfaceInsets.left,
4578 -parent.mFrame.top + parent.mAttrs.surfaceInsets.top);
chaviwe07246a2017-12-12 16:18:29 -08004579 } else if (parentWindowContainer != null) {
4580 final Rect parentBounds = parentWindowContainer.getBounds();
4581 outPoint.offset(-parentBounds.left, -parentBounds.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004582 }
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004583
Robert Carr32bcb102018-01-29 15:03:23 -08004584 TaskStack stack = getStack();
4585
4586 // If we have stack outsets, that means the top-left
4587 // will be outset, and we need to inset ourselves
4588 // to account for it. If we actually have shadows we will
4589 // then un-inset ourselves by the surfaceInsets.
4590 if (stack != null) {
4591 final int outset = stack.getStackOutset();
4592 outPoint.offset(outset, outset);
4593 }
4594
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004595 // Expand for surface insets. See WindowState.expandForSurfaceInsets.
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004596 outPoint.offset(-mAttrs.surfaceInsets.left, -mAttrs.surfaceInsets.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004597 }
4598
4599 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004600 void assignLayer(Transaction t, int layer) {
4601 // See comment in assignRelativeLayerForImeTargetChild
4602 if (!isChildWindow()
4603 || (mService.mInputMethodTarget != getParentWindow())
4604 || !inSplitScreenWindowingMode()) {
4605 super.assignLayer(t, layer);
4606 return;
4607 }
4608 getDisplayContent().assignRelativeLayerForImeTargetChild(t, this);
4609 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07004610
4611 @Override
4612 public boolean isDimming() {
4613 return mIsDimming;
4614 }
Robert Carr0eff1872017-12-01 14:27:04 -08004615
4616 // TODO(b/70040778): We should aim to eliminate the last user of TYPE_APPLICATION_MEDIA
4617 // then we can drop all negative layering on the windowing side and simply inherit
4618 // the default implementation here.
4619 public void assignChildLayers(Transaction t) {
4620 int layer = 1;
4621 for (int i = 0; i < mChildren.size(); i++) {
4622 final WindowState w = mChildren.get(i);
4623
4624 // APPLICATION_MEDIA_OVERLAY needs to go above APPLICATION_MEDIA
4625 // while they both need to go below the main window. However the
4626 // relative layering of multiple APPLICATION_MEDIA/OVERLAY has never
4627 // been defined and so we can use static layers and leave it that way.
4628 if (w.mAttrs.type == TYPE_APPLICATION_MEDIA) {
4629 w.assignLayer(t, -2);
4630 } else if (w.mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) {
4631 w.assignLayer(t, -1);
4632 } else {
4633 w.assignLayer(t, layer);
4634 }
4635 w.assignChildLayers(t);
4636 layer++;
4637 }
4638 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01004639
Andrii Kulian4b6599e2018-01-15 17:24:08 -08004640 /**
4641 * Update a tap exclude region with a rectangular area identified by provided id. The requested
4642 * area will be clipped to the window bounds.
4643 */
4644 void updateTapExcludeRegion(int regionId, int left, int top, int width, int height) {
4645 final DisplayContent currentDisplay = getDisplayContent();
4646 if (currentDisplay == null) {
4647 throw new IllegalStateException("Trying to update window not attached to any display.");
4648 }
4649
4650 if (mTapExcludeRegionHolder == null) {
4651 mTapExcludeRegionHolder = new TapExcludeRegionHolder();
4652
4653 // Make sure that this window is registered as one that provides a tap exclude region
4654 // for its containing display.
4655 currentDisplay.mTapExcludeProvidingWindows.add(this);
4656 }
4657
4658 mTapExcludeRegionHolder.updateRegion(regionId, left, top, width, height);
4659 // Trigger touch exclude region update on current display.
4660 final boolean isAppFocusedOnDisplay = mService.mFocusedApp != null
4661 && mService.mFocusedApp.getDisplayContent() == currentDisplay;
4662 currentDisplay.setTouchExcludeRegion(isAppFocusedOnDisplay ? mService.mFocusedApp.getTask()
4663 : null);
4664 }
4665
4666 /** Union the region with current tap exclude region that this window provides. */
4667 void amendTapExcludeRegion(Region region) {
4668 mTapExcludeRegionHolder.amendRegion(region, getBounds());
4669 }
4670
Jorim Jaggia5e10572017-11-15 14:36:26 +01004671 private final class MoveAnimationSpec implements AnimationSpec {
4672
4673 private final long mDuration;
4674 private Interpolator mInterpolator;
4675 private Point mFrom = new Point();
4676 private Point mTo = new Point();
4677
4678 private MoveAnimationSpec(int fromX, int fromY, int toX, int toY) {
4679 final Animation anim = AnimationUtils.loadAnimation(mContext,
4680 com.android.internal.R.anim.window_move_from_decor);
Jorim Jaggi08f75cf2018-01-08 14:38:53 +01004681 mDuration = (long)
4682 (anim.computeDurationHint() * mService.getWindowAnimationScaleLocked());
Jorim Jaggia5e10572017-11-15 14:36:26 +01004683 mInterpolator = anim.getInterpolator();
4684 mFrom.set(fromX, fromY);
4685 mTo.set(toX, toY);
4686 }
4687
4688 @Override
4689 public long getDuration() {
4690 return mDuration;
4691 }
4692
4693 @Override
4694 public void apply(Transaction t, SurfaceControl leash, long currentPlayTime) {
4695 final float fraction = (float) currentPlayTime / getDuration();
4696 final float v = mInterpolator.getInterpolation(fraction);
4697 t.setPosition(leash, mFrom.x + (mTo.x - mFrom.x) * v,
4698 mFrom.y + (mTo.y - mFrom.y) * v);
4699 }
4700 }
satokcef37fb2011-10-24 21:49:38 +09004701}