blob: f47d96b044be26d1d47d533410f14c05ac052304 [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;
Adrian Roos4d18a2e2017-12-19 19:08:05 +010023import static android.view.View.SYSTEM_UI_FLAG_FULLSCREEN;
24import static android.view.View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
Jorim Jaggi02886a82016-12-06 09:10:06 -080025import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
26import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
27import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
28import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
29import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
30import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW;
Adrian Roos4d18a2e2017-12-19 19:08:05 +010031import static android.view.WindowManager.LayoutParams.FLAG2_LAYOUT_IN_DISPLAY_CUTOUT_AREA;
Jorim Jaggi02886a82016-12-06 09:10:06 -080032import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
33import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
34import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
35import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Adrian Roos4d18a2e2017-12-19 19:08:05 +010036import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN;
Jorim Jaggi02886a82016-12-06 09:10:06 -080037import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
38import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
39import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
40import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080041import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
42import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
43import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Robert Carrc91d1c32017-02-15 19:37:46 -080044import static android.view.WindowManager.LayoutParams.FORMAT_CHANGED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080045import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
46import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
47import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070048import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Jorim Jaggi02886a82016-12-06 09:10:06 -080049import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
50import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
51import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
52import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
53import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
54import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Robert Carr0eff1872017-12-01 14:27:04 -080055import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;
Vishnu Nair1d0fa072018-01-04 07:53:00 -080056import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080057import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
58import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
59import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
60import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
61import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
62import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Robert Carrb1579c82017-09-05 14:54:47 -070063import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY;
64import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
Robert Carree4d4b92017-11-22 12:21:46 -080065import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;
Robert Carrb1579c82017-09-05 14:54:47 -070066import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070067import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Jorim Jaggi02886a82016-12-06 09:10:06 -080068import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070069import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType;
Robert Carrc91d1c32017-02-15 19:37:46 -080070import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED;
71import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM;
72import static android.view.WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME;
73import static android.view.WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED;
Adrian Roose99bc052017-11-20 17:55:31 +010074import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
75import static com.android.server.policy.WindowManagerPolicy.TRANSIT_ENTER;
76import static com.android.server.policy.WindowManagerPolicy.TRANSIT_EXIT;
77import static com.android.server.policy.WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
Jorim Jaggi02886a82016-12-06 09:10:06 -080078import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
79import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
80import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
81import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
82import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
83import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
84import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
85import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
86import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Jorim Jaggi02886a82016-12-06 09:10:06 -080087import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
88import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
89import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
90import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
91import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +020092import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Jorim Jaggi02886a82016-12-06 09:10:06 -080093import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080094import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
95import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
96import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
97import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
Jorim Jaggia5e10572017-11-15 14:36:26 +010098import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
Jorim Jaggi02886a82016-12-06 09:10:06 -080099import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
100import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
101import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
102import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
103import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
104import static com.android.server.wm.WindowManagerService.localLOGV;
105import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING;
106import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
107import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN;
108import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700109import static com.android.server.wm.proto.IdentifierProto.HASH_CODE;
110import static com.android.server.wm.proto.IdentifierProto.TITLE;
111import static com.android.server.wm.proto.IdentifierProto.USER_ID;
112import static com.android.server.wm.proto.WindowStateProto.ANIMATING_EXIT;
113import static com.android.server.wm.proto.WindowStateProto.ANIMATOR;
114import static com.android.server.wm.proto.WindowStateProto.ATTRIBUTES;
115import static com.android.server.wm.proto.WindowStateProto.CHILD_WINDOWS;
116import static com.android.server.wm.proto.WindowStateProto.CONTAINING_FRAME;
117import static com.android.server.wm.proto.WindowStateProto.CONTENT_FRAME;
118import static com.android.server.wm.proto.WindowStateProto.CONTENT_INSETS;
Vishnu Nair1d0fa072018-01-04 07:53:00 -0800119import static com.android.server.wm.proto.WindowStateProto.CUTOUT;
120import static com.android.server.wm.proto.WindowStateProto.DECOR_FRAME;
121import static com.android.server.wm.proto.WindowStateProto.DESTROYING;
122import static com.android.server.wm.proto.WindowStateProto.DISPLAY_FRAME;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700123import static com.android.server.wm.proto.WindowStateProto.DISPLAY_ID;
124import static com.android.server.wm.proto.WindowStateProto.FRAME;
125import static com.android.server.wm.proto.WindowStateProto.GIVEN_CONTENT_INSETS;
Vishnu Nair1d0fa072018-01-04 07:53:00 -0800126import static com.android.server.wm.proto.WindowStateProto.HAS_SURFACE;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700127import static com.android.server.wm.proto.WindowStateProto.IDENTIFIER;
Vishnu Nair1d0fa072018-01-04 07:53:00 -0800128import static com.android.server.wm.proto.WindowStateProto.IS_ON_SCREEN;
129import static com.android.server.wm.proto.WindowStateProto.IS_READY_FOR_DISPLAY;
130import static com.android.server.wm.proto.WindowStateProto.IS_VISIBLE;
131import static com.android.server.wm.proto.WindowStateProto.OUTSETS;
132import static com.android.server.wm.proto.WindowStateProto.OUTSET_FRAME;
133import static com.android.server.wm.proto.WindowStateProto.OVERSCAN_FRAME;
134import static com.android.server.wm.proto.WindowStateProto.OVERSCAN_INSETS;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700135import static com.android.server.wm.proto.WindowStateProto.PARENT_FRAME;
Vishnu Nair1d0fa072018-01-04 07:53:00 -0800136import static com.android.server.wm.proto.WindowStateProto.REMOVED;
137import static com.android.server.wm.proto.WindowStateProto.REMOVE_ON_EXIT;
138import static com.android.server.wm.proto.WindowStateProto.REQUESTED_HEIGHT;
139import static com.android.server.wm.proto.WindowStateProto.REQUESTED_WIDTH;
Jorim Jaggi45be1c4c2017-12-15 18:44:43 +0100140import static com.android.server.wm.proto.WindowStateProto.SHOWN_POSITION;
Vishnu Nair1d0fa072018-01-04 07:53:00 -0800141import static com.android.server.wm.proto.WindowStateProto.STABLE_INSETS;
142import static com.android.server.wm.proto.WindowStateProto.STACK_ID;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700143import static com.android.server.wm.proto.WindowStateProto.SURFACE_INSETS;
Jorim Jaggi45be1c4c2017-12-15 18:44:43 +0100144import static com.android.server.wm.proto.WindowStateProto.SURFACE_POSITION;
Vishnu Nair1d0fa072018-01-04 07:53:00 -0800145import static com.android.server.wm.proto.WindowStateProto.SYSTEM_UI_VISIBILITY;
146import static com.android.server.wm.proto.WindowStateProto.VIEW_VISIBILITY;
147import static com.android.server.wm.proto.WindowStateProto.VISIBLE_FRAME;
148import static com.android.server.wm.proto.WindowStateProto.VISIBLE_INSETS;
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700149import static com.android.server.wm.proto.WindowStateProto.WINDOW_CONTAINER;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800150
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700151import android.annotation.CallSuper;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800152import android.app.AppOpsManager;
153import android.content.Context;
154import android.content.res.Configuration;
155import android.graphics.Matrix;
156import android.graphics.PixelFormat;
157import android.graphics.Point;
158import android.graphics.Rect;
159import android.graphics.Region;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700160import android.os.Binder;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700161import android.os.Debug;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800162import android.os.IBinder;
163import android.os.PowerManager;
164import android.os.RemoteCallbackList;
165import android.os.RemoteException;
166import android.os.SystemClock;
167import android.os.Trace;
168import android.os.UserHandle;
169import android.os.WorkSource;
Phil Weaverbb2f28a2017-12-22 09:44:28 -0800170import android.text.TextUtils;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800171import android.util.DisplayMetrics;
Jorim Jaggie7d2b852017-08-28 17:55:15 +0200172import android.util.MergedConfiguration;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800173import android.util.Slog;
174import android.util.TimeUtils;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700175import android.util.proto.ProtoOutputStream;
Adrian Roos5c6b6222017-11-07 17:36:10 +0100176import android.view.DisplayCutout;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800177import android.view.DisplayInfo;
178import android.view.Gravity;
179import android.view.IApplicationToken;
180import android.view.IWindow;
181import android.view.IWindowFocusObserver;
182import android.view.IWindowId;
183import android.view.InputChannel;
184import android.view.InputEvent;
185import android.view.InputEventReceiver;
Robert Carrb1579c82017-09-05 14:54:47 -0700186import android.view.SurfaceControl;
187import android.view.SurfaceSession;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800188import android.view.View;
189import android.view.ViewTreeObserver;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700190import android.view.WindowInfo;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800191import android.view.WindowManager;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100192import android.view.animation.Animation;
193import android.view.animation.AnimationUtils;
194import android.view.animation.Interpolator;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800195
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800196import com.android.internal.util.ToBooleanFunction;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800197import com.android.server.input.InputWindowHandle;
Adrian Roose99bc052017-11-20 17:55:31 +0100198import com.android.server.policy.WindowManagerPolicy;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100199import com.android.server.wm.LocalAnimationAdapter.AnimationSpec;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800200
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800201import java.io.PrintWriter;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200202import java.lang.ref.WeakReference;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800203import java.util.ArrayList;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700204import java.util.Comparator;
Wale Ogunwaled1880962016-11-08 10:31:59 -0800205import java.util.function.Predicate;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800206
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700207/** A window in the window manager. */
208class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800209 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800210
Skuhne81c524a2015-08-12 13:34:14 -0700211 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700212 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
213 // use hard-coded min sizes for now.
214 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
215 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700216
217 // The thickness of a window resize handle outside the window bounds on the free form workspace
218 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700219 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700220
Craig Mautnere7ae2502012-03-26 17:11:19 -0700221 final WindowManagerPolicy mPolicy;
222 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800223 final Session mSession;
224 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800225 final int mAppOp;
226 // UserId and appId of the owner. Don't display windows of non-current user.
227 final int mOwnerUid;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800228 /** The owner has {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} */
229 final boolean mOwnerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200230 final WindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800231 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700232 // The same object as mToken if this is an app window and null for non-app windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800233 AppWindowToken mAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700234
235 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
236 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800237 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
238 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700239 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800240 final int mBaseLayer;
241 final int mSubLayer;
242 final boolean mLayoutAttached;
243 final boolean mIsImWindow;
244 final boolean mIsWallpaper;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700245 private final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700246 int mSeq;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700247 boolean mEnforceSizeCompat;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800248 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700249 int mSystemUiVisibility;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700250 /**
251 * The visibility of the window based on policy like {@link WindowManagerPolicy}.
252 * Normally set by calling {@link #showLw} and {@link #hideLw}.
253 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800254 boolean mPolicyVisibility = true;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700255 /**
256 * What {@link #mPolicyVisibility} should be set to after a transition animation.
257 * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and
258 * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit
259 * animation is done.
260 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800261 boolean mPolicyVisibilityAfterAnim = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700262 private boolean mAppOpVisibility = true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700263 boolean mPermanentlyHidden; // the window should never be shown again
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700264 // This is a non-system overlay window that is currently force hidden.
265 private boolean mForceHideNonSystemOverlayWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800266 boolean mAppFreezing;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700267 boolean mHidden; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800268 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700269 private boolean mDragResizing;
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200270 private boolean mDragResizingChangeReported = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700271 private int mResizeMode;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700272
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700273 private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800274
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700275 /**
276 * The window size that was requested by the application. These are in
277 * the application's coordinate space (without compatibility scale applied).
278 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800279 int mRequestedWidth;
280 int mRequestedHeight;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700281 private int mLastRequestedWidth;
282 private int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700283
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800284 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800285 boolean mHaveFrame;
286 boolean mObscured;
287 boolean mTurnOnScreen;
288
289 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700290
Andrii Kulian9d91ca62016-09-29 22:28:09 -0700291 /**
292 * Used to store last reported to client configuration and check if we have newer available.
293 * We'll send configuration to client only if it is different from the last applied one and
294 * client won't perform unnecessary updates.
295 */
Bryce Lee2b17afd2017-09-21 10:38:20 -0700296 private final MergedConfiguration mLastReportedConfiguration = new MergedConfiguration();
Craig Mautnera2c77052012-03-26 12:14:43 -0700297
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700298 /**
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700299 * Actual position of the surface shown on-screen (may be modified by animation). These are
300 * in the screen's coordinate space (WITH the compatibility scale applied).
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700301 */
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -0700302 final Point mShownPosition = new Point();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800303
304 /**
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700305 * Insets that determine the actually visible area. These are in the application's
306 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800307 */
308 final Rect mVisibleInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700309 private final Rect mLastVisibleInsets = new Rect();
310 private boolean mVisibleInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800311
312 /**
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700313 * Insets that are covered by system windows (such as the status bar) and
314 * transient docking windows (such as the IME). These are in the application's
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700315 * coordinate space (without compatibility scale applied).
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800316 */
317 final Rect mContentInsets = new Rect();
318 final Rect mLastContentInsets = new Rect();
Robert Carr18f622f2017-05-08 11:20:43 -0700319
320 /**
321 * The last content insets returned to the client in relayout. We use
322 * these in the bounds animation to ensure we only observe inset changes
323 * at the same time that a client resizes it's surface so that we may use
324 * the geometryAppliesWithResize synchronization mechanism to keep
325 * the contents in place.
326 */
327 final Rect mLastRelayoutContentInsets = new Rect();
328
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700329 private boolean mContentInsetsChanged;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800330
331 /**
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800332 * Insets that determine the area covered by the display overscan region. These are in the
333 * application's coordinate space (without compatibility scale applied).
334 */
335 final Rect mOverscanInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700336 private final Rect mLastOverscanInsets = new Rect();
337 private boolean mOverscanInsetsChanged;
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800338
339 /**
Adrian Roosfa104232014-06-20 16:10:14 -0700340 * Insets that determine the area covered by the stable system windows. These are in the
341 * application's coordinate space (without compatibility scale applied).
342 */
343 final Rect mStableInsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700344 private final Rect mLastStableInsets = new Rect();
345 private boolean mStableInsetsChanged;
Adrian Roosfa104232014-06-20 16:10:14 -0700346
347 /**
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700348 * Outsets determine the area outside of the surface where we want to pretend that it's possible
349 * to draw anyway.
350 */
351 final Rect mOutsets = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700352 private final Rect mLastOutsets = new Rect();
353 private boolean mOutsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700354
Adrian Roos5c6b6222017-11-07 17:36:10 +0100355 /** Part of the display that has been cut away. See {@link DisplayCutout}. */
356 DisplayCutout mDisplayCutout = DisplayCutout.NO_CUTOUT;
357 private DisplayCutout mLastDisplayCutout = DisplayCutout.NO_CUTOUT;
358 private boolean mDisplayCutoutChanged;
359
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700360 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800361 * Set to true if we are waiting for this window to receive its
362 * given internal insets before laying out other windows based on it.
363 */
364 boolean mGivenInsetsPending;
365
366 /**
367 * These are the content insets that were given during layout for
368 * this window, to be applied to windows behind it.
369 */
370 final Rect mGivenContentInsets = new Rect();
371
372 /**
373 * These are the visible insets that were given during layout for
374 * this window, to be applied to windows behind it.
375 */
376 final Rect mGivenVisibleInsets = new Rect();
377
378 /**
379 * This is the given touchable area relative to the window frame, or null if none.
380 */
381 final Region mGivenTouchableRegion = new Region();
382
383 /**
384 * Flag indicating whether the touchable region should be adjusted by
385 * the visible insets; if false the area outside the visible insets is
386 * NOT touchable, so we must use those to adjust the frame during hit
387 * tests.
388 */
389 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
390
391 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400392 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700393 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800394 float mHScale=1, mVScale=1;
395 float mLastHScale=1, mLastVScale=1;
396 final Matrix mTmpMatrix = new Matrix();
397
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700398 // "Real" frame that the application sees, in display coordinate space.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800399 final Rect mFrame = new Rect();
400 final Rect mLastFrame = new Rect();
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700401 private boolean mFrameSizeChanged = false;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700402 // Frame that is scaled to the application's coordinate space when in
403 // screen size compatibility mode.
404 final Rect mCompatFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800405
406 final Rect mContainingFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700407
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700408 private final Rect mParentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700409
Wale Ogunwale94596652015-02-06 19:27:34 -0800410 // The entire screen area of the {@link TaskStack} this window is in. Usually equal to the
411 // screen area of the device.
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700412 final Rect mDisplayFrame = new Rect();
413
414 // The region of the display frame that the display type supports displaying content on. This
415 // is mostly a special case for TV where some displays don’t have the entire display usable.
416 // {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_OVERSCAN} flag can be used to allow
417 // window display contents to extend into the overscan region.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700418 private final Rect mOverscanFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700419
420 // The display frame minus the stable insets. This value is always constant regardless of if
421 // the status bar or navigation bar is visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700422 private final Rect mStableFrame = new Rect();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800423
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700424 // The area not occupied by the status and navigation bars. So, if both status and navigation
425 // bars are visible, the decor frame is equal to the stable frame.
426 final Rect mDecorFrame = new Rect();
427
428 // Equal to the decor frame if the IME (e.g. keyboard) is not present. Equal to the decor frame
429 // minus the area occupied by the IME if the IME is present.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700430 private final Rect mContentFrame = new Rect();
Wale Ogunwalec6061fa2014-10-21 13:15:11 -0700431
432 // Legacy stuff. Generally equal to the content frame expect when the IME for older apps
433 // displays hint text.
434 final Rect mVisibleFrame = new Rect();
435
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700436 // Frame that includes dead area outside of the surface but where we want to pretend that it's
437 // possible to draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700438 private final Rect mOutsetFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700439
Jorim Jaggidc249c42015-12-15 14:57:31 -0800440 /**
441 * Usually empty. Set to the task's tempInsetFrame. See
442 *{@link android.app.IActivityManager#resizeDockedStack}.
443 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700444 private final Rect mInsetFrame = new Rect();
Jorim Jaggidc249c42015-12-15 14:57:31 -0800445
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800446 boolean mContentChanged;
447
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800448 // If a window showing a wallpaper: the requested offset for the
449 // wallpaper; if a wallpaper window: the currently applied offset.
450 float mWallpaperX = -1;
451 float mWallpaperY = -1;
452
453 // If a window showing a wallpaper: what fraction of the offset
454 // range corresponds to a full virtual screen.
455 float mWallpaperXStep = -1;
456 float mWallpaperYStep = -1;
457
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700458 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
459 // to its window; if a wallpaper window: not used.
460 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
461 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
462
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800463 // Wallpaper windows: pixels offset based on above variables.
464 int mXOffset;
465 int mYOffset;
466
Craig Mautner2268e7e2012-12-13 15:40:00 -0800467 /**
468 * This is set after IWindowSession.relayout() has been called at
469 * least once for the window. It allows us to detect the situation
470 * where we don't yet have a surface, but should have one soon, so
471 * we can give the window focus before waiting for the relayout.
472 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800473 boolean mRelayoutCalled;
474
Robert Carrfed10072016-05-26 11:48:49 -0700475 boolean mInRelayout;
476
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800477 /**
478 * If the application has called relayout() with changes that can
479 * impact its window's size, we need to perform a layout pass on it
480 * even if it is not currently visible for layout. This is set
481 * when in that case until the layout is done.
482 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800483 boolean mLayoutNeeded;
484
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800485 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800486 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800487
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800488 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800489 boolean mDestroying;
490
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800491 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800492 boolean mRemoveOnExit;
493
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800494 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800495 * Whether the app died while it was visible, if true we might need
496 * to continue to show it until it's restarted.
497 */
498 boolean mAppDied;
499
500 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800501 * Set when the orientation is changing and this window has not yet
502 * been updated for the new orientation.
503 */
Bryce Lee8c3cf382017-07-06 19:47:10 -0700504 private boolean mOrientationChanging;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800505
Dianne Hackborna57c6952013-03-29 14:46:40 -0700506 /**
Robert Carr9c1c3a02017-08-08 12:59:01 -0700507 * Sometimes in addition to the mOrientationChanging
508 * flag we report that the orientation is changing
509 * due to a mismatch in current and reported configuration.
510 *
511 * In the case of timeout we still need to make sure we
512 * leave the orientation changing state though, so we
513 * use this as a special time out escape hatch.
514 */
515 private boolean mOrientationChangeTimedOut;
516
517 /**
Robert Carr237028a2016-07-26 10:39:45 -0700518 * The orientation during the last visible call to relayout. If our
519 * current orientation is different, the window can't be ready
520 * to be shown.
521 */
522 int mLastVisibleLayoutRotation = -1;
523
524 /**
Andrii Kulianb2e37802017-01-11 00:36:44 -0800525 * Set when we need to report the orientation change to client to trigger a relayout.
526 */
527 boolean mReportOrientationChanged;
528
529 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700530 * How long we last kept the screen frozen.
531 */
532 int mLastFreezeDuration;
533
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800534 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800535 boolean mRemoved;
536
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800537 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800538 * It is save to remove the window and destroy the surface because the client requested removal
539 * or some other higher level component said so (e.g. activity manager).
540 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800541 */
Svetoslav Ganov200adfb2016-10-18 13:29:27 -0700542 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800543
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800544 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700545 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800546 InputChannel mInputChannel;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700547 private InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800548
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800549 // Used to improve performance of toString()
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700550 private String mStringNameCache;
551 private CharSequence mLastTitle;
552 private boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800553
Craig Mautnera2c77052012-03-26 12:14:43 -0700554 final WindowStateAnimator mWinAnimator;
555
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700556 boolean mHasSurface = false;
557
Craig Mautner88400d32012-09-30 12:35:45 -0700558 /** When true this window can be displayed on screens owther than mOwnerUid's */
559 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700560
Chong Zhang92147042016-05-09 12:47:11 -0700561 // Whether the window was visible when we set the app to invisible last time. WM uses
562 // this as a hint to restore the surface (if available) for early animation next time
563 // the app is brought visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700564 private boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800565
Robert Carra1eb4392015-12-10 12:43:51 -0800566 // This window will be replaced due to relaunch. This allows window manager
567 // to differentiate between simple removal of a window and replacement. In the latter case it
568 // will preserve the old window until the new one is drawn.
569 boolean mWillReplaceWindow = false;
570 // If true, the replaced window was already requested to be removed.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700571 private boolean mReplacingRemoveRequested = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800572 // Whether the replacement of the window should trigger app transition animation.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700573 private boolean mAnimateReplacingWindow = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800574 // If not null, the window that will be used to replace the old one. This is being set when
575 // the window is added and unset when this window reports its first draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700576 private WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700577 // For the new window in the replacement transition, if we have
578 // requested to replace without animation, then we should
579 // make sure we also don't apply an enter animation for
580 // the new window.
581 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800582 // Whether this window is being moved via the resize API
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700583 private boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800584
Jeff Brownc2932a12014-11-20 18:04:05 -0800585 /**
586 * Wake lock for drawing.
587 * Even though it's slightly more expensive to do so, we will use a separate wake lock
588 * for each app that is requesting to draw while dozing so that we can accurately track
589 * who is preventing the system from suspending.
590 * This lock is only acquired on first use.
591 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700592 private PowerManager.WakeLock mDrawLock;
Jeff Brownc2932a12014-11-20 18:04:05 -0800593
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700594 final private Rect mTmpRect = new Rect();
595
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800596 /**
597 * Whether the window was resized by us while it was gone for layout.
598 */
599 boolean mResizedWhileGone = false;
600
Andrii Kulianeb1d3222016-05-16 15:17:55 -0700601 /** @see #isResizedWhileNotDragResizing(). */
602 private boolean mResizedWhileNotDragResizing;
603
604 /** @see #isResizedWhileNotDragResizingReported(). */
605 private boolean mResizedWhileNotDragResizingReported;
Jorim Jaggif3df0aa2016-04-06 15:56:33 -0700606
Robert Carr6da3cc02016-06-16 15:17:07 -0700607 /**
608 * During seamless rotation we have two phases, first the old window contents
609 * are rotated to look as if they didn't move in the new coordinate system. Then we
610 * have to freeze updates to this layer (to preserve the transformation) until
611 * the resize actually occurs. This is true from when the transformation is set
612 * and false until the transaction to resize is sent.
613 */
614 boolean mSeamlesslyRotated = false;
615
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700616 /**
Robert Carrc91d1c32017-02-15 19:37:46 -0800617 * Surface insets from the previous call to relayout(), used to track
618 * if we are changing the Surface insets.
619 */
620 final Rect mLastSurfaceInsets = new Rect();
621
622 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700623 * A flag set by the {@link WindowState} parent to indicate that the parent has examined this
624 * {@link WindowState} in its overall drawing context. This book-keeping allows the parent to
625 * make sure all children have been considered.
626 */
627 private boolean mDrawnStateEvaluated;
628
Jorim Jaggia5e10572017-11-15 14:36:26 +0100629 private final Point mSurfacePosition = new Point();
630
Bryce Leed390deb2017-06-22 13:14:28 -0700631 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700632 * 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 -0700633 * of z-order and 1 otherwise.
634 */
Griff Hazen51d00d82016-11-22 15:39:24 -0800635 private static final Comparator<WindowState> sWindowSubLayerComparator =
636 new Comparator<WindowState>() {
637 @Override
638 public int compare(WindowState w1, WindowState w2) {
639 final int layer1 = w1.mSubLayer;
640 final int layer2 = w2.mSubLayer;
641 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
642 // We insert the child window into the list ordered by
643 // the sub-layer. For same sub-layers, the negative one
644 // should go below others; the positive one should go
645 // above others.
646 return -1;
647 }
648 return 1;
649 };
650 };
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700651
Robert Carrf59b8dd2017-10-02 18:58:36 -0700652 /**
653 * Indicates whether we have requested a Dim (in the sense of {@link Dimmer}) from our host
654 * container.
655 */
656 private boolean mIsDimming = false;
657
658 private static final float DEFAULT_DIM_AMOUNT_DEAD_WINDOW = 0.5f;
659
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800660 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700661 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800662 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100663 super(service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800664 mSession = s;
665 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800666 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800667 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700668 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700669 mOwnerUid = ownerId;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800670 mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200671 mWindowId = new WindowId(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800672 mAttrs.copyFrom(a);
673 mViewVisibility = viewVisibility;
Craig Mautnere7ae2502012-03-26 17:11:19 -0700674 mPolicy = mService.mPolicy;
675 mContext = mService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800676 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700677 mSeq = seq;
Adam Lesinski95c42972013-10-02 10:13:27 -0700678 mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700679 if (localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700680 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700681 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800682 try {
683 c.asBinder().linkToDeath(deathRecipient, 0);
684 } catch (RemoteException e) {
685 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700686 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800687 mLayoutAttached = false;
688 mIsImWindow = false;
689 mIsWallpaper = false;
690 mIsFloatingLayer = false;
691 mBaseLayer = 0;
692 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700693 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700694 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800695 return;
696 }
697 mDeathRecipient = deathRecipient;
698
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700699 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800700 // The multiplier here is to reserve space for multiple
701 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800702 mBaseLayer = mPolicy.getWindowLayerLw(parentWindow)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700703 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800704 mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700705 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900706
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700707 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow);
708 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900709
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800710 mLayoutAttached = mAttrs.type !=
711 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700712 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
713 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
714 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800715 } else {
716 // The multiplier here is to reserve space for multiple
717 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800718 mBaseLayer = mPolicy.getWindowLayerLw(this)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700719 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800720 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700721 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800722 mLayoutAttached = false;
723 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
724 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
725 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800726 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700727 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800728
Wale Ogunwale72919d22016-12-08 18:58:50 -0800729 if (mAppToken != null && mAppToken.mShowForAllUsers) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700730 // Windows for apps that can show for all users should also show when the device is
731 // locked.
732 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
Craig Mautner19ab8282014-05-07 10:35:34 -0700733 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800734
Craig Mautner322e4032012-07-13 13:35:20 -0700735 mWinAnimator = new WindowStateAnimator(this);
736 mWinAnimator.mAlpha = a.alpha;
737
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800738 mRequestedWidth = 0;
739 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700740 mLastRequestedWidth = 0;
741 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800742 mXOffset = 0;
743 mYOffset = 0;
744 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800745 mInputWindowHandle = new InputWindowHandle(
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800746 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this, c,
747 getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800748 }
749
750 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700751 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800752 mSession.windowAddedLocked(mAttrs.packageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800753 }
754
Bryce Leed390deb2017-06-22 13:14:28 -0700755 /**
756 * Returns whether this {@link WindowState} has been considered for drawing by its parent.
757 */
Bryce Lee6311c4b2017-07-06 14:09:29 -0700758 boolean getDrawnStateEvaluated() {
Bryce Leed390deb2017-06-22 13:14:28 -0700759 return mDrawnStateEvaluated;
760 }
761
762 /**
763 * Sets whether this {@link WindowState} has been considered for drawing by its parent. Should
764 * be cleared when detached from parent.
765 */
766 void setDrawnStateEvaluated(boolean evaluated) {
767 mDrawnStateEvaluated = evaluated;
768 }
769
770 @Override
771 void onParentSet() {
772 super.onParentSet();
773 setDrawnStateEvaluated(false /*evaluated*/);
774 }
775
Craig Mautnera2c77052012-03-26 12:14:43 -0700776 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800777 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800778 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800779 }
780
781 @Override
782 public String getOwningPackage() {
783 return mAttrs.packageName;
784 }
785
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800786 @Override
787 public boolean canAddInternalSystemWindow() {
788 return mOwnerCanAddInternalSystemWindow;
789 }
790
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200791 @Override
792 public boolean canAcquireSleepToken() {
793 return mSession.mCanAcquireSleepToken;
794 }
795
Jorim Jaggif5834272016-04-04 20:25:41 -0700796 /**
797 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
798 * from {@param frame}. In other words, it applies the insets that would result if
799 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700800 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
801 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700802 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700803 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
804 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
805 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
806 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
807 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700808 frame.inset(left, top, right, bottom);
809 }
810
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800811 @Override
Robert Carr43521762016-10-28 13:15:04 -0700812 public void computeFrameLw(Rect parentFrame, Rect displayFrame, Rect overscanFrame,
813 Rect contentFrame, Rect visibleFrame, Rect decorFrame, Rect stableFrame,
Adrian Roos5c6b6222017-11-07 17:36:10 +0100814 Rect outsetFrame, DisplayCutout displayCutout) {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800815 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700816 // This window is being replaced and either already got information that it's being
817 // removed or we are still waiting for some information. Because of this we don't
818 // want to apply any more changes to it, so it remains in this state until new window
819 // appears.
820 return;
821 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800822 mHaveFrame = true;
823
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700824 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700825 final boolean inFullscreenContainer = inFullscreenContainer();
Robert Carre6275582016-02-29 15:45:45 -0800826 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700827 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800828
Chong Zhangae35fef2016-03-16 15:56:55 -0700829 // If the task has temp inset bounds set, we have to make sure all its windows uses
830 // the temp inset frame. Otherwise different display frames get applied to the main
831 // window and the child window, making them misaligned.
Andrii Kulianc24f3732017-08-08 19:35:17 -0700832 if (inFullscreenContainer || isLetterboxedAppWindow()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700833 mInsetFrame.setEmpty();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700834 } else if (task != null && isInMultiWindowMode()) {
Chong Zhangae35fef2016-03-16 15:56:55 -0700835 task.getTempInsetBounds(mInsetFrame);
836 }
837
Jorim Jaggif5834272016-04-04 20:25:41 -0700838 // Denotes the actual frame used to calculate the insets and to perform the layout. When
839 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
840 // insets temporarily. By the notion of a task having a different layout frame, we can
841 // achieve that while still moving the task around.
842 final Rect layoutContainingFrame;
843 final Rect layoutDisplayFrame;
844
845 // The offset from the layout containing frame to the actual containing frame.
846 final int layoutXDiff;
847 final int layoutYDiff;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700848 if (inFullscreenContainer || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800849 // We use the parent frame as the containing frame for fullscreen and child windows
Robert Carr43521762016-10-28 13:15:04 -0700850 mContainingFrame.set(parentFrame);
851 mDisplayFrame.set(displayFrame);
852 layoutDisplayFrame = displayFrame;
853 layoutContainingFrame = parentFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700854 layoutXDiff = 0;
855 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800856 } else {
Bryce Leef3c6a472017-11-14 14:53:06 -0800857 getBounds(mContainingFrame);
Jorim Jaggi0429f352015-12-22 16:29:16 +0100858 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
859
860 // If the bounds are frozen, we still want to translate the window freely and only
861 // freeze the size.
862 Rect frozen = mAppToken.mFrozenBounds.peek();
863 mContainingFrame.right = mContainingFrame.left + frozen.width();
864 mContainingFrame.bottom = mContainingFrame.top + frozen.height();
865 }
Wale Ogunwalef9c81492015-02-25 18:06:17 -0800866 final WindowState imeWin = mService.mInputMethodWindow;
Robert Carrfc03b2b2016-03-31 15:22:02 -0700867 // IME is up and obscuring this window. Adjust the window position so it is visible.
868 if (imeWin != null && imeWin.isVisibleNow() && mService.mInputMethodTarget == this) {
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700869 if (inFreeformWindowingMode()
Winson Chungd73e94b2017-05-31 16:25:30 -0700870 && mContainingFrame.bottom > contentFrame.bottom) {
871 // In freeform we want to move the top up directly.
872 // TODO: Investigate why this is contentFrame not parentFrame.
873 mContainingFrame.top -= mContainingFrame.bottom - contentFrame.bottom;
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700874 } else if (!inPinnedWindowingMode()
Winson Chungd73e94b2017-05-31 16:25:30 -0700875 && mContainingFrame.bottom > parentFrame.bottom) {
876 // But in docked we want to behave like fullscreen and behave as if the task
877 // were given smaller bounds for the purposes of layout. Skip adjustments for
878 // the pinned stack, they are handled separately in the PinnedStackController.
879 mContainingFrame.bottom = parentFrame.bottom;
880 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700881 }
Skuhne81c524a2015-08-12 13:34:14 -0700882
Robert Carre6275582016-02-29 15:45:45 -0800883 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700884 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
885 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800886 // "content frame" since it is allowed to be outside the visible desktop.
Skuhne81c524a2015-08-12 13:34:14 -0700887 if (mContainingFrame.isEmpty()) {
Robert Carr43521762016-10-28 13:15:04 -0700888 mContainingFrame.set(contentFrame);
Skuhne81c524a2015-08-12 13:34:14 -0700889 }
Doris Liu06d582d2015-06-01 13:18:43 -0700890 }
Wale Ogunwale94596652015-02-06 19:27:34 -0800891 mDisplayFrame.set(mContainingFrame);
Jorim Jaggif5834272016-04-04 20:25:41 -0700892 layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
893 layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
894 layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700895 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
Robert Carr43521762016-10-28 13:15:04 -0700896 subtractInsets(mDisplayFrame, layoutContainingFrame, displayFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700897 if (!layoutInParentFrame()) {
Robert Carr43521762016-10-28 13:15:04 -0700898 subtractInsets(mContainingFrame, layoutContainingFrame, parentFrame, mTmpRect);
899 subtractInsets(mInsetFrame, layoutContainingFrame, parentFrame, mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700900 }
Robert Carr43521762016-10-28 13:15:04 -0700901 layoutDisplayFrame = displayFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700902 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700903 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800904
Craig Mautner967212c2013-04-13 21:10:58 -0700905 final int pw = mContainingFrame.width();
906 final int ph = mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800907
Robert Carr43521762016-10-28 13:15:04 -0700908 if (!mParentFrame.equals(parentFrame)) {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800909 //Slog.i(TAG_WM, "Window " + this + " content frame from " + mParentFrame
Robert Carr43521762016-10-28 13:15:04 -0700910 // + " to " + parentFrame);
911 mParentFrame.set(parentFrame);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800912 mContentChanged = true;
913 }
Dianne Hackborn1743b642012-03-12 17:04:43 -0700914 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
915 mLastRequestedWidth = mRequestedWidth;
916 mLastRequestedHeight = mRequestedHeight;
917 mContentChanged = true;
918 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800919
Robert Carr43521762016-10-28 13:15:04 -0700920 mOverscanFrame.set(overscanFrame);
921 mContentFrame.set(contentFrame);
922 mVisibleFrame.set(visibleFrame);
923 mDecorFrame.set(decorFrame);
924 mStableFrame.set(stableFrame);
925 final boolean hasOutsets = outsetFrame != null;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700926 if (hasOutsets) {
Robert Carr43521762016-10-28 13:15:04 -0700927 mOutsetFrame.set(outsetFrame);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700928 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800929
Craig Mautnereda67292013-04-28 13:50:14 -0700930 final int fw = mFrame.width();
931 final int fh = mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800932
Jorim Jaggif5834272016-04-04 20:25:41 -0700933 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
934
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700935 // Calculate the outsets before the content frame gets shrinked to the window frame.
936 if (hasOutsets) {
937 mOutsets.set(Math.max(mContentFrame.left - mOutsetFrame.left, 0),
938 Math.max(mContentFrame.top - mOutsetFrame.top, 0),
939 Math.max(mOutsetFrame.right - mContentFrame.right, 0),
940 Math.max(mOutsetFrame.bottom - mContentFrame.bottom, 0));
941 } else {
942 mOutsets.set(0, 0, 0, 0);
943 }
944
Craig Mautnera248eee2013-05-07 11:41:27 -0700945 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800946 // final window frame.
Robert Carre6275582016-02-29 15:45:45 -0800947 if (windowsAreFloating && !mFrame.isEmpty()) {
Robert Carre65a1c42017-02-28 16:52:59 -0800948 // For pinned workspace the frame isn't limited in any particular
949 // way since SystemUI controls the bounds. For freeform however
950 // we want to keep things inside the content frame.
Wale Ogunwale44f036f2017-09-29 05:09:09 -0700951 final Rect limitFrame = task.inPinnedWindowingMode() ? mFrame : mContentFrame;
Skuhne81c524a2015-08-12 13:34:14 -0700952 // Keep the frame out of the blocked system area, limit it in size to the content area
953 // and make sure that there is always a minimum visible so that the user can drag it
954 // into a usable area..
Robert Carre65a1c42017-02-28 16:52:59 -0800955 final int height = Math.min(mFrame.height(), limitFrame.height());
956 final int width = Math.min(limitFrame.width(), mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700957 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +0900958 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
959 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
960 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
961 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Robert Carre65a1c42017-02-28 16:52:59 -0800962 final int top = Math.max(limitFrame.top,
963 Math.min(mFrame.top, limitFrame.bottom - minVisibleHeight));
964 final int left = Math.max(limitFrame.left + minVisibleWidth - width,
965 Math.min(mFrame.left, limitFrame.right - minVisibleWidth));
Skuhne81c524a2015-08-12 13:34:14 -0700966 mFrame.set(left, top, left + width, top + height);
967 mContentFrame.set(mFrame);
968 mVisibleFrame.set(mContentFrame);
969 mStableFrame.set(mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700970 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700971 dc.getDockedDividerController().positionDockedStackedDivider(mFrame);
Jorim Jaggi192086e2016-03-11 17:17:03 +0100972 mContentFrame.set(mFrame);
973 if (!mFrame.equals(mLastFrame)) {
974 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800975 }
Skuhne81c524a2015-08-12 13:34:14 -0700976 } else {
Jorim Jaggi656f6502016-04-11 21:08:17 -0700977 mContentFrame.set(Math.max(mContentFrame.left, mFrame.left),
978 Math.max(mContentFrame.top, mFrame.top),
979 Math.min(mContentFrame.right, mFrame.right),
980 Math.min(mContentFrame.bottom, mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800981
Jorim Jaggi656f6502016-04-11 21:08:17 -0700982 mVisibleFrame.set(Math.max(mVisibleFrame.left, mFrame.left),
983 Math.max(mVisibleFrame.top, mFrame.top),
984 Math.min(mVisibleFrame.right, mFrame.right),
985 Math.min(mVisibleFrame.bottom, mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800986
Jorim Jaggi656f6502016-04-11 21:08:17 -0700987 mStableFrame.set(Math.max(mStableFrame.left, mFrame.left),
988 Math.max(mStableFrame.top, mFrame.top),
989 Math.min(mStableFrame.right, mFrame.right),
990 Math.min(mStableFrame.bottom, mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700991 }
Adrian Roosfa104232014-06-20 16:10:14 -0700992
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700993 if (inFullscreenContainer && !windowsAreFloating) {
Jorim Jaggi899327f2016-02-25 20:44:18 -0500994 // Windows that are not fullscreen can be positioned outside of the display frame,
995 // but that is not a reason to provide them with overscan insets.
Jorim Jaggif5834272016-04-04 20:25:41 -0700996 mOverscanInsets.set(Math.max(mOverscanFrame.left - layoutContainingFrame.left, 0),
997 Math.max(mOverscanFrame.top - layoutContainingFrame.top, 0),
998 Math.max(layoutContainingFrame.right - mOverscanFrame.right, 0),
999 Math.max(layoutContainingFrame.bottom - mOverscanFrame.bottom, 0));
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -08001000 }
Craig Mautnereda67292013-04-28 13:50:14 -07001001
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001002 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001003 // For the docked divider, we calculate the stable insets like a full-screen window
1004 // so it can use it to calculate the snap positions.
1005 mStableInsets.set(Math.max(mStableFrame.left - mDisplayFrame.left, 0),
1006 Math.max(mStableFrame.top - mDisplayFrame.top, 0),
1007 Math.max(mDisplayFrame.right - mStableFrame.right, 0),
1008 Math.max(mDisplayFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi2e95a482016-01-14 17:36:55 -08001009
1010 // The divider doesn't care about insets in any case, so set it to empty so we don't
1011 // trigger a relayout when moving it.
1012 mContentInsets.setEmpty();
1013 mVisibleInsets.setEmpty();
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001014 } else {
Bryce Leef3c6a472017-11-14 14:53:06 -08001015 getDisplayContent().getBounds(mTmpRect);
Andrii Kuliana9d168c2016-03-23 13:19:32 -07001016 // Override right and/or bottom insets in case if the frame doesn't fit the screen in
1017 // non-fullscreen mode.
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07001018 boolean overrideRightInset = !windowsAreFloating && !inFullscreenContainer
1019 && mFrame.right > mTmpRect.right;
1020 boolean overrideBottomInset = !windowsAreFloating && !inFullscreenContainer
1021 && mFrame.bottom > mTmpRect.bottom;
Jorim Jaggi656f6502016-04-11 21:08:17 -07001022 mContentInsets.set(mContentFrame.left - mFrame.left,
1023 mContentFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -07001024 overrideRightInset ? mTmpRect.right - mContentFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -07001025 : mFrame.right - mContentFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -07001026 overrideBottomInset ? mTmpRect.bottom - mContentFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -07001027 : mFrame.bottom - mContentFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -08001028
Jorim Jaggi656f6502016-04-11 21:08:17 -07001029 mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
1030 mVisibleFrame.top - mFrame.top,
Andrii Kuliand9003372016-04-04 17:46:59 -07001031 overrideRightInset ? mTmpRect.right - mVisibleFrame.right
Jorim Jaggi656f6502016-04-11 21:08:17 -07001032 : mFrame.right - mVisibleFrame.right,
Andrii Kuliand9003372016-04-04 17:46:59 -07001033 overrideBottomInset ? mTmpRect.bottom - mVisibleFrame.bottom
Jorim Jaggi656f6502016-04-11 21:08:17 -07001034 : mFrame.bottom - mVisibleFrame.bottom);
Jorim Jaggi2e95a482016-01-14 17:36:55 -08001035
Jorim Jaggi656f6502016-04-11 21:08:17 -07001036 mStableInsets.set(Math.max(mStableFrame.left - mFrame.left, 0),
1037 Math.max(mStableFrame.top - mFrame.top, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -07001038 overrideRightInset ? Math.max(mTmpRect.right - mStableFrame.right, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -07001039 : Math.max(mFrame.right - mStableFrame.right, 0),
Andrii Kuliand9003372016-04-04 17:46:59 -07001040 overrideBottomInset ? Math.max(mTmpRect.bottom - mStableFrame.bottom, 0)
Jorim Jaggi656f6502016-04-11 21:08:17 -07001041 : Math.max(mFrame.bottom - mStableFrame.bottom, 0));
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001042 }
Adrian Roosfa104232014-06-20 16:10:14 -07001043
Jorim Jaggi656f6502016-04-11 21:08:17 -07001044 // Offset the actual frame by the amount layout frame is off.
1045 mFrame.offset(-layoutXDiff, -layoutYDiff);
1046 mCompatFrame.offset(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -07001047 mContentFrame.offset(-layoutXDiff, -layoutYDiff);
1048 mVisibleFrame.offset(-layoutXDiff, -layoutYDiff);
1049 mStableFrame.offset(-layoutXDiff, -layoutYDiff);
1050
Adrian Roos5c6b6222017-11-07 17:36:10 +01001051 // TODO(roosa): Figure out what frame exactly this needs to be calculated with.
1052 mDisplayCutout = displayCutout.calculateRelativeTo(mFrame);
1053
1054
Craig Mautnereda67292013-04-28 13:50:14 -07001055 mCompatFrame.set(mFrame);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001056 if (mEnforceSizeCompat) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001057 // If there is a size compatibility scale being applied to the
1058 // window, we need to apply this to its insets so that they are
1059 // reported to the app in its coordinate space.
Craig Mautnereda67292013-04-28 13:50:14 -07001060 mOverscanInsets.scale(mInvGlobalScale);
1061 mContentInsets.scale(mInvGlobalScale);
1062 mVisibleInsets.scale(mInvGlobalScale);
Adrian Roosfa104232014-06-20 16:10:14 -07001063 mStableInsets.scale(mInvGlobalScale);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001064 mOutsets.scale(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001065
1066 // Also the scaled frame that we report to the app needs to be
1067 // adjusted to be in its coordinate space.
1068 mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001069 }
1070
Craig Mautnereda67292013-04-28 13:50:14 -07001071 if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001072 final DisplayContent displayContent = getDisplayContent();
1073 if (displayContent != null) {
1074 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
Wale Ogunwale0303c572016-10-20 10:16:29 -07001075 getDisplayContent().mWallpaperController.updateWallpaperOffset(
Wale Ogunwalee8069dc2015-08-18 09:52:01 -07001076 this, displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001077 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001078 }
1079
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001080 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001081 "Resolving (mRequestedWidth="
1082 + mRequestedWidth + ", mRequestedheight="
1083 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
1084 + "): frame=" + mFrame.toShortString()
1085 + " ci=" + mContentInsets.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07001086 + " vi=" + mVisibleInsets.toShortString()
Andrii Kuliana9d168c2016-03-23 13:19:32 -07001087 + " si=" + mStableInsets.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001088 + " of=" + mOutsets.toShortString());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001089 }
1090
Bryce Leef3c6a472017-11-14 14:53:06 -08001091 // TODO: Look into whether this override is still necessary.
1092 @Override
1093 public Rect getBounds() {
1094 if (isInMultiWindowMode()) {
1095 return getTask().getBounds();
1096 } else if (mAppToken != null){
1097 return mAppToken.getBounds();
1098 } else {
1099 return super.getBounds();
1100 }
1101 }
1102
Craig Mautnera2c77052012-03-26 12:14:43 -07001103 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001104 public Rect getFrameLw() {
1105 return mFrame;
1106 }
1107
Craig Mautnera2c77052012-03-26 12:14:43 -07001108 @Override
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07001109 public Point getShownPositionLw() {
1110 return mShownPosition;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001111 }
1112
Craig Mautnera2c77052012-03-26 12:14:43 -07001113 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001114 public Rect getDisplayFrameLw() {
1115 return mDisplayFrame;
1116 }
1117
Craig Mautnera2c77052012-03-26 12:14:43 -07001118 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001119 public Rect getOverscanFrameLw() {
1120 return mOverscanFrame;
1121 }
1122
1123 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001124 public Rect getContentFrameLw() {
1125 return mContentFrame;
1126 }
1127
Craig Mautnera2c77052012-03-26 12:14:43 -07001128 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001129 public Rect getVisibleFrameLw() {
1130 return mVisibleFrame;
1131 }
1132
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001133 Rect getStableFrameLw() {
1134 return mStableFrame;
1135 }
1136
Craig Mautnera2c77052012-03-26 12:14:43 -07001137 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001138 public boolean getGivenInsetsPendingLw() {
1139 return mGivenInsetsPending;
1140 }
1141
Craig Mautnera2c77052012-03-26 12:14:43 -07001142 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001143 public Rect getGivenContentInsetsLw() {
1144 return mGivenContentInsets;
1145 }
1146
Craig Mautnera2c77052012-03-26 12:14:43 -07001147 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001148 public Rect getGivenVisibleInsetsLw() {
1149 return mGivenVisibleInsets;
1150 }
1151
Craig Mautnera2c77052012-03-26 12:14:43 -07001152 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001153 public WindowManager.LayoutParams getAttrs() {
1154 return mAttrs;
1155 }
1156
Craig Mautner812d2ca2012-09-27 15:35:34 -07001157 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001158 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001159 return getDisplayContent().getNeedsMenu(this, bottom);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001160 }
1161
Craig Mautner19d59bc2012-09-04 11:15:56 -07001162 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001163 public int getSystemUiVisibility() {
1164 return mSystemUiVisibility;
1165 }
1166
Craig Mautner19d59bc2012-09-04 11:15:56 -07001167 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001168 public int getSurfaceLayer() {
1169 return mLayer;
1170 }
1171
Craig Mautner812d2ca2012-09-27 15:35:34 -07001172 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001173 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001174 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001175 }
1176
1177 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001178 public IApplicationToken getAppToken() {
1179 return mAppToken != null ? mAppToken.appToken : null;
1180 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001181
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001182 @Override
1183 public boolean isVoiceInteraction() {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001184 return mAppToken != null && mAppToken.mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001185 }
1186
Robert Carr31aa98b2016-07-20 15:29:03 -07001187 boolean setReportResizeHints() {
Craig Mautner4c5eb222013-11-18 12:59:05 -08001188 mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
1189 mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
1190 mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
Adrian Roosfa104232014-06-20 16:10:14 -07001191 mStableInsetsChanged |= !mLastStableInsets.equals(mStableInsets);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001192 mOutsetsChanged |= !mLastOutsets.equals(mOutsets);
Robert Carr31aa98b2016-07-20 15:29:03 -07001193 mFrameSizeChanged |= (mLastFrame.width() != mFrame.width()) ||
1194 (mLastFrame.height() != mFrame.height());
Adrian Roos5c6b6222017-11-07 17:36:10 +01001195 mDisplayCutoutChanged |= !mLastDisplayCutout.equals(mDisplayCutout);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07001196 return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged
Adrian Roos5c6b6222017-11-07 17:36:10 +01001197 || mOutsetsChanged || mFrameSizeChanged || mDisplayCutoutChanged;
Craig Mautner4c5eb222013-11-18 12:59:05 -08001198 }
1199
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001200 /**
1201 * Adds the window to the resizing list if any of the parameters we use to track the window
1202 * dimensions or insets have changed.
1203 */
1204 void updateResizingWindowIfNeeded() {
1205 final WindowStateAnimator winAnimator = mWinAnimator;
1206 if (!mHasSurface || mService.mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
1207 return;
1208 }
1209
1210 final Task task = getTask();
1211 // In the case of stack bound animations, the window frames will update (unlike other
1212 // animations which just modify various transformation properties). We don't want to
1213 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1214 // the frame may not correspond to the surface size or the onscreen area at various
1215 // phases in the animation, and the client will become sad and confused.
Winson Chung40a5f932017-04-13 16:39:36 -07001216 if (task != null && task.mStack.isAnimatingBounds()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001217 return;
1218 }
1219
1220 setReportResizeHints();
1221 boolean configChanged = isConfigChanged();
1222 if (DEBUG_CONFIGURATION && configChanged) {
1223 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1224 }
1225
1226 final boolean dragResizingChanged = isDragResizeChanged()
1227 && !isDragResizingChangeReported();
1228
1229 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
1230 + " dragResizingChanged=" + dragResizingChanged + " last=" + mLastFrame
1231 + " frame=" + mFrame);
1232
1233 // We update mLastFrame always rather than in the conditional with the last inset
1234 // variables, because mFrameSizeChanged only tracks the width and height changing.
1235 mLastFrame.set(mFrame);
1236
1237 if (mContentInsetsChanged
1238 || mVisibleInsetsChanged
1239 || winAnimator.mSurfaceResized
1240 || mOutsetsChanged
1241 || mFrameSizeChanged
Adrian Roos5c6b6222017-11-07 17:36:10 +01001242 || mDisplayCutoutChanged
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001243 || configChanged
1244 || dragResizingChanged
Andrii Kulianb2e37802017-01-11 00:36:44 -08001245 || !isResizedWhileNotDragResizingReported()
1246 || mReportOrientationChanged) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001247 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1248 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
1249 + " contentInsetsChanged=" + mContentInsetsChanged
1250 + " " + mContentInsets.toShortString()
1251 + " visibleInsetsChanged=" + mVisibleInsetsChanged
1252 + " " + mVisibleInsets.toShortString()
1253 + " stableInsetsChanged=" + mStableInsetsChanged
1254 + " " + mStableInsets.toShortString()
1255 + " outsetsChanged=" + mOutsetsChanged
1256 + " " + mOutsets.toShortString()
1257 + " surfaceResized=" + winAnimator.mSurfaceResized
1258 + " configChanged=" + configChanged
1259 + " dragResizingChanged=" + dragResizingChanged
1260 + " resizedWhileNotDragResizingReported="
Andrii Kulianb2e37802017-01-11 00:36:44 -08001261 + isResizedWhileNotDragResizingReported()
Adrian Roos5c6b6222017-11-07 17:36:10 +01001262 + " reportOrientationChanged=" + mReportOrientationChanged
1263 + " displayCutoutChanged=" + mDisplayCutoutChanged);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001264 }
1265
1266 // If it's a dead window left on screen, and the configuration changed, there is nothing
1267 // we can do about it. Remove the window now.
1268 if (mAppToken != null && mAppDied) {
1269 mAppToken.removeDeadWindows();
1270 return;
1271 }
1272
Jorim Jaggidc9385a2017-05-13 02:00:31 +02001273 updateLastInsetValues();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001274 mService.makeWindowFreezingScreenIfNeededLocked(this);
1275
1276 // If the orientation is changing, or we're starting or ending a drag resizing action,
1277 // then we need to hold off on unfreezing the display until this window has been
1278 // redrawn; to do that, we need to go through the process of getting informed by the
1279 // application when it has finished drawing.
Bryce Lee8c3cf382017-07-06 19:47:10 -07001280 if (getOrientationChanging() || dragResizingChanged
1281 || isResizedWhileNotDragResizing()) {
Robert Carre13b58e2017-08-31 14:50:44 -07001282 if (DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001283 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1284 + ", mDrawState=DRAW_PENDING in " + this
1285 + ", surfaceController " + winAnimator.mSurfaceController);
1286 }
1287 winAnimator.mDrawState = DRAW_PENDING;
1288 if (mAppToken != null) {
1289 mAppToken.clearAllDrawn();
1290 }
1291 }
1292 if (!mService.mResizingWindows.contains(this)) {
1293 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
1294 mService.mResizingWindows.add(this);
1295 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07001296 } else if (getOrientationChanging()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001297 if (isDrawnLw()) {
1298 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1299 + this + ", surfaceController " + winAnimator.mSurfaceController);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001300 setOrientationChanging(false);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001301 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
1302 - mService.mDisplayFreezeTime);
1303 }
1304 }
1305 }
1306
Bryce Lee8c3cf382017-07-06 19:47:10 -07001307 boolean getOrientationChanging() {
1308 // In addition to the local state flag, we must also consider the difference in the last
1309 // reported configuration vs. the current state. If the client code has not been informed of
1310 // the change, logic dependent on having finished processing the orientation, such as
1311 // unfreezing, could be improperly triggered.
1312 // TODO(b/62846907): Checking against {@link mLastReportedConfiguration} could be flaky as
1313 // this is not necessarily what the client has processed yet. Find a
1314 // better indicator consistent with the client.
Robert Carr926643f2017-08-02 12:01:12 -07001315 return (mOrientationChanging || (isVisible()
Bryce Lee2b17afd2017-09-21 10:38:20 -07001316 && getConfiguration().orientation != getLastReportedConfiguration().orientation))
Robert Carr9c1c3a02017-08-08 12:59:01 -07001317 && !mSeamlesslyRotated
1318 && !mOrientationChangeTimedOut;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001319 }
1320
1321 void setOrientationChanging(boolean changing) {
1322 mOrientationChanging = changing;
Robert Carr9c1c3a02017-08-08 12:59:01 -07001323 mOrientationChangeTimedOut = false;
1324 }
1325
1326 void orientationChangeTimedOut() {
1327 mOrientationChangeTimedOut = true;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001328 }
1329
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001330 DisplayContent getDisplayContent() {
1331 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001332 }
1333
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001334 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001335 final DisplayContent displayContent = getDisplayContent();
1336 return displayContent != null ? displayContent.getDisplayInfo() : null;
1337 }
1338
Jorim Jaggife762342016-10-13 14:33:27 +02001339 @Override
1340 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001341 final DisplayContent displayContent = getDisplayContent();
1342 if (displayContent == null) {
1343 return -1;
1344 }
1345 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001346 }
1347
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001348 Task getTask() {
Bryce Lee6d410262017-02-28 15:30:17 -08001349 return mAppToken != null ? mAppToken.getTask() : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001350 }
1351
1352 TaskStack getStack() {
1353 Task task = getTask();
1354 if (task != null) {
1355 if (task.mStack != null) {
1356 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001357 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001358 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001359 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1360 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001361 final DisplayContent dc = getDisplayContent();
1362 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001363 }
1364
Skuhnef932e562015-08-20 12:07:30 -07001365 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001366 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001367 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001368 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001369 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001370 final Task task = getTask();
1371 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001372 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001373 mTmpRect.setEmpty();
1374 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001375 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001376 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001377 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001378 } else {
1379 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001380 }
1381 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001382
Chong Zhang9184ec62015-09-24 12:32:21 -07001383 bounds.set(mVisibleFrame);
1384 if (intersectWithStackBounds) {
1385 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001386 }
1387
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001388 if (bounds.isEmpty()) {
1389 bounds.set(mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001390 if (intersectWithStackBounds) {
1391 bounds.intersect(mTmpRect);
1392 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001393 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001394 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001395 }
1396
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001397 public long getInputDispatchingTimeoutNanos() {
1398 return mAppToken != null
Wale Ogunwale72919d22016-12-08 18:58:50 -08001399 ? mAppToken.mInputDispatchingTimeoutNanos
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001400 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1401 }
1402
Craig Mautnere8552142012-11-07 13:55:47 -08001403 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001404 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001405 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001406 }
1407
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001408 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1409 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1410 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1411 if (dtdx < -.000001f || dtdx > .000001f) return false;
1412 if (dsdy < -.000001f || dsdy > .000001f) return false;
1413 return true;
1414 }
1415
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001416 void prelayout() {
1417 if (mEnforceSizeCompat) {
Andrii Kulian06d07d62017-03-14 11:11:47 -07001418 mGlobalScale = getDisplayContent().mCompatibleScreenScale;
1419 mInvGlobalScale = 1 / mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001420 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001421 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001422 }
1423 }
1424
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001425 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001426 boolean hasContentToDisplay() {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001427 if (!mAppFreezing && isDrawnLw() && (mViewVisibility == View.VISIBLE
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001428 || (mWinAnimator.isAnimationSet() && !mService.mAppTransition.isTransitionSet()))) {
1429 return true;
1430 }
1431
Wale Ogunwale44f21802016-09-02 12:49:48 -07001432 return super.hasContentToDisplay();
1433 }
1434
1435 @Override
1436 boolean isVisible() {
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001437 return wouldBeVisibleIfPolicyIgnored() && mPolicyVisibility;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001438 }
1439
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001440 /**
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001441 * @return True if the window would be visible if we'd ignore policy visibility, false
1442 * otherwise.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001443 */
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001444 boolean wouldBeVisibleIfPolicyIgnored() {
Jorim Jaggi43530c92017-05-18 01:53:56 +02001445 return mHasSurface && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001446 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001447 }
1448
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001449 @Override
1450 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001451 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001452 }
1453
1454 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001455 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1456 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001457 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001458 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1459 boolean isWinVisibleLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001460 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.isSelfAnimating())
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001461 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001462 }
1463
1464 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001465 * The same as isVisible(), but follows the current hidden state of the associated app token,
1466 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001467 */
1468 boolean isVisibleNow() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001469 return (!mToken.isHidden() || mAttrs.type == TYPE_APPLICATION_STARTING)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001470 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001471 }
1472
1473 /**
1474 * Can this window possibly be a drag/drop target? The test here is
1475 * a combination of the above "visible now" with the check that the
1476 * Input Manager uses when discarding windows from input consideration.
1477 */
1478 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001479 return isVisibleNow() && !mRemoved
1480 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001481 }
1482
1483 /**
1484 * Same as isVisible(), but we also count it as visible between the
1485 * call to IWindowSession.add() and the first relayout().
1486 */
1487 boolean isVisibleOrAdding() {
1488 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001489 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001490 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001491 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001492 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001493 }
1494
1495 /**
1496 * Is this window currently on-screen? It is on-screen either if it
1497 * is visible or it is currently running an animation before no longer
1498 * being visible.
1499 */
1500 boolean isOnScreen() {
Jorim Jaggiaf221d12016-11-15 14:59:57 -08001501 if (!mHasSurface || mDestroying || !mPolicyVisibility) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001502 return false;
1503 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001504 final AppWindowToken atoken = mAppToken;
1505 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001506 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001507 || mWinAnimator.isAnimationSet());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001508 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01001509 return !isParentWindowHidden() || mWinAnimator.isAnimationSet();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001510 }
1511
1512 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001513 * Whether this window's drawn state might affect the drawn states of the app token.
1514 *
Chong Zhang8e4bda92016-05-04 15:08:18 -07001515 * @return true if the window should be considered while evaluating allDrawn flags.
1516 */
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001517 boolean mightAffectAllDrawn() {
1518 final boolean isAppType = mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1519 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION;
1520 return (isOnScreen() || isAppType) && !mAnimatingExit && !mDestroying;
Chong Zhang8e4bda92016-05-04 15:08:18 -07001521 }
1522
1523 /**
1524 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1525 * it must be drawn before allDrawn can become true.
1526 */
1527 boolean isInteresting() {
1528 return mAppToken != null && !mAppDied
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001529 && (!mAppToken.isFreezingScreen() || !mAppFreezing);
Chong Zhang8e4bda92016-05-04 15:08:18 -07001530 }
1531
1532 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001533 * Like isOnScreen(), but we don't return true if the window is part
1534 * of a transition that has not yet been started.
1535 */
1536 boolean isReadyForDisplay() {
Wale Ogunwalea6cc3612016-08-04 07:25:33 -07001537 if (mToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001538 return false;
1539 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001540 return mHasSurface && mPolicyVisibility && !mDestroying
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001541 && ((!isParentWindowHidden() && mViewVisibility == View.VISIBLE && !mToken.isHidden())
1542 || mWinAnimator.isAnimationSet());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001543 }
1544
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001545 // TODO: Another visibility method that was added late in the release to minimize risk.
1546 @Override
1547 public boolean canAffectSystemUiFlags() {
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001548 final boolean translucent = mAttrs.alpha == 0.0f;
Jorim Jaggi72207752018-01-08 13:16:59 +01001549 if (translucent) {
1550 return false;
1551 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001552 if (mAppToken == null) {
1553 final boolean shown = mWinAnimator.getShown();
1554 final boolean exiting = mAnimatingExit || mDestroying;
Jorim Jaggi72207752018-01-08 13:16:59 +01001555 return shown && !exiting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001556 } else {
1557 return !mAppToken.isHidden();
1558 }
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001559 }
1560
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001561 /**
1562 * Like isOnScreen, but returns false if the surface hasn't yet
1563 * been drawn.
1564 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001565 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001566 public boolean isDisplayedLw() {
1567 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001568 return isDrawnLw() && mPolicyVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001569 && ((!isParentWindowHidden() && (atoken == null || !atoken.hiddenRequested))
1570 || mWinAnimator.isAnimationSet());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001571 }
1572
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001573 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001574 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001575 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001576 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001577 public boolean isAnimatingLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001578 return isAnimating();
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001579 }
1580
Craig Mautner812d2ca2012-09-27 15:35:34 -07001581 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001582 public boolean isGoneForLayoutLw() {
1583 final AppWindowToken atoken = mAppToken;
1584 return mViewVisibility == View.GONE
1585 || !mRelayoutCalled
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001586 || (atoken == null && mToken.isHidden())
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001587 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001588 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001589 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001590 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001591 }
1592
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001593 /**
1594 * Returns true if the window has a surface that it has drawn a
1595 * complete UI in to.
1596 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001597 public boolean isDrawFinishedLw() {
1598 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001599 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1600 || mWinAnimator.mDrawState == READY_TO_SHOW
1601 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001602 }
1603
1604 /**
1605 * Returns true if the window has a surface that it has drawn a
1606 * complete UI in to.
1607 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001608 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001609 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001610 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001611 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001612 }
1613
1614 /**
1615 * Return true if the window is opaque and fully drawn. This indicates
1616 * it may obscure windows behind it.
1617 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001618 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001619 // When there is keyguard, wallpaper could be placed over the secure app
1620 // window but invisible. We need to check wallpaper visibility explicitly
1621 // to determine if it's occluding apps.
1622 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1623 || (mIsWallpaper && mWallpaperVisible))
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001624 && isDrawnLw() && !mWinAnimator.isAnimationSet();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001625 }
1626
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001627 @Override
1628 void onMovedByResize() {
1629 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001630 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001631 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001632 }
1633
1634 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1635 boolean changed = false;
1636
1637 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001638 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001639 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1640 }
1641
1642 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1643 // Starting window that's exiting will be removed when the animation finishes.
1644 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1645 // to actually remove it.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001646 if (!visible && isVisibleNow() && mAppToken.isSelfAnimating()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001647 mAnimatingExit = true;
1648 mRemoveOnExit = true;
1649 mWindowRemovalAllowed = true;
1650 }
1651 return changed;
1652 }
1653
Robert Carrd5c7dd62017-03-08 10:39:30 -08001654 // Next up we will notify the client that it's visibility has changed.
1655 // We need to prevent it from destroying child surfaces until
1656 // the animation has finished.
1657 if (!visible && isVisibleNow()) {
1658 mWinAnimator.detachChildren();
1659 }
1660
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001661 if (visible != isVisibleNow()) {
1662 if (!runningAppAnimation) {
1663 final AccessibilityController accessibilityController =
1664 mService.mAccessibilityController;
1665 final int winTransit = visible ? TRANSIT_ENTER : TRANSIT_EXIT;
1666 mWinAnimator.applyAnimationLocked(winTransit, visible);
1667 //TODO (multidisplay): Magnification is supported only for the default
1668 if (accessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
1669 accessibilityController.onWindowTransitionLocked(this, winTransit);
1670 }
1671 }
1672 changed = true;
1673 setDisplayLayoutNeeded();
1674 }
1675
1676 return changed;
1677 }
1678
1679 boolean onSetAppExiting() {
1680 final DisplayContent displayContent = getDisplayContent();
1681 boolean changed = false;
1682
1683 if (isVisibleNow()) {
1684 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
1685 //TODO (multidisplay): Magnification is supported only for the default
1686 if (mService.mAccessibilityController != null && isDefaultDisplay()) {
1687 mService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
1688 }
1689 changed = true;
1690 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001691 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001692 }
1693 }
1694
1695 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001696 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001697 changed |= c.onSetAppExiting();
1698 }
1699
1700 return changed;
1701 }
1702
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001703 @Override
1704 void onResize() {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001705 final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
1706 if (mHasSurface && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001707 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001708 resizingWindows.add(this);
1709
1710 // If we are not drag resizing, force recreating of a new surface so updating
1711 // the content and positioning that surface will be in sync.
1712 //
1713 // As we use this flag as a hint to freeze surface boundary updates, we'd like to only
1714 // apply this to TYPE_BASE_APPLICATION, windows of TYPE_APPLICATION like dialogs, could
1715 // appear to not be drag resizing while they resize, but we'd still like to manipulate
1716 // their frame to update crop, etc...
1717 //
1718 // Anyway we don't need to synchronize position and content updates for these
1719 // windows since they aren't at the base layer and could be moved around anyway.
Wale Ogunwale44f036f2017-09-29 05:09:09 -07001720 if (!computeDragResizing() && mAttrs.type == TYPE_BASE_APPLICATION
1721 && !mWinAnimator.isForceScaled() && !isGoneForLayoutLw()
1722 && !getTask().inPinnedWindowingMode()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001723 setResizedWhileNotDragResizing(true);
1724 }
1725 }
1726 if (isGoneForLayoutLw()) {
1727 mResizedWhileGone = true;
1728 }
1729
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001730 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001731 }
1732
1733 void onUnfreezeBounds() {
1734 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001735 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001736 c.onUnfreezeBounds();
1737 }
1738
1739 if (!mHasSurface) {
1740 return;
1741 }
1742
1743 mLayoutNeeded = true;
1744 setDisplayLayoutNeeded();
1745 if (!mService.mResizingWindows.contains(this)) {
1746 mService.mResizingWindows.add(this);
1747 }
1748 }
1749
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001750 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001751 * If the window has moved due to its containing content frame changing, then notify the
1752 * listeners and optionally animate it. Simply checking a change of position is not enough,
1753 * because being move due to dock divider is not a trigger for animation.
1754 */
Jorim Jaggia5e10572017-11-15 14:36:26 +01001755 void handleWindowMovedIfNeeded(Transaction t) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001756 if (!hasMoved()) {
1757 return;
1758 }
1759
1760 // Frame has moved, containing content frame has also moved, and we're not currently
1761 // animating... let's do something.
1762 final int left = mFrame.left;
1763 final int top = mFrame.top;
1764 final Task task = getTask();
1765 final boolean adjustedForMinimizedDockOrIme = task != null
1766 && (task.mStack.isAdjustedForMinimizedDockedStack()
1767 || task.mStack.isAdjustedForIme());
David Stevens9440dc82017-03-16 19:00:20 -07001768 if (mToken.okToAnimate()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001769 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1770 && !isDragResizing() && !adjustedForMinimizedDockOrIme
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001771 && getWindowConfiguration().hasMovementAnimations()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001772 && !mWinAnimator.mLastHidden) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01001773 startMoveAnimation(t, left, top);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001774 }
1775
1776 //TODO (multidisplay): Accessibility supported only for the default display.
1777 if (mService.mAccessibilityController != null
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001778 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001779 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
1780 }
1781
1782 try {
1783 mClient.moved(left, top);
1784 } catch (RemoteException e) {
1785 }
1786 mMovedByResize = false;
1787 }
1788
1789 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001790 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001791 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1792 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001793 private boolean hasMoved() {
Chong Zhangbd0d9372015-12-28 15:18:29 -08001794 return mHasSurface && (mContentChanged || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001795 && !mAnimatingExit
Chong Zhangbd0d9372015-12-28 15:18:29 -08001796 && (mFrame.top != mLastFrame.top || mFrame.left != mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001797 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001798 }
1799
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001800 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001801 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001802 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001803 return false;
1804 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001805 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001806 }
1807
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001808 boolean fillsDisplay() {
1809 final DisplayInfo displayInfo = getDisplayInfo();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001810 return mFrame.left <= 0 && mFrame.top <= 0
1811 && mFrame.right >= displayInfo.appWidth && mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001812 }
1813
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001814 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001815 boolean isConfigChanged() {
Bryce Lee2b17afd2017-09-21 10:38:20 -07001816 return !getLastReportedConfiguration().equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001817 }
1818
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001819 void onWindowReplacementTimeout() {
1820 if (mWillReplaceWindow) {
1821 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001822 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001823 // delays removal on certain conditions, which will leave the stale window in the
1824 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1825 //
1826 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001827 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001828 } else {
1829 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001830 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001831 c.onWindowReplacementTimeout();
1832 }
1833 }
1834 }
1835
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001836 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001837 void forceWindowsScaleableInTransaction(boolean force) {
1838 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1839 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1840 }
1841
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001842 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001843 }
1844
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001845 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001846 void removeImmediately() {
1847 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001848
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001849 if (mRemoved) {
1850 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001851 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1852 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001853 return;
1854 }
1855
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001856 mRemoved = true;
1857
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001858 mWillReplaceWindow = false;
1859 if (mReplacementWindow != null) {
1860 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1861 }
1862
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001863 final DisplayContent dc = getDisplayContent();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001864 if (mService.mInputMethodTarget == this) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001865 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001866 }
1867
1868 final int type = mAttrs.type;
1869 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001870 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001871 }
1872 mPolicy.removeWindowLw(this);
1873
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001874 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001875
Craig Mautner96868332012-12-04 14:29:11 -08001876 mWinAnimator.destroyDeferredSurfaceLocked();
1877 mWinAnimator.destroySurfaceLocked();
Wale Ogunwale943002b2017-02-15 19:34:01 -08001878 mSession.windowRemovedLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001879 try {
1880 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1881 } catch (RuntimeException e) {
1882 // Ignore if it has already been removed (usually because
1883 // we are doing this as part of processing a death note.)
1884 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001885
1886 mService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001887 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001888
Wale Ogunwale571771c2016-08-26 13:18:50 -07001889 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001890 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001891 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001892 removeIfPossible(false /*keepVisibleDeadWindow*/);
1893 }
1894
Wale Ogunwale571771c2016-08-26 13:18:50 -07001895 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001896 mWindowRemovalAllowed = true;
1897 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1898 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1899
1900 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1901 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1902 "Starting window removed " + this);
1903
1904 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && this == mService.mCurrentFocus)
1905 Slog.v(TAG_WM, "Remove " + this + " client="
1906 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1907 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1908 + Debug.getCallers(5));
1909
1910 final long origId = Binder.clearCallingIdentity();
1911
Peter Visontay3556a3b2017-11-01 17:23:17 +00001912 try {
1913 disposeInputChannel();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001914
Peter Visontay3556a3b2017-11-01 17:23:17 +00001915 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1916 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1917 + " mAnimatingExit=" + mAnimatingExit
1918 + " mRemoveOnExit=" + mRemoveOnExit
1919 + " mHasSurface=" + mHasSurface
1920 + " surfaceShowing=" + mWinAnimator.getShown()
1921 + " isAnimationSet=" + mWinAnimator.isAnimationSet()
1922 + " app-animation="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001923 + (mAppToken != null ? mAppToken.isSelfAnimating() : "false")
Peter Visontay3556a3b2017-11-01 17:23:17 +00001924 + " mWillReplaceWindow=" + mWillReplaceWindow
1925 + " inPendingTransaction="
1926 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
1927 + " mDisplayFrozen=" + mService.mDisplayFrozen
1928 + " callers=" + Debug.getCallers(6));
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001929
Peter Visontay3556a3b2017-11-01 17:23:17 +00001930 // Visibility of the removed window. Will be used later to update orientation later on.
1931 boolean wasVisible = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001932
Peter Visontay3556a3b2017-11-01 17:23:17 +00001933 final int displayId = getDisplayId();
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001934
Peter Visontay3556a3b2017-11-01 17:23:17 +00001935 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1936 // window until the animation is done. If the display is frozen, just remove immediately,
1937 // since the animation wouldn't be seen.
1938 if (mHasSurface && mToken.okToAnimate()) {
1939 if (mWillReplaceWindow) {
1940 // This window is going to be replaced. We need to keep it around until the new one
1941 // gets added, then we will get rid of this one.
1942 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1943 "Preserving " + this + " until the new one is " + "added");
1944 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1945 // been removed. We probably need another flag to indicate that window removal
1946 // should be deffered vs. overloading the flag that says we are playing an exit
1947 // animation.
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001948 mAnimatingExit = true;
Peter Visontay3556a3b2017-11-01 17:23:17 +00001949 mReplacingRemoveRequested = true;
1950 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001951 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001952
Peter Visontay3556a3b2017-11-01 17:23:17 +00001953 // If we are not currently running the exit animation, we need to see about starting one
1954 wasVisible = isWinVisibleLw();
1955
1956 if (keepVisibleDeadWindow) {
1957 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1958 "Not removing " + this + " because app died while it's visible");
1959
1960 mAppDied = true;
1961 setDisplayLayoutNeeded();
1962 mService.mWindowPlacerLocked.performSurfacePlacement();
1963
1964 // Set up a replacement input channel since the app is now dead.
1965 // We need to catch tapping on the dead window to restart the app.
1966 openInputChannel(null);
1967 mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
1968 return;
1969 }
1970
1971 if (wasVisible) {
1972 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
1973
1974 // Try starting an animation.
1975 if (mWinAnimator.applyAnimationLocked(transit, false)) {
1976 mAnimatingExit = true;
1977 }
1978 //TODO (multidisplay): Magnification is supported only for the default display.
1979 if (mService.mAccessibilityController != null && displayId == DEFAULT_DISPLAY) {
1980 mService.mAccessibilityController.onWindowTransitionLocked(this, transit);
1981 }
1982 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001983 final boolean isAnimating = mWinAnimator.isAnimationSet()
1984 && (mAppToken == null || !mAppToken.isWaitingForTransitionStart());
Peter Visontay3556a3b2017-11-01 17:23:17 +00001985 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
1986 && mAppToken.isLastWindow(this);
1987 // We delay the removal of a window if it has a showing surface that can be used to run
1988 // exit animation and it is marked as exiting.
1989 // Also, If isn't the an animating starting window that is the last window in the app.
1990 // We allow the removal of the non-animating starting window now as there is no
1991 // additional window or animation that will trigger its removal.
1992 if (mWinAnimator.getShown() && mAnimatingExit
1993 && (!lastWindowIsStartingWindow || isAnimating)) {
1994 // The exit animation is running or should run... wait for it!
1995 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1996 "Not removing " + this + " due to exit animation ");
1997 setupWindowForRemoveOnExit();
1998 if (mAppToken != null) {
1999 mAppToken.updateReportedVisibilityLocked();
2000 }
2001 return;
2002 }
2003 }
2004
2005 removeImmediately();
2006 // Removing a visible window will effect the computed orientation
2007 // So just update orientation if needed.
2008 if (wasVisible && mService.updateOrientationFromAppTokensLocked(false, displayId)) {
2009 mService.mH.obtainMessage(SEND_NEW_CONFIGURATION, displayId).sendToTarget();
2010 }
2011 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
2012 } finally {
2013 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002014 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002015 }
2016
2017 private void setupWindowForRemoveOnExit() {
2018 mRemoveOnExit = true;
2019 setDisplayLayoutNeeded();
2020 // Request a focus update as this window's input channel is already gone. Otherwise
2021 // we could have no focused window in input manager.
2022 final boolean focusChanged = mService.updateFocusedWindowLocked(
2023 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
2024 mService.mWindowPlacerLocked.performSurfacePlacement();
2025 if (focusChanged) {
2026 mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
2027 }
2028 }
2029
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08002030 void setHasSurface(boolean hasSurface) {
2031 mHasSurface = hasSurface;
2032 }
2033
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002034 boolean canBeImeTarget() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002035 if (mIsImWindow) {
2036 // IME windows can't be IME targets. IME targets are required to be below the IME
2037 // windows and that wouldn't be possible if the IME window is its own target...silly.
2038 return false;
2039 }
2040
Winson Chung3d0a74a2017-07-12 12:37:19 -07002041 final boolean windowsAreFocusable = mAppToken == null || mAppToken.windowsAreFocusable();
Winson Chungb1549342017-07-11 09:59:56 -07002042 if (!windowsAreFocusable) {
2043 // This window can't be an IME target if the app's windows should not be focusable.
2044 return false;
2045 }
2046
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002047 final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002048 final int type = mAttrs.type;
2049
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002050 // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are set or
2051 // both are cleared...and not a starting window.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002052 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
2053 && type != TYPE_APPLICATION_STARTING) {
2054 return false;
2055 }
2056
2057 if (DEBUG_INPUT_METHOD) {
2058 Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding());
2059 if (!isVisibleOrAdding()) {
2060 Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController
2061 + " relayoutCalled=" + mRelayoutCalled
2062 + " viewVis=" + mViewVisibility
2063 + " policyVis=" + mPolicyVisibility
2064 + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim
2065 + " parentHidden=" + isParentWindowHidden()
2066 + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
2067 if (mAppToken != null) {
2068 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + mAppToken.hiddenRequested);
2069 }
2070 }
2071 }
2072 return isVisibleOrAdding();
2073 }
2074
Chong Zhangacf11402015-11-04 16:23:10 -08002075 private final class DeadWindowEventReceiver extends InputEventReceiver {
2076 DeadWindowEventReceiver(InputChannel inputChannel) {
2077 super(inputChannel, mService.mH.getLooper());
2078 }
2079 @Override
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -07002080 public void onInputEvent(InputEvent event, int displayId) {
Chong Zhangacf11402015-11-04 16:23:10 -08002081 finishInputEvent(event, true);
2082 }
2083 }
2084 /**
2085 * Dummy event receiver for windows that died visible.
2086 */
2087 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2088
Chong Zhang112eb8c2015-11-02 11:17:00 -08002089 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002090 if (mInputChannel != null) {
2091 throw new IllegalStateException("Window already has an input channel.");
2092 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002093 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002094 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2095 mInputChannel = inputChannels[0];
2096 mClientChannel = inputChannels[1];
2097 mInputWindowHandle.inputChannel = inputChannels[0];
2098 if (outInputChannel != null) {
2099 mClientChannel.transferTo(outInputChannel);
2100 mClientChannel.dispose();
2101 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002102 } else {
2103 // If the window died visible, we setup a dummy input channel, so that taps
2104 // can still detected by input monitor channel, and we can relaunch the app.
2105 // Create dummy event receiver that simply reports all events as handled.
2106 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002107 }
2108 mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
Jeff Browncc4f7db2011-08-30 20:34:48 -07002109 }
2110
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002111 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002112 if (mDeadWindowEventReceiver != null) {
2113 mDeadWindowEventReceiver.dispose();
2114 mDeadWindowEventReceiver = null;
2115 }
2116
2117 // unregister server channel first otherwise it complains about broken channel
2118 if (mInputChannel != null) {
2119 mService.mInputManager.unregisterInputChannel(mInputChannel);
2120 mInputChannel.dispose();
2121 mInputChannel = null;
2122 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002123 if (mClientChannel != null) {
2124 mClientChannel.dispose();
2125 mClientChannel = null;
2126 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07002127 mInputWindowHandle.inputChannel = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002128 }
2129
Robert Carrf59b8dd2017-10-02 18:58:36 -07002130 private Dimmer getDimmer() {
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002131 Task task = getTask();
2132 if (task != null) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07002133 return task.getDimmer();
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002134 }
Robert Carrf07ef9e2017-11-21 12:12:49 -08002135 TaskStack taskStack = getStack();
2136 if (taskStack != null) {
2137 return taskStack.getDimmer();
2138 }
2139 return null;
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07002140 }
2141
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002142 /** Returns true if the replacement window was removed. */
2143 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2144 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2145 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2146 removeReplacedWindow();
2147 return true;
2148 }
2149
2150 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002151 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002152 if (c.removeReplacedWindowIfNeeded(replacement)) {
2153 return true;
2154 }
2155 }
2156 return false;
2157 }
2158
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002159 private void removeReplacedWindow() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002160 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002161 mWillReplaceWindow = false;
2162 mAnimateReplacingWindow = false;
2163 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002164 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002165 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002166 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002167 }
2168 }
2169
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002170 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2171 boolean replacementSet = false;
2172
2173 if (mWillReplaceWindow && mReplacementWindow == null
2174 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2175
2176 mReplacementWindow = replacementCandidate;
2177 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2178 replacementSet = true;
2179 }
2180
2181 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002182 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002183 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2184 }
2185
2186 return replacementSet;
2187 }
2188
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002189 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002190 final DisplayContent dc = getDisplayContent();
2191 if (dc != null) {
2192 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002193 }
2194 }
2195
Chong Zhang5117e272016-05-03 12:47:34 -07002196 void applyAdjustForImeIfNeeded() {
2197 final Task task = getTask();
2198 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2199 task.mStack.applyAdjustForImeIfNeeded(task);
2200 }
2201 }
2202
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002203 @Override
2204 void switchUser() {
2205 super.switchUser();
2206 if (isHiddenFromUserLocked()) {
2207 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2208 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
2209 hideLw(false);
2210 }
2211 }
2212
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002213 int getTouchableRegion(Region region, int flags) {
2214 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002215 if (modal && mAppToken != null) {
2216 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002217 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002218 // If this is a modal window we need to dismiss it if it's not full screen and the
2219 // touch happens outside of the frame that displays the content. This means we
2220 // need to intercept touches outside of that window. The dim layer user
2221 // associated with the window (task or stack) will give us the good bounds, as
2222 // they would be used to display the dim layer.
Robert Carrf59b8dd2017-10-02 18:58:36 -07002223 final Task task = getTask();
2224 if (task != null) {
2225 task.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002226 } else {
Robert Carrf59b8dd2017-10-02 18:58:36 -07002227 getStack().getDimBounds(mTmpRect);
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002228 }
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002229 if (inFreeformWindowingMode()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002230 // For freeform windows we the touch region to include the whole surface for the
2231 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002232 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2233 final int delta = WindowManagerService.dipToPixel(
2234 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2235 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002236 }
2237 region.set(mTmpRect);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002238 cropRegionToStackBoundsIfNeeded(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002239 } else {
2240 // Not modal or full screen modal
2241 getTouchableRegion(region);
2242 }
2243 return flags;
2244 }
2245
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002246 void checkPolicyVisibilityChange() {
2247 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2248 if (DEBUG_VISIBILITY) {
2249 Slog.v(TAG, "Policy visibility changing after anim in " +
2250 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2251 }
2252 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002253 if (!mPolicyVisibility) {
Jorim Jaggi2e05af22017-12-28 15:15:11 +01002254 mWinAnimator.hide("checkPolicyVisibilityChange");
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002255 if (mService.mCurrentFocus == this) {
2256 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2257 "setAnimationLocked: setting mFocusMayChange true");
2258 mService.mFocusMayChange = true;
Jorim Jaggi2e05af22017-12-28 15:15:11 +01002259 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002260 }
2261 // Window is no longer visible -- make sure if we were waiting
2262 // for it to be displayed before enabling the display, that
2263 // we allow the display to be enabled now.
2264 mService.enableScreenIfNeededLocked();
2265 }
2266 }
2267 }
2268
2269 void setRequestedSize(int requestedWidth, int requestedHeight) {
2270 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2271 mLayoutNeeded = true;
2272 mRequestedWidth = requestedWidth;
2273 mRequestedHeight = requestedHeight;
2274 }
2275 }
2276
Bryce Leef858b572017-06-29 14:03:33 -07002277 void prepareWindowToDisplayDuringRelayout(boolean wasVisible) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002278 // We need to turn on screen regardless of visibility.
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002279 if ((mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0) {
2280 if (DEBUG_VISIBILITY) Slog.v(TAG, "Relayout window turning screen on: " + this);
2281 mTurnOnScreen = true;
2282 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002283
2284 // If we were already visible, skip rest of preparation.
2285 if (wasVisible) {
2286 if (DEBUG_VISIBILITY) Slog.v(TAG,
2287 "Already visible and does not turn on screen, skip preparing: " + this);
2288 return;
2289 }
2290
2291 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2292 == SOFT_INPUT_ADJUST_RESIZE) {
2293 mLayoutNeeded = true;
2294 }
2295
David Stevens9440dc82017-03-16 19:00:20 -07002296 if (isDrawnLw() && mToken.okToAnimate()) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002297 mWinAnimator.applyEnterAnimationLocked();
2298 }
Bryce Leef858b572017-06-29 14:03:33 -07002299 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002300
Bryce Leef858b572017-06-29 14:03:33 -07002301 void getMergedConfiguration(MergedConfiguration outConfiguration) {
2302 final Configuration globalConfig = mService.mRoot.getConfiguration();
2303 final Configuration overrideConfig = getMergedOverrideConfiguration();
2304 outConfiguration.setConfiguration(globalConfig, overrideConfig);
2305 }
2306
Bryce Lee2b17afd2017-09-21 10:38:20 -07002307 void setLastReportedMergedConfiguration(MergedConfiguration config) {
2308 mLastReportedConfiguration.setTo(config);
2309 }
2310
2311 void getLastReportedMergedConfiguration(MergedConfiguration config) {
2312 config.setTo(mLastReportedConfiguration);
2313 }
2314
2315 private Configuration getLastReportedConfiguration() {
2316 return mLastReportedConfiguration.getMergedConfiguration();
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002317 }
2318
2319 void adjustStartingWindowFlags() {
2320 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2321 && mAppToken.startingWindow != null) {
2322 // Special handling of starting window over the base
2323 // window of the app: propagate lock screen flags to it,
2324 // to provide the correct semantics while starting.
2325 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2326 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2327 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2328 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2329 }
2330 }
2331
2332 void setWindowScale(int requestedWidth, int requestedHeight) {
2333 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2334
2335 if (scaledWindow) {
2336 // requested{Width|Height} Surface's physical size
2337 // attrs.{width|height} Size on screen
2338 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2339 mHScale = (mAttrs.width != requestedWidth) ?
2340 (mAttrs.width / (float)requestedWidth) : 1.0f;
2341 mVScale = (mAttrs.height != requestedHeight) ?
2342 (mAttrs.height / (float)requestedHeight) : 1.0f;
2343 } else {
2344 mHScale = mVScale = 1;
2345 }
2346 }
2347
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002348 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002349 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002350 public void binderDied() {
2351 try {
2352 synchronized(mService.mWindowMap) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002353 final WindowState win = mService.windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002354 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002355 if (win != null) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002356 final DisplayContent dc = getDisplayContent();
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002357 if (win.mAppToken != null && win.mAppToken.findMainWindow() == win) {
2358 mService.mTaskSnapshotController.onAppDied(win.mAppToken);
2359 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002360 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002361 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2362 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002363 // just in case they have the divider at an unstable position. Better
2364 // also reset drag resizing state, because the owner can't do it
2365 // anymore.
Wale Ogunwale61911492017-10-11 08:50:50 -07002366 final TaskStack stack =
Matthew Ng64e77cf2017-10-31 14:01:31 -07002367 dc.getSplitScreenPrimaryStackIgnoringVisibility();
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002368 if (stack != null) {
2369 stack.resetDockedStackToMiddle();
2370 }
Jorim Jaggidcb68142016-02-09 21:51:30 -08002371 mService.setDockedStackResizing(false);
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002372 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002373 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002374 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002375 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002376 }
2377 }
2378 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002379 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002380 }
2381 }
2382 }
2383
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002384 /**
2385 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2386 * because we want to preserve its location on screen to be re-activated later when the user
2387 * interacts with it.
2388 */
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002389 private boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwale89973222017-04-23 18:39:45 -07002390 if (!isWinVisibleLw() || mAppToken == null || mAppToken.isClientHidden()) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002391 // Not a visible app window or the app isn't dead.
2392 return false;
2393 }
2394
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002395 if (mAttrs.token != mClient.asBinder()) {
2396 // The window was add by a client using another client's app token. We don't want to
2397 // keep the dead window around for this case since this is meant for 'real' apps.
2398 return false;
2399 }
2400
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002401 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2402 // We don't keep starting windows since they were added by the window manager before
2403 // the app even launched.
2404 return false;
2405 }
2406
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002407 return getWindowConfiguration().keepVisibleDeadAppWindowOnScreen();
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002408 }
2409
Wale Ogunwaled045c822015-12-02 09:14:28 -08002410 /** @return true if this window desires key events. */
2411 boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002412 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002413 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002414 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002415 && (mAppToken == null || mAppToken.windowsAreFocusable())
Matthew Nge15352e2016-12-20 15:36:29 -08002416 && !canReceiveTouchInput();
2417 }
2418
2419 /** @return true if this window desires touch events. */
2420 boolean canReceiveTouchInput() {
Bryce Lee6d410262017-02-28 15:30:17 -08002421 return mAppToken != null && mAppToken.getTask() != null
2422 && mAppToken.getTask().mStack.shouldIgnoreInput();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002423 }
2424
Craig Mautner749a7bb2012-04-02 13:49:53 -07002425 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002426 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002427 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002428 }
2429
Craig Mautner749a7bb2012-04-02 13:49:53 -07002430 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002431 public boolean showLw(boolean doAnimation) {
2432 return showLw(doAnimation, true);
2433 }
2434
2435 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002436 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002437 return false;
2438 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002439 if (!mAppOpVisibility) {
2440 // Being hidden due to app op request.
2441 return false;
2442 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002443 if (mPermanentlyHidden) {
2444 // Permanently hidden until the app exists as apps aren't prepared
2445 // to handle their windows being removed from under them.
2446 return false;
2447 }
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002448 if (mForceHideNonSystemOverlayWindow) {
2449 // This is an alert window that is currently force hidden.
2450 return false;
2451 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002452 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002453 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002454 return false;
2455 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002456 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002457 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002458 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Jorim Jaggia5e10572017-11-15 14:36:26 +01002459 + mPolicyVisibility + " isAnimationSet=" + mWinAnimator.isAnimationSet());
David Stevens9440dc82017-03-16 19:00:20 -07002460 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002461 doAnimation = false;
Jorim Jaggia5e10572017-11-15 14:36:26 +01002462 } else if (mPolicyVisibility && !mWinAnimator.isAnimationSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002463 // Check for the case where we are currently visible and
2464 // not animating; we do not want to do animation at such a
2465 // point to become visible when we already are.
2466 doAnimation = false;
2467 }
2468 }
2469 mPolicyVisibility = true;
2470 mPolicyVisibilityAfterAnim = true;
2471 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002472 mWinAnimator.applyAnimationLocked(TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002473 }
2474 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002475 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002476 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002477 if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) {
2478 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2479 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002480 return true;
2481 }
2482
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002483 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002484 public boolean hideLw(boolean doAnimation) {
2485 return hideLw(doAnimation, true);
2486 }
2487
2488 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2489 if (doAnimation) {
David Stevens9440dc82017-03-16 19:00:20 -07002490 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002491 doAnimation = false;
2492 }
2493 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002494 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002495 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002496 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002497 return false;
2498 }
2499 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002500 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
Jorim Jaggia5e10572017-11-15 14:36:26 +01002501 if (!mWinAnimator.isAnimationSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002502 doAnimation = false;
2503 }
2504 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002505 mPolicyVisibilityAfterAnim = false;
2506 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002507 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002508 mPolicyVisibility = false;
2509 // Window is no longer visible -- make sure if we were waiting
2510 // for it to be displayed before enabling the display, that
2511 // we allow the display to be enabled now.
2512 mService.enableScreenIfNeededLocked();
2513 if (mService.mCurrentFocus == this) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002514 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002515 "WindowState.hideLw: setting mFocusMayChange true");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002516 mService.mFocusMayChange = true;
2517 }
2518 }
2519 if (requestAnim) {
Craig Mautner96868332012-12-04 14:29:11 -08002520 mService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002521 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002522 if (mService.mCurrentFocus == this) {
2523 mService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
2524 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002525 return true;
2526 }
2527
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002528 void setForceHideNonSystemOverlayWindowIfNeeded(boolean forceHide) {
2529 if (mOwnerCanAddInternalSystemWindow
2530 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2531 return;
2532 }
2533 if (mForceHideNonSystemOverlayWindow == forceHide) {
2534 return;
2535 }
2536 mForceHideNonSystemOverlayWindow = forceHide;
2537 if (forceHide) {
2538 hideLw(true /* doAnimation */, true /* requestAnim */);
2539 } else {
2540 showLw(true /* doAnimation */, true /* requestAnim */);
2541 }
2542 }
2543
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002544 public void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002545 if (mAppOpVisibility != state) {
2546 mAppOpVisibility = state;
2547 if (state) {
2548 // If the policy visibility had last been to hide, then this
2549 // will incorrectly show at this point since we lost that
2550 // information. Not a big deal -- for the windows that have app
2551 // ops modifies they should only be hidden by policy due to the
2552 // lock screen, and the user won't be changing this if locked.
2553 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002554 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002555 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002556 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002557 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002558 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002559 }
2560
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002561 public void hidePermanentlyLw() {
2562 if (!mPermanentlyHidden) {
2563 mPermanentlyHidden = true;
2564 hideLw(true, true);
2565 }
2566 }
2567
Jeff Brownc2932a12014-11-20 18:04:05 -08002568 public void pokeDrawLockLw(long timeout) {
2569 if (isVisibleOrAdding()) {
2570 if (mDrawLock == null) {
2571 // We want the tag name to be somewhat stable so that it is easier to correlate
2572 // in wake lock statistics. So in particular, we don't want to include the
2573 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002574 final CharSequence tag = getWindowTag();
Jeff Brownc2932a12014-11-20 18:04:05 -08002575 mDrawLock = mService.mPowerManager.newWakeLock(
2576 PowerManager.DRAW_WAKE_LOCK, "Window:" + tag);
2577 mDrawLock.setReferenceCounted(false);
2578 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2579 }
2580 // Each call to acquire resets the timeout.
2581 if (DEBUG_POWER) {
2582 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2583 + mAttrs.packageName);
2584 }
2585 mDrawLock.acquire(timeout);
2586 } else if (DEBUG_POWER) {
2587 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2588 + "owned by " + mAttrs.packageName);
2589 }
2590 }
2591
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002592 @Override
2593 public boolean isAlive() {
2594 return mClient.asBinder().isBinderAlive();
2595 }
2596
Craig Mautnera987d432012-10-11 14:07:58 -07002597 boolean isClosing() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -08002598 return mAnimatingExit || (mService.mClosingApps.contains(mAppToken));
Craig Mautnera987d432012-10-11 14:07:58 -07002599 }
2600
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002601 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2602 animators.add(mWinAnimator);
2603
2604 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002605 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002606 c.addWinAnimatorToList(animators);
2607 }
2608 }
2609
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002610 void sendAppVisibilityToClients() {
2611 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002612
Wale Ogunwale89973222017-04-23 18:39:45 -07002613 final boolean clientHidden = mAppToken.isClientHidden();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002614 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2615 // Don't hide the starting window.
2616 return;
2617 }
2618
Wale Ogunwale89973222017-04-23 18:39:45 -07002619 if (clientHidden) {
2620 // Once we are notifying the client that it's visibility has changed, we need to prevent
2621 // it from destroying child surfaces until the animation has finished. We do this by
2622 // detaching any surface control the client added from the client.
2623 for (int i = mChildren.size() - 1; i >= 0; --i) {
2624 final WindowState c = mChildren.get(i);
2625 c.mWinAnimator.detachChildren();
2626 }
2627
2628 mWinAnimator.detachChildren();
2629 }
2630
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002631 try {
2632 if (DEBUG_VISIBILITY) Slog.v(TAG,
2633 "Setting visibility of " + this + ": " + (!clientHidden));
2634 mClient.dispatchAppVisibility(!clientHidden);
2635 } catch (RemoteException e) {
2636 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002637 }
2638
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002639 void onStartFreezingScreen() {
2640 mAppFreezing = true;
2641 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002642 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002643 c.onStartFreezingScreen();
2644 }
2645 }
2646
2647 boolean onStopFreezingScreen() {
2648 boolean unfrozeWindows = false;
2649 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002650 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002651 unfrozeWindows |= c.onStopFreezingScreen();
2652 }
2653
2654 if (!mAppFreezing) {
2655 return unfrozeWindows;
2656 }
2657
Wale Ogunwale953171d2016-09-30 09:17:30 -07002658 mAppFreezing = false;
2659
Bryce Lee8c3cf382017-07-06 19:47:10 -07002660 if (mHasSurface && !getOrientationChanging()
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002661 && mService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
2662 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
Bryce Lee8c3cf382017-07-06 19:47:10 -07002663 setOrientationChanging(true);
Wale Ogunwalee05f5012016-09-16 16:27:29 -07002664 mService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002665 }
2666 mLastFreezeDuration = 0;
2667 setDisplayLayoutNeeded();
2668 return true;
2669 }
2670
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002671 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2672 boolean destroyedSomething = false;
Jorim Jaggi59f3e922018-01-05 15:40:32 +01002673
2674 // Copying to a different list as multiple children can be removed.
2675 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
2676 for (int i = childWindows.size() - 1; i >= 0; --i) {
2677 final WindowState c = childWindows.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002678 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2679 }
2680
Robert Carrdb2f6e62017-03-01 20:17:58 -08002681 if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) {
2682 return destroyedSomething;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002683 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08002684
2685 if (appStopped || mWindowRemovalAllowed) {
2686 mWinAnimator.destroyPreservedSurfaceLocked();
2687 }
2688
2689 if (mDestroying) {
2690 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2691 + " destroySurfaces: appStopped=" + appStopped
2692 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2693 + " win.mRemoveOnExit=" + mRemoveOnExit);
2694 if (!cleanupOnResume || mRemoveOnExit) {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002695 destroySurfaceUnchecked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08002696 }
2697 if (mRemoveOnExit) {
2698 removeImmediately();
2699 }
2700 if (cleanupOnResume) {
2701 requestUpdateWallpaperIfNeeded();
2702 }
2703 mDestroying = false;
2704 destroyedSomething = true;
2705 }
2706
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002707 return destroyedSomething;
2708 }
Chris Craik3131bde2016-05-06 13:39:08 -07002709
Robert Carr89a28ab2017-04-24 15:33:11 -07002710 // Destroy or save the application surface without checking
2711 // various indicators of whether the client has released the surface.
2712 // This is in general unsafe, and most callers should use {@link #destroySurface}
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002713 void destroySurfaceUnchecked() {
2714 mWinAnimator.destroySurfaceLocked();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002715
Chong Zhang92147042016-05-09 12:47:11 -07002716 // Clear animating flags now, since the surface is now gone. (Note this is true even
2717 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2718 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002719 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002720
Craig Mautner69b08182012-09-05 13:07:13 -07002721 @Override
2722 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002723 final DisplayContent displayContent = getDisplayContent();
2724 if (displayContent == null) {
2725 // Only a window that was on a non-default display can be detached from it.
2726 return false;
2727 }
Winson Chung47a3e652014-05-21 16:03:42 -07002728 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002729 }
2730
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002731 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07002732 mShowToOwnerOnly = showToOwnerOnly;
2733 }
2734
Wale Ogunwaleea92d972016-12-08 07:33:13 -08002735 private boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002736 // Child windows are evaluated based on their parent window.
2737 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002738 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale72919d22016-12-08 18:58:50 -08002739 && win.mAppToken != null && win.mAppToken.mShowForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002740
2741 // All window frames that are fullscreen extend above status bar, but some don't extend
2742 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2743 // bottom right.
2744 if (win.mFrame.left <= win.mDisplayFrame.left
2745 && win.mFrame.top <= win.mDisplayFrame.top
2746 && win.mFrame.right >= win.mStableFrame.right
2747 && win.mFrame.bottom >= win.mStableFrame.bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002748 // Is a fullscreen window, like the clock alarm. Show to everyone.
2749 return false;
2750 }
2751 }
2752
Craig Mautner341220f2012-10-16 15:20:09 -07002753 return win.mShowToOwnerOnly
Kenny Guy2a764942014-04-02 13:29:20 +01002754 && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002755 }
2756
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002757 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2758 outRegion.set(
2759 frame.left + inset.left, frame.top + inset.top,
2760 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002761 }
2762
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002763 void getTouchableRegion(Region outRegion) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002764 final Rect frame = mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002765 switch (mTouchableInsets) {
2766 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002767 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002768 outRegion.set(frame);
2769 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002770 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002771 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002772 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002773 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002774 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002775 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002776 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002777 outRegion.set(mGivenTouchableRegion);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002778 outRegion.translate(frame.left, frame.top);
2779 break;
2780 }
2781 }
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002782 cropRegionToStackBoundsIfNeeded(outRegion);
2783 }
2784
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002785 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002786 final Task task = getTask();
2787 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002788 return;
2789 }
2790
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002791 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002792 if (stack == null) {
2793 return;
2794 }
2795
2796 stack.getDimBounds(mTmpRect);
2797 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002798 }
2799
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002800 /**
2801 * Report a focus change. Must be called with no locks held, and consistently
2802 * from the same serialized thread (such as dispatched from a handler).
2803 */
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07002804 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002805 try {
2806 mClient.windowFocusChanged(focused, inTouchMode);
2807 } catch (RemoteException e) {
2808 }
2809 if (mFocusCallbacks != null) {
2810 final int N = mFocusCallbacks.beginBroadcast();
2811 for (int i=0; i<N; i++) {
2812 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2813 try {
2814 if (focused) {
2815 obs.focusGained(mWindowId.asBinder());
2816 } else {
2817 obs.focusLost(mWindowId.asBinder());
2818 }
2819 } catch (RemoteException e) {
2820 }
2821 }
2822 mFocusCallbacks.finishBroadcast();
2823 }
2824 }
2825
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002826 @Override
2827 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002828 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002829 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002830 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002831
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002832 return super.getConfiguration();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002833 }
2834
Craig Mautnerdf88d732014-01-27 09:21:32 -08002835 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002836 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08002837 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002838 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
2839 + ": " + mCompatFrame);
Bryce Leef858b572017-06-29 14:03:33 -07002840 final MergedConfiguration mergedConfiguration =
2841 new MergedConfiguration(mService.mRoot.getConfiguration(),
2842 getMergedOverrideConfiguration());
2843
Bryce Lee2b17afd2017-09-21 10:38:20 -07002844 setLastReportedMergedConfiguration(mergedConfiguration);
Bryce Leef858b572017-06-29 14:03:33 -07002845
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002846 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002847 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
2848
Craig Mautnerdf88d732014-01-27 09:21:32 -08002849 final Rect frame = mFrame;
2850 final Rect overscanInsets = mLastOverscanInsets;
2851 final Rect contentInsets = mLastContentInsets;
2852 final Rect visibleInsets = mLastVisibleInsets;
Adrian Roosfa104232014-06-20 16:10:14 -07002853 final Rect stableInsets = mLastStableInsets;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002854 final Rect outsets = mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002855 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Andrii Kulianb2e37802017-01-11 00:36:44 -08002856 final boolean reportOrientation = mReportOrientationChanged;
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002857 final int displayId = getDisplayId();
Adrian Roos5c6b6222017-11-07 17:36:10 +01002858 final DisplayCutout displayCutout = mDisplayCutout;
Chet Haase8eb48d22014-09-24 07:31:29 -07002859 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
2860 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002861 // To prevent deadlock simulate one-way call if win.mClient is a local object.
2862 mService.mH.post(new Runnable() {
2863 @Override
2864 public void run() {
2865 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002866 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07002867 stableInsets, outsets, reportDraw, mergedConfiguration,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002868 reportOrientation, displayId, displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002869 } catch (RemoteException e) {
2870 // Not a remote call, RemoteException won't be raised.
2871 }
2872 }
2873 });
2874 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002875 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002876 outsets, reportDraw, mergedConfiguration, reportOrientation, displayId,
2877 displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002878 }
Svetoslav4604abc2014-06-10 18:59:30 -07002879
2880 //TODO (multidisplay): Accessibility supported only for the default display.
Andrii Kulian5406e7a2016-10-21 11:55:23 -07002881 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
Svetoslavf7174e82014-06-12 11:29:35 -07002882 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07002883 }
2884
Craig Mautnerdf88d732014-01-27 09:21:32 -08002885 mOverscanInsetsChanged = false;
2886 mContentInsetsChanged = false;
2887 mVisibleInsetsChanged = false;
Adrian Roosfa104232014-06-20 16:10:14 -07002888 mStableInsetsChanged = false;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07002889 mOutsetsChanged = false;
Robert Carr31aa98b2016-07-20 15:29:03 -07002890 mFrameSizeChanged = false;
Adrian Roos5c6b6222017-11-07 17:36:10 +01002891 mDisplayCutoutChanged = false;
Andrii Kulianeb1d3222016-05-16 15:17:55 -07002892 mResizedWhileNotDragResizingReported = true;
Craig Mautnerdf88d732014-01-27 09:21:32 -08002893 mWinAnimator.mSurfaceResized = false;
Andrii Kulianb2e37802017-01-11 00:36:44 -08002894 mReportOrientationChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08002895 } catch (RemoteException e) {
Bryce Lee8c3cf382017-07-06 19:47:10 -07002896 setOrientationChanging(false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002897 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
2898 - mService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08002899 // We are assuming the hosting process is dead or in a zombie state.
2900 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
2901 + ", removing this window.");
2902 mService.mPendingRemove.add(this);
Filip Gruszczynski24966d42015-09-05 15:00:00 -07002903 mService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08002904 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002905 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002906 }
2907
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002908 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08002909 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
2910 // start even if we haven't received the relayout window, so that the client requests
2911 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
2912 // until the window to small size, otherwise the multithread renderer will shift last
2913 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
2914 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002915 boolean resizing = isDragResizing() || isDragResizeChanged();
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002916 if (getWindowConfiguration().useWindowFrameForBackdrop() || !resizing) {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002917 return frame;
2918 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07002919 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002920 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002921 return mTmpRect;
2922 }
2923
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002924 private int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08002925 final TaskStack stack = getStack();
2926 if (stack == null) {
2927 return INVALID_STACK_ID;
2928 }
2929 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08002930 }
2931
2932 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
2933 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002934 MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId,
2935 DisplayCutout displayCutout)
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002936 throws RemoteException {
Andrii Kulianb2e37802017-01-11 00:36:44 -08002937 final boolean forceRelayout = isDragResizeChanged() || mResizedWhileNotDragResizing
2938 || reportOrientation;
Chong Zhangedaf3052016-04-22 15:04:31 -07002939
Jorim Jaggidc249c42015-12-15 14:57:31 -08002940 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Andrii Kulian44607962017-03-16 11:06:24 -07002941 reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002942 mPolicy.isNavBarForcedShownLw(this), displayId,
2943 new DisplayCutout.ParcelableWrapper(displayCutout));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08002944 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002945 }
2946
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002947 public void registerFocusObserver(IWindowFocusObserver observer) {
2948 synchronized(mService.mWindowMap) {
2949 if (mFocusCallbacks == null) {
2950 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
2951 }
2952 mFocusCallbacks.register(observer);
2953 }
2954 }
2955
2956 public void unregisterFocusObserver(IWindowFocusObserver observer) {
2957 synchronized(mService.mWindowMap) {
2958 if (mFocusCallbacks != null) {
2959 mFocusCallbacks.unregister(observer);
2960 }
2961 }
2962 }
2963
2964 public boolean isFocused() {
2965 synchronized(mService.mWindowMap) {
2966 return mService.mCurrentFocus == this;
2967 }
2968 }
2969
Wale Ogunwale9185fb02016-03-11 18:06:14 -08002970 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07002971 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08002972 final Task task = getTask();
2973 return task != null && !task.isFullscreen();
2974 }
2975
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002976 /** Is this window in a container that takes up the entire screen space? */
2977 private boolean inFullscreenContainer() {
Bryce Leef3c6a472017-11-14 14:53:06 -08002978 return mAppToken == null || (mAppToken.matchParentBounds() && !isInMultiWindowMode());
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07002979 }
2980
Andrii Kulian283acd22017-08-03 04:03:51 -07002981 /** @return true when the window is in fullscreen task, but has non-fullscreen bounds set. */
2982 boolean isLetterboxedAppWindow() {
Adrian Roos865c70f2018-01-10 17:32:27 +01002983 return !isInMultiWindowMode() && mAppToken != null && !mAppToken.matchParentBounds()
2984 || isLetterboxedForDisplayCutoutLw();
Adrian Roos4d18a2e2017-12-19 19:08:05 +01002985 }
2986
Adrian Roos865c70f2018-01-10 17:32:27 +01002987 @Override
2988 public boolean isLetterboxedForDisplayCutoutLw() {
2989 if (mAppToken == null) {
2990 // Only windows with an AppWindowToken are letterboxed.
2991 return false;
2992 }
Adrian Roos4d18a2e2017-12-19 19:08:05 +01002993 if (getDisplayContent().getDisplayInfo().displayCutout == null) {
2994 // No cutout, no letterbox.
2995 return false;
2996 }
2997 if ((mAttrs.flags2 & FLAG2_LAYOUT_IN_DISPLAY_CUTOUT_AREA) != 0) {
2998 // Layout in cutout, no letterbox.
2999 return false;
3000 }
3001 // TODO: handle dialogs and other non-filling windows
3002 // Letterbox if any fullscreen mode is set.
3003 final int fl = mAttrs.flags;
3004 final int sysui = mSystemUiVisibility;
Adrian Roos2dfb7852018-01-15 13:41:37 +01003005 return (fl & FLAG_FULLSCREEN) != 0 || (sysui & (SYSTEM_UI_FLAG_FULLSCREEN)) != 0;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003006 }
3007
Chong Zhang3005e752015-09-18 18:46:28 -07003008 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003009 return mDragResizing != computeDragResizing();
3010 }
3011
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003012 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003013 void setWaitingForDrawnIfResizingChanged() {
3014 if (isDragResizeChanged()) {
3015 mService.mWaitingForDrawn.add(this);
3016 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003017 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003018 }
3019
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003020 /**
3021 * @return Whether we reported a drag resize change to the application or not already.
3022 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003023 private boolean isDragResizingChangeReported() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003024 return mDragResizingChangeReported;
3025 }
3026
3027 /**
3028 * Resets the state whether we reported a drag resize change to the app.
3029 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003030 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003031 void resetDragResizingChangeReported() {
3032 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003033 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003034 }
3035
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003036 /**
3037 * Set whether we got resized but drag resizing flag was false.
3038 * @see #isResizedWhileNotDragResizing().
3039 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003040 private void setResizedWhileNotDragResizing(boolean resizedWhileNotDragResizing) {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003041 mResizedWhileNotDragResizing = resizedWhileNotDragResizing;
3042 mResizedWhileNotDragResizingReported = !resizedWhileNotDragResizing;
3043 }
3044
3045 /**
3046 * Indicates whether we got resized but drag resizing flag was false. In this case, we also
3047 * need to recreate the surface and defer surface bound updates in order to make sure the
3048 * buffer contents and the positioning/size stay in sync.
3049 */
3050 boolean isResizedWhileNotDragResizing() {
3051 return mResizedWhileNotDragResizing;
3052 }
3053
3054 /**
3055 * @return Whether we reported "resize while not drag resizing" to the application.
3056 * @see #isResizedWhileNotDragResizing()
3057 */
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003058 private boolean isResizedWhileNotDragResizingReported() {
Andrii Kulianeb1d3222016-05-16 15:17:55 -07003059 return mResizedWhileNotDragResizingReported;
3060 }
3061
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003062 int getResizeMode() {
3063 return mResizeMode;
3064 }
3065
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003066 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003067 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003068 if (task == null) {
3069 return false;
3070 }
Tomasz Mikolajewskiaf20b8d2017-11-20 16:11:33 +09003071 if (!inSplitScreenWindowingMode() && !inFreeformWindowingMode()) {
Winson Chung2af04b32017-01-24 16:21:13 -08003072 return false;
3073 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003074 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003075 // Floating windows never enter drag resize mode.
3076 return false;
3077 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003078 if (task.isDragResizing()) {
3079 return true;
3080 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003081
3082 // If the bounds are currently frozen, it means that the layout size that the app sees
3083 // and the bounds we clip this window to might be different. In order to avoid holes, we
3084 // simulate that we are still resizing so the app fills the hole with the resizing
3085 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003086 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003087 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003088 !task.inFreeformWindowingMode() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003089
Chong Zhang3005e752015-09-18 18:46:28 -07003090 }
3091
3092 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003093 final boolean resizing = computeDragResizing();
3094 if (resizing == mDragResizing) {
3095 return;
3096 }
3097 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003098 final Task task = getTask();
3099 if (task != null && task.isDragResizing()) {
3100 mResizeMode = task.getDragResizeMode();
3101 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003102 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003103 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3104 : DRAG_RESIZE_MODE_FREEFORM;
3105 }
Chong Zhang3005e752015-09-18 18:46:28 -07003106 }
3107
3108 boolean isDragResizing() {
3109 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003110 }
3111
Robert Carr2487ce72016-04-07 15:18:45 -07003112 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003113 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3114 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003115 }
3116
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07003117 @CallSuper
3118 @Override
Adrian Roos4921ccf2017-09-28 16:54:06 +02003119 public void writeToProto(ProtoOutputStream proto, long fieldId, boolean trim) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003120 final long token = proto.start(fieldId);
Adrian Roos4921ccf2017-09-28 16:54:06 +02003121 super.writeToProto(proto, WINDOW_CONTAINER, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003122 writeIdentifierToProto(proto, IDENTIFIER);
3123 proto.write(DISPLAY_ID, getDisplayId());
3124 proto.write(STACK_ID, getStackId());
3125 mAttrs.writeToProto(proto, ATTRIBUTES);
3126 mGivenContentInsets.writeToProto(proto, GIVEN_CONTENT_INSETS);
3127 mFrame.writeToProto(proto, FRAME);
3128 mContainingFrame.writeToProto(proto, CONTAINING_FRAME);
3129 mParentFrame.writeToProto(proto, PARENT_FRAME);
3130 mContentFrame.writeToProto(proto, CONTENT_FRAME);
3131 mContentInsets.writeToProto(proto, CONTENT_INSETS);
3132 mAttrs.surfaceInsets.writeToProto(proto, SURFACE_INSETS);
Jorim Jaggi45be1c4c2017-12-15 18:44:43 +01003133 mSurfacePosition.writeToProto(proto, SURFACE_POSITION);
3134 mShownPosition.writeToProto(proto, SHOWN_POSITION);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003135 mWinAnimator.writeToProto(proto, ANIMATOR);
3136 proto.write(ANIMATING_EXIT, mAnimatingExit);
3137 for (int i = 0; i < mChildren.size(); i++) {
Adrian Roos4921ccf2017-09-28 16:54:06 +02003138 mChildren.get(i).writeToProto(proto, CHILD_WINDOWS, trim);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003139 }
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003140 proto.write(REQUESTED_WIDTH, mRequestedWidth);
3141 proto.write(REQUESTED_HEIGHT, mRequestedHeight);
3142 proto.write(VIEW_VISIBILITY, mViewVisibility);
3143 proto.write(SYSTEM_UI_VISIBILITY, mSystemUiVisibility);
3144 proto.write(HAS_SURFACE, mHasSurface);
3145 proto.write(IS_READY_FOR_DISPLAY, isReadyForDisplay());
3146 mDisplayFrame.writeToProto(proto, DISPLAY_FRAME);
3147 mOverscanFrame.writeToProto(proto, OVERSCAN_FRAME);
3148 mVisibleFrame.writeToProto(proto, VISIBLE_FRAME);
3149 mDecorFrame.writeToProto(proto, DECOR_FRAME);
3150 mOutsetFrame.writeToProto(proto, OUTSET_FRAME);
3151 mOverscanInsets.writeToProto(proto, OVERSCAN_INSETS);
3152 mVisibleInsets.writeToProto(proto, VISIBLE_INSETS);
3153 mStableInsets.writeToProto(proto, STABLE_INSETS);
3154 mOutsets.writeToProto(proto, OUTSETS);
3155 mDisplayCutout.writeToProto(proto, CUTOUT);
3156 proto.write(REMOVE_ON_EXIT, mRemoveOnExit);
3157 proto.write(DESTROYING, mDestroying);
3158 proto.write(REMOVED, mRemoved);
3159 proto.write(IS_ON_SCREEN, isOnScreen());
3160 proto.write(IS_VISIBLE, isVisible());
Steven Timotiusaf03df62017-07-18 16:56:43 -07003161 proto.end(token);
3162 }
3163
3164 void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) {
3165 final long token = proto.start(fieldId);
3166 proto.write(HASH_CODE, System.identityHashCode(this));
3167 proto.write(USER_ID, UserHandle.getUserId(mOwnerUid));
3168 final CharSequence title = getWindowTag();
3169 if (title != null) {
3170 proto.write(TITLE, title.toString());
3171 }
3172 proto.end(token);
3173 }
3174
Jorim Jaggia5e10572017-11-15 14:36:26 +01003175 @Override
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003176 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003177 final TaskStack stack = getStack();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003178 pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003179 if (stack != null) {
3180 pw.print(" stackId="); pw.print(stack.mStackId);
3181 }
Craig Mautner59c00972012-07-30 12:10:24 -07003182 pw.print(" mSession="); pw.print(mSession);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003183 pw.print(" mClient="); pw.println(mClient.asBinder());
Craig Mautner88400d32012-09-30 12:35:45 -07003184 pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
Dianne Hackbornc2293022013-02-06 23:14:49 -08003185 pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
3186 pw.print(" package="); pw.print(mAttrs.packageName);
3187 pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
Jorim Jaggi484851b2017-09-22 16:03:27 +02003188 pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs.toString(prefix));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003189 pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
3190 pw.print(" h="); pw.print(mRequestedHeight);
3191 pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003192 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
3193 pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
3194 pw.print(" h="); pw.println(mLastRequestedHeight);
3195 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003196 if (mIsChildWindow || mLayoutAttached) {
3197 pw.print(prefix); pw.print("mParentWindow="); pw.print(getParentWindow());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003198 pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
3199 }
3200 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
3201 pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
3202 pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
3203 pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
3204 pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
3205 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003206 if (dumpAll) {
3207 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3208 pw.print(" mSubLayer="); pw.print(mSubLayer);
3209 pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
Craig Mautnerc2f9be02012-03-27 17:32:29 -07003210 pw.print("="); pw.print(mWinAnimator.mAnimLayer);
3211 pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003212 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003213 if (dumpAll) {
3214 pw.print(prefix); pw.print("mToken="); pw.println(mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003215 if (mAppToken != null) {
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003216 pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
3217 pw.print(prefix); pw.print(" isAnimatingWithSavedSurface()=");
Bryce Lee6311c4b2017-07-06 14:09:29 -07003218 pw.print(" mAppDied=");pw.print(mAppDied);
3219 pw.print(prefix); pw.print("drawnStateEvaluated=");
3220 pw.print(getDrawnStateEvaluated());
3221 pw.print(prefix); pw.print("mightAffectAllDrawn=");
Jorim Jaggie7d2b852017-08-28 17:55:15 +02003222 pw.println(mightAffectAllDrawn());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003223 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003224 pw.print(prefix); pw.print("mViewVisibility=0x");
3225 pw.print(Integer.toHexString(mViewVisibility));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003226 pw.print(" mHaveFrame="); pw.print(mHaveFrame);
3227 pw.print(" mObscured="); pw.println(mObscured);
Dianne Hackborn9a230e02011-10-06 11:51:27 -07003228 pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
3229 pw.print(" mSystemUiVisibility=0x");
3230 pw.println(Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003231 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003232 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003233 || isParentWindowHidden()|| mPermanentlyHidden || mForceHideNonSystemOverlayWindow) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003234 pw.print(prefix); pw.print("mPolicyVisibility=");
3235 pw.print(mPolicyVisibility);
3236 pw.print(" mPolicyVisibilityAfterAnim=");
3237 pw.print(mPolicyVisibilityAfterAnim);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003238 pw.print(" mAppOpVisibility=");
3239 pw.print(mAppOpVisibility);
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003240 pw.print(" parentHidden="); pw.print(isParentWindowHidden());
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003241 pw.print(" mPermanentlyHidden="); pw.print(mPermanentlyHidden);
3242 pw.print(" mForceHideNonSystemOverlayWindow="); pw.println(
3243 mForceHideNonSystemOverlayWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003244 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003245 if (!mRelayoutCalled || mLayoutNeeded) {
3246 pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
3247 pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003248 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003249 if (mXOffset != 0 || mYOffset != 0) {
3250 pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
3251 pw.print(" y="); pw.println(mYOffset);
3252 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003253 if (dumpAll) {
3254 pw.print(prefix); pw.print("mGivenContentInsets=");
3255 mGivenContentInsets.printShortString(pw);
3256 pw.print(" mGivenVisibleInsets=");
3257 mGivenVisibleInsets.printShortString(pw);
3258 pw.println();
3259 if (mTouchableInsets != 0 || mGivenInsetsPending) {
3260 pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
3261 pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003262 Region region = new Region();
3263 getTouchableRegion(region);
3264 pw.print(prefix); pw.print("touchable region="); pw.println(region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003265 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07003266 pw.print(prefix); pw.print("mFullConfiguration="); pw.println(getConfiguration());
3267 pw.print(prefix); pw.print("mLastReportedConfiguration=");
Bryce Lee2b17afd2017-09-21 10:38:20 -07003268 pw.println(getLastReportedConfiguration());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003269 }
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07003270 pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07003271 pw.print(" mShownPosition="); mShownPosition.printShortString(pw);
Chong Zhanga8975bd2016-01-28 17:13:47 -08003272 pw.print(" isReadyForDisplay()="); pw.print(isReadyForDisplay());
Wale Ogunwale9017ec02016-02-25 08:55:25 -08003273 pw.print(" mWindowRemovalAllowed="); pw.println(mWindowRemovalAllowed);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003274 if (dumpAll) {
3275 pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
3276 pw.print(" last="); mLastFrame.printShortString(pw);
3277 pw.println();
3278 }
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003279 if (mEnforceSizeCompat) {
3280 pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003281 pw.println();
3282 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003283 if (dumpAll) {
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003284 pw.print(prefix); pw.print("Frames: containing=");
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003285 mContainingFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003286 pw.print(" parent="); mParentFrame.printShortString(pw);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003287 pw.println();
3288 pw.print(prefix); pw.print(" display="); mDisplayFrame.printShortString(pw);
3289 pw.print(" overscan="); mOverscanFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003290 pw.println();
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003291 pw.print(prefix); pw.print(" content="); mContentFrame.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003292 pw.print(" visible="); mVisibleFrame.printShortString(pw);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003293 pw.println();
John Spurlock46646232013-09-30 22:32:42 -04003294 pw.print(prefix); pw.print(" decor="); mDecorFrame.printShortString(pw);
3295 pw.println();
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003296 pw.print(prefix); pw.print(" outset="); mOutsetFrame.printShortString(pw);
3297 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003298 pw.print(prefix); pw.print("Cur insets: overscan=");
3299 mOverscanInsets.printShortString(pw);
3300 pw.print(" content="); mContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003301 pw.print(" visible="); mVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003302 pw.print(" stable="); mStableInsets.printShortString(pw);
Wale Ogunwale6bab4cf2016-04-07 12:23:08 -07003303 pw.print(" surface="); mAttrs.surfaceInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003304 pw.print(" outsets="); mOutsets.printShortString(pw);
Adrian Roos5c6b6222017-11-07 17:36:10 +01003305 pw.print(" cutout=" + mDisplayCutout);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003306 pw.println();
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003307 pw.print(prefix); pw.print("Lst insets: overscan=");
3308 mLastOverscanInsets.printShortString(pw);
3309 pw.print(" content="); mLastContentInsets.printShortString(pw);
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003310 pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
Adrian Roosfa104232014-06-20 16:10:14 -07003311 pw.print(" stable="); mLastStableInsets.printShortString(pw);
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003312 pw.print(" physical="); mLastOutsets.printShortString(pw);
3313 pw.print(" outset="); mLastOutsets.printShortString(pw);
Adrian Roos5c6b6222017-11-07 17:36:10 +01003314 pw.print(" cutout=" + mLastDisplayCutout);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003315 pw.println();
3316 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01003317 super.dump(pw, prefix, dumpAll);
Dianne Hackborn529e7442012-11-01 14:22:28 -07003318 pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
3319 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003320 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
3321 pw.print(prefix); pw.print("mAnimatingExit="); pw.print(mAnimatingExit);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003322 pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
3323 pw.print(" mDestroying="); pw.print(mDestroying);
3324 pw.print(" mRemoved="); pw.println(mRemoved);
3325 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07003326 if (getOrientationChanging() || mAppFreezing || mTurnOnScreen
Andrii Kulianb2e37802017-01-11 00:36:44 -08003327 || mReportOrientationChanged) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003328 pw.print(prefix); pw.print("mOrientationChanging=");
3329 pw.print(mOrientationChanging);
Bryce Lee8c3cf382017-07-06 19:47:10 -07003330 pw.print(" configOrientationChanging=");
Bryce Lee2b17afd2017-09-21 10:38:20 -07003331 pw.print(getLastReportedConfiguration().orientation
Bryce Lee8c3cf382017-07-06 19:47:10 -07003332 != getConfiguration().orientation);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003333 pw.print(" mAppFreezing="); pw.print(mAppFreezing);
Wale Ogunwalebfa81ad2017-05-24 15:14:42 -07003334 pw.print(" mTurnOnScreen="); pw.print(mTurnOnScreen);
Andrii Kulianb2e37802017-01-11 00:36:44 -08003335 pw.print(" mReportOrientationChanged="); pw.println(mReportOrientationChanged);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003336 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003337 if (mLastFreezeDuration != 0) {
3338 pw.print(prefix); pw.print("mLastFreezeDuration=");
3339 TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
3340 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003341 if (mHScale != 1 || mVScale != 1) {
3342 pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
3343 pw.print(" mVScale="); pw.println(mVScale);
3344 }
3345 if (mWallpaperX != -1 || mWallpaperY != -1) {
3346 pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
3347 pw.print(" mWallpaperY="); pw.println(mWallpaperY);
3348 }
3349 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
3350 pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
3351 pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
3352 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003353 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3354 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
3355 pw.print(prefix); pw.print("mWallpaperDisplayOffsetX=");
3356 pw.print(mWallpaperDisplayOffsetX);
3357 pw.print(" mWallpaperDisplayOffsetY=");
3358 pw.println(mWallpaperDisplayOffsetY);
3359 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003360 if (mDrawLock != null) {
Wale Ogunwale85b90ab2015-04-27 20:54:47 -07003361 pw.print(prefix); pw.println("mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003362 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003363 if (isDragResizing()) {
3364 pw.print(prefix); pw.println("isDragResizing=" + isDragResizing());
3365 }
3366 if (computeDragResizing()) {
3367 pw.print(prefix); pw.println("computeDragResizing=" + computeDragResizing());
3368 }
Bryce Lee6311c4b2017-07-06 14:09:29 -07003369 pw.print(prefix); pw.println("isOnScreen=" + isOnScreen());
3370 pw.print(prefix); pw.println("isVisible=" + isVisible());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003371 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003372
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003373 @Override
3374 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003375 return Integer.toHexString(System.identityHashCode(this))
Jorim Jaggia5e10572017-11-15 14:36:26 +01003376 + " " + getWindowTag();
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003377 }
3378
Robert Carra1eb4392015-12-10 12:43:51 -08003379 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003380 CharSequence tag = mAttrs.getTitle();
3381 if (tag == null || tag.length() <= 0) {
3382 tag = mAttrs.packageName;
3383 }
3384 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003385 }
3386
3387 @Override
3388 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003389 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003390 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003391 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003392 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003393 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003394 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003395 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003396 }
3397 return mStringNameCache;
3398 }
Robert Carr58f29132015-10-29 14:19:05 -07003399
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003400 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003401 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003402 clipRect.left = (int) (clipRect.left / mHScale);
3403 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003404 }
3405 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003406 clipRect.top = (int) (clipRect.top / mVScale);
3407 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003408 }
3409 }
Robert Carr31e28482015-12-02 16:53:18 -08003410
Jorim Jaggif5834272016-04-04 20:25:41 -07003411 void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
3412 final int pw = containingFrame.width();
3413 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003414 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003415 final boolean inNonFullscreenContainer = !inFullscreenContainer();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003416 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3417
3418 // We need to fit it to the display if either
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003419 // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen
3420 // for the taskless windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003421 // 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 -07003422 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on
3423 // screen, but SurfaceViews want to be always at a specific location so we don't fit it to
3424 // the display.
3425 final boolean fitToDisplay = (task == null || !inNonFullscreenContainer)
Robert Carr6f44db12016-07-21 14:54:43 -07003426 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003427 float x, y;
3428 int w,h;
3429
3430 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3431 if (mAttrs.width < 0) {
3432 w = pw;
3433 } else if (mEnforceSizeCompat) {
3434 w = (int)(mAttrs.width * mGlobalScale + .5f);
3435 } else {
3436 w = mAttrs.width;
3437 }
3438 if (mAttrs.height < 0) {
3439 h = ph;
3440 } else if (mEnforceSizeCompat) {
3441 h = (int)(mAttrs.height * mGlobalScale + .5f);
3442 } else {
3443 h = mAttrs.height;
3444 }
3445 } else {
3446 if (mAttrs.width == MATCH_PARENT) {
3447 w = pw;
3448 } else if (mEnforceSizeCompat) {
3449 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3450 } else {
3451 w = mRequestedWidth;
3452 }
3453 if (mAttrs.height == MATCH_PARENT) {
3454 h = ph;
3455 } else if (mEnforceSizeCompat) {
3456 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3457 } else {
3458 h = mRequestedHeight;
3459 }
3460 }
3461
3462 if (mEnforceSizeCompat) {
3463 x = mAttrs.x * mGlobalScale;
3464 y = mAttrs.y * mGlobalScale;
3465 } else {
3466 x = mAttrs.x;
3467 y = mAttrs.y;
3468 }
3469
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003470 if (inNonFullscreenContainer && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003471 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003472 // required by {@link Gravity#apply} call.
3473 w = Math.min(w, pw);
3474 h = Math.min(h, ph);
3475 }
3476
3477 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003478 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003479 (int) (x + mAttrs.horizontalMargin * pw),
3480 (int) (y + mAttrs.verticalMargin * ph), mFrame);
3481
3482 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003483 if (fitToDisplay) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003484 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003485 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003486
3487 // We need to make sure we update the CompatFrame as it is used for
3488 // cropping decisions, etc, on systems where we lack a decor layer.
3489 mCompatFrame.set(mFrame);
3490 if (mEnforceSizeCompat) {
3491 // See comparable block in computeFrameLw.
3492 mCompatFrame.scale(mInvGlobalScale);
3493 }
Robert Carr31e28482015-12-02 16:53:18 -08003494 }
Robert Carr51a1b872015-12-08 14:03:13 -08003495
3496 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003497 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003498 }
3499
Robert Carrf3b72c72016-03-21 18:16:39 -07003500 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003501 return mIsChildWindow
3502 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003503 }
3504
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003505 /**
3506 * Returns true if any window added by an application process that if of type
3507 * {@link android.view.WindowManager.LayoutParams#TYPE_TOAST} or that requires that requires
3508 * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when
3509 * this window is visible.
3510 */
3511 boolean hideNonSystemOverlayWindowsWhenVisible() {
3512 return (mAttrs.privateFlags & PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != 0
3513 && mSession.mCanHideNonSystemOverlayWindows;
3514 }
3515
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003516 /** Returns the parent window if this is a child of another window, else null. */
3517 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003518 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3519 // WindowContainer that isn't a WindowState.
3520 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003521 }
3522
3523 /** Returns the topmost parent window if this is a child of another window, else this. */
3524 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003525 WindowState current = this;
3526 WindowState topParent = current;
3527 while (current != null && current.mIsChildWindow) {
3528 current = current.getParentWindow();
3529 // Parent window can be null if the child is detached from it's parent already, but
3530 // someone still has a reference to access it. So, we return the top parent value we
3531 // already have instead of null.
3532 if (current != null) {
3533 topParent = current;
3534 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003535 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003536 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003537 }
3538
Wale Ogunwale9d147902016-07-16 11:58:55 -07003539 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003540 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003541 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003542 }
3543
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003544 void setWillReplaceWindow(boolean animate) {
3545 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003546 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003547 c.setWillReplaceWindow(animate);
3548 }
3549
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003550 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3551 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3552 // We don't set replacing on starting windows since they are added by window manager and
3553 // not the client so won't be replaced by the client.
3554 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003555 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003556
3557 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003558 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003559 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003560 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003561
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003562 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003563 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003564 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003565 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003566
3567 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003568 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003569 c.clearWillReplaceWindow();
3570 }
3571 }
3572
3573 boolean waitingForReplacement() {
3574 if (mWillReplaceWindow) {
3575 return true;
3576 }
3577
3578 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003579 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003580 if (c.waitingForReplacement()) {
3581 return true;
3582 }
3583 }
3584 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003585 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003586
Chong Zhang4d7369a2016-04-25 16:09:14 -07003587 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003588 final DisplayContent dc = getDisplayContent();
3589 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3590 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3591 dc.setLayoutNeeded();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003592 mService.mWindowPlacerLocked.requestTraversal();
3593 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003594
3595 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003596 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003597 c.requestUpdateWallpaperIfNeeded();
3598 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003599 }
3600
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003601 float translateToWindowX(float x) {
3602 float winX = x - mFrame.left;
3603 if (mEnforceSizeCompat) {
3604 winX *= mGlobalScale;
3605 }
3606 return winX;
3607 }
3608
3609 float translateToWindowY(float y) {
3610 float winY = y - mFrame.top;
3611 if (mEnforceSizeCompat) {
3612 winY *= mGlobalScale;
3613 }
3614 return winY;
3615 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003616
3617 // During activity relaunch due to resize, we sometimes use window replacement
3618 // for only child windows (as the main window is handled by window preservation)
3619 // and the big surface.
3620 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003621 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3622 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3623 // we also want to replace them at such phases, as they won't be covered by window
3624 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003625 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003626 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003627 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003628 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003629
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003630 void setWillReplaceChildWindows() {
3631 if (shouldBeReplacedWithChildren()) {
3632 setWillReplaceWindow(false /* animate */);
3633 }
3634 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003635 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003636 c.setWillReplaceChildWindows();
3637 }
3638 }
3639
3640 WindowState getReplacingWindow() {
3641 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3642 return this;
3643 }
3644 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003645 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003646 final WindowState replacing = c.getReplacingWindow();
3647 if (replacing != null) {
3648 return replacing;
3649 }
3650 }
3651 return null;
3652 }
3653
Jorim Jaggife762342016-10-13 14:33:27 +02003654 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07003655 public int getRotationAnimationHint() {
3656 if (mAppToken != null) {
3657 return mAppToken.mRotationAnimationHint;
3658 } else {
3659 return -1;
3660 }
3661 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003662
Jorim Jaggife762342016-10-13 14:33:27 +02003663 @Override
3664 public boolean isInputMethodWindow() {
3665 return mIsImWindow;
3666 }
3667
Wale Ogunwale9d147902016-07-16 11:58:55 -07003668 // This must be called while inside a transaction.
3669 boolean performShowLocked() {
3670 if (isHiddenFromUserLocked()) {
3671 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3672 hideLw(false);
3673 return false;
3674 }
3675
3676 logPerformShow("performShow on ");
3677
Jorim Jaggia50da602016-12-29 11:51:42 +01003678 final int drawState = mWinAnimator.mDrawState;
3679 if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW)
3680 && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3681 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3682 }
3683
Jorim Jaggib0d27342016-11-01 16:10:42 -07003684 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003685 return false;
3686 }
3687
3688 logPerformShow("Showing ");
3689
3690 mService.enableScreenIfNeededLocked();
3691 mWinAnimator.applyEnterAnimationLocked();
3692
3693 // Force the show in the next prepareSurfaceLocked() call.
3694 mWinAnimator.mLastAlpha = -1;
Robert Carre13b58e2017-08-31 14:50:44 -07003695 if (DEBUG_ANIM) Slog.v(TAG,
Wale Ogunwale9d147902016-07-16 11:58:55 -07003696 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3697 mWinAnimator.mDrawState = HAS_DRAWN;
3698 mService.scheduleAnimationLocked();
3699
3700 if (mHidden) {
3701 mHidden = false;
3702 final DisplayContent displayContent = getDisplayContent();
3703
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003704 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003705 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003706 if (c.mWinAnimator.mSurfaceController != null) {
3707 c.performShowLocked();
3708 // It hadn't been shown, which means layout not performed on it, so now we
3709 // want to make sure to do a layout. If called from within the transaction
3710 // loop, this will cause it to restart with a new layout.
3711 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003712 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003713 }
3714 }
3715 }
3716 }
3717
Wale Ogunwale9d147902016-07-16 11:58:55 -07003718 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003719 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003720 }
3721
3722 return true;
3723 }
3724
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003725 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003726 if (DEBUG_VISIBILITY
Jorim Jaggie4b0f282017-05-17 15:10:29 +02003727 || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003728 Slog.v(TAG, prefix + this
3729 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07003730 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003731 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3732 + " during animation: policyVis=" + mPolicyVisibility
3733 + " parentHidden=" + isParentWindowHidden()
3734 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003735 + (mAppToken != null && mAppToken.hiddenRequested)
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003736 + " tok.hidden=" + (mAppToken != null && mAppToken.isHidden())
Jorim Jaggia5e10572017-11-15 14:36:26 +01003737 + " animationSet=" + mWinAnimator.isAnimationSet()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003738 + " tok animating="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003739 + (mAppToken != null && mAppToken.isSelfAnimating())
Wale Ogunwale9d147902016-07-16 11:58:55 -07003740 + " Callers=" + Debug.getCallers(4));
3741 }
3742 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003743
3744 WindowInfo getWindowInfo() {
3745 WindowInfo windowInfo = WindowInfo.obtain();
3746 windowInfo.type = mAttrs.type;
3747 windowInfo.layer = mLayer;
3748 windowInfo.token = mClient.asBinder();
Phil Weaver5dc3ebc2017-08-16 13:04:20 -07003749 if (mAppToken != null) {
3750 windowInfo.activityToken = mAppToken.appToken.asBinder();
3751 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003752 windowInfo.title = mAttrs.accessibilityTitle;
Phil Weaverbb2f28a2017-12-22 09:44:28 -08003753 // Panel windows have no public way to set the a11y title directly. Use the
3754 // regular title as a fallback.
3755 if (TextUtils.isEmpty(windowInfo.title)
3756 && (mAttrs.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW)
3757 && (mAttrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW)) {
3758 windowInfo.title = mAttrs.getTitle();
3759 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003760 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3761 windowInfo.focused = isFocused();
Phil Weaverf00cd142017-03-03 13:44:00 -08003762 Task task = getTask();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003763 windowInfo.inPictureInPicture = (task != null) && task.inPinnedWindowingMode();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003764
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003765 if (mIsChildWindow) {
3766 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003767 }
3768
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003769 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003770 if (childCount > 0) {
3771 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003772 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003773 }
3774 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003775 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003776 windowInfo.childTokens.add(child.mClient.asBinder());
3777 }
3778 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003779 return windowInfo;
3780 }
3781
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003782 int getHighestAnimLayer() {
3783 int highest = mWinAnimator.mAnimLayer;
3784 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003785 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003786 final int childLayer = c.getHighestAnimLayer();
3787 if (childLayer > highest) {
3788 highest = childLayer;
3789 }
3790 }
3791 return highest;
3792 }
3793
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003794 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003795 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003796 if (mChildren.isEmpty()) {
3797 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003798 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003799 }
3800
3801 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003802 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003803 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003804 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003805 }
3806 }
3807
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003808 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003809 // We want to consume the negative sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003810 // below the parent, then this window (the parent), and then the positive sublayer children
3811 // because they need to appear above the parent.
3812 int i = 0;
3813 final int count = mChildren.size();
3814 WindowState child = mChildren.get(i);
3815
3816 while (i < count && child.mSubLayer < 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003817 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003818 return true;
3819 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003820 i++;
3821 if (i >= count) {
3822 break;
3823 }
3824 child = mChildren.get(i);
3825 }
3826
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003827 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003828 return true;
3829 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003830
3831 while (i < count) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003832 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003833 return true;
3834 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003835 i++;
3836 if (i >= count) {
3837 break;
3838 }
3839 child = mChildren.get(i);
3840 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003841
3842 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003843 }
3844
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003845 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003846 // We want to consume the positive sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003847 // above the parent, then this window (the parent), and then the negative sublayer children
3848 // because they need to appear above the parent.
3849 int i = mChildren.size() - 1;
3850 WindowState child = mChildren.get(i);
3851
3852 while (i >= 0 && child.mSubLayer >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003853 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003854 return true;
3855 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003856 --i;
3857 if (i < 0) {
3858 break;
3859 }
3860 child = mChildren.get(i);
3861 }
3862
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003863 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003864 return true;
3865 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003866
3867 while (i >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003868 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003869 return true;
3870 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003871 --i;
3872 if (i < 0) {
3873 break;
3874 }
3875 child = mChildren.get(i);
3876 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003877
3878 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003879 }
3880
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003881 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
3882 boolean traverseTopToBottom) {
3883 if (traverseTopToBottom) {
3884 if (mService.mInputMethodTarget == this) {
3885 // This window is the current IME target, so we need to process the IME windows
3886 // directly above it.
3887 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
3888 return true;
3889 }
3890 }
3891 if (callback.apply(this)) {
3892 return true;
3893 }
3894 } else {
3895 if (callback.apply(this)) {
3896 return true;
3897 }
3898 if (mService.mInputMethodTarget == this) {
3899 // This window is the current IME target, so we need to process the IME windows
3900 // directly above it.
3901 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
3902 return true;
3903 }
3904 }
3905 }
3906
3907 return false;
3908 }
3909
Wale Ogunwaled1880962016-11-08 10:31:59 -08003910 WindowState getWindow(Predicate<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003911 if (mChildren.isEmpty()) {
3912 return callback.test(this) ? this : null;
3913 }
3914
3915 // We want to consume the positive sublayer children first because they need to appear
3916 // above the parent, then this window (the parent), and then the negative sublayer children
3917 // because they need to appear above the parent.
3918 int i = mChildren.size() - 1;
3919 WindowState child = mChildren.get(i);
3920
3921 while (i >= 0 && child.mSubLayer >= 0) {
3922 if (callback.test(child)) {
3923 return child;
3924 }
3925 --i;
3926 if (i < 0) {
3927 break;
3928 }
3929 child = mChildren.get(i);
3930 }
3931
Wale Ogunwaled1880962016-11-08 10:31:59 -08003932 if (callback.test(this)) {
3933 return this;
3934 }
Wale Ogunwale34247952017-02-19 11:57:53 -08003935
3936 while (i >= 0) {
3937 if (callback.test(child)) {
3938 return child;
3939 }
3940 --i;
3941 if (i < 0) {
3942 break;
3943 }
3944 child = mChildren.get(i);
3945 }
3946
3947 return null;
Wale Ogunwaled1880962016-11-08 10:31:59 -08003948 }
3949
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003950 void onExitAnimationDone() {
3951 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
3952 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
Jorim Jaggia5e10572017-11-15 14:36:26 +01003953 + " selfAnimating=" + isSelfAnimating());
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003954
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003955 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003956 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +01003957 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003958 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003959 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003960 }
3961 }
3962
3963 if (mWinAnimator.mEnteringAnimation) {
3964 mWinAnimator.mEnteringAnimation = false;
3965 mService.requestTraversal();
3966 // System windows don't have an activity and an app token as a result, but need a way
3967 // to be informed about their entrance animation end.
3968 if (mAppToken == null) {
3969 try {
3970 mClient.dispatchWindowShown();
3971 } catch (RemoteException e) {
3972 }
3973 }
3974 }
3975
Jorim Jaggia5e10572017-11-15 14:36:26 +01003976 if (isSelfAnimating()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003977 return;
3978 }
3979
Jorim Jaggia5e10572017-11-15 14:36:26 +01003980 //TODO (multidisplay): Accessibility is supported only for the default display.
3981 if (mService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
3982 mService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
3983 }
3984
3985 if (!mAnimatingExit) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003986 return;
3987 }
3988
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07003989 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003990 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
3991
3992 mDestroying = true;
3993
3994 final boolean hasSurface = mWinAnimator.hasSurface();
3995 if (hasSurface) {
3996 mWinAnimator.hide("onExitAnimationDone");
3997 }
3998
3999 // If we have an app token, we ask it to destroy the surface for us, so that it can take
4000 // care to ensure the activity has actually stopped and the surface is not still in use.
4001 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
4002 // transaction.
4003 if (mAppToken != null) {
4004 mAppToken.destroySurfaces();
4005 } else {
4006 if (hasSurface) {
4007 mService.mDestroySurface.add(this);
4008 }
4009 if (mRemoveOnExit) {
4010 mService.mPendingRemove.add(this);
4011 mRemoveOnExit = false;
4012 }
4013 }
4014 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07004015 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004016 }
Dan Willemsen117197f2016-07-30 13:02:59 -07004017
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004018 boolean clearAnimatingFlags() {
4019 boolean didSomething = false;
4020 // We don't want to clear it out for windows that get replaced, because the
4021 // animation depends on the flag to remove the replaced window.
4022 //
4023 // We also don't clear the mAnimatingExit flag for windows which have the
4024 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4025 // by the client. We should let animation proceed and not clear this flag or
4026 // they won't eventually be removed by WindowStateAnimator#finishExit.
4027 if (!mWillReplaceWindow && !mRemoveOnExit) {
4028 // Clear mAnimating flag together with mAnimatingExit. When animation
4029 // changes from exiting to entering, we need to clear this flag until the
4030 // new animation gets applied, so that isAnimationStarting() becomes true
4031 // until then.
4032 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4033 // placement for this window during this period, one or more frame will
4034 // show up with wrong position or scale.
4035 if (mAnimatingExit) {
4036 mAnimatingExit = false;
4037 didSomething = true;
4038 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004039 if (mDestroying) {
4040 mDestroying = false;
4041 mService.mDestroySurface.remove(this);
4042 didSomething = true;
4043 }
4044 }
4045
4046 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004047 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004048 }
4049
4050 return didSomething;
4051 }
4052
Winson4b4ba902016-07-27 19:45:52 -07004053 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004054 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004055 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004056
4057 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004058 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004059 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004060 c.hideWallpaperWindow(wasDeferred, reason);
4061 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004062 if (!mWinAnimator.mLastHidden || wasDeferred) {
4063 mWinAnimator.hide(reason);
4064 dispatchWallpaperVisibility(false);
4065 final DisplayContent displayContent = getDisplayContent();
4066 if (displayContent != null) {
4067 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
4068 }
4069 }
4070 }
4071
4072 /**
4073 * Check wallpaper window for visibility change and notify window if so.
4074 * @param visible Current visibility.
4075 */
4076 void dispatchWallpaperVisibility(final boolean visible) {
4077 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07004078 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004079
4080 // Only send notification if the visibility actually changed and we are not trying to hide
4081 // the wallpaper when we are deferring hiding of the wallpaper.
4082 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4083 mWallpaperVisible = visible;
4084 try {
4085 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4086 "Updating vis of wallpaper " + this
4087 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4088 mClient.dispatchAppVisibility(visible);
4089 } catch (RemoteException e) {
4090 }
4091 }
4092 }
4093
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004094 boolean hasVisibleNotDrawnWallpaper() {
4095 if (mWallpaperVisible && !isDrawnLw()) {
4096 return true;
4097 }
4098 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004099 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004100 if (c.hasVisibleNotDrawnWallpaper()) {
4101 return true;
4102 }
4103 }
4104 return false;
4105 }
4106
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004107 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4108 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004109 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004110 c.updateReportedVisibility(results);
4111 }
4112
4113 if (mAppFreezing || mViewVisibility != View.VISIBLE
4114 || mAttrs.type == TYPE_APPLICATION_STARTING
4115 || mDestroying) {
4116 return;
4117 }
4118 if (DEBUG_VISIBILITY) {
4119 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
4120 + ", isAnimationSet=" + mWinAnimator.isAnimationSet());
4121 if (!isDrawnLw()) {
4122 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4123 + " pv=" + mPolicyVisibility
4124 + " mDrawState=" + mWinAnimator.mDrawState
4125 + " ph=" + isParentWindowHidden()
4126 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
Jorim Jaggia5e10572017-11-15 14:36:26 +01004127 + " a=" + mWinAnimator.isAnimationSet());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004128 }
4129 }
4130
4131 results.numInteresting++;
4132 if (isDrawnLw()) {
4133 results.numDrawn++;
4134 if (!mWinAnimator.isAnimationSet()) {
4135 results.numVisible++;
4136 }
4137 results.nowGone = false;
4138 } else if (mWinAnimator.isAnimationSet()) {
4139 results.nowGone = false;
4140 }
4141 }
4142
Robert Carrfbbde852016-10-18 11:02:28 -07004143 /**
4144 * Calculate the window crop according to system decor policy. In general this is
4145 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4146 * special cases. This rectangle is in screen space.
4147 */
4148 void calculatePolicyCrop(Rect policyCrop) {
4149 final DisplayContent displayContent = getDisplayContent();
4150 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
4151
4152 if (!isDefaultDisplay()) {
4153 // On a different display there is no system decor. Crop the window
4154 // by the screen boundaries.
4155 // TODO(multi-display)
4156 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4157 policyCrop.intersect(-mCompatFrame.left, -mCompatFrame.top,
4158 displayInfo.logicalWidth - mCompatFrame.left,
4159 displayInfo.logicalHeight - mCompatFrame.top);
Robert Carrfbbde852016-10-18 11:02:28 -07004160 } else if (mDecorFrame.isEmpty()) {
4161 // Windows without policy decor aren't cropped.
4162 policyCrop.set(0, 0, mCompatFrame.width(), mCompatFrame.height());
4163 } else {
4164 // Crop to the system decor specified by policy.
4165 calculateSystemDecorRect(policyCrop);
4166 }
4167 }
4168
4169 /**
4170 * The system decor rect is the region of the window which is not covered
4171 * by system decorations.
4172 */
4173 private void calculateSystemDecorRect(Rect systemDecorRect) {
4174 final Rect decorRect = mDecorFrame;
4175 final int width = mFrame.width();
4176 final int height = mFrame.height();
4177
4178 // Compute the offset of the window in relation to the decor rect.
4179 final int left = mXOffset + mFrame.left;
4180 final int top = mYOffset + mFrame.top;
4181
4182 // Initialize the decor rect to the entire frame.
4183 if (isDockedResizing()) {
4184 // If we are resizing with the divider, the task bounds might be smaller than the
4185 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4186 // want in this case in order to avoid holes.
4187 //
4188 // We take care to not shrink the width, for surfaces which are larger than
4189 // the display region. Of course this area will not eventually be visible
4190 // but if we truncate the width now, we will calculate incorrectly
4191 // when adjusting to the stack bounds.
4192 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4193 systemDecorRect.set(0, 0,
4194 Math.max(width, displayInfo.logicalWidth),
4195 Math.max(height, displayInfo.logicalHeight));
4196 } else {
4197 systemDecorRect.set(0, 0, width, height);
4198 }
4199
4200 // If a freeform window is animating from a position where it would be cutoff, it would be
4201 // cutoff during the animation. We don't want that, so for the duration of the animation
4202 // we ignore the decor cropping and depend on layering to position windows correctly.
Wale Ogunwale44f036f2017-09-29 05:09:09 -07004203 final boolean cropToDecor = !(inFreeformWindowingMode() && isAnimatingLw());
Robert Carrfbbde852016-10-18 11:02:28 -07004204 if (cropToDecor) {
4205 // Intersect with the decor rect, offsetted by window position.
4206 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
4207 decorRect.right - left, decorRect.bottom - top);
4208 }
4209
4210 // If size compatibility is being applied to the window, the
4211 // surface is scaled relative to the screen. Also apply this
4212 // scaling to the crop rect. We aren't using the standard rect
4213 // scale function because we want to round things to make the crop
4214 // always round to a larger rect to ensure we don't crop too
4215 // much and hide part of the window that should be seen.
4216 if (mEnforceSizeCompat && mInvGlobalScale != 1.0f) {
4217 final float scale = mInvGlobalScale;
4218 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
4219 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
4220 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
4221 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
4222 }
4223
4224 }
4225
4226 /**
4227 * Expand the given rectangle by this windows surface insets. This
4228 * takes you from the 'window size' to the 'surface size'.
4229 * The surface insets are positive in each direction, so we inset by
4230 * the inverse.
4231 */
4232 void expandForSurfaceInsets(Rect r) {
4233 r.inset(-mAttrs.surfaceInsets.left,
4234 -mAttrs.surfaceInsets.top,
4235 -mAttrs.surfaceInsets.right,
4236 -mAttrs.surfaceInsets.bottom);
4237 }
4238
Robert Carrc91d1c32017-02-15 19:37:46 -08004239 boolean surfaceInsetsChanging() {
4240 return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets);
4241 }
4242
Bryce Leef858b572017-06-29 14:03:33 -07004243 int relayoutVisibleWindow(int result, int attrChanges, int oldVisibility) {
Robert Carrecc06b32017-04-18 14:25:10 -07004244 final boolean wasVisible = isVisibleLw();
4245
4246 result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004247 if (mAnimatingExit) {
4248 Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit="
4249 + mRemoveOnExit + ", mDestroying=" + mDestroying);
4250
4251 mWinAnimator.cancelExitAnimationForNextAnimationLocked();
4252 mAnimatingExit = false;
4253 }
4254 if (mDestroying) {
4255 mDestroying = false;
4256 mService.mDestroySurface.remove(this);
4257 }
4258 if (oldVisibility == View.GONE) {
4259 mWinAnimator.mEnterAnimationPending = true;
4260 }
4261
Andrii Kulian8ee72852017-03-10 10:36:45 -08004262 mLastVisibleLayoutRotation = getDisplayContent().getRotation();
Robert Carrc91d1c32017-02-15 19:37:46 -08004263
4264 mWinAnimator.mEnteringAnimation = true;
Bryce Leeae73ba42017-05-05 09:58:25 -07004265
Bryce Leef858b572017-06-29 14:03:33 -07004266 prepareWindowToDisplayDuringRelayout(wasVisible);
Bryce Leeae73ba42017-05-05 09:58:25 -07004267
Robert Carrc91d1c32017-02-15 19:37:46 -08004268 if ((attrChanges & FORMAT_CHANGED) != 0) {
4269 // If the format can't be changed in place, preserve the old surface until the app draws
4270 // on the new one. This prevents blinking when we change elevation of freeform and
4271 // pinned windows.
4272 if (!mWinAnimator.tryChangeFormatInPlaceLocked()) {
4273 mWinAnimator.preserveSurfaceLocked();
4274 result |= RELAYOUT_RES_SURFACE_CHANGED
4275 | RELAYOUT_RES_FIRST_TIME;
4276 }
4277 }
4278
4279 // When we change the Surface size, in scenarios which may require changing
4280 // the surface position in sync with the resize, we use a preserved surface
4281 // so we can freeze it while waiting for the client to report draw on the newly
Winson Chung8bca9e42017-04-16 15:59:43 -07004282 // sized surface. Don't preserve surfaces if the insets change while animating the pinned
4283 // stack since it can lead to issues if a new surface is created while calculating the
4284 // scale for the animation using the source hint rect
4285 // (see WindowStateAnimator#setSurfaceBoundariesLocked()).
Robert Carrc91d1c32017-02-15 19:37:46 -08004286 if (isDragResizeChanged() || isResizedWhileNotDragResizing()
Wale Ogunwale44f036f2017-09-29 05:09:09 -07004287 || (surfaceInsetsChanging() && !inPinnedWindowingMode())) {
Robert Carrc91d1c32017-02-15 19:37:46 -08004288 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
4289
4290 setDragResizing();
4291 setResizedWhileNotDragResizing(false);
4292 // We can only change top level windows to the full-screen surface when
4293 // resizing (as we only have one full-screen surface). So there is no need
4294 // to preserve and destroy windows which are attached to another, they
4295 // will keep their surface and its size may change over time.
4296 if (mHasSurface && !isChildWindow()) {
4297 mWinAnimator.preserveSurfaceLocked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08004298 result |= RELAYOUT_RES_SURFACE_CHANGED |
4299 RELAYOUT_RES_FIRST_TIME;
Robert Carrc91d1c32017-02-15 19:37:46 -08004300 }
4301 }
4302 final boolean freeformResizing = isDragResizing()
4303 && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
4304 final boolean dockedResizing = isDragResizing()
4305 && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
4306 result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0;
4307 result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004308 return result;
4309 }
4310
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004311 /**
4312 * @return True if this window has been laid out at least once; false otherwise.
4313 */
4314 boolean isLaidOut() {
4315 return mLayoutSeq != -1;
4316 }
4317
4318 /**
4319 * Updates the last inset values to the current ones.
4320 */
4321 void updateLastInsetValues() {
4322 mLastOverscanInsets.set(mOverscanInsets);
4323 mLastContentInsets.set(mContentInsets);
4324 mLastVisibleInsets.set(mVisibleInsets);
4325 mLastStableInsets.set(mStableInsets);
4326 mLastOutsets.set(mOutsets);
Adrian Roos5c6b6222017-11-07 17:36:10 +01004327 mLastDisplayCutout = mDisplayCutout;
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004328 }
4329
Jorim Jaggia5e10572017-11-15 14:36:26 +01004330 void startAnimation(Animation anim) {
4331 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4332 anim.initialize(mFrame.width(), mFrame.height(),
4333 displayInfo.appWidth, displayInfo.appHeight);
4334 anim.restrictDuration(MAX_ANIMATION_DURATION);
4335 anim.scaleCurrentDuration(mService.getWindowAnimationScaleLocked());
4336 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi2e3c31d2017-11-20 19:49:00 +01004337 new WindowAnimationSpec(anim, mSurfacePosition, false /* canSkipFirstFrame */),
4338 mService.mSurfaceAnimationRunner);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004339 startAnimation(mPendingTransaction, adapter);
4340 commitPendingTransaction();
4341 }
4342
4343 private void startMoveAnimation(Transaction t, int left, int top) {
4344 if (DEBUG_ANIM) Slog.v(TAG, "Setting move animation on " + this);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004345 final Point oldPosition = new Point();
4346 final Point newPosition = new Point();
4347 transformFrameToSurfacePosition(mLastFrame.left, mLastFrame.top, oldPosition);
4348 transformFrameToSurfacePosition(left, top, newPosition);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004349 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004350 new MoveAnimationSpec(oldPosition.x, oldPosition.y, newPosition.x, newPosition.y),
Jorim Jaggia5e10572017-11-15 14:36:26 +01004351 mService.mSurfaceAnimationRunner);
4352 startAnimation(t, adapter);
4353 }
4354
4355 private void startAnimation(Transaction t, AnimationAdapter adapter) {
4356 startAnimation(t, adapter, mWinAnimator.mLastHidden);
4357 }
4358
4359 @Override
4360 protected void onAnimationFinished() {
4361 mWinAnimator.onAnimationFinished();
4362 }
4363
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004364 /**
4365 * Retrieves the current transformation matrix of the window, relative to the display.
4366 *
4367 * @param float9 A temporary array of 9 floats.
4368 * @param outMatrix Matrix to fill in the transformation.
4369 */
4370 void getTransformationMatrix(float[] float9, Matrix outMatrix) {
4371 float9[Matrix.MSCALE_X] = mWinAnimator.mDsDx;
4372 float9[Matrix.MSKEW_Y] = mWinAnimator.mDtDx;
4373 float9[Matrix.MSKEW_X] = mWinAnimator.mDtDy;
4374 float9[Matrix.MSCALE_Y] = mWinAnimator.mDsDy;
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004375 int x = mSurfacePosition.x + mShownPosition.x;
4376 int y = mSurfacePosition.y + mShownPosition.y;
4377
4378 // If changed, also adjust transformFrameToSurfacePosition
4379 final WindowContainer parent = getParent();
4380 if (isChildWindow()) {
4381 final WindowState parentWindow = getParentWindow();
4382 x += parentWindow.mFrame.left - parentWindow.mAttrs.surfaceInsets.left;
4383 y += parentWindow.mFrame.top - parentWindow.mAttrs.surfaceInsets.top;
4384 } else if (parent != null) {
4385 final Rect parentBounds = parent.getBounds();
4386 x += parentBounds.left;
4387 y += parentBounds.top;
4388 }
4389 float9[Matrix.MTRANS_X] = x;
4390 float9[Matrix.MTRANS_Y] = y;
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004391 float9[Matrix.MPERSP_0] = 0;
4392 float9[Matrix.MPERSP_1] = 0;
4393 float9[Matrix.MPERSP_2] = 1;
4394 outMatrix.setValues(float9);
4395 }
4396
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004397 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4398 // access to its windows children. Need to investigate re-writing
4399 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4400 static final class UpdateReportedVisibilityResults {
4401 int numInteresting;
4402 int numVisible;
4403 int numDrawn;
4404 boolean nowGone = true;
4405
4406 void reset() {
4407 numInteresting = 0;
4408 numVisible = 0;
4409 numDrawn = 0;
4410 nowGone = true;
4411 }
4412 }
Robert Carraf422a82017-04-10 18:34:33 -07004413
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004414 private static final class WindowId extends IWindowId.Stub {
4415 private final WeakReference<WindowState> mOuter;
4416
4417 private WindowId(WindowState outer) {
4418
4419 // Use a weak reference for the outer class. This is important to prevent the following
4420 // leak: Since we send this class to the client process, binder will keep it alive as
4421 // long as the client keeps it alive. Now, if the window is removed, we need to clear
4422 // out our reference so even though this class is kept alive we don't leak WindowState,
4423 // which can keep a whole lot of classes alive.
4424 mOuter = new WeakReference<>(outer);
4425 }
4426
4427 @Override
4428 public void registerFocusObserver(IWindowFocusObserver observer) {
4429 final WindowState outer = mOuter.get();
4430 if (outer != null) {
4431 outer.registerFocusObserver(observer);
4432 }
4433 }
4434 @Override
4435 public void unregisterFocusObserver(IWindowFocusObserver observer) {
4436 final WindowState outer = mOuter.get();
4437 if (outer != null) {
4438 outer.unregisterFocusObserver(observer);
4439 }
4440 }
4441 @Override
4442 public boolean isFocused() {
4443 final WindowState outer = mOuter.get();
4444 return outer != null && outer.isFocused();
4445 }
4446 }
4447
Robert Carrb1579c82017-09-05 14:54:47 -07004448
4449 @Override
4450 boolean shouldMagnify() {
4451 if (mAttrs.type == TYPE_INPUT_METHOD ||
Robert Carree4d4b92017-11-22 12:21:46 -08004452 mAttrs.type == TYPE_INPUT_METHOD_DIALOG ||
4453 mAttrs.type == TYPE_MAGNIFICATION_OVERLAY ||
4454 mAttrs.type == TYPE_NAVIGATION_BAR ||
4455 // It's tempting to wonder: Have we forgotten the rounded corners overlay?
4456 // worry not: it's a fake TYPE_NAVIGATION_BAR_PANEL
4457 mAttrs.type == TYPE_NAVIGATION_BAR_PANEL ||
4458 mAttrs.type == TYPE_STATUS_BAR) {
Robert Carrb1579c82017-09-05 14:54:47 -07004459 return false;
4460 }
4461 return true;
4462 }
4463
4464 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004465 SurfaceSession getSession() {
4466 if (mSession.mSurfaceSession != null) {
4467 return mSession.mSurfaceSession;
4468 } else {
4469 return getParent().getSession();
4470 }
4471 }
4472
4473 @Override
4474 boolean needsZBoost() {
Jorim Jaggib0fc8172017-11-23 17:04:08 +00004475 if (mIsImWindow && mService.mInputMethodTarget != null) {
4476 final AppWindowToken appToken = mService.mInputMethodTarget.mAppToken;
4477 if (appToken != null) {
4478 return appToken.needsZBoost();
4479 }
4480 }
4481 return mWillReplaceWindow;
Robert Carrb1579c82017-09-05 14:54:47 -07004482 }
4483
Robert Carrf07ef9e2017-11-21 12:12:49 -08004484 private void applyDims(Dimmer dimmer) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07004485 if (!mAnimatingExit && mAppDied) {
4486 mIsDimming = true;
4487 getDimmer().dimAbove(getPendingTransaction(), this, DEFAULT_DIM_AMOUNT_DEAD_WINDOW);
4488 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
4489 && !mAnimatingExit && isVisible()) {
4490 mIsDimming = true;
4491 getDimmer().dimBelow(getPendingTransaction(), this, mAttrs.dimAmount);
4492 }
Robert Carrf07ef9e2017-11-21 12:12:49 -08004493 }
4494
4495 @Override
4496 void prepareSurfaces() {
4497 final Dimmer dimmer = getDimmer();
4498 mIsDimming = false;
4499 if (dimmer != null) {
4500 applyDims(dimmer);
4501 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07004502
Jorim Jaggia5e10572017-11-15 14:36:26 +01004503 updateSurfacePosition(mPendingTransaction);
4504
Robert Carrb1579c82017-09-05 14:54:47 -07004505 mWinAnimator.prepareSurfaceLocked(true);
4506 super.prepareSurfaces();
4507 }
4508
4509 @Override
Jorim Jaggia5e10572017-11-15 14:36:26 +01004510 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
4511 super.onAnimationLeashCreated(t, leash);
4512
4513 // Leash is now responsible for position, so set our position to 0.
4514 t.setPosition(mSurfaceControl, 0, 0);
Jorim Jaggi1e8c4c82018-01-09 15:14:15 +01004515 mLastSurfacePosition.set(0, 0);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004516 }
4517
4518 @Override
4519 public void onAnimationLeashDestroyed(Transaction t) {
4520 super.onAnimationLeashDestroyed(t);
4521 updateSurfacePosition(t);
4522 }
4523
chaviwe07246a2017-12-12 16:18:29 -08004524 @Override
Jorim Jaggia5e10572017-11-15 14:36:26 +01004525 void updateSurfacePosition(Transaction t) {
4526 if (mSurfaceControl == null) {
4527 return;
4528 }
4529
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004530 transformFrameToSurfacePosition(mFrame.left, mFrame.top, mSurfacePosition);
Jorim Jaggi1e8c4c82018-01-09 15:14:15 +01004531 if (!mSurfaceAnimator.hasLeash() && !mLastSurfacePosition.equals(mSurfacePosition)) {
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004532 t.setPosition(mSurfaceControl, mSurfacePosition.x, mSurfacePosition.y);
Jorim Jaggi1e8c4c82018-01-09 15:14:15 +01004533 mLastSurfacePosition.set(mSurfacePosition.x, mSurfacePosition.y);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004534 }
4535 }
4536
4537 private void transformFrameToSurfacePosition(int left, int top, Point outPoint) {
4538 outPoint.set(left, top);
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004539
4540 // If changed, also adjust getTransformationMatrix
chaviwe07246a2017-12-12 16:18:29 -08004541 final WindowContainer parentWindowContainer = getParent();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004542 if (isChildWindow()) {
4543 // TODO: This probably falls apart at some point and we should
4544 // actually compute relative coordinates.
Jorim Jaggi50d3f8f2017-12-27 17:41:25 +01004545
4546 // Since the parent was outset by its surface insets, we need to undo the outsetting
4547 // with insetting by the same amount.
Jorim Jaggia5e10572017-11-15 14:36:26 +01004548 final WindowState parent = getParentWindow();
Jorim Jaggi50d3f8f2017-12-27 17:41:25 +01004549 outPoint.offset(-parent.mFrame.left + parent.mAttrs.surfaceInsets.left,
4550 -parent.mFrame.top + parent.mAttrs.surfaceInsets.top);
chaviwe07246a2017-12-12 16:18:29 -08004551 } else if (parentWindowContainer != null) {
4552 final Rect parentBounds = parentWindowContainer.getBounds();
4553 outPoint.offset(-parentBounds.left, -parentBounds.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004554 }
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004555
4556 // Expand for surface insets. See WindowState.expandForSurfaceInsets.
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004557 outPoint.offset(-mAttrs.surfaceInsets.left, -mAttrs.surfaceInsets.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004558 }
4559
4560 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004561 void assignLayer(Transaction t, int layer) {
4562 // See comment in assignRelativeLayerForImeTargetChild
4563 if (!isChildWindow()
4564 || (mService.mInputMethodTarget != getParentWindow())
4565 || !inSplitScreenWindowingMode()) {
4566 super.assignLayer(t, layer);
4567 return;
4568 }
4569 getDisplayContent().assignRelativeLayerForImeTargetChild(t, this);
4570 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07004571
4572 @Override
4573 public boolean isDimming() {
4574 return mIsDimming;
4575 }
Robert Carr0eff1872017-12-01 14:27:04 -08004576
4577 // TODO(b/70040778): We should aim to eliminate the last user of TYPE_APPLICATION_MEDIA
4578 // then we can drop all negative layering on the windowing side and simply inherit
4579 // the default implementation here.
4580 public void assignChildLayers(Transaction t) {
4581 int layer = 1;
4582 for (int i = 0; i < mChildren.size(); i++) {
4583 final WindowState w = mChildren.get(i);
4584
4585 // APPLICATION_MEDIA_OVERLAY needs to go above APPLICATION_MEDIA
4586 // while they both need to go below the main window. However the
4587 // relative layering of multiple APPLICATION_MEDIA/OVERLAY has never
4588 // been defined and so we can use static layers and leave it that way.
4589 if (w.mAttrs.type == TYPE_APPLICATION_MEDIA) {
4590 w.assignLayer(t, -2);
4591 } else if (w.mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) {
4592 w.assignLayer(t, -1);
4593 } else {
4594 w.assignLayer(t, layer);
4595 }
4596 w.assignChildLayers(t);
4597 layer++;
4598 }
4599 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01004600
4601 private final class MoveAnimationSpec implements AnimationSpec {
4602
4603 private final long mDuration;
4604 private Interpolator mInterpolator;
4605 private Point mFrom = new Point();
4606 private Point mTo = new Point();
4607
4608 private MoveAnimationSpec(int fromX, int fromY, int toX, int toY) {
4609 final Animation anim = AnimationUtils.loadAnimation(mContext,
4610 com.android.internal.R.anim.window_move_from_decor);
Jorim Jaggi08f75cf2018-01-08 14:38:53 +01004611 mDuration = (long)
4612 (anim.computeDurationHint() * mService.getWindowAnimationScaleLocked());
Jorim Jaggia5e10572017-11-15 14:36:26 +01004613 mInterpolator = anim.getInterpolator();
4614 mFrom.set(fromX, fromY);
4615 mTo.set(toX, toY);
4616 }
4617
4618 @Override
4619 public long getDuration() {
4620 return mDuration;
4621 }
4622
4623 @Override
4624 public void apply(Transaction t, SurfaceControl leash, long currentPlayTime) {
4625 final float fraction = (float) currentPlayTime / getDuration();
4626 final float v = mInterpolator.getInterpolation(fraction);
4627 t.setPosition(leash, mFrom.x + (mTo.x - mFrom.x) * v,
4628 mFrom.y + (mTo.y - mFrom.y) * v);
4629 }
4630 }
satokcef37fb2011-10-24 21:49:38 +09004631}