blob: 600178fa3276ffd640bde0e08907129cd955ec7b [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
Wale Ogunwale65ebd952018-04-25 15:41:44 -070019import static android.app.ActivityTaskManager.INVALID_STACK_ID;
Svet Ganovf7b47252018-02-26 11:11:27 -080020import static android.app.AppOpsManager.MODE_ALLOWED;
21import static android.app.AppOpsManager.MODE_DEFAULT;
22import static android.app.AppOpsManager.OP_NONE;
chaviw40234662018-02-07 09:37:16 -080023import static android.os.PowerManager.DRAW_WAKE_LOCK;
Jorim Jaggi02886a82016-12-06 09:10:06 -080024import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
25import static android.view.Display.DEFAULT_DISPLAY;
Jorim Jaggia5e10572017-11-15 14:36:26 +010026import static android.view.SurfaceControl.Transaction;
Jorim Jaggi02886a82016-12-06 09:10:06 -080027import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT;
28import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
29import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
30import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
31import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
32import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW;
33import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
34import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
35import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
36import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
37import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
38import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
39import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
40import static android.view.WindowManager.LayoutParams.FLAG_SCALED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080041import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
42import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
43import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
Robert Carrc91d1c32017-02-15 19:37:46 -080044import static android.view.WindowManager.LayoutParams.FORMAT_CHANGED;
Jorim Jaggi02886a82016-12-06 09:10:06 -080045import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
Adrian Roosfa02da62018-01-15 16:01:18 +010046import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Jorim Jaggi02886a82016-12-06 09:10:06 -080047import static android.view.WindowManager.LayoutParams.MATCH_PARENT;
48import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
49import 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;
Philip P. Moltmann66ce2382018-10-09 13:46:11 -070054import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
Jorim Jaggi02886a82016-12-06 09:10:06 -080055import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
Robert Carr0eff1872017-12-01 14:27:04 -080056import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;
Vishnu Nair1d0fa072018-01-04 07:53:00 -080057import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
Jorim Jaggi02886a82016-12-06 09:10:06 -080058import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
59import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
60import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
61import static android.view.WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION;
62import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
63import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Robert Carrb1579c82017-09-05 14:54:47 -070064import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY;
65import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
Robert Carree4d4b92017-11-22 12:21:46 -080066import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070067import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Jorim Jaggi02886a82016-12-06 09:10:06 -080068import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Wale Ogunwale01ad4342017-06-30 07:07:01 -070069import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType;
Robert Carrc91d1c32017-02-15 19:37:46 -080070import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED;
71import static android.view.WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM;
72import static android.view.WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME;
73import static android.view.WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED;
Vishnu Nairddd80742018-08-21 14:12:46 -070074
Adrian Roose99bc052017-11-20 17:55:31 +010075import static com.android.server.policy.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
76import static com.android.server.policy.WindowManagerPolicy.TRANSIT_ENTER;
77import static com.android.server.policy.WindowManagerPolicy.TRANSIT_EXIT;
78import static com.android.server.policy.WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
Vishnu Nairddd80742018-08-21 14:12:46 -070079import static com.android.server.wm.AnimationSpecProto.MOVE;
Jorim Jaggi02886a82016-12-06 09:10:06 -080080import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_DOCKED_DIVIDER;
81import static com.android.server.wm.DragResizeMode.DRAG_RESIZE_MODE_FREEFORM;
Vishnu Nairddd80742018-08-21 14:12:46 -070082import static com.android.server.wm.IdentifierProto.HASH_CODE;
83import static com.android.server.wm.IdentifierProto.TITLE;
84import static com.android.server.wm.IdentifierProto.USER_ID;
85import static com.android.server.wm.MoveAnimationSpecProto.DURATION_MS;
86import static com.android.server.wm.MoveAnimationSpecProto.FROM;
87import static com.android.server.wm.MoveAnimationSpecProto.TO;
Jorim Jaggi02886a82016-12-06 09:10:06 -080088import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
89import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
90import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
91import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_CONFIGURATION;
92import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
93import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
94import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
Jorim Jaggi02886a82016-12-06 09:10:06 -080095import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
Tiger Huang50d45462018-05-25 22:57:52 +080096import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
Jorim Jaggi02886a82016-12-06 09:10:06 -080097import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
98import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_POWER;
99import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_RESIZE;
100import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW;
Jorim Jaggie4b0f282017-05-17 15:10:29 +0200101import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STARTING_WINDOW_VERBOSE;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800102import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800103import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
104import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
105import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100106import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800107import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
108import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
109import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
Tiger Huang8af6ba42018-06-07 19:24:09 +0800110import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_REMOVING_FOCUS;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800111import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
112import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
113import static com.android.server.wm.WindowManagerService.localLOGV;
114import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING;
115import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
116import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN;
Tiger Huang9c8ee262019-02-19 20:44:27 +0800117import static com.android.server.wm.WindowStateAnimator.PRESERVED_SURFACE_LAYER;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800118import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700119import static com.android.server.wm.WindowStateProto.ANIMATING_EXIT;
120import static com.android.server.wm.WindowStateProto.ANIMATOR;
121import static com.android.server.wm.WindowStateProto.ATTRIBUTES;
122import static com.android.server.wm.WindowStateProto.CHILD_WINDOWS;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700123import static com.android.server.wm.WindowStateProto.DESTROYING;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700124import static com.android.server.wm.WindowStateProto.DISPLAY_ID;
Vishnu Nairddd80742018-08-21 14:12:46 -0700125import static com.android.server.wm.WindowStateProto.FINISHED_SEAMLESS_ROTATION_FRAME;
126import static com.android.server.wm.WindowStateProto.FORCE_SEAMLESS_ROTATION;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700127import static com.android.server.wm.WindowStateProto.GIVEN_CONTENT_INSETS;
128import static com.android.server.wm.WindowStateProto.HAS_SURFACE;
129import static com.android.server.wm.WindowStateProto.IDENTIFIER;
130import static com.android.server.wm.WindowStateProto.IS_ON_SCREEN;
131import static com.android.server.wm.WindowStateProto.IS_READY_FOR_DISPLAY;
132import static com.android.server.wm.WindowStateProto.IS_VISIBLE;
Vishnu Nairddd80742018-08-21 14:12:46 -0700133import static com.android.server.wm.WindowStateProto.PENDING_SEAMLESS_ROTATION;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700134import static com.android.server.wm.WindowStateProto.REMOVED;
135import static com.android.server.wm.WindowStateProto.REMOVE_ON_EXIT;
136import static com.android.server.wm.WindowStateProto.REQUESTED_HEIGHT;
137import static com.android.server.wm.WindowStateProto.REQUESTED_WIDTH;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700138import static com.android.server.wm.WindowStateProto.STACK_ID;
139import static com.android.server.wm.WindowStateProto.SURFACE_INSETS;
140import static com.android.server.wm.WindowStateProto.SURFACE_POSITION;
141import static com.android.server.wm.WindowStateProto.SYSTEM_UI_VISIBILITY;
142import static com.android.server.wm.WindowStateProto.VIEW_VISIBILITY;
Yi Jin6c6e9ca2018-03-20 16:53:35 -0700143import static com.android.server.wm.WindowStateProto.WINDOW_CONTAINER;
chaviw553b0212018-07-12 13:37:01 -0700144import static com.android.server.wm.WindowStateProto.WINDOW_FRAMES;
Jorim Jaggi02886a82016-12-06 09:10:06 -0800145
Wale Ogunwale0d5609b2017-09-13 05:55:07 -0700146import android.annotation.CallSuper;
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200147import android.annotation.Nullable;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800148import android.app.AppOpsManager;
149import android.content.Context;
150import android.content.res.Configuration;
151import android.graphics.Matrix;
152import android.graphics.PixelFormat;
153import android.graphics.Point;
154import android.graphics.Rect;
155import android.graphics.Region;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700156import android.os.Binder;
Wale Ogunwale9d147902016-07-16 11:58:55 -0700157import android.os.Debug;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800158import android.os.IBinder;
159import android.os.PowerManager;
Michael Wrighte3001042019-02-05 00:13:14 +0000160import android.os.PowerManager.WakeReason;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800161import android.os.RemoteCallbackList;
162import android.os.RemoteException;
163import android.os.SystemClock;
164import android.os.Trace;
165import android.os.UserHandle;
166import android.os.WorkSource;
chaviw40234662018-02-07 09:37:16 -0800167import android.provider.Settings;
Phil Weaverbb2f28a2017-12-22 09:44:28 -0800168import android.text.TextUtils;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800169import android.util.DisplayMetrics;
Jorim Jaggie7d2b852017-08-28 17:55:15 +0200170import android.util.MergedConfiguration;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800171import android.util.Slog;
172import android.util.TimeUtils;
Steven Timotiusaf03df62017-07-18 16:56:43 -0700173import android.util.proto.ProtoOutputStream;
Brad Stenningaf596412018-04-02 12:03:19 -0700174import android.view.Display;
Adrian Roos5c6b6222017-11-07 17:36:10 +0100175import android.view.DisplayCutout;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800176import android.view.DisplayInfo;
177import android.view.Gravity;
178import android.view.IApplicationToken;
179import android.view.IWindow;
180import android.view.IWindowFocusObserver;
181import android.view.IWindowId;
182import android.view.InputChannel;
183import android.view.InputEvent;
184import android.view.InputEventReceiver;
Tiger Huang7c610aa2018-10-27 00:01:01 +0800185import android.view.InputWindowHandle;
Vishnu Nairba183352018-11-21 11:16:49 -0800186import android.view.Surface.Rotation;
Robert Carrb1579c82017-09-05 14:54:47 -0700187import android.view.SurfaceControl;
188import android.view.SurfaceSession;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800189import android.view.View;
190import android.view.ViewTreeObserver;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -0700191import android.view.WindowInfo;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800192import android.view.WindowManager;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100193import android.view.animation.Animation;
194import android.view.animation.AnimationUtils;
195import android.view.animation.Interpolator;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800196
Jorim Jaggi4876b4a2018-01-11 15:43:49 +0100197import com.android.internal.annotations.VisibleForTesting;
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -0800198import com.android.internal.util.ToBooleanFunction;
Adrian Roose99bc052017-11-20 17:55:31 +0100199import com.android.server.policy.WindowManagerPolicy;
Jorim Jaggia5e10572017-11-15 14:36:26 +0100200import com.android.server.wm.LocalAnimationAdapter.AnimationSpec;
chaviw9c81e632018-07-31 11:17:52 -0700201import com.android.server.wm.utils.InsetUtils;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100202import com.android.server.wm.utils.WmDisplayCutout;
Jorim Jaggi9511b0f2016-01-29 19:12:44 -0800203
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800204import java.io.PrintWriter;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200205import java.lang.ref.WeakReference;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800206import java.util.ArrayList;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700207import java.util.Comparator;
Adrian Roos4ffc8972019-02-07 20:45:11 +0100208import java.util.List;
Wale Ogunwaled1880962016-11-08 10:31:59 -0800209import java.util.function.Predicate;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800210
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700211/** A window in the window manager. */
212class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800213 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800214
Skuhne81c524a2015-08-12 13:34:14 -0700215 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700216 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
217 // use hard-coded min sizes for now.
218 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
219 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700220
221 // The thickness of a window resize handle outside the window bounds on the free form workspace
222 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700223 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700224
Craig Mautnere7ae2502012-03-26 17:11:19 -0700225 final WindowManagerPolicy mPolicy;
226 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800227 final Session mSession;
228 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800229 final int mAppOp;
230 // UserId and appId of the owner. Don't display windows of non-current user.
231 final int mOwnerUid;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800232 /** The owner has {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} */
233 final boolean mOwnerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200234 final WindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800235 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700236 // The same object as mToken if this is an app window and null for non-app windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800237 AppWindowToken mAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700238
239 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
240 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800241 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
242 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700243 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800244 final int mBaseLayer;
245 final int mSubLayer;
246 final boolean mLayoutAttached;
247 final boolean mIsImWindow;
248 final boolean mIsWallpaper;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700249 private final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700250 int mSeq;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800251 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700252 int mSystemUiVisibility;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700253 /**
254 * The visibility of the window based on policy like {@link WindowManagerPolicy}.
255 * Normally set by calling {@link #showLw} and {@link #hideLw}.
256 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800257 boolean mPolicyVisibility = true;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700258 /**
259 * What {@link #mPolicyVisibility} should be set to after a transition animation.
260 * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and
261 * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit
262 * animation is done.
263 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800264 boolean mPolicyVisibilityAfterAnim = true;
Suprabh Shukla69c71422018-04-02 18:39:01 -0700265 // overlay window is hidden because the owning app is suspended
266 private boolean mHiddenWhileSuspended;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700267 private boolean mAppOpVisibility = true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700268 boolean mPermanentlyHidden; // the window should never be shown again
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700269 // This is a non-system overlay window that is currently force hidden.
270 private boolean mForceHideNonSystemOverlayWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800271 boolean mAppFreezing;
chaviwebcbc342018-02-07 13:19:00 -0800272 boolean mHidden = true; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800273 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700274 private boolean mDragResizing;
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200275 private boolean mDragResizingChangeReported = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700276 private int mResizeMode;
Vishnu Nair83537a72018-07-19 21:27:48 -0700277 /**
278 * Special mode that is intended only for the rounded corner overlay: during rotation
279 * transition, we un-rotate the window token such that the window appears as it did before the
280 * rotation.
Vishnu Nair83537a72018-07-19 21:27:48 -0700281 */
282 final boolean mForceSeamlesslyRotate;
Vishnu Nairddd80742018-08-21 14:12:46 -0700283 SeamlessRotator mPendingSeamlessRotate;
284 long mFinishSeamlessRotateFrameNumber;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700285
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700286 private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800287
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700288 /**
289 * The window size that was requested by the application. These are in
290 * the application's coordinate space (without compatibility scale applied).
291 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800292 int mRequestedWidth;
293 int mRequestedHeight;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700294 private int mLastRequestedWidth;
295 private int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700296
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800297 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800298 boolean mHaveFrame;
299 boolean mObscured;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800300
301 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700302
Andrii Kulian9d91ca62016-09-29 22:28:09 -0700303 /**
304 * Used to store last reported to client configuration and check if we have newer available.
305 * We'll send configuration to client only if it is different from the last applied one and
306 * client won't perform unnecessary updates.
307 */
Bryce Lee2b17afd2017-09-21 10:38:20 -0700308 private final MergedConfiguration mLastReportedConfiguration = new MergedConfiguration();
Craig Mautnera2c77052012-03-26 12:14:43 -0700309
Yunfan Chen75157d72018-07-27 14:47:21 +0900310 private final Configuration mTempConfiguration = new Configuration();
311
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700312 /**
Robert Carr18f622f2017-05-08 11:20:43 -0700313 * The last content insets returned to the client in relayout. We use
314 * these in the bounds animation to ensure we only observe inset changes
315 * at the same time that a client resizes it's surface so that we may use
316 * the geometryAppliesWithResize synchronization mechanism to keep
317 * the contents in place.
318 */
319 final Rect mLastRelayoutContentInsets = new Rect();
320
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700321 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800322 * Set to true if we are waiting for this window to receive its
323 * given internal insets before laying out other windows based on it.
324 */
325 boolean mGivenInsetsPending;
326
327 /**
328 * These are the content insets that were given during layout for
329 * this window, to be applied to windows behind it.
330 */
331 final Rect mGivenContentInsets = new Rect();
332
333 /**
334 * These are the visible insets that were given during layout for
335 * this window, to be applied to windows behind it.
336 */
337 final Rect mGivenVisibleInsets = new Rect();
338
339 /**
340 * This is the given touchable area relative to the window frame, or null if none.
341 */
342 final Region mGivenTouchableRegion = new Region();
343
344 /**
345 * Flag indicating whether the touchable region should be adjusted by
346 * the visible insets; if false the area outside the visible insets is
347 * NOT touchable, so we must use those to adjust the frame during hit
348 * tests.
349 */
350 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
351
352 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400353 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700354 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800355 float mHScale=1, mVScale=1;
356 float mLastHScale=1, mLastVScale=1;
357 final Matrix mTmpMatrix = new Matrix();
358
chaviw553b0212018-07-12 13:37:01 -0700359 private final WindowFrames mWindowFrames = new WindowFrames();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700360
Jorim Jaggidc249c42015-12-15 14:57:31 -0800361 /**
362 * Usually empty. Set to the task's tempInsetFrame. See
Wale Ogunwale04d9cb52018-04-30 13:55:07 -0700363 *{@link android.app.IActivityTaskManager#resizeDockedStack}.
Jorim Jaggidc249c42015-12-15 14:57:31 -0800364 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700365 private final Rect mInsetFrame = new Rect();
Jorim Jaggidc249c42015-12-15 14:57:31 -0800366
Adrian Roos4ffc8972019-02-07 20:45:11 +0100367 /**
368 * List of rects where system gestures should be ignored.
369 *
370 * Coordinates are relative to the window's position.
371 */
372 private final List<Rect> mExclusionRects = new ArrayList<>();
373
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800374 // If a window showing a wallpaper: the requested offset for the
375 // wallpaper; if a wallpaper window: the currently applied offset.
376 float mWallpaperX = -1;
377 float mWallpaperY = -1;
378
379 // If a window showing a wallpaper: what fraction of the offset
380 // range corresponds to a full virtual screen.
381 float mWallpaperXStep = -1;
382 float mWallpaperYStep = -1;
383
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700384 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
385 // to its window; if a wallpaper window: not used.
386 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
387 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
388
Craig Mautner2268e7e2012-12-13 15:40:00 -0800389 /**
390 * This is set after IWindowSession.relayout() has been called at
391 * least once for the window. It allows us to detect the situation
392 * where we don't yet have a surface, but should have one soon, so
393 * we can give the window focus before waiting for the relayout.
394 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800395 boolean mRelayoutCalled;
396
Robert Carrfed10072016-05-26 11:48:49 -0700397 boolean mInRelayout;
398
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800399 /**
400 * If the application has called relayout() with changes that can
401 * impact its window's size, we need to perform a layout pass on it
402 * even if it is not currently visible for layout. This is set
403 * when in that case until the layout is done.
404 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800405 boolean mLayoutNeeded;
406
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800407 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800408 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800409
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800410 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800411 boolean mDestroying;
412
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800413 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800414 boolean mRemoveOnExit;
415
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800416 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800417 * Whether the app died while it was visible, if true we might need
418 * to continue to show it until it's restarted.
419 */
420 boolean mAppDied;
421
422 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800423 * Set when the orientation is changing and this window has not yet
424 * been updated for the new orientation.
425 */
Bryce Lee8c3cf382017-07-06 19:47:10 -0700426 private boolean mOrientationChanging;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800427
Dianne Hackborna57c6952013-03-29 14:46:40 -0700428 /**
Robert Carr9c1c3a02017-08-08 12:59:01 -0700429 * Sometimes in addition to the mOrientationChanging
430 * flag we report that the orientation is changing
431 * due to a mismatch in current and reported configuration.
432 *
433 * In the case of timeout we still need to make sure we
434 * leave the orientation changing state though, so we
435 * use this as a special time out escape hatch.
436 */
437 private boolean mOrientationChangeTimedOut;
438
439 /**
Robert Carr237028a2016-07-26 10:39:45 -0700440 * The orientation during the last visible call to relayout. If our
441 * current orientation is different, the window can't be ready
442 * to be shown.
443 */
444 int mLastVisibleLayoutRotation = -1;
445
446 /**
Andrii Kulianb2e37802017-01-11 00:36:44 -0800447 * Set when we need to report the orientation change to client to trigger a relayout.
448 */
449 boolean mReportOrientationChanged;
450
451 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700452 * How long we last kept the screen frozen.
453 */
454 int mLastFreezeDuration;
455
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800456 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800457 boolean mRemoved;
458
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800459 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800460 * It is save to remove the window and destroy the surface because the client requested removal
461 * or some other higher level component said so (e.g. activity manager).
462 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800463 */
Svetoslav Ganov200adfb2016-10-18 13:29:27 -0700464 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800465
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800466 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700467 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800468 InputChannel mInputChannel;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700469 private InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800470
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800471 // Used to improve performance of toString()
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700472 private String mStringNameCache;
473 private CharSequence mLastTitle;
474 private boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800475
Craig Mautnera2c77052012-03-26 12:14:43 -0700476 final WindowStateAnimator mWinAnimator;
477
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700478 boolean mHasSurface = false;
479
Craig Mautner88400d32012-09-30 12:35:45 -0700480 /** When true this window can be displayed on screens owther than mOwnerUid's */
481 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700482
Chong Zhang92147042016-05-09 12:47:11 -0700483 // Whether the window was visible when we set the app to invisible last time. WM uses
484 // this as a hint to restore the surface (if available) for early animation next time
485 // the app is brought visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700486 private boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800487
Robert Carra1eb4392015-12-10 12:43:51 -0800488 // This window will be replaced due to relaunch. This allows window manager
489 // to differentiate between simple removal of a window and replacement. In the latter case it
490 // will preserve the old window until the new one is drawn.
491 boolean mWillReplaceWindow = false;
492 // If true, the replaced window was already requested to be removed.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700493 private boolean mReplacingRemoveRequested = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800494 // Whether the replacement of the window should trigger app transition animation.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700495 private boolean mAnimateReplacingWindow = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800496 // If not null, the window that will be used to replace the old one. This is being set when
497 // the window is added and unset when this window reports its first draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700498 private WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700499 // For the new window in the replacement transition, if we have
500 // requested to replace without animation, then we should
501 // make sure we also don't apply an enter animation for
502 // the new window.
503 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800504 // Whether this window is being moved via the resize API
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700505 private boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800506
Jeff Brownc2932a12014-11-20 18:04:05 -0800507 /**
508 * Wake lock for drawing.
509 * Even though it's slightly more expensive to do so, we will use a separate wake lock
510 * for each app that is requesting to draw while dozing so that we can accurately track
511 * who is preventing the system from suspending.
512 * This lock is only acquired on first use.
513 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700514 private PowerManager.WakeLock mDrawLock;
Jeff Brownc2932a12014-11-20 18:04:05 -0800515
Riddle Hsub398da32019-01-21 21:48:16 +0800516 private final Rect mTmpRect = new Rect();
517 private final Point mTmpPoint = new Point();
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700518
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800519 /**
520 * Whether the window was resized by us while it was gone for layout.
521 */
522 boolean mResizedWhileGone = false;
523
Robert Carr6da3cc02016-06-16 15:17:07 -0700524 /**
525 * During seamless rotation we have two phases, first the old window contents
526 * are rotated to look as if they didn't move in the new coordinate system. Then we
527 * have to freeze updates to this layer (to preserve the transformation) until
528 * the resize actually occurs. This is true from when the transformation is set
529 * and false until the transaction to resize is sent.
530 */
531 boolean mSeamlesslyRotated = false;
532
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700533 /**
Robert Carrc91d1c32017-02-15 19:37:46 -0800534 * Surface insets from the previous call to relayout(), used to track
535 * if we are changing the Surface insets.
536 */
537 final Rect mLastSurfaceInsets = new Rect();
538
539 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700540 * A flag set by the {@link WindowState} parent to indicate that the parent has examined this
541 * {@link WindowState} in its overall drawing context. This book-keeping allows the parent to
542 * make sure all children have been considered.
543 */
544 private boolean mDrawnStateEvaluated;
545
Jorim Jaggia5e10572017-11-15 14:36:26 +0100546 private final Point mSurfacePosition = new Point();
547
Bryce Leed390deb2017-06-22 13:14:28 -0700548 /**
Tiger Huang04dc4cc2019-01-17 18:41:41 +0800549 * A region inside of this window to be excluded from touch.
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800550 */
551 private TapExcludeRegionHolder mTapExcludeRegionHolder;
552
553 /**
chaviw40234662018-02-07 09:37:16 -0800554 * Used for testing because the real PowerManager is final.
555 */
556 private PowerManagerWrapper mPowerManagerWrapper;
557
558 /**
chaviwbe43ac82018-04-04 15:14:49 -0700559 * A frame number in which changes requested in this layout will be rendered.
560 */
561 private long mFrameNumber = -1;
562
chaviwc65fa582018-08-09 15:33:13 -0700563 private static final StringBuilder sTmpSB = new StringBuilder();
564
chaviwbe43ac82018-04-04 15:14:49 -0700565 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700566 * 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 -0700567 * of z-order and 1 otherwise.
568 */
Griff Hazen51d00d82016-11-22 15:39:24 -0800569 private static final Comparator<WindowState> sWindowSubLayerComparator =
570 new Comparator<WindowState>() {
571 @Override
572 public int compare(WindowState w1, WindowState w2) {
573 final int layer1 = w1.mSubLayer;
574 final int layer2 = w2.mSubLayer;
575 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
576 // We insert the child window into the list ordered by
577 // the sub-layer. For same sub-layers, the negative one
578 // should go below others; the positive one should go
579 // above others.
580 return -1;
581 }
582 return 1;
583 };
584 };
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700585
Robert Carrf59b8dd2017-10-02 18:58:36 -0700586 /**
587 * Indicates whether we have requested a Dim (in the sense of {@link Dimmer}) from our host
588 * container.
589 */
590 private boolean mIsDimming = false;
591
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200592 private @Nullable InsetsSourceProvider mInsetProvider;
593
Robert Carrf59b8dd2017-10-02 18:58:36 -0700594 private static final float DEFAULT_DIM_AMOUNT_DEAD_WINDOW = 0.5f;
595
Vishnu Nairba183352018-11-21 11:16:49 -0800596 void seamlesslyRotateIfAllowed(Transaction transaction, @Rotation int oldRotation,
597 @Rotation int rotation, boolean requested) {
Vishnu Nairddd80742018-08-21 14:12:46 -0700598 // Invisible windows and the wallpaper do not participate in the seamless rotation animation
599 if (!isVisibleNow() || mIsWallpaper) {
600 return;
601 }
Adrian Roosfaa102f2018-08-02 15:56:15 +0200602
Vishnu Nairddd80742018-08-21 14:12:46 -0700603 if (mPendingSeamlessRotate != null) {
604 oldRotation = mPendingSeamlessRotate.getOldRotation();
605 }
606
607 if (mForceSeamlesslyRotate || requested) {
608 mPendingSeamlessRotate = new SeamlessRotator(oldRotation, rotation, getDisplayInfo());
Vishnu Nairec634062018-09-20 20:16:18 -0700609 mPendingSeamlessRotate.unrotate(transaction, this);
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800610 mWmService.markForSeamlessRotation(this, true);
Vishnu Nairddd80742018-08-21 14:12:46 -0700611 }
612 }
613
Vishnu Nairba183352018-11-21 11:16:49 -0800614 void finishSeamlessRotation(boolean timeout) {
Vishnu Nairddd80742018-08-21 14:12:46 -0700615 if (mPendingSeamlessRotate != null) {
Vishnu Nairba183352018-11-21 11:16:49 -0800616 mPendingSeamlessRotate.finish(this, timeout);
Vishnu Nairddd80742018-08-21 14:12:46 -0700617 mFinishSeamlessRotateFrameNumber = getFrameNumber();
618 mPendingSeamlessRotate = null;
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800619 mWmService.markForSeamlessRotation(this, false);
Vishnu Nair83537a72018-07-19 21:27:48 -0700620 }
621 }
622
Adrian Roos4ffc8972019-02-07 20:45:11 +0100623 List<Rect> getSystemGestureExclusion() {
624 return mExclusionRects;
625 }
626
627 /**
628 * Sets the system gesture exclusion rects.
629 *
630 * @return {@code true} if anything changed
631 */
632 boolean setSystemGestureExclusion(List<Rect> exclusionRects) {
633 if (mExclusionRects.equals(exclusionRects)) {
634 return false;
635 }
636 mExclusionRects.clear();
637 mExclusionRects.addAll(exclusionRects);
638 return true;
639 }
640
chaviw40234662018-02-07 09:37:16 -0800641 interface PowerManagerWrapper {
Michael Wrighte3001042019-02-05 00:13:14 +0000642 void wakeUp(long time, @WakeReason int reason, String details);
chaviw40234662018-02-07 09:37:16 -0800643
644 boolean isInteractive();
645
646 }
647
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800648 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
chaviw40234662018-02-07 09:37:16 -0800649 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
650 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow) {
651 this(service, s, c, token, parentWindow, appOp, seq, a, viewVisibility, ownerId,
652 ownerCanAddInternalSystemWindow, new PowerManagerWrapper() {
653 @Override
Michael Wrighte3001042019-02-05 00:13:14 +0000654 public void wakeUp(long time, @WakeReason int reason, String details) {
655 service.mPowerManager.wakeUp(time, reason, details);
chaviw40234662018-02-07 09:37:16 -0800656 }
657
658 @Override
659 public boolean isInteractive() {
660 return service.mPowerManager.isInteractive();
661 }
662 });
663 }
664
665 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
666 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
667 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow,
668 PowerManagerWrapper powerManagerWrapper) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100669 super(service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800670 mSession = s;
671 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800672 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800673 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700674 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700675 mOwnerUid = ownerId;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800676 mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200677 mWindowId = new WindowId(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800678 mAttrs.copyFrom(a);
Robert Carrb08ed042018-03-12 15:49:08 -0700679 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800680 mViewVisibility = viewVisibility;
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800681 mPolicy = mWmService.mPolicy;
682 mContext = mWmService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800683 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700684 mSeq = seq;
chaviw40234662018-02-07 09:37:16 -0800685 mPowerManagerWrapper = powerManagerWrapper;
Vishnu Nair83537a72018-07-19 21:27:48 -0700686 mForceSeamlesslyRotate = token.mRoundedCornerOverlay;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700687 if (localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700688 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700689 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800690 try {
691 c.asBinder().linkToDeath(deathRecipient, 0);
692 } catch (RemoteException e) {
693 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700694 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800695 mLayoutAttached = false;
696 mIsImWindow = false;
697 mIsWallpaper = false;
698 mIsFloatingLayer = false;
699 mBaseLayer = 0;
700 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700701 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700702 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800703 return;
704 }
705 mDeathRecipient = deathRecipient;
706
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700707 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800708 // The multiplier here is to reserve space for multiple
709 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800710 mBaseLayer = mPolicy.getWindowLayerLw(parentWindow)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700711 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800712 mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700713 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900714
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700715 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow);
716 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900717
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800718 mLayoutAttached = mAttrs.type !=
719 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700720 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
721 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
722 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800723 } else {
724 // The multiplier here is to reserve space for multiple
725 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800726 mBaseLayer = mPolicy.getWindowLayerLw(this)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700727 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800728 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700729 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800730 mLayoutAttached = false;
731 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
732 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
733 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800734 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700735 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800736
Wale Ogunwale72919d22016-12-08 18:58:50 -0800737 if (mAppToken != null && mAppToken.mShowForAllUsers) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700738 // Windows for apps that can show for all users should also show when the device is
739 // locked.
740 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
Craig Mautner19ab8282014-05-07 10:35:34 -0700741 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800742
Craig Mautner322e4032012-07-13 13:35:20 -0700743 mWinAnimator = new WindowStateAnimator(this);
744 mWinAnimator.mAlpha = a.alpha;
745
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800746 mRequestedWidth = 0;
747 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700748 mLastRequestedWidth = 0;
749 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800750 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800751 mInputWindowHandle = new InputWindowHandle(
Robert Carre0a353c2018-08-02 16:38:04 -0700752 mAppToken != null ? mAppToken.mInputApplicationHandle : null, c,
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800753 getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800754 }
755
756 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700757 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800758 mSession.windowAddedLocked(mAttrs.packageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800759 }
760
Bryce Leed390deb2017-06-22 13:14:28 -0700761 /**
Riddle Hsub398da32019-01-21 21:48:16 +0800762 * @return {@code true} if the application runs in size compatibility mode.
763 * @see android.content.res.CompatibilityInfo#supportsScreen
764 * @see ActivityRecord#inSizeCompatMode
765 */
766 boolean inSizeCompatMode() {
767 return (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0
768 || (mAppToken != null && mAppToken.inSizeCompatMode()
769 // Exclude starting window because it is not displayed by the application.
770 && mAttrs.type != TYPE_APPLICATION_STARTING);
771 }
772
773 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700774 * Returns whether this {@link WindowState} has been considered for drawing by its parent.
775 */
Bryce Lee6311c4b2017-07-06 14:09:29 -0700776 boolean getDrawnStateEvaluated() {
Bryce Leed390deb2017-06-22 13:14:28 -0700777 return mDrawnStateEvaluated;
778 }
779
780 /**
781 * Sets whether this {@link WindowState} has been considered for drawing by its parent. Should
782 * be cleared when detached from parent.
783 */
784 void setDrawnStateEvaluated(boolean evaluated) {
785 mDrawnStateEvaluated = evaluated;
786 }
787
788 @Override
Riddle Hsu3a4bb612019-01-31 00:02:22 +0800789 void onParentChanged() {
790 super.onParentChanged();
Bryce Leed390deb2017-06-22 13:14:28 -0700791 setDrawnStateEvaluated(false /*evaluated*/);
Robert Carr24be9ab2018-04-30 17:54:53 -0700792
793 getDisplayContent().reapplyMagnificationSpec();
Bryce Leed390deb2017-06-22 13:14:28 -0700794 }
795
Craig Mautnera2c77052012-03-26 12:14:43 -0700796 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800797 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800798 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800799 }
800
801 @Override
802 public String getOwningPackage() {
803 return mAttrs.packageName;
804 }
805
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800806 @Override
807 public boolean canAddInternalSystemWindow() {
808 return mOwnerCanAddInternalSystemWindow;
809 }
810
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200811 @Override
812 public boolean canAcquireSleepToken() {
813 return mSession.mCanAcquireSleepToken;
814 }
815
Jorim Jaggif5834272016-04-04 20:25:41 -0700816 /**
817 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
818 * from {@param frame}. In other words, it applies the insets that would result if
819 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700820 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
821 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700822 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700823 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
824 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
825 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
826 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
827 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700828 frame.inset(left, top, right, bottom);
829 }
830
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800831 @Override
Evan Roskyed6767f2018-10-26 17:21:06 -0700832 public Rect getDisplayedBounds() {
833 final Task task = getTask();
834 if (task != null) {
835 Rect bounds = task.getOverrideDisplayedBounds();
836 if (!bounds.isEmpty()) {
837 return bounds;
838 }
839 }
840 return super.getDisplayedBounds();
841 }
842
843 @Override
chaviw1454b392018-08-06 09:54:04 -0700844 public void computeFrameLw() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800845 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700846 // This window is being replaced and either already got information that it's being
847 // removed or we are still waiting for some information. Because of this we don't
848 // want to apply any more changes to it, so it remains in this state until new window
849 // appears.
850 return;
851 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800852 mHaveFrame = true;
853
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700854 final Task task = getTask();
Evan Rosky4fb1e912019-03-06 13:54:43 -0800855 final boolean isFullscreenAndFillsDisplay = !inMultiWindowMode() && matchesDisplayBounds();
Robert Carre6275582016-02-29 15:45:45 -0800856 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700857 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800858
Evan Roskyed6767f2018-10-26 17:21:06 -0700859 mInsetFrame.set(getBounds());
Chong Zhangae35fef2016-03-16 15:56:55 -0700860
Jorim Jaggif5834272016-04-04 20:25:41 -0700861 // Denotes the actual frame used to calculate the insets and to perform the layout. When
862 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
863 // insets temporarily. By the notion of a task having a different layout frame, we can
864 // achieve that while still moving the task around.
865 final Rect layoutContainingFrame;
866 final Rect layoutDisplayFrame;
867
868 // The offset from the layout containing frame to the actual containing frame.
869 final int layoutXDiff;
870 final int layoutYDiff;
Evan Rosky0d654cb2019-02-26 10:59:10 -0800871 final WindowState imeWin = mWmService.mRoot.getCurrentInputMethodWindow();
872 final boolean isImeTarget =
873 imeWin != null && imeWin.isVisibleNow() && isInputMethodTarget();
Evan Rosky4fb1e912019-03-06 13:54:43 -0800874 if (isFullscreenAndFillsDisplay || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800875 // We use the parent frame as the containing frame for fullscreen and child windows
chaviw1454b392018-08-06 09:54:04 -0700876 mWindowFrames.mContainingFrame.set(mWindowFrames.mParentFrame);
877 layoutDisplayFrame = mWindowFrames.mDisplayFrame;
878 layoutContainingFrame = mWindowFrames.mParentFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700879 layoutXDiff = 0;
880 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800881 } else {
Evan Roskyed6767f2018-10-26 17:21:06 -0700882 mWindowFrames.mContainingFrame.set(getDisplayedBounds());
Jorim Jaggi0429f352015-12-22 16:29:16 +0100883 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
884
885 // If the bounds are frozen, we still want to translate the window freely and only
886 // freeze the size.
887 Rect frozen = mAppToken.mFrozenBounds.peek();
chaviw553b0212018-07-12 13:37:01 -0700888 mWindowFrames.mContainingFrame.right =
889 mWindowFrames.mContainingFrame.left + frozen.width();
890 mWindowFrames.mContainingFrame.bottom =
891 mWindowFrames.mContainingFrame.top + frozen.height();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100892 }
Robert Carrfc03b2b2016-03-31 15:22:02 -0700893 // IME is up and obscuring this window. Adjust the window position so it is visible.
Evan Rosky0d654cb2019-02-26 10:59:10 -0800894 if (isImeTarget) {
895 if (inFreeformWindowingMode()) {
896 // Push the freeform window up to make room for the IME. However, don't push
897 // it up past the top of the screen.
898 final int bottomOverlap = mWindowFrames.mContainingFrame.bottom
899 - mWindowFrames.mVisibleFrame.bottom;
900 if (bottomOverlap > 0) {
901 final int distanceToTop = Math.max(mWindowFrames.mContainingFrame.top
902 - mWindowFrames.mDisplayFrame.top, 0);
903 int offs = Math.min(bottomOverlap, distanceToTop);
904 mWindowFrames.mContainingFrame.top -= offs;
905 }
chaviw553b0212018-07-12 13:37:01 -0700906 } else if (!inPinnedWindowingMode() && mWindowFrames.mContainingFrame.bottom
chaviw1454b392018-08-06 09:54:04 -0700907 > mWindowFrames.mParentFrame.bottom) {
Winson Chungd73e94b2017-05-31 16:25:30 -0700908 // But in docked we want to behave like fullscreen and behave as if the task
909 // were given smaller bounds for the purposes of layout. Skip adjustments for
910 // the pinned stack, they are handled separately in the PinnedStackController.
chaviw1454b392018-08-06 09:54:04 -0700911 mWindowFrames.mContainingFrame.bottom = mWindowFrames.mParentFrame.bottom;
Winson Chungd73e94b2017-05-31 16:25:30 -0700912 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700913 }
Skuhne81c524a2015-08-12 13:34:14 -0700914
Robert Carre6275582016-02-29 15:45:45 -0800915 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700916 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
917 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800918 // "content frame" since it is allowed to be outside the visible desktop.
chaviw553b0212018-07-12 13:37:01 -0700919 if (mWindowFrames.mContainingFrame.isEmpty()) {
chaviw1454b392018-08-06 09:54:04 -0700920 mWindowFrames.mContainingFrame.set(mWindowFrames.mContentFrame);
Skuhne81c524a2015-08-12 13:34:14 -0700921 }
Doris Liu06d582d2015-06-01 13:18:43 -0700922 }
Adrian Roos604ef952018-05-15 20:13:13 +0200923
924 final TaskStack stack = getStack();
925 if (inPinnedWindowingMode() && stack != null
926 && stack.lastAnimatingBoundsWasToFullscreen()) {
927 // PIP edge case: When going from pinned to fullscreen, we apply a
928 // tempInsetFrame for the full task - but we're still at the start of the animation.
929 // To prevent a jump if there's a letterbox, restrict to the parent frame.
chaviw1454b392018-08-06 09:54:04 -0700930 mInsetFrame.intersectUnchecked(mWindowFrames.mParentFrame);
931 mWindowFrames.mContainingFrame.intersectUnchecked(mWindowFrames.mParentFrame);
Adrian Roos604ef952018-05-15 20:13:13 +0200932 }
933
chaviw1454b392018-08-06 09:54:04 -0700934 layoutDisplayFrame = new Rect(mWindowFrames.mDisplayFrame);
chaviw553b0212018-07-12 13:37:01 -0700935 mWindowFrames.mDisplayFrame.set(mWindowFrames.mContainingFrame);
Evan Roskyed6767f2018-10-26 17:21:06 -0700936 layoutXDiff = mInsetFrame.left - mWindowFrames.mContainingFrame.left;
937 layoutYDiff = mInsetFrame.top - mWindowFrames.mContainingFrame.top;
938 layoutContainingFrame = mInsetFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700939 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
chaviw1454b392018-08-06 09:54:04 -0700940 subtractInsets(mWindowFrames.mDisplayFrame, layoutContainingFrame, layoutDisplayFrame,
941 mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700942 if (!layoutInParentFrame()) {
chaviw553b0212018-07-12 13:37:01 -0700943 subtractInsets(mWindowFrames.mContainingFrame, layoutContainingFrame,
chaviw1454b392018-08-06 09:54:04 -0700944 mWindowFrames.mParentFrame, mTmpRect);
945 subtractInsets(mInsetFrame, layoutContainingFrame, mWindowFrames.mParentFrame,
chaviw553b0212018-07-12 13:37:01 -0700946 mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700947 }
Jorim Jaggif5834272016-04-04 20:25:41 -0700948 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700949 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800950
chaviw553b0212018-07-12 13:37:01 -0700951 final int pw = mWindowFrames.mContainingFrame.width();
952 final int ph = mWindowFrames.mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800953
Dianne Hackborn1743b642012-03-12 17:04:43 -0700954 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
955 mLastRequestedWidth = mRequestedWidth;
956 mLastRequestedHeight = mRequestedHeight;
chaviw1454b392018-08-06 09:54:04 -0700957 mWindowFrames.setContentChanged(true);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700958 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800959
chaviw492139a2018-07-16 16:07:35 -0700960 final int fw = mWindowFrames.mFrame.width();
961 final int fh = mWindowFrames.mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800962
Jorim Jaggif5834272016-04-04 20:25:41 -0700963 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
964
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700965 // Calculate the outsets before the content frame gets shrinked to the window frame.
chaviw1454b392018-08-06 09:54:04 -0700966 mWindowFrames.calculateOutsets();
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700967
Craig Mautnera248eee2013-05-07 11:41:27 -0700968 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800969 // final window frame.
chaviw492139a2018-07-16 16:07:35 -0700970 if (windowsAreFloating && !mWindowFrames.mFrame.isEmpty()) {
Evan Rosky0d654cb2019-02-26 10:59:10 -0800971 final int visBottom = mWindowFrames.mVisibleFrame.bottom;
972 final int contentBottom = mWindowFrames.mContentFrame.bottom;
Evan Rosky60dba2f2019-02-01 10:58:38 -0800973 mWindowFrames.mContentFrame.set(mWindowFrames.mFrame);
chaviw553b0212018-07-12 13:37:01 -0700974 mWindowFrames.mVisibleFrame.set(mWindowFrames.mContentFrame);
975 mWindowFrames.mStableFrame.set(mWindowFrames.mContentFrame);
Evan Rosky0d654cb2019-02-26 10:59:10 -0800976 if (isImeTarget && inFreeformWindowingMode()) {
977 // After displacing a freeform window to make room for the ime, any part of
978 // the window still covered by IME should be inset.
979 if (contentBottom + layoutYDiff < mWindowFrames.mContentFrame.bottom) {
980 mWindowFrames.mContentFrame.bottom = contentBottom + layoutYDiff;
981 }
982 if (visBottom + layoutYDiff < mWindowFrames.mVisibleFrame.bottom) {
983 mWindowFrames.mVisibleFrame.bottom = visBottom + layoutYDiff;
984 }
985 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700986 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
chaviw492139a2018-07-16 16:07:35 -0700987 dc.getDockedDividerController().positionDockedStackedDivider(mWindowFrames.mFrame);
988 mWindowFrames.mContentFrame.set(mWindowFrames.mFrame);
989 if (!mWindowFrames.mFrame.equals(mWindowFrames.mLastFrame)) {
Jorim Jaggi192086e2016-03-11 17:17:03 +0100990 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800991 }
Skuhne81c524a2015-08-12 13:34:14 -0700992 } else {
chaviw492139a2018-07-16 16:07:35 -0700993 mWindowFrames.mContentFrame.set(
994 Math.max(mWindowFrames.mContentFrame.left, mWindowFrames.mFrame.left),
995 Math.max(mWindowFrames.mContentFrame.top, mWindowFrames.mFrame.top),
996 Math.min(mWindowFrames.mContentFrame.right, mWindowFrames.mFrame.right),
997 Math.min(mWindowFrames.mContentFrame.bottom, mWindowFrames.mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800998
chaviw492139a2018-07-16 16:07:35 -0700999 mWindowFrames.mVisibleFrame.set(
1000 Math.max(mWindowFrames.mVisibleFrame.left, mWindowFrames.mFrame.left),
1001 Math.max(mWindowFrames.mVisibleFrame.top, mWindowFrames.mFrame.top),
1002 Math.min(mWindowFrames.mVisibleFrame.right, mWindowFrames.mFrame.right),
1003 Math.min(mWindowFrames.mVisibleFrame.bottom, mWindowFrames.mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001004
chaviw492139a2018-07-16 16:07:35 -07001005 mWindowFrames.mStableFrame.set(
1006 Math.max(mWindowFrames.mStableFrame.left, mWindowFrames.mFrame.left),
1007 Math.max(mWindowFrames.mStableFrame.top, mWindowFrames.mFrame.top),
1008 Math.min(mWindowFrames.mStableFrame.right, mWindowFrames.mFrame.right),
1009 Math.min(mWindowFrames.mStableFrame.bottom, mWindowFrames.mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -07001010 }
Adrian Roosfa104232014-06-20 16:10:14 -07001011
Evan Rosky4fb1e912019-03-06 13:54:43 -08001012 if (isFullscreenAndFillsDisplay && !windowsAreFloating) {
Jorim Jaggi899327f2016-02-25 20:44:18 -05001013 // Windows that are not fullscreen can be positioned outside of the display frame,
1014 // but that is not a reason to provide them with overscan insets.
chaviw9c81e632018-07-31 11:17:52 -07001015 InsetUtils.insetsBetweenFrames(layoutContainingFrame, mWindowFrames.mOverscanFrame,
1016 mWindowFrames.mOverscanInsets);
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -08001017 }
Craig Mautnereda67292013-04-28 13:50:14 -07001018
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001019 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
chaviw1454b392018-08-06 09:54:04 -07001020 final WmDisplayCutout c = mWindowFrames.mDisplayCutout.calculateRelativeTo(
chaviw553b0212018-07-12 13:37:01 -07001021 mWindowFrames.mDisplayFrame);
chaviw9c81e632018-07-31 11:17:52 -07001022 mWindowFrames.calculateDockedDividerInsets(c.getDisplayCutout().getSafeInsets());
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001023 } else {
Bryce Leef3c6a472017-11-14 14:53:06 -08001024 getDisplayContent().getBounds(mTmpRect);
Evan Rosky4fb1e912019-03-06 13:54:43 -08001025 mWindowFrames.calculateInsets(
1026 windowsAreFloating, isFullscreenAndFillsDisplay, mTmpRect);
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001027 }
Adrian Roosfa104232014-06-20 16:10:14 -07001028
chaviwcdba9a42018-07-19 11:36:42 -07001029 mWindowFrames.setDisplayCutout(
chaviw1454b392018-08-06 09:54:04 -07001030 mWindowFrames.mDisplayCutout.calculateRelativeTo(mWindowFrames.mFrame));
Jorim Jaggibae2b152018-04-18 17:27:27 +02001031
Jorim Jaggi656f6502016-04-11 21:08:17 -07001032 // Offset the actual frame by the amount layout frame is off.
chaviw9c81e632018-07-31 11:17:52 -07001033 mWindowFrames.offsetFrames(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -07001034
chaviw9c81e632018-07-31 11:17:52 -07001035 mWindowFrames.mCompatFrame.set(mWindowFrames.mFrame);
Riddle Hsub398da32019-01-21 21:48:16 +08001036 if (inSizeCompatMode()) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001037 // If there is a size compatibility scale being applied to the
1038 // window, we need to apply this to its insets so that they are
1039 // reported to the app in its coordinate space.
chaviw9c81e632018-07-31 11:17:52 -07001040 mWindowFrames.scaleInsets(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001041
1042 // Also the scaled frame that we report to the app needs to be
1043 // adjusted to be in its coordinate space.
chaviw9c81e632018-07-31 11:17:52 -07001044 mWindowFrames.mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001045 }
1046
chaviw492139a2018-07-16 16:07:35 -07001047 if (mIsWallpaper && (fw != mWindowFrames.mFrame.width()
1048 || fh != mWindowFrames.mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001049 final DisplayContent displayContent = getDisplayContent();
1050 if (displayContent != null) {
1051 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
chaviw553b0212018-07-12 13:37:01 -07001052 getDisplayContent().mWallpaperController.updateWallpaperOffset(this,
1053 displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001054 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001055 }
1056
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001057 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001058 "Resolving (mRequestedWidth="
1059 + mRequestedWidth + ", mRequestedheight="
1060 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
chaviw492139a2018-07-16 16:07:35 -07001061 + "): frame=" + mWindowFrames.mFrame.toShortString()
chaviw9c81e632018-07-31 11:17:52 -07001062 + " " + mWindowFrames.getInsetsInfo());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001063 }
1064
Bryce Leef3c6a472017-11-14 14:53:06 -08001065 // TODO: Look into whether this override is still necessary.
1066 @Override
1067 public Rect getBounds() {
Evan Rosky4fb1e912019-03-06 13:54:43 -08001068 if (mAppToken != null) {
Bryce Leef3c6a472017-11-14 14:53:06 -08001069 return mAppToken.getBounds();
1070 } else {
1071 return super.getBounds();
1072 }
1073 }
1074
Craig Mautnera2c77052012-03-26 12:14:43 -07001075 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001076 public Rect getFrameLw() {
chaviw492139a2018-07-16 16:07:35 -07001077 return mWindowFrames.mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001078 }
1079
Craig Mautnera2c77052012-03-26 12:14:43 -07001080 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001081 public Rect getDisplayFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001082 return mWindowFrames.mDisplayFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001083 }
1084
Craig Mautnera2c77052012-03-26 12:14:43 -07001085 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001086 public Rect getOverscanFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001087 return mWindowFrames.mOverscanFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001088 }
1089
1090 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001091 public Rect getContentFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001092 return mWindowFrames.mContentFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001093 }
1094
Craig Mautnera2c77052012-03-26 12:14:43 -07001095 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001096 public Rect getVisibleFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001097 return mWindowFrames.mVisibleFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001098 }
1099
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001100 Rect getStableFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001101 return mWindowFrames.mStableFrame;
1102 }
1103
1104 Rect getDecorFrame() {
1105 return mWindowFrames.mDecorFrame;
1106 }
1107
1108 Rect getParentFrame() {
1109 return mWindowFrames.mParentFrame;
1110 }
1111
1112 Rect getContainingFrame() {
1113 return mWindowFrames.mContainingFrame;
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001114 }
1115
chaviwcdba9a42018-07-19 11:36:42 -07001116 WmDisplayCutout getWmDisplayCutout() {
1117 return mWindowFrames.mDisplayCutout;
1118 }
1119
chaviw9c81e632018-07-31 11:17:52 -07001120 void getCompatFrame(Rect outFrame) {
1121 outFrame.set(mWindowFrames.mCompatFrame);
1122 }
1123
1124 void getCompatFrameSize(Rect outFrame) {
1125 outFrame.set(0, 0, mWindowFrames.mCompatFrame.width(), mWindowFrames.mCompatFrame.height());
1126 }
1127
Craig Mautnera2c77052012-03-26 12:14:43 -07001128 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001129 public boolean getGivenInsetsPendingLw() {
1130 return mGivenInsetsPending;
1131 }
1132
Craig Mautnera2c77052012-03-26 12:14:43 -07001133 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001134 public Rect getGivenContentInsetsLw() {
1135 return mGivenContentInsets;
1136 }
1137
Craig Mautnera2c77052012-03-26 12:14:43 -07001138 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001139 public Rect getGivenVisibleInsetsLw() {
1140 return mGivenVisibleInsets;
1141 }
1142
Craig Mautnera2c77052012-03-26 12:14:43 -07001143 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001144 public WindowManager.LayoutParams getAttrs() {
1145 return mAttrs;
1146 }
1147
Craig Mautner812d2ca2012-09-27 15:35:34 -07001148 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001149 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001150 return getDisplayContent().getNeedsMenu(this, bottom);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001151 }
1152
Craig Mautner19d59bc2012-09-04 11:15:56 -07001153 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001154 public int getSystemUiVisibility() {
1155 return mSystemUiVisibility;
1156 }
1157
Craig Mautner19d59bc2012-09-04 11:15:56 -07001158 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001159 public int getSurfaceLayer() {
1160 return mLayer;
1161 }
1162
Craig Mautner812d2ca2012-09-27 15:35:34 -07001163 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001164 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001165 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001166 }
1167
1168 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001169 public IApplicationToken getAppToken() {
1170 return mAppToken != null ? mAppToken.appToken : null;
1171 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001172
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001173 @Override
1174 public boolean isVoiceInteraction() {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001175 return mAppToken != null && mAppToken.mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001176 }
1177
Robert Carr31aa98b2016-07-20 15:29:03 -07001178 boolean setReportResizeHints() {
chaviw9c81e632018-07-31 11:17:52 -07001179 return mWindowFrames.setReportResizeHints();
Craig Mautner4c5eb222013-11-18 12:59:05 -08001180 }
1181
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001182 /**
1183 * Adds the window to the resizing list if any of the parameters we use to track the window
1184 * dimensions or insets have changed.
1185 */
1186 void updateResizingWindowIfNeeded() {
1187 final WindowStateAnimator winAnimator = mWinAnimator;
Adrian Roos5251b1d2018-03-23 18:57:43 +01001188 if (!mHasSurface || getDisplayContent().mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001189 return;
1190 }
1191
1192 final Task task = getTask();
1193 // In the case of stack bound animations, the window frames will update (unlike other
1194 // animations which just modify various transformation properties). We don't want to
1195 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1196 // the frame may not correspond to the surface size or the onscreen area at various
1197 // phases in the animation, and the client will become sad and confused.
Winson Chung40a5f932017-04-13 16:39:36 -07001198 if (task != null && task.mStack.isAnimatingBounds()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001199 return;
1200 }
1201
chaviw9c81e632018-07-31 11:17:52 -07001202 boolean didFrameInsetsChange = setReportResizeHints();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001203 boolean configChanged = isConfigChanged();
1204 if (DEBUG_CONFIGURATION && configChanged) {
1205 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1206 }
1207
1208 final boolean dragResizingChanged = isDragResizeChanged()
1209 && !isDragResizingChangeReported();
1210
1211 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
chaviw492139a2018-07-16 16:07:35 -07001212 + " dragResizingChanged=" + dragResizingChanged
1213 + " last=" + mWindowFrames.mLastFrame + " frame=" + mWindowFrames.mFrame);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001214
1215 // We update mLastFrame always rather than in the conditional with the last inset
1216 // variables, because mFrameSizeChanged only tracks the width and height changing.
chaviw492139a2018-07-16 16:07:35 -07001217 mWindowFrames.mLastFrame.set(mWindowFrames.mFrame);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001218
chaviw9c81e632018-07-31 11:17:52 -07001219 if (didFrameInsetsChange
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001220 || winAnimator.mSurfaceResized
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001221 || configChanged
1222 || dragResizingChanged
Andrii Kulianb2e37802017-01-11 00:36:44 -08001223 || mReportOrientationChanged) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001224 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1225 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
chaviw9c81e632018-07-31 11:17:52 -07001226 + " " + mWindowFrames.getInsetsChangedInfo()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001227 + " surfaceResized=" + winAnimator.mSurfaceResized
1228 + " configChanged=" + configChanged
1229 + " dragResizingChanged=" + dragResizingChanged
chaviw9c81e632018-07-31 11:17:52 -07001230 + " reportOrientationChanged=" + mReportOrientationChanged);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001231 }
1232
1233 // If it's a dead window left on screen, and the configuration changed, there is nothing
1234 // we can do about it. Remove the window now.
1235 if (mAppToken != null && mAppDied) {
1236 mAppToken.removeDeadWindows();
1237 return;
1238 }
1239
Jorim Jaggidc9385a2017-05-13 02:00:31 +02001240 updateLastInsetValues();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001241 mWmService.makeWindowFreezingScreenIfNeededLocked(this);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001242
1243 // If the orientation is changing, or we're starting or ending a drag resizing action,
1244 // then we need to hold off on unfreezing the display until this window has been
1245 // redrawn; to do that, we need to go through the process of getting informed by the
1246 // application when it has finished drawing.
Robert Carr09286c92018-02-15 13:52:31 -08001247 if (getOrientationChanging() || dragResizingChanged) {
Robert Carre13b58e2017-08-31 14:50:44 -07001248 if (DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001249 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1250 + ", mDrawState=DRAW_PENDING in " + this
1251 + ", surfaceController " + winAnimator.mSurfaceController);
1252 }
1253 winAnimator.mDrawState = DRAW_PENDING;
1254 if (mAppToken != null) {
1255 mAppToken.clearAllDrawn();
1256 }
1257 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001258 if (!mWmService.mResizingWindows.contains(this)) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001259 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001260 mWmService.mResizingWindows.add(this);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001261 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07001262 } else if (getOrientationChanging()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001263 if (isDrawnLw()) {
1264 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1265 + this + ", surfaceController " + winAnimator.mSurfaceController);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001266 setOrientationChanging(false);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001267 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001268 - mWmService.mDisplayFreezeTime);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001269 }
1270 }
1271 }
1272
Bryce Lee8c3cf382017-07-06 19:47:10 -07001273 boolean getOrientationChanging() {
1274 // In addition to the local state flag, we must also consider the difference in the last
1275 // reported configuration vs. the current state. If the client code has not been informed of
1276 // the change, logic dependent on having finished processing the orientation, such as
1277 // unfreezing, could be improperly triggered.
1278 // TODO(b/62846907): Checking against {@link mLastReportedConfiguration} could be flaky as
1279 // this is not necessarily what the client has processed yet. Find a
1280 // better indicator consistent with the client.
Robert Carr926643f2017-08-02 12:01:12 -07001281 return (mOrientationChanging || (isVisible()
Bryce Lee2b17afd2017-09-21 10:38:20 -07001282 && getConfiguration().orientation != getLastReportedConfiguration().orientation))
Robert Carr9c1c3a02017-08-08 12:59:01 -07001283 && !mSeamlesslyRotated
1284 && !mOrientationChangeTimedOut;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001285 }
1286
1287 void setOrientationChanging(boolean changing) {
1288 mOrientationChanging = changing;
Robert Carr9c1c3a02017-08-08 12:59:01 -07001289 mOrientationChangeTimedOut = false;
1290 }
1291
1292 void orientationChangeTimedOut() {
1293 mOrientationChangeTimedOut = true;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001294 }
1295
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001296 DisplayContent getDisplayContent() {
1297 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001298 }
1299
Adrian Roos5251b1d2018-03-23 18:57:43 +01001300 @Override
1301 void onDisplayChanged(DisplayContent dc) {
1302 super.onDisplayChanged(dc);
1303 // Window was not laid out for this display yet, so make sure mLayoutSeq does not match.
1304 if (dc != null) {
1305 mLayoutSeq = dc.mLayoutSeq - 1;
Brad Stenningaf596412018-04-02 12:03:19 -07001306 mInputWindowHandle.displayId = dc.getDisplayId();
Adrian Roos5251b1d2018-03-23 18:57:43 +01001307 }
1308 }
1309
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001310 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001311 final DisplayContent displayContent = getDisplayContent();
1312 return displayContent != null ? displayContent.getDisplayInfo() : null;
1313 }
1314
Jorim Jaggife762342016-10-13 14:33:27 +02001315 @Override
1316 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001317 final DisplayContent displayContent = getDisplayContent();
1318 if (displayContent == null) {
Brad Stenningaf596412018-04-02 12:03:19 -07001319 return Display.INVALID_DISPLAY;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001320 }
1321 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001322 }
1323
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001324 Task getTask() {
Bryce Lee6d410262017-02-28 15:30:17 -08001325 return mAppToken != null ? mAppToken.getTask() : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001326 }
1327
1328 TaskStack getStack() {
1329 Task task = getTask();
1330 if (task != null) {
1331 if (task.mStack != null) {
1332 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001333 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001334 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001335 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1336 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001337 final DisplayContent dc = getDisplayContent();
1338 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001339 }
1340
Skuhnef932e562015-08-20 12:07:30 -07001341 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001342 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001343 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001344 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001345 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001346 final Task task = getTask();
1347 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001348 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001349 mTmpRect.setEmpty();
1350 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001351 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001352 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001353 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001354 } else {
1355 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001356 }
1357 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001358
chaviw553b0212018-07-12 13:37:01 -07001359 bounds.set(mWindowFrames.mVisibleFrame);
Chong Zhang9184ec62015-09-24 12:32:21 -07001360 if (intersectWithStackBounds) {
1361 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001362 }
1363
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001364 if (bounds.isEmpty()) {
chaviw492139a2018-07-16 16:07:35 -07001365 bounds.set(mWindowFrames.mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001366 if (intersectWithStackBounds) {
1367 bounds.intersect(mTmpRect);
1368 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001369 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001370 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001371 }
1372
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001373 public long getInputDispatchingTimeoutNanos() {
1374 return mAppToken != null
Wale Ogunwale72919d22016-12-08 18:58:50 -08001375 ? mAppToken.mInputDispatchingTimeoutNanos
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001376 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1377 }
1378
Craig Mautnere8552142012-11-07 13:55:47 -08001379 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001380 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001381 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001382 }
1383
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001384 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1385 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1386 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1387 if (dtdx < -.000001f || dtdx > .000001f) return false;
1388 if (dsdy < -.000001f || dsdy > .000001f) return false;
1389 return true;
1390 }
1391
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001392 void prelayout() {
Riddle Hsub398da32019-01-21 21:48:16 +08001393 if (inSizeCompatMode()) {
1394 mGlobalScale = mToken.getSizeCompatScale();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001395 mInvGlobalScale = 1 / mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001396 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001397 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001398 }
1399 }
1400
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001401 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001402 boolean hasContentToDisplay() {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001403 if (!mAppFreezing && isDrawnLw() && (mViewVisibility == View.VISIBLE
lumark588a3e82018-07-20 18:53:54 +08001404 || (isAnimating() && !getDisplayContent().mAppTransition.isTransitionSet()))) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001405 return true;
1406 }
1407
Wale Ogunwale44f21802016-09-02 12:49:48 -07001408 return super.hasContentToDisplay();
1409 }
1410
1411 @Override
1412 boolean isVisible() {
Jorim Jaggicfd6f3b2018-11-07 15:30:18 +01001413 return wouldBeVisibleIfPolicyIgnored() && mPolicyVisibility
1414 // If we don't have a provider, this window isn't used as a window generating
1415 // insets, so nobody can hide it over the inset APIs.
1416 && (mInsetProvider == null || mInsetProvider.isClientVisible());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001417 }
1418
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001419 /**
Jorim Jaggicfd6f3b2018-11-07 15:30:18 +01001420 * @return {@code true} if the window would be visible if we'd ignore policy visibility,
1421 * {@code false} otherwise.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001422 */
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001423 boolean wouldBeVisibleIfPolicyIgnored() {
Jorim Jaggi43530c92017-05-18 01:53:56 +02001424 return mHasSurface && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001425 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001426 }
1427
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001428 @Override
1429 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001430 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001431 }
1432
1433 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001434 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1435 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001436 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001437 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1438 boolean isWinVisibleLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001439 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.isSelfAnimating())
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001440 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001441 }
1442
1443 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001444 * The same as isVisible(), but follows the current hidden state of the associated app token,
1445 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001446 */
1447 boolean isVisibleNow() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001448 return (!mToken.isHidden() || mAttrs.type == TYPE_APPLICATION_STARTING)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001449 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001450 }
1451
1452 /**
1453 * Can this window possibly be a drag/drop target? The test here is
1454 * a combination of the above "visible now" with the check that the
1455 * Input Manager uses when discarding windows from input consideration.
1456 */
1457 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001458 return isVisibleNow() && !mRemoved
1459 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001460 }
1461
1462 /**
1463 * Same as isVisible(), but we also count it as visible between the
1464 * call to IWindowSession.add() and the first relayout().
1465 */
1466 boolean isVisibleOrAdding() {
1467 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001468 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001469 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001470 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001471 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001472 }
1473
1474 /**
1475 * Is this window currently on-screen? It is on-screen either if it
1476 * is visible or it is currently running an animation before no longer
1477 * being visible.
1478 */
1479 boolean isOnScreen() {
Jorim Jaggiaf221d12016-11-15 14:59:57 -08001480 if (!mHasSurface || mDestroying || !mPolicyVisibility) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001481 return false;
1482 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001483 final AppWindowToken atoken = mAppToken;
1484 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001485 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001486 || isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001487 }
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001488 return !isParentWindowHidden() || isAnimating();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001489 }
1490
1491 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001492 * Whether this window's drawn state might affect the drawn states of the app token.
1493 *
Chong Zhang8e4bda92016-05-04 15:08:18 -07001494 * @return true if the window should be considered while evaluating allDrawn flags.
1495 */
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001496 boolean mightAffectAllDrawn() {
1497 final boolean isAppType = mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1498 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION;
1499 return (isOnScreen() || isAppType) && !mAnimatingExit && !mDestroying;
Chong Zhang8e4bda92016-05-04 15:08:18 -07001500 }
1501
1502 /**
1503 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1504 * it must be drawn before allDrawn can become true.
1505 */
1506 boolean isInteresting() {
1507 return mAppToken != null && !mAppDied
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001508 && (!mAppToken.isFreezingScreen() || !mAppFreezing);
Chong Zhang8e4bda92016-05-04 15:08:18 -07001509 }
1510
1511 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001512 * Like isOnScreen(), but we don't return true if the window is part
1513 * of a transition that has not yet been started.
1514 */
1515 boolean isReadyForDisplay() {
lumark588a3e82018-07-20 18:53:54 +08001516 if (mToken.waitingToShow && getDisplayContent().mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001517 return false;
1518 }
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001519 final boolean parentAndClientVisible = !isParentWindowHidden()
1520 && mViewVisibility == View.VISIBLE && !mToken.isHidden();
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001521 return mHasSurface && mPolicyVisibility && !mDestroying
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001522 && (parentAndClientVisible || isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001523 }
1524
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001525 // TODO: Another visibility method that was added late in the release to minimize risk.
1526 @Override
1527 public boolean canAffectSystemUiFlags() {
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001528 final boolean translucent = mAttrs.alpha == 0.0f;
Jorim Jaggi72207752018-01-08 13:16:59 +01001529 if (translucent) {
1530 return false;
1531 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001532 if (mAppToken == null) {
1533 final boolean shown = mWinAnimator.getShown();
1534 final boolean exiting = mAnimatingExit || mDestroying;
Jorim Jaggi72207752018-01-08 13:16:59 +01001535 return shown && !exiting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001536 } else {
Jorim Jaggi50bf59c2018-03-09 17:29:48 +01001537 final Task task = getTask();
1538 final boolean canFromTask = task != null && task.canAffectSystemUiFlags();
1539 return canFromTask && !mAppToken.isHidden();
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001540 }
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001541 }
1542
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001543 /**
1544 * Like isOnScreen, but returns false if the surface hasn't yet
1545 * been drawn.
1546 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001547 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001548 public boolean isDisplayedLw() {
1549 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001550 return isDrawnLw() && mPolicyVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001551 && ((!isParentWindowHidden() && (atoken == null || !atoken.hiddenRequested))
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001552 || isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001553 }
1554
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001555 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001556 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001557 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001558 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001559 public boolean isAnimatingLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001560 return isAnimating();
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001561 }
1562
Craig Mautner812d2ca2012-09-27 15:35:34 -07001563 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001564 public boolean isGoneForLayoutLw() {
1565 final AppWindowToken atoken = mAppToken;
1566 return mViewVisibility == View.GONE
1567 || !mRelayoutCalled
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001568 || (atoken == null && mToken.isHidden())
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001569 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001570 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001571 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001572 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001573 }
1574
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001575 /**
1576 * Returns true if the window has a surface that it has drawn a
1577 * complete UI in to.
1578 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001579 public boolean isDrawFinishedLw() {
1580 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001581 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1582 || mWinAnimator.mDrawState == READY_TO_SHOW
1583 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001584 }
1585
1586 /**
1587 * Returns true if the window has a surface that it has drawn a
1588 * complete UI in to.
1589 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001590 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001591 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001592 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001593 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001594 }
1595
1596 /**
1597 * Return true if the window is opaque and fully drawn. This indicates
1598 * it may obscure windows behind it.
1599 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001600 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001601 // When there is keyguard, wallpaper could be placed over the secure app
1602 // window but invisible. We need to check wallpaper visibility explicitly
1603 // to determine if it's occluding apps.
1604 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1605 || (mIsWallpaper && mWallpaperVisible))
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001606 && isDrawnLw() && !isAnimating();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001607 }
1608
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001609 @Override
1610 void onMovedByResize() {
1611 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001612 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001613 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001614 }
1615
1616 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1617 boolean changed = false;
1618
1619 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001620 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001621 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1622 }
1623
1624 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1625 // Starting window that's exiting will be removed when the animation finishes.
1626 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1627 // to actually remove it.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001628 if (!visible && isVisibleNow() && mAppToken.isSelfAnimating()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001629 mAnimatingExit = true;
1630 mRemoveOnExit = true;
1631 mWindowRemovalAllowed = true;
1632 }
1633 return changed;
1634 }
1635
chaviwe390cbd2018-04-16 15:29:38 -07001636 final boolean isVisibleNow = isVisibleNow();
1637 if (visible != isVisibleNow) {
1638 // Run exit animation if:
1639 // 1. App visibility and WS visibility are different
1640 // 2. App is not running an animation
1641 // 3. WS is currently visible
1642 if (!runningAppAnimation && isVisibleNow) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001643 final AccessibilityController accessibilityController =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001644 mWmService.mAccessibilityController;
chaviwe390cbd2018-04-16 15:29:38 -07001645 final int winTransit = TRANSIT_EXIT;
1646 mWinAnimator.applyAnimationLocked(winTransit, false /* isEntrance */);
Rhed Jao02655dc2018-10-30 20:44:52 +08001647 if (accessibilityController != null) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001648 accessibilityController.onWindowTransitionLocked(this, winTransit);
1649 }
1650 }
1651 changed = true;
1652 setDisplayLayoutNeeded();
1653 }
1654
1655 return changed;
1656 }
1657
1658 boolean onSetAppExiting() {
1659 final DisplayContent displayContent = getDisplayContent();
1660 boolean changed = false;
1661
1662 if (isVisibleNow()) {
1663 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
Rhed Jao02655dc2018-10-30 20:44:52 +08001664 if (mWmService.mAccessibilityController != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001665 mWmService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001666 }
1667 changed = true;
1668 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001669 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001670 }
1671 }
1672
1673 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001674 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001675 changed |= c.onSetAppExiting();
1676 }
1677
1678 return changed;
1679 }
1680
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001681 @Override
1682 void onResize() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001683 final ArrayList<WindowState> resizingWindows = mWmService.mResizingWindows;
Andrii Kulian3dcdf642018-05-23 17:14:00 -07001684 if (mHasSurface && !isGoneForLayoutLw() && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001685 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001686 resizingWindows.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001687 }
1688 if (isGoneForLayoutLw()) {
1689 mResizedWhileGone = true;
1690 }
1691
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001692 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001693 }
1694
1695 void onUnfreezeBounds() {
1696 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001697 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001698 c.onUnfreezeBounds();
1699 }
1700
1701 if (!mHasSurface) {
1702 return;
1703 }
1704
1705 mLayoutNeeded = true;
1706 setDisplayLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001707 if (!mWmService.mResizingWindows.contains(this)) {
1708 mWmService.mResizingWindows.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001709 }
1710 }
1711
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001712 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001713 * If the window has moved due to its containing content frame changing, then notify the
1714 * listeners and optionally animate it. Simply checking a change of position is not enough,
1715 * because being move due to dock divider is not a trigger for animation.
1716 */
chaviw161ea3e2018-01-31 12:01:12 -08001717 void handleWindowMovedIfNeeded() {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001718 if (!hasMoved()) {
1719 return;
1720 }
1721
1722 // Frame has moved, containing content frame has also moved, and we're not currently
1723 // animating... let's do something.
chaviw492139a2018-07-16 16:07:35 -07001724 final int left = mWindowFrames.mFrame.left;
1725 final int top = mWindowFrames.mFrame.top;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001726 final Task task = getTask();
1727 final boolean adjustedForMinimizedDockOrIme = task != null
1728 && (task.mStack.isAdjustedForMinimizedDockedStack()
1729 || task.mStack.isAdjustedForIme());
David Stevens9440dc82017-03-16 19:00:20 -07001730 if (mToken.okToAnimate()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001731 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1732 && !isDragResizing() && !adjustedForMinimizedDockOrIme
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001733 && getWindowConfiguration().hasMovementAnimations()
Adrian Roos0e7b70a2018-06-07 15:29:34 +02001734 && !mWinAnimator.mLastHidden
1735 && !mSeamlesslyRotated) {
chaviw161ea3e2018-01-31 12:01:12 -08001736 startMoveAnimation(left, top);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001737 }
1738
1739 //TODO (multidisplay): Accessibility supported only for the default display.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001740 if (mWmService.mAccessibilityController != null
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001741 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001742 mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001743 }
1744
1745 try {
1746 mClient.moved(left, top);
1747 } catch (RemoteException e) {
1748 }
1749 mMovedByResize = false;
1750 }
1751
1752 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001753 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001754 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1755 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001756 private boolean hasMoved() {
chaviw1454b392018-08-06 09:54:04 -07001757 return mHasSurface && (mWindowFrames.hasContentChanged() || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001758 && !mAnimatingExit
chaviw492139a2018-07-16 16:07:35 -07001759 && (mWindowFrames.mFrame.top != mWindowFrames.mLastFrame.top
1760 || mWindowFrames.mFrame.left != mWindowFrames.mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001761 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001762 }
1763
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001764 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001765 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001766 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001767 return false;
1768 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001769 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001770 }
1771
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001772 boolean fillsDisplay() {
1773 final DisplayInfo displayInfo = getDisplayInfo();
chaviw492139a2018-07-16 16:07:35 -07001774 return mWindowFrames.mFrame.left <= 0 && mWindowFrames.mFrame.top <= 0
1775 && mWindowFrames.mFrame.right >= displayInfo.appWidth
1776 && mWindowFrames.mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001777 }
1778
Evan Rosky4fb1e912019-03-06 13:54:43 -08001779 private boolean matchesDisplayBounds() {
1780 return getDisplayContent().getBounds().equals(getBounds());
1781 }
1782
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001783 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001784 boolean isConfigChanged() {
Bryce Lee2b17afd2017-09-21 10:38:20 -07001785 return !getLastReportedConfiguration().equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001786 }
1787
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001788 void onWindowReplacementTimeout() {
1789 if (mWillReplaceWindow) {
1790 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001791 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001792 // delays removal on certain conditions, which will leave the stale window in the
1793 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1794 //
1795 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001796 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001797 } else {
1798 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001799 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001800 c.onWindowReplacementTimeout();
1801 }
1802 }
1803 }
1804
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001805 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001806 void forceWindowsScaleableInTransaction(boolean force) {
1807 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1808 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1809 }
1810
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001811 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001812 }
1813
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001814 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001815 void removeImmediately() {
1816 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001817
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001818 if (mRemoved) {
1819 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001820 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1821 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001822 return;
1823 }
1824
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001825 mRemoved = true;
1826
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001827 mWillReplaceWindow = false;
1828 if (mReplacementWindow != null) {
1829 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1830 }
1831
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001832 final DisplayContent dc = getDisplayContent();
Robert Carr825581a2018-03-30 14:00:53 -07001833 if (isInputMethodTarget()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001834 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001835 }
1836
1837 final int type = mAttrs.type;
1838 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001839 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001840 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001841 if (mTapExcludeRegionHolder != null) {
1842 // If a tap exclude region container was initialized for this window, then it should've
1843 // also been registered in display.
1844 dc.mTapExcludeProvidingWindows.remove(this);
1845 }
Tiger Huang7c610aa2018-10-27 00:01:01 +08001846 dc.getDisplayPolicy().removeWindowLw(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001847
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001848 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001849
Craig Mautner96868332012-12-04 14:29:11 -08001850 mWinAnimator.destroyDeferredSurfaceLocked();
1851 mWinAnimator.destroySurfaceLocked();
Wale Ogunwale943002b2017-02-15 19:34:01 -08001852 mSession.windowRemovedLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001853 try {
1854 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1855 } catch (RuntimeException e) {
1856 // Ignore if it has already been removed (usually because
1857 // we are doing this as part of processing a death note.)
1858 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001859
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001860 mWmService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001861 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001862
Wale Ogunwale571771c2016-08-26 13:18:50 -07001863 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001864 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001865 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001866 removeIfPossible(false /*keepVisibleDeadWindow*/);
1867 }
1868
Wale Ogunwale571771c2016-08-26 13:18:50 -07001869 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001870 mWindowRemovalAllowed = true;
1871 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1872 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1873
1874 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1875 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1876 "Starting window removed " + this);
1877
Tiger Huang1e5b10a2018-07-30 20:19:51 +08001878 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && isFocused())
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001879 Slog.v(TAG_WM, "Remove " + this + " client="
1880 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1881 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1882 + Debug.getCallers(5));
1883
1884 final long origId = Binder.clearCallingIdentity();
1885
Peter Visontay3556a3b2017-11-01 17:23:17 +00001886 try {
1887 disposeInputChannel();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001888
Peter Visontay3556a3b2017-11-01 17:23:17 +00001889 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1890 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1891 + " mAnimatingExit=" + mAnimatingExit
1892 + " mRemoveOnExit=" + mRemoveOnExit
1893 + " mHasSurface=" + mHasSurface
1894 + " surfaceShowing=" + mWinAnimator.getShown()
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001895 + " animating=" + isAnimating()
Peter Visontay3556a3b2017-11-01 17:23:17 +00001896 + " app-animation="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001897 + (mAppToken != null ? mAppToken.isSelfAnimating() : "false")
Peter Visontay3556a3b2017-11-01 17:23:17 +00001898 + " mWillReplaceWindow=" + mWillReplaceWindow
1899 + " inPendingTransaction="
1900 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001901 + " mDisplayFrozen=" + mWmService.mDisplayFrozen
Peter Visontay3556a3b2017-11-01 17:23:17 +00001902 + " callers=" + Debug.getCallers(6));
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001903
Peter Visontay3556a3b2017-11-01 17:23:17 +00001904 // Visibility of the removed window. Will be used later to update orientation later on.
1905 boolean wasVisible = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001906
Peter Visontay3556a3b2017-11-01 17:23:17 +00001907 final int displayId = getDisplayId();
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001908
Peter Visontay3556a3b2017-11-01 17:23:17 +00001909 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1910 // window until the animation is done. If the display is frozen, just remove immediately,
1911 // since the animation wouldn't be seen.
1912 if (mHasSurface && mToken.okToAnimate()) {
1913 if (mWillReplaceWindow) {
1914 // This window is going to be replaced. We need to keep it around until the new one
1915 // gets added, then we will get rid of this one.
1916 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1917 "Preserving " + this + " until the new one is " + "added");
1918 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1919 // been removed. We probably need another flag to indicate that window removal
1920 // should be deffered vs. overloading the flag that says we are playing an exit
1921 // animation.
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001922 mAnimatingExit = true;
Peter Visontay3556a3b2017-11-01 17:23:17 +00001923 mReplacingRemoveRequested = true;
1924 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001925 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001926
Peter Visontay3556a3b2017-11-01 17:23:17 +00001927 // If we are not currently running the exit animation, we need to see about starting one
1928 wasVisible = isWinVisibleLw();
1929
1930 if (keepVisibleDeadWindow) {
1931 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1932 "Not removing " + this + " because app died while it's visible");
1933
1934 mAppDied = true;
1935 setDisplayLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001936 mWmService.mWindowPlacerLocked.performSurfacePlacement();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001937
1938 // Set up a replacement input channel since the app is now dead.
1939 // We need to catch tapping on the dead window to restart the app.
1940 openInputChannel(null);
Arthur Hung95b38a92018-07-20 18:56:12 +08001941 getDisplayContent().getInputMonitor().updateInputWindowsLw(true /*force*/);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001942 return;
1943 }
1944
1945 if (wasVisible) {
1946 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
1947
1948 // Try starting an animation.
1949 if (mWinAnimator.applyAnimationLocked(transit, false)) {
1950 mAnimatingExit = true;
Jorim Jaggif41e8822018-04-06 17:22:03 +02001951
1952 // mAnimatingExit affects canAffectSystemUiFlags(). Run layout such that
1953 // any change from that is performed immediately.
1954 setDisplayLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001955 mWmService.requestTraversal();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001956 }
Rhed Jao02655dc2018-10-30 20:44:52 +08001957 if (mWmService.mAccessibilityController != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001958 mWmService.mAccessibilityController.onWindowTransitionLocked(this, transit);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001959 }
1960 }
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001961 final boolean isAnimating = isAnimating()
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001962 && (mAppToken == null || !mAppToken.isWaitingForTransitionStart());
Peter Visontay3556a3b2017-11-01 17:23:17 +00001963 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
1964 && mAppToken.isLastWindow(this);
1965 // We delay the removal of a window if it has a showing surface that can be used to run
1966 // exit animation and it is marked as exiting.
1967 // Also, If isn't the an animating starting window that is the last window in the app.
1968 // We allow the removal of the non-animating starting window now as there is no
1969 // additional window or animation that will trigger its removal.
1970 if (mWinAnimator.getShown() && mAnimatingExit
1971 && (!lastWindowIsStartingWindow || isAnimating)) {
1972 // The exit animation is running or should run... wait for it!
1973 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1974 "Not removing " + this + " due to exit animation ");
1975 setupWindowForRemoveOnExit();
1976 if (mAppToken != null) {
1977 mAppToken.updateReportedVisibilityLocked();
1978 }
1979 return;
1980 }
1981 }
1982
1983 removeImmediately();
1984 // Removing a visible window will effect the computed orientation
1985 // So just update orientation if needed.
Riddle Hsu4e611772018-10-31 18:58:28 +08001986 if (wasVisible) {
1987 final DisplayContent displayContent = getDisplayContent();
1988 if (displayContent.updateOrientationFromAppTokens()) {
1989 displayContent.sendNewConfiguration();
1990 }
Peter Visontay3556a3b2017-11-01 17:23:17 +00001991 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001992 mWmService.updateFocusedWindowLocked(isFocused()
Tiger Huang8af6ba42018-06-07 19:24:09 +08001993 ? UPDATE_FOCUS_REMOVING_FOCUS
1994 : UPDATE_FOCUS_NORMAL,
1995 true /*updateInputWindows*/);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001996 } finally {
1997 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001998 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001999 }
2000
2001 private void setupWindowForRemoveOnExit() {
2002 mRemoveOnExit = true;
2003 setDisplayLayoutNeeded();
2004 // Request a focus update as this window's input channel is already gone. Otherwise
2005 // we could have no focused window in input manager.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002006 final boolean focusChanged = mWmService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002007 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002008 mWmService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002009 if (focusChanged) {
Arthur Hung95b38a92018-07-20 18:56:12 +08002010 getDisplayContent().getInputMonitor().updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002011 }
2012 }
2013
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08002014 void setHasSurface(boolean hasSurface) {
2015 mHasSurface = hasSurface;
2016 }
2017
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002018 boolean canBeImeTarget() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002019 if (mIsImWindow) {
2020 // IME windows can't be IME targets. IME targets are required to be below the IME
2021 // windows and that wouldn't be possible if the IME window is its own target...silly.
2022 return false;
2023 }
2024
Winson Chung3d0a74a2017-07-12 12:37:19 -07002025 final boolean windowsAreFocusable = mAppToken == null || mAppToken.windowsAreFocusable();
Winson Chungb1549342017-07-11 09:59:56 -07002026 if (!windowsAreFocusable) {
2027 // This window can't be an IME target if the app's windows should not be focusable.
2028 return false;
2029 }
2030
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002031 final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002032 final int type = mAttrs.type;
2033
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002034 // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are set or
2035 // both are cleared...and not a starting window.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002036 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
2037 && type != TYPE_APPLICATION_STARTING) {
2038 return false;
2039 }
2040
2041 if (DEBUG_INPUT_METHOD) {
2042 Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding());
2043 if (!isVisibleOrAdding()) {
2044 Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController
2045 + " relayoutCalled=" + mRelayoutCalled
2046 + " viewVis=" + mViewVisibility
2047 + " policyVis=" + mPolicyVisibility
2048 + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim
2049 + " parentHidden=" + isParentWindowHidden()
2050 + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
2051 if (mAppToken != null) {
2052 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + mAppToken.hiddenRequested);
2053 }
2054 }
2055 }
2056 return isVisibleOrAdding();
2057 }
2058
Chong Zhangacf11402015-11-04 16:23:10 -08002059 private final class DeadWindowEventReceiver extends InputEventReceiver {
2060 DeadWindowEventReceiver(InputChannel inputChannel) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002061 super(inputChannel, mWmService.mH.getLooper());
Chong Zhangacf11402015-11-04 16:23:10 -08002062 }
2063 @Override
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08002064 public void onInputEvent(InputEvent event) {
Chong Zhangacf11402015-11-04 16:23:10 -08002065 finishInputEvent(event, true);
2066 }
2067 }
2068 /**
2069 * Dummy event receiver for windows that died visible.
2070 */
2071 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2072
Chong Zhang112eb8c2015-11-02 11:17:00 -08002073 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002074 if (mInputChannel != null) {
2075 throw new IllegalStateException("Window already has an input channel.");
2076 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002077 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002078 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2079 mInputChannel = inputChannels[0];
2080 mClientChannel = inputChannels[1];
Robert Carreadae822018-10-11 19:07:03 -07002081 mInputWindowHandle.token = mClient.asBinder();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002082 if (outInputChannel != null) {
2083 mClientChannel.transferTo(outInputChannel);
2084 mClientChannel.dispose();
2085 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002086 } else {
2087 // If the window died visible, we setup a dummy input channel, so that taps
2088 // can still detected by input monitor channel, and we can relaunch the app.
2089 // Create dummy event receiver that simply reports all events as handled.
2090 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002091 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002092 mWmService.mInputManager.registerInputChannel(mInputChannel, mClient.asBinder());
Jeff Browncc4f7db2011-08-30 20:34:48 -07002093 }
2094
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002095 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002096 if (mDeadWindowEventReceiver != null) {
2097 mDeadWindowEventReceiver.dispose();
2098 mDeadWindowEventReceiver = null;
2099 }
2100
2101 // unregister server channel first otherwise it complains about broken channel
2102 if (mInputChannel != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002103 mWmService.mInputManager.unregisterInputChannel(mInputChannel);
Robert Carre0a353c2018-08-02 16:38:04 -07002104
Chong Zhangacf11402015-11-04 16:23:10 -08002105 mInputChannel.dispose();
2106 mInputChannel = null;
2107 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002108 if (mClientChannel != null) {
2109 mClientChannel.dispose();
2110 mClientChannel = null;
2111 }
Robert Carreadae822018-10-11 19:07:03 -07002112 mInputWindowHandle.token = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002113 }
2114
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002115 /** Returns true if the replacement window was removed. */
2116 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2117 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2118 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2119 removeReplacedWindow();
2120 return true;
2121 }
2122
2123 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002124 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002125 if (c.removeReplacedWindowIfNeeded(replacement)) {
2126 return true;
2127 }
2128 }
2129 return false;
2130 }
2131
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002132 private void removeReplacedWindow() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002133 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002134 mWillReplaceWindow = false;
2135 mAnimateReplacingWindow = false;
2136 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002137 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002138 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002139 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002140 }
2141 }
2142
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002143 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2144 boolean replacementSet = false;
2145
2146 if (mWillReplaceWindow && mReplacementWindow == null
2147 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2148
2149 mReplacementWindow = replacementCandidate;
2150 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2151 replacementSet = true;
2152 }
2153
2154 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002155 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002156 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2157 }
2158
2159 return replacementSet;
2160 }
2161
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002162 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002163 final DisplayContent dc = getDisplayContent();
2164 if (dc != null) {
2165 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002166 }
2167 }
2168
Chong Zhang5117e272016-05-03 12:47:34 -07002169 void applyAdjustForImeIfNeeded() {
2170 final Task task = getTask();
2171 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2172 task.mStack.applyAdjustForImeIfNeeded(task);
2173 }
2174 }
2175
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002176 @Override
2177 void switchUser() {
2178 super.switchUser();
2179 if (isHiddenFromUserLocked()) {
2180 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2181 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
2182 hideLw(false);
2183 }
2184 }
2185
Riddle Hsuff03df52018-12-05 21:43:02 +08002186 int getSurfaceTouchableRegion(Region region, int flags) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002187 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Riddle Hsub398da32019-01-21 21:48:16 +08002188 if (mAppToken != null && !mAppToken.getResolvedOverrideBounds().isEmpty()) {
2189 // There may have touchable letterboxes around the activity, so in order to let the
2190 // letterboxes are able to receive touch event and slip to activity, the activity with
2191 // compatibility bounds cannot occupy full screen touchable region.
2192 if (modal) {
2193 // A modal window uses the whole compatibility bounds.
2194 flags |= FLAG_NOT_TOUCH_MODAL;
2195 mTmpRect.set(mAppToken.getResolvedOverrideBounds());
Riddle Hsub398da32019-01-21 21:48:16 +08002196 } else {
2197 // Non-modal uses the application based frame.
2198 mTmpRect.set(mWindowFrames.mCompatFrame);
2199 }
2200 // The offset of compatibility bounds is applied to surface of {@link #AppWindowToken}
2201 // and frame, so it is unnecessary to translate twice in surface based coordinates.
2202 final int surfaceOffsetX = mAppToken.inSizeCompatMode()
2203 ? mAppToken.getBounds().left : 0;
2204 mTmpRect.offset(surfaceOffsetX - mWindowFrames.mFrame.left, -mWindowFrames.mFrame.top);
2205 region.set(mTmpRect);
2206 return flags;
2207 }
2208
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002209 if (modal && mAppToken != null) {
2210 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002211 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002212 // If this is a modal window we need to dismiss it if it's not full screen and the
2213 // touch happens outside of the frame that displays the content. This means we
2214 // need to intercept touches outside of that window. The dim layer user
2215 // associated with the window (task or stack) will give us the good bounds, as
2216 // they would be used to display the dim layer.
Robert Carrf59b8dd2017-10-02 18:58:36 -07002217 final Task task = getTask();
2218 if (task != null) {
2219 task.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002220 } else {
Robert Carrf59b8dd2017-10-02 18:58:36 -07002221 getStack().getDimBounds(mTmpRect);
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002222 }
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002223 if (inFreeformWindowingMode()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002224 // For freeform windows we the touch region to include the whole surface for the
2225 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002226 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2227 final int delta = WindowManagerService.dipToPixel(
2228 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2229 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002230 }
2231 region.set(mTmpRect);
Riddle Hsub5e960f2018-12-07 14:51:26 +08002232 cropRegionToStackBoundsIfNeeded(region);
Tiger Huang04dc4cc2019-01-17 18:41:41 +08002233 subtractTouchExcludeRegionIfNeeded(region);
2234 } else if (modal && mTapExcludeRegionHolder != null) {
2235 final Region touchExcludeRegion = Region.obtain();
2236 amendTapExcludeRegion(touchExcludeRegion);
2237 if (!touchExcludeRegion.isEmpty()) {
2238 // Remove touch modal because there are some areas that cannot be touched.
2239 flags |= FLAG_NOT_TOUCH_MODAL;
2240 // Give it a large touchable region at first because it was touch modal. The window
2241 // might be moved on the display, so the touchable region should be large enough to
2242 // ensure it covers the whole display, no matter where it is moved.
2243 getDisplayContent().getBounds(mTmpRect);
2244 final int dw = mTmpRect.width();
2245 final int dh = mTmpRect.height();
2246 region.set(-dw, -dh, dw + dw, dh + dh);
2247 // Subtract the area that cannot be touched.
2248 region.op(touchExcludeRegion, Region.Op.DIFFERENCE);
2249 }
2250 touchExcludeRegion.recycle();
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002251 } else {
2252 // Not modal or full screen modal
Riddle Hsub5e960f2018-12-07 14:51:26 +08002253 getTouchableRegion(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002254 }
Riddle Hsub5e960f2018-12-07 14:51:26 +08002255 // Translate to surface based coordinates.
2256 region.translate(-mWindowFrames.mFrame.left, -mWindowFrames.mFrame.top);
Robert Carra80ad042018-08-14 12:54:20 -07002257
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002258 return flags;
2259 }
2260
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002261 void checkPolicyVisibilityChange() {
2262 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2263 if (DEBUG_VISIBILITY) {
2264 Slog.v(TAG, "Policy visibility changing after anim in " +
2265 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2266 }
2267 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002268 if (!mPolicyVisibility) {
Jorim Jaggi2e05af22017-12-28 15:15:11 +01002269 mWinAnimator.hide("checkPolicyVisibilityChange");
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002270 if (isFocused()) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002271 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2272 "setAnimationLocked: setting mFocusMayChange true");
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002273 mWmService.mFocusMayChange = true;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002274 }
Tetsutoki Shiozawa64c5f0c2018-05-18 10:55:01 +09002275 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002276 // Window is no longer visible -- make sure if we were waiting
2277 // for it to be displayed before enabling the display, that
2278 // we allow the display to be enabled now.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002279 mWmService.enableScreenIfNeededLocked();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002280 }
2281 }
2282 }
2283
2284 void setRequestedSize(int requestedWidth, int requestedHeight) {
2285 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2286 mLayoutNeeded = true;
2287 mRequestedWidth = requestedWidth;
2288 mRequestedHeight = requestedHeight;
2289 }
2290 }
2291
Bryce Leef858b572017-06-29 14:03:33 -07002292 void prepareWindowToDisplayDuringRelayout(boolean wasVisible) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002293 // We need to turn on screen regardless of visibility.
chaviw40234662018-02-07 09:37:16 -08002294 boolean hasTurnScreenOnFlag = (mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0;
2295 boolean allowTheaterMode =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002296 mWmService.mAllowTheaterModeWakeFromLayout || Settings.Global.getInt(
2297 mWmService.mContext.getContentResolver(), Settings.Global.THEATER_MODE_ON, 0)
chaviw40234662018-02-07 09:37:16 -08002298 == 0;
2299 boolean canTurnScreenOn = mAppToken == null || mAppToken.canTurnScreenOn();
2300
2301 // The screen will turn on if the following conditions are met
2302 // 1. The window has the flag FLAG_TURN_SCREEN_ON
2303 // 2. The WMS allows theater mode.
2304 // 3. No AWT or the AWT allows the screen to be turned on. This should only be true once
2305 // per resume to prevent the screen getting getting turned on for each relayout. Set
2306 // canTurnScreenOn will be set to false so the window doesn't turn the screen on again
2307 // during this resume.
2308 // 4. When the screen is not interactive. This is because when the screen is already
2309 // interactive, the value may persist until the next animation, which could potentially
2310 // be occurring while turning off the screen. This would lead to the screen incorrectly
2311 // turning back on.
chaviw474093d2018-03-07 15:03:38 -08002312 if (hasTurnScreenOnFlag) {
2313 if (allowTheaterMode && canTurnScreenOn && !mPowerManagerWrapper.isInteractive()) {
2314 if (DEBUG_VISIBILITY || DEBUG_POWER) {
2315 Slog.v(TAG, "Relayout window turning screen on: " + this);
2316 }
2317 mPowerManagerWrapper.wakeUp(SystemClock.uptimeMillis(),
Michael Wrighte3001042019-02-05 00:13:14 +00002318 PowerManager.WAKE_REASON_APPLICATION, "android.server.wm:SCREEN_ON_FLAG");
chaviw40234662018-02-07 09:37:16 -08002319 }
chaviwb28de1f2018-03-02 10:42:36 -08002320
2321 if (mAppToken != null) {
2322 mAppToken.setCanTurnScreenOn(false);
2323 }
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002324 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002325
2326 // If we were already visible, skip rest of preparation.
2327 if (wasVisible) {
2328 if (DEBUG_VISIBILITY) Slog.v(TAG,
2329 "Already visible and does not turn on screen, skip preparing: " + this);
2330 return;
2331 }
2332
2333 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2334 == SOFT_INPUT_ADJUST_RESIZE) {
2335 mLayoutNeeded = true;
2336 }
2337
David Stevens9440dc82017-03-16 19:00:20 -07002338 if (isDrawnLw() && mToken.okToAnimate()) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002339 mWinAnimator.applyEnterAnimationLocked();
2340 }
Bryce Leef858b572017-06-29 14:03:33 -07002341 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002342
Yunfan Chen75157d72018-07-27 14:47:21 +09002343 private Configuration getProcessGlobalConfiguration() {
2344 // For child windows we want to use the pid for the parent window in case the the child
2345 // window was added from another process.
Yunfan Chen79b96062018-10-17 12:45:23 -07002346 final int pid = getParentWindow() != null ? getParentWindow().mSession.mPid : mSession.mPid;
Yunfan Chenc2ff6cf2018-12-04 16:56:21 -08002347 final Configuration processConfig =
2348 mWmService.mAtmService.getGlobalConfigurationForPid(pid);
2349 mTempConfiguration.setTo(processConfig == null
2350 ? mWmService.mRoot.getConfiguration() : processConfig);
Yunfan Chen75157d72018-07-27 14:47:21 +09002351 return mTempConfiguration;
2352 }
2353
Bryce Leef858b572017-06-29 14:03:33 -07002354 void getMergedConfiguration(MergedConfiguration outConfiguration) {
Yunfan Chen75157d72018-07-27 14:47:21 +09002355 final Configuration globalConfig = getProcessGlobalConfiguration();
Bryce Leef858b572017-06-29 14:03:33 -07002356 final Configuration overrideConfig = getMergedOverrideConfiguration();
2357 outConfiguration.setConfiguration(globalConfig, overrideConfig);
2358 }
2359
Bryce Lee2b17afd2017-09-21 10:38:20 -07002360 void setLastReportedMergedConfiguration(MergedConfiguration config) {
2361 mLastReportedConfiguration.setTo(config);
2362 }
2363
2364 void getLastReportedMergedConfiguration(MergedConfiguration config) {
2365 config.setTo(mLastReportedConfiguration);
2366 }
2367
2368 private Configuration getLastReportedConfiguration() {
2369 return mLastReportedConfiguration.getMergedConfiguration();
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002370 }
2371
2372 void adjustStartingWindowFlags() {
2373 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2374 && mAppToken.startingWindow != null) {
2375 // Special handling of starting window over the base
2376 // window of the app: propagate lock screen flags to it,
2377 // to provide the correct semantics while starting.
2378 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2379 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2380 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2381 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2382 }
2383 }
2384
2385 void setWindowScale(int requestedWidth, int requestedHeight) {
2386 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2387
2388 if (scaledWindow) {
2389 // requested{Width|Height} Surface's physical size
2390 // attrs.{width|height} Size on screen
2391 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2392 mHScale = (mAttrs.width != requestedWidth) ?
2393 (mAttrs.width / (float)requestedWidth) : 1.0f;
2394 mVScale = (mAttrs.height != requestedHeight) ?
2395 (mAttrs.height / (float)requestedHeight) : 1.0f;
2396 } else {
2397 mHScale = mVScale = 1;
2398 }
2399 }
2400
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002401 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002402 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002403 public void binderDied() {
2404 try {
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002405 boolean resetSplitScreenResizing = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002406 synchronized (mWmService.mGlobalLock) {
2407 final WindowState win = mWmService
2408 .windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002409 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002410 if (win != null) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002411 final DisplayContent dc = getDisplayContent();
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002412 if (win.mAppToken != null && win.mAppToken.findMainWindow() == win) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002413 mWmService.mTaskSnapshotController.onAppDied(win.mAppToken);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002414 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002415 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002416 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2417 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002418 // just in case they have the divider at an unstable position. Better
2419 // also reset drag resizing state, because the owner can't do it
2420 // anymore.
Wale Ogunwale61911492017-10-11 08:50:50 -07002421 final TaskStack stack =
Matthew Ng64e77cf2017-10-31 14:01:31 -07002422 dc.getSplitScreenPrimaryStackIgnoringVisibility();
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002423 if (stack != null) {
2424 stack.resetDockedStackToMiddle();
2425 }
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002426 resetSplitScreenResizing = true;
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002427 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002428 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002429 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002430 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002431 }
2432 }
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002433 if (resetSplitScreenResizing) {
2434 try {
2435 // Note: this calls into ActivityManager, so we must *not* hold the window
2436 // manager lock while calling this.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002437 mWmService.mActivityTaskManager.setSplitScreenResizing(false);
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002438 } catch (RemoteException e) {
2439 // Local call, shouldn't return RemoteException.
2440 throw e.rethrowAsRuntimeException();
2441 }
2442 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002443 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002444 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002445 }
2446 }
2447 }
2448
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002449 /**
2450 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2451 * because we want to preserve its location on screen to be re-activated later when the user
2452 * interacts with it.
2453 */
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002454 private boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwale89973222017-04-23 18:39:45 -07002455 if (!isWinVisibleLw() || mAppToken == null || mAppToken.isClientHidden()) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002456 // Not a visible app window or the app isn't dead.
2457 return false;
2458 }
2459
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002460 if (mAttrs.token != mClient.asBinder()) {
2461 // The window was add by a client using another client's app token. We don't want to
2462 // keep the dead window around for this case since this is meant for 'real' apps.
2463 return false;
2464 }
2465
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002466 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2467 // We don't keep starting windows since they were added by the window manager before
2468 // the app even launched.
2469 return false;
2470 }
2471
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002472 return getWindowConfiguration().keepVisibleDeadAppWindowOnScreen();
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002473 }
2474
Tiger Huang513d5e12018-07-16 21:49:50 +08002475 @Override
2476 public boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002477 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002478 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002479 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002480 && (mAppToken == null || mAppToken.windowsAreFocusable())
Robert Carrebdf8582018-09-04 14:50:15 -07002481 && !cantReceiveTouchInput();
Matthew Nge15352e2016-12-20 15:36:29 -08002482 }
2483
lumark31e4f8e2019-01-10 20:48:18 +08002484 @Override
2485 public boolean canShowWhenLocked() {
2486 final boolean showBecauseOfActivity =
2487 mAppToken != null && mAppToken.mActivityRecord.canShowWhenLocked();
2488 final boolean showBecauseOfWindow = (getAttrs().flags & FLAG_SHOW_WHEN_LOCKED) != 0;
2489 return showBecauseOfActivity || showBecauseOfWindow;
2490 }
2491
Robert Carrebdf8582018-09-04 14:50:15 -07002492 /** @return false if this window desires touch events. */
2493 boolean cantReceiveTouchInput() {
Bryce Lee6d410262017-02-28 15:30:17 -08002494 return mAppToken != null && mAppToken.getTask() != null
Arthur Hung0b650ba2019-01-30 19:23:53 +08002495 && (mAppToken.getTask().mStack.shouldIgnoreInput() || mAppToken.hiddenRequested);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002496 }
2497
Craig Mautner749a7bb2012-04-02 13:49:53 -07002498 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002499 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002500 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002501 }
2502
Craig Mautner749a7bb2012-04-02 13:49:53 -07002503 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002504 public boolean showLw(boolean doAnimation) {
2505 return showLw(doAnimation, true);
2506 }
2507
2508 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002509 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002510 return false;
2511 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002512 if (!mAppOpVisibility) {
2513 // Being hidden due to app op request.
2514 return false;
2515 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002516 if (mPermanentlyHidden) {
2517 // Permanently hidden until the app exists as apps aren't prepared
2518 // to handle their windows being removed from under them.
2519 return false;
2520 }
Suprabh Shukla69c71422018-04-02 18:39:01 -07002521 if (mHiddenWhileSuspended) {
2522 // Being hidden due to owner package being suspended.
2523 return false;
2524 }
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002525 if (mForceHideNonSystemOverlayWindow) {
2526 // This is an alert window that is currently force hidden.
2527 return false;
2528 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002529 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002530 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002531 return false;
2532 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002533 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002534 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002535 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02002536 + mPolicyVisibility + " animating=" + isAnimating());
David Stevens9440dc82017-03-16 19:00:20 -07002537 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002538 doAnimation = false;
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02002539 } else if (mPolicyVisibility && !isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002540 // Check for the case where we are currently visible and
2541 // not animating; we do not want to do animation at such a
2542 // point to become visible when we already are.
2543 doAnimation = false;
2544 }
2545 }
2546 mPolicyVisibility = true;
2547 mPolicyVisibilityAfterAnim = true;
2548 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002549 mWinAnimator.applyAnimationLocked(TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002550 }
2551 if (requestAnim) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002552 mWmService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002553 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002554 if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002555 mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002556 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002557 return true;
2558 }
2559
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002560 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002561 public boolean hideLw(boolean doAnimation) {
2562 return hideLw(doAnimation, true);
2563 }
2564
2565 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2566 if (doAnimation) {
David Stevens9440dc82017-03-16 19:00:20 -07002567 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002568 doAnimation = false;
2569 }
2570 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002571 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002572 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002573 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002574 return false;
2575 }
2576 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002577 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02002578 if (!isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002579 doAnimation = false;
2580 }
2581 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002582 mPolicyVisibilityAfterAnim = false;
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002583 final boolean isFocused = isFocused();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002584 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002585 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002586 mPolicyVisibility = false;
2587 // Window is no longer visible -- make sure if we were waiting
2588 // for it to be displayed before enabling the display, that
2589 // we allow the display to be enabled now.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002590 mWmService.enableScreenIfNeededLocked();
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002591 if (isFocused) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002592 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002593 "WindowState.hideLw: setting mFocusMayChange true");
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002594 mWmService.mFocusMayChange = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002595 }
2596 }
2597 if (requestAnim) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002598 mWmService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002599 }
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002600 if (isFocused) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002601 mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002602 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002603 return true;
2604 }
2605
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002606 void setForceHideNonSystemOverlayWindowIfNeeded(boolean forceHide) {
2607 if (mOwnerCanAddInternalSystemWindow
2608 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2609 return;
2610 }
2611 if (mForceHideNonSystemOverlayWindow == forceHide) {
2612 return;
2613 }
2614 mForceHideNonSystemOverlayWindow = forceHide;
2615 if (forceHide) {
2616 hideLw(true /* doAnimation */, true /* requestAnim */);
2617 } else {
2618 showLw(true /* doAnimation */, true /* requestAnim */);
2619 }
2620 }
2621
Suprabh Shukla69c71422018-04-02 18:39:01 -07002622 void setHiddenWhileSuspended(boolean hide) {
2623 if (mOwnerCanAddInternalSystemWindow
2624 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2625 return;
2626 }
2627 if (mHiddenWhileSuspended == hide) {
2628 return;
2629 }
2630 mHiddenWhileSuspended = hide;
2631 if (hide) {
2632 hideLw(true, true);
2633 } else {
2634 showLw(true, true);
2635 }
2636 }
2637
Svet Ganovf7b47252018-02-26 11:11:27 -08002638 private void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002639 if (mAppOpVisibility != state) {
2640 mAppOpVisibility = state;
2641 if (state) {
2642 // If the policy visibility had last been to hide, then this
2643 // will incorrectly show at this point since we lost that
2644 // information. Not a big deal -- for the windows that have app
2645 // ops modifies they should only be hidden by policy due to the
2646 // lock screen, and the user won't be changing this if locked.
2647 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002648 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002649 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002650 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002651 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002652 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002653 }
2654
Svet Ganovf7b47252018-02-26 11:11:27 -08002655 void initAppOpsState() {
2656 if (mAppOp == OP_NONE || !mAppOpVisibility) {
2657 return;
2658 }
2659 // If the app op was MODE_DEFAULT we would have checked the permission
2660 // and add the window only if the permission was granted. Therefore, if
2661 // the mode is MODE_DEFAULT we want the op to succeed as the window is
2662 // shown.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002663 final int mode = mWmService.mAppOps.startOpNoThrow(mAppOp,
Svet Ganovf7b47252018-02-26 11:11:27 -08002664 getOwningUid(), getOwningPackage(), true);
2665 if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) {
2666 setAppOpVisibilityLw(false);
2667 }
2668 }
2669
2670 void resetAppOpsState() {
2671 if (mAppOp != OP_NONE && mAppOpVisibility) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002672 mWmService.mAppOps.finishOp(mAppOp, getOwningUid(), getOwningPackage());
Svet Ganovf7b47252018-02-26 11:11:27 -08002673 }
2674 }
2675
2676 void updateAppOpsState() {
2677 if (mAppOp == OP_NONE) {
2678 return;
2679 }
2680 final int uid = getOwningUid();
2681 final String packageName = getOwningPackage();
2682 if (mAppOpVisibility) {
2683 // There is a race between the check and the finish calls but this is fine
2684 // as this would mean we will get another change callback and will reconcile.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002685 int mode = mWmService.mAppOps.checkOpNoThrow(mAppOp, uid, packageName);
Svet Ganovf7b47252018-02-26 11:11:27 -08002686 if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002687 mWmService.mAppOps.finishOp(mAppOp, uid, packageName);
Svet Ganovf7b47252018-02-26 11:11:27 -08002688 setAppOpVisibilityLw(false);
2689 }
2690 } else {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002691 final int mode = mWmService.mAppOps.startOpNoThrow(mAppOp, uid, packageName, true);
Svet Ganovf7b47252018-02-26 11:11:27 -08002692 if (mode == MODE_ALLOWED || mode == MODE_DEFAULT) {
2693 setAppOpVisibilityLw(true);
2694 }
2695 }
2696 }
2697
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002698 public void hidePermanentlyLw() {
2699 if (!mPermanentlyHidden) {
2700 mPermanentlyHidden = true;
2701 hideLw(true, true);
2702 }
2703 }
2704
Jeff Brownc2932a12014-11-20 18:04:05 -08002705 public void pokeDrawLockLw(long timeout) {
2706 if (isVisibleOrAdding()) {
2707 if (mDrawLock == null) {
2708 // We want the tag name to be somewhat stable so that it is easier to correlate
2709 // in wake lock statistics. So in particular, we don't want to include the
2710 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002711 final CharSequence tag = getWindowTag();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002712 mDrawLock = mWmService.mPowerManager.newWakeLock(DRAW_WAKE_LOCK, "Window:" + tag);
Jeff Brownc2932a12014-11-20 18:04:05 -08002713 mDrawLock.setReferenceCounted(false);
2714 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2715 }
2716 // Each call to acquire resets the timeout.
2717 if (DEBUG_POWER) {
2718 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2719 + mAttrs.packageName);
2720 }
2721 mDrawLock.acquire(timeout);
2722 } else if (DEBUG_POWER) {
2723 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2724 + "owned by " + mAttrs.packageName);
2725 }
2726 }
2727
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002728 @Override
2729 public boolean isAlive() {
2730 return mClient.asBinder().isBinderAlive();
2731 }
2732
Craig Mautnera987d432012-10-11 14:07:58 -07002733 boolean isClosing() {
chaviw4ad54912018-05-30 11:05:44 -07002734 return mAnimatingExit || (mAppToken != null && mAppToken.isClosingOrEnteringPip());
Craig Mautnera987d432012-10-11 14:07:58 -07002735 }
2736
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002737 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2738 animators.add(mWinAnimator);
2739
2740 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002741 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002742 c.addWinAnimatorToList(animators);
2743 }
2744 }
2745
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002746 void sendAppVisibilityToClients() {
2747 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002748
Wale Ogunwale89973222017-04-23 18:39:45 -07002749 final boolean clientHidden = mAppToken.isClientHidden();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002750 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2751 // Don't hide the starting window.
2752 return;
2753 }
2754
Wale Ogunwale89973222017-04-23 18:39:45 -07002755 if (clientHidden) {
2756 // Once we are notifying the client that it's visibility has changed, we need to prevent
2757 // it from destroying child surfaces until the animation has finished. We do this by
2758 // detaching any surface control the client added from the client.
2759 for (int i = mChildren.size() - 1; i >= 0; --i) {
2760 final WindowState c = mChildren.get(i);
2761 c.mWinAnimator.detachChildren();
2762 }
2763
2764 mWinAnimator.detachChildren();
2765 }
2766
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002767 try {
2768 if (DEBUG_VISIBILITY) Slog.v(TAG,
2769 "Setting visibility of " + this + ": " + (!clientHidden));
2770 mClient.dispatchAppVisibility(!clientHidden);
2771 } catch (RemoteException e) {
2772 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002773 }
2774
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002775 void onStartFreezingScreen() {
2776 mAppFreezing = true;
2777 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002778 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002779 c.onStartFreezingScreen();
2780 }
2781 }
2782
2783 boolean onStopFreezingScreen() {
2784 boolean unfrozeWindows = false;
2785 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002786 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002787 unfrozeWindows |= c.onStopFreezingScreen();
2788 }
2789
2790 if (!mAppFreezing) {
2791 return unfrozeWindows;
2792 }
2793
Wale Ogunwale953171d2016-09-30 09:17:30 -07002794 mAppFreezing = false;
2795
Bryce Lee8c3cf382017-07-06 19:47:10 -07002796 if (mHasSurface && !getOrientationChanging()
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002797 && mWmService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002798 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
Bryce Lee8c3cf382017-07-06 19:47:10 -07002799 setOrientationChanging(true);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002800 mWmService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002801 }
2802 mLastFreezeDuration = 0;
2803 setDisplayLayoutNeeded();
2804 return true;
2805 }
2806
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002807 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2808 boolean destroyedSomething = false;
Jorim Jaggi59f3e922018-01-05 15:40:32 +01002809
2810 // Copying to a different list as multiple children can be removed.
2811 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
2812 for (int i = childWindows.size() - 1; i >= 0; --i) {
2813 final WindowState c = childWindows.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002814 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2815 }
2816
Robert Carrdb2f6e62017-03-01 20:17:58 -08002817 if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) {
2818 return destroyedSomething;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002819 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08002820
2821 if (appStopped || mWindowRemovalAllowed) {
2822 mWinAnimator.destroyPreservedSurfaceLocked();
2823 }
2824
2825 if (mDestroying) {
2826 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2827 + " destroySurfaces: appStopped=" + appStopped
2828 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2829 + " win.mRemoveOnExit=" + mRemoveOnExit);
2830 if (!cleanupOnResume || mRemoveOnExit) {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002831 destroySurfaceUnchecked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08002832 }
2833 if (mRemoveOnExit) {
2834 removeImmediately();
2835 }
2836 if (cleanupOnResume) {
2837 requestUpdateWallpaperIfNeeded();
2838 }
2839 mDestroying = false;
2840 destroyedSomething = true;
2841 }
2842
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002843 return destroyedSomething;
2844 }
Chris Craik3131bde2016-05-06 13:39:08 -07002845
Robert Carr89a28ab2017-04-24 15:33:11 -07002846 // Destroy or save the application surface without checking
2847 // various indicators of whether the client has released the surface.
2848 // This is in general unsafe, and most callers should use {@link #destroySurface}
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002849 void destroySurfaceUnchecked() {
2850 mWinAnimator.destroySurfaceLocked();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002851
Chong Zhang92147042016-05-09 12:47:11 -07002852 // Clear animating flags now, since the surface is now gone. (Note this is true even
2853 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2854 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002855 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002856
Craig Mautner69b08182012-09-05 13:07:13 -07002857 @Override
2858 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002859 final DisplayContent displayContent = getDisplayContent();
2860 if (displayContent == null) {
2861 // Only a window that was on a non-default display can be detached from it.
2862 return false;
2863 }
Winson Chung47a3e652014-05-21 16:03:42 -07002864 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002865 }
2866
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002867 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07002868 mShowToOwnerOnly = showToOwnerOnly;
2869 }
2870
Wale Ogunwaleea92d972016-12-08 07:33:13 -08002871 private boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002872 // Child windows are evaluated based on their parent window.
2873 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002874 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale72919d22016-12-08 18:58:50 -08002875 && win.mAppToken != null && win.mAppToken.mShowForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002876
2877 // All window frames that are fullscreen extend above status bar, but some don't extend
2878 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2879 // bottom right.
chaviw492139a2018-07-16 16:07:35 -07002880 if (win.getFrameLw().left <= win.getDisplayFrameLw().left
2881 && win.getFrameLw().top <= win.getDisplayFrameLw().top
2882 && win.getFrameLw().right >= win.getStableFrameLw().right
2883 && win.getFrameLw().bottom >= win.getStableFrameLw().bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002884 // Is a fullscreen window, like the clock alarm. Show to everyone.
2885 return false;
2886 }
2887 }
2888
Craig Mautner341220f2012-10-16 15:20:09 -07002889 return win.mShowToOwnerOnly
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002890 && !mWmService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002891 }
2892
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002893 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2894 outRegion.set(
2895 frame.left + inset.left, frame.top + inset.top,
2896 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002897 }
2898
Riddle Hsuff03df52018-12-05 21:43:02 +08002899 /** Get the touchable region in global coordinates. */
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002900 void getTouchableRegion(Region outRegion) {
chaviw492139a2018-07-16 16:07:35 -07002901 final Rect frame = mWindowFrames.mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002902 switch (mTouchableInsets) {
2903 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002904 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002905 outRegion.set(frame);
2906 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002907 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002908 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002909 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002910 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002911 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002912 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002913 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002914 outRegion.set(mGivenTouchableRegion);
Riddle Hsub5e960f2018-12-07 14:51:26 +08002915 outRegion.translate(frame.left, frame.top);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002916 break;
2917 }
2918 }
Vishnu Nairb9246322018-12-06 13:54:02 -08002919 cropRegionToStackBoundsIfNeeded(outRegion);
Tiger Huang04dc4cc2019-01-17 18:41:41 +08002920 subtractTouchExcludeRegionIfNeeded(outRegion);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002921 }
2922
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002923 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002924 final Task task = getTask();
2925 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002926 return;
2927 }
2928
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002929 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002930 if (stack == null) {
2931 return;
2932 }
2933
2934 stack.getDimBounds(mTmpRect);
2935 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002936 }
2937
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002938 /**
Tiger Huang04dc4cc2019-01-17 18:41:41 +08002939 * If this window has areas that cannot be touched, we subtract those areas from its touchable
2940 * region.
2941 */
2942 private void subtractTouchExcludeRegionIfNeeded(Region touchableRegion) {
2943 if (mTapExcludeRegionHolder == null) {
2944 return;
2945 }
2946 final Region touchExcludeRegion = Region.obtain();
2947 amendTapExcludeRegion(touchExcludeRegion);
2948 if (!touchExcludeRegion.isEmpty()) {
2949 touchableRegion.op(touchExcludeRegion, Region.Op.DIFFERENCE);
2950 }
2951 touchExcludeRegion.recycle();
2952 }
2953
2954 /**
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002955 * Report a focus change. Must be called with no locks held, and consistently
2956 * from the same serialized thread (such as dispatched from a handler).
2957 */
Tiger Huang51c5a1d2018-12-11 20:24:51 +08002958 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002959 try {
Tiger Huang51c5a1d2018-12-11 20:24:51 +08002960 mClient.windowFocusChanged(focused, inTouchMode);
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002961 } catch (RemoteException e) {
2962 }
Tiger Huang51c5a1d2018-12-11 20:24:51 +08002963 if (mFocusCallbacks != null) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002964 final int N = mFocusCallbacks.beginBroadcast();
2965 for (int i=0; i<N; i++) {
2966 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2967 try {
2968 if (focused) {
2969 obs.focusGained(mWindowId.asBinder());
2970 } else {
2971 obs.focusLost(mWindowId.asBinder());
2972 }
2973 } catch (RemoteException e) {
2974 }
2975 }
2976 mFocusCallbacks.finishBroadcast();
2977 }
2978 }
2979
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002980 @Override
2981 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002982 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002983 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002984 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002985
Yunfan Chen75157d72018-07-27 14:47:21 +09002986 // We use the process config this window is associated with as the based global config since
2987 // the process can override it config, but isn't part of the window hierarchy.
2988 final Configuration config = getProcessGlobalConfiguration();
2989 config.updateFrom(getMergedOverrideConfiguration());
2990 return config;
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002991 }
2992
Craig Mautnerdf88d732014-01-27 09:21:32 -08002993 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002994 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08002995 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002996 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
chaviw9c81e632018-07-31 11:17:52 -07002997 + ": " + mWindowFrames.mCompatFrame);
Bryce Leef858b572017-06-29 14:03:33 -07002998 final MergedConfiguration mergedConfiguration =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002999 new MergedConfiguration(mWmService.mRoot.getConfiguration(),
Bryce Leef858b572017-06-29 14:03:33 -07003000 getMergedOverrideConfiguration());
3001
Bryce Lee2b17afd2017-09-21 10:38:20 -07003002 setLastReportedMergedConfiguration(mergedConfiguration);
Bryce Leef858b572017-06-29 14:03:33 -07003003
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003004 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08003005 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
3006
Riddle Hsub398da32019-01-21 21:48:16 +08003007 final Rect frame = mWindowFrames.mCompatFrame;
chaviw9c81e632018-07-31 11:17:52 -07003008 final Rect overscanInsets = mWindowFrames.mLastOverscanInsets;
3009 final Rect contentInsets = mWindowFrames.mLastContentInsets;
3010 final Rect visibleInsets = mWindowFrames.mLastVisibleInsets;
3011 final Rect stableInsets = mWindowFrames.mLastStableInsets;
3012 final Rect outsets = mWindowFrames.mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07003013 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003014 final boolean reportOrientation = mReportOrientationChanged;
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003015 final int displayId = getDisplayId();
chaviwcdba9a42018-07-19 11:36:42 -07003016 final DisplayCutout displayCutout = getWmDisplayCutout().getDisplayCutout();
Chet Haase8eb48d22014-09-24 07:31:29 -07003017 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
3018 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08003019 // To prevent deadlock simulate one-way call if win.mClient is a local object.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003020 mWmService.mH.post(new Runnable() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08003021 @Override
3022 public void run() {
3023 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003024 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003025 stableInsets, outsets, reportDraw, mergedConfiguration,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003026 reportOrientation, displayId, displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003027 } catch (RemoteException e) {
3028 // Not a remote call, RemoteException won't be raised.
3029 }
3030 }
3031 });
3032 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003033 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003034 outsets, reportDraw, mergedConfiguration, reportOrientation, displayId,
3035 displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003036 }
Svetoslav4604abc2014-06-10 18:59:30 -07003037
3038 //TODO (multidisplay): Accessibility supported only for the default display.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003039 if (mWmService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
3040 mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07003041 }
3042
chaviw9c81e632018-07-31 11:17:52 -07003043 mWindowFrames.resetInsetsChanged();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003044 mWinAnimator.mSurfaceResized = false;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003045 mReportOrientationChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003046 } catch (RemoteException e) {
Bryce Lee8c3cf382017-07-06 19:47:10 -07003047 setOrientationChanging(false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003048 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003049 - mWmService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08003050 // We are assuming the hosting process is dead or in a zombie state.
3051 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
3052 + ", removing this window.");
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003053 mWmService.mPendingRemove.add(this);
3054 mWmService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003055 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003056 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003057 }
3058
Jorim Jaggif96c90a2018-09-26 16:55:15 +02003059 /**
3060 * Called when the insets state changed.
3061 */
3062 void notifyInsetsChanged() {
3063 try {
3064 mClient.insetsChanged(
3065 getDisplayContent().getInsetsStateController().getInsetsForDispatch(this));
3066 } catch (RemoteException e) {
3067 Slog.w(TAG, "Failed to deliver inset state change", e);
3068 }
3069 }
3070
Jorim Jaggib6030952018-10-23 18:31:52 +02003071 void notifyInsetsControlChanged() {
3072 final InsetsStateController stateController =
3073 getDisplayContent().getInsetsStateController();
3074 try {
3075 mClient.insetsControlChanged(stateController.getInsetsForDispatch(this),
3076 stateController.getControlsForDispatch(this));
3077 } catch (RemoteException e) {
3078 Slog.w(TAG, "Failed to deliver inset state change", e);
3079 }
3080 }
3081
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003082 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08003083 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
3084 // start even if we haven't received the relayout window, so that the client requests
3085 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
3086 // until the window to small size, otherwise the multithread renderer will shift last
3087 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
3088 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003089 boolean resizing = isDragResizing() || isDragResizeChanged();
Wale Ogunwale3382ab12017-07-27 08:55:03 -07003090 if (getWindowConfiguration().useWindowFrameForBackdrop() || !resizing) {
Garfield Tanfbd8ea62018-10-16 17:09:49 -07003091 // Surface position is now inherited from parent, and BackdropFrameRenderer uses
3092 // backdrop frame to position content. Thus we just keep the size of backdrop frame, and
3093 // remove the offset to avoid double offset from display origin.
3094 mTmpRect.set(frame);
3095 mTmpRect.offsetTo(0, 0);
3096 return mTmpRect;
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003097 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07003098 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003099 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003100 return mTmpRect;
3101 }
3102
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003103 private int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003104 final TaskStack stack = getStack();
3105 if (stack == null) {
3106 return INVALID_STACK_ID;
3107 }
3108 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003109 }
3110
3111 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
3112 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003113 MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId,
3114 DisplayCutout displayCutout)
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003115 throws RemoteException {
Robert Carr09286c92018-02-15 13:52:31 -08003116 final boolean forceRelayout = isDragResizeChanged() || reportOrientation;
Chong Zhangedaf3052016-04-22 15:04:31 -07003117
Jorim Jaggidc249c42015-12-15 14:57:31 -08003118 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003119 reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout,
Tiger Huang7c610aa2018-10-27 00:01:01 +08003120 getDisplayContent().getDisplayPolicy().isNavBarForcedShownLw(this), displayId,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003121 new DisplayCutout.ParcelableWrapper(displayCutout));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003122 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003123 }
3124
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003125 public void registerFocusObserver(IWindowFocusObserver observer) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003126 synchronized (mWmService.mGlobalLock) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003127 if (mFocusCallbacks == null) {
3128 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
3129 }
3130 mFocusCallbacks.register(observer);
3131 }
3132 }
3133
3134 public void unregisterFocusObserver(IWindowFocusObserver observer) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003135 synchronized (mWmService.mGlobalLock) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003136 if (mFocusCallbacks != null) {
3137 mFocusCallbacks.unregister(observer);
3138 }
3139 }
3140 }
3141
Tiger Huang1e5b10a2018-07-30 20:19:51 +08003142 boolean isFocused() {
3143 return getDisplayContent().mCurrentFocus == this;
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003144 }
3145
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003146
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003147 /** Is this window in a container that takes up the entire screen space? */
Evan Rosky4fb1e912019-03-06 13:54:43 -08003148 private boolean inAppWindowThatMatchesParentBounds() {
3149 return mAppToken == null || (mAppToken.matchParentBounds() && !inMultiWindowMode());
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003150 }
3151
Evan Rosky4fb1e912019-03-06 13:54:43 -08003152 /** @return true when the window is in fullscreen mode, but has non-fullscreen bounds set, or
3153 * is transitioning into/out-of fullscreen. */
Andrii Kulian283acd22017-08-03 04:03:51 -07003154 boolean isLetterboxedAppWindow() {
Evan Rosky4fb1e912019-03-06 13:54:43 -08003155 return !inMultiWindowMode() && !matchesDisplayBounds()
Adrian Roos865c70f2018-01-10 17:32:27 +01003156 || isLetterboxedForDisplayCutoutLw();
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003157 }
3158
Adrian Roos865c70f2018-01-10 17:32:27 +01003159 @Override
3160 public boolean isLetterboxedForDisplayCutoutLw() {
3161 if (mAppToken == null) {
3162 // Only windows with an AppWindowToken are letterboxed.
3163 return false;
3164 }
chaviwcdba9a42018-07-19 11:36:42 -07003165 if (!mWindowFrames.parentFrameWasClippedByDisplayCutout()) {
Adrian Roos5ed644f2018-03-19 17:01:05 +01003166 // Cutout didn't make a difference, no letterbox
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003167 return false;
3168 }
Adrian Roosfa02da62018-01-15 16:01:18 +01003169 if (mAttrs.layoutInDisplayCutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003170 // Layout in cutout, no letterbox.
3171 return false;
3172 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003173 if (!mAttrs.isFullscreen()) {
3174 // Not filling the parent frame, no letterbox
3175 return false;
Adrian Roosfa02da62018-01-15 16:01:18 +01003176 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003177 // Otherwise we need a letterbox if the layout was smaller than the app window token allowed
3178 // it to be.
3179 return !frameCoversEntireAppTokenBounds();
3180 }
3181
3182 /**
3183 * @return true if this window covers the entire bounds of its app window token
3184 * @throws NullPointerException if there is no app window token for this window
3185 */
3186 private boolean frameCoversEntireAppTokenBounds() {
3187 mTmpRect.set(mAppToken.getBounds());
chaviw492139a2018-07-16 16:07:35 -07003188 mTmpRect.intersectUnchecked(mWindowFrames.mFrame);
Adrian Roos5ed644f2018-03-19 17:01:05 +01003189 return mAppToken.getBounds().equals(mTmpRect);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003190 }
3191
Adrian Roos23df3a32018-03-15 15:41:13 +01003192 @Override
3193 public boolean isLetterboxedOverlappingWith(Rect rect) {
3194 return mAppToken != null && mAppToken.isLetterboxOverlappingWith(rect);
3195 }
3196
Chong Zhang3005e752015-09-18 18:46:28 -07003197 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003198 return mDragResizing != computeDragResizing();
3199 }
3200
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003201 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003202 void setWaitingForDrawnIfResizingChanged() {
3203 if (isDragResizeChanged()) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003204 mWmService.mWaitingForDrawn.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003205 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003206 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003207 }
3208
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003209 /**
3210 * @return Whether we reported a drag resize change to the application or not already.
3211 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003212 private boolean isDragResizingChangeReported() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003213 return mDragResizingChangeReported;
3214 }
3215
3216 /**
3217 * Resets the state whether we reported a drag resize change to the app.
3218 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003219 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003220 void resetDragResizingChangeReported() {
3221 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003222 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003223 }
3224
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003225 int getResizeMode() {
3226 return mResizeMode;
3227 }
3228
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003229 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003230 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003231 if (task == null) {
3232 return false;
3233 }
Tomasz Mikolajewskiaf20b8d2017-11-20 16:11:33 +09003234 if (!inSplitScreenWindowingMode() && !inFreeformWindowingMode()) {
Winson Chung2af04b32017-01-24 16:21:13 -08003235 return false;
3236 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003237 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003238 // Floating windows never enter drag resize mode.
3239 return false;
3240 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003241 if (task.isDragResizing()) {
3242 return true;
3243 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003244
3245 // If the bounds are currently frozen, it means that the layout size that the app sees
3246 // and the bounds we clip this window to might be different. In order to avoid holes, we
3247 // simulate that we are still resizing so the app fills the hole with the resizing
3248 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003249 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003250 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003251 !task.inFreeformWindowingMode() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003252
Chong Zhang3005e752015-09-18 18:46:28 -07003253 }
3254
3255 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003256 final boolean resizing = computeDragResizing();
3257 if (resizing == mDragResizing) {
3258 return;
3259 }
3260 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003261 final Task task = getTask();
3262 if (task != null && task.isDragResizing()) {
3263 mResizeMode = task.getDragResizeMode();
3264 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003265 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003266 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3267 : DRAG_RESIZE_MODE_FREEFORM;
3268 }
Chong Zhang3005e752015-09-18 18:46:28 -07003269 }
3270
3271 boolean isDragResizing() {
3272 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003273 }
3274
Robert Carr2487ce72016-04-07 15:18:45 -07003275 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003276 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3277 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003278 }
3279
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07003280 @CallSuper
3281 @Override
Nataniel Borges023ecb52019-01-16 14:15:43 -08003282 public void writeToProto(ProtoOutputStream proto, long fieldId,
3283 @WindowTraceLogLevel int logLevel) {
3284 boolean isVisible = isVisible();
3285 if (logLevel == WindowTraceLogLevel.CRITICAL && !isVisible) {
3286 return;
3287 }
3288
Steven Timotiusaf03df62017-07-18 16:56:43 -07003289 final long token = proto.start(fieldId);
Nataniel Borges023ecb52019-01-16 14:15:43 -08003290 super.writeToProto(proto, WINDOW_CONTAINER, logLevel);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003291 writeIdentifierToProto(proto, IDENTIFIER);
3292 proto.write(DISPLAY_ID, getDisplayId());
3293 proto.write(STACK_ID, getStackId());
3294 mAttrs.writeToProto(proto, ATTRIBUTES);
3295 mGivenContentInsets.writeToProto(proto, GIVEN_CONTENT_INSETS);
chaviw553b0212018-07-12 13:37:01 -07003296 mWindowFrames.writeToProto(proto, WINDOW_FRAMES);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003297 mAttrs.surfaceInsets.writeToProto(proto, SURFACE_INSETS);
Jorim Jaggi45be1c4c2017-12-15 18:44:43 +01003298 mSurfacePosition.writeToProto(proto, SURFACE_POSITION);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003299 mWinAnimator.writeToProto(proto, ANIMATOR);
3300 proto.write(ANIMATING_EXIT, mAnimatingExit);
3301 for (int i = 0; i < mChildren.size(); i++) {
Nataniel Borges023ecb52019-01-16 14:15:43 -08003302 mChildren.get(i).writeToProto(proto, CHILD_WINDOWS, logLevel);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003303 }
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003304 proto.write(REQUESTED_WIDTH, mRequestedWidth);
3305 proto.write(REQUESTED_HEIGHT, mRequestedHeight);
3306 proto.write(VIEW_VISIBILITY, mViewVisibility);
3307 proto.write(SYSTEM_UI_VISIBILITY, mSystemUiVisibility);
3308 proto.write(HAS_SURFACE, mHasSurface);
3309 proto.write(IS_READY_FOR_DISPLAY, isReadyForDisplay());
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003310 proto.write(REMOVE_ON_EXIT, mRemoveOnExit);
3311 proto.write(DESTROYING, mDestroying);
3312 proto.write(REMOVED, mRemoved);
3313 proto.write(IS_ON_SCREEN, isOnScreen());
Nataniel Borges023ecb52019-01-16 14:15:43 -08003314 proto.write(IS_VISIBLE, isVisible);
Vishnu Nairddd80742018-08-21 14:12:46 -07003315 proto.write(PENDING_SEAMLESS_ROTATION, mPendingSeamlessRotate != null);
3316 proto.write(FINISHED_SEAMLESS_ROTATION_FRAME, mFinishSeamlessRotateFrameNumber);
3317 proto.write(FORCE_SEAMLESS_ROTATION, mForceSeamlesslyRotate);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003318 proto.end(token);
3319 }
3320
Vishnu Nair9a3e4062018-01-11 08:42:54 -08003321 @Override
3322 public void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003323 final long token = proto.start(fieldId);
3324 proto.write(HASH_CODE, System.identityHashCode(this));
3325 proto.write(USER_ID, UserHandle.getUserId(mOwnerUid));
3326 final CharSequence title = getWindowTag();
3327 if (title != null) {
3328 proto.write(TITLE, title.toString());
3329 }
3330 proto.end(token);
3331 }
3332
Jorim Jaggia5e10572017-11-15 14:36:26 +01003333 @Override
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003334 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003335 final TaskStack stack = getStack();
chaviwc65fa582018-08-09 15:33:13 -07003336 pw.print(prefix + "mDisplayId=" + getDisplayId());
3337 if (stack != null) {
3338 pw.print(" stackId=" + stack.mStackId);
3339 }
3340 pw.println(" mSession=" + mSession
3341 + " mClient=" + mClient.asBinder());
3342 pw.println(prefix + "mOwnerUid=" + mOwnerUid
3343 + " mShowToOwnerOnly=" + mShowToOwnerOnly
3344 + " package=" + mAttrs.packageName
3345 + " appop=" + AppOpsManager.opToName(mAppOp));
3346 pw.println(prefix + "mAttrs=" + mAttrs.toString(prefix));
3347 pw.println(prefix + "Requested w=" + mRequestedWidth
3348 + " h=" + mRequestedHeight
3349 + " mLayoutSeq=" + mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003350 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
chaviwc65fa582018-08-09 15:33:13 -07003351 pw.println(prefix + "LastRequested w=" + mLastRequestedWidth
3352 + " h=" + mLastRequestedHeight);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003353 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003354 if (mIsChildWindow || mLayoutAttached) {
chaviwc65fa582018-08-09 15:33:13 -07003355 pw.println(prefix + "mParentWindow=" + getParentWindow()
3356 + " mLayoutAttached=" + mLayoutAttached);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003357 }
3358 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
chaviwc65fa582018-08-09 15:33:13 -07003359 pw.println(prefix + "mIsImWindow=" + mIsImWindow
3360 + " mIsWallpaper=" + mIsWallpaper
3361 + " mIsFloatingLayer=" + mIsFloatingLayer
3362 + " mWallpaperVisible=" + mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003363 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003364 if (dumpAll) {
Jorim Jaggi35d328a2018-08-14 17:00:20 +02003365 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3366 pw.print(" mSubLayer="); pw.print(mSubLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003367 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003368 if (dumpAll) {
chaviwc65fa582018-08-09 15:33:13 -07003369 pw.println(prefix + "mToken=" + mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003370 if (mAppToken != null) {
chaviwc65fa582018-08-09 15:33:13 -07003371 pw.println(prefix + "mAppToken=" + mAppToken);
3372 pw.print(prefix + "mAppDied=" + mAppDied);
3373 pw.print(prefix + "drawnStateEvaluated=" + getDrawnStateEvaluated());
3374 pw.println(prefix + "mightAffectAllDrawn=" + mightAffectAllDrawn());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003375 }
chaviwc65fa582018-08-09 15:33:13 -07003376 pw.println(prefix + "mViewVisibility=0x" + Integer.toHexString(mViewVisibility)
3377 + " mHaveFrame=" + mHaveFrame
3378 + " mObscured=" + mObscured);
3379 pw.println(prefix + "mSeq=" + mSeq
3380 + " mSystemUiVisibility=0x" + Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003381 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003382 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
chaviwc65fa582018-08-09 15:33:13 -07003383 || isParentWindowHidden() || mPermanentlyHidden || mForceHideNonSystemOverlayWindow
Suprabh Shukla69c71422018-04-02 18:39:01 -07003384 || mHiddenWhileSuspended) {
chaviwc65fa582018-08-09 15:33:13 -07003385 pw.println(prefix + "mPolicyVisibility=" + mPolicyVisibility
3386 + " mPolicyVisibilityAfterAnim=" + mPolicyVisibilityAfterAnim
3387 + " mAppOpVisibility=" + mAppOpVisibility
3388 + " parentHidden=" + isParentWindowHidden()
3389 + " mPermanentlyHidden=" + mPermanentlyHidden
3390 + " mHiddenWhileSuspended=" + mHiddenWhileSuspended
3391 + " mForceHideNonSystemOverlayWindow=" + mForceHideNonSystemOverlayWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003392 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003393 if (!mRelayoutCalled || mLayoutNeeded) {
chaviwc65fa582018-08-09 15:33:13 -07003394 pw.println(prefix + "mRelayoutCalled=" + mRelayoutCalled
3395 + " mLayoutNeeded=" + mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003396 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003397 if (dumpAll) {
chaviwc65fa582018-08-09 15:33:13 -07003398 pw.println(prefix + "mGivenContentInsets=" + mGivenContentInsets.toShortString(sTmpSB)
3399 + " mGivenVisibleInsets=" + mGivenVisibleInsets.toShortString(sTmpSB));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003400 if (mTouchableInsets != 0 || mGivenInsetsPending) {
chaviwc65fa582018-08-09 15:33:13 -07003401 pw.println(prefix + "mTouchableInsets=" + mTouchableInsets
3402 + " mGivenInsetsPending=" + mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003403 Region region = new Region();
3404 getTouchableRegion(region);
chaviwc65fa582018-08-09 15:33:13 -07003405 pw.println(prefix + "touchable region=" + region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003406 }
chaviwc65fa582018-08-09 15:33:13 -07003407 pw.println(prefix + "mFullConfiguration=" + getConfiguration());
3408 pw.println(prefix + "mLastReportedConfiguration=" + getLastReportedConfiguration());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003409 }
chaviwc65fa582018-08-09 15:33:13 -07003410 pw.println(prefix + "mHasSurface=" + mHasSurface
3411 + " isReadyForDisplay()=" + isReadyForDisplay()
3412 + " mWindowRemovalAllowed=" + mWindowRemovalAllowed);
Riddle Hsub398da32019-01-21 21:48:16 +08003413 if (inSizeCompatMode()) {
chaviw9c81e632018-07-31 11:17:52 -07003414 pw.println(prefix + "mCompatFrame=" + mWindowFrames.mCompatFrame.toShortString(sTmpSB));
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003415 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003416 if (dumpAll) {
chaviw553b0212018-07-12 13:37:01 -07003417 mWindowFrames.dump(pw, prefix);
chaviw9c81e632018-07-31 11:17:52 -07003418 pw.println(prefix + " surface=" + mAttrs.surfaceInsets.toShortString(sTmpSB));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003419 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01003420 super.dump(pw, prefix, dumpAll);
chaviwc65fa582018-08-09 15:33:13 -07003421 pw.println(prefix + mWinAnimator + ":");
Dianne Hackborn529e7442012-11-01 14:22:28 -07003422 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003423 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
chaviwc65fa582018-08-09 15:33:13 -07003424 pw.println(prefix + "mAnimatingExit=" + mAnimatingExit
3425 + " mRemoveOnExit=" + mRemoveOnExit
3426 + " mDestroying=" + mDestroying
3427 + " mRemoved=" + mRemoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003428 }
chaviw40234662018-02-07 09:37:16 -08003429 if (getOrientationChanging() || mAppFreezing || mReportOrientationChanged) {
chaviwc65fa582018-08-09 15:33:13 -07003430 pw.println(prefix + "mOrientationChanging=" + mOrientationChanging
3431 + " configOrientationChanging="
3432 + (getLastReportedConfiguration().orientation != getConfiguration().orientation)
3433 + " mAppFreezing=" + mAppFreezing
3434 + " mReportOrientationChanged=" + mReportOrientationChanged);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003435 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003436 if (mLastFreezeDuration != 0) {
chaviwc65fa582018-08-09 15:33:13 -07003437 pw.print(prefix + "mLastFreezeDuration=");
3438 TimeUtils.formatDuration(mLastFreezeDuration, pw);
3439 pw.println();
Dianne Hackborna57c6952013-03-29 14:46:40 -07003440 }
chaviwc65fa582018-08-09 15:33:13 -07003441 pw.print(prefix + "mForceSeamlesslyRotate=" + mForceSeamlesslyRotate
3442 + " seamlesslyRotate: pending=");
Vishnu Nairddd80742018-08-21 14:12:46 -07003443 if (mPendingSeamlessRotate != null) {
3444 mPendingSeamlessRotate.dump(pw);
3445 } else {
3446 pw.print("null");
Adrian Roos27a90d22018-07-06 02:39:54 -07003447 }
chaviwc65fa582018-08-09 15:33:13 -07003448 pw.println(" finishedFrameNumber=" + mFinishSeamlessRotateFrameNumber);
Vishnu Nairddd80742018-08-21 14:12:46 -07003449
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003450 if (mHScale != 1 || mVScale != 1) {
chaviwc65fa582018-08-09 15:33:13 -07003451 pw.println(prefix + "mHScale=" + mHScale
3452 + " mVScale=" + mVScale);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003453 }
3454 if (mWallpaperX != -1 || mWallpaperY != -1) {
chaviwc65fa582018-08-09 15:33:13 -07003455 pw.println(prefix + "mWallpaperX=" + mWallpaperX
3456 + " mWallpaperY=" + mWallpaperY);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003457 }
3458 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
chaviwc65fa582018-08-09 15:33:13 -07003459 pw.println(prefix + "mWallpaperXStep=" + mWallpaperXStep
3460 + " mWallpaperYStep=" + mWallpaperYStep);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003461 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003462 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3463 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
chaviwc65fa582018-08-09 15:33:13 -07003464 pw.println(prefix + "mWallpaperDisplayOffsetX=" + mWallpaperDisplayOffsetX
3465 + " mWallpaperDisplayOffsetY=" + mWallpaperDisplayOffsetY);
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003466 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003467 if (mDrawLock != null) {
chaviwc65fa582018-08-09 15:33:13 -07003468 pw.println(prefix + "mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003469 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003470 if (isDragResizing()) {
chaviwc65fa582018-08-09 15:33:13 -07003471 pw.println(prefix + "isDragResizing=" + isDragResizing());
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003472 }
3473 if (computeDragResizing()) {
chaviwc65fa582018-08-09 15:33:13 -07003474 pw.println(prefix + "computeDragResizing=" + computeDragResizing());
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003475 }
chaviwc65fa582018-08-09 15:33:13 -07003476 pw.println(prefix + "isOnScreen=" + isOnScreen());
3477 pw.println(prefix + "isVisible=" + isVisible());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003478 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003479
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003480 @Override
3481 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003482 return Integer.toHexString(System.identityHashCode(this))
Jorim Jaggia5e10572017-11-15 14:36:26 +01003483 + " " + getWindowTag();
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003484 }
3485
Robert Carra1eb4392015-12-10 12:43:51 -08003486 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003487 CharSequence tag = mAttrs.getTitle();
3488 if (tag == null || tag.length() <= 0) {
3489 tag = mAttrs.packageName;
3490 }
3491 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003492 }
3493
3494 @Override
3495 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003496 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003497 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003498 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003499 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003500 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003501 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003502 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003503 }
3504 return mStringNameCache;
3505 }
Robert Carr58f29132015-10-29 14:19:05 -07003506
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003507 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003508 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003509 clipRect.left = (int) (clipRect.left / mHScale);
3510 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003511 }
3512 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003513 clipRect.top = (int) (clipRect.top / mVScale);
3514 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003515 }
3516 }
Robert Carr31e28482015-12-02 16:53:18 -08003517
chaviw9c81e632018-07-31 11:17:52 -07003518 private void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003519 final int pw = containingFrame.width();
3520 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003521 final Task task = getTask();
Evan Rosky4fb1e912019-03-06 13:54:43 -08003522 final boolean inNonFullscreenContainer = !inAppWindowThatMatchesParentBounds();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003523 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3524
3525 // We need to fit it to the display if either
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003526 // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen
3527 // for the taskless windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003528 // 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 -07003529 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on
3530 // screen, but SurfaceViews want to be always at a specific location so we don't fit it to
3531 // the display.
3532 final boolean fitToDisplay = (task == null || !inNonFullscreenContainer)
Robert Carr6f44db12016-07-21 14:54:43 -07003533 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003534 float x, y;
3535 int w,h;
3536
Riddle Hsub398da32019-01-21 21:48:16 +08003537 final boolean inSizeCompatMode = inSizeCompatMode();
Robert Carr31e28482015-12-02 16:53:18 -08003538 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3539 if (mAttrs.width < 0) {
3540 w = pw;
Riddle Hsub398da32019-01-21 21:48:16 +08003541 } else if (inSizeCompatMode) {
Robert Carr31e28482015-12-02 16:53:18 -08003542 w = (int)(mAttrs.width * mGlobalScale + .5f);
3543 } else {
3544 w = mAttrs.width;
3545 }
3546 if (mAttrs.height < 0) {
3547 h = ph;
Riddle Hsub398da32019-01-21 21:48:16 +08003548 } else if (inSizeCompatMode) {
Robert Carr31e28482015-12-02 16:53:18 -08003549 h = (int)(mAttrs.height * mGlobalScale + .5f);
3550 } else {
3551 h = mAttrs.height;
3552 }
3553 } else {
3554 if (mAttrs.width == MATCH_PARENT) {
3555 w = pw;
Riddle Hsub398da32019-01-21 21:48:16 +08003556 } else if (inSizeCompatMode) {
Robert Carr31e28482015-12-02 16:53:18 -08003557 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3558 } else {
3559 w = mRequestedWidth;
3560 }
3561 if (mAttrs.height == MATCH_PARENT) {
3562 h = ph;
Riddle Hsub398da32019-01-21 21:48:16 +08003563 } else if (inSizeCompatMode) {
Robert Carr31e28482015-12-02 16:53:18 -08003564 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3565 } else {
3566 h = mRequestedHeight;
3567 }
3568 }
3569
Riddle Hsub398da32019-01-21 21:48:16 +08003570 if (inSizeCompatMode) {
Robert Carr31e28482015-12-02 16:53:18 -08003571 x = mAttrs.x * mGlobalScale;
3572 y = mAttrs.y * mGlobalScale;
3573 } else {
3574 x = mAttrs.x;
3575 y = mAttrs.y;
3576 }
3577
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003578 if (inNonFullscreenContainer && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003579 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003580 // required by {@link Gravity#apply} call.
3581 w = Math.min(w, pw);
3582 h = Math.min(h, ph);
3583 }
3584
3585 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003586 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003587 (int) (x + mAttrs.horizontalMargin * pw),
chaviw492139a2018-07-16 16:07:35 -07003588 (int) (y + mAttrs.verticalMargin * ph), mWindowFrames.mFrame);
Robert Carr31e28482015-12-02 16:53:18 -08003589
3590 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003591 if (fitToDisplay) {
chaviw492139a2018-07-16 16:07:35 -07003592 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mWindowFrames.mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003593 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003594
3595 // We need to make sure we update the CompatFrame as it is used for
3596 // cropping decisions, etc, on systems where we lack a decor layer.
chaviw9c81e632018-07-31 11:17:52 -07003597 mWindowFrames.mCompatFrame.set(mWindowFrames.mFrame);
Riddle Hsub398da32019-01-21 21:48:16 +08003598 if (inSizeCompatMode) {
Robert Carr6e18c5e2016-02-29 15:57:13 -08003599 // See comparable block in computeFrameLw.
chaviw9c81e632018-07-31 11:17:52 -07003600 mWindowFrames.mCompatFrame.scale(mInvGlobalScale);
Robert Carr6e18c5e2016-02-29 15:57:13 -08003601 }
Robert Carr31e28482015-12-02 16:53:18 -08003602 }
Robert Carr51a1b872015-12-08 14:03:13 -08003603
3604 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003605 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003606 }
3607
Robert Carrf3b72c72016-03-21 18:16:39 -07003608 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003609 return mIsChildWindow
3610 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003611 }
3612
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003613 /**
3614 * Returns true if any window added by an application process that if of type
3615 * {@link android.view.WindowManager.LayoutParams#TYPE_TOAST} or that requires that requires
3616 * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when
3617 * this window is visible.
3618 */
3619 boolean hideNonSystemOverlayWindowsWhenVisible() {
Philip P. Moltmann66ce2382018-10-09 13:46:11 -07003620 return (mAttrs.privateFlags & SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != 0
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003621 && mSession.mCanHideNonSystemOverlayWindows;
3622 }
3623
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003624 /** Returns the parent window if this is a child of another window, else null. */
3625 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003626 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3627 // WindowContainer that isn't a WindowState.
3628 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003629 }
3630
3631 /** Returns the topmost parent window if this is a child of another window, else this. */
3632 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003633 WindowState current = this;
3634 WindowState topParent = current;
3635 while (current != null && current.mIsChildWindow) {
3636 current = current.getParentWindow();
3637 // Parent window can be null if the child is detached from it's parent already, but
3638 // someone still has a reference to access it. So, we return the top parent value we
3639 // already have instead of null.
3640 if (current != null) {
3641 topParent = current;
3642 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003643 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003644 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003645 }
3646
Wale Ogunwale9d147902016-07-16 11:58:55 -07003647 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003648 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003649 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003650 }
3651
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003652 void setWillReplaceWindow(boolean animate) {
3653 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003654 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003655 c.setWillReplaceWindow(animate);
3656 }
3657
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003658 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3659 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3660 // We don't set replacing on starting windows since they are added by window manager and
3661 // not the client so won't be replaced by the client.
3662 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003663 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003664
3665 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003666 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003667 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003668 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003669
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003670 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003671 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003672 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003673 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003674
3675 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003676 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003677 c.clearWillReplaceWindow();
3678 }
3679 }
3680
3681 boolean waitingForReplacement() {
3682 if (mWillReplaceWindow) {
3683 return true;
3684 }
3685
3686 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003687 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003688 if (c.waitingForReplacement()) {
3689 return true;
3690 }
3691 }
3692 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003693 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003694
Chong Zhang4d7369a2016-04-25 16:09:14 -07003695 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003696 final DisplayContent dc = getDisplayContent();
3697 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3698 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3699 dc.setLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003700 mWmService.mWindowPlacerLocked.requestTraversal();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003701 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003702
3703 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003704 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003705 c.requestUpdateWallpaperIfNeeded();
3706 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003707 }
3708
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003709 float translateToWindowX(float x) {
chaviw492139a2018-07-16 16:07:35 -07003710 float winX = x - mWindowFrames.mFrame.left;
Riddle Hsub398da32019-01-21 21:48:16 +08003711 if (inSizeCompatMode()) {
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003712 winX *= mGlobalScale;
3713 }
3714 return winX;
3715 }
3716
3717 float translateToWindowY(float y) {
chaviw492139a2018-07-16 16:07:35 -07003718 float winY = y - mWindowFrames.mFrame.top;
Riddle Hsub398da32019-01-21 21:48:16 +08003719 if (inSizeCompatMode()) {
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003720 winY *= mGlobalScale;
3721 }
3722 return winY;
3723 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003724
3725 // During activity relaunch due to resize, we sometimes use window replacement
3726 // for only child windows (as the main window is handled by window preservation)
3727 // and the big surface.
3728 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003729 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3730 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3731 // we also want to replace them at such phases, as they won't be covered by window
3732 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003733 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003734 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003735 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003736 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003737
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003738 void setWillReplaceChildWindows() {
3739 if (shouldBeReplacedWithChildren()) {
3740 setWillReplaceWindow(false /* animate */);
3741 }
3742 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003743 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003744 c.setWillReplaceChildWindows();
3745 }
3746 }
3747
3748 WindowState getReplacingWindow() {
3749 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3750 return this;
3751 }
3752 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003753 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003754 final WindowState replacing = c.getReplacingWindow();
3755 if (replacing != null) {
3756 return replacing;
3757 }
3758 }
3759 return null;
3760 }
3761
Jorim Jaggife762342016-10-13 14:33:27 +02003762 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07003763 public int getRotationAnimationHint() {
3764 if (mAppToken != null) {
3765 return mAppToken.mRotationAnimationHint;
3766 } else {
3767 return -1;
3768 }
3769 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003770
Jorim Jaggife762342016-10-13 14:33:27 +02003771 @Override
3772 public boolean isInputMethodWindow() {
3773 return mIsImWindow;
3774 }
3775
Wale Ogunwale9d147902016-07-16 11:58:55 -07003776 // This must be called while inside a transaction.
3777 boolean performShowLocked() {
3778 if (isHiddenFromUserLocked()) {
3779 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3780 hideLw(false);
3781 return false;
3782 }
3783
3784 logPerformShow("performShow on ");
3785
Jorim Jaggia50da602016-12-29 11:51:42 +01003786 final int drawState = mWinAnimator.mDrawState;
3787 if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW)
3788 && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3789 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3790 }
3791
Jorim Jaggib0d27342016-11-01 16:10:42 -07003792 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003793 return false;
3794 }
3795
3796 logPerformShow("Showing ");
3797
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003798 mWmService.enableScreenIfNeededLocked();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003799 mWinAnimator.applyEnterAnimationLocked();
3800
3801 // Force the show in the next prepareSurfaceLocked() call.
3802 mWinAnimator.mLastAlpha = -1;
Robert Carre13b58e2017-08-31 14:50:44 -07003803 if (DEBUG_ANIM) Slog.v(TAG,
Wale Ogunwale9d147902016-07-16 11:58:55 -07003804 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3805 mWinAnimator.mDrawState = HAS_DRAWN;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003806 mWmService.scheduleAnimationLocked();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003807
3808 if (mHidden) {
3809 mHidden = false;
3810 final DisplayContent displayContent = getDisplayContent();
3811
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003812 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003813 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003814 if (c.mWinAnimator.mSurfaceController != null) {
3815 c.performShowLocked();
3816 // It hadn't been shown, which means layout not performed on it, so now we
3817 // want to make sure to do a layout. If called from within the transaction
3818 // loop, this will cause it to restart with a new layout.
3819 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003820 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003821 }
3822 }
3823 }
3824 }
3825
Wale Ogunwale9d147902016-07-16 11:58:55 -07003826 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003827 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003828 }
3829
3830 return true;
3831 }
3832
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003833 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003834 if (DEBUG_VISIBILITY
Jorim Jaggie4b0f282017-05-17 15:10:29 +02003835 || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003836 Slog.v(TAG, prefix + this
3837 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07003838 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003839 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3840 + " during animation: policyVis=" + mPolicyVisibility
3841 + " parentHidden=" + isParentWindowHidden()
3842 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003843 + (mAppToken != null && mAppToken.hiddenRequested)
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003844 + " tok.hidden=" + (mAppToken != null && mAppToken.isHidden())
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02003845 + " animating=" + isAnimating()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003846 + " tok animating="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003847 + (mAppToken != null && mAppToken.isSelfAnimating())
Wale Ogunwale9d147902016-07-16 11:58:55 -07003848 + " Callers=" + Debug.getCallers(4));
3849 }
3850 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003851
3852 WindowInfo getWindowInfo() {
3853 WindowInfo windowInfo = WindowInfo.obtain();
3854 windowInfo.type = mAttrs.type;
3855 windowInfo.layer = mLayer;
3856 windowInfo.token = mClient.asBinder();
Phil Weaver5dc3ebc2017-08-16 13:04:20 -07003857 if (mAppToken != null) {
3858 windowInfo.activityToken = mAppToken.appToken.asBinder();
3859 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003860 windowInfo.title = mAttrs.accessibilityTitle;
Phil Weaverbb2f28a2017-12-22 09:44:28 -08003861 // Panel windows have no public way to set the a11y title directly. Use the
3862 // regular title as a fallback.
Phil Weaver568cf662018-04-24 17:09:26 -07003863 final boolean isPanelWindow = (mAttrs.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW)
3864 && (mAttrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW);
3865 // Accessibility overlays should have titles that work for accessibility, and can't set
3866 // the a11y title themselves.
3867 final boolean isAccessibilityOverlay =
3868 windowInfo.type == WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
3869 if (TextUtils.isEmpty(windowInfo.title) && (isPanelWindow || isAccessibilityOverlay)) {
Jackal Guo25a33cbd2018-08-01 16:08:45 +08003870 final CharSequence title = mAttrs.getTitle();
3871 windowInfo.title = TextUtils.isEmpty(title) ? null : title;
Phil Weaverbb2f28a2017-12-22 09:44:28 -08003872 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003873 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3874 windowInfo.focused = isFocused();
Phil Weaverf00cd142017-03-03 13:44:00 -08003875 Task task = getTask();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003876 windowInfo.inPictureInPicture = (task != null) && task.inPinnedWindowingMode();
Jackal Guoac2b62e2018-08-22 18:28:46 +08003877 windowInfo.hasFlagWatchOutsideTouch =
3878 (mAttrs.flags & WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH) != 0;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003879
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003880 if (mIsChildWindow) {
3881 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003882 }
3883
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003884 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003885 if (childCount > 0) {
3886 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003887 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003888 }
3889 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003890 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003891 windowInfo.childTokens.add(child.mClient.asBinder());
3892 }
3893 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003894 return windowInfo;
3895 }
3896
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003897 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003898 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003899 if (mChildren.isEmpty()) {
3900 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003901 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003902 }
3903
3904 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003905 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003906 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003907 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003908 }
3909 }
3910
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003911 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003912 // We want to consume the negative sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003913 // below the parent, then this window (the parent), and then the positive sublayer children
3914 // because they need to appear above the parent.
3915 int i = 0;
3916 final int count = mChildren.size();
3917 WindowState child = mChildren.get(i);
3918
3919 while (i < count && child.mSubLayer < 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003920 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003921 return true;
3922 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003923 i++;
3924 if (i >= count) {
3925 break;
3926 }
3927 child = mChildren.get(i);
3928 }
3929
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003930 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003931 return true;
3932 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003933
3934 while (i < count) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003935 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003936 return true;
3937 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003938 i++;
3939 if (i >= count) {
3940 break;
3941 }
3942 child = mChildren.get(i);
3943 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003944
3945 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003946 }
3947
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003948 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003949 // We want to consume the positive sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003950 // above the parent, then this window (the parent), and then the negative sublayer children
3951 // because they need to appear above the parent.
3952 int i = mChildren.size() - 1;
3953 WindowState child = mChildren.get(i);
3954
3955 while (i >= 0 && child.mSubLayer >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003956 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003957 return true;
3958 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003959 --i;
3960 if (i < 0) {
3961 break;
3962 }
3963 child = mChildren.get(i);
3964 }
3965
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003966 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003967 return true;
3968 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003969
3970 while (i >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003971 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003972 return true;
3973 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003974 --i;
3975 if (i < 0) {
3976 break;
3977 }
3978 child = mChildren.get(i);
3979 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003980
3981 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003982 }
3983
Robert Carr9785cf32018-04-25 15:06:07 -07003984 private boolean applyImeWindowsIfNeeded(ToBooleanFunction<WindowState> callback,
3985 boolean traverseTopToBottom) {
3986 // If this window is the current IME target, so we need to process the IME windows
3987 // directly above it. The exception is if we are in split screen
3988 // in which case we process the IME at the DisplayContent level to
3989 // ensure it is above the docked divider.
3990 if (isInputMethodTarget() && !inSplitScreenWindowingMode()) {
3991 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
3992 return true;
3993 }
3994 }
3995 return false;
3996 }
3997
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003998 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
3999 boolean traverseTopToBottom) {
4000 if (traverseTopToBottom) {
Robert Carr9785cf32018-04-25 15:06:07 -07004001 if (applyImeWindowsIfNeeded(callback, traverseTopToBottom)
4002 || callback.apply(this)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004003 return true;
4004 }
4005 } else {
Robert Carr9785cf32018-04-25 15:06:07 -07004006 if (callback.apply(this)
4007 || applyImeWindowsIfNeeded(callback, traverseTopToBottom)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004008 return true;
4009 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004010 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08004011 return false;
4012 }
4013
Wale Ogunwaled1880962016-11-08 10:31:59 -08004014 WindowState getWindow(Predicate<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08004015 if (mChildren.isEmpty()) {
4016 return callback.test(this) ? this : null;
4017 }
4018
4019 // We want to consume the positive sublayer children first because they need to appear
4020 // above the parent, then this window (the parent), and then the negative sublayer children
4021 // because they need to appear above the parent.
4022 int i = mChildren.size() - 1;
4023 WindowState child = mChildren.get(i);
4024
4025 while (i >= 0 && child.mSubLayer >= 0) {
4026 if (callback.test(child)) {
4027 return child;
4028 }
4029 --i;
4030 if (i < 0) {
4031 break;
4032 }
4033 child = mChildren.get(i);
4034 }
4035
Wale Ogunwaled1880962016-11-08 10:31:59 -08004036 if (callback.test(this)) {
4037 return this;
4038 }
Wale Ogunwale34247952017-02-19 11:57:53 -08004039
4040 while (i >= 0) {
4041 if (callback.test(child)) {
4042 return child;
4043 }
4044 --i;
4045 if (i < 0) {
4046 break;
4047 }
4048 child = mChildren.get(i);
4049 }
4050
4051 return null;
Wale Ogunwaled1880962016-11-08 10:31:59 -08004052 }
4053
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01004054 /**
4055 * @return True if we our one of our ancestors has {@link #mAnimatingExit} set to true, false
4056 * otherwise.
4057 */
4058 @VisibleForTesting
4059 boolean isSelfOrAncestorWindowAnimatingExit() {
4060 WindowState window = this;
4061 do {
4062 if (window.mAnimatingExit) {
4063 return true;
4064 }
4065 window = window.getParentWindow();
4066 } while (window != null);
4067 return false;
4068 }
4069
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004070 void onExitAnimationDone() {
4071 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
4072 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
Jorim Jaggia5e10572017-11-15 14:36:26 +01004073 + " selfAnimating=" + isSelfAnimating());
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004074
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004075 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004076 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +01004077 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004078 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004079 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004080 }
4081 }
4082
4083 if (mWinAnimator.mEnteringAnimation) {
4084 mWinAnimator.mEnteringAnimation = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004085 mWmService.requestTraversal();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004086 // System windows don't have an activity and an app token as a result, but need a way
4087 // to be informed about their entrance animation end.
4088 if (mAppToken == null) {
4089 try {
4090 mClient.dispatchWindowShown();
4091 } catch (RemoteException e) {
4092 }
4093 }
4094 }
4095
Jorim Jaggia5e10572017-11-15 14:36:26 +01004096 if (isSelfAnimating()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004097 return;
4098 }
4099
Jorim Jaggia5e10572017-11-15 14:36:26 +01004100 //TODO (multidisplay): Accessibility is supported only for the default display.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004101 if (mWmService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
4102 mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004103 }
4104
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01004105 if (!isSelfOrAncestorWindowAnimatingExit()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004106 return;
4107 }
4108
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07004109 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004110 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
4111
4112 mDestroying = true;
4113
4114 final boolean hasSurface = mWinAnimator.hasSurface();
Jorim Jaggi50575902018-04-10 17:49:30 +02004115
4116 // Use pendingTransaction here so hide is done the same transaction as the other
4117 // animations when exiting
4118 mWinAnimator.hide(getPendingTransaction(), "onExitAnimationDone");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004119
4120 // If we have an app token, we ask it to destroy the surface for us, so that it can take
4121 // care to ensure the activity has actually stopped and the surface is not still in use.
4122 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
4123 // transaction.
4124 if (mAppToken != null) {
4125 mAppToken.destroySurfaces();
4126 } else {
4127 if (hasSurface) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004128 mWmService.mDestroySurface.add(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004129 }
4130 if (mRemoveOnExit) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004131 mWmService.mPendingRemove.add(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004132 mRemoveOnExit = false;
4133 }
4134 }
4135 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07004136 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004137 }
Dan Willemsen117197f2016-07-30 13:02:59 -07004138
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004139 boolean clearAnimatingFlags() {
4140 boolean didSomething = false;
4141 // We don't want to clear it out for windows that get replaced, because the
4142 // animation depends on the flag to remove the replaced window.
4143 //
4144 // We also don't clear the mAnimatingExit flag for windows which have the
4145 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4146 // by the client. We should let animation proceed and not clear this flag or
4147 // they won't eventually be removed by WindowStateAnimator#finishExit.
4148 if (!mWillReplaceWindow && !mRemoveOnExit) {
4149 // Clear mAnimating flag together with mAnimatingExit. When animation
4150 // changes from exiting to entering, we need to clear this flag until the
4151 // new animation gets applied, so that isAnimationStarting() becomes true
4152 // until then.
4153 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4154 // placement for this window during this period, one or more frame will
4155 // show up with wrong position or scale.
4156 if (mAnimatingExit) {
4157 mAnimatingExit = false;
4158 didSomething = true;
4159 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004160 if (mDestroying) {
4161 mDestroying = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004162 mWmService.mDestroySurface.remove(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004163 didSomething = true;
4164 }
4165 }
4166
4167 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004168 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004169 }
4170
4171 return didSomething;
4172 }
4173
Winson4b4ba902016-07-27 19:45:52 -07004174 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004175 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004176 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004177
4178 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004179 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004180 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004181 c.hideWallpaperWindow(wasDeferred, reason);
4182 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004183 if (!mWinAnimator.mLastHidden || wasDeferred) {
4184 mWinAnimator.hide(reason);
Tiger Huang50d45462018-05-25 22:57:52 +08004185 getDisplayContent().mWallpaperController.mDeferredHideWallpaper = null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004186 dispatchWallpaperVisibility(false);
4187 final DisplayContent displayContent = getDisplayContent();
4188 if (displayContent != null) {
4189 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
Tiger Huang50d45462018-05-25 22:57:52 +08004190 if (DEBUG_LAYOUT_REPEATS) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004191 mWmService.mWindowPlacerLocked.debugLayoutRepeats("hideWallpaperWindow " + this,
Tiger Huang50d45462018-05-25 22:57:52 +08004192 displayContent.pendingLayoutChanges);
4193 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004194 }
4195 }
4196 }
4197
4198 /**
4199 * Check wallpaper window for visibility change and notify window if so.
4200 * @param visible Current visibility.
4201 */
4202 void dispatchWallpaperVisibility(final boolean visible) {
4203 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07004204 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004205
4206 // Only send notification if the visibility actually changed and we are not trying to hide
4207 // the wallpaper when we are deferring hiding of the wallpaper.
4208 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4209 mWallpaperVisible = visible;
4210 try {
4211 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4212 "Updating vis of wallpaper " + this
4213 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4214 mClient.dispatchAppVisibility(visible);
4215 } catch (RemoteException e) {
4216 }
4217 }
4218 }
4219
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004220 boolean hasVisibleNotDrawnWallpaper() {
4221 if (mWallpaperVisible && !isDrawnLw()) {
4222 return true;
4223 }
4224 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004225 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004226 if (c.hasVisibleNotDrawnWallpaper()) {
4227 return true;
4228 }
4229 }
4230 return false;
4231 }
4232
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004233 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4234 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004235 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004236 c.updateReportedVisibility(results);
4237 }
4238
4239 if (mAppFreezing || mViewVisibility != View.VISIBLE
4240 || mAttrs.type == TYPE_APPLICATION_STARTING
4241 || mDestroying) {
4242 return;
4243 }
4244 if (DEBUG_VISIBILITY) {
4245 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02004246 + ", animating=" + isAnimating());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004247 if (!isDrawnLw()) {
4248 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4249 + " pv=" + mPolicyVisibility
4250 + " mDrawState=" + mWinAnimator.mDrawState
4251 + " ph=" + isParentWindowHidden()
4252 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02004253 + " a=" + isAnimating());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004254 }
4255 }
4256
4257 results.numInteresting++;
4258 if (isDrawnLw()) {
4259 results.numDrawn++;
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02004260 if (!isAnimating()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004261 results.numVisible++;
4262 }
4263 results.nowGone = false;
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02004264 } else if (isAnimating()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004265 results.nowGone = false;
4266 }
4267 }
4268
Robert Carr683e05d2018-04-18 15:11:04 -07004269 private boolean skipDecorCrop() {
4270 // The decor frame is used to specify the region not covered by the system
4271 // decorations (nav bar, status bar). In case this is empty, for example with
4272 // FLAG_TRANSLUCENT_NAVIGATION, we don't need to do any cropping.
chaviw553b0212018-07-12 13:37:01 -07004273 if (mWindowFrames.mDecorFrame.isEmpty()) {
Robert Carr683e05d2018-04-18 15:11:04 -07004274 return true;
4275 }
4276
4277 // But if we have a frame, and are an application window, then we must be cropped.
4278 if (mAppToken != null) {
4279 return false;
4280 }
4281
4282 // For non application windows, we may be allowed to extend over the decor bars
4283 // depending on our type and permissions assosciated with our token.
4284 return mToken.canLayerAboveSystemBars();
4285 }
4286
Robert Carrfbbde852016-10-18 11:02:28 -07004287 /**
4288 * Calculate the window crop according to system decor policy. In general this is
4289 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4290 * special cases. This rectangle is in screen space.
4291 */
4292 void calculatePolicyCrop(Rect policyCrop) {
4293 final DisplayContent displayContent = getDisplayContent();
Robert Carrfbbde852016-10-18 11:02:28 -07004294
Riddle Hsub398da32019-01-21 21:48:16 +08004295 if (!displayContent.isDefaultDisplay && !displayContent.supportsSystemDecorations()) {
Robert Carrfbbde852016-10-18 11:02:28 -07004296 // On a different display there is no system decor. Crop the window
4297 // by the screen boundaries.
Riddle Hsub398da32019-01-21 21:48:16 +08004298 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
chaviw9c81e632018-07-31 11:17:52 -07004299 policyCrop.set(0, 0, mWindowFrames.mCompatFrame.width(),
4300 mWindowFrames.mCompatFrame.height());
4301 policyCrop.intersect(-mWindowFrames.mCompatFrame.left, -mWindowFrames.mCompatFrame.top,
4302 displayInfo.logicalWidth - mWindowFrames.mCompatFrame.left,
4303 displayInfo.logicalHeight - mWindowFrames.mCompatFrame.top);
Robert Carr683e05d2018-04-18 15:11:04 -07004304 } else if (skipDecorCrop()) {
Robert Carrfbbde852016-10-18 11:02:28 -07004305 // Windows without policy decor aren't cropped.
chaviw9c81e632018-07-31 11:17:52 -07004306 policyCrop.set(0, 0, mWindowFrames.mCompatFrame.width(),
4307 mWindowFrames.mCompatFrame.height());
Robert Carrfbbde852016-10-18 11:02:28 -07004308 } else {
4309 // Crop to the system decor specified by policy.
4310 calculateSystemDecorRect(policyCrop);
4311 }
4312 }
4313
4314 /**
4315 * The system decor rect is the region of the window which is not covered
4316 * by system decorations.
4317 */
4318 private void calculateSystemDecorRect(Rect systemDecorRect) {
chaviw553b0212018-07-12 13:37:01 -07004319 final Rect decorRect = mWindowFrames.mDecorFrame;
chaviw492139a2018-07-16 16:07:35 -07004320 final int width = mWindowFrames.mFrame.width();
4321 final int height = mWindowFrames.mFrame.height();
Robert Carrfbbde852016-10-18 11:02:28 -07004322
chaviw492139a2018-07-16 16:07:35 -07004323 final int left = mWindowFrames.mFrame.left;
4324 final int top = mWindowFrames.mFrame.top;
Robert Carrfbbde852016-10-18 11:02:28 -07004325
4326 // Initialize the decor rect to the entire frame.
4327 if (isDockedResizing()) {
4328 // If we are resizing with the divider, the task bounds might be smaller than the
4329 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4330 // want in this case in order to avoid holes.
4331 //
4332 // We take care to not shrink the width, for surfaces which are larger than
4333 // the display region. Of course this area will not eventually be visible
4334 // but if we truncate the width now, we will calculate incorrectly
4335 // when adjusting to the stack bounds.
4336 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4337 systemDecorRect.set(0, 0,
4338 Math.max(width, displayInfo.logicalWidth),
4339 Math.max(height, displayInfo.logicalHeight));
4340 } else {
4341 systemDecorRect.set(0, 0, width, height);
4342 }
4343
4344 // If a freeform window is animating from a position where it would be cutoff, it would be
4345 // cutoff during the animation. We don't want that, so for the duration of the animation
4346 // we ignore the decor cropping and depend on layering to position windows correctly.
chaviw95136622018-04-09 15:20:06 -07004347
4348 // We also ignore cropping when the window is currently being drag resized in split screen
4349 // to prevent issues with the crop for screenshot.
4350 final boolean cropToDecor =
4351 !(inFreeformWindowingMode() && isAnimatingLw()) && !isDockedResizing();
Robert Carrfbbde852016-10-18 11:02:28 -07004352 if (cropToDecor) {
4353 // Intersect with the decor rect, offsetted by window position.
4354 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
4355 decorRect.right - left, decorRect.bottom - top);
4356 }
4357
4358 // If size compatibility is being applied to the window, the
4359 // surface is scaled relative to the screen. Also apply this
4360 // scaling to the crop rect. We aren't using the standard rect
4361 // scale function because we want to round things to make the crop
4362 // always round to a larger rect to ensure we don't crop too
4363 // much and hide part of the window that should be seen.
Riddle Hsub398da32019-01-21 21:48:16 +08004364 if (inSizeCompatMode() && mInvGlobalScale != 1.0f) {
Robert Carrfbbde852016-10-18 11:02:28 -07004365 final float scale = mInvGlobalScale;
4366 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
4367 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
4368 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
4369 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
4370 }
4371
4372 }
4373
4374 /**
4375 * Expand the given rectangle by this windows surface insets. This
4376 * takes you from the 'window size' to the 'surface size'.
4377 * The surface insets are positive in each direction, so we inset by
4378 * the inverse.
4379 */
4380 void expandForSurfaceInsets(Rect r) {
4381 r.inset(-mAttrs.surfaceInsets.left,
4382 -mAttrs.surfaceInsets.top,
4383 -mAttrs.surfaceInsets.right,
4384 -mAttrs.surfaceInsets.bottom);
4385 }
4386
Robert Carrc91d1c32017-02-15 19:37:46 -08004387 boolean surfaceInsetsChanging() {
4388 return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets);
4389 }
4390
Bryce Leef858b572017-06-29 14:03:33 -07004391 int relayoutVisibleWindow(int result, int attrChanges, int oldVisibility) {
Robert Carrecc06b32017-04-18 14:25:10 -07004392 final boolean wasVisible = isVisibleLw();
4393
4394 result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0;
Robert Carr7b3d11d2018-03-15 14:34:45 -07004395
Robert Carrc91d1c32017-02-15 19:37:46 -08004396 if (mAnimatingExit) {
4397 Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit="
4398 + mRemoveOnExit + ", mDestroying=" + mDestroying);
4399
Riddle Hsub8d704b2019-02-22 12:44:12 +08004400 // Cancel the existing exit animation for the next enter animation.
4401 if (isSelfAnimating()) {
4402 cancelAnimation();
4403 destroySurfaceUnchecked();
4404 }
Robert Carrc91d1c32017-02-15 19:37:46 -08004405 mAnimatingExit = false;
4406 }
4407 if (mDestroying) {
4408 mDestroying = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004409 mWmService.mDestroySurface.remove(this);
Robert Carrc91d1c32017-02-15 19:37:46 -08004410 }
4411 if (oldVisibility == View.GONE) {
4412 mWinAnimator.mEnterAnimationPending = true;
4413 }
4414
Andrii Kulian8ee72852017-03-10 10:36:45 -08004415 mLastVisibleLayoutRotation = getDisplayContent().getRotation();
Robert Carrc91d1c32017-02-15 19:37:46 -08004416
4417 mWinAnimator.mEnteringAnimation = true;
Bryce Leeae73ba42017-05-05 09:58:25 -07004418
Bryce Leef858b572017-06-29 14:03:33 -07004419 prepareWindowToDisplayDuringRelayout(wasVisible);
Bryce Leeae73ba42017-05-05 09:58:25 -07004420
Robert Carrc91d1c32017-02-15 19:37:46 -08004421 if ((attrChanges & FORMAT_CHANGED) != 0) {
4422 // If the format can't be changed in place, preserve the old surface until the app draws
4423 // on the new one. This prevents blinking when we change elevation of freeform and
4424 // pinned windows.
4425 if (!mWinAnimator.tryChangeFormatInPlaceLocked()) {
4426 mWinAnimator.preserveSurfaceLocked();
4427 result |= RELAYOUT_RES_SURFACE_CHANGED
4428 | RELAYOUT_RES_FIRST_TIME;
4429 }
4430 }
4431
4432 // When we change the Surface size, in scenarios which may require changing
4433 // the surface position in sync with the resize, we use a preserved surface
4434 // so we can freeze it while waiting for the client to report draw on the newly
Robert Carrc6d5af52018-02-26 17:46:00 -08004435 // sized surface. At the moment this logic is only in place for switching
4436 // in and out of the big surface for split screen resize.
4437 if (isDragResizeChanged()) {
Robert Carrc91d1c32017-02-15 19:37:46 -08004438 setDragResizing();
Robert Carrc91d1c32017-02-15 19:37:46 -08004439 // We can only change top level windows to the full-screen surface when
4440 // resizing (as we only have one full-screen surface). So there is no need
4441 // to preserve and destroy windows which are attached to another, they
4442 // will keep their surface and its size may change over time.
4443 if (mHasSurface && !isChildWindow()) {
4444 mWinAnimator.preserveSurfaceLocked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08004445 result |= RELAYOUT_RES_SURFACE_CHANGED |
4446 RELAYOUT_RES_FIRST_TIME;
Robert Carrc91d1c32017-02-15 19:37:46 -08004447 }
4448 }
4449 final boolean freeformResizing = isDragResizing()
4450 && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
4451 final boolean dockedResizing = isDragResizing()
4452 && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
4453 result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0;
4454 result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004455 return result;
4456 }
4457
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004458 /**
4459 * @return True if this window has been laid out at least once; false otherwise.
4460 */
4461 boolean isLaidOut() {
4462 return mLayoutSeq != -1;
4463 }
4464
4465 /**
4466 * Updates the last inset values to the current ones.
4467 */
4468 void updateLastInsetValues() {
chaviw9c81e632018-07-31 11:17:52 -07004469 mWindowFrames.updateLastInsetValues();
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004470 }
4471
Jorim Jaggia5e10572017-11-15 14:36:26 +01004472 void startAnimation(Animation anim) {
Jorim Jaggia2759b22019-01-24 13:21:40 +01004473
4474 // If we are an inset provider, all our animations are driven by the inset client.
4475 if (mInsetProvider != null && mInsetProvider.isControllable()) {
4476 return;
4477 }
4478
Jorim Jaggia5e10572017-11-15 14:36:26 +01004479 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
chaviw492139a2018-07-16 16:07:35 -07004480 anim.initialize(mWindowFrames.mFrame.width(), mWindowFrames.mFrame.height(),
Jorim Jaggia5e10572017-11-15 14:36:26 +01004481 displayInfo.appWidth, displayInfo.appHeight);
4482 anim.restrictDuration(MAX_ANIMATION_DURATION);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004483 anim.scaleCurrentDuration(mWmService.getWindowAnimationScaleLocked());
Jorim Jaggia5e10572017-11-15 14:36:26 +01004484 final AnimationAdapter adapter = new LocalAnimationAdapter(
Lucas Dupin3e1dc202018-12-02 15:14:20 -08004485 new WindowAnimationSpec(anim, mSurfacePosition, false /* canSkipFirstFrame */,
4486 mWmService.mWindowCornerRadius),
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004487 mWmService.mSurfaceAnimationRunner);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004488 startAnimation(mPendingTransaction, adapter);
4489 commitPendingTransaction();
4490 }
4491
chaviw161ea3e2018-01-31 12:01:12 -08004492 private void startMoveAnimation(int left, int top) {
Jorim Jaggia2759b22019-01-24 13:21:40 +01004493
4494 // If we are an inset provider, all our animations are driven by the inset client.
4495 if (mInsetProvider != null && mInsetProvider.isControllable()) {
4496 return;
4497 }
4498
Jorim Jaggia5e10572017-11-15 14:36:26 +01004499 if (DEBUG_ANIM) Slog.v(TAG, "Setting move animation on " + this);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004500 final Point oldPosition = new Point();
4501 final Point newPosition = new Point();
chaviw492139a2018-07-16 16:07:35 -07004502 transformFrameToSurfacePosition(mWindowFrames.mLastFrame.left, mWindowFrames.mLastFrame.top,
4503 oldPosition);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004504 transformFrameToSurfacePosition(left, top, newPosition);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004505 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004506 new MoveAnimationSpec(oldPosition.x, oldPosition.y, newPosition.x, newPosition.y),
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004507 mWmService.mSurfaceAnimationRunner);
chaviw161ea3e2018-01-31 12:01:12 -08004508 startAnimation(getPendingTransaction(), adapter);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004509 }
4510
4511 private void startAnimation(Transaction t, AnimationAdapter adapter) {
4512 startAnimation(t, adapter, mWinAnimator.mLastHidden);
4513 }
4514
4515 @Override
4516 protected void onAnimationFinished() {
chaviwccd5d502019-02-22 13:30:31 -08004517 super.onAnimationFinished();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004518 mWinAnimator.onAnimationFinished();
4519 }
4520
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004521 /**
4522 * Retrieves the current transformation matrix of the window, relative to the display.
4523 *
4524 * @param float9 A temporary array of 9 floats.
4525 * @param outMatrix Matrix to fill in the transformation.
4526 */
4527 void getTransformationMatrix(float[] float9, Matrix outMatrix) {
4528 float9[Matrix.MSCALE_X] = mWinAnimator.mDsDx;
4529 float9[Matrix.MSKEW_Y] = mWinAnimator.mDtDx;
4530 float9[Matrix.MSKEW_X] = mWinAnimator.mDtDy;
4531 float9[Matrix.MSCALE_Y] = mWinAnimator.mDsDy;
Robert Carr217e7cc2018-01-31 18:08:39 -08004532 int x = mSurfacePosition.x;
4533 int y = mSurfacePosition.y;
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004534
4535 // If changed, also adjust transformFrameToSurfacePosition
4536 final WindowContainer parent = getParent();
4537 if (isChildWindow()) {
4538 final WindowState parentWindow = getParentWindow();
chaviw492139a2018-07-16 16:07:35 -07004539 x += parentWindow.mWindowFrames.mFrame.left - parentWindow.mAttrs.surfaceInsets.left;
4540 y += parentWindow.mWindowFrames.mFrame.top - parentWindow.mAttrs.surfaceInsets.top;
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004541 } else if (parent != null) {
4542 final Rect parentBounds = parent.getBounds();
4543 x += parentBounds.left;
4544 y += parentBounds.top;
4545 }
4546 float9[Matrix.MTRANS_X] = x;
4547 float9[Matrix.MTRANS_Y] = y;
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004548 float9[Matrix.MPERSP_0] = 0;
4549 float9[Matrix.MPERSP_1] = 0;
4550 float9[Matrix.MPERSP_2] = 1;
4551 outMatrix.setValues(float9);
4552 }
4553
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004554 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4555 // access to its windows children. Need to investigate re-writing
4556 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4557 static final class UpdateReportedVisibilityResults {
4558 int numInteresting;
4559 int numVisible;
4560 int numDrawn;
4561 boolean nowGone = true;
4562
4563 void reset() {
4564 numInteresting = 0;
4565 numVisible = 0;
4566 numDrawn = 0;
4567 nowGone = true;
4568 }
4569 }
Robert Carraf422a82017-04-10 18:34:33 -07004570
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004571 private static final class WindowId extends IWindowId.Stub {
4572 private final WeakReference<WindowState> mOuter;
4573
4574 private WindowId(WindowState outer) {
4575
4576 // Use a weak reference for the outer class. This is important to prevent the following
4577 // leak: Since we send this class to the client process, binder will keep it alive as
4578 // long as the client keeps it alive. Now, if the window is removed, we need to clear
4579 // out our reference so even though this class is kept alive we don't leak WindowState,
4580 // which can keep a whole lot of classes alive.
4581 mOuter = new WeakReference<>(outer);
4582 }
4583
4584 @Override
4585 public void registerFocusObserver(IWindowFocusObserver observer) {
4586 final WindowState outer = mOuter.get();
4587 if (outer != null) {
4588 outer.registerFocusObserver(observer);
4589 }
4590 }
4591 @Override
4592 public void unregisterFocusObserver(IWindowFocusObserver observer) {
4593 final WindowState outer = mOuter.get();
4594 if (outer != null) {
4595 outer.unregisterFocusObserver(observer);
4596 }
4597 }
4598 @Override
4599 public boolean isFocused() {
4600 final WindowState outer = mOuter.get();
Tiger Huang1e5b10a2018-07-30 20:19:51 +08004601 if (outer != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004602 synchronized (outer.mWmService.mGlobalLock) {
Tiger Huang1e5b10a2018-07-30 20:19:51 +08004603 return outer.isFocused();
4604 }
4605 }
4606 return false;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004607 }
4608 }
4609
Robert Carrb1579c82017-09-05 14:54:47 -07004610
4611 @Override
4612 boolean shouldMagnify() {
4613 if (mAttrs.type == TYPE_INPUT_METHOD ||
Robert Carree4d4b92017-11-22 12:21:46 -08004614 mAttrs.type == TYPE_INPUT_METHOD_DIALOG ||
4615 mAttrs.type == TYPE_MAGNIFICATION_OVERLAY ||
4616 mAttrs.type == TYPE_NAVIGATION_BAR ||
4617 // It's tempting to wonder: Have we forgotten the rounded corners overlay?
4618 // worry not: it's a fake TYPE_NAVIGATION_BAR_PANEL
Eugene Susla9552b262018-03-13 12:24:50 -07004619 mAttrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Robert Carrb1579c82017-09-05 14:54:47 -07004620 return false;
4621 }
4622 return true;
4623 }
4624
4625 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004626 SurfaceSession getSession() {
4627 if (mSession.mSurfaceSession != null) {
4628 return mSession.mSurfaceSession;
4629 } else {
4630 return getParent().getSession();
4631 }
4632 }
4633
4634 @Override
4635 boolean needsZBoost() {
lumarkff0ab692018-11-05 20:32:30 +08004636 final WindowState inputMethodTarget = getDisplayContent().mInputMethodTarget;
4637 if (mIsImWindow && inputMethodTarget != null) {
4638 final AppWindowToken appToken = inputMethodTarget.mAppToken;
Jorim Jaggib0fc8172017-11-23 17:04:08 +00004639 if (appToken != null) {
4640 return appToken.needsZBoost();
4641 }
4642 }
4643 return mWillReplaceWindow;
Robert Carrb1579c82017-09-05 14:54:47 -07004644 }
4645
Robert Carrf07ef9e2017-11-21 12:12:49 -08004646 private void applyDims(Dimmer dimmer) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07004647 if (!mAnimatingExit && mAppDied) {
4648 mIsDimming = true;
chaviw2fb06bc2018-01-19 17:09:15 -08004649 dimmer.dimAbove(getPendingTransaction(), this, DEFAULT_DIM_AMOUNT_DEAD_WINDOW);
chaviwebcbc342018-02-07 13:19:00 -08004650 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0 && isVisibleNow() && !mHidden) {
chaviw14076152018-02-02 14:51:20 -08004651 // Only show a dim behind when the following is satisfied:
4652 // 1. The window has the flag FLAG_DIM_BEHIND
4653 // 2. The WindowToken is not hidden so dims aren't shown when the window is exiting.
4654 // 3. The WS is considered visible according to the isVisible() method
chaviwebcbc342018-02-07 13:19:00 -08004655 // 4. The WS is not hidden.
Robert Carrf59b8dd2017-10-02 18:58:36 -07004656 mIsDimming = true;
chaviw2fb06bc2018-01-19 17:09:15 -08004657 dimmer.dimBelow(getPendingTransaction(), this, mAttrs.dimAmount);
Robert Carrf59b8dd2017-10-02 18:58:36 -07004658 }
Robert Carrf07ef9e2017-11-21 12:12:49 -08004659 }
4660
4661 @Override
4662 void prepareSurfaces() {
4663 final Dimmer dimmer = getDimmer();
4664 mIsDimming = false;
4665 if (dimmer != null) {
4666 applyDims(dimmer);
4667 }
chaviw2f0567b2018-01-29 16:22:02 -08004668 updateSurfacePosition();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004669
Robert Carrb1579c82017-09-05 14:54:47 -07004670 mWinAnimator.prepareSurfaceLocked(true);
4671 super.prepareSurfaces();
4672 }
4673
4674 @Override
Jorim Jaggia5e10572017-11-15 14:36:26 +01004675 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
4676 super.onAnimationLeashCreated(t, leash);
4677
4678 // Leash is now responsible for position, so set our position to 0.
4679 t.setPosition(mSurfaceControl, 0, 0);
chaviw3e751af2018-01-11 11:22:39 -08004680 mLastSurfacePosition.set(0, 0);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004681 }
4682
4683 @Override
4684 public void onAnimationLeashDestroyed(Transaction t) {
4685 super.onAnimationLeashDestroyed(t);
4686 updateSurfacePosition(t);
4687 }
4688
chaviwe07246a2017-12-12 16:18:29 -08004689 @Override
chaviw2f0567b2018-01-29 16:22:02 -08004690 void updateSurfacePosition() {
4691 updateSurfacePosition(getPendingTransaction());
4692 }
4693
Vishnu Naird8c664b2018-09-24 12:52:35 -07004694 @VisibleForTesting
4695 void updateSurfacePosition(Transaction t) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01004696 if (mSurfaceControl == null) {
4697 return;
4698 }
4699
chaviw492139a2018-07-16 16:07:35 -07004700 transformFrameToSurfacePosition(mWindowFrames.mFrame.left, mWindowFrames.mFrame.top,
4701 mSurfacePosition);
Robert Carrc6d5af52018-02-26 17:46:00 -08004702
Vishnu Nair83537a72018-07-19 21:27:48 -07004703 // Freeze position while we're unrotated, so the surface remains at the position it was
4704 // prior to the rotation.
Vishnu Nairddd80742018-08-21 14:12:46 -07004705 if (!mSurfaceAnimator.hasLeash() && mPendingSeamlessRotate == null
4706 && !mLastSurfacePosition.equals(mSurfacePosition)) {
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004707 t.setPosition(mSurfaceControl, mSurfacePosition.x, mSurfacePosition.y);
chaviw3e751af2018-01-11 11:22:39 -08004708 mLastSurfacePosition.set(mSurfacePosition.x, mSurfacePosition.y);
Robert Carrc6d5af52018-02-26 17:46:00 -08004709 if (surfaceInsetsChanging() && mWinAnimator.hasSurface()) {
4710 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
4711 t.deferTransactionUntil(mSurfaceControl,
4712 mWinAnimator.mSurfaceController.mSurfaceControl.getHandle(),
chaviwbe43ac82018-04-04 15:14:49 -07004713 getFrameNumber());
Robert Carrc6d5af52018-02-26 17:46:00 -08004714 }
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004715 }
4716 }
4717
4718 private void transformFrameToSurfacePosition(int left, int top, Point outPoint) {
4719 outPoint.set(left, top);
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004720
4721 // If changed, also adjust getTransformationMatrix
chaviwe07246a2017-12-12 16:18:29 -08004722 final WindowContainer parentWindowContainer = getParent();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004723 if (isChildWindow()) {
4724 // TODO: This probably falls apart at some point and we should
4725 // actually compute relative coordinates.
Jorim Jaggi50d3f8f2017-12-27 17:41:25 +01004726
4727 // Since the parent was outset by its surface insets, we need to undo the outsetting
4728 // with insetting by the same amount.
Jorim Jaggia5e10572017-11-15 14:36:26 +01004729 final WindowState parent = getParentWindow();
Riddle Hsub398da32019-01-21 21:48:16 +08004730 transformSurfaceInsetsPosition(mTmpPoint, parent.mAttrs.surfaceInsets);
4731 outPoint.offset(-parent.mWindowFrames.mFrame.left + mTmpPoint.x,
4732 -parent.mWindowFrames.mFrame.top + mTmpPoint.y);
chaviwe07246a2017-12-12 16:18:29 -08004733 } else if (parentWindowContainer != null) {
Evan Roskyed6767f2018-10-26 17:21:06 -07004734 final Rect parentBounds = parentWindowContainer.getDisplayedBounds();
chaviwe07246a2017-12-12 16:18:29 -08004735 outPoint.offset(-parentBounds.left, -parentBounds.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004736 }
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004737
Robert Carr32bcb102018-01-29 15:03:23 -08004738 TaskStack stack = getStack();
4739
4740 // If we have stack outsets, that means the top-left
4741 // will be outset, and we need to inset ourselves
4742 // to account for it. If we actually have shadows we will
4743 // then un-inset ourselves by the surfaceInsets.
4744 if (stack != null) {
4745 final int outset = stack.getStackOutset();
4746 outPoint.offset(outset, outset);
4747 }
4748
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004749 // Expand for surface insets. See WindowState.expandForSurfaceInsets.
Riddle Hsub398da32019-01-21 21:48:16 +08004750 transformSurfaceInsetsPosition(mTmpPoint, mAttrs.surfaceInsets);
4751 outPoint.offset(-mTmpPoint.x, -mTmpPoint.y);
4752 }
4753
4754 /**
4755 * The surface insets from layout parameter are in application coordinate. If the window is
4756 * scaled, the insets also need to be scaled for surface position in global coordinate.
4757 */
4758 private void transformSurfaceInsetsPosition(Point outPos, Rect surfaceInsets) {
4759 if (!inSizeCompatMode()) {
4760 outPos.x = surfaceInsets.left;
4761 outPos.y = surfaceInsets.top;
4762 return;
4763 }
4764 outPos.x = (int) (surfaceInsets.left * mGlobalScale + 0.5f);
4765 outPos.y = (int) (surfaceInsets.top * mGlobalScale + 0.5f);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004766 }
4767
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004768 boolean needsRelativeLayeringToIme() {
4769 // We only use the relative layering mode in split screen, as part of elevating the IME
4770 // and windows above it's target above the docked divider.
4771 if (!inSplitScreenWindowingMode()) {
4772 return false;
4773 }
4774
4775 if (isChildWindow()) {
4776 // If we are a child of the input method target we need this promotion.
4777 if (getParentWindow().isInputMethodTarget()) {
4778 return true;
4779 }
4780 } else if (mAppToken != null) {
4781 // Likewise if we share a token with the Input method target and are ordered
4782 // above it but not necessarily a child (e.g. a Dialog) then we also need
4783 // this promotion.
lumarkff0ab692018-11-05 20:32:30 +08004784 final WindowState imeTarget = getDisplayContent().mInputMethodTarget;
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004785 boolean inTokenWithAndAboveImeTarget = imeTarget != null && imeTarget != this
4786 && imeTarget.mToken == mToken && imeTarget.compareTo(this) <= 0;
4787 return inTokenWithAndAboveImeTarget;
4788 }
4789 return false;
4790 }
4791
Jorim Jaggia5e10572017-11-15 14:36:26 +01004792 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004793 void assignLayer(Transaction t, int layer) {
4794 // See comment in assignRelativeLayerForImeTargetChild
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004795 if (needsRelativeLayeringToIme()) {
4796 getDisplayContent().assignRelativeLayerForImeTargetChild(t, this);
Robert Carrb1579c82017-09-05 14:54:47 -07004797 return;
4798 }
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004799 super.assignLayer(t, layer);
Robert Carrb1579c82017-09-05 14:54:47 -07004800 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07004801
4802 @Override
4803 public boolean isDimming() {
4804 return mIsDimming;
4805 }
Robert Carr0eff1872017-12-01 14:27:04 -08004806
4807 // TODO(b/70040778): We should aim to eliminate the last user of TYPE_APPLICATION_MEDIA
4808 // then we can drop all negative layering on the windowing side and simply inherit
4809 // the default implementation here.
4810 public void assignChildLayers(Transaction t) {
Tiger Huang9c8ee262019-02-19 20:44:27 +08004811 // The surface of the main window might be preserved. So the child window on top of the main
4812 // window should be also on top of the preserved surface.
4813 int layer = PRESERVED_SURFACE_LAYER + 1;
Robert Carr0eff1872017-12-01 14:27:04 -08004814 for (int i = 0; i < mChildren.size(); i++) {
4815 final WindowState w = mChildren.get(i);
4816
4817 // APPLICATION_MEDIA_OVERLAY needs to go above APPLICATION_MEDIA
4818 // while they both need to go below the main window. However the
4819 // relative layering of multiple APPLICATION_MEDIA/OVERLAY has never
4820 // been defined and so we can use static layers and leave it that way.
4821 if (w.mAttrs.type == TYPE_APPLICATION_MEDIA) {
4822 w.assignLayer(t, -2);
4823 } else if (w.mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) {
4824 w.assignLayer(t, -1);
4825 } else {
4826 w.assignLayer(t, layer);
4827 }
4828 w.assignChildLayers(t);
4829 layer++;
4830 }
4831 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01004832
Andrii Kulian4b6599e2018-01-15 17:24:08 -08004833 /**
4834 * Update a tap exclude region with a rectangular area identified by provided id. The requested
4835 * area will be clipped to the window bounds.
4836 */
4837 void updateTapExcludeRegion(int regionId, int left, int top, int width, int height) {
4838 final DisplayContent currentDisplay = getDisplayContent();
4839 if (currentDisplay == null) {
4840 throw new IllegalStateException("Trying to update window not attached to any display.");
4841 }
4842
4843 if (mTapExcludeRegionHolder == null) {
4844 mTapExcludeRegionHolder = new TapExcludeRegionHolder();
4845
4846 // Make sure that this window is registered as one that provides a tap exclude region
4847 // for its containing display.
4848 currentDisplay.mTapExcludeProvidingWindows.add(this);
4849 }
4850
4851 mTapExcludeRegionHolder.updateRegion(regionId, left, top, width, height);
4852 // Trigger touch exclude region update on current display.
Tiger Huang1e5b10a2018-07-30 20:19:51 +08004853 currentDisplay.updateTouchExcludeRegion();
Tiger Huang04dc4cc2019-01-17 18:41:41 +08004854 // Trigger touchable region update for this window.
4855 currentDisplay.getInputMonitor().updateInputWindowsLw(true /* force */);
Andrii Kulian4b6599e2018-01-15 17:24:08 -08004856 }
4857
Tiger Huang04dc4cc2019-01-17 18:41:41 +08004858 /**
4859 * Union the region with current tap exclude region that this window provides.
4860 *
4861 * @param region The region to be amended. It is on the screen coordinates.
4862 */
Andrii Kulian4b6599e2018-01-15 17:24:08 -08004863 void amendTapExcludeRegion(Region region) {
Tiger Huang04dc4cc2019-01-17 18:41:41 +08004864 final Region tempRegion = Region.obtain();
4865 mTmpRect.set(mWindowFrames.mFrame);
4866 mTmpRect.offsetTo(0, 0);
4867 mTapExcludeRegionHolder.amendRegion(tempRegion, mTmpRect);
4868 // The region held by the holder is on the window coordinates. We need to translate it to
4869 // the screen coordinates.
4870 tempRegion.translate(mWindowFrames.mFrame.left, mWindowFrames.mFrame.top);
4871 region.op(tempRegion, Region.Op.UNION);
4872 tempRegion.recycle();
Andrii Kulian4b6599e2018-01-15 17:24:08 -08004873 }
4874
Robert Carr825581a2018-03-30 14:00:53 -07004875 @Override
4876 public boolean isInputMethodTarget() {
lumarkff0ab692018-11-05 20:32:30 +08004877 return getDisplayContent().mInputMethodTarget == this;
Robert Carr825581a2018-03-30 14:00:53 -07004878 }
4879
chaviwbe43ac82018-04-04 15:14:49 -07004880 long getFrameNumber() {
4881 return mFrameNumber;
4882 }
4883
4884 void setFrameNumber(long frameNumber) {
4885 mFrameNumber = frameNumber;
4886 }
4887
chaviw553b0212018-07-12 13:37:01 -07004888 public void getMaxVisibleBounds(Rect out) {
4889 if (out.isEmpty()) {
4890 out.set(mWindowFrames.mVisibleFrame);
4891 return;
4892 }
4893
4894 if (mWindowFrames.mVisibleFrame.left < out.left) {
4895 out.left = mWindowFrames.mVisibleFrame.left;
4896 }
4897 if (mWindowFrames.mVisibleFrame.top < out.top) {
4898 out.top = mWindowFrames.mVisibleFrame.top;
4899 }
4900 if (mWindowFrames.mVisibleFrame.right > out.right) {
4901 out.right = mWindowFrames.mVisibleFrame.right;
4902 }
4903 if (mWindowFrames.mVisibleFrame.bottom > out.bottom) {
4904 out.bottom = mWindowFrames.mVisibleFrame.bottom;
4905 }
4906 }
4907
chaviw9c81e632018-07-31 11:17:52 -07004908 /**
4909 * Copy the inset values over so they can be sent back to the client when a relayout occurs.
4910 */
4911 void getInsetsForRelayout(Rect outOverscanInsets, Rect outContentInsets, Rect outVisibleInsets,
4912 Rect outStableInsets, Rect outOutsets) {
4913 outOverscanInsets.set(mWindowFrames.mOverscanInsets);
4914 outContentInsets.set(mWindowFrames.mContentInsets);
4915 outVisibleInsets.set(mWindowFrames.mVisibleInsets);
4916 outStableInsets.set(mWindowFrames.mStableInsets);
4917 outOutsets.set(mWindowFrames.mOutsets);
4918
4919 mLastRelayoutContentInsets.set(mWindowFrames.mContentInsets);
4920 }
4921
4922 void getContentInsets(Rect outContentInsets) {
4923 outContentInsets.set(mWindowFrames.mContentInsets);
4924 }
4925
4926 Rect getContentInsets() {
4927 return mWindowFrames.mContentInsets;
4928 }
4929
4930 void getStableInsets(Rect outStableInsets) {
4931 outStableInsets.set(mWindowFrames.mStableInsets);
4932 }
4933
4934 Rect getStableInsets() {
4935 return mWindowFrames.mStableInsets;
4936 }
4937
4938 void resetLastContentInsets() {
4939 mWindowFrames.resetLastContentInsets();
4940 }
4941
4942 Rect getVisibleInsets() {
4943 return mWindowFrames.mVisibleInsets;
4944 }
4945
chaviw1454b392018-08-06 09:54:04 -07004946 @Override
4947 public WindowFrames getWindowFrames() {
4948 return mWindowFrames;
4949 }
4950
4951 void resetContentChanged() {
4952 mWindowFrames.setContentChanged(false);
4953 }
4954
Jorim Jaggif96c90a2018-09-26 16:55:15 +02004955 void setInsetProvider(InsetsSourceProvider insetProvider) {
4956 mInsetProvider = insetProvider;
4957 }
4958
4959 InsetsSourceProvider getInsetProvider() {
4960 return mInsetProvider;
4961 }
4962
Jorim Jaggia5e10572017-11-15 14:36:26 +01004963 private final class MoveAnimationSpec implements AnimationSpec {
4964
4965 private final long mDuration;
4966 private Interpolator mInterpolator;
4967 private Point mFrom = new Point();
4968 private Point mTo = new Point();
4969
4970 private MoveAnimationSpec(int fromX, int fromY, int toX, int toY) {
4971 final Animation anim = AnimationUtils.loadAnimation(mContext,
4972 com.android.internal.R.anim.window_move_from_decor);
Jorim Jaggi08f75cf2018-01-08 14:38:53 +01004973 mDuration = (long)
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004974 (anim.computeDurationHint() * mWmService.getWindowAnimationScaleLocked());
Jorim Jaggia5e10572017-11-15 14:36:26 +01004975 mInterpolator = anim.getInterpolator();
4976 mFrom.set(fromX, fromY);
4977 mTo.set(toX, toY);
4978 }
4979
4980 @Override
4981 public long getDuration() {
4982 return mDuration;
4983 }
4984
4985 @Override
4986 public void apply(Transaction t, SurfaceControl leash, long currentPlayTime) {
4987 final float fraction = (float) currentPlayTime / getDuration();
4988 final float v = mInterpolator.getInterpolation(fraction);
4989 t.setPosition(leash, mFrom.x + (mTo.x - mFrom.x) * v,
4990 mFrom.y + (mTo.y - mFrom.y) * v);
4991 }
Jorim Jaggif75d1612018-02-27 15:05:21 +01004992
4993 @Override
4994 public void dump(PrintWriter pw, String prefix) {
chaviwc65fa582018-08-09 15:33:13 -07004995 pw.println(prefix + "from=" + mFrom
4996 + " to=" + mTo
4997 + " duration=" + mDuration);
Jorim Jaggif75d1612018-02-27 15:05:21 +01004998 }
4999
5000 @Override
5001 public void writeToProtoInner(ProtoOutputStream proto) {
5002 final long token = proto.start(MOVE);
5003 mFrom.writeToProto(proto, FROM);
5004 mTo.writeToProto(proto, TO);
Kweku Adams21b8d262018-03-30 12:19:58 -07005005 proto.write(DURATION_MS, mDuration);
Jorim Jaggif75d1612018-02-27 15:05:21 +01005006 proto.end(token);
5007 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01005008 }
satokcef37fb2011-10-24 21:49:38 +09005009}