blob: b3809dd8f6c9d96c35a94449f062b9122fcb16f8 [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;
Jorim Jaggi02886a82016-12-06 09:10:06 -080020import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
21import static android.view.Display.DEFAULT_DISPLAY;
Jorim Jaggia5e10572017-11-15 14:36:26 +010022import static android.view.SurfaceControl.Transaction;
Jorim Jaggi02886a82016-12-06 09:10:06 -080023import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
24import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
25import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
26import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
27import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
28import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW;
29import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
30import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
31import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
32import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
33import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
34import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
35import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
36import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080037import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
38import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
39import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Robert Carrc91d1c32017-02-15 19:37:46 -080040import static android.view.WindowManager.LayoutParams.FORMAT_CHANGED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080041import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
42import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
43import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070044import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Jorim Jaggi02886a82016-12-06 09:10:06 -080045import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
46import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
47import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
48import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
49import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
50import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Robert Carr0eff1872017-12-01 14:27:04 -080051import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;
Vishnu Nair1d0fa072018-01-04 07:53:00 -080052import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080053import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
54import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
55import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
56import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
57import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
58import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Robert Carrb1579c82017-09-05 14:54:47 -070059import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY;
60import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
Robert Carree4d4b92017-11-22 12:21:46 -080061import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;
Robert Carrb1579c82017-09-05 14:54:47 -070062import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070063import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Jorim Jaggi02886a82016-12-06 09:10:06 -080064import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070065import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType;
Robert Carrc91d1c32017-02-15 19:37:46 -080066import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED;
67import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM;
68import static android.view.WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME;
69import static android.view.WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED;
Adrian Roose99bc052017-11-20 17:55:31 +010070import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
71import static com.android.server.policy.WindowManagerPolicy.TRANSIT_ENTER;
72import static com.android.server.policy.WindowManagerPolicy.TRANSIT_EXIT;
73import static com.android.server.policy.WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
Jorim Jaggi02886a82016-12-06 09:10:06 -080074import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
75import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
76import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
77import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
78import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
79import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
80import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
81import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
82import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Jorim Jaggi02886a82016-12-06 09:10:06 -080083import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
84import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
85import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
86import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
87import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020088import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Jorim Jaggi02886a82016-12-06 09:10:06 -080089import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080090import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
91import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
92import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
93import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
Jorim Jaggia5e10572017-11-15 14:36:26 +010094import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
Jorim Jaggi02886a82016-12-06 09:10:06 -080095import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
96import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
97import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
98import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
99import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
100import static com.android.server.wm.WindowManagerService.localLOGV;
101import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING;
102import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
103import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN;
104import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700105import static com.android.server.wm.proto.IdentifierProto.HASH_CODE;
106import static com.android.server.wm.proto.IdentifierProto.TITLE;
107import static com.android.server.wm.proto.IdentifierProto.USER_ID;
108import static com.android.server.wm.proto.WindowStateProto.ANIMATING_EXIT;
109import static com.android.server.wm.proto.WindowStateProto.ANIMATOR;
110import static com.android.server.wm.proto.WindowStateProto.ATTRIBUTES;
111import static com.android.server.wm.proto.WindowStateProto.CHILD_WINDOWS;
112import static com.android.server.wm.proto.WindowStateProto.CONTAINING_FRAME;
113import static com.android.server.wm.proto.WindowStateProto.CONTENT_FRAME;
114import static com.android.server.wm.proto.WindowStateProto.CONTENT_INSETS;
Vishnu Nair1d0fa072018-01-04 07:53:00 -0800115import static com.android.server.wm.proto.WindowStateProto.CUTOUT;
116import static com.android.server.wm.proto.WindowStateProto.DECOR_FRAME;
117import static com.android.server.wm.proto.WindowStateProto.DESTROYING;
118import static com.android.server.wm.proto.WindowStateProto.DISPLAY_FRAME;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700119import static com.android.server.wm.proto.WindowStateProto.DISPLAY_ID;
120import static com.android.server.wm.proto.WindowStateProto.FRAME;
121import static com.android.server.wm.proto.WindowStateProto.GIVEN_CONTENT_INSETS;
Vishnu Nair1d0fa072018-01-04 07:53:00 -0800122import static com.android.server.wm.proto.WindowStateProto.HAS_SURFACE;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700123import static com.android.server.wm.proto.WindowStateProto.IDENTIFIER;
Vishnu Nair1d0fa072018-01-04 07:53:00 -0800124import static com.android.server.wm.proto.WindowStateProto.IS_ON_SCREEN;
125import static com.android.server.wm.proto.WindowStateProto.IS_READY_FOR_DISPLAY;
126import static com.android.server.wm.proto.WindowStateProto.IS_VISIBLE;
127import static com.android.server.wm.proto.WindowStateProto.OUTSETS;
128import static com.android.server.wm.proto.WindowStateProto.OUTSET_FRAME;
129import static com.android.server.wm.proto.WindowStateProto.OVERSCAN_FRAME;
130import static com.android.server.wm.proto.WindowStateProto.OVERSCAN_INSETS;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700131import static com.android.server.wm.proto.WindowStateProto.PARENT_FRAME;
Vishnu Nair1d0fa072018-01-04 07:53:00 -0800132import static com.android.server.wm.proto.WindowStateProto.REMOVED;
133import static com.android.server.wm.proto.WindowStateProto.REMOVE_ON_EXIT;
134import static com.android.server.wm.proto.WindowStateProto.REQUESTED_HEIGHT;
135import static com.android.server.wm.proto.WindowStateProto.REQUESTED_WIDTH;
Jorim Jaggi45be1c4c2017-12-15 18:44:43 +0100136import static com.android.server.wm.proto.WindowStateProto.SHOWN_POSITION;
Vishnu Nair1d0fa072018-01-04 07:53:00 -0800137import static com.android.server.wm.proto.WindowStateProto.STABLE_INSETS;
138import static com.android.server.wm.proto.WindowStateProto.STACK_ID;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700139import static com.android.server.wm.proto.WindowStateProto.SURFACE_INSETS;
Jorim Jaggi45be1c4c2017-12-15 18:44:43 +0100140import static com.android.server.wm.proto.WindowStateProto.SURFACE_POSITION;
Vishnu Nair1d0fa072018-01-04 07:53:00 -0800141import static com.android.server.wm.proto.WindowStateProto.SYSTEM_UI_VISIBILITY;
142import static com.android.server.wm.proto.WindowStateProto.VIEW_VISIBILITY;
143import static com.android.server.wm.proto.WindowStateProto.VISIBLE_FRAME;
144import static com.android.server.wm.proto.WindowStateProto.VISIBLE_INSETS;
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700145import static com.android.server.wm.proto.WindowStateProto.WINDOW_CONTAINER;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800146
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700147import android.annotation.CallSuper;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800148import android.app.AppOpsManager;
149import android.content.Context;
150import android.content.res.Configuration;
151import android.graphics.Matrix;
152import android.graphics.PixelFormat;
153import android.graphics.Point;
154import android.graphics.Rect;
155import android.graphics.Region;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700156import android.os.Binder;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700157import android.os.Debug;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800158import android.os.IBinder;
159import android.os.PowerManager;
160import android.os.RemoteCallbackList;
161import android.os.RemoteException;
162import android.os.SystemClock;
163import android.os.Trace;
164import android.os.UserHandle;
165import android.os.WorkSource;
Phil Weaverbb2f28a2017-12-22 09:44:28 -0800166import android.text.TextUtils;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800167import android.util.DisplayMetrics;
Jorim Jaggie7d2b852017-08-28 17:55:15 +0200168import android.util.MergedConfiguration;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800169import android.util.Slog;
170import android.util.TimeUtils;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700171import android.util.proto.ProtoOutputStream;
Adrian Roos5c6b6222017-11-07 17:36:10 +0100172import android.view.DisplayCutout;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800173import android.view.DisplayInfo;
174import android.view.Gravity;
175import android.view.IApplicationToken;
176import android.view.IWindow;
177import android.view.IWindowFocusObserver;
178import android.view.IWindowId;
179import android.view.InputChannel;
180import android.view.InputEvent;
181import android.view.InputEventReceiver;
Robert Carrb1579c82017-09-05 14:54:47 -0700182import android.view.SurfaceControl;
183import android.view.SurfaceSession;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800184import android.view.View;
185import android.view.ViewTreeObserver;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700186import android.view.WindowInfo;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800187import android.view.WindowManager;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100188import android.view.animation.Animation;
189import android.view.animation.AnimationUtils;
190import android.view.animation.Interpolator;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800191
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800192import com.android.internal.util.ToBooleanFunction;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800193import com.android.server.input.InputWindowHandle;
Adrian Roose99bc052017-11-20 17:55:31 +0100194import com.android.server.policy.WindowManagerPolicy;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100195import com.android.server.wm.LocalAnimationAdapter.AnimationSpec;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800196
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800197import java.io.PrintWriter;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200198import java.lang.ref.WeakReference;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800199import java.util.ArrayList;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700200import java.util.Comparator;
201import java.util.LinkedList;
Wale Ogunwaled1880962016-11-08 10:31:59 -0800202import java.util.function.Predicate;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800203
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700204/** A window in the window manager. */
205class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800206 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800207
Skuhne81c524a2015-08-12 13:34:14 -0700208 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700209 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
210 // use hard-coded min sizes for now.
211 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
212 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700213
214 // The thickness of a window resize handle outside the window bounds on the free form workspace
215 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700216 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700217
Craig Mautnere7ae2502012-03-26 17:11:19 -0700218 final WindowManagerPolicy mPolicy;
219 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800220 final Session mSession;
221 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800222 final int mAppOp;
223 // UserId and appId of the owner. Don't display windows of non-current user.
224 final int mOwnerUid;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800225 /** The owner has {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} */
226 final boolean mOwnerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200227 final WindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800228 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700229 // The same object as mToken if this is an app window and null for non-app windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800230 AppWindowToken mAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700231
232 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
233 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800234 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
235 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700236 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800237 final int mBaseLayer;
238 final int mSubLayer;
239 final boolean mLayoutAttached;
240 final boolean mIsImWindow;
241 final boolean mIsWallpaper;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700242 private final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700243 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700244 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800245 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700246 int mSystemUiVisibility;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700247 /**
248 * The visibility of the window based on policy like {@link WindowManagerPolicy}.
249 * Normally set by calling {@link #showLw} and {@link #hideLw}.
250 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800251 boolean mPolicyVisibility = true;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700252 /**
253 * What {@link #mPolicyVisibility} should be set to after a transition animation.
254 * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and
255 * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit
256 * animation is done.
257 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800258 boolean mPolicyVisibilityAfterAnim = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700259 private boolean mAppOpVisibility = true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700260 boolean mPermanentlyHidden; // the window should never be shown again
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700261 // This is a non-system overlay window that is currently force hidden.
262 private boolean mForceHideNonSystemOverlayWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800263 boolean mAppFreezing;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700264 boolean mHidden; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800265 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700266 private boolean mDragResizing;
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200267 private boolean mDragResizingChangeReported = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700268 private int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700269
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700270 private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800271
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700272 /**
273 * The window size that was requested by the application. These are in
274 * the application's coordinate space (without compatibility scale applied).
275 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800276 int mRequestedWidth;
277 int mRequestedHeight;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700278 private int mLastRequestedWidth;
279 private int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700280
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800281 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800282 boolean mHaveFrame;
283 boolean mObscured;
284 boolean mTurnOnScreen;
285
286 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700287
Andrii Kulian9d91ca62016-09-29 22:28:09 -0700288 /**
289 * Used to store last reported to client configuration and check if we have newer available.
290 * We'll send configuration to client only if it is different from the last applied one and
291 * client won't perform unnecessary updates.
292 */
Bryce Lee2b17afd2017-09-21 10:38:20 -0700293 private final MergedConfiguration mLastReportedConfiguration = new MergedConfiguration();
Craig Mautnera2c77052012-03-26 12:14:43 -0700294
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700295 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700296 * Actual position of the surface shown on-screen (may be modified by animation). These are
297 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700298 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700299 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800300
301 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700302 * Insets that determine the actually visible area. These are in the application's
303 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800304 */
305 final Rect mVisibleInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700306 private final Rect mLastVisibleInsets = new Rect();
307 private boolean mVisibleInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800308
309 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700310 * Insets that are covered by system windows (such as the status bar) and
311 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700312 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800313 */
314 final Rect mContentInsets = new Rect();
315 final Rect mLastContentInsets = new Rect();
Robert Carr18f622f2017-05-08 11:20:43 -0700316
317 /**
318 * The last content insets returned to the client in relayout. We use
319 * these in the bounds animation to ensure we only observe inset changes
320 * at the same time that a client resizes it's surface so that we may use
321 * the geometryAppliesWithResize synchronization mechanism to keep
322 * the contents in place.
323 */
324 final Rect mLastRelayoutContentInsets = new Rect();
325
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700326 private boolean mContentInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800327
328 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800329 * Insets that determine the area covered by the display overscan region. These are in the
330 * application's coordinate space (without compatibility scale applied).
331 */
332 final Rect mOverscanInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700333 private final Rect mLastOverscanInsets = new Rect();
334 private boolean mOverscanInsetsChanged;
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800335
336 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700337 * Insets that determine the area covered by the stable system windows. These are in the
338 * application's coordinate space (without compatibility scale applied).
339 */
340 final Rect mStableInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700341 private final Rect mLastStableInsets = new Rect();
342 private boolean mStableInsetsChanged;
Adrian Roosfa104232014-06-20 16:10:14 -0700343
344 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700345 * Outsets determine the area outside of the surface where we want to pretend that it's possible
346 * to draw anyway.
347 */
348 final Rect mOutsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700349 private final Rect mLastOutsets = new Rect();
350 private boolean mOutsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700351
Adrian Roos5c6b6222017-11-07 17:36:10 +0100352 /** Part of the display that has been cut away. See {@link DisplayCutout}. */
353 DisplayCutout mDisplayCutout = DisplayCutout.NO_CUTOUT;
354 private DisplayCutout mLastDisplayCutout = DisplayCutout.NO_CUTOUT;
355 private boolean mDisplayCutoutChanged;
356
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700357 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800358 * Set to true if we are waiting for this window to receive its
359 * given internal insets before laying out other windows based on it.
360 */
361 boolean mGivenInsetsPending;
362
363 /**
364 * These are the content insets that were given during layout for
365 * this window, to be applied to windows behind it.
366 */
367 final Rect mGivenContentInsets = new Rect();
368
369 /**
370 * These are the visible insets that were given during layout for
371 * this window, to be applied to windows behind it.
372 */
373 final Rect mGivenVisibleInsets = new Rect();
374
375 /**
376 * This is the given touchable area relative to the window frame, or null if none.
377 */
378 final Region mGivenTouchableRegion = new Region();
379
380 /**
381 * Flag indicating whether the touchable region should be adjusted by
382 * the visible insets; if false the area outside the visible insets is
383 * NOT touchable, so we must use those to adjust the frame during hit
384 * tests.
385 */
386 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
387
388 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400389 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700390 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800391 float mHScale=1, mVScale=1;
392 float mLastHScale=1, mLastVScale=1;
393 final Matrix mTmpMatrix = new Matrix();
394
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700395 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800396 final Rect mFrame = new Rect();
397 final Rect mLastFrame = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700398 private boolean mFrameSizeChanged = false;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700399 // Frame that is scaled to the application's coordinate space when in
400 // screen size compatibility mode.
401 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800402
403 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700404
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700405 private final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700406
Wale Ogunwale94596652015-02-06 19:27:34 -0800407 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
408 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700409 final Rect mDisplayFrame = new Rect();
410
411 // The region of the display frame that the display type supports displaying content on. This
412 // is mostly a special case for TV where some displays don’t have the entire display usable.
413 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
414 // window display contents to extend into the overscan region.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700415 private final Rect mOverscanFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700416
417 // The display frame minus the stable insets. This value is always constant regardless of if
418 // the status bar or navigation bar is visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700419 private final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800420
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700421 // The area not occupied by the status and navigation bars. So, if both status and navigation
422 // bars are visible, the decor frame is equal to the stable frame.
423 final Rect mDecorFrame = new Rect();
424
425 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
426 // minus the area occupied by the IME if the IME is present.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700427 private final Rect mContentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700428
429 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
430 // displays hint text.
431 final Rect mVisibleFrame = new Rect();
432
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700433 // Frame that includes dead area outside of the surface but where we want to pretend that it's
434 // possible to draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700435 private final Rect mOutsetFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700436
Jorim Jaggidc249c42015-12-15 14:57:31 -0800437 /**
438 * Usually empty. Set to the task's tempInsetFrame. See
439 *{@link android.app.IActivityManager#resizeDockedStack}.
440 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700441 private final Rect mInsetFrame = new Rect();
Jorim Jaggidc249c42015-12-15 14:57:31 -0800442
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800443 boolean mContentChanged;
444
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800445 // If a window showing a wallpaper: the requested offset for the
446 // wallpaper; if a wallpaper window: the currently applied offset.
447 float mWallpaperX = -1;
448 float mWallpaperY = -1;
449
450 // If a window showing a wallpaper: what fraction of the offset
451 // range corresponds to a full virtual screen.
452 float mWallpaperXStep = -1;
453 float mWallpaperYStep = -1;
454
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700455 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
456 // to its window; if a wallpaper window: not used.
457 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
458 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
459
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800460 // Wallpaper windows: pixels offset based on above variables.
461 int mXOffset;
462 int mYOffset;
463
Craig Mautner2268e7e2012-12-13 15:40:00 -0800464 /**
465 * This is set after IWindowSession.relayout() has been called at
466 * least once for the window. It allows us to detect the situation
467 * where we don't yet have a surface, but should have one soon, so
468 * we can give the window focus before waiting for the relayout.
469 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800470 boolean mRelayoutCalled;
471
Robert Carrfed10072016-05-26 11:48:49 -0700472 boolean mInRelayout;
473
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800474 /**
475 * If the application has called relayout() with changes that can
476 * impact its window's size, we need to perform a layout pass on it
477 * even if it is not currently visible for layout. This is set
478 * when in that case until the layout is done.
479 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800480 boolean mLayoutNeeded;
481
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800482 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800483 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800484
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800485 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800486 boolean mDestroying;
487
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800488 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800489 boolean mRemoveOnExit;
490
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800491 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800492 * Whether the app died while it was visible, if true we might need
493 * to continue to show it until it's restarted.
494 */
495 boolean mAppDied;
496
497 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800498 * Set when the orientation is changing and this window has not yet
499 * been updated for the new orientation.
500 */
Bryce Lee8c3cf382017-07-06 19:47:10 -0700501 private boolean mOrientationChanging;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800502
Dianne Hackborna57c6952013-03-29 14:46:40 -0700503 /**
Robert Carr9c1c3a02017-08-08 12:59:01 -0700504 * Sometimes in addition to the mOrientationChanging
505 * flag we report that the orientation is changing
506 * due to a mismatch in current and reported configuration.
507 *
508 * In the case of timeout we still need to make sure we
509 * leave the orientation changing state though, so we
510 * use this as a special time out escape hatch.
511 */
512 private boolean mOrientationChangeTimedOut;
513
514 /**
Robert Carr237028a2016-07-26 10:39:45 -0700515 * The orientation during the last visible call to relayout. If our
516 * current orientation is different, the window can't be ready
517 * to be shown.
518 */
519 int mLastVisibleLayoutRotation = -1;
520
521 /**
Andrii Kulianb2e37802017-01-11 00:36:44 -0800522 * Set when we need to report the orientation change to client to trigger a relayout.
523 */
524 boolean mReportOrientationChanged;
525
526 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700527 * How long we last kept the screen frozen.
528 */
529 int mLastFreezeDuration;
530
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800531 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800532 boolean mRemoved;
533
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800534 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800535 * It is save to remove the window and destroy the surface because the client requested removal
536 * or some other higher level component said so (e.g. activity manager).
537 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800538 */
Svetoslav Ganov200adfb2016-10-18 13:29:27 -0700539 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800540
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800541 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700542 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800543 InputChannel mInputChannel;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700544 private InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800545
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800546 // Used to improve performance of toString()
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700547 private String mStringNameCache;
548 private CharSequence mLastTitle;
549 private boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800550
Craig Mautnera2c77052012-03-26 12:14:43 -0700551 final WindowStateAnimator mWinAnimator;
552
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700553 boolean mHasSurface = false;
554
Craig Mautner88400d32012-09-30 12:35:45 -0700555 /** When true this window can be displayed on screens owther than mOwnerUid's */
556 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700557
Chong Zhang92147042016-05-09 12:47:11 -0700558 // Whether the window was visible when we set the app to invisible last time. WM uses
559 // this as a hint to restore the surface (if available) for early animation next time
560 // the app is brought visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700561 private boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800562
Robert Carra1eb4392015-12-10 12:43:51 -0800563 // This window will be replaced due to relaunch. This allows window manager
564 // to differentiate between simple removal of a window and replacement. In the latter case it
565 // will preserve the old window until the new one is drawn.
566 boolean mWillReplaceWindow = false;
567 // If true, the replaced window was already requested to be removed.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700568 private boolean mReplacingRemoveRequested = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800569 // Whether the replacement of the window should trigger app transition animation.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700570 private boolean mAnimateReplacingWindow = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800571 // If not null, the window that will be used to replace the old one. This is being set when
572 // the window is added and unset when this window reports its first draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700573 private WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700574 // For the new window in the replacement transition, if we have
575 // requested to replace without animation, then we should
576 // make sure we also don't apply an enter animation for
577 // the new window.
578 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800579 // Whether this window is being moved via the resize API
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700580 private boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800581
Jeff Brownc2932a12014-11-20 18:04:05 -0800582 /**
583 * Wake lock for drawing.
584 * Even though it's slightly more expensive to do so, we will use a separate wake lock
585 * for each app that is requesting to draw while dozing so that we can accurately track
586 * who is preventing the system from suspending.
587 * This lock is only acquired on first use.
588 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700589 private PowerManager.WakeLock mDrawLock;
Jeff Brownc2932a12014-11-20 18:04:05 -0800590
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700591 final private Rect mTmpRect = new Rect();
592
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800593 /**
594 * Whether the window was resized by us while it was gone for layout.
595 */
596 boolean mResizedWhileGone = false;
597
Andrii Kulianeb1d3222016-05-16 15:17:55 -0700598 /** @see #isResizedWhileNotDragResizing(). */
599 private boolean mResizedWhileNotDragResizing;
600
601 /** @see #isResizedWhileNotDragResizingReported(). */
602 private boolean mResizedWhileNotDragResizingReported;
Jorim Jaggif3df0aa2016-04-06 15:56:33 -0700603
Robert Carr6da3cc02016-06-16 15:17:07 -0700604 /**
605 * During seamless rotation we have two phases, first the old window contents
606 * are rotated to look as if they didn't move in the new coordinate system. Then we
607 * have to freeze updates to this layer (to preserve the transformation) until
608 * the resize actually occurs. This is true from when the transformation is set
609 * and false until the transaction to resize is sent.
610 */
611 boolean mSeamlesslyRotated = false;
612
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700613 /**
Robert Carrc91d1c32017-02-15 19:37:46 -0800614 * Surface insets from the previous call to relayout(), used to track
615 * if we are changing the Surface insets.
616 */
617 final Rect mLastSurfaceInsets = new Rect();
618
619 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700620 * A flag set by the {@link WindowState} parent to indicate that the parent has examined this
621 * {@link WindowState} in its overall drawing context. This book-keeping allows the parent to
622 * make sure all children have been considered.
623 */
624 private boolean mDrawnStateEvaluated;
625
Jorim Jaggia5e10572017-11-15 14:36:26 +0100626 private final Point mSurfacePosition = new Point();
627
Bryce Leed390deb2017-06-22 13:14:28 -0700628 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700629 * 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 -0700630 * of z-order and 1 otherwise.
631 */
Griff Hazen51d00d82016-11-22 15:39:24 -0800632 private static final Comparator<WindowState> sWindowSubLayerComparator =
633 new Comparator<WindowState>() {
634 @Override
635 public int compare(WindowState w1, WindowState w2) {
636 final int layer1 = w1.mSubLayer;
637 final int layer2 = w2.mSubLayer;
638 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
639 // We insert the child window into the list ordered by
640 // the sub-layer. For same sub-layers, the negative one
641 // should go below others; the positive one should go
642 // above others.
643 return -1;
644 }
645 return 1;
646 };
647 };
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700648
Robert Carrf59b8dd2017-10-02 18:58:36 -0700649 /**
650 * Indicates whether we have requested a Dim (in the sense of {@link Dimmer}) from our host
651 * container.
652 */
653 private boolean mIsDimming = false;
654
655 private static final float DEFAULT_DIM_AMOUNT_DEAD_WINDOW = 0.5f;
656
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800657 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700658 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800659 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100660 super(service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800661 mSession = s;
662 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800663 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800664 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700665 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700666 mOwnerUid = ownerId;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800667 mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200668 mWindowId = new WindowId(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800669 mAttrs.copyFrom(a);
670 mViewVisibility = viewVisibility;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700671 mPolicy = mService.mPolicy;
672 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800673 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700674 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700675 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700676 if (localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700677 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700678 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800679 try {
680 c.asBinder().linkToDeath(deathRecipient, 0);
681 } catch (RemoteException e) {
682 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700683 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800684 mLayoutAttached = false;
685 mIsImWindow = false;
686 mIsWallpaper = false;
687 mIsFloatingLayer = false;
688 mBaseLayer = 0;
689 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700690 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700691 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800692 return;
693 }
694 mDeathRecipient = deathRecipient;
695
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700696 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800697 // The multiplier here is to reserve space for multiple
698 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800699 mBaseLayer = mPolicy.getWindowLayerLw(parentWindow)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700700 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800701 mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700702 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900703
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700704 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow);
705 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900706
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800707 mLayoutAttached = mAttrs.type !=
708 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700709 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
710 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
711 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800712 } else {
713 // The multiplier here is to reserve space for multiple
714 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800715 mBaseLayer = mPolicy.getWindowLayerLw(this)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700716 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800717 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700718 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800719 mLayoutAttached = false;
720 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
721 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
722 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800723 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700724 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800725
Wale Ogunwale72919d22016-12-08 18:58:50 -0800726 if (mAppToken != null && mAppToken.mShowForAllUsers) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700727 // Windows for apps that can show for all users should also show when the device is
728 // locked.
729 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
Craig Mautner19ab8282014-05-07 10:35:34 -0700730 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800731
Craig Mautner322e4032012-07-13 13:35:20 -0700732 mWinAnimator = new WindowStateAnimator(this);
733 mWinAnimator.mAlpha = a.alpha;
734
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800735 mRequestedWidth = 0;
736 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700737 mLastRequestedWidth = 0;
738 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800739 mXOffset = 0;
740 mYOffset = 0;
741 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800742 mInputWindowHandle = new InputWindowHandle(
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800743 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this, c,
744 getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800745 }
746
747 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700748 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800749 mSession.windowAddedLocked(mAttrs.packageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800750 }
751
Bryce Leed390deb2017-06-22 13:14:28 -0700752 /**
753 * Returns whether this {@link WindowState} has been considered for drawing by its parent.
754 */
Bryce Lee6311c4b2017-07-06 14:09:29 -0700755 boolean getDrawnStateEvaluated() {
Bryce Leed390deb2017-06-22 13:14:28 -0700756 return mDrawnStateEvaluated;
757 }
758
759 /**
760 * Sets whether this {@link WindowState} has been considered for drawing by its parent. Should
761 * be cleared when detached from parent.
762 */
763 void setDrawnStateEvaluated(boolean evaluated) {
764 mDrawnStateEvaluated = evaluated;
765 }
766
767 @Override
768 void onParentSet() {
769 super.onParentSet();
770 setDrawnStateEvaluated(false /*evaluated*/);
771 }
772
Craig Mautnera2c77052012-03-26 12:14:43 -0700773 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800774 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800775 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800776 }
777
778 @Override
779 public String getOwningPackage() {
780 return mAttrs.packageName;
781 }
782
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800783 @Override
784 public boolean canAddInternalSystemWindow() {
785 return mOwnerCanAddInternalSystemWindow;
786 }
787
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200788 @Override
789 public boolean canAcquireSleepToken() {
790 return mSession.mCanAcquireSleepToken;
791 }
792
Jorim Jaggif5834272016-04-04 20:25:41 -0700793 /**
794 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
795 * from {@param frame}. In other words, it applies the insets that would result if
796 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700797 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
798 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700799 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700800 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
801 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
802 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
803 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
804 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700805 frame.inset(left, top, right, bottom);
806 }
807
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800808 @Override
Robert Carr43521762016-10-28 13:15:04 -0700809 public void computeFrameLw(Rect parentFrame, Rect displayFrame, Rect overscanFrame,
810 Rect contentFrame, Rect visibleFrame, Rect decorFrame, Rect stableFrame,
Adrian Roos5c6b6222017-11-07 17:36:10 +0100811 Rect outsetFrame, DisplayCutout displayCutout) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800812 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700813 // This window is being replaced and either already got information that it's being
814 // removed or we are still waiting for some information. Because of this we don't
815 // want to apply any more changes to it, so it remains in this state until new window
816 // appears.
817 return;
818 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800819 mHaveFrame = true;
820
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700821 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700822 final boolean inFullscreenContainer = inFullscreenContainer();
Robert Carre6275582016-02-29 15:45:45 -0800823 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700824 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800825
Chong Zhangae35fef2016-03-16 15:56:55 -0700826 // If the task has temp inset bounds set, we have to make sure all its windows uses
827 // the temp inset frame. Otherwise different display frames get applied to the main
828 // window and the child window, making them misaligned.
Andrii Kulianc24f3732017-08-08 19:35:17 -0700829 if (inFullscreenContainer || isLetterboxedAppWindow()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700830 mInsetFrame.setEmpty();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700831 } else if (task != null && isInMultiWindowMode()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700832 task.getTempInsetBounds(mInsetFrame);
833 }
834
Jorim Jaggif5834272016-04-04 20:25:41 -0700835 // Denotes the actual frame used to calculate the insets and to perform the layout. When
836 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
837 // insets temporarily. By the notion of a task having a different layout frame, we can
838 // achieve that while still moving the task around.
839 final Rect layoutContainingFrame;
840 final Rect layoutDisplayFrame;
841
842 // The offset from the layout containing frame to the actual containing frame.
843 final int layoutXDiff;
844 final int layoutYDiff;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700845 if (inFullscreenContainer || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800846 // We use the parent frame as the containing frame for fullscreen and child windows
Robert Carr43521762016-10-28 13:15:04 -0700847 mContainingFrame.set(parentFrame);
848 mDisplayFrame.set(displayFrame);
849 layoutDisplayFrame = displayFrame;
850 layoutContainingFrame = parentFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700851 layoutXDiff = 0;
852 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800853 } else {
Bryce Leef3c6a472017-11-14 14:53:06 -0800854 getBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100855 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
856
857 // If the bounds are frozen, we still want to translate the window freely and only
858 // freeze the size.
859 Rect frozen = mAppToken.mFrozenBounds.peek();
860 mContainingFrame.right = mContainingFrame.left + frozen.width();
861 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
862 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800863 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700864 // IME is up and obscuring this window. Adjust the window position so it is visible.
865 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this) {
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700866 if (inFreeformWindowingMode()
Winson Chungd73e94b2017-05-31 16:25:30 -0700867 && mContainingFrame.bottom > contentFrame.bottom) {
868 // In freeform we want to move the top up directly.
869 // TODO: Investigate why this is contentFrame not parentFrame.
870 mContainingFrame.top -= mContainingFrame.bottom - contentFrame.bottom;
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700871 } else if (!inPinnedWindowingMode()
Winson Chungd73e94b2017-05-31 16:25:30 -0700872 && mContainingFrame.bottom > parentFrame.bottom) {
873 // But in docked we want to behave like fullscreen and behave as if the task
874 // were given smaller bounds for the purposes of layout. Skip adjustments for
875 // the pinned stack, they are handled separately in the PinnedStackController.
876 mContainingFrame.bottom = parentFrame.bottom;
877 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700878 }
Skuhne81c524a2015-08-12 13:34:14 -0700879
Robert Carre6275582016-02-29 15:45:45 -0800880 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700881 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
882 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800883 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700884 if (mContainingFrame.isEmpty()) {
Robert Carr43521762016-10-28 13:15:04 -0700885 mContainingFrame.set(contentFrame);
Skuhne81c524a2015-08-12 13:34:14 -0700886 }
Doris Liu06d582d2015-06-01 13:18:43 -0700887 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800888 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700889 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
890 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
891 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700892 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
Robert Carr43521762016-10-28 13:15:04 -0700893 subtractInsets(mDisplayFrame, layoutContainingFrame, displayFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700894 if (!layoutInParentFrame()) {
Robert Carr43521762016-10-28 13:15:04 -0700895 subtractInsets(mContainingFrame, layoutContainingFrame, parentFrame, mTmpRect);
896 subtractInsets(mInsetFrame, layoutContainingFrame, parentFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700897 }
Robert Carr43521762016-10-28 13:15:04 -0700898 layoutDisplayFrame = displayFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700899 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700900 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800901
Craig Mautner967212c2013-04-13 21:10:58 -0700902 final int pw = mContainingFrame.width();
903 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800904
Robert Carr43521762016-10-28 13:15:04 -0700905 if (!mParentFrame.equals(parentFrame)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800906 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Robert Carr43521762016-10-28 13:15:04 -0700907 // + " to " + parentFrame);
908 mParentFrame.set(parentFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800909 mContentChanged = true;
910 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700911 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
912 mLastRequestedWidth = mRequestedWidth;
913 mLastRequestedHeight = mRequestedHeight;
914 mContentChanged = true;
915 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800916
Robert Carr43521762016-10-28 13:15:04 -0700917 mOverscanFrame.set(overscanFrame);
918 mContentFrame.set(contentFrame);
919 mVisibleFrame.set(visibleFrame);
920 mDecorFrame.set(decorFrame);
921 mStableFrame.set(stableFrame);
922 final boolean hasOutsets = outsetFrame != null;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700923 if (hasOutsets) {
Robert Carr43521762016-10-28 13:15:04 -0700924 mOutsetFrame.set(outsetFrame);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700925 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800926
Craig Mautnereda67292013-04-28 13:50:14 -0700927 final int fw = mFrame.width();
928 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800929
Jorim Jaggif5834272016-04-04 20:25:41 -0700930 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
931
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700932 // Calculate the outsets before the content frame gets shrinked to the window frame.
933 if (hasOutsets) {
934 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
935 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
936 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
937 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
938 } else {
939 mOutsets.set(0, 0, 0, 0);
940 }
941
Craig Mautnera248eee2013-05-07 11:41:27 -0700942 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800943 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -0800944 if (windowsAreFloating && !mFrame.isEmpty()) {
Robert Carre65a1c42017-02-28 16:52:59 -0800945 // For pinned workspace the frame isn't limited in any particular
946 // way since SystemUI controls the bounds. For freeform however
947 // we want to keep things inside the content frame.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700948 final Rect limitFrame = task.inPinnedWindowingMode() ? mFrame : mContentFrame;
Skuhne81c524a2015-08-12 13:34:14 -0700949 // Keep the frame out of the blocked system area, limit it in size to the content area
950 // and make sure that there is always a minimum visible so that the user can drag it
951 // into a usable area..
Robert Carre65a1c42017-02-28 16:52:59 -0800952 final int height = Math.min(mFrame.height(), limitFrame.height());
953 final int width = Math.min(limitFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700954 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +0900955 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
956 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
957 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
958 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Robert Carre65a1c42017-02-28 16:52:59 -0800959 final int top = Math.max(limitFrame.top,
960 Math.min(mFrame.top, limitFrame.bottom - minVisibleHeight));
961 final int left = Math.max(limitFrame.left + minVisibleWidth - width,
962 Math.min(mFrame.left, limitFrame.right - minVisibleWidth));
Skuhne81c524a2015-08-12 13:34:14 -0700963 mFrame.set(left, top, left + width, top + height);
964 mContentFrame.set(mFrame);
965 mVisibleFrame.set(mContentFrame);
966 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700967 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700968 dc.getDockedDividerController().positionDockedStackedDivider(mFrame);
Jorim Jaggi192086e2016-03-11 17:17:03 +0100969 mContentFrame.set(mFrame);
970 if (!mFrame.equals(mLastFrame)) {
971 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800972 }
Skuhne81c524a2015-08-12 13:34:14 -0700973 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -0700974 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
975 Math.max(mContentFrame.top, mFrame.top),
976 Math.min(mContentFrame.right, mFrame.right),
977 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800978
Jorim Jaggi656f6502016-04-11 21:08:17 -0700979 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
980 Math.max(mVisibleFrame.top, mFrame.top),
981 Math.min(mVisibleFrame.right, mFrame.right),
982 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800983
Jorim Jaggi656f6502016-04-11 21:08:17 -0700984 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
985 Math.max(mStableFrame.top, mFrame.top),
986 Math.min(mStableFrame.right, mFrame.right),
987 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700988 }
Adrian Roosfa104232014-06-20 16:10:14 -0700989
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700990 if (inFullscreenContainer && !windowsAreFloating) {
Jorim Jaggi899327f2016-02-25 20:44:18 -0500991 // Windows that are not fullscreen can be positioned outside of the display frame,
992 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -0700993 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
994 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
995 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
996 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800997 }
Craig Mautnereda67292013-04-28 13:50:14 -0700998
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100999 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001000 // For the docked divider, we calculate the stable insets like a full-screen window
1001 // so it can use it to calculate the snap positions.
1002 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
1003 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
1004 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
1005 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -08001006
1007 // The divider doesn't care about insets in any case, so set it to empty so we don't
1008 // trigger a relayout when moving it.
1009 mContentInsets.setEmpty();
1010 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001011 } else {
Bryce Leef3c6a472017-11-14 14:53:06 -08001012 getDisplayContent().getBounds(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -07001013 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
1014 // non-fullscreen mode.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07001015 boolean overrideRightInset = !windowsAreFloating && !inFullscreenContainer
1016 && mFrame.right > mTmpRect.right;
1017 boolean overrideBottomInset = !windowsAreFloating && !inFullscreenContainer
1018 && mFrame.bottom > mTmpRect.bottom;
Jorim Jaggi656f6502016-04-11 21:08:17 -07001019 mContentInsets.set(mContentFrame.left - mFrame.left,
1020 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -07001021 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -07001022 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -07001023 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -07001024 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -08001025
Jorim Jaggi656f6502016-04-11 21:08:17 -07001026 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
1027 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -07001028 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -07001029 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -07001030 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -07001031 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -08001032
Jorim Jaggi656f6502016-04-11 21:08:17 -07001033 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
1034 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -07001035 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -07001036 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -07001037 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -07001038 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001039 }
Adrian Roosfa104232014-06-20 16:10:14 -07001040
Jorim Jaggi656f6502016-04-11 21:08:17 -07001041 // Offset the actual frame by the amount layout frame is off.
1042 mFrame.offset(-layoutXDiff, -layoutYDiff);
1043 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -07001044 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
1045 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
1046 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
1047
Adrian Roos5c6b6222017-11-07 17:36:10 +01001048 // TODO(roosa): Figure out what frame exactly this needs to be calculated with.
1049 mDisplayCutout = displayCutout.calculateRelativeTo(mFrame);
1050
1051
Craig Mautnereda67292013-04-28 13:50:14 -07001052 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001053 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001054 // If there is a size compatibility scale being applied to the
1055 // window, we need to apply this to its insets so that they are
1056 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -07001057 mOverscanInsets.scale(mInvGlobalScale);
1058 mContentInsets.scale(mInvGlobalScale);
1059 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -07001060 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001061 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001062
1063 // Also the scaled frame that we report to the app needs to be
1064 // adjusted to be in its coordinate space.
1065 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001066 }
1067
Craig Mautnereda67292013-04-28 13:50:14 -07001068 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001069 final DisplayContent displayContent = getDisplayContent();
1070 if (displayContent != null) {
1071 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwale0303c572016-10-20 10:16:29 -07001072 getDisplayContent().mWallpaperController.updateWallpaperOffset(
Wale Ogunwalee8069dc2015-08-18 09:52:01 -07001073 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001074 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001075 }
1076
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001077 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001078 "Resolving (mRequestedWidth="
1079 + mRequestedWidth + ", mRequestedheight="
1080 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
1081 + "): frame=" + mFrame.toShortString()
1082 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07001083 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -07001084 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001085 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001086 }
1087
Bryce Leef3c6a472017-11-14 14:53:06 -08001088 // TODO: Look into whether this override is still necessary.
1089 @Override
1090 public Rect getBounds() {
1091 if (isInMultiWindowMode()) {
1092 return getTask().getBounds();
1093 } else if (mAppToken != null){
1094 return mAppToken.getBounds();
1095 } else {
1096 return super.getBounds();
1097 }
1098 }
1099
Craig Mautnera2c77052012-03-26 12:14:43 -07001100 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001101 public Rect getFrameLw() {
1102 return mFrame;
1103 }
1104
Craig Mautnera2c77052012-03-26 12:14:43 -07001105 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001106 public Point getShownPositionLw() {
1107 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001108 }
1109
Craig Mautnera2c77052012-03-26 12:14:43 -07001110 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001111 public Rect getDisplayFrameLw() {
1112 return mDisplayFrame;
1113 }
1114
Craig Mautnera2c77052012-03-26 12:14:43 -07001115 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001116 public Rect getOverscanFrameLw() {
1117 return mOverscanFrame;
1118 }
1119
1120 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001121 public Rect getContentFrameLw() {
1122 return mContentFrame;
1123 }
1124
Craig Mautnera2c77052012-03-26 12:14:43 -07001125 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001126 public Rect getVisibleFrameLw() {
1127 return mVisibleFrame;
1128 }
1129
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001130 Rect getStableFrameLw() {
1131 return mStableFrame;
1132 }
1133
Craig Mautnera2c77052012-03-26 12:14:43 -07001134 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001135 public boolean getGivenInsetsPendingLw() {
1136 return mGivenInsetsPending;
1137 }
1138
Craig Mautnera2c77052012-03-26 12:14:43 -07001139 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001140 public Rect getGivenContentInsetsLw() {
1141 return mGivenContentInsets;
1142 }
1143
Craig Mautnera2c77052012-03-26 12:14:43 -07001144 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001145 public Rect getGivenVisibleInsetsLw() {
1146 return mGivenVisibleInsets;
1147 }
1148
Craig Mautnera2c77052012-03-26 12:14:43 -07001149 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001150 public WindowManager.LayoutParams getAttrs() {
1151 return mAttrs;
1152 }
1153
Craig Mautner812d2ca2012-09-27 15:35:34 -07001154 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001155 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001156 return getDisplayContent().getNeedsMenu(this, bottom);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001157 }
1158
Craig Mautner19d59bc2012-09-04 11:15:56 -07001159 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001160 public int getSystemUiVisibility() {
1161 return mSystemUiVisibility;
1162 }
1163
Craig Mautner19d59bc2012-09-04 11:15:56 -07001164 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001165 public int getSurfaceLayer() {
1166 return mLayer;
1167 }
1168
Craig Mautner812d2ca2012-09-27 15:35:34 -07001169 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001170 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001171 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001172 }
1173
1174 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001175 public IApplicationToken getAppToken() {
1176 return mAppToken != null ? mAppToken.appToken : null;
1177 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001178
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001179 @Override
1180 public boolean isVoiceInteraction() {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001181 return mAppToken != null && mAppToken.mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001182 }
1183
Robert Carr31aa98b2016-07-20 15:29:03 -07001184 boolean setReportResizeHints() {
Craig Mautner4c5eb222013-11-18 12:59:05 -08001185 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1186 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1187 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001188 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001189 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
Robert Carr31aa98b2016-07-20 15:29:03 -07001190 mFrameSizeChanged |= (mLastFrame.width() != mFrame.width()) ||
1191 (mLastFrame.height() != mFrame.height());
Adrian Roos5c6b6222017-11-07 17:36:10 +01001192 mDisplayCutoutChanged |= !mLastDisplayCutout.equals(mDisplayCutout);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001193 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
Adrian Roos5c6b6222017-11-07 17:36:10 +01001194 || mOutsetsChanged || mFrameSizeChanged || mDisplayCutoutChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001195 }
1196
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001197 /**
1198 * Adds the window to the resizing list if any of the parameters we use to track the window
1199 * dimensions or insets have changed.
1200 */
1201 void updateResizingWindowIfNeeded() {
1202 final WindowStateAnimator winAnimator = mWinAnimator;
1203 if (!mHasSurface || mService.mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
1204 return;
1205 }
1206
1207 final Task task = getTask();
1208 // In the case of stack bound animations, the window frames will update (unlike other
1209 // animations which just modify various transformation properties). We don't want to
1210 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1211 // the frame may not correspond to the surface size or the onscreen area at various
1212 // phases in the animation, and the client will become sad and confused.
Winson Chung40a5f932017-04-13 16:39:36 -07001213 if (task != null && task.mStack.isAnimatingBounds()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001214 return;
1215 }
1216
1217 setReportResizeHints();
1218 boolean configChanged = isConfigChanged();
1219 if (DEBUG_CONFIGURATION && configChanged) {
1220 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1221 }
1222
1223 final boolean dragResizingChanged = isDragResizeChanged()
1224 && !isDragResizingChangeReported();
1225
1226 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
1227 + " dragResizingChanged=" + dragResizingChanged + " last=" + mLastFrame
1228 + " frame=" + mFrame);
1229
1230 // We update mLastFrame always rather than in the conditional with the last inset
1231 // variables, because mFrameSizeChanged only tracks the width and height changing.
1232 mLastFrame.set(mFrame);
1233
1234 if (mContentInsetsChanged
1235 || mVisibleInsetsChanged
1236 || winAnimator.mSurfaceResized
1237 || mOutsetsChanged
1238 || mFrameSizeChanged
Adrian Roos5c6b6222017-11-07 17:36:10 +01001239 || mDisplayCutoutChanged
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001240 || configChanged
1241 || dragResizingChanged
Andrii Kulianb2e37802017-01-11 00:36:44 -08001242 || !isResizedWhileNotDragResizingReported()
1243 || mReportOrientationChanged) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001244 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1245 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
1246 + " contentInsetsChanged=" + mContentInsetsChanged
1247 + " " + mContentInsets.toShortString()
1248 + " visibleInsetsChanged=" + mVisibleInsetsChanged
1249 + " " + mVisibleInsets.toShortString()
1250 + " stableInsetsChanged=" + mStableInsetsChanged
1251 + " " + mStableInsets.toShortString()
1252 + " outsetsChanged=" + mOutsetsChanged
1253 + " " + mOutsets.toShortString()
1254 + " surfaceResized=" + winAnimator.mSurfaceResized
1255 + " configChanged=" + configChanged
1256 + " dragResizingChanged=" + dragResizingChanged
1257 + " resizedWhileNotDragResizingReported="
Andrii Kulianb2e37802017-01-11 00:36:44 -08001258 + isResizedWhileNotDragResizingReported()
Adrian Roos5c6b6222017-11-07 17:36:10 +01001259 + " reportOrientationChanged=" + mReportOrientationChanged
1260 + " displayCutoutChanged=" + mDisplayCutoutChanged);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001261 }
1262
1263 // If it's a dead window left on screen, and the configuration changed, there is nothing
1264 // we can do about it. Remove the window now.
1265 if (mAppToken != null && mAppDied) {
1266 mAppToken.removeDeadWindows();
1267 return;
1268 }
1269
Jorim Jaggidc9385a2017-05-13 02:00:31 +02001270 updateLastInsetValues();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001271 mService.makeWindowFreezingScreenIfNeededLocked(this);
1272
1273 // If the orientation is changing, or we're starting or ending a drag resizing action,
1274 // then we need to hold off on unfreezing the display until this window has been
1275 // redrawn; to do that, we need to go through the process of getting informed by the
1276 // application when it has finished drawing.
Bryce Lee8c3cf382017-07-06 19:47:10 -07001277 if (getOrientationChanging() || dragResizingChanged
1278 || isResizedWhileNotDragResizing()) {
Robert Carre13b58e2017-08-31 14:50:44 -07001279 if (DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001280 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1281 + ", mDrawState=DRAW_PENDING in " + this
1282 + ", surfaceController " + winAnimator.mSurfaceController);
1283 }
1284 winAnimator.mDrawState = DRAW_PENDING;
1285 if (mAppToken != null) {
1286 mAppToken.clearAllDrawn();
1287 }
1288 }
1289 if (!mService.mResizingWindows.contains(this)) {
1290 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
1291 mService.mResizingWindows.add(this);
1292 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07001293 } else if (getOrientationChanging()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001294 if (isDrawnLw()) {
1295 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1296 + this + ", surfaceController " + winAnimator.mSurfaceController);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001297 setOrientationChanging(false);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001298 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1299 - mService.mDisplayFreezeTime);
1300 }
1301 }
1302 }
1303
Bryce Lee8c3cf382017-07-06 19:47:10 -07001304 boolean getOrientationChanging() {
1305 // In addition to the local state flag, we must also consider the difference in the last
1306 // reported configuration vs. the current state. If the client code has not been informed of
1307 // the change, logic dependent on having finished processing the orientation, such as
1308 // unfreezing, could be improperly triggered.
1309 // TODO(b/62846907): Checking against {@link mLastReportedConfiguration} could be flaky as
1310 // this is not necessarily what the client has processed yet. Find a
1311 // better indicator consistent with the client.
Robert Carr926643f2017-08-02 12:01:12 -07001312 return (mOrientationChanging || (isVisible()
Bryce Lee2b17afd2017-09-21 10:38:20 -07001313 && getConfiguration().orientation != getLastReportedConfiguration().orientation))
Robert Carr9c1c3a02017-08-08 12:59:01 -07001314 && !mSeamlesslyRotated
1315 && !mOrientationChangeTimedOut;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001316 }
1317
1318 void setOrientationChanging(boolean changing) {
1319 mOrientationChanging = changing;
Robert Carr9c1c3a02017-08-08 12:59:01 -07001320 mOrientationChangeTimedOut = false;
1321 }
1322
1323 void orientationChangeTimedOut() {
1324 mOrientationChangeTimedOut = true;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001325 }
1326
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001327 DisplayContent getDisplayContent() {
1328 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001329 }
1330
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001331 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001332 final DisplayContent displayContent = getDisplayContent();
1333 return displayContent != null ? displayContent.getDisplayInfo() : null;
1334 }
1335
Jorim Jaggife762342016-10-13 14:33:27 +02001336 @Override
1337 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001338 final DisplayContent displayContent = getDisplayContent();
1339 if (displayContent == null) {
1340 return -1;
1341 }
1342 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001343 }
1344
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001345 Task getTask() {
Bryce Lee6d410262017-02-28 15:30:17 -08001346 return mAppToken != null ? mAppToken.getTask() : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001347 }
1348
1349 TaskStack getStack() {
1350 Task task = getTask();
1351 if (task != null) {
1352 if (task.mStack != null) {
1353 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001354 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001355 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001356 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1357 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001358 final DisplayContent dc = getDisplayContent();
1359 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001360 }
1361
Skuhnef932e562015-08-20 12:07:30 -07001362 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001363 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001364 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001365 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001366 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001367 final Task task = getTask();
1368 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001369 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001370 mTmpRect.setEmpty();
1371 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001372 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001373 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001374 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001375 } else {
1376 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001377 }
1378 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001379
Chong Zhang9184ec62015-09-24 12:32:21 -07001380 bounds.set(mVisibleFrame);
1381 if (intersectWithStackBounds) {
1382 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001383 }
1384
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001385 if (bounds.isEmpty()) {
1386 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001387 if (intersectWithStackBounds) {
1388 bounds.intersect(mTmpRect);
1389 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001390 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001391 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001392 }
1393
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001394 public long getInputDispatchingTimeoutNanos() {
1395 return mAppToken != null
Wale Ogunwale72919d22016-12-08 18:58:50 -08001396 ? mAppToken.mInputDispatchingTimeoutNanos
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001397 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1398 }
1399
Craig Mautnere8552142012-11-07 13:55:47 -08001400 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001401 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001402 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001403 }
1404
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001405 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1406 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1407 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1408 if (dtdx < -.000001f || dtdx > .000001f) return false;
1409 if (dsdy < -.000001f || dsdy > .000001f) return false;
1410 return true;
1411 }
1412
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001413 void prelayout() {
1414 if (mEnforceSizeCompat) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001415 mGlobalScale = getDisplayContent().mCompatibleScreenScale;
1416 mInvGlobalScale = 1 / mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001417 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001418 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001419 }
1420 }
1421
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001422 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001423 boolean hasContentToDisplay() {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001424 if (!mAppFreezing && isDrawnLw() && (mViewVisibility == View.VISIBLE
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001425 || (mWinAnimator.isAnimationSet() && !mService.mAppTransition.isTransitionSet()))) {
1426 return true;
1427 }
1428
Wale Ogunwale44f21802016-09-02 12:49:48 -07001429 return super.hasContentToDisplay();
1430 }
1431
1432 @Override
1433 boolean isVisible() {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001434 return wouldBeVisibleIfPolicyIgnored() && mPolicyVisibility;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001435 }
1436
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001437 /**
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001438 * @return True if the window would be visible if we'd ignore policy visibility, false
1439 * otherwise.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001440 */
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001441 boolean wouldBeVisibleIfPolicyIgnored() {
Jorim Jaggi43530c92017-05-18 01:53:56 +02001442 return mHasSurface && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001443 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001444 }
1445
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001446 @Override
1447 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001448 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001449 }
1450
1451 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001452 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1453 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001454 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001455 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1456 boolean isWinVisibleLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001457 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.isSelfAnimating())
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001458 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001459 }
1460
1461 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001462 * The same as isVisible(), but follows the current hidden state of the associated app token,
1463 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001464 */
1465 boolean isVisibleNow() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001466 return (!mToken.isHidden() || mAttrs.type == TYPE_APPLICATION_STARTING)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001467 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001468 }
1469
1470 /**
1471 * Can this window possibly be a drag/drop target? The test here is
1472 * a combination of the above "visible now" with the check that the
1473 * Input Manager uses when discarding windows from input consideration.
1474 */
1475 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001476 return isVisibleNow() && !mRemoved
1477 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001478 }
1479
1480 /**
1481 * Same as isVisible(), but we also count it as visible between the
1482 * call to IWindowSession.add() and the first relayout().
1483 */
1484 boolean isVisibleOrAdding() {
1485 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001486 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001487 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001488 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001489 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001490 }
1491
1492 /**
1493 * Is this window currently on-screen? It is on-screen either if it
1494 * is visible or it is currently running an animation before no longer
1495 * being visible.
1496 */
1497 boolean isOnScreen() {
Jorim Jaggiaf221d12016-11-15 14:59:57 -08001498 if (!mHasSurface || mDestroying || !mPolicyVisibility) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001499 return false;
1500 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001501 final AppWindowToken atoken = mAppToken;
1502 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001503 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001504 || mWinAnimator.isAnimationSet());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001505 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01001506 return !isParentWindowHidden() || mWinAnimator.isAnimationSet();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001507 }
1508
1509 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001510 * Whether this window's drawn state might affect the drawn states of the app token.
1511 *
Chong Zhang8e4bda92016-05-04 15:08:18 -07001512 * @return true if the window should be considered while evaluating allDrawn flags.
1513 */
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001514 boolean mightAffectAllDrawn() {
1515 final boolean isAppType = mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1516 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION;
1517 return (isOnScreen() || isAppType) && !mAnimatingExit && !mDestroying;
Chong Zhang8e4bda92016-05-04 15:08:18 -07001518 }
1519
1520 /**
1521 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1522 * it must be drawn before allDrawn can become true.
1523 */
1524 boolean isInteresting() {
1525 return mAppToken != null && !mAppDied
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001526 && (!mAppToken.isFreezingScreen() || !mAppFreezing);
Chong Zhang8e4bda92016-05-04 15:08:18 -07001527 }
1528
1529 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001530 * Like isOnScreen(), but we don't return true if the window is part
1531 * of a transition that has not yet been started.
1532 */
1533 boolean isReadyForDisplay() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001534 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001535 return false;
1536 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001537 return mHasSurface && mPolicyVisibility && !mDestroying
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001538 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.isHidden())
1539 || mWinAnimator.isAnimationSet());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001540 }
1541
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001542 // TODO: Another visibility method that was added late in the release to minimize risk.
1543 @Override
1544 public boolean canAffectSystemUiFlags() {
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001545 final boolean translucent = mAttrs.alpha == 0.0f;
Jorim Jaggi72207752018-01-08 13:16:59 +01001546 if (translucent) {
1547 return false;
1548 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001549 if (mAppToken == null) {
1550 final boolean shown = mWinAnimator.getShown();
1551 final boolean exiting = mAnimatingExit || mDestroying;
Jorim Jaggi72207752018-01-08 13:16:59 +01001552 return shown && !exiting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001553 } else {
1554 return !mAppToken.isHidden();
1555 }
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001556 }
1557
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001558 /**
1559 * Like isOnScreen, but returns false if the surface hasn't yet
1560 * been drawn.
1561 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001562 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001563 public boolean isDisplayedLw() {
1564 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001565 return isDrawnLw() && mPolicyVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001566 && ((!isParentWindowHidden() && (atoken == null || !atoken.hiddenRequested))
1567 || mWinAnimator.isAnimationSet());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001568 }
1569
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001570 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001571 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001572 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001573 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001574 public boolean isAnimatingLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001575 return isAnimating();
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001576 }
1577
Craig Mautner812d2ca2012-09-27 15:35:34 -07001578 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001579 public boolean isGoneForLayoutLw() {
1580 final AppWindowToken atoken = mAppToken;
1581 return mViewVisibility == View.GONE
1582 || !mRelayoutCalled
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001583 || (atoken == null && mToken.isHidden())
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001584 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001585 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001586 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001587 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001588 }
1589
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001590 /**
1591 * Returns true if the window has a surface that it has drawn a
1592 * complete UI in to.
1593 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001594 public boolean isDrawFinishedLw() {
1595 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001596 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1597 || mWinAnimator.mDrawState == READY_TO_SHOW
1598 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001599 }
1600
1601 /**
1602 * Returns true if the window has a surface that it has drawn a
1603 * complete UI in to.
1604 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001605 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001606 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001607 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001608 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001609 }
1610
1611 /**
1612 * Return true if the window is opaque and fully drawn. This indicates
1613 * it may obscure windows behind it.
1614 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001615 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001616 // When there is keyguard, wallpaper could be placed over the secure app
1617 // window but invisible. We need to check wallpaper visibility explicitly
1618 // to determine if it's occluding apps.
1619 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1620 || (mIsWallpaper && mWallpaperVisible))
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001621 && isDrawnLw() && !mWinAnimator.isAnimationSet();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001622 }
1623
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001624 @Override
1625 void onMovedByResize() {
1626 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001627 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001628 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001629 }
1630
1631 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1632 boolean changed = false;
1633
1634 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001635 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001636 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1637 }
1638
1639 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1640 // Starting window that's exiting will be removed when the animation finishes.
1641 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1642 // to actually remove it.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001643 if (!visible && isVisibleNow() && mAppToken.isSelfAnimating()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001644 mAnimatingExit = true;
1645 mRemoveOnExit = true;
1646 mWindowRemovalAllowed = true;
1647 }
1648 return changed;
1649 }
1650
Robert Carrd5c7dd62017-03-08 10:39:30 -08001651 // Next up we will notify the client that it's visibility has changed.
1652 // We need to prevent it from destroying child surfaces until
1653 // the animation has finished.
1654 if (!visible && isVisibleNow()) {
1655 mWinAnimator.detachChildren();
1656 }
1657
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001658 if (visible != isVisibleNow()) {
1659 if (!runningAppAnimation) {
1660 final AccessibilityController accessibilityController =
1661 mService.mAccessibilityController;
1662 final int winTransit = visible ? TRANSIT_ENTER : TRANSIT_EXIT;
1663 mWinAnimator.applyAnimationLocked(winTransit, visible);
1664 //TODO (multidisplay): Magnification is supported only for the default
1665 if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
1666 accessibilityController.onWindowTransitionLocked(this, winTransit);
1667 }
1668 }
1669 changed = true;
1670 setDisplayLayoutNeeded();
1671 }
1672
1673 return changed;
1674 }
1675
1676 boolean onSetAppExiting() {
1677 final DisplayContent displayContent = getDisplayContent();
1678 boolean changed = false;
1679
1680 if (isVisibleNow()) {
1681 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
1682 //TODO (multidisplay): Magnification is supported only for the default
1683 if (mService.mAccessibilityController != null && isDefaultDisplay()) {
1684 mService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
1685 }
1686 changed = true;
1687 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001688 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001689 }
1690 }
1691
1692 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001693 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001694 changed |= c.onSetAppExiting();
1695 }
1696
1697 return changed;
1698 }
1699
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001700 @Override
1701 void onResize() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001702 final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
1703 if (mHasSurface && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001704 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001705 resizingWindows.add(this);
1706
1707 // If we are not drag resizing, force recreating of a new surface so updating
1708 // the content and positioning that surface will be in sync.
1709 //
1710 // As we use this flag as a hint to freeze surface boundary updates, we'd like to only
1711 // apply this to TYPE_BASE_APPLICATION, windows of TYPE_APPLICATION like dialogs, could
1712 // appear to not be drag resizing while they resize, but we'd still like to manipulate
1713 // their frame to update crop, etc...
1714 //
1715 // Anyway we don't need to synchronize position and content updates for these
1716 // windows since they aren't at the base layer and could be moved around anyway.
Wale Ogunwale44f036f2017-09-29 05:09:09 -07001717 if (!computeDragResizing() && mAttrs.type == TYPE_BASE_APPLICATION
1718 && !mWinAnimator.isForceScaled() && !isGoneForLayoutLw()
1719 && !getTask().inPinnedWindowingMode()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001720 setResizedWhileNotDragResizing(true);
1721 }
1722 }
1723 if (isGoneForLayoutLw()) {
1724 mResizedWhileGone = true;
1725 }
1726
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001727 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001728 }
1729
1730 void onUnfreezeBounds() {
1731 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001732 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001733 c.onUnfreezeBounds();
1734 }
1735
1736 if (!mHasSurface) {
1737 return;
1738 }
1739
1740 mLayoutNeeded = true;
1741 setDisplayLayoutNeeded();
1742 if (!mService.mResizingWindows.contains(this)) {
1743 mService.mResizingWindows.add(this);
1744 }
1745 }
1746
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001747 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001748 * If the window has moved due to its containing content frame changing, then notify the
1749 * listeners and optionally animate it. Simply checking a change of position is not enough,
1750 * because being move due to dock divider is not a trigger for animation.
1751 */
Jorim Jaggia5e10572017-11-15 14:36:26 +01001752 void handleWindowMovedIfNeeded(Transaction t) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001753 if (!hasMoved()) {
1754 return;
1755 }
1756
1757 // Frame has moved, containing content frame has also moved, and we're not currently
1758 // animating... let's do something.
1759 final int left = mFrame.left;
1760 final int top = mFrame.top;
1761 final Task task = getTask();
1762 final boolean adjustedForMinimizedDockOrIme = task != null
1763 && (task.mStack.isAdjustedForMinimizedDockedStack()
1764 || task.mStack.isAdjustedForIme());
David Stevens9440dc82017-03-16 19:00:20 -07001765 if (mToken.okToAnimate()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001766 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1767 && !isDragResizing() && !adjustedForMinimizedDockOrIme
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001768 && getWindowConfiguration().hasMovementAnimations()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001769 && !mWinAnimator.mLastHidden) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01001770 startMoveAnimation(t, left, top);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001771 }
1772
1773 //TODO (multidisplay): Accessibility supported only for the default display.
1774 if (mService.mAccessibilityController != null
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001775 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001776 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
1777 }
1778
1779 try {
1780 mClient.moved(left, top);
1781 } catch (RemoteException e) {
1782 }
1783 mMovedByResize = false;
1784 }
1785
1786 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001787 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001788 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1789 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001790 private boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001791 return mHasSurface && (mContentChanged || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001792 && !mAnimatingExit
Chong Zhangbd0d9372015-12-28 15:18:29 -08001793 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001794 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001795 }
1796
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001797 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001798 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001799 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001800 return false;
1801 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001802 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001803 }
1804
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001805 boolean fillsDisplay() {
1806 final DisplayInfo displayInfo = getDisplayInfo();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001807 return mFrame.left <= 0 && mFrame.top <= 0
1808 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001809 }
1810
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001811 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001812 boolean isConfigChanged() {
Bryce Lee2b17afd2017-09-21 10:38:20 -07001813 return !getLastReportedConfiguration().equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001814 }
1815
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001816 void onWindowReplacementTimeout() {
1817 if (mWillReplaceWindow) {
1818 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001819 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001820 // delays removal on certain conditions, which will leave the stale window in the
1821 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1822 //
1823 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001824 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001825 } else {
1826 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001827 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001828 c.onWindowReplacementTimeout();
1829 }
1830 }
1831 }
1832
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001833 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001834 void forceWindowsScaleableInTransaction(boolean force) {
1835 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1836 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1837 }
1838
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001839 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001840 }
1841
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001842 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001843 void removeImmediately() {
1844 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001845
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001846 if (mRemoved) {
1847 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001848 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1849 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001850 return;
1851 }
1852
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001853 mRemoved = true;
1854
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001855 mWillReplaceWindow = false;
1856 if (mReplacementWindow != null) {
1857 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1858 }
1859
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001860 final DisplayContent dc = getDisplayContent();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001861 if (mService.mInputMethodTarget == this) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001862 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001863 }
1864
1865 final int type = mAttrs.type;
1866 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001867 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001868 }
1869 mPolicy.removeWindowLw(this);
1870
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001871 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001872
Craig Mautner96868332012-12-04 14:29:11 -08001873 mWinAnimator.destroyDeferredSurfaceLocked();
1874 mWinAnimator.destroySurfaceLocked();
Wale Ogunwale943002b2017-02-15 19:34:01 -08001875 mSession.windowRemovedLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001876 try {
1877 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1878 } catch (RuntimeException e) {
1879 // Ignore if it has already been removed (usually because
1880 // we are doing this as part of processing a death note.)
1881 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001882
1883 mService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001884 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001885
Wale Ogunwale571771c2016-08-26 13:18:50 -07001886 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001887 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001888 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001889 removeIfPossible(false /*keepVisibleDeadWindow*/);
1890 }
1891
Wale Ogunwale571771c2016-08-26 13:18:50 -07001892 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001893 mWindowRemovalAllowed = true;
1894 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1895 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1896
1897 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1898 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1899 "Starting window removed " + this);
1900
1901 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && this == mService.mCurrentFocus)
1902 Slog.v(TAG_WM, "Remove " + this + " client="
1903 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1904 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1905 + Debug.getCallers(5));
1906
1907 final long origId = Binder.clearCallingIdentity();
1908
Peter Visontay3556a3b2017-11-01 17:23:17 +00001909 try {
1910 disposeInputChannel();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001911
Peter Visontay3556a3b2017-11-01 17:23:17 +00001912 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1913 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1914 + " mAnimatingExit=" + mAnimatingExit
1915 + " mRemoveOnExit=" + mRemoveOnExit
1916 + " mHasSurface=" + mHasSurface
1917 + " surfaceShowing=" + mWinAnimator.getShown()
1918 + " isAnimationSet=" + mWinAnimator.isAnimationSet()
1919 + " app-animation="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001920 + (mAppToken != null ? mAppToken.isSelfAnimating() : "false")
Peter Visontay3556a3b2017-11-01 17:23:17 +00001921 + " mWillReplaceWindow=" + mWillReplaceWindow
1922 + " inPendingTransaction="
1923 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
1924 + " mDisplayFrozen=" + mService.mDisplayFrozen
1925 + " callers=" + Debug.getCallers(6));
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001926
Peter Visontay3556a3b2017-11-01 17:23:17 +00001927 // Visibility of the removed window. Will be used later to update orientation later on.
1928 boolean wasVisible = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001929
Peter Visontay3556a3b2017-11-01 17:23:17 +00001930 final int displayId = getDisplayId();
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001931
Peter Visontay3556a3b2017-11-01 17:23:17 +00001932 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1933 // window until the animation is done. If the display is frozen, just remove immediately,
1934 // since the animation wouldn't be seen.
1935 if (mHasSurface && mToken.okToAnimate()) {
1936 if (mWillReplaceWindow) {
1937 // This window is going to be replaced. We need to keep it around until the new one
1938 // gets added, then we will get rid of this one.
1939 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1940 "Preserving " + this + " until the new one is " + "added");
1941 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1942 // been removed. We probably need another flag to indicate that window removal
1943 // should be deffered vs. overloading the flag that says we are playing an exit
1944 // animation.
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001945 mAnimatingExit = true;
Peter Visontay3556a3b2017-11-01 17:23:17 +00001946 mReplacingRemoveRequested = true;
1947 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001948 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001949
Peter Visontay3556a3b2017-11-01 17:23:17 +00001950 // If we are not currently running the exit animation, we need to see about starting one
1951 wasVisible = isWinVisibleLw();
1952
1953 if (keepVisibleDeadWindow) {
1954 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1955 "Not removing " + this + " because app died while it's visible");
1956
1957 mAppDied = true;
1958 setDisplayLayoutNeeded();
1959 mService.mWindowPlacerLocked.performSurfacePlacement();
1960
1961 // Set up a replacement input channel since the app is now dead.
1962 // We need to catch tapping on the dead window to restart the app.
1963 openInputChannel(null);
1964 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
1965 return;
1966 }
1967
1968 if (wasVisible) {
1969 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
1970
1971 // Try starting an animation.
1972 if (mWinAnimator.applyAnimationLocked(transit, false)) {
1973 mAnimatingExit = true;
1974 }
1975 //TODO (multidisplay): Magnification is supported only for the default display.
1976 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
1977 mService.mAccessibilityController.onWindowTransitionLocked(this, transit);
1978 }
1979 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001980 final boolean isAnimating = mWinAnimator.isAnimationSet()
1981 && (mAppToken == null || !mAppToken.isWaitingForTransitionStart());
Peter Visontay3556a3b2017-11-01 17:23:17 +00001982 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
1983 && mAppToken.isLastWindow(this);
1984 // We delay the removal of a window if it has a showing surface that can be used to run
1985 // exit animation and it is marked as exiting.
1986 // Also, If isn't the an animating starting window that is the last window in the app.
1987 // We allow the removal of the non-animating starting window now as there is no
1988 // additional window or animation that will trigger its removal.
1989 if (mWinAnimator.getShown() && mAnimatingExit
1990 && (!lastWindowIsStartingWindow || isAnimating)) {
1991 // The exit animation is running or should run... wait for it!
1992 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1993 "Not removing " + this + " due to exit animation ");
1994 setupWindowForRemoveOnExit();
1995 if (mAppToken != null) {
1996 mAppToken.updateReportedVisibilityLocked();
1997 }
1998 return;
1999 }
2000 }
2001
2002 removeImmediately();
2003 // Removing a visible window will effect the computed orientation
2004 // So just update orientation if needed.
2005 if (wasVisible && mService.updateOrientationFromAppTokensLocked(false, displayId)) {
2006 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
2007 }
2008 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
2009 } finally {
2010 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002011 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002012 }
2013
2014 private void setupWindowForRemoveOnExit() {
2015 mRemoveOnExit = true;
2016 setDisplayLayoutNeeded();
2017 // Request a focus update as this window's input channel is already gone. Otherwise
2018 // we could have no focused window in input manager.
2019 final boolean focusChanged = mService.updateFocusedWindowLocked(
2020 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
2021 mService.mWindowPlacerLocked.performSurfacePlacement();
2022 if (focusChanged) {
2023 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2024 }
2025 }
2026
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08002027 void setHasSurface(boolean hasSurface) {
2028 mHasSurface = hasSurface;
2029 }
2030
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002031 boolean canBeImeTarget() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002032 if (mIsImWindow) {
2033 // IME windows can't be IME targets. IME targets are required to be below the IME
2034 // windows and that wouldn't be possible if the IME window is its own target...silly.
2035 return false;
2036 }
2037
Winson Chung3d0a74a2017-07-12 12:37:19 -07002038 final boolean windowsAreFocusable = mAppToken == null || mAppToken.windowsAreFocusable();
Winson Chungb1549342017-07-11 09:59:56 -07002039 if (!windowsAreFocusable) {
2040 // This window can't be an IME target if the app's windows should not be focusable.
2041 return false;
2042 }
2043
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002044 final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002045 final int type = mAttrs.type;
2046
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002047 // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are set or
2048 // both are cleared...and not a starting window.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002049 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
2050 && type != TYPE_APPLICATION_STARTING) {
2051 return false;
2052 }
2053
2054 if (DEBUG_INPUT_METHOD) {
2055 Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding());
2056 if (!isVisibleOrAdding()) {
2057 Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController
2058 + " relayoutCalled=" + mRelayoutCalled
2059 + " viewVis=" + mViewVisibility
2060 + " policyVis=" + mPolicyVisibility
2061 + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim
2062 + " parentHidden=" + isParentWindowHidden()
2063 + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
2064 if (mAppToken != null) {
2065 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + mAppToken.hiddenRequested);
2066 }
2067 }
2068 }
2069 return isVisibleOrAdding();
2070 }
2071
Chong Zhangacf11402015-11-04 16:23:10 -08002072 private final class DeadWindowEventReceiver extends InputEventReceiver {
2073 DeadWindowEventReceiver(InputChannel inputChannel) {
2074 super(inputChannel, mService.mH.getLooper());
2075 }
2076 @Override
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -07002077 public void onInputEvent(InputEvent event, int displayId) {
Chong Zhangacf11402015-11-04 16:23:10 -08002078 finishInputEvent(event, true);
2079 }
2080 }
2081 /**
2082 * Dummy event receiver for windows that died visible.
2083 */
2084 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2085
Chong Zhang112eb8c2015-11-02 11:17:00 -08002086 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002087 if (mInputChannel != null) {
2088 throw new IllegalStateException("Window already has an input channel.");
2089 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002090 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002091 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2092 mInputChannel = inputChannels[0];
2093 mClientChannel = inputChannels[1];
2094 mInputWindowHandle.inputChannel = inputChannels[0];
2095 if (outInputChannel != null) {
2096 mClientChannel.transferTo(outInputChannel);
2097 mClientChannel.dispose();
2098 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002099 } else {
2100 // If the window died visible, we setup a dummy input channel, so that taps
2101 // can still detected by input monitor channel, and we can relaunch the app.
2102 // Create dummy event receiver that simply reports all events as handled.
2103 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002104 }
2105 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002106 }
2107
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002108 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002109 if (mDeadWindowEventReceiver != null) {
2110 mDeadWindowEventReceiver.dispose();
2111 mDeadWindowEventReceiver = null;
2112 }
2113
2114 // unregister server channel first otherwise it complains about broken channel
2115 if (mInputChannel != null) {
2116 mService.mInputManager.unregisterInputChannel(mInputChannel);
2117 mInputChannel.dispose();
2118 mInputChannel = null;
2119 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002120 if (mClientChannel != null) {
2121 mClientChannel.dispose();
2122 mClientChannel = null;
2123 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07002124 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002125 }
2126
Robert Carrf59b8dd2017-10-02 18:58:36 -07002127 private Dimmer getDimmer() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002128 Task task = getTask();
2129 if (task != null) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07002130 return task.getDimmer();
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002131 }
Robert Carrf07ef9e2017-11-21 12:12:49 -08002132 TaskStack taskStack = getStack();
2133 if (taskStack != null) {
2134 return taskStack.getDimmer();
2135 }
2136 return null;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002137 }
2138
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002139 /** Returns true if the replacement window was removed. */
2140 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2141 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2142 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2143 removeReplacedWindow();
2144 return true;
2145 }
2146
2147 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002148 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002149 if (c.removeReplacedWindowIfNeeded(replacement)) {
2150 return true;
2151 }
2152 }
2153 return false;
2154 }
2155
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002156 private void removeReplacedWindow() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002157 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002158 mWillReplaceWindow = false;
2159 mAnimateReplacingWindow = false;
2160 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002161 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002162 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002163 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002164 }
2165 }
2166
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002167 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2168 boolean replacementSet = false;
2169
2170 if (mWillReplaceWindow && mReplacementWindow == null
2171 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2172
2173 mReplacementWindow = replacementCandidate;
2174 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2175 replacementSet = true;
2176 }
2177
2178 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002179 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002180 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2181 }
2182
2183 return replacementSet;
2184 }
2185
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002186 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002187 final DisplayContent dc = getDisplayContent();
2188 if (dc != null) {
2189 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002190 }
2191 }
2192
Chong Zhang5117e272016-05-03 12:47:34 -07002193 void applyAdjustForImeIfNeeded() {
2194 final Task task = getTask();
2195 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2196 task.mStack.applyAdjustForImeIfNeeded(task);
2197 }
2198 }
2199
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002200 @Override
2201 void switchUser() {
2202 super.switchUser();
2203 if (isHiddenFromUserLocked()) {
2204 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2205 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
2206 hideLw(false);
2207 }
2208 }
2209
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002210 int getTouchableRegion(Region region, int flags) {
2211 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002212 if (modal && mAppToken != null) {
2213 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002214 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002215 // If this is a modal window we need to dismiss it if it's not full screen and the
2216 // touch happens outside of the frame that displays the content. This means we
2217 // need to intercept touches outside of that window. The dim layer user
2218 // associated with the window (task or stack) will give us the good bounds, as
2219 // they would be used to display the dim layer.
Robert Carrf59b8dd2017-10-02 18:58:36 -07002220 final Task task = getTask();
2221 if (task != null) {
2222 task.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002223 } else {
Robert Carrf59b8dd2017-10-02 18:58:36 -07002224 getStack().getDimBounds(mTmpRect);
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002225 }
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002226 if (inFreeformWindowingMode()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002227 // For freeform windows we the touch region to include the whole surface for the
2228 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002229 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2230 final int delta = WindowManagerService.dipToPixel(
2231 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2232 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002233 }
2234 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002235 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002236 } else {
2237 // Not modal or full screen modal
2238 getTouchableRegion(region);
2239 }
2240 return flags;
2241 }
2242
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002243 void checkPolicyVisibilityChange() {
2244 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2245 if (DEBUG_VISIBILITY) {
2246 Slog.v(TAG, "Policy visibility changing after anim in " +
2247 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2248 }
2249 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002250 if (!mPolicyVisibility) {
Jorim Jaggi2e05af22017-12-28 15:15:11 +01002251 mWinAnimator.hide("checkPolicyVisibilityChange");
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002252 if (mService.mCurrentFocus == this) {
2253 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2254 "setAnimationLocked: setting mFocusMayChange true");
2255 mService.mFocusMayChange = true;
Jorim Jaggi2e05af22017-12-28 15:15:11 +01002256 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002257 }
2258 // Window is no longer visible -- make sure if we were waiting
2259 // for it to be displayed before enabling the display, that
2260 // we allow the display to be enabled now.
2261 mService.enableScreenIfNeededLocked();
2262 }
2263 }
2264 }
2265
2266 void setRequestedSize(int requestedWidth, int requestedHeight) {
2267 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2268 mLayoutNeeded = true;
2269 mRequestedWidth = requestedWidth;
2270 mRequestedHeight = requestedHeight;
2271 }
2272 }
2273
Bryce Leef858b572017-06-29 14:03:33 -07002274 void prepareWindowToDisplayDuringRelayout(boolean wasVisible) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002275 // We need to turn on screen regardless of visibility.
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002276 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
2277 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
2278 mTurnOnScreen = true;
2279 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002280
2281 // If we were already visible, skip rest of preparation.
2282 if (wasVisible) {
2283 if (DEBUG_VISIBILITY) Slog.v(TAG,
2284 "Already visible and does not turn on screen, skip preparing: " + this);
2285 return;
2286 }
2287
2288 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2289 == SOFT_INPUT_ADJUST_RESIZE) {
2290 mLayoutNeeded = true;
2291 }
2292
David Stevens9440dc82017-03-16 19:00:20 -07002293 if (isDrawnLw() && mToken.okToAnimate()) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002294 mWinAnimator.applyEnterAnimationLocked();
2295 }
Bryce Leef858b572017-06-29 14:03:33 -07002296 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002297
Bryce Leef858b572017-06-29 14:03:33 -07002298 void getMergedConfiguration(MergedConfiguration outConfiguration) {
2299 final Configuration globalConfig = mService.mRoot.getConfiguration();
2300 final Configuration overrideConfig = getMergedOverrideConfiguration();
2301 outConfiguration.setConfiguration(globalConfig, overrideConfig);
2302 }
2303
Bryce Lee2b17afd2017-09-21 10:38:20 -07002304 void setLastReportedMergedConfiguration(MergedConfiguration config) {
2305 mLastReportedConfiguration.setTo(config);
2306 }
2307
2308 void getLastReportedMergedConfiguration(MergedConfiguration config) {
2309 config.setTo(mLastReportedConfiguration);
2310 }
2311
2312 private Configuration getLastReportedConfiguration() {
2313 return mLastReportedConfiguration.getMergedConfiguration();
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002314 }
2315
2316 void adjustStartingWindowFlags() {
2317 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2318 && mAppToken.startingWindow != null) {
2319 // Special handling of starting window over the base
2320 // window of the app: propagate lock screen flags to it,
2321 // to provide the correct semantics while starting.
2322 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2323 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2324 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2325 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2326 }
2327 }
2328
2329 void setWindowScale(int requestedWidth, int requestedHeight) {
2330 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2331
2332 if (scaledWindow) {
2333 // requested{Width|Height} Surface's physical size
2334 // attrs.{width|height} Size on screen
2335 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2336 mHScale = (mAttrs.width != requestedWidth) ?
2337 (mAttrs.width / (float)requestedWidth) : 1.0f;
2338 mVScale = (mAttrs.height != requestedHeight) ?
2339 (mAttrs.height / (float)requestedHeight) : 1.0f;
2340 } else {
2341 mHScale = mVScale = 1;
2342 }
2343 }
2344
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002345 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002346 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002347 public void binderDied() {
2348 try {
2349 synchronized(mService.mWindowMap) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002350 final WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002351 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002352 if (win != null) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002353 final DisplayContent dc = getDisplayContent();
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002354 if (win.mAppToken != null && win.mAppToken.findMainWindow() == win) {
2355 mService.mTaskSnapshotController.onAppDied(win.mAppToken);
2356 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002357 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002358 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2359 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002360 // just in case they have the divider at an unstable position. Better
2361 // also reset drag resizing state, because the owner can't do it
2362 // anymore.
Wale Ogunwale61911492017-10-11 08:50:50 -07002363 final TaskStack stack =
Matthew Ng64e77cf2017-10-31 14:01:31 -07002364 dc.getSplitScreenPrimaryStackIgnoringVisibility();
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002365 if (stack != null) {
2366 stack.resetDockedStackToMiddle();
2367 }
Jorim Jaggidcb68142016-02-09 21:51:30 -08002368 mService.setDockedStackResizing(false);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002369 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002370 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002371 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002372 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002373 }
2374 }
2375 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002376 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002377 }
2378 }
2379 }
2380
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002381 /**
2382 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2383 * because we want to preserve its location on screen to be re-activated later when the user
2384 * interacts with it.
2385 */
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002386 private boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwale89973222017-04-23 18:39:45 -07002387 if (!isWinVisibleLw() || mAppToken == null || mAppToken.isClientHidden()) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002388 // Not a visible app window or the app isn't dead.
2389 return false;
2390 }
2391
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002392 if (mAttrs.token != mClient.asBinder()) {
2393 // The window was add by a client using another client's app token. We don't want to
2394 // keep the dead window around for this case since this is meant for 'real' apps.
2395 return false;
2396 }
2397
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002398 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2399 // We don't keep starting windows since they were added by the window manager before
2400 // the app even launched.
2401 return false;
2402 }
2403
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002404 return getWindowConfiguration().keepVisibleDeadAppWindowOnScreen();
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002405 }
2406
Wale Ogunwaled045c822015-12-02 09:14:28 -08002407 /** @return true if this window desires key events. */
2408 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002409 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002410 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002411 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002412 && (mAppToken == null || mAppToken.windowsAreFocusable())
Matthew Nge15352e2016-12-20 15:36:29 -08002413 && !canReceiveTouchInput();
2414 }
2415
2416 /** @return true if this window desires touch events. */
2417 boolean canReceiveTouchInput() {
Bryce Lee6d410262017-02-28 15:30:17 -08002418 return mAppToken != null && mAppToken.getTask() != null
2419 && mAppToken.getTask().mStack.shouldIgnoreInput();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002420 }
2421
Craig Mautner749a7bb2012-04-02 13:49:53 -07002422 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002423 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002424 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002425 }
2426
Craig Mautner749a7bb2012-04-02 13:49:53 -07002427 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002428 public boolean showLw(boolean doAnimation) {
2429 return showLw(doAnimation, true);
2430 }
2431
2432 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002433 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002434 return false;
2435 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002436 if (!mAppOpVisibility) {
2437 // Being hidden due to app op request.
2438 return false;
2439 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002440 if (mPermanentlyHidden) {
2441 // Permanently hidden until the app exists as apps aren't prepared
2442 // to handle their windows being removed from under them.
2443 return false;
2444 }
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002445 if (mForceHideNonSystemOverlayWindow) {
2446 // This is an alert window that is currently force hidden.
2447 return false;
2448 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002449 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002450 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002451 return false;
2452 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002453 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002454 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002455 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Jorim Jaggia5e10572017-11-15 14:36:26 +01002456 + mPolicyVisibility + " isAnimationSet=" + mWinAnimator.isAnimationSet());
David Stevens9440dc82017-03-16 19:00:20 -07002457 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002458 doAnimation = false;
Jorim Jaggia5e10572017-11-15 14:36:26 +01002459 } else if (mPolicyVisibility && !mWinAnimator.isAnimationSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002460 // Check for the case where we are currently visible and
2461 // not animating; we do not want to do animation at such a
2462 // point to become visible when we already are.
2463 doAnimation = false;
2464 }
2465 }
2466 mPolicyVisibility = true;
2467 mPolicyVisibilityAfterAnim = true;
2468 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002469 mWinAnimator.applyAnimationLocked(TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002470 }
2471 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002472 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002473 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002474 if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) {
2475 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2476 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002477 return true;
2478 }
2479
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002480 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002481 public boolean hideLw(boolean doAnimation) {
2482 return hideLw(doAnimation, true);
2483 }
2484
2485 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2486 if (doAnimation) {
David Stevens9440dc82017-03-16 19:00:20 -07002487 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002488 doAnimation = false;
2489 }
2490 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002491 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002492 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002493 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002494 return false;
2495 }
2496 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002497 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
Jorim Jaggia5e10572017-11-15 14:36:26 +01002498 if (!mWinAnimator.isAnimationSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002499 doAnimation = false;
2500 }
2501 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002502 mPolicyVisibilityAfterAnim = false;
2503 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002504 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002505 mPolicyVisibility = false;
2506 // Window is no longer visible -- make sure if we were waiting
2507 // for it to be displayed before enabling the display, that
2508 // we allow the display to be enabled now.
2509 mService.enableScreenIfNeededLocked();
2510 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002511 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002512 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002513 mService.mFocusMayChange = true;
2514 }
2515 }
2516 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002517 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002518 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002519 if (mService.mCurrentFocus == this) {
2520 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2521 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002522 return true;
2523 }
2524
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002525 void setForceHideNonSystemOverlayWindowIfNeeded(boolean forceHide) {
2526 if (mOwnerCanAddInternalSystemWindow
2527 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2528 return;
2529 }
2530 if (mForceHideNonSystemOverlayWindow == forceHide) {
2531 return;
2532 }
2533 mForceHideNonSystemOverlayWindow = forceHide;
2534 if (forceHide) {
2535 hideLw(true /* doAnimation */, true /* requestAnim */);
2536 } else {
2537 showLw(true /* doAnimation */, true /* requestAnim */);
2538 }
2539 }
2540
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002541 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002542 if (mAppOpVisibility != state) {
2543 mAppOpVisibility = state;
2544 if (state) {
2545 // If the policy visibility had last been to hide, then this
2546 // will incorrectly show at this point since we lost that
2547 // information. Not a big deal -- for the windows that have app
2548 // ops modifies they should only be hidden by policy due to the
2549 // lock screen, and the user won't be changing this if locked.
2550 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002551 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002552 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002553 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002554 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002555 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002556 }
2557
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002558 public void hidePermanentlyLw() {
2559 if (!mPermanentlyHidden) {
2560 mPermanentlyHidden = true;
2561 hideLw(true, true);
2562 }
2563 }
2564
Jeff Brownc2932a12014-11-20 18:04:05 -08002565 public void pokeDrawLockLw(long timeout) {
2566 if (isVisibleOrAdding()) {
2567 if (mDrawLock == null) {
2568 // We want the tag name to be somewhat stable so that it is easier to correlate
2569 // in wake lock statistics. So in particular, we don't want to include the
2570 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002571 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08002572 mDrawLock = mService.mPowerManager.newWakeLock(
2573 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
2574 mDrawLock.setReferenceCounted(false);
2575 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2576 }
2577 // Each call to acquire resets the timeout.
2578 if (DEBUG_POWER) {
2579 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2580 + mAttrs.packageName);
2581 }
2582 mDrawLock.acquire(timeout);
2583 } else if (DEBUG_POWER) {
2584 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2585 + "owned by " + mAttrs.packageName);
2586 }
2587 }
2588
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002589 @Override
2590 public boolean isAlive() {
2591 return mClient.asBinder().isBinderAlive();
2592 }
2593
Craig Mautnera987d432012-10-11 14:07:58 -07002594 boolean isClosing() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002595 return mAnimatingExit || (mService.mClosingApps.contains(mAppToken));
Craig Mautnera987d432012-10-11 14:07:58 -07002596 }
2597
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002598 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2599 animators.add(mWinAnimator);
2600
2601 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002602 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002603 c.addWinAnimatorToList(animators);
2604 }
2605 }
2606
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002607 void sendAppVisibilityToClients() {
2608 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002609
Wale Ogunwale89973222017-04-23 18:39:45 -07002610 final boolean clientHidden = mAppToken.isClientHidden();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002611 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2612 // Don't hide the starting window.
2613 return;
2614 }
2615
Wale Ogunwale89973222017-04-23 18:39:45 -07002616 if (clientHidden) {
2617 // Once we are notifying the client that it's visibility has changed, we need to prevent
2618 // it from destroying child surfaces until the animation has finished. We do this by
2619 // detaching any surface control the client added from the client.
2620 for (int i = mChildren.size() - 1; i >= 0; --i) {
2621 final WindowState c = mChildren.get(i);
2622 c.mWinAnimator.detachChildren();
2623 }
2624
2625 mWinAnimator.detachChildren();
2626 }
2627
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002628 try {
2629 if (DEBUG_VISIBILITY) Slog.v(TAG,
2630 "Setting visibility of " + this + ": " + (!clientHidden));
2631 mClient.dispatchAppVisibility(!clientHidden);
2632 } catch (RemoteException e) {
2633 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002634 }
2635
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002636 void onStartFreezingScreen() {
2637 mAppFreezing = true;
2638 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002639 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002640 c.onStartFreezingScreen();
2641 }
2642 }
2643
2644 boolean onStopFreezingScreen() {
2645 boolean unfrozeWindows = false;
2646 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002647 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002648 unfrozeWindows |= c.onStopFreezingScreen();
2649 }
2650
2651 if (!mAppFreezing) {
2652 return unfrozeWindows;
2653 }
2654
Wale Ogunwale953171d2016-09-30 09:17:30 -07002655 mAppFreezing = false;
2656
Bryce Lee8c3cf382017-07-06 19:47:10 -07002657 if (mHasSurface && !getOrientationChanging()
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002658 && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
2659 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
Bryce Lee8c3cf382017-07-06 19:47:10 -07002660 setOrientationChanging(true);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002661 mService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002662 }
2663 mLastFreezeDuration = 0;
2664 setDisplayLayoutNeeded();
2665 return true;
2666 }
2667
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002668 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2669 boolean destroyedSomething = false;
Jorim Jaggi59f3e922018-01-05 15:40:32 +01002670
2671 // Copying to a different list as multiple children can be removed.
2672 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
2673 for (int i = childWindows.size() - 1; i >= 0; --i) {
2674 final WindowState c = childWindows.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002675 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2676 }
2677
Robert Carrdb2f6e62017-03-01 20:17:58 -08002678 if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) {
2679 return destroyedSomething;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002680 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08002681
2682 if (appStopped || mWindowRemovalAllowed) {
2683 mWinAnimator.destroyPreservedSurfaceLocked();
2684 }
2685
2686 if (mDestroying) {
2687 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2688 + " destroySurfaces: appStopped=" + appStopped
2689 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2690 + " win.mRemoveOnExit=" + mRemoveOnExit);
2691 if (!cleanupOnResume || mRemoveOnExit) {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002692 destroySurfaceUnchecked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08002693 }
2694 if (mRemoveOnExit) {
2695 removeImmediately();
2696 }
2697 if (cleanupOnResume) {
2698 requestUpdateWallpaperIfNeeded();
2699 }
2700 mDestroying = false;
2701 destroyedSomething = true;
2702 }
2703
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002704 return destroyedSomething;
2705 }
Chris Craik3131bde2016-05-06 13:39:08 -07002706
Robert Carr89a28ab2017-04-24 15:33:11 -07002707 // Destroy or save the application surface without checking
2708 // various indicators of whether the client has released the surface.
2709 // This is in general unsafe, and most callers should use {@link #destroySurface}
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002710 void destroySurfaceUnchecked() {
2711 mWinAnimator.destroySurfaceLocked();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002712
Chong Zhang92147042016-05-09 12:47:11 -07002713 // Clear animating flags now, since the surface is now gone. (Note this is true even
2714 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2715 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002716 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002717
Craig Mautner69b08182012-09-05 13:07:13 -07002718 @Override
2719 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002720 final DisplayContent displayContent = getDisplayContent();
2721 if (displayContent == null) {
2722 // Only a window that was on a non-default display can be detached from it.
2723 return false;
2724 }
Winson Chung47a3e652014-05-21 16:03:42 -07002725 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002726 }
2727
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002728 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07002729 mShowToOwnerOnly = showToOwnerOnly;
2730 }
2731
Wale Ogunwaleea92d972016-12-08 07:33:13 -08002732 private boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002733 // Child windows are evaluated based on their parent window.
2734 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002735 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale72919d22016-12-08 18:58:50 -08002736 && win.mAppToken != null && win.mAppToken.mShowForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002737
2738 // All window frames that are fullscreen extend above status bar, but some don't extend
2739 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2740 // bottom right.
2741 if (win.mFrame.left <= win.mDisplayFrame.left
2742 && win.mFrame.top <= win.mDisplayFrame.top
2743 && win.mFrame.right >= win.mStableFrame.right
2744 && win.mFrame.bottom >= win.mStableFrame.bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002745 // Is a fullscreen window, like the clock alarm. Show to everyone.
2746 return false;
2747 }
2748 }
2749
Craig Mautner341220f2012-10-16 15:20:09 -07002750 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01002751 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002752 }
2753
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002754 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2755 outRegion.set(
2756 frame.left + inset.left, frame.top + inset.top,
2757 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002758 }
2759
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002760 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002761 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002762 switch (mTouchableInsets) {
2763 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002764 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002765 outRegion.set(frame);
2766 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002767 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002768 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002769 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002770 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002771 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002772 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002773 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002774 outRegion.set(mGivenTouchableRegion);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002775 outRegion.translate(frame.left, frame.top);
2776 break;
2777 }
2778 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002779 cropRegionToStackBoundsIfNeeded(outRegion);
2780 }
2781
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002782 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002783 final Task task = getTask();
2784 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002785 return;
2786 }
2787
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002788 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002789 if (stack == null) {
2790 return;
2791 }
2792
2793 stack.getDimBounds(mTmpRect);
2794 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002795 }
2796
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002797 /**
2798 * Report a focus change. Must be called with no locks held, and consistently
2799 * from the same serialized thread (such as dispatched from a handler).
2800 */
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07002801 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002802 try {
2803 mClient.windowFocusChanged(focused, inTouchMode);
2804 } catch (RemoteException e) {
2805 }
2806 if (mFocusCallbacks != null) {
2807 final int N = mFocusCallbacks.beginBroadcast();
2808 for (int i=0; i<N; i++) {
2809 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2810 try {
2811 if (focused) {
2812 obs.focusGained(mWindowId.asBinder());
2813 } else {
2814 obs.focusLost(mWindowId.asBinder());
2815 }
2816 } catch (RemoteException e) {
2817 }
2818 }
2819 mFocusCallbacks.finishBroadcast();
2820 }
2821 }
2822
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002823 @Override
2824 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002825 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002826 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002827 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002828
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002829 return super.getConfiguration();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002830 }
2831
Craig Mautnerdf88d732014-01-27 09:21:32 -08002832 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002833 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08002834 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002835 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
2836 + ": " + mCompatFrame);
Bryce Leef858b572017-06-29 14:03:33 -07002837 final MergedConfiguration mergedConfiguration =
2838 new MergedConfiguration(mService.mRoot.getConfiguration(),
2839 getMergedOverrideConfiguration());
2840
Bryce Lee2b17afd2017-09-21 10:38:20 -07002841 setLastReportedMergedConfiguration(mergedConfiguration);
Bryce Leef858b572017-06-29 14:03:33 -07002842
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002843 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002844 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
2845
Craig Mautnerdf88d732014-01-27 09:21:32 -08002846 final Rect frame = mFrame;
2847 final Rect overscanInsets = mLastOverscanInsets;
2848 final Rect contentInsets = mLastContentInsets;
2849 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07002850 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002851 final Rect outsets = mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002852 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Andrii Kulianb2e37802017-01-11 00:36:44 -08002853 final boolean reportOrientation = mReportOrientationChanged;
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002854 final int displayId = getDisplayId();
Adrian Roos5c6b6222017-11-07 17:36:10 +01002855 final DisplayCutout displayCutout = mDisplayCutout;
Chet Haase8eb48d22014-09-24 07:31:29 -07002856 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
2857 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002858 // To prevent deadlock simulate one-way call if win.mClient is a local object.
2859 mService.mH.post(new Runnable() {
2860 @Override
2861 public void run() {
2862 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002863 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07002864 stableInsets, outsets, reportDraw, mergedConfiguration,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002865 reportOrientation, displayId, displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002866 } catch (RemoteException e) {
2867 // Not a remote call, RemoteException won't be raised.
2868 }
2869 }
2870 });
2871 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002872 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002873 outsets, reportDraw, mergedConfiguration, reportOrientation, displayId,
2874 displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002875 }
Svetoslav4604abc2014-06-10 18:59:30 -07002876
2877 //TODO (multidisplay): Accessibility supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002878 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07002879 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07002880 }
2881
Craig Mautnerdf88d732014-01-27 09:21:32 -08002882 mOverscanInsetsChanged = false;
2883 mContentInsetsChanged = false;
2884 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07002885 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002886 mOutsetsChanged = false;
Robert Carr31aa98b2016-07-20 15:29:03 -07002887 mFrameSizeChanged = false;
Adrian Roos5c6b6222017-11-07 17:36:10 +01002888 mDisplayCutoutChanged = false;
Andrii Kulianeb1d3222016-05-16 15:17:55 -07002889 mResizedWhileNotDragResizingReported = true;
Craig Mautnerdf88d732014-01-27 09:21:32 -08002890 mWinAnimator.mSurfaceResized = false;
Andrii Kulianb2e37802017-01-11 00:36:44 -08002891 mReportOrientationChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08002892 } catch (RemoteException e) {
Bryce Lee8c3cf382017-07-06 19:47:10 -07002893 setOrientationChanging(false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002894 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2895 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08002896 // We are assuming the hosting process is dead or in a zombie state.
2897 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
2898 + ", removing this window.");
2899 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002900 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002901 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002902 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002903 }
2904
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002905 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08002906 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
2907 // start even if we haven't received the relayout window, so that the client requests
2908 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
2909 // until the window to small size, otherwise the multithread renderer will shift last
2910 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
2911 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002912 boolean resizing = isDragResizing() || isDragResizeChanged();
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002913 if (getWindowConfiguration().useWindowFrameForBackdrop() || !resizing) {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002914 return frame;
2915 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07002916 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002917 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002918 return mTmpRect;
2919 }
2920
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002921 private int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002922 final TaskStack stack = getStack();
2923 if (stack == null) {
2924 return INVALID_STACK_ID;
2925 }
2926 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002927 }
2928
2929 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
2930 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002931 MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId,
2932 DisplayCutout displayCutout)
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002933 throws RemoteException {
Andrii Kulianb2e37802017-01-11 00:36:44 -08002934 final boolean forceRelayout = isDragResizeChanged() || mResizedWhileNotDragResizing
2935 || reportOrientation;
Chong Zhangedaf3052016-04-22 15:04:31 -07002936
Jorim Jaggidc249c42015-12-15 14:57:31 -08002937 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Andrii Kulian44607962017-03-16 11:06:24 -07002938 reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002939 mPolicy.isNavBarForcedShownLw(this), displayId,
2940 new DisplayCutout.ParcelableWrapper(displayCutout));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002941 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002942 }
2943
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002944 public void registerFocusObserver(IWindowFocusObserver observer) {
2945 synchronized(mService.mWindowMap) {
2946 if (mFocusCallbacks == null) {
2947 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
2948 }
2949 mFocusCallbacks.register(observer);
2950 }
2951 }
2952
2953 public void unregisterFocusObserver(IWindowFocusObserver observer) {
2954 synchronized(mService.mWindowMap) {
2955 if (mFocusCallbacks != null) {
2956 mFocusCallbacks.unregister(observer);
2957 }
2958 }
2959 }
2960
2961 public boolean isFocused() {
2962 synchronized(mService.mWindowMap) {
2963 return mService.mCurrentFocus == this;
2964 }
2965 }
2966
Wale Ogunwale9185fb02016-03-11 18:06:14 -08002967 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07002968 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08002969 final Task task = getTask();
2970 return task != null && !task.isFullscreen();
2971 }
2972
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002973 /** Is this window in a container that takes up the entire screen space? */
2974 private boolean inFullscreenContainer() {
Bryce Leef3c6a472017-11-14 14:53:06 -08002975 return mAppToken == null || (mAppToken.matchParentBounds() && !isInMultiWindowMode());
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002976 }
2977
Andrii Kulian283acd22017-08-03 04:03:51 -07002978 /** @return true when the window is in fullscreen task, but has non-fullscreen bounds set. */
2979 boolean isLetterboxedAppWindow() {
Bryce Leef3c6a472017-11-14 14:53:06 -08002980 return !isInMultiWindowMode() && mAppToken != null && !mAppToken.matchParentBounds();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002981 }
2982
Chong Zhang3005e752015-09-18 18:46:28 -07002983 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07002984 return mDragResizing != computeDragResizing();
2985 }
2986
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002987 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002988 void setWaitingForDrawnIfResizingChanged() {
2989 if (isDragResizeChanged()) {
2990 mService.mWaitingForDrawn.add(this);
2991 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002992 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002993 }
2994
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002995 /**
2996 * @return Whether we reported a drag resize change to the application or not already.
2997 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002998 private boolean isDragResizingChangeReported() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002999 return mDragResizingChangeReported;
3000 }
3001
3002 /**
3003 * Resets the state whether we reported a drag resize change to the app.
3004 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003005 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003006 void resetDragResizingChangeReported() {
3007 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003008 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003009 }
3010
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003011 /**
3012 * Set whether we got resized but drag resizing flag was false.
3013 * @see #isResizedWhileNotDragResizing().
3014 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003015 private void setResizedWhileNotDragResizing(boolean resizedWhileNotDragResizing) {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003016 mResizedWhileNotDragResizing = resizedWhileNotDragResizing;
3017 mResizedWhileNotDragResizingReported = !resizedWhileNotDragResizing;
3018 }
3019
3020 /**
3021 * Indicates whether we got resized but drag resizing flag was false. In this case, we also
3022 * need to recreate the surface and defer surface bound updates in order to make sure the
3023 * buffer contents and the positioning/size stay in sync.
3024 */
3025 boolean isResizedWhileNotDragResizing() {
3026 return mResizedWhileNotDragResizing;
3027 }
3028
3029 /**
3030 * @return Whether we reported "resize while not drag resizing" to the application.
3031 * @see #isResizedWhileNotDragResizing()
3032 */
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003033 private boolean isResizedWhileNotDragResizingReported() {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003034 return mResizedWhileNotDragResizingReported;
3035 }
3036
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003037 int getResizeMode() {
3038 return mResizeMode;
3039 }
3040
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003041 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003042 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003043 if (task == null) {
3044 return false;
3045 }
Tomasz Mikolajewskiaf20b8d2017-11-20 16:11:33 +09003046 if (!inSplitScreenWindowingMode() && !inFreeformWindowingMode()) {
Winson Chung2af04b32017-01-24 16:21:13 -08003047 return false;
3048 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003049 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003050 // Floating windows never enter drag resize mode.
3051 return false;
3052 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003053 if (task.isDragResizing()) {
3054 return true;
3055 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003056
3057 // If the bounds are currently frozen, it means that the layout size that the app sees
3058 // and the bounds we clip this window to might be different. In order to avoid holes, we
3059 // simulate that we are still resizing so the app fills the hole with the resizing
3060 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003061 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003062 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003063 !task.inFreeformWindowingMode() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003064
Chong Zhang3005e752015-09-18 18:46:28 -07003065 }
3066
3067 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003068 final boolean resizing = computeDragResizing();
3069 if (resizing == mDragResizing) {
3070 return;
3071 }
3072 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003073 final Task task = getTask();
3074 if (task != null && task.isDragResizing()) {
3075 mResizeMode = task.getDragResizeMode();
3076 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003077 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003078 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3079 : DRAG_RESIZE_MODE_FREEFORM;
3080 }
Chong Zhang3005e752015-09-18 18:46:28 -07003081 }
3082
3083 boolean isDragResizing() {
3084 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003085 }
3086
Robert Carr2487ce72016-04-07 15:18:45 -07003087 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003088 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3089 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003090 }
3091
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07003092 @CallSuper
3093 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02003094 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003095 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02003096 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003097 writeIdentifierToProto(proto, IDENTIFIER);
3098 proto.write(DISPLAY_ID, getDisplayId());
3099 proto.write(STACK_ID, getStackId());
3100 mAttrs.writeToProto(proto, ATTRIBUTES);
3101 mGivenContentInsets.writeToProto(proto, GIVEN_CONTENT_INSETS);
3102 mFrame.writeToProto(proto, FRAME);
3103 mContainingFrame.writeToProto(proto, CONTAINING_FRAME);
3104 mParentFrame.writeToProto(proto, PARENT_FRAME);
3105 mContentFrame.writeToProto(proto, CONTENT_FRAME);
3106 mContentInsets.writeToProto(proto, CONTENT_INSETS);
3107 mAttrs.surfaceInsets.writeToProto(proto, SURFACE_INSETS);
Jorim Jaggi45be1c4c2017-12-15 18:44:43 +01003108 mSurfacePosition.writeToProto(proto, SURFACE_POSITION);
3109 mShownPosition.writeToProto(proto, SHOWN_POSITION);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003110 mWinAnimator.writeToProto(proto, ANIMATOR);
3111 proto.write(ANIMATING_EXIT, mAnimatingExit);
3112 for (int i = 0; i < mChildren.size(); i++) {
Adrian Roos4921ccf2017-09-28 16:54:06 +02003113 mChildren.get(i).writeToProto(proto, CHILD_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003114 }
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003115 proto.write(REQUESTED_WIDTH, mRequestedWidth);
3116 proto.write(REQUESTED_HEIGHT, mRequestedHeight);
3117 proto.write(VIEW_VISIBILITY, mViewVisibility);
3118 proto.write(SYSTEM_UI_VISIBILITY, mSystemUiVisibility);
3119 proto.write(HAS_SURFACE, mHasSurface);
3120 proto.write(IS_READY_FOR_DISPLAY, isReadyForDisplay());
3121 mDisplayFrame.writeToProto(proto, DISPLAY_FRAME);
3122 mOverscanFrame.writeToProto(proto, OVERSCAN_FRAME);
3123 mVisibleFrame.writeToProto(proto, VISIBLE_FRAME);
3124 mDecorFrame.writeToProto(proto, DECOR_FRAME);
3125 mOutsetFrame.writeToProto(proto, OUTSET_FRAME);
3126 mOverscanInsets.writeToProto(proto, OVERSCAN_INSETS);
3127 mVisibleInsets.writeToProto(proto, VISIBLE_INSETS);
3128 mStableInsets.writeToProto(proto, STABLE_INSETS);
3129 mOutsets.writeToProto(proto, OUTSETS);
3130 mDisplayCutout.writeToProto(proto, CUTOUT);
3131 proto.write(REMOVE_ON_EXIT, mRemoveOnExit);
3132 proto.write(DESTROYING, mDestroying);
3133 proto.write(REMOVED, mRemoved);
3134 proto.write(IS_ON_SCREEN, isOnScreen());
3135 proto.write(IS_VISIBLE, isVisible());
Steven Timotiusaf03df62017-07-18 16:56:43 -07003136 proto.end(token);
3137 }
3138
3139 void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) {
3140 final long token = proto.start(fieldId);
3141 proto.write(HASH_CODE, System.identityHashCode(this));
3142 proto.write(USER_ID, UserHandle.getUserId(mOwnerUid));
3143 final CharSequence title = getWindowTag();
3144 if (title != null) {
3145 proto.write(TITLE, title.toString());
3146 }
3147 proto.end(token);
3148 }
3149
Jorim Jaggia5e10572017-11-15 14:36:26 +01003150 @Override
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003151 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003152 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003153 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003154 if (stack != null) {
3155 pw.print(" stackId="); pw.print(stack.mStackId);
3156 }
Craig Mautner59c00972012-07-30 12:10:24 -07003157 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003158 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07003159 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08003160 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
3161 pw.print(" package="); pw.print(mAttrs.packageName);
3162 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Jorim Jaggi484851b2017-09-22 16:03:27 +02003163 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs.toString(prefix));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003164 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
3165 pw.print(" h="); pw.print(mRequestedHeight);
3166 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003167 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
3168 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
3169 pw.print(" h="); pw.println(mLastRequestedHeight);
3170 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003171 if (mIsChildWindow || mLayoutAttached) {
3172 pw.print(prefix); pw.print("mParentWindow="); pw.print(getParentWindow());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003173 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
3174 }
3175 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
3176 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
3177 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
3178 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
3179 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
3180 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003181 if (dumpAll) {
3182 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3183 pw.print(" mSubLayer="); pw.print(mSubLayer);
3184 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautnerc2f9be02012-03-27 17:32:29 -07003185 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
3186 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003187 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003188 if (dumpAll) {
3189 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003190 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003191 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
3192 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Bryce Lee6311c4b2017-07-06 14:09:29 -07003193 pw.print(" mAppDied=");pw.print(mAppDied);
3194 pw.print(prefix); pw.print("drawnStateEvaluated=");
3195 pw.print(getDrawnStateEvaluated());
3196 pw.print(prefix); pw.print("mightAffectAllDrawn=");
Jorim Jaggie7d2b852017-08-28 17:55:15 +02003197 pw.println(mightAffectAllDrawn());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003198 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003199 pw.print(prefix); pw.print("mViewVisibility=0x");
3200 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003201 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
3202 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07003203 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
3204 pw.print(" mSystemUiVisibility=0x");
3205 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003206 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003207 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003208 || isParentWindowHidden()|| mPermanentlyHidden || mForceHideNonSystemOverlayWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003209 pw.print(prefix); pw.print("mPolicyVisibility=");
3210 pw.print(mPolicyVisibility);
3211 pw.print(" mPolicyVisibilityAfterAnim=");
3212 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003213 pw.print(" mAppOpVisibility=");
3214 pw.print(mAppOpVisibility);
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003215 pw.print(" parentHidden="); pw.print(isParentWindowHidden());
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003216 pw.print(" mPermanentlyHidden="); pw.print(mPermanentlyHidden);
3217 pw.print(" mForceHideNonSystemOverlayWindow="); pw.println(
3218 mForceHideNonSystemOverlayWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003219 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003220 if (!mRelayoutCalled || mLayoutNeeded) {
3221 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
3222 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003223 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003224 if (mXOffset != 0 || mYOffset != 0) {
3225 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
3226 pw.print(" y="); pw.println(mYOffset);
3227 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003228 if (dumpAll) {
3229 pw.print(prefix); pw.print("mGivenContentInsets=");
3230 mGivenContentInsets.printShortString(pw);
3231 pw.print(" mGivenVisibleInsets=");
3232 mGivenVisibleInsets.printShortString(pw);
3233 pw.println();
3234 if (mTouchableInsets != 0 || mGivenInsetsPending) {
3235 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
3236 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003237 Region region = new Region();
3238 getTouchableRegion(region);
3239 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003240 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003241 pw.print(prefix); pw.print("mFullConfiguration="); pw.println(getConfiguration());
3242 pw.print(prefix); pw.print("mLastReportedConfiguration=");
Bryce Lee2b17afd2017-09-21 10:38:20 -07003243 pw.println(getLastReportedConfiguration());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003244 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07003245 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07003246 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Chong Zhanga8975bd2016-01-28 17:13:47 -08003247 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08003248 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003249 if (dumpAll) {
3250 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
3251 pw.print(" last="); mLastFrame.printShortString(pw);
3252 pw.println();
3253 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003254 if (mEnforceSizeCompat) {
3255 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003256 pw.println();
3257 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003258 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003259 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003260 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003261 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003262 pw.println();
3263 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
3264 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003265 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003266 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003267 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003268 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04003269 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
3270 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003271 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
3272 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003273 pw.print(prefix); pw.print("Cur insets: overscan=");
3274 mOverscanInsets.printShortString(pw);
3275 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003276 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003277 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003278 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003279 pw.print(" outsets="); mOutsets.printShortString(pw);
Adrian Roos5c6b6222017-11-07 17:36:10 +01003280 pw.print(" cutout=" + mDisplayCutout);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003281 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003282 pw.print(prefix); pw.print("Lst insets: overscan=");
3283 mLastOverscanInsets.printShortString(pw);
3284 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003285 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003286 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003287 pw.print(" physical="); mLastOutsets.printShortString(pw);
3288 pw.print(" outset="); mLastOutsets.printShortString(pw);
Adrian Roos5c6b6222017-11-07 17:36:10 +01003289 pw.print(" cutout=" + mLastDisplayCutout);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003290 pw.println();
3291 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01003292 super.dump(pw, prefix, dumpAll);
Dianne Hackborn529e7442012-11-01 14:22:28 -07003293 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
3294 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003295 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
3296 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003297 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
3298 pw.print(" mDestroying="); pw.print(mDestroying);
3299 pw.print(" mRemoved="); pw.println(mRemoved);
3300 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07003301 if (getOrientationChanging() || mAppFreezing || mTurnOnScreen
Andrii Kulianb2e37802017-01-11 00:36:44 -08003302 || mReportOrientationChanged) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003303 pw.print(prefix); pw.print("mOrientationChanging=");
3304 pw.print(mOrientationChanging);
Bryce Lee8c3cf382017-07-06 19:47:10 -07003305 pw.print(" configOrientationChanging=");
Bryce Lee2b17afd2017-09-21 10:38:20 -07003306 pw.print(getLastReportedConfiguration().orientation
Bryce Lee8c3cf382017-07-06 19:47:10 -07003307 != getConfiguration().orientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003308 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003309 pw.print(" mTurnOnScreen="); pw.print(mTurnOnScreen);
Andrii Kulianb2e37802017-01-11 00:36:44 -08003310 pw.print(" mReportOrientationChanged="); pw.println(mReportOrientationChanged);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003311 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003312 if (mLastFreezeDuration != 0) {
3313 pw.print(prefix); pw.print("mLastFreezeDuration=");
3314 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
3315 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003316 if (mHScale != 1 || mVScale != 1) {
3317 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
3318 pw.print(" mVScale="); pw.println(mVScale);
3319 }
3320 if (mWallpaperX != -1 || mWallpaperY != -1) {
3321 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
3322 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
3323 }
3324 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
3325 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
3326 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
3327 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003328 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3329 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
3330 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
3331 pw.print(mWallpaperDisplayOffsetX);
3332 pw.print(" mWallpaperDisplayOffsetY=");
3333 pw.println(mWallpaperDisplayOffsetY);
3334 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003335 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07003336 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003337 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003338 if (isDragResizing()) {
3339 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
3340 }
3341 if (computeDragResizing()) {
3342 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
3343 }
Bryce Lee6311c4b2017-07-06 14:09:29 -07003344 pw.print(prefix); pw.println("isOnScreen=" + isOnScreen());
3345 pw.print(prefix); pw.println("isVisible=" + isVisible());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003346 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003347
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003348 @Override
3349 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003350 return Integer.toHexString(System.identityHashCode(this))
Jorim Jaggia5e10572017-11-15 14:36:26 +01003351 + " " + getWindowTag();
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003352 }
3353
Robert Carra1eb4392015-12-10 12:43:51 -08003354 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003355 CharSequence tag = mAttrs.getTitle();
3356 if (tag == null || tag.length() <= 0) {
3357 tag = mAttrs.packageName;
3358 }
3359 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003360 }
3361
3362 @Override
3363 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003364 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003365 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003366 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003367 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003368 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003369 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003370 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003371 }
3372 return mStringNameCache;
3373 }
Robert Carr58f29132015-10-29 14:19:05 -07003374
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003375 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003376 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003377 clipRect.left = (int) (clipRect.left / mHScale);
3378 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003379 }
3380 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003381 clipRect.top = (int) (clipRect.top / mVScale);
3382 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003383 }
3384 }
Robert Carr31e28482015-12-02 16:53:18 -08003385
Jorim Jaggif5834272016-04-04 20:25:41 -07003386 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
3387 final int pw = containingFrame.width();
3388 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003389 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003390 final boolean inNonFullscreenContainer = !inFullscreenContainer();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003391 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3392
3393 // We need to fit it to the display if either
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003394 // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen
3395 // for the taskless windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003396 // 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 -07003397 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on
3398 // screen, but SurfaceViews want to be always at a specific location so we don't fit it to
3399 // the display.
3400 final boolean fitToDisplay = (task == null || !inNonFullscreenContainer)
Robert Carr6f44db12016-07-21 14:54:43 -07003401 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003402 float x, y;
3403 int w,h;
3404
3405 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3406 if (mAttrs.width < 0) {
3407 w = pw;
3408 } else if (mEnforceSizeCompat) {
3409 w = (int)(mAttrs.width * mGlobalScale + .5f);
3410 } else {
3411 w = mAttrs.width;
3412 }
3413 if (mAttrs.height < 0) {
3414 h = ph;
3415 } else if (mEnforceSizeCompat) {
3416 h = (int)(mAttrs.height * mGlobalScale + .5f);
3417 } else {
3418 h = mAttrs.height;
3419 }
3420 } else {
3421 if (mAttrs.width == MATCH_PARENT) {
3422 w = pw;
3423 } else if (mEnforceSizeCompat) {
3424 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3425 } else {
3426 w = mRequestedWidth;
3427 }
3428 if (mAttrs.height == MATCH_PARENT) {
3429 h = ph;
3430 } else if (mEnforceSizeCompat) {
3431 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3432 } else {
3433 h = mRequestedHeight;
3434 }
3435 }
3436
3437 if (mEnforceSizeCompat) {
3438 x = mAttrs.x * mGlobalScale;
3439 y = mAttrs.y * mGlobalScale;
3440 } else {
3441 x = mAttrs.x;
3442 y = mAttrs.y;
3443 }
3444
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003445 if (inNonFullscreenContainer && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003446 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003447 // required by {@link Gravity#apply} call.
3448 w = Math.min(w, pw);
3449 h = Math.min(h, ph);
3450 }
3451
3452 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003453 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003454 (int) (x + mAttrs.horizontalMargin * pw),
3455 (int) (y + mAttrs.verticalMargin * ph), mFrame);
3456
3457 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003458 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003459 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003460 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003461
3462 // We need to make sure we update the CompatFrame as it is used for
3463 // cropping decisions, etc, on systems where we lack a decor layer.
3464 mCompatFrame.set(mFrame);
3465 if (mEnforceSizeCompat) {
3466 // See comparable block in computeFrameLw.
3467 mCompatFrame.scale(mInvGlobalScale);
3468 }
Robert Carr31e28482015-12-02 16:53:18 -08003469 }
Robert Carr51a1b872015-12-08 14:03:13 -08003470
3471 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003472 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003473 }
3474
Robert Carrf3b72c72016-03-21 18:16:39 -07003475 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003476 return mIsChildWindow
3477 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003478 }
3479
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003480 /**
3481 * Returns true if any window added by an application process that if of type
3482 * {@link android.view.WindowManager.LayoutParams#TYPE_TOAST} or that requires that requires
3483 * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when
3484 * this window is visible.
3485 */
3486 boolean hideNonSystemOverlayWindowsWhenVisible() {
3487 return (mAttrs.privateFlags & PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != 0
3488 && mSession.mCanHideNonSystemOverlayWindows;
3489 }
3490
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003491 /** Returns the parent window if this is a child of another window, else null. */
3492 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003493 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3494 // WindowContainer that isn't a WindowState.
3495 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003496 }
3497
3498 /** Returns the topmost parent window if this is a child of another window, else this. */
3499 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003500 WindowState current = this;
3501 WindowState topParent = current;
3502 while (current != null && current.mIsChildWindow) {
3503 current = current.getParentWindow();
3504 // Parent window can be null if the child is detached from it's parent already, but
3505 // someone still has a reference to access it. So, we return the top parent value we
3506 // already have instead of null.
3507 if (current != null) {
3508 topParent = current;
3509 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003510 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003511 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003512 }
3513
Wale Ogunwale9d147902016-07-16 11:58:55 -07003514 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003515 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003516 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003517 }
3518
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003519 void setWillReplaceWindow(boolean animate) {
3520 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003521 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003522 c.setWillReplaceWindow(animate);
3523 }
3524
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003525 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3526 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3527 // We don't set replacing on starting windows since they are added by window manager and
3528 // not the client so won't be replaced by the client.
3529 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003530 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003531
3532 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003533 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003534 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003535 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003536
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003537 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003538 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003539 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003540 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003541
3542 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003543 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003544 c.clearWillReplaceWindow();
3545 }
3546 }
3547
3548 boolean waitingForReplacement() {
3549 if (mWillReplaceWindow) {
3550 return true;
3551 }
3552
3553 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003554 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003555 if (c.waitingForReplacement()) {
3556 return true;
3557 }
3558 }
3559 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003560 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003561
Chong Zhang4d7369a2016-04-25 16:09:14 -07003562 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003563 final DisplayContent dc = getDisplayContent();
3564 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3565 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3566 dc.setLayoutNeeded();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003567 mService.mWindowPlacerLocked.requestTraversal();
3568 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003569
3570 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003571 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003572 c.requestUpdateWallpaperIfNeeded();
3573 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003574 }
3575
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003576 float translateToWindowX(float x) {
3577 float winX = x - mFrame.left;
3578 if (mEnforceSizeCompat) {
3579 winX *= mGlobalScale;
3580 }
3581 return winX;
3582 }
3583
3584 float translateToWindowY(float y) {
3585 float winY = y - mFrame.top;
3586 if (mEnforceSizeCompat) {
3587 winY *= mGlobalScale;
3588 }
3589 return winY;
3590 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003591
3592 // During activity relaunch due to resize, we sometimes use window replacement
3593 // for only child windows (as the main window is handled by window preservation)
3594 // and the big surface.
3595 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003596 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3597 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3598 // we also want to replace them at such phases, as they won't be covered by window
3599 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003600 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003601 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003602 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003603 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003604
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003605 void setWillReplaceChildWindows() {
3606 if (shouldBeReplacedWithChildren()) {
3607 setWillReplaceWindow(false /* animate */);
3608 }
3609 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003610 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003611 c.setWillReplaceChildWindows();
3612 }
3613 }
3614
3615 WindowState getReplacingWindow() {
3616 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3617 return this;
3618 }
3619 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003620 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003621 final WindowState replacing = c.getReplacingWindow();
3622 if (replacing != null) {
3623 return replacing;
3624 }
3625 }
3626 return null;
3627 }
3628
Jorim Jaggife762342016-10-13 14:33:27 +02003629 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07003630 public int getRotationAnimationHint() {
3631 if (mAppToken != null) {
3632 return mAppToken.mRotationAnimationHint;
3633 } else {
3634 return -1;
3635 }
3636 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003637
Jorim Jaggife762342016-10-13 14:33:27 +02003638 @Override
3639 public boolean isInputMethodWindow() {
3640 return mIsImWindow;
3641 }
3642
Wale Ogunwale9d147902016-07-16 11:58:55 -07003643 // This must be called while inside a transaction.
3644 boolean performShowLocked() {
3645 if (isHiddenFromUserLocked()) {
3646 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3647 hideLw(false);
3648 return false;
3649 }
3650
3651 logPerformShow("performShow on ");
3652
Jorim Jaggia50da602016-12-29 11:51:42 +01003653 final int drawState = mWinAnimator.mDrawState;
3654 if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW)
3655 && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3656 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3657 }
3658
Jorim Jaggib0d27342016-11-01 16:10:42 -07003659 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003660 return false;
3661 }
3662
3663 logPerformShow("Showing ");
3664
3665 mService.enableScreenIfNeededLocked();
3666 mWinAnimator.applyEnterAnimationLocked();
3667
3668 // Force the show in the next prepareSurfaceLocked() call.
3669 mWinAnimator.mLastAlpha = -1;
Robert Carre13b58e2017-08-31 14:50:44 -07003670 if (DEBUG_ANIM) Slog.v(TAG,
Wale Ogunwale9d147902016-07-16 11:58:55 -07003671 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3672 mWinAnimator.mDrawState = HAS_DRAWN;
3673 mService.scheduleAnimationLocked();
3674
3675 if (mHidden) {
3676 mHidden = false;
3677 final DisplayContent displayContent = getDisplayContent();
3678
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003679 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003680 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003681 if (c.mWinAnimator.mSurfaceController != null) {
3682 c.performShowLocked();
3683 // It hadn't been shown, which means layout not performed on it, so now we
3684 // want to make sure to do a layout. If called from within the transaction
3685 // loop, this will cause it to restart with a new layout.
3686 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003687 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003688 }
3689 }
3690 }
3691 }
3692
Wale Ogunwale9d147902016-07-16 11:58:55 -07003693 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003694 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003695 }
3696
3697 return true;
3698 }
3699
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003700 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003701 if (DEBUG_VISIBILITY
Jorim Jaggie4b0f282017-05-17 15:10:29 +02003702 || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003703 Slog.v(TAG, prefix + this
3704 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07003705 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003706 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3707 + " during animation: policyVis=" + mPolicyVisibility
3708 + " parentHidden=" + isParentWindowHidden()
3709 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003710 + (mAppToken != null && mAppToken.hiddenRequested)
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003711 + " tok.hidden=" + (mAppToken != null && mAppToken.isHidden())
Jorim Jaggia5e10572017-11-15 14:36:26 +01003712 + " animationSet=" + mWinAnimator.isAnimationSet()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003713 + " tok animating="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003714 + (mAppToken != null && mAppToken.isSelfAnimating())
Wale Ogunwale9d147902016-07-16 11:58:55 -07003715 + " Callers=" + Debug.getCallers(4));
3716 }
3717 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003718
3719 WindowInfo getWindowInfo() {
3720 WindowInfo windowInfo = WindowInfo.obtain();
3721 windowInfo.type = mAttrs.type;
3722 windowInfo.layer = mLayer;
3723 windowInfo.token = mClient.asBinder();
Phil Weaver5dc3ebc2017-08-16 13:04:20 -07003724 if (mAppToken != null) {
3725 windowInfo.activityToken = mAppToken.appToken.asBinder();
3726 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003727 windowInfo.title = mAttrs.accessibilityTitle;
Phil Weaverbb2f28a2017-12-22 09:44:28 -08003728 // Panel windows have no public way to set the a11y title directly. Use the
3729 // regular title as a fallback.
3730 if (TextUtils.isEmpty(windowInfo.title)
3731 && (mAttrs.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW)
3732 && (mAttrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW)) {
3733 windowInfo.title = mAttrs.getTitle();
3734 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003735 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3736 windowInfo.focused = isFocused();
Phil Weaverf00cd142017-03-03 13:44:00 -08003737 Task task = getTask();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003738 windowInfo.inPictureInPicture = (task != null) && task.inPinnedWindowingMode();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003739
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003740 if (mIsChildWindow) {
3741 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003742 }
3743
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003744 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003745 if (childCount > 0) {
3746 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003747 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003748 }
3749 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003750 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003751 windowInfo.childTokens.add(child.mClient.asBinder());
3752 }
3753 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003754 return windowInfo;
3755 }
3756
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003757 int getHighestAnimLayer() {
3758 int highest = mWinAnimator.mAnimLayer;
3759 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003760 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003761 final int childLayer = c.getHighestAnimLayer();
3762 if (childLayer > highest) {
3763 highest = childLayer;
3764 }
3765 }
3766 return highest;
3767 }
3768
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003769 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003770 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003771 if (mChildren.isEmpty()) {
3772 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003773 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003774 }
3775
3776 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003777 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003778 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003779 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003780 }
3781 }
3782
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003783 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003784 // We want to consume the negative sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003785 // below the parent, then this window (the parent), and then the positive sublayer children
3786 // because they need to appear above the parent.
3787 int i = 0;
3788 final int count = mChildren.size();
3789 WindowState child = mChildren.get(i);
3790
3791 while (i < count && child.mSubLayer < 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003792 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003793 return true;
3794 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003795 i++;
3796 if (i >= count) {
3797 break;
3798 }
3799 child = mChildren.get(i);
3800 }
3801
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003802 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003803 return true;
3804 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003805
3806 while (i < count) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003807 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003808 return true;
3809 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003810 i++;
3811 if (i >= count) {
3812 break;
3813 }
3814 child = mChildren.get(i);
3815 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003816
3817 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003818 }
3819
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003820 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003821 // We want to consume the positive sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003822 // above the parent, then this window (the parent), and then the negative sublayer children
3823 // because they need to appear above the parent.
3824 int i = mChildren.size() - 1;
3825 WindowState child = mChildren.get(i);
3826
3827 while (i >= 0 && child.mSubLayer >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003828 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003829 return true;
3830 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003831 --i;
3832 if (i < 0) {
3833 break;
3834 }
3835 child = mChildren.get(i);
3836 }
3837
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003838 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003839 return true;
3840 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003841
3842 while (i >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003843 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003844 return true;
3845 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003846 --i;
3847 if (i < 0) {
3848 break;
3849 }
3850 child = mChildren.get(i);
3851 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003852
3853 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003854 }
3855
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003856 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
3857 boolean traverseTopToBottom) {
3858 if (traverseTopToBottom) {
3859 if (mService.mInputMethodTarget == this) {
3860 // This window is the current IME target, so we need to process the IME windows
3861 // directly above it.
3862 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
3863 return true;
3864 }
3865 }
3866 if (callback.apply(this)) {
3867 return true;
3868 }
3869 } else {
3870 if (callback.apply(this)) {
3871 return true;
3872 }
3873 if (mService.mInputMethodTarget == this) {
3874 // This window is the current IME target, so we need to process the IME windows
3875 // directly above it.
3876 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
3877 return true;
3878 }
3879 }
3880 }
3881
3882 return false;
3883 }
3884
Wale Ogunwaled1880962016-11-08 10:31:59 -08003885 WindowState getWindow(Predicate<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003886 if (mChildren.isEmpty()) {
3887 return callback.test(this) ? this : null;
3888 }
3889
3890 // We want to consume the positive sublayer children first because they need to appear
3891 // above the parent, then this window (the parent), and then the negative sublayer children
3892 // because they need to appear above the parent.
3893 int i = mChildren.size() - 1;
3894 WindowState child = mChildren.get(i);
3895
3896 while (i >= 0 && child.mSubLayer >= 0) {
3897 if (callback.test(child)) {
3898 return child;
3899 }
3900 --i;
3901 if (i < 0) {
3902 break;
3903 }
3904 child = mChildren.get(i);
3905 }
3906
Wale Ogunwaled1880962016-11-08 10:31:59 -08003907 if (callback.test(this)) {
3908 return this;
3909 }
Wale Ogunwale34247952017-02-19 11:57:53 -08003910
3911 while (i >= 0) {
3912 if (callback.test(child)) {
3913 return child;
3914 }
3915 --i;
3916 if (i < 0) {
3917 break;
3918 }
3919 child = mChildren.get(i);
3920 }
3921
3922 return null;
Wale Ogunwaled1880962016-11-08 10:31:59 -08003923 }
3924
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003925 void onExitAnimationDone() {
3926 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
3927 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
Jorim Jaggia5e10572017-11-15 14:36:26 +01003928 + " selfAnimating=" + isSelfAnimating());
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003929
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003930 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003931 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +01003932 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003933 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003934 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003935 }
3936 }
3937
3938 if (mWinAnimator.mEnteringAnimation) {
3939 mWinAnimator.mEnteringAnimation = false;
3940 mService.requestTraversal();
3941 // System windows don't have an activity and an app token as a result, but need a way
3942 // to be informed about their entrance animation end.
3943 if (mAppToken == null) {
3944 try {
3945 mClient.dispatchWindowShown();
3946 } catch (RemoteException e) {
3947 }
3948 }
3949 }
3950
Jorim Jaggia5e10572017-11-15 14:36:26 +01003951 if (isSelfAnimating()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003952 return;
3953 }
3954
Jorim Jaggia5e10572017-11-15 14:36:26 +01003955 //TODO (multidisplay): Accessibility is supported only for the default display.
3956 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
3957 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
3958 }
3959
3960 if (!mAnimatingExit) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003961 return;
3962 }
3963
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07003964 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003965 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
3966
3967 mDestroying = true;
3968
3969 final boolean hasSurface = mWinAnimator.hasSurface();
3970 if (hasSurface) {
3971 mWinAnimator.hide("onExitAnimationDone");
3972 }
3973
3974 // If we have an app token, we ask it to destroy the surface for us, so that it can take
3975 // care to ensure the activity has actually stopped and the surface is not still in use.
3976 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
3977 // transaction.
3978 if (mAppToken != null) {
3979 mAppToken.destroySurfaces();
3980 } else {
3981 if (hasSurface) {
3982 mService.mDestroySurface.add(this);
3983 }
3984 if (mRemoveOnExit) {
3985 mService.mPendingRemove.add(this);
3986 mRemoveOnExit = false;
3987 }
3988 }
3989 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07003990 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003991 }
Dan Willemsen117197f2016-07-30 13:02:59 -07003992
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003993 boolean clearAnimatingFlags() {
3994 boolean didSomething = false;
3995 // We don't want to clear it out for windows that get replaced, because the
3996 // animation depends on the flag to remove the replaced window.
3997 //
3998 // We also don't clear the mAnimatingExit flag for windows which have the
3999 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4000 // by the client. We should let animation proceed and not clear this flag or
4001 // they won't eventually be removed by WindowStateAnimator#finishExit.
4002 if (!mWillReplaceWindow && !mRemoveOnExit) {
4003 // Clear mAnimating flag together with mAnimatingExit. When animation
4004 // changes from exiting to entering, we need to clear this flag until the
4005 // new animation gets applied, so that isAnimationStarting() becomes true
4006 // until then.
4007 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4008 // placement for this window during this period, one or more frame will
4009 // show up with wrong position or scale.
4010 if (mAnimatingExit) {
4011 mAnimatingExit = false;
4012 didSomething = true;
4013 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004014 if (mDestroying) {
4015 mDestroying = false;
4016 mService.mDestroySurface.remove(this);
4017 didSomething = true;
4018 }
4019 }
4020
4021 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004022 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004023 }
4024
4025 return didSomething;
4026 }
4027
Winson4b4ba902016-07-27 19:45:52 -07004028 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004029 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004030 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004031
4032 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004033 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004034 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004035 c.hideWallpaperWindow(wasDeferred, reason);
4036 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004037 if (!mWinAnimator.mLastHidden || wasDeferred) {
4038 mWinAnimator.hide(reason);
4039 dispatchWallpaperVisibility(false);
4040 final DisplayContent displayContent = getDisplayContent();
4041 if (displayContent != null) {
4042 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
4043 }
4044 }
4045 }
4046
4047 /**
4048 * Check wallpaper window for visibility change and notify window if so.
4049 * @param visible Current visibility.
4050 */
4051 void dispatchWallpaperVisibility(final boolean visible) {
4052 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07004053 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004054
4055 // Only send notification if the visibility actually changed and we are not trying to hide
4056 // the wallpaper when we are deferring hiding of the wallpaper.
4057 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4058 mWallpaperVisible = visible;
4059 try {
4060 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4061 "Updating vis of wallpaper " + this
4062 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4063 mClient.dispatchAppVisibility(visible);
4064 } catch (RemoteException e) {
4065 }
4066 }
4067 }
4068
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004069 boolean hasVisibleNotDrawnWallpaper() {
4070 if (mWallpaperVisible && !isDrawnLw()) {
4071 return true;
4072 }
4073 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004074 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004075 if (c.hasVisibleNotDrawnWallpaper()) {
4076 return true;
4077 }
4078 }
4079 return false;
4080 }
4081
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004082 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4083 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004084 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004085 c.updateReportedVisibility(results);
4086 }
4087
4088 if (mAppFreezing || mViewVisibility != View.VISIBLE
4089 || mAttrs.type == TYPE_APPLICATION_STARTING
4090 || mDestroying) {
4091 return;
4092 }
4093 if (DEBUG_VISIBILITY) {
4094 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
4095 + ", isAnimationSet=" + mWinAnimator.isAnimationSet());
4096 if (!isDrawnLw()) {
4097 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4098 + " pv=" + mPolicyVisibility
4099 + " mDrawState=" + mWinAnimator.mDrawState
4100 + " ph=" + isParentWindowHidden()
4101 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
Jorim Jaggia5e10572017-11-15 14:36:26 +01004102 + " a=" + mWinAnimator.isAnimationSet());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004103 }
4104 }
4105
4106 results.numInteresting++;
4107 if (isDrawnLw()) {
4108 results.numDrawn++;
4109 if (!mWinAnimator.isAnimationSet()) {
4110 results.numVisible++;
4111 }
4112 results.nowGone = false;
4113 } else if (mWinAnimator.isAnimationSet()) {
4114 results.nowGone = false;
4115 }
4116 }
4117
Robert Carrfbbde852016-10-18 11:02:28 -07004118 /**
4119 * Calculate the window crop according to system decor policy. In general this is
4120 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4121 * special cases. This rectangle is in screen space.
4122 */
4123 void calculatePolicyCrop(Rect policyCrop) {
4124 final DisplayContent displayContent = getDisplayContent();
4125 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
4126
4127 if (!isDefaultDisplay()) {
4128 // On a different display there is no system decor. Crop the window
4129 // by the screen boundaries.
4130 // TODO(multi-display)
4131 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4132 policyCrop.intersect(-mCompatFrame.left, -mCompatFrame.top,
4133 displayInfo.logicalWidth - mCompatFrame.left,
4134 displayInfo.logicalHeight - mCompatFrame.top);
Robert Carrfbbde852016-10-18 11:02:28 -07004135 } else if (mDecorFrame.isEmpty()) {
4136 // Windows without policy decor aren't cropped.
4137 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4138 } else {
4139 // Crop to the system decor specified by policy.
4140 calculateSystemDecorRect(policyCrop);
4141 }
4142 }
4143
4144 /**
4145 * The system decor rect is the region of the window which is not covered
4146 * by system decorations.
4147 */
4148 private void calculateSystemDecorRect(Rect systemDecorRect) {
4149 final Rect decorRect = mDecorFrame;
4150 final int width = mFrame.width();
4151 final int height = mFrame.height();
4152
4153 // Compute the offset of the window in relation to the decor rect.
4154 final int left = mXOffset + mFrame.left;
4155 final int top = mYOffset + mFrame.top;
4156
4157 // Initialize the decor rect to the entire frame.
4158 if (isDockedResizing()) {
4159 // If we are resizing with the divider, the task bounds might be smaller than the
4160 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4161 // want in this case in order to avoid holes.
4162 //
4163 // We take care to not shrink the width, for surfaces which are larger than
4164 // the display region. Of course this area will not eventually be visible
4165 // but if we truncate the width now, we will calculate incorrectly
4166 // when adjusting to the stack bounds.
4167 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4168 systemDecorRect.set(0, 0,
4169 Math.max(width, displayInfo.logicalWidth),
4170 Math.max(height, displayInfo.logicalHeight));
4171 } else {
4172 systemDecorRect.set(0, 0, width, height);
4173 }
4174
4175 // If a freeform window is animating from a position where it would be cutoff, it would be
4176 // cutoff during the animation. We don't want that, so for the duration of the animation
4177 // we ignore the decor cropping and depend on layering to position windows correctly.
Wale Ogunwale44f036f2017-09-29 05:09:09 -07004178 final boolean cropToDecor = !(inFreeformWindowingMode() && isAnimatingLw());
Robert Carrfbbde852016-10-18 11:02:28 -07004179 if (cropToDecor) {
4180 // Intersect with the decor rect, offsetted by window position.
4181 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
4182 decorRect.right - left, decorRect.bottom - top);
4183 }
4184
4185 // If size compatibility is being applied to the window, the
4186 // surface is scaled relative to the screen. Also apply this
4187 // scaling to the crop rect. We aren't using the standard rect
4188 // scale function because we want to round things to make the crop
4189 // always round to a larger rect to ensure we don't crop too
4190 // much and hide part of the window that should be seen.
4191 if (mEnforceSizeCompat && mInvGlobalScale != 1.0f) {
4192 final float scale = mInvGlobalScale;
4193 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
4194 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
4195 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
4196 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
4197 }
4198
4199 }
4200
4201 /**
4202 * Expand the given rectangle by this windows surface insets. This
4203 * takes you from the 'window size' to the 'surface size'.
4204 * The surface insets are positive in each direction, so we inset by
4205 * the inverse.
4206 */
4207 void expandForSurfaceInsets(Rect r) {
4208 r.inset(-mAttrs.surfaceInsets.left,
4209 -mAttrs.surfaceInsets.top,
4210 -mAttrs.surfaceInsets.right,
4211 -mAttrs.surfaceInsets.bottom);
4212 }
4213
Robert Carrc91d1c32017-02-15 19:37:46 -08004214 boolean surfaceInsetsChanging() {
4215 return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets);
4216 }
4217
Bryce Leef858b572017-06-29 14:03:33 -07004218 int relayoutVisibleWindow(int result, int attrChanges, int oldVisibility) {
Robert Carrecc06b32017-04-18 14:25:10 -07004219 final boolean wasVisible = isVisibleLw();
4220
4221 result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004222 if (mAnimatingExit) {
4223 Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit="
4224 + mRemoveOnExit + ", mDestroying=" + mDestroying);
4225
4226 mWinAnimator.cancelExitAnimationForNextAnimationLocked();
4227 mAnimatingExit = false;
4228 }
4229 if (mDestroying) {
4230 mDestroying = false;
4231 mService.mDestroySurface.remove(this);
4232 }
4233 if (oldVisibility == View.GONE) {
4234 mWinAnimator.mEnterAnimationPending = true;
4235 }
4236
Andrii Kulian8ee72852017-03-10 10:36:45 -08004237 mLastVisibleLayoutRotation = getDisplayContent().getRotation();
Robert Carrc91d1c32017-02-15 19:37:46 -08004238
4239 mWinAnimator.mEnteringAnimation = true;
Bryce Leeae73ba42017-05-05 09:58:25 -07004240
Bryce Leef858b572017-06-29 14:03:33 -07004241 prepareWindowToDisplayDuringRelayout(wasVisible);
Bryce Leeae73ba42017-05-05 09:58:25 -07004242
Robert Carrc91d1c32017-02-15 19:37:46 -08004243 if ((attrChanges & FORMAT_CHANGED) != 0) {
4244 // If the format can't be changed in place, preserve the old surface until the app draws
4245 // on the new one. This prevents blinking when we change elevation of freeform and
4246 // pinned windows.
4247 if (!mWinAnimator.tryChangeFormatInPlaceLocked()) {
4248 mWinAnimator.preserveSurfaceLocked();
4249 result |= RELAYOUT_RES_SURFACE_CHANGED
4250 | RELAYOUT_RES_FIRST_TIME;
4251 }
4252 }
4253
4254 // When we change the Surface size, in scenarios which may require changing
4255 // the surface position in sync with the resize, we use a preserved surface
4256 // so we can freeze it while waiting for the client to report draw on the newly
Winson Chung8bca9e42017-04-16 15:59:43 -07004257 // sized surface. Don't preserve surfaces if the insets change while animating the pinned
4258 // stack since it can lead to issues if a new surface is created while calculating the
4259 // scale for the animation using the source hint rect
4260 // (see WindowStateAnimator#setSurfaceBoundariesLocked()).
Robert Carrc91d1c32017-02-15 19:37:46 -08004261 if (isDragResizeChanged() || isResizedWhileNotDragResizing()
Wale Ogunwale44f036f2017-09-29 05:09:09 -07004262 || (surfaceInsetsChanging() && !inPinnedWindowingMode())) {
Robert Carrc91d1c32017-02-15 19:37:46 -08004263 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
4264
4265 setDragResizing();
4266 setResizedWhileNotDragResizing(false);
4267 // We can only change top level windows to the full-screen surface when
4268 // resizing (as we only have one full-screen surface). So there is no need
4269 // to preserve and destroy windows which are attached to another, they
4270 // will keep their surface and its size may change over time.
4271 if (mHasSurface && !isChildWindow()) {
4272 mWinAnimator.preserveSurfaceLocked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08004273 result |= RELAYOUT_RES_SURFACE_CHANGED |
4274 RELAYOUT_RES_FIRST_TIME;
Robert Carrc91d1c32017-02-15 19:37:46 -08004275 }
4276 }
4277 final boolean freeformResizing = isDragResizing()
4278 && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
4279 final boolean dockedResizing = isDragResizing()
4280 && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
4281 result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0;
4282 result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004283 return result;
4284 }
4285
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004286 /**
4287 * @return True if this window has been laid out at least once; false otherwise.
4288 */
4289 boolean isLaidOut() {
4290 return mLayoutSeq != -1;
4291 }
4292
4293 /**
4294 * Updates the last inset values to the current ones.
4295 */
4296 void updateLastInsetValues() {
4297 mLastOverscanInsets.set(mOverscanInsets);
4298 mLastContentInsets.set(mContentInsets);
4299 mLastVisibleInsets.set(mVisibleInsets);
4300 mLastStableInsets.set(mStableInsets);
4301 mLastOutsets.set(mOutsets);
Adrian Roos5c6b6222017-11-07 17:36:10 +01004302 mLastDisplayCutout = mDisplayCutout;
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004303 }
4304
Jorim Jaggia5e10572017-11-15 14:36:26 +01004305 void startAnimation(Animation anim) {
4306 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4307 anim.initialize(mFrame.width(), mFrame.height(),
4308 displayInfo.appWidth, displayInfo.appHeight);
4309 anim.restrictDuration(MAX_ANIMATION_DURATION);
4310 anim.scaleCurrentDuration(mService.getWindowAnimationScaleLocked());
4311 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi2e3c31d2017-11-20 19:49:00 +01004312 new WindowAnimationSpec(anim, mSurfacePosition, false /* canSkipFirstFrame */),
4313 mService.mSurfaceAnimationRunner);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004314 startAnimation(mPendingTransaction, adapter);
4315 commitPendingTransaction();
4316 }
4317
4318 private void startMoveAnimation(Transaction t, int left, int top) {
4319 if (DEBUG_ANIM) Slog.v(TAG, "Setting move animation on " + this);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004320 final Point oldPosition = new Point();
4321 final Point newPosition = new Point();
4322 transformFrameToSurfacePosition(mLastFrame.left, mLastFrame.top, oldPosition);
4323 transformFrameToSurfacePosition(left, top, newPosition);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004324 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004325 new MoveAnimationSpec(oldPosition.x, oldPosition.y, newPosition.x, newPosition.y),
Jorim Jaggia5e10572017-11-15 14:36:26 +01004326 mService.mSurfaceAnimationRunner);
4327 startAnimation(t, adapter);
4328 }
4329
4330 private void startAnimation(Transaction t, AnimationAdapter adapter) {
4331 startAnimation(t, adapter, mWinAnimator.mLastHidden);
4332 }
4333
4334 @Override
4335 protected void onAnimationFinished() {
4336 mWinAnimator.onAnimationFinished();
4337 }
4338
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004339 /**
4340 * Retrieves the current transformation matrix of the window, relative to the display.
4341 *
4342 * @param float9 A temporary array of 9 floats.
4343 * @param outMatrix Matrix to fill in the transformation.
4344 */
4345 void getTransformationMatrix(float[] float9, Matrix outMatrix) {
4346 float9[Matrix.MSCALE_X] = mWinAnimator.mDsDx;
4347 float9[Matrix.MSKEW_Y] = mWinAnimator.mDtDx;
4348 float9[Matrix.MSKEW_X] = mWinAnimator.mDtDy;
4349 float9[Matrix.MSCALE_Y] = mWinAnimator.mDsDy;
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004350 int x = mSurfacePosition.x + mShownPosition.x;
4351 int y = mSurfacePosition.y + mShownPosition.y;
4352
4353 // If changed, also adjust transformFrameToSurfacePosition
4354 final WindowContainer parent = getParent();
4355 if (isChildWindow()) {
4356 final WindowState parentWindow = getParentWindow();
4357 x += parentWindow.mFrame.left - parentWindow.mAttrs.surfaceInsets.left;
4358 y += parentWindow.mFrame.top - parentWindow.mAttrs.surfaceInsets.top;
4359 } else if (parent != null) {
4360 final Rect parentBounds = parent.getBounds();
4361 x += parentBounds.left;
4362 y += parentBounds.top;
4363 }
4364 float9[Matrix.MTRANS_X] = x;
4365 float9[Matrix.MTRANS_Y] = y;
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004366 float9[Matrix.MPERSP_0] = 0;
4367 float9[Matrix.MPERSP_1] = 0;
4368 float9[Matrix.MPERSP_2] = 1;
4369 outMatrix.setValues(float9);
4370 }
4371
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004372 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4373 // access to its windows children. Need to investigate re-writing
4374 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4375 static final class UpdateReportedVisibilityResults {
4376 int numInteresting;
4377 int numVisible;
4378 int numDrawn;
4379 boolean nowGone = true;
4380
4381 void reset() {
4382 numInteresting = 0;
4383 numVisible = 0;
4384 numDrawn = 0;
4385 nowGone = true;
4386 }
4387 }
Robert Carraf422a82017-04-10 18:34:33 -07004388
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004389 private static final class WindowId extends IWindowId.Stub {
4390 private final WeakReference<WindowState> mOuter;
4391
4392 private WindowId(WindowState outer) {
4393
4394 // Use a weak reference for the outer class. This is important to prevent the following
4395 // leak: Since we send this class to the client process, binder will keep it alive as
4396 // long as the client keeps it alive. Now, if the window is removed, we need to clear
4397 // out our reference so even though this class is kept alive we don't leak WindowState,
4398 // which can keep a whole lot of classes alive.
4399 mOuter = new WeakReference<>(outer);
4400 }
4401
4402 @Override
4403 public void registerFocusObserver(IWindowFocusObserver observer) {
4404 final WindowState outer = mOuter.get();
4405 if (outer != null) {
4406 outer.registerFocusObserver(observer);
4407 }
4408 }
4409 @Override
4410 public void unregisterFocusObserver(IWindowFocusObserver observer) {
4411 final WindowState outer = mOuter.get();
4412 if (outer != null) {
4413 outer.unregisterFocusObserver(observer);
4414 }
4415 }
4416 @Override
4417 public boolean isFocused() {
4418 final WindowState outer = mOuter.get();
4419 return outer != null && outer.isFocused();
4420 }
4421 }
4422
Robert Carrb1579c82017-09-05 14:54:47 -07004423
4424 @Override
4425 boolean shouldMagnify() {
4426 if (mAttrs.type == TYPE_INPUT_METHOD ||
Robert Carree4d4b92017-11-22 12:21:46 -08004427 mAttrs.type == TYPE_INPUT_METHOD_DIALOG ||
4428 mAttrs.type == TYPE_MAGNIFICATION_OVERLAY ||
4429 mAttrs.type == TYPE_NAVIGATION_BAR ||
4430 // It's tempting to wonder: Have we forgotten the rounded corners overlay?
4431 // worry not: it's a fake TYPE_NAVIGATION_BAR_PANEL
4432 mAttrs.type == TYPE_NAVIGATION_BAR_PANEL ||
4433 mAttrs.type == TYPE_STATUS_BAR) {
Robert Carrb1579c82017-09-05 14:54:47 -07004434 return false;
4435 }
4436 return true;
4437 }
4438
4439 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004440 SurfaceSession getSession() {
4441 if (mSession.mSurfaceSession != null) {
4442 return mSession.mSurfaceSession;
4443 } else {
4444 return getParent().getSession();
4445 }
4446 }
4447
4448 @Override
4449 boolean needsZBoost() {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00004450 if (mIsImWindow && mService.mInputMethodTarget != null) {
4451 final AppWindowToken appToken = mService.mInputMethodTarget.mAppToken;
4452 if (appToken != null) {
4453 return appToken.needsZBoost();
4454 }
4455 }
4456 return mWillReplaceWindow;
Robert Carrb1579c82017-09-05 14:54:47 -07004457 }
4458
Robert Carrf07ef9e2017-11-21 12:12:49 -08004459 private void applyDims(Dimmer dimmer) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07004460 if (!mAnimatingExit && mAppDied) {
4461 mIsDimming = true;
4462 getDimmer().dimAbove(getPendingTransaction(), this, DEFAULT_DIM_AMOUNT_DEAD_WINDOW);
4463 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
4464 && !mAnimatingExit && isVisible()) {
4465 mIsDimming = true;
4466 getDimmer().dimBelow(getPendingTransaction(), this, mAttrs.dimAmount);
4467 }
Robert Carrf07ef9e2017-11-21 12:12:49 -08004468 }
4469
4470 @Override
4471 void prepareSurfaces() {
4472 final Dimmer dimmer = getDimmer();
4473 mIsDimming = false;
4474 if (dimmer != null) {
4475 applyDims(dimmer);
4476 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07004477
Jorim Jaggia5e10572017-11-15 14:36:26 +01004478 updateSurfacePosition(mPendingTransaction);
4479
Robert Carrb1579c82017-09-05 14:54:47 -07004480 mWinAnimator.prepareSurfaceLocked(true);
4481 super.prepareSurfaces();
4482 }
4483
4484 @Override
Jorim Jaggia5e10572017-11-15 14:36:26 +01004485 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
4486 super.onAnimationLeashCreated(t, leash);
4487
4488 // Leash is now responsible for position, so set our position to 0.
4489 t.setPosition(mSurfaceControl, 0, 0);
4490 }
4491
4492 @Override
4493 public void onAnimationLeashDestroyed(Transaction t) {
4494 super.onAnimationLeashDestroyed(t);
4495 updateSurfacePosition(t);
4496 }
4497
chaviwe07246a2017-12-12 16:18:29 -08004498 @Override
Jorim Jaggia5e10572017-11-15 14:36:26 +01004499 void updateSurfacePosition(Transaction t) {
4500 if (mSurfaceControl == null) {
4501 return;
4502 }
4503
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004504 transformFrameToSurfacePosition(mFrame.left, mFrame.top, mSurfacePosition);
Jorim Jaggid70feb22018-01-08 17:33:30 +01004505 if (!mSurfaceAnimator.hasLeash()) {
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004506 t.setPosition(mSurfaceControl, mSurfacePosition.x, mSurfacePosition.y);
4507 }
4508 }
4509
4510 private void transformFrameToSurfacePosition(int left, int top, Point outPoint) {
4511 outPoint.set(left, top);
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004512
4513 // If changed, also adjust getTransformationMatrix
chaviwe07246a2017-12-12 16:18:29 -08004514 final WindowContainer parentWindowContainer = getParent();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004515 if (isChildWindow()) {
4516 // TODO: This probably falls apart at some point and we should
4517 // actually compute relative coordinates.
Jorim Jaggi50d3f8f2017-12-27 17:41:25 +01004518
4519 // Since the parent was outset by its surface insets, we need to undo the outsetting
4520 // with insetting by the same amount.
Jorim Jaggia5e10572017-11-15 14:36:26 +01004521 final WindowState parent = getParentWindow();
Jorim Jaggi50d3f8f2017-12-27 17:41:25 +01004522 outPoint.offset(-parent.mFrame.left + parent.mAttrs.surfaceInsets.left,
4523 -parent.mFrame.top + parent.mAttrs.surfaceInsets.top);
chaviwe07246a2017-12-12 16:18:29 -08004524 } else if (parentWindowContainer != null) {
4525 final Rect parentBounds = parentWindowContainer.getBounds();
4526 outPoint.offset(-parentBounds.left, -parentBounds.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004527 }
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004528
4529 // Expand for surface insets. See WindowState.expandForSurfaceInsets.
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004530 outPoint.offset(-mAttrs.surfaceInsets.left, -mAttrs.surfaceInsets.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004531 }
4532
4533 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004534 void assignLayer(Transaction t, int layer) {
4535 // See comment in assignRelativeLayerForImeTargetChild
4536 if (!isChildWindow()
4537 || (mService.mInputMethodTarget != getParentWindow())
4538 || !inSplitScreenWindowingMode()) {
4539 super.assignLayer(t, layer);
4540 return;
4541 }
4542 getDisplayContent().assignRelativeLayerForImeTargetChild(t, this);
4543 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07004544
4545 @Override
4546 public boolean isDimming() {
4547 return mIsDimming;
4548 }
Robert Carr0eff1872017-12-01 14:27:04 -08004549
4550 // TODO(b/70040778): We should aim to eliminate the last user of TYPE_APPLICATION_MEDIA
4551 // then we can drop all negative layering on the windowing side and simply inherit
4552 // the default implementation here.
4553 public void assignChildLayers(Transaction t) {
4554 int layer = 1;
4555 for (int i = 0; i < mChildren.size(); i++) {
4556 final WindowState w = mChildren.get(i);
4557
4558 // APPLICATION_MEDIA_OVERLAY needs to go above APPLICATION_MEDIA
4559 // while they both need to go below the main window. However the
4560 // relative layering of multiple APPLICATION_MEDIA/OVERLAY has never
4561 // been defined and so we can use static layers and leave it that way.
4562 if (w.mAttrs.type == TYPE_APPLICATION_MEDIA) {
4563 w.assignLayer(t, -2);
4564 } else if (w.mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) {
4565 w.assignLayer(t, -1);
4566 } else {
4567 w.assignLayer(t, layer);
4568 }
4569 w.assignChildLayers(t);
4570 layer++;
4571 }
4572 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01004573
4574 private final class MoveAnimationSpec implements AnimationSpec {
4575
4576 private final long mDuration;
4577 private Interpolator mInterpolator;
4578 private Point mFrom = new Point();
4579 private Point mTo = new Point();
4580
4581 private MoveAnimationSpec(int fromX, int fromY, int toX, int toY) {
4582 final Animation anim = AnimationUtils.loadAnimation(mContext,
4583 com.android.internal.R.anim.window_move_from_decor);
Jorim Jaggi08f75cf2018-01-08 14:38:53 +01004584 mDuration = (long)
4585 (anim.computeDurationHint() * mService.getWindowAnimationScaleLocked());
Jorim Jaggia5e10572017-11-15 14:36:26 +01004586 mInterpolator = anim.getInterpolator();
4587 mFrom.set(fromX, fromY);
4588 mTo.set(toX, toY);
4589 }
4590
4591 @Override
4592 public long getDuration() {
4593 return mDuration;
4594 }
4595
4596 @Override
4597 public void apply(Transaction t, SurfaceControl leash, long currentPlayTime) {
4598 final float fraction = (float) currentPlayTime / getDuration();
4599 final float v = mInterpolator.getInterpolation(fraction);
4600 t.setPosition(leash, mFrom.x + (mTo.x - mFrom.x) * v,
4601 mFrom.y + (mTo.y - mFrom.y) * v);
4602 }
4603 }
satokcef37fb2011-10-24 21:49:38 +09004604}