blob: 706901bb97850abf5df3d3e0d7f5ec7eaa1154b0 [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;
Wale Ogunwaled1880962016-11-08 10:31:59 -0800208import java.util.function.Predicate;
Wale Ogunwale053c8e42015-11-16 14:27:21 -0800209
Wale Ogunwaled90546a2016-09-09 23:28:03 -0700210/** A window in the window manager. */
211class WindowState extends WindowContainer<WindowState> implements WindowManagerPolicy.WindowState {
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -0800212 static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800213
Skuhne81c524a2015-08-12 13:34:14 -0700214 // The minimal size of a window within the usable area of the freeform stack.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700215 // TODO(multi-window): fix the min sizes when we have mininum width/height support,
216 // use hard-coded min sizes for now.
217 static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
218 static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
Skuhnef932e562015-08-20 12:07:30 -0700219
220 // The thickness of a window resize handle outside the window bounds on the free form workspace
221 // to capture touch events in that area.
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700222 static final int RESIZE_HANDLE_WIDTH_IN_DP = 30;
Skuhnef932e562015-08-20 12:07:30 -0700223
Craig Mautnere7ae2502012-03-26 17:11:19 -0700224 final WindowManagerPolicy mPolicy;
225 final Context mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800226 final Session mSession;
227 final IWindow mClient;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800228 final int mAppOp;
229 // UserId and appId of the owner. Don't display windows of non-current user.
230 final int mOwnerUid;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800231 /** The owner has {@link android.Manifest.permission#INTERNAL_SYSTEM_WINDOW} */
232 final boolean mOwnerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200233 final WindowId mWindowId;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800234 WindowToken mToken;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700235 // The same object as mToken if this is an app window and null for non-app windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800236 AppWindowToken mAppToken;
Craig Mautnerd09cc4b2012-04-04 10:23:31 -0700237
238 // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
239 // modified they will need to be locked.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800240 final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
241 final DeathRecipient mDeathRecipient;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700242 private boolean mIsChildWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800243 final int mBaseLayer;
244 final int mSubLayer;
245 final boolean mLayoutAttached;
246 final boolean mIsImWindow;
247 final boolean mIsWallpaper;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700248 private final boolean mIsFloatingLayer;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700249 int mSeq;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800250 int mViewVisibility;
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700251 int mSystemUiVisibility;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700252 /**
253 * The visibility of the window based on policy like {@link WindowManagerPolicy}.
254 * Normally set by calling {@link #showLw} and {@link #hideLw}.
255 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800256 boolean mPolicyVisibility = true;
Wale Ogunwale571771c2016-08-26 13:18:50 -0700257 /**
258 * What {@link #mPolicyVisibility} should be set to after a transition animation.
259 * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and
260 * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit
261 * animation is done.
262 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800263 boolean mPolicyVisibilityAfterAnim = true;
Suprabh Shukla69c71422018-04-02 18:39:01 -0700264 // overlay window is hidden because the owning app is suspended
265 private boolean mHiddenWhileSuspended;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700266 private boolean mAppOpVisibility = true;
Svetoslav Ganovaa076532016-08-01 19:16:43 -0700267 boolean mPermanentlyHidden; // the window should never be shown again
Wale Ogunwale01ad4342017-06-30 07:07:01 -0700268 // This is a non-system overlay window that is currently force hidden.
269 private boolean mForceHideNonSystemOverlayWindow;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800270 boolean mAppFreezing;
chaviwebcbc342018-02-07 13:19:00 -0800271 boolean mHidden = true; // Used to determine if to show child windows.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800272 boolean mWallpaperVisible; // for wallpaper, what was last vis report?
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700273 private boolean mDragResizing;
Jorim Jaggidc9385a2017-05-13 02:00:31 +0200274 private boolean mDragResizingChangeReported = true;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700275 private int mResizeMode;
Vishnu Nair83537a72018-07-19 21:27:48 -0700276 /**
277 * Special mode that is intended only for the rounded corner overlay: during rotation
278 * transition, we un-rotate the window token such that the window appears as it did before the
279 * rotation.
Vishnu Nair83537a72018-07-19 21:27:48 -0700280 */
281 final boolean mForceSeamlesslyRotate;
Vishnu Nairddd80742018-08-21 14:12:46 -0700282 SeamlessRotator mPendingSeamlessRotate;
283 long mFinishSeamlessRotateFrameNumber;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700284
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700285 private RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
Dianne Hackborne3f23a32013-03-01 13:25:35 -0800286
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700287 /**
288 * The window size that was requested by the application. These are in
289 * the application's coordinate space (without compatibility scale applied).
290 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800291 int mRequestedWidth;
292 int mRequestedHeight;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700293 private int mLastRequestedWidth;
294 private int mLastRequestedHeight;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700295
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800296 int mLayer;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800297 boolean mHaveFrame;
298 boolean mObscured;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800299
300 int mLayoutSeq = -1;
Craig Mautnera2c77052012-03-26 12:14:43 -0700301
Andrii Kulian9d91ca62016-09-29 22:28:09 -0700302 /**
303 * Used to store last reported to client configuration and check if we have newer available.
304 * We'll send configuration to client only if it is different from the last applied one and
305 * client won't perform unnecessary updates.
306 */
Bryce Lee2b17afd2017-09-21 10:38:20 -0700307 private final MergedConfiguration mLastReportedConfiguration = new MergedConfiguration();
Craig Mautnera2c77052012-03-26 12:14:43 -0700308
Yunfan Chen75157d72018-07-27 14:47:21 +0900309 private final Configuration mTempConfiguration = new Configuration();
310
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700311 /**
Robert Carr18f622f2017-05-08 11:20:43 -0700312 * The last content insets returned to the client in relayout. We use
313 * these in the bounds animation to ensure we only observe inset changes
314 * at the same time that a client resizes it's surface so that we may use
315 * the geometryAppliesWithResize synchronization mechanism to keep
316 * the contents in place.
317 */
318 final Rect mLastRelayoutContentInsets = new Rect();
319
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700320 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800321 * Set to true if we are waiting for this window to receive its
322 * given internal insets before laying out other windows based on it.
323 */
324 boolean mGivenInsetsPending;
325
326 /**
327 * These are the content insets that were given during layout for
328 * this window, to be applied to windows behind it.
329 */
330 final Rect mGivenContentInsets = new Rect();
331
332 /**
333 * These are the visible insets that were given during layout for
334 * this window, to be applied to windows behind it.
335 */
336 final Rect mGivenVisibleInsets = new Rect();
337
338 /**
339 * This is the given touchable area relative to the window frame, or null if none.
340 */
341 final Region mGivenTouchableRegion = new Region();
342
343 /**
344 * Flag indicating whether the touchable region should be adjusted by
345 * the visible insets; if false the area outside the visible insets is
346 * NOT touchable, so we must use those to adjust the frame during hit
347 * tests.
348 */
349 int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
350
351 // Current transformation being applied.
Dianne Hackborne2515ee2011-04-27 18:52:56 -0400352 float mGlobalScale=1;
Dianne Hackbornffb3d932011-05-17 17:44:51 -0700353 float mInvGlobalScale=1;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800354 float mHScale=1, mVScale=1;
355 float mLastHScale=1, mLastVScale=1;
356 final Matrix mTmpMatrix = new Matrix();
357
chaviw553b0212018-07-12 13:37:01 -0700358 private final WindowFrames mWindowFrames = new WindowFrames();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700359
Jorim Jaggidc249c42015-12-15 14:57:31 -0800360 /**
361 * Usually empty. Set to the task's tempInsetFrame. See
Wale Ogunwale04d9cb52018-04-30 13:55:07 -0700362 *{@link android.app.IActivityTaskManager#resizeDockedStack}.
Jorim Jaggidc249c42015-12-15 14:57:31 -0800363 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700364 private final Rect mInsetFrame = new Rect();
Jorim Jaggidc249c42015-12-15 14:57:31 -0800365
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800366 // If a window showing a wallpaper: the requested offset for the
367 // wallpaper; if a wallpaper window: the currently applied offset.
368 float mWallpaperX = -1;
369 float mWallpaperY = -1;
370
371 // If a window showing a wallpaper: what fraction of the offset
372 // range corresponds to a full virtual screen.
373 float mWallpaperXStep = -1;
374 float mWallpaperYStep = -1;
375
Dianne Hackborn067e5f62014-09-07 23:14:30 -0700376 // If a window showing a wallpaper: a raw pixel offset to forcibly apply
377 // to its window; if a wallpaper window: not used.
378 int mWallpaperDisplayOffsetX = Integer.MIN_VALUE;
379 int mWallpaperDisplayOffsetY = Integer.MIN_VALUE;
380
Craig Mautner2268e7e2012-12-13 15:40:00 -0800381 /**
382 * This is set after IWindowSession.relayout() has been called at
383 * least once for the window. It allows us to detect the situation
384 * where we don't yet have a surface, but should have one soon, so
385 * we can give the window focus before waiting for the relayout.
386 */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800387 boolean mRelayoutCalled;
388
Robert Carrfed10072016-05-26 11:48:49 -0700389 boolean mInRelayout;
390
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800391 /**
392 * If the application has called relayout() with changes that can
393 * impact its window's size, we need to perform a layout pass on it
394 * even if it is not currently visible for layout. This is set
395 * when in that case until the layout is done.
396 */
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -0800397 boolean mLayoutNeeded;
398
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800399 /** Currently running an exit animation? */
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800400 boolean mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800401
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800402 /** Currently on the mDestroySurface list? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800403 boolean mDestroying;
404
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800405 /** Completely remove from window manager after exit animation? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800406 boolean mRemoveOnExit;
407
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800408 /**
Chong Zhang112eb8c2015-11-02 11:17:00 -0800409 * Whether the app died while it was visible, if true we might need
410 * to continue to show it until it's restarted.
411 */
412 boolean mAppDied;
413
414 /**
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800415 * Set when the orientation is changing and this window has not yet
416 * been updated for the new orientation.
417 */
Bryce Lee8c3cf382017-07-06 19:47:10 -0700418 private boolean mOrientationChanging;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800419
Dianne Hackborna57c6952013-03-29 14:46:40 -0700420 /**
Robert Carr9c1c3a02017-08-08 12:59:01 -0700421 * Sometimes in addition to the mOrientationChanging
422 * flag we report that the orientation is changing
423 * due to a mismatch in current and reported configuration.
424 *
425 * In the case of timeout we still need to make sure we
426 * leave the orientation changing state though, so we
427 * use this as a special time out escape hatch.
428 */
429 private boolean mOrientationChangeTimedOut;
430
431 /**
Robert Carr237028a2016-07-26 10:39:45 -0700432 * The orientation during the last visible call to relayout. If our
433 * current orientation is different, the window can't be ready
434 * to be shown.
435 */
436 int mLastVisibleLayoutRotation = -1;
437
438 /**
Andrii Kulianb2e37802017-01-11 00:36:44 -0800439 * Set when we need to report the orientation change to client to trigger a relayout.
440 */
441 boolean mReportOrientationChanged;
442
443 /**
Dianne Hackborna57c6952013-03-29 14:46:40 -0700444 * How long we last kept the screen frozen.
445 */
446 int mLastFreezeDuration;
447
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800448 /** Is this window now (or just being) removed? */
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800449 boolean mRemoved;
450
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800451 /**
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800452 * It is save to remove the window and destroy the surface because the client requested removal
453 * or some other higher level component said so (e.g. activity manager).
454 * TODO: We should either have different booleans for the removal reason or use a bit-field.
Robert Carre12aece2016-02-02 22:43:27 -0800455 */
Svetoslav Ganov200adfb2016-10-18 13:29:27 -0700456 boolean mWindowRemovalAllowed;
Robert Carre12aece2016-02-02 22:43:27 -0800457
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800458 // Input channel and input window handle used by the input dispatcher.
Jeff Brown9302c872011-07-13 22:51:29 -0700459 final InputWindowHandle mInputWindowHandle;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800460 InputChannel mInputChannel;
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700461 private InputChannel mClientChannel;
Craig Mautner164d4bb2012-11-26 13:51:23 -0800462
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800463 // Used to improve performance of toString()
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700464 private String mStringNameCache;
465 private CharSequence mLastTitle;
466 private boolean mWasExiting;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800467
Craig Mautnera2c77052012-03-26 12:14:43 -0700468 final WindowStateAnimator mWinAnimator;
469
Craig Mautnerc8bc97e2012-04-02 12:54:54 -0700470 boolean mHasSurface = false;
471
Craig Mautner88400d32012-09-30 12:35:45 -0700472 /** When true this window can be displayed on screens owther than mOwnerUid's */
473 private boolean mShowToOwnerOnly;
Craig Mautner9dc52bc2012-08-06 14:15:42 -0700474
Chong Zhang92147042016-05-09 12:47:11 -0700475 // Whether the window was visible when we set the app to invisible last time. WM uses
476 // this as a hint to restore the surface (if available) for early animation next time
477 // the app is brought visible.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700478 private boolean mWasVisibleBeforeClientHidden;
Robert Carr13f7be9e2015-12-02 18:39:45 -0800479
Robert Carra1eb4392015-12-10 12:43:51 -0800480 // This window will be replaced due to relaunch. This allows window manager
481 // to differentiate between simple removal of a window and replacement. In the latter case it
482 // will preserve the old window until the new one is drawn.
483 boolean mWillReplaceWindow = false;
484 // If true, the replaced window was already requested to be removed.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700485 private boolean mReplacingRemoveRequested = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800486 // Whether the replacement of the window should trigger app transition animation.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700487 private boolean mAnimateReplacingWindow = false;
Robert Carra1eb4392015-12-10 12:43:51 -0800488 // If not null, the window that will be used to replace the old one. This is being set when
489 // the window is added and unset when this window reports its first draw.
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700490 private WindowState mReplacementWindow = null;
Robert Carrb439a632016-04-07 22:52:10 -0700491 // For the new window in the replacement transition, if we have
492 // requested to replace without animation, then we should
493 // make sure we also don't apply an enter animation for
494 // the new window.
495 boolean mSkipEnterAnimationForSeamlessReplacement = false;
Chong Zhangbd0d9372015-12-28 15:18:29 -0800496 // Whether this window is being moved via the resize API
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700497 private boolean mMovedByResize;
Robert Carr0d00c2e2016-02-29 17:45:02 -0800498
Jeff Brownc2932a12014-11-20 18:04:05 -0800499 /**
500 * Wake lock for drawing.
501 * Even though it's slightly more expensive to do so, we will use a separate wake lock
502 * for each app that is requesting to draw while dozing so that we can accurately track
503 * who is preventing the system from suspending.
504 * This lock is only acquired on first use.
505 */
Wale Ogunwaled4a00a02016-10-10 11:29:17 -0700506 private PowerManager.WakeLock mDrawLock;
Jeff Brownc2932a12014-11-20 18:04:05 -0800507
Riddle Hsub398da32019-01-21 21:48:16 +0800508 private final Rect mTmpRect = new Rect();
509 private final Point mTmpPoint = new Point();
Wale Ogunwale2b19b602015-09-18 15:14:59 -0700510
Jorim Jaggi8fa45222016-02-19 19:54:39 -0800511 /**
512 * Whether the window was resized by us while it was gone for layout.
513 */
514 boolean mResizedWhileGone = false;
515
Robert Carr6da3cc02016-06-16 15:17:07 -0700516 /**
517 * During seamless rotation we have two phases, first the old window contents
518 * are rotated to look as if they didn't move in the new coordinate system. Then we
519 * have to freeze updates to this layer (to preserve the transformation) until
520 * the resize actually occurs. This is true from when the transformation is set
521 * and false until the transaction to resize is sent.
522 */
523 boolean mSeamlesslyRotated = false;
524
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700525 /**
Robert Carrc91d1c32017-02-15 19:37:46 -0800526 * Surface insets from the previous call to relayout(), used to track
527 * if we are changing the Surface insets.
528 */
529 final Rect mLastSurfaceInsets = new Rect();
530
531 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700532 * A flag set by the {@link WindowState} parent to indicate that the parent has examined this
533 * {@link WindowState} in its overall drawing context. This book-keeping allows the parent to
534 * make sure all children have been considered.
535 */
536 private boolean mDrawnStateEvaluated;
537
Jorim Jaggia5e10572017-11-15 14:36:26 +0100538 private final Point mSurfacePosition = new Point();
539
Bryce Leed390deb2017-06-22 13:14:28 -0700540 /**
Tiger Huang04dc4cc2019-01-17 18:41:41 +0800541 * A region inside of this window to be excluded from touch.
Andrii Kulian4b6599e2018-01-15 17:24:08 -0800542 */
543 private TapExcludeRegionHolder mTapExcludeRegionHolder;
544
545 /**
chaviw40234662018-02-07 09:37:16 -0800546 * Used for testing because the real PowerManager is final.
547 */
548 private PowerManagerWrapper mPowerManagerWrapper;
549
550 /**
chaviwbe43ac82018-04-04 15:14:49 -0700551 * A frame number in which changes requested in this layout will be rendered.
552 */
553 private long mFrameNumber = -1;
554
chaviwc65fa582018-08-09 15:33:13 -0700555 private static final StringBuilder sTmpSB = new StringBuilder();
556
chaviwbe43ac82018-04-04 15:14:49 -0700557 /**
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -0700558 * 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 -0700559 * of z-order and 1 otherwise.
560 */
Griff Hazen51d00d82016-11-22 15:39:24 -0800561 private static final Comparator<WindowState> sWindowSubLayerComparator =
562 new Comparator<WindowState>() {
563 @Override
564 public int compare(WindowState w1, WindowState w2) {
565 final int layer1 = w1.mSubLayer;
566 final int layer2 = w2.mSubLayer;
567 if (layer1 < layer2 || (layer1 == layer2 && layer2 < 0 )) {
568 // We insert the child window into the list ordered by
569 // the sub-layer. For same sub-layers, the negative one
570 // should go below others; the positive one should go
571 // above others.
572 return -1;
573 }
574 return 1;
575 };
576 };
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700577
Robert Carrf59b8dd2017-10-02 18:58:36 -0700578 /**
579 * Indicates whether we have requested a Dim (in the sense of {@link Dimmer}) from our host
580 * container.
581 */
582 private boolean mIsDimming = false;
583
Jorim Jaggif96c90a2018-09-26 16:55:15 +0200584 private @Nullable InsetsSourceProvider mInsetProvider;
585
Robert Carrf59b8dd2017-10-02 18:58:36 -0700586 private static final float DEFAULT_DIM_AMOUNT_DEAD_WINDOW = 0.5f;
587
Vishnu Nairba183352018-11-21 11:16:49 -0800588 void seamlesslyRotateIfAllowed(Transaction transaction, @Rotation int oldRotation,
589 @Rotation int rotation, boolean requested) {
Vishnu Nairddd80742018-08-21 14:12:46 -0700590 // Invisible windows and the wallpaper do not participate in the seamless rotation animation
591 if (!isVisibleNow() || mIsWallpaper) {
592 return;
593 }
Adrian Roosfaa102f2018-08-02 15:56:15 +0200594
Vishnu Nairddd80742018-08-21 14:12:46 -0700595 if (mPendingSeamlessRotate != null) {
596 oldRotation = mPendingSeamlessRotate.getOldRotation();
597 }
598
599 if (mForceSeamlesslyRotate || requested) {
600 mPendingSeamlessRotate = new SeamlessRotator(oldRotation, rotation, getDisplayInfo());
Vishnu Nairec634062018-09-20 20:16:18 -0700601 mPendingSeamlessRotate.unrotate(transaction, this);
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800602 mWmService.markForSeamlessRotation(this, true);
Vishnu Nairddd80742018-08-21 14:12:46 -0700603 }
604 }
605
Vishnu Nairba183352018-11-21 11:16:49 -0800606 void finishSeamlessRotation(boolean timeout) {
Vishnu Nairddd80742018-08-21 14:12:46 -0700607 if (mPendingSeamlessRotate != null) {
Vishnu Nairba183352018-11-21 11:16:49 -0800608 mPendingSeamlessRotate.finish(this, timeout);
Vishnu Nairddd80742018-08-21 14:12:46 -0700609 mFinishSeamlessRotateFrameNumber = getFrameNumber();
610 mPendingSeamlessRotate = null;
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800611 mWmService.markForSeamlessRotation(this, false);
Vishnu Nair83537a72018-07-19 21:27:48 -0700612 }
613 }
614
chaviw40234662018-02-07 09:37:16 -0800615 interface PowerManagerWrapper {
Michael Wrighte3001042019-02-05 00:13:14 +0000616 void wakeUp(long time, @WakeReason int reason, String details);
chaviw40234662018-02-07 09:37:16 -0800617
618 boolean isInteractive();
619
620 }
621
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800622 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
chaviw40234662018-02-07 09:37:16 -0800623 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
624 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow) {
625 this(service, s, c, token, parentWindow, appOp, seq, a, viewVisibility, ownerId,
626 ownerCanAddInternalSystemWindow, new PowerManagerWrapper() {
627 @Override
Michael Wrighte3001042019-02-05 00:13:14 +0000628 public void wakeUp(long time, @WakeReason int reason, String details) {
629 service.mPowerManager.wakeUp(time, reason, details);
chaviw40234662018-02-07 09:37:16 -0800630 }
631
632 @Override
633 public boolean isInteractive() {
634 return service.mPowerManager.isInteractive();
635 }
636 });
637 }
638
639 WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
640 WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
641 int viewVisibility, int ownerId, boolean ownerCanAddInternalSystemWindow,
642 PowerManagerWrapper powerManagerWrapper) {
Jorim Jaggiffe128d2017-11-30 13:54:36 +0100643 super(service);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800644 mSession = s;
645 mClient = c;
Dianne Hackbornc2293022013-02-06 23:14:49 -0800646 mAppOp = appOp;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800647 mToken = token;
Wale Ogunwalea6cc3612016-08-04 07:25:33 -0700648 mAppToken = mToken.asAppWindowToken();
Wale Ogunwaleb699ce02016-07-18 12:05:30 -0700649 mOwnerUid = ownerId;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800650 mOwnerCanAddInternalSystemWindow = ownerCanAddInternalSystemWindow;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +0200651 mWindowId = new WindowId(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800652 mAttrs.copyFrom(a);
Robert Carrb08ed042018-03-12 15:49:08 -0700653 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800654 mViewVisibility = viewVisibility;
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800655 mPolicy = mWmService.mPolicy;
656 mContext = mWmService.mContext;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800657 DeathRecipient deathRecipient = new DeathRecipient();
Dianne Hackborn9a230e02011-10-06 11:51:27 -0700658 mSeq = seq;
chaviw40234662018-02-07 09:37:16 -0800659 mPowerManagerWrapper = powerManagerWrapper;
Vishnu Nair83537a72018-07-19 21:27:48 -0700660 mForceSeamlesslyRotate = token.mRoundedCornerOverlay;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700661 if (localLOGV) Slog.v(
Craig Mautnerd87946b2012-03-29 18:00:19 -0700662 TAG, "Window " + this + " client=" + c.asBinder()
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700663 + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800664 try {
665 c.asBinder().linkToDeath(deathRecipient, 0);
666 } catch (RemoteException e) {
667 mDeathRecipient = null;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700668 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800669 mLayoutAttached = false;
670 mIsImWindow = false;
671 mIsWallpaper = false;
672 mIsFloatingLayer = false;
673 mBaseLayer = 0;
674 mSubLayer = 0;
Jeff Brown9302c872011-07-13 22:51:29 -0700675 mInputWindowHandle = null;
Craig Mautnera2c77052012-03-26 12:14:43 -0700676 mWinAnimator = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800677 return;
678 }
679 mDeathRecipient = deathRecipient;
680
Wale Ogunwale9bc47732016-08-10 14:44:22 -0700681 if (mAttrs.type >= FIRST_SUB_WINDOW && mAttrs.type <= LAST_SUB_WINDOW) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800682 // The multiplier here is to reserve space for multiple
683 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800684 mBaseLayer = mPolicy.getWindowLayerLw(parentWindow)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700685 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800686 mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type);
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700687 mIsChildWindow = true;
takeda.masayuki18735092012-12-12 11:06:24 +0900688
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700689 if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + parentWindow);
690 parentWindow.addChild(this, sWindowSubLayerComparator);
takeda.masayuki18735092012-12-12 11:06:24 +0900691
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800692 mLayoutAttached = mAttrs.type !=
693 WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Wale Ogunwale7ed4d372016-07-09 15:28:55 -0700694 mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
695 || parentWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
696 mIsWallpaper = parentWindow.mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800697 } else {
698 // The multiplier here is to reserve space for multiple
699 // windows in the same type layer.
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800700 mBaseLayer = mPolicy.getWindowLayerLw(this)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700701 * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800702 mSubLayer = 0;
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700703 mIsChildWindow = false;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800704 mLayoutAttached = false;
705 mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
706 || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
707 mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800708 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -0700709 mIsFloatingLayer = mIsImWindow || mIsWallpaper;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800710
Wale Ogunwale72919d22016-12-08 18:58:50 -0800711 if (mAppToken != null && mAppToken.mShowForAllUsers) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700712 // Windows for apps that can show for all users should also show when the device is
713 // locked.
714 mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
Craig Mautner19ab8282014-05-07 10:35:34 -0700715 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800716
Craig Mautner322e4032012-07-13 13:35:20 -0700717 mWinAnimator = new WindowStateAnimator(this);
718 mWinAnimator.mAlpha = a.alpha;
719
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800720 mRequestedWidth = 0;
721 mRequestedHeight = 0;
Dianne Hackborn1743b642012-03-12 17:04:43 -0700722 mLastRequestedWidth = 0;
723 mLastRequestedHeight = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800724 mLayer = 0;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800725 mInputWindowHandle = new InputWindowHandle(
Robert Carre0a353c2018-08-02 16:38:04 -0700726 mAppToken != null ? mAppToken.mInputApplicationHandle : null, c,
Vladislav Kaznacheev3787de12016-12-21 10:36:35 -0800727 getDisplayId());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800728 }
729
730 void attach() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -0700731 if (localLOGV) Slog.v(TAG, "Attaching " + this + " token=" + mToken);
Wale Ogunwale387e4c62017-02-13 09:50:02 -0800732 mSession.windowAddedLocked(mAttrs.packageName);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800733 }
734
Bryce Leed390deb2017-06-22 13:14:28 -0700735 /**
Riddle Hsub398da32019-01-21 21:48:16 +0800736 * @return {@code true} if the application runs in size compatibility mode.
737 * @see android.content.res.CompatibilityInfo#supportsScreen
738 * @see ActivityRecord#inSizeCompatMode
739 */
740 boolean inSizeCompatMode() {
741 return (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0
742 || (mAppToken != null && mAppToken.inSizeCompatMode()
743 // Exclude starting window because it is not displayed by the application.
744 && mAttrs.type != TYPE_APPLICATION_STARTING);
745 }
746
747 /**
Bryce Leed390deb2017-06-22 13:14:28 -0700748 * Returns whether this {@link WindowState} has been considered for drawing by its parent.
749 */
Bryce Lee6311c4b2017-07-06 14:09:29 -0700750 boolean getDrawnStateEvaluated() {
Bryce Leed390deb2017-06-22 13:14:28 -0700751 return mDrawnStateEvaluated;
752 }
753
754 /**
755 * Sets whether this {@link WindowState} has been considered for drawing by its parent. Should
756 * be cleared when detached from parent.
757 */
758 void setDrawnStateEvaluated(boolean evaluated) {
759 mDrawnStateEvaluated = evaluated;
760 }
761
762 @Override
Riddle Hsu3a4bb612019-01-31 00:02:22 +0800763 void onParentChanged() {
764 super.onParentChanged();
Bryce Leed390deb2017-06-22 13:14:28 -0700765 setDrawnStateEvaluated(false /*evaluated*/);
Robert Carr24be9ab2018-04-30 17:54:53 -0700766
767 getDisplayContent().reapplyMagnificationSpec();
Bryce Leed390deb2017-06-22 13:14:28 -0700768 }
769
Craig Mautnera2c77052012-03-26 12:14:43 -0700770 @Override
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800771 public int getOwningUid() {
Dianne Hackbornc2293022013-02-06 23:14:49 -0800772 return mOwnerUid;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800773 }
774
775 @Override
776 public String getOwningPackage() {
777 return mAttrs.packageName;
778 }
779
Wale Ogunwale5cd907d2017-01-26 14:14:08 -0800780 @Override
781 public boolean canAddInternalSystemWindow() {
782 return mOwnerCanAddInternalSystemWindow;
783 }
784
Jorim Jaggif12ec0f2017-08-23 16:14:10 +0200785 @Override
786 public boolean canAcquireSleepToken() {
787 return mSession.mCanAcquireSleepToken;
788 }
789
Jorim Jaggif5834272016-04-04 20:25:41 -0700790 /**
791 * Subtracts the insets calculated by intersecting {@param layoutFrame} with {@param insetFrame}
792 * from {@param frame}. In other words, it applies the insets that would result if
793 * {@param frame} would be shifted to {@param layoutFrame} and then applying the insets from
Andrii Kuliandaea3572016-04-08 13:20:51 -0700794 * {@param insetFrame}. Also it respects {@param displayFrame} in case window has minimum
795 * width/height applied and insets should be overridden.
Jorim Jaggif5834272016-04-04 20:25:41 -0700796 */
Andrii Kuliandaea3572016-04-08 13:20:51 -0700797 private void subtractInsets(Rect frame, Rect layoutFrame, Rect insetFrame, Rect displayFrame) {
798 final int left = Math.max(0, insetFrame.left - Math.max(layoutFrame.left, displayFrame.left));
799 final int top = Math.max(0, insetFrame.top - Math.max(layoutFrame.top, displayFrame.top));
800 final int right = Math.max(0, Math.min(layoutFrame.right, displayFrame.right) - insetFrame.right);
801 final int bottom = Math.max(0, Math.min(layoutFrame.bottom, displayFrame.bottom) - insetFrame.bottom);
Jorim Jaggif5834272016-04-04 20:25:41 -0700802 frame.inset(left, top, right, bottom);
803 }
804
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800805 @Override
Evan Roskyed6767f2018-10-26 17:21:06 -0700806 public Rect getDisplayedBounds() {
807 final Task task = getTask();
808 if (task != null) {
809 Rect bounds = task.getOverrideDisplayedBounds();
810 if (!bounds.isEmpty()) {
811 return bounds;
812 }
813 }
814 return super.getDisplayedBounds();
815 }
816
817 @Override
chaviw1454b392018-08-06 09:54:04 -0700818 public void computeFrameLw() {
Wale Ogunwalec48a3542016-02-19 15:18:45 -0800819 if (mWillReplaceWindow && (mAnimatingExit || !mReplacingRemoveRequested)) {
Filip Gruszczynski55a309f2015-09-04 17:15:01 -0700820 // This window is being replaced and either already got information that it's being
821 // removed or we are still waiting for some information. Because of this we don't
822 // want to apply any more changes to it, so it remains in this state until new window
823 // appears.
824 return;
825 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800826 mHaveFrame = true;
827
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -0700828 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700829 final boolean inFullscreenContainer = inFullscreenContainer();
Robert Carre6275582016-02-29 15:45:45 -0800830 final boolean windowsAreFloating = task != null && task.isFloating();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700831 final DisplayContent dc = getDisplayContent();
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800832
Evan Roskyed6767f2018-10-26 17:21:06 -0700833 mInsetFrame.set(getBounds());
Chong Zhangae35fef2016-03-16 15:56:55 -0700834
Jorim Jaggif5834272016-04-04 20:25:41 -0700835 // Denotes the actual frame used to calculate the insets and to perform the layout. When
836 // resizing in docked mode, we'd like to freeze the layout, so we also need to freeze the
837 // insets temporarily. By the notion of a task having a different layout frame, we can
838 // achieve that while still moving the task around.
839 final Rect layoutContainingFrame;
840 final Rect layoutDisplayFrame;
841
842 // The offset from the layout containing frame to the actual containing frame.
843 final int layoutXDiff;
844 final int layoutYDiff;
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700845 if (inFullscreenContainer || layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800846 // We use the parent frame as the containing frame for fullscreen and child windows
chaviw1454b392018-08-06 09:54:04 -0700847 mWindowFrames.mContainingFrame.set(mWindowFrames.mParentFrame);
848 layoutDisplayFrame = mWindowFrames.mDisplayFrame;
849 layoutContainingFrame = mWindowFrames.mParentFrame;
Jorim Jaggif5834272016-04-04 20:25:41 -0700850 layoutXDiff = 0;
851 layoutYDiff = 0;
Wale Ogunwale79f268d2015-12-18 08:25:47 -0800852 } else {
Evan Roskyed6767f2018-10-26 17:21:06 -0700853 mWindowFrames.mContainingFrame.set(getDisplayedBounds());
Jorim Jaggi0429f352015-12-22 16:29:16 +0100854 if (mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) {
855
856 // If the bounds are frozen, we still want to translate the window freely and only
857 // freeze the size.
858 Rect frozen = mAppToken.mFrozenBounds.peek();
chaviw553b0212018-07-12 13:37:01 -0700859 mWindowFrames.mContainingFrame.right =
860 mWindowFrames.mContainingFrame.left + frozen.width();
861 mWindowFrames.mContainingFrame.bottom =
862 mWindowFrames.mContainingFrame.top + frozen.height();
Jorim Jaggi0429f352015-12-22 16:29:16 +0100863 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -0800864 final WindowState imeWin = mWmService.mRoot.getCurrentInputMethodWindow();
Robert Carrfc03b2b2016-03-31 15:22:02 -0700865 // IME is up and obscuring this window. Adjust the window position so it is visible.
Robert Carr825581a2018-03-30 14:00:53 -0700866 if (imeWin != null && imeWin.isVisibleNow() && isInputMethodTarget()) {
chaviw553b0212018-07-12 13:37:01 -0700867 if (inFreeformWindowingMode() && mWindowFrames.mContainingFrame.bottom
chaviw1454b392018-08-06 09:54:04 -0700868 > mWindowFrames.mContentFrame.bottom) {
Winson Chungd73e94b2017-05-31 16:25:30 -0700869 // In freeform we want to move the top up directly.
870 // TODO: Investigate why this is contentFrame not parentFrame.
chaviw553b0212018-07-12 13:37:01 -0700871 mWindowFrames.mContainingFrame.top -= mWindowFrames.mContainingFrame.bottom
chaviw1454b392018-08-06 09:54:04 -0700872 - mWindowFrames.mContentFrame.bottom;
chaviw553b0212018-07-12 13:37:01 -0700873 } else if (!inPinnedWindowingMode() && mWindowFrames.mContainingFrame.bottom
chaviw1454b392018-08-06 09:54:04 -0700874 > mWindowFrames.mParentFrame.bottom) {
Winson Chungd73e94b2017-05-31 16:25:30 -0700875 // But in docked we want to behave like fullscreen and behave as if the task
876 // were given smaller bounds for the purposes of layout. Skip adjustments for
877 // the pinned stack, they are handled separately in the PinnedStackController.
chaviw1454b392018-08-06 09:54:04 -0700878 mWindowFrames.mContainingFrame.bottom = mWindowFrames.mParentFrame.bottom;
Winson Chungd73e94b2017-05-31 16:25:30 -0700879 }
Craig Mautnerc5a6e442013-06-05 17:22:35 -0700880 }
Skuhne81c524a2015-08-12 13:34:14 -0700881
Robert Carre6275582016-02-29 15:45:45 -0800882 if (windowsAreFloating) {
Chong Zhang65d15d02016-03-14 13:59:32 -0700883 // In floating modes (e.g. freeform, pinned) we have only to set the rectangle
884 // if it wasn't set already. No need to intersect it with the (visible)
Robert Carre6275582016-02-29 15:45:45 -0800885 // "content frame" since it is allowed to be outside the visible desktop.
chaviw553b0212018-07-12 13:37:01 -0700886 if (mWindowFrames.mContainingFrame.isEmpty()) {
chaviw1454b392018-08-06 09:54:04 -0700887 mWindowFrames.mContainingFrame.set(mWindowFrames.mContentFrame);
Skuhne81c524a2015-08-12 13:34:14 -0700888 }
Doris Liu06d582d2015-06-01 13:18:43 -0700889 }
Adrian Roos604ef952018-05-15 20:13:13 +0200890
891 final TaskStack stack = getStack();
892 if (inPinnedWindowingMode() && stack != null
893 && stack.lastAnimatingBoundsWasToFullscreen()) {
894 // PIP edge case: When going from pinned to fullscreen, we apply a
895 // tempInsetFrame for the full task - but we're still at the start of the animation.
896 // To prevent a jump if there's a letterbox, restrict to the parent frame.
chaviw1454b392018-08-06 09:54:04 -0700897 mInsetFrame.intersectUnchecked(mWindowFrames.mParentFrame);
898 mWindowFrames.mContainingFrame.intersectUnchecked(mWindowFrames.mParentFrame);
Adrian Roos604ef952018-05-15 20:13:13 +0200899 }
900
chaviw1454b392018-08-06 09:54:04 -0700901 layoutDisplayFrame = new Rect(mWindowFrames.mDisplayFrame);
chaviw553b0212018-07-12 13:37:01 -0700902 mWindowFrames.mDisplayFrame.set(mWindowFrames.mContainingFrame);
Evan Roskyed6767f2018-10-26 17:21:06 -0700903 layoutXDiff = mInsetFrame.left - mWindowFrames.mContainingFrame.left;
904 layoutYDiff = mInsetFrame.top - mWindowFrames.mContainingFrame.top;
905 layoutContainingFrame = mInsetFrame;
Wale Ogunwale360a8bc2016-10-10 13:25:26 -0700906 mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
chaviw1454b392018-08-06 09:54:04 -0700907 subtractInsets(mWindowFrames.mDisplayFrame, layoutContainingFrame, layoutDisplayFrame,
908 mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700909 if (!layoutInParentFrame()) {
chaviw553b0212018-07-12 13:37:01 -0700910 subtractInsets(mWindowFrames.mContainingFrame, layoutContainingFrame,
chaviw1454b392018-08-06 09:54:04 -0700911 mWindowFrames.mParentFrame, mTmpRect);
912 subtractInsets(mInsetFrame, layoutContainingFrame, mWindowFrames.mParentFrame,
chaviw553b0212018-07-12 13:37:01 -0700913 mTmpRect);
Robert Carrfd2bd1b2016-04-07 13:52:43 -0700914 }
Jorim Jaggif5834272016-04-04 20:25:41 -0700915 layoutDisplayFrame.intersect(layoutContainingFrame);
Craig Mautner967212c2013-04-13 21:10:58 -0700916 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800917
chaviw553b0212018-07-12 13:37:01 -0700918 final int pw = mWindowFrames.mContainingFrame.width();
919 final int ph = mWindowFrames.mContainingFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800920
Dianne Hackborn1743b642012-03-12 17:04:43 -0700921 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
922 mLastRequestedWidth = mRequestedWidth;
923 mLastRequestedHeight = mRequestedHeight;
chaviw1454b392018-08-06 09:54:04 -0700924 mWindowFrames.setContentChanged(true);
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700925 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800926
chaviw492139a2018-07-16 16:07:35 -0700927 final int fw = mWindowFrames.mFrame.width();
928 final int fh = mWindowFrames.mFrame.height();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800929
Jorim Jaggif5834272016-04-04 20:25:41 -0700930 applyGravityAndUpdateFrame(layoutContainingFrame, layoutDisplayFrame);
931
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700932 // Calculate the outsets before the content frame gets shrinked to the window frame.
chaviw1454b392018-08-06 09:54:04 -0700933 mWindowFrames.calculateOutsets();
Filip Gruszczynskiaaf18112015-06-05 13:37:40 -0700934
Craig Mautnera248eee2013-05-07 11:41:27 -0700935 // Make sure the content and visible frames are inside of the
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800936 // final window frame.
chaviw492139a2018-07-16 16:07:35 -0700937 if (windowsAreFloating && !mWindowFrames.mFrame.isEmpty()) {
Robert Carre65a1c42017-02-28 16:52:59 -0800938 // For pinned workspace the frame isn't limited in any particular
939 // way since SystemUI controls the bounds. For freeform however
940 // we want to keep things inside the content frame.
chaviw492139a2018-07-16 16:07:35 -0700941 final Rect limitFrame = task.inPinnedWindowingMode() ? mWindowFrames.mFrame
942 : mWindowFrames.mContentFrame;
Skuhne81c524a2015-08-12 13:34:14 -0700943 // Keep the frame out of the blocked system area, limit it in size to the content area
944 // and make sure that there is always a minimum visible so that the user can drag it
945 // into a usable area..
chaviw492139a2018-07-16 16:07:35 -0700946 final int height = Math.min(mWindowFrames.mFrame.height(), limitFrame.height());
947 final int width = Math.min(limitFrame.width(), mWindowFrames.mFrame.width());
Wale Ogunwale231b06e2015-09-16 12:03:09 -0700948 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
Kazuhiro Inaba63e24d12016-07-14 13:02:55 +0900949 final int minVisibleHeight = Math.min(height, WindowManagerService.dipToPixel(
950 MINIMUM_VISIBLE_HEIGHT_IN_DP, displayMetrics));
951 final int minVisibleWidth = Math.min(width, WindowManagerService.dipToPixel(
952 MINIMUM_VISIBLE_WIDTH_IN_DP, displayMetrics));
Robert Carre65a1c42017-02-28 16:52:59 -0800953 final int top = Math.max(limitFrame.top,
chaviw492139a2018-07-16 16:07:35 -0700954 Math.min( mWindowFrames.mFrame.top, limitFrame.bottom - minVisibleHeight));
Robert Carre65a1c42017-02-28 16:52:59 -0800955 final int left = Math.max(limitFrame.left + minVisibleWidth - width,
chaviw492139a2018-07-16 16:07:35 -0700956 Math.min( mWindowFrames.mFrame.left, limitFrame.right - minVisibleWidth));
957 mWindowFrames.mFrame.set(left, top, left + width, top + height);
958 mWindowFrames.mContentFrame.set( mWindowFrames.mFrame);
chaviw553b0212018-07-12 13:37:01 -0700959 mWindowFrames.mVisibleFrame.set(mWindowFrames.mContentFrame);
960 mWindowFrames.mStableFrame.set(mWindowFrames.mContentFrame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700961 } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
chaviw492139a2018-07-16 16:07:35 -0700962 dc.getDockedDividerController().positionDockedStackedDivider(mWindowFrames.mFrame);
963 mWindowFrames.mContentFrame.set(mWindowFrames.mFrame);
964 if (!mWindowFrames.mFrame.equals(mWindowFrames.mLastFrame)) {
Jorim Jaggi192086e2016-03-11 17:17:03 +0100965 mMovedByResize = true;
Filip Gruszczynskiae100802015-11-11 15:58:03 -0800966 }
Skuhne81c524a2015-08-12 13:34:14 -0700967 } else {
chaviw492139a2018-07-16 16:07:35 -0700968 mWindowFrames.mContentFrame.set(
969 Math.max(mWindowFrames.mContentFrame.left, mWindowFrames.mFrame.left),
970 Math.max(mWindowFrames.mContentFrame.top, mWindowFrames.mFrame.top),
971 Math.min(mWindowFrames.mContentFrame.right, mWindowFrames.mFrame.right),
972 Math.min(mWindowFrames.mContentFrame.bottom, mWindowFrames.mFrame.bottom));
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800973
chaviw492139a2018-07-16 16:07:35 -0700974 mWindowFrames.mVisibleFrame.set(
975 Math.max(mWindowFrames.mVisibleFrame.left, mWindowFrames.mFrame.left),
976 Math.max(mWindowFrames.mVisibleFrame.top, mWindowFrames.mFrame.top),
977 Math.min(mWindowFrames.mVisibleFrame.right, mWindowFrames.mFrame.right),
978 Math.min(mWindowFrames.mVisibleFrame.bottom, mWindowFrames.mFrame.bottom));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -0800979
chaviw492139a2018-07-16 16:07:35 -0700980 mWindowFrames.mStableFrame.set(
981 Math.max(mWindowFrames.mStableFrame.left, mWindowFrames.mFrame.left),
982 Math.max(mWindowFrames.mStableFrame.top, mWindowFrames.mFrame.top),
983 Math.min(mWindowFrames.mStableFrame.right, mWindowFrames.mFrame.right),
984 Math.min(mWindowFrames.mStableFrame.bottom, mWindowFrames.mFrame.bottom));
Skuhne81c524a2015-08-12 13:34:14 -0700985 }
Adrian Roosfa104232014-06-20 16:10:14 -0700986
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -0700987 if (inFullscreenContainer && !windowsAreFloating) {
Jorim Jaggi899327f2016-02-25 20:44:18 -0500988 // Windows that are not fullscreen can be positioned outside of the display frame,
989 // but that is not a reason to provide them with overscan insets.
chaviw9c81e632018-07-31 11:17:52 -0700990 InsetUtils.insetsBetweenFrames(layoutContainingFrame, mWindowFrames.mOverscanFrame,
991 mWindowFrames.mOverscanInsets);
Filip Gruszczynski01ef404d52016-01-28 18:14:27 -0800992 }
Craig Mautnereda67292013-04-28 13:50:14 -0700993
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100994 if (mAttrs.type == TYPE_DOCK_DIVIDER) {
chaviw1454b392018-08-06 09:54:04 -0700995 final WmDisplayCutout c = mWindowFrames.mDisplayCutout.calculateRelativeTo(
chaviw553b0212018-07-12 13:37:01 -0700996 mWindowFrames.mDisplayFrame);
chaviw9c81e632018-07-31 11:17:52 -0700997 mWindowFrames.calculateDockedDividerInsets(c.getDisplayCutout().getSafeInsets());
Jorim Jaggi81fe2d12015-12-21 14:45:18 +0100998 } else {
Bryce Leef3c6a472017-11-14 14:53:06 -0800999 getDisplayContent().getBounds(mTmpRect);
chaviw9c81e632018-07-31 11:17:52 -07001000 mWindowFrames.calculateInsets(windowsAreFloating, inFullscreenContainer, mTmpRect);
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01001001 }
Adrian Roosfa104232014-06-20 16:10:14 -07001002
chaviwcdba9a42018-07-19 11:36:42 -07001003 mWindowFrames.setDisplayCutout(
chaviw1454b392018-08-06 09:54:04 -07001004 mWindowFrames.mDisplayCutout.calculateRelativeTo(mWindowFrames.mFrame));
Jorim Jaggibae2b152018-04-18 17:27:27 +02001005
Jorim Jaggi656f6502016-04-11 21:08:17 -07001006 // Offset the actual frame by the amount layout frame is off.
chaviw9c81e632018-07-31 11:17:52 -07001007 mWindowFrames.offsetFrames(-layoutXDiff, -layoutYDiff);
Jorim Jaggif5834272016-04-04 20:25:41 -07001008
chaviw9c81e632018-07-31 11:17:52 -07001009 mWindowFrames.mCompatFrame.set(mWindowFrames.mFrame);
Riddle Hsub398da32019-01-21 21:48:16 +08001010 if (inSizeCompatMode()) {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001011 // If there is a size compatibility scale being applied to the
1012 // window, we need to apply this to its insets so that they are
1013 // reported to the app in its coordinate space.
chaviw9c81e632018-07-31 11:17:52 -07001014 mWindowFrames.scaleInsets(mInvGlobalScale);
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001015
1016 // Also the scaled frame that we report to the app needs to be
1017 // adjusted to be in its coordinate space.
chaviw9c81e632018-07-31 11:17:52 -07001018 mWindowFrames.mCompatFrame.scale(mInvGlobalScale);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001019 }
1020
chaviw492139a2018-07-16 16:07:35 -07001021 if (mIsWallpaper && (fw != mWindowFrames.mFrame.width()
1022 || fh != mWindowFrames.mFrame.height())) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001023 final DisplayContent displayContent = getDisplayContent();
1024 if (displayContent != null) {
1025 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
chaviw553b0212018-07-12 13:37:01 -07001026 getDisplayContent().mWallpaperController.updateWallpaperOffset(this,
1027 displayInfo.logicalWidth, displayInfo.logicalHeight, false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08001028 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001029 }
1030
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001031 if (DEBUG_LAYOUT || localLOGV) Slog.v(TAG,
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07001032 "Resolving (mRequestedWidth="
1033 + mRequestedWidth + ", mRequestedheight="
1034 + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
chaviw492139a2018-07-16 16:07:35 -07001035 + "): frame=" + mWindowFrames.mFrame.toShortString()
chaviw9c81e632018-07-31 11:17:52 -07001036 + " " + mWindowFrames.getInsetsInfo());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001037 }
1038
Bryce Leef3c6a472017-11-14 14:53:06 -08001039 // TODO: Look into whether this override is still necessary.
1040 @Override
1041 public Rect getBounds() {
1042 if (isInMultiWindowMode()) {
1043 return getTask().getBounds();
1044 } else if (mAppToken != null){
1045 return mAppToken.getBounds();
1046 } else {
1047 return super.getBounds();
1048 }
1049 }
1050
Craig Mautnera2c77052012-03-26 12:14:43 -07001051 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001052 public Rect getFrameLw() {
chaviw492139a2018-07-16 16:07:35 -07001053 return mWindowFrames.mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001054 }
1055
Craig Mautnera2c77052012-03-26 12:14:43 -07001056 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001057 public Rect getDisplayFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001058 return mWindowFrames.mDisplayFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001059 }
1060
Craig Mautnera2c77052012-03-26 12:14:43 -07001061 @Override
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001062 public Rect getOverscanFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001063 return mWindowFrames.mOverscanFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08001064 }
1065
1066 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001067 public Rect getContentFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001068 return mWindowFrames.mContentFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001069 }
1070
Craig Mautnera2c77052012-03-26 12:14:43 -07001071 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001072 public Rect getVisibleFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001073 return mWindowFrames.mVisibleFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001074 }
1075
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001076 Rect getStableFrameLw() {
chaviw553b0212018-07-12 13:37:01 -07001077 return mWindowFrames.mStableFrame;
1078 }
1079
1080 Rect getDecorFrame() {
1081 return mWindowFrames.mDecorFrame;
1082 }
1083
1084 Rect getParentFrame() {
1085 return mWindowFrames.mParentFrame;
1086 }
1087
1088 Rect getContainingFrame() {
1089 return mWindowFrames.mContainingFrame;
Robert Carre4ee8f8a2016-10-31 12:40:15 -07001090 }
1091
chaviwcdba9a42018-07-19 11:36:42 -07001092 WmDisplayCutout getWmDisplayCutout() {
1093 return mWindowFrames.mDisplayCutout;
1094 }
1095
chaviw9c81e632018-07-31 11:17:52 -07001096 void getCompatFrame(Rect outFrame) {
1097 outFrame.set(mWindowFrames.mCompatFrame);
1098 }
1099
1100 void getCompatFrameSize(Rect outFrame) {
1101 outFrame.set(0, 0, mWindowFrames.mCompatFrame.width(), mWindowFrames.mCompatFrame.height());
1102 }
1103
Craig Mautnera2c77052012-03-26 12:14:43 -07001104 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001105 public boolean getGivenInsetsPendingLw() {
1106 return mGivenInsetsPending;
1107 }
1108
Craig Mautnera2c77052012-03-26 12:14:43 -07001109 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001110 public Rect getGivenContentInsetsLw() {
1111 return mGivenContentInsets;
1112 }
1113
Craig Mautnera2c77052012-03-26 12:14:43 -07001114 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001115 public Rect getGivenVisibleInsetsLw() {
1116 return mGivenVisibleInsets;
1117 }
1118
Craig Mautnera2c77052012-03-26 12:14:43 -07001119 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001120 public WindowManager.LayoutParams getAttrs() {
1121 return mAttrs;
1122 }
1123
Craig Mautner812d2ca2012-09-27 15:35:34 -07001124 @Override
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001125 public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001126 return getDisplayContent().getNeedsMenu(this, bottom);
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08001127 }
1128
Craig Mautner19d59bc2012-09-04 11:15:56 -07001129 @Override
Dianne Hackborn9a230e02011-10-06 11:51:27 -07001130 public int getSystemUiVisibility() {
1131 return mSystemUiVisibility;
1132 }
1133
Craig Mautner19d59bc2012-09-04 11:15:56 -07001134 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001135 public int getSurfaceLayer() {
1136 return mLayer;
1137 }
1138
Craig Mautner812d2ca2012-09-27 15:35:34 -07001139 @Override
Selim Cinekd6623612015-05-22 18:56:22 -07001140 public int getBaseType() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07001141 return getTopParentWindow().mAttrs.type;
Selim Cinekd6623612015-05-22 18:56:22 -07001142 }
1143
1144 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001145 public IApplicationToken getAppToken() {
1146 return mAppToken != null ? mAppToken.appToken : null;
1147 }
Craig Mautner19d59bc2012-09-04 11:15:56 -07001148
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001149 @Override
1150 public boolean isVoiceInteraction() {
Wale Ogunwale72919d22016-12-08 18:58:50 -08001151 return mAppToken != null && mAppToken.mVoiceInteraction;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001152 }
1153
Robert Carr31aa98b2016-07-20 15:29:03 -07001154 boolean setReportResizeHints() {
chaviw9c81e632018-07-31 11:17:52 -07001155 return mWindowFrames.setReportResizeHints();
Craig Mautner4c5eb222013-11-18 12:59:05 -08001156 }
1157
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001158 /**
1159 * Adds the window to the resizing list if any of the parameters we use to track the window
1160 * dimensions or insets have changed.
1161 */
1162 void updateResizingWindowIfNeeded() {
1163 final WindowStateAnimator winAnimator = mWinAnimator;
Adrian Roos5251b1d2018-03-23 18:57:43 +01001164 if (!mHasSurface || getDisplayContent().mLayoutSeq != mLayoutSeq || isGoneForLayoutLw()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001165 return;
1166 }
1167
1168 final Task task = getTask();
1169 // In the case of stack bound animations, the window frames will update (unlike other
1170 // animations which just modify various transformation properties). We don't want to
1171 // notify the client of frame changes in this case. Not only is it a lot of churn, but
1172 // the frame may not correspond to the surface size or the onscreen area at various
1173 // phases in the animation, and the client will become sad and confused.
Winson Chung40a5f932017-04-13 16:39:36 -07001174 if (task != null && task.mStack.isAnimatingBounds()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001175 return;
1176 }
1177
chaviw9c81e632018-07-31 11:17:52 -07001178 boolean didFrameInsetsChange = setReportResizeHints();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001179 boolean configChanged = isConfigChanged();
1180 if (DEBUG_CONFIGURATION && configChanged) {
1181 Slog.v(TAG_WM, "Win " + this + " config changed: " + getConfiguration());
1182 }
1183
1184 final boolean dragResizingChanged = isDragResizeChanged()
1185 && !isDragResizingChangeReported();
1186
1187 if (localLOGV) Slog.v(TAG_WM, "Resizing " + this + ": configChanged=" + configChanged
chaviw492139a2018-07-16 16:07:35 -07001188 + " dragResizingChanged=" + dragResizingChanged
1189 + " last=" + mWindowFrames.mLastFrame + " frame=" + mWindowFrames.mFrame);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001190
1191 // We update mLastFrame always rather than in the conditional with the last inset
1192 // variables, because mFrameSizeChanged only tracks the width and height changing.
chaviw492139a2018-07-16 16:07:35 -07001193 mWindowFrames.mLastFrame.set(mWindowFrames.mFrame);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001194
chaviw9c81e632018-07-31 11:17:52 -07001195 if (didFrameInsetsChange
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001196 || winAnimator.mSurfaceResized
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001197 || configChanged
1198 || dragResizingChanged
Andrii Kulianb2e37802017-01-11 00:36:44 -08001199 || mReportOrientationChanged) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001200 if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
1201 Slog.v(TAG_WM, "Resize reasons for w=" + this + ": "
chaviw9c81e632018-07-31 11:17:52 -07001202 + " " + mWindowFrames.getInsetsChangedInfo()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001203 + " surfaceResized=" + winAnimator.mSurfaceResized
1204 + " configChanged=" + configChanged
1205 + " dragResizingChanged=" + dragResizingChanged
chaviw9c81e632018-07-31 11:17:52 -07001206 + " reportOrientationChanged=" + mReportOrientationChanged);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001207 }
1208
1209 // If it's a dead window left on screen, and the configuration changed, there is nothing
1210 // we can do about it. Remove the window now.
1211 if (mAppToken != null && mAppDied) {
1212 mAppToken.removeDeadWindows();
1213 return;
1214 }
1215
Jorim Jaggidc9385a2017-05-13 02:00:31 +02001216 updateLastInsetValues();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001217 mWmService.makeWindowFreezingScreenIfNeededLocked(this);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001218
1219 // If the orientation is changing, or we're starting or ending a drag resizing action,
1220 // then we need to hold off on unfreezing the display until this window has been
1221 // redrawn; to do that, we need to go through the process of getting informed by the
1222 // application when it has finished drawing.
Robert Carr09286c92018-02-15 13:52:31 -08001223 if (getOrientationChanging() || dragResizingChanged) {
Robert Carre13b58e2017-08-31 14:50:44 -07001224 if (DEBUG_ANIM || DEBUG_ORIENTATION || DEBUG_RESIZE) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001225 Slog.v(TAG_WM, "Orientation or resize start waiting for draw"
1226 + ", mDrawState=DRAW_PENDING in " + this
1227 + ", surfaceController " + winAnimator.mSurfaceController);
1228 }
1229 winAnimator.mDrawState = DRAW_PENDING;
1230 if (mAppToken != null) {
1231 mAppToken.clearAllDrawn();
1232 }
1233 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001234 if (!mWmService.mResizingWindows.contains(this)) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001235 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG_WM, "Resizing window " + this);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001236 mWmService.mResizingWindows.add(this);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001237 }
Bryce Lee8c3cf382017-07-06 19:47:10 -07001238 } else if (getOrientationChanging()) {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001239 if (isDrawnLw()) {
1240 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Orientation not waiting for draw in "
1241 + this + ", surfaceController " + winAnimator.mSurfaceController);
Bryce Lee8c3cf382017-07-06 19:47:10 -07001242 setOrientationChanging(false);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001243 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001244 - mWmService.mDisplayFreezeTime);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001245 }
1246 }
1247 }
1248
Bryce Lee8c3cf382017-07-06 19:47:10 -07001249 boolean getOrientationChanging() {
1250 // In addition to the local state flag, we must also consider the difference in the last
1251 // reported configuration vs. the current state. If the client code has not been informed of
1252 // the change, logic dependent on having finished processing the orientation, such as
1253 // unfreezing, could be improperly triggered.
1254 // TODO(b/62846907): Checking against {@link mLastReportedConfiguration} could be flaky as
1255 // this is not necessarily what the client has processed yet. Find a
1256 // better indicator consistent with the client.
Robert Carr926643f2017-08-02 12:01:12 -07001257 return (mOrientationChanging || (isVisible()
Bryce Lee2b17afd2017-09-21 10:38:20 -07001258 && getConfiguration().orientation != getLastReportedConfiguration().orientation))
Robert Carr9c1c3a02017-08-08 12:59:01 -07001259 && !mSeamlesslyRotated
1260 && !mOrientationChangeTimedOut;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001261 }
1262
1263 void setOrientationChanging(boolean changing) {
1264 mOrientationChanging = changing;
Robert Carr9c1c3a02017-08-08 12:59:01 -07001265 mOrientationChangeTimedOut = false;
1266 }
1267
1268 void orientationChangeTimedOut() {
1269 mOrientationChangeTimedOut = true;
Bryce Lee8c3cf382017-07-06 19:47:10 -07001270 }
1271
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001272 DisplayContent getDisplayContent() {
1273 return mToken.getDisplayContent();
Craig Mautnerdf88d732014-01-27 09:21:32 -08001274 }
1275
Adrian Roos5251b1d2018-03-23 18:57:43 +01001276 @Override
1277 void onDisplayChanged(DisplayContent dc) {
1278 super.onDisplayChanged(dc);
1279 // Window was not laid out for this display yet, so make sure mLayoutSeq does not match.
1280 if (dc != null) {
1281 mLayoutSeq = dc.mLayoutSeq - 1;
Brad Stenningaf596412018-04-02 12:03:19 -07001282 mInputWindowHandle.displayId = dc.getDisplayId();
Adrian Roos5251b1d2018-03-23 18:57:43 +01001283 }
1284 }
1285
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001286 DisplayInfo getDisplayInfo() {
Chong Zhang09b21ef2015-09-14 10:20:21 -07001287 final DisplayContent displayContent = getDisplayContent();
1288 return displayContent != null ? displayContent.getDisplayInfo() : null;
1289 }
1290
Jorim Jaggife762342016-10-13 14:33:27 +02001291 @Override
1292 public int getDisplayId() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08001293 final DisplayContent displayContent = getDisplayContent();
1294 if (displayContent == null) {
Brad Stenningaf596412018-04-02 12:03:19 -07001295 return Display.INVALID_DISPLAY;
Craig Mautnerdf88d732014-01-27 09:21:32 -08001296 }
1297 return displayContent.getDisplayId();
Craig Mautner19d59bc2012-09-04 11:15:56 -07001298 }
1299
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001300 Task getTask() {
Bryce Lee6d410262017-02-28 15:30:17 -08001301 return mAppToken != null ? mAppToken.getTask() : null;
Wale Ogunwalee4a0c572015-06-30 08:40:31 -07001302 }
1303
1304 TaskStack getStack() {
1305 Task task = getTask();
1306 if (task != null) {
1307 if (task.mStack != null) {
1308 return task.mStack;
Craig Mautnerf06b8c12013-04-18 14:27:28 -07001309 }
Craig Mautnerd9a22882013-03-16 15:00:36 -07001310 }
Filip Gruszczynski0689ae92015-10-01 12:30:31 -07001311 // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
1312 // associate them with some stack to enable dimming.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07001313 final DisplayContent dc = getDisplayContent();
1314 return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
Craig Mautnerd9a22882013-03-16 15:00:36 -07001315 }
1316
Skuhnef932e562015-08-20 12:07:30 -07001317 /**
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001318 * Retrieves the visible bounds of the window.
Skuhnef932e562015-08-20 12:07:30 -07001319 * @param bounds The rect which gets the bounds.
Skuhnef932e562015-08-20 12:07:30 -07001320 */
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001321 void getVisibleBounds(Rect bounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001322 final Task task = getTask();
1323 boolean intersectWithStackBounds = task != null && task.cropWindowsToStackBounds();
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001324 bounds.setEmpty();
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001325 mTmpRect.setEmpty();
1326 if (intersectWithStackBounds) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08001327 final TaskStack stack = task.mStack;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001328 if (stack != null) {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08001329 stack.getDimBounds(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001330 } else {
1331 intersectWithStackBounds = false;
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001332 }
1333 }
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001334
chaviw553b0212018-07-12 13:37:01 -07001335 bounds.set(mWindowFrames.mVisibleFrame);
Chong Zhang9184ec62015-09-24 12:32:21 -07001336 if (intersectWithStackBounds) {
1337 bounds.intersect(mTmpRect);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001338 }
1339
Wale Ogunwale61b009e2015-09-16 15:43:05 -07001340 if (bounds.isEmpty()) {
chaviw492139a2018-07-16 16:07:35 -07001341 bounds.set(mWindowFrames.mFrame);
Wale Ogunwale2b19b602015-09-18 15:14:59 -07001342 if (intersectWithStackBounds) {
1343 bounds.intersect(mTmpRect);
1344 }
Craig Mautnerbdc748af2013-12-02 14:08:25 -08001345 return;
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001346 }
Craig Mautner4cd0c13f2013-04-16 15:55:52 -07001347 }
1348
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001349 public long getInputDispatchingTimeoutNanos() {
1350 return mAppToken != null
Wale Ogunwale72919d22016-12-08 18:58:50 -08001351 ? mAppToken.mInputDispatchingTimeoutNanos
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001352 : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
1353 }
1354
Craig Mautnere8552142012-11-07 13:55:47 -08001355 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001356 public boolean hasAppShownWindows() {
Craig Mautnerf4120952012-06-21 18:25:39 -07001357 return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001358 }
1359
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001360 boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
1361 if (dsdx < .99999f || dsdx > 1.00001f) return false;
1362 if (dtdy < .99999f || dtdy > 1.00001f) return false;
1363 if (dtdx < -.000001f || dtdx > .000001f) return false;
1364 if (dsdy < -.000001f || dsdy > .000001f) return false;
1365 return true;
1366 }
1367
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001368 void prelayout() {
Riddle Hsub398da32019-01-21 21:48:16 +08001369 if (inSizeCompatMode()) {
1370 mGlobalScale = mToken.getSizeCompatScale();
Andrii Kulian06d07d62017-03-14 11:11:47 -07001371 mInvGlobalScale = 1 / mGlobalScale;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001372 } else {
Dianne Hackbornffb3d932011-05-17 17:44:51 -07001373 mGlobalScale = mInvGlobalScale = 1;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001374 }
1375 }
1376
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001377 @Override
Wale Ogunwale44f21802016-09-02 12:49:48 -07001378 boolean hasContentToDisplay() {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001379 if (!mAppFreezing && isDrawnLw() && (mViewVisibility == View.VISIBLE
lumark588a3e82018-07-20 18:53:54 +08001380 || (isAnimating() && !getDisplayContent().mAppTransition.isTransitionSet()))) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001381 return true;
1382 }
1383
Wale Ogunwale44f21802016-09-02 12:49:48 -07001384 return super.hasContentToDisplay();
1385 }
1386
1387 @Override
1388 boolean isVisible() {
Jorim Jaggicfd6f3b2018-11-07 15:30:18 +01001389 return wouldBeVisibleIfPolicyIgnored() && mPolicyVisibility
1390 // If we don't have a provider, this window isn't used as a window generating
1391 // insets, so nobody can hide it over the inset APIs.
1392 && (mInsetProvider == null || mInsetProvider.isClientVisible());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001393 }
1394
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001395 /**
Jorim Jaggicfd6f3b2018-11-07 15:30:18 +01001396 * @return {@code true} if the window would be visible if we'd ignore policy visibility,
1397 * {@code false} otherwise.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001398 */
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001399 boolean wouldBeVisibleIfPolicyIgnored() {
Jorim Jaggi43530c92017-05-18 01:53:56 +02001400 return mHasSurface && !isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001401 && !mAnimatingExit && !mDestroying && (!mIsWallpaper || mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001402 }
1403
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001404 @Override
1405 public boolean isVisibleLw() {
Wale Ogunwale44f21802016-09-02 12:49:48 -07001406 return isVisible();
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001407 }
1408
1409 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001410 * Is this window visible, ignoring its app token? It is not visible if there is no surface,
1411 * or we are in the process of running an exit animation that will remove the surface.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001412 */
Wale Ogunwale44f21802016-09-02 12:49:48 -07001413 // TODO: Can we consolidate this with #isVisible() or have a more appropriate name for this?
1414 boolean isWinVisibleLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001415 return (mAppToken == null || !mAppToken.hiddenRequested || mAppToken.isSelfAnimating())
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001416 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001417 }
1418
1419 /**
Wale Ogunwale329b7e52016-01-15 15:00:57 -08001420 * The same as isVisible(), but follows the current hidden state of the associated app token,
1421 * not the pending requested hidden state.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001422 */
1423 boolean isVisibleNow() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001424 return (!mToken.isHidden() || mAttrs.type == TYPE_APPLICATION_STARTING)
Jorim Jaggic6ae42a2017-05-08 23:42:02 +02001425 && isVisible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001426 }
1427
1428 /**
1429 * Can this window possibly be a drag/drop target? The test here is
1430 * a combination of the above "visible now" with the check that the
1431 * Input Manager uses when discarding windows from input consideration.
1432 */
1433 boolean isPotentialDragTarget() {
Jeff Browncc4f7db2011-08-30 20:34:48 -07001434 return isVisibleNow() && !mRemoved
1435 && mInputChannel != null && mInputWindowHandle != null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001436 }
1437
1438 /**
1439 * Same as isVisible(), but we also count it as visible between the
1440 * call to IWindowSession.add() and the first relayout().
1441 */
1442 boolean isVisibleOrAdding() {
1443 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf08af32012-05-16 19:43:42 -07001444 return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
Wale Ogunwale9d147902016-07-16 11:58:55 -07001445 && mPolicyVisibility && !isParentWindowHidden()
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001446 && (atoken == null || !atoken.hiddenRequested)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001447 && !mAnimatingExit && !mDestroying;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001448 }
1449
1450 /**
1451 * Is this window currently on-screen? It is on-screen either if it
1452 * is visible or it is currently running an animation before no longer
1453 * being visible.
1454 */
1455 boolean isOnScreen() {
Jorim Jaggiaf221d12016-11-15 14:59:57 -08001456 if (!mHasSurface || mDestroying || !mPolicyVisibility) {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001457 return false;
1458 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001459 final AppWindowToken atoken = mAppToken;
1460 if (atoken != null) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07001461 return ((!isParentWindowHidden() && !atoken.hiddenRequested)
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001462 || isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001463 }
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001464 return !isParentWindowHidden() || isAnimating();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001465 }
1466
1467 /**
Chong Zhang8e4bda92016-05-04 15:08:18 -07001468 * Whether this window's drawn state might affect the drawn states of the app token.
1469 *
Chong Zhang8e4bda92016-05-04 15:08:18 -07001470 * @return true if the window should be considered while evaluating allDrawn flags.
1471 */
Jorim Jaggie7d2b852017-08-28 17:55:15 +02001472 boolean mightAffectAllDrawn() {
1473 final boolean isAppType = mWinAnimator.mAttrType == TYPE_BASE_APPLICATION
1474 || mWinAnimator.mAttrType == TYPE_DRAWN_APPLICATION;
1475 return (isOnScreen() || isAppType) && !mAnimatingExit && !mDestroying;
Chong Zhang8e4bda92016-05-04 15:08:18 -07001476 }
1477
1478 /**
1479 * Whether this window is "interesting" when evaluating allDrawn. If it's interesting,
1480 * it must be drawn before allDrawn can become true.
1481 */
1482 boolean isInteresting() {
1483 return mAppToken != null && !mAppDied
Jorim Jaggib0fc8172017-11-23 17:04:08 +00001484 && (!mAppToken.isFreezingScreen() || !mAppFreezing);
Chong Zhang8e4bda92016-05-04 15:08:18 -07001485 }
1486
1487 /**
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001488 * Like isOnScreen(), but we don't return true if the window is part
1489 * of a transition that has not yet been started.
1490 */
1491 boolean isReadyForDisplay() {
lumark588a3e82018-07-20 18:53:54 +08001492 if (mToken.waitingToShow && getDisplayContent().mAppTransition.isTransitionSet()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001493 return false;
1494 }
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001495 final boolean parentAndClientVisible = !isParentWindowHidden()
1496 && mViewVisibility == View.VISIBLE && !mToken.isHidden();
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001497 return mHasSurface && mPolicyVisibility && !mDestroying
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001498 && (parentAndClientVisible || isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001499 }
1500
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001501 // TODO: Another visibility method that was added late in the release to minimize risk.
1502 @Override
1503 public boolean canAffectSystemUiFlags() {
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001504 final boolean translucent = mAttrs.alpha == 0.0f;
Jorim Jaggi72207752018-01-08 13:16:59 +01001505 if (translucent) {
1506 return false;
1507 }
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001508 if (mAppToken == null) {
1509 final boolean shown = mWinAnimator.getShown();
1510 final boolean exiting = mAnimatingExit || mDestroying;
Jorim Jaggi72207752018-01-08 13:16:59 +01001511 return shown && !exiting;
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001512 } else {
Jorim Jaggi50bf59c2018-03-09 17:29:48 +01001513 final Task task = getTask();
1514 final boolean canFromTask = task != null && task.canAffectSystemUiFlags();
1515 return canFromTask && !mAppToken.isHidden();
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001516 }
Jorim Jaggi23cc9aa2017-05-23 16:05:35 +02001517 }
1518
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001519 /**
1520 * Like isOnScreen, but returns false if the surface hasn't yet
1521 * been drawn.
1522 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001523 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001524 public boolean isDisplayedLw() {
1525 final AppWindowToken atoken = mAppToken;
Craig Mautnerbf90eaa2012-03-15 11:28:53 -07001526 return isDrawnLw() && mPolicyVisibility
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001527 && ((!isParentWindowHidden() && (atoken == null || !atoken.hiddenRequested))
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001528 || isAnimating());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001529 }
1530
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001531 /**
Craig Mautnerae446592012-12-06 19:05:05 -08001532 * Return true if this window or its app token is currently animating.
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001533 */
Craig Mautnere6f7d5052012-10-08 10:34:17 -07001534 @Override
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001535 public boolean isAnimatingLw() {
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001536 return isAnimating();
Dianne Hackborn5c58de32012-04-28 19:52:37 -07001537 }
1538
Craig Mautner812d2ca2012-09-27 15:35:34 -07001539 @Override
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001540 public boolean isGoneForLayoutLw() {
1541 final AppWindowToken atoken = mAppToken;
1542 return mViewVisibility == View.GONE
1543 || !mRelayoutCalled
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001544 || (atoken == null && mToken.isHidden())
Jorim Jaggi8fa45222016-02-19 19:54:39 -08001545 || (atoken != null && atoken.hiddenRequested)
Wale Ogunwale9d147902016-07-16 11:58:55 -07001546 || isParentWindowHidden()
Wale Ogunwalec48a3542016-02-19 15:18:45 -08001547 || (mAnimatingExit && !isAnimatingLw())
Craig Mautner0e415c62013-04-29 16:10:58 -07001548 || mDestroying;
Dianne Hackborncfbf7de2012-01-12 14:05:03 -08001549 }
1550
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001551 /**
1552 * Returns true if the window has a surface that it has drawn a
1553 * complete UI in to.
1554 */
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001555 public boolean isDrawFinishedLw() {
1556 return mHasSurface && !mDestroying &&
Wale Ogunwale9d147902016-07-16 11:58:55 -07001557 (mWinAnimator.mDrawState == COMMIT_DRAW_PENDING
1558 || mWinAnimator.mDrawState == READY_TO_SHOW
1559 || mWinAnimator.mDrawState == HAS_DRAWN);
Craig Mautnerccc9e9b2012-12-11 09:40:34 -08001560 }
1561
1562 /**
1563 * Returns true if the window has a surface that it has drawn a
1564 * complete UI in to.
1565 */
Adrian Roos76d2fe42015-07-09 14:54:08 -07001566 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001567 public boolean isDrawnLw() {
Craig Mautnerc8bc97e2012-04-02 12:54:54 -07001568 return mHasSurface && !mDestroying &&
Wale Ogunwale571771c2016-08-26 13:18:50 -07001569 (mWinAnimator.mDrawState == READY_TO_SHOW || mWinAnimator.mDrawState == HAS_DRAWN);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001570 }
1571
1572 /**
1573 * Return true if the window is opaque and fully drawn. This indicates
1574 * it may obscure windows behind it.
1575 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001576 private boolean isOpaqueDrawn() {
Chong Zhang66bf071d2016-02-05 14:42:36 -08001577 // When there is keyguard, wallpaper could be placed over the secure app
1578 // window but invisible. We need to check wallpaper visibility explicitly
1579 // to determine if it's occluding apps.
1580 return ((!mIsWallpaper && mAttrs.format == PixelFormat.OPAQUE)
1581 || (mIsWallpaper && mWallpaperVisible))
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001582 && isDrawnLw() && !isAnimating();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001583 }
1584
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001585 @Override
1586 void onMovedByResize() {
1587 if (DEBUG_RESIZE) Slog.d(TAG, "onMovedByResize: Moving " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001588 mMovedByResize = true;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001589 super.onMovedByResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001590 }
1591
1592 boolean onAppVisibilityChanged(boolean visible, boolean runningAppAnimation) {
1593 boolean changed = false;
1594
1595 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001596 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001597 changed |= c.onAppVisibilityChanged(visible, runningAppAnimation);
1598 }
1599
1600 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
1601 // Starting window that's exiting will be removed when the animation finishes.
1602 // Mark all relevant flags for that onExitAnimationDone will proceed all the way
1603 // to actually remove it.
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001604 if (!visible && isVisibleNow() && mAppToken.isSelfAnimating()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001605 mAnimatingExit = true;
1606 mRemoveOnExit = true;
1607 mWindowRemovalAllowed = true;
1608 }
1609 return changed;
1610 }
1611
chaviwe390cbd2018-04-16 15:29:38 -07001612 final boolean isVisibleNow = isVisibleNow();
1613 if (visible != isVisibleNow) {
1614 // Run exit animation if:
1615 // 1. App visibility and WS visibility are different
1616 // 2. App is not running an animation
1617 // 3. WS is currently visible
1618 if (!runningAppAnimation && isVisibleNow) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001619 final AccessibilityController accessibilityController =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001620 mWmService.mAccessibilityController;
chaviwe390cbd2018-04-16 15:29:38 -07001621 final int winTransit = TRANSIT_EXIT;
1622 mWinAnimator.applyAnimationLocked(winTransit, false /* isEntrance */);
Rhed Jao02655dc2018-10-30 20:44:52 +08001623 if (accessibilityController != null) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001624 accessibilityController.onWindowTransitionLocked(this, winTransit);
1625 }
1626 }
1627 changed = true;
1628 setDisplayLayoutNeeded();
1629 }
1630
1631 return changed;
1632 }
1633
1634 boolean onSetAppExiting() {
1635 final DisplayContent displayContent = getDisplayContent();
1636 boolean changed = false;
1637
1638 if (isVisibleNow()) {
1639 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
Rhed Jao02655dc2018-10-30 20:44:52 +08001640 if (mWmService.mAccessibilityController != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001641 mWmService.mAccessibilityController.onWindowTransitionLocked(this, TRANSIT_EXIT);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001642 }
1643 changed = true;
1644 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07001645 displayContent.setLayoutNeeded();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001646 }
1647 }
1648
1649 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001650 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001651 changed |= c.onSetAppExiting();
1652 }
1653
1654 return changed;
1655 }
1656
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001657 @Override
1658 void onResize() {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001659 final ArrayList<WindowState> resizingWindows = mWmService.mResizingWindows;
Andrii Kulian3dcdf642018-05-23 17:14:00 -07001660 if (mHasSurface && !isGoneForLayoutLw() && !resizingWindows.contains(this)) {
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001661 if (DEBUG_RESIZE) Slog.d(TAG, "onResize: Resizing " + this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001662 resizingWindows.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001663 }
1664 if (isGoneForLayoutLw()) {
1665 mResizedWhileGone = true;
1666 }
1667
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001668 super.onResize();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001669 }
1670
1671 void onUnfreezeBounds() {
1672 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001673 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001674 c.onUnfreezeBounds();
1675 }
1676
1677 if (!mHasSurface) {
1678 return;
1679 }
1680
1681 mLayoutNeeded = true;
1682 setDisplayLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001683 if (!mWmService.mResizingWindows.contains(this)) {
1684 mWmService.mResizingWindows.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001685 }
1686 }
1687
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001688 /**
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001689 * If the window has moved due to its containing content frame changing, then notify the
1690 * listeners and optionally animate it. Simply checking a change of position is not enough,
1691 * because being move due to dock divider is not a trigger for animation.
1692 */
chaviw161ea3e2018-01-31 12:01:12 -08001693 void handleWindowMovedIfNeeded() {
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001694 if (!hasMoved()) {
1695 return;
1696 }
1697
1698 // Frame has moved, containing content frame has also moved, and we're not currently
1699 // animating... let's do something.
chaviw492139a2018-07-16 16:07:35 -07001700 final int left = mWindowFrames.mFrame.left;
1701 final int top = mWindowFrames.mFrame.top;
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001702 final Task task = getTask();
1703 final boolean adjustedForMinimizedDockOrIme = task != null
1704 && (task.mStack.isAdjustedForMinimizedDockedStack()
1705 || task.mStack.isAdjustedForIme());
David Stevens9440dc82017-03-16 19:00:20 -07001706 if (mToken.okToAnimate()
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001707 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
1708 && !isDragResizing() && !adjustedForMinimizedDockOrIme
Wale Ogunwale3382ab12017-07-27 08:55:03 -07001709 && getWindowConfiguration().hasMovementAnimations()
Adrian Roos0e7b70a2018-06-07 15:29:34 +02001710 && !mWinAnimator.mLastHidden
1711 && !mSeamlesslyRotated) {
chaviw161ea3e2018-01-31 12:01:12 -08001712 startMoveAnimation(left, top);
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001713 }
1714
1715 //TODO (multidisplay): Accessibility supported only for the default display.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001716 if (mWmService.mAccessibilityController != null
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001717 && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001718 mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001719 }
1720
1721 try {
1722 mClient.moved(left, top);
1723 } catch (RemoteException e) {
1724 }
1725 mMovedByResize = false;
1726 }
1727
1728 /**
Craig Mautner4557c082015-04-27 13:07:40 -07001729 * Return whether this window has moved. (Only makes
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001730 * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
1731 */
Wale Ogunwale9d9d8f12016-09-28 15:29:59 -07001732 private boolean hasMoved() {
chaviw1454b392018-08-06 09:54:04 -07001733 return mHasSurface && (mWindowFrames.hasContentChanged() || mMovedByResize)
Robert Carrc67c2a92016-09-22 13:25:45 -07001734 && !mAnimatingExit
chaviw492139a2018-07-16 16:07:35 -07001735 && (mWindowFrames.mFrame.top != mWindowFrames.mLastFrame.top
1736 || mWindowFrames.mFrame.left != mWindowFrames.mLastFrame.left)
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001737 && (!mIsChildWindow || !getParentWindow().hasMoved());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001738 }
1739
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001740 boolean isObscuringDisplay() {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001741 Task task = getTask();
Wale Ogunwale14a3fb92016-09-11 15:19:05 -07001742 if (task != null && task.mStack != null && !task.mStack.fillsParent()) {
Chong Zhang0abb20f2015-11-19 14:17:31 -08001743 return false;
1744 }
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001745 return isOpaqueDrawn() && fillsDisplay();
Chong Zhang0abb20f2015-11-19 14:17:31 -08001746 }
1747
Wale Ogunwaleca9e0612016-12-02 07:45:59 -08001748 boolean fillsDisplay() {
1749 final DisplayInfo displayInfo = getDisplayInfo();
chaviw492139a2018-07-16 16:07:35 -07001750 return mWindowFrames.mFrame.left <= 0 && mWindowFrames.mFrame.top <= 0
1751 && mWindowFrames.mFrame.right >= displayInfo.appWidth
1752 && mWindowFrames.mFrame.bottom >= displayInfo.appHeight;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001753 }
1754
Andrii Kulian9d91ca62016-09-29 22:28:09 -07001755 /** Returns true if last applied config was not yet requested by client. */
Craig Mautner812d2ca2012-09-27 15:35:34 -07001756 boolean isConfigChanged() {
Bryce Lee2b17afd2017-09-21 10:38:20 -07001757 return !getLastReportedConfiguration().equals(getConfiguration());
Craig Mautner812d2ca2012-09-27 15:35:34 -07001758 }
1759
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001760 void onWindowReplacementTimeout() {
1761 if (mWillReplaceWindow) {
1762 // Since the window already timed out, remove it immediately now.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001763 // Use WindowState#removeImmediately() instead of WindowState#removeIfPossible(), as the latter
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001764 // delays removal on certain conditions, which will leave the stale window in the
1765 // stack and marked mWillReplaceWindow=false, so the window will never be removed.
1766 //
1767 // Also removes child windows.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001768 removeImmediately();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001769 } else {
1770 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07001771 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001772 c.onWindowReplacementTimeout();
1773 }
1774 }
1775 }
1776
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001777 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001778 void forceWindowsScaleableInTransaction(boolean force) {
1779 if (mWinAnimator != null && mWinAnimator.hasSurface()) {
1780 mWinAnimator.mSurfaceController.forceScaleableInTransaction(force);
1781 }
1782
Wale Ogunwaled1c37912016-08-16 03:19:39 -07001783 super.forceWindowsScaleableInTransaction(force);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001784 }
1785
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001786 @Override
Wale Ogunwale571771c2016-08-26 13:18:50 -07001787 void removeImmediately() {
1788 super.removeImmediately();
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07001789
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001790 if (mRemoved) {
1791 // Nothing to do.
Wale Ogunwale571771c2016-08-26 13:18:50 -07001792 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1793 "WS.removeImmediately: " + this + " Already removed...");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001794 return;
1795 }
1796
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001797 mRemoved = true;
1798
Wale Ogunwale9bc47732016-08-10 14:44:22 -07001799 mWillReplaceWindow = false;
1800 if (mReplacementWindow != null) {
1801 mReplacementWindow.mSkipEnterAnimationForSeamlessReplacement = false;
1802 }
1803
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001804 final DisplayContent dc = getDisplayContent();
Robert Carr825581a2018-03-30 14:00:53 -07001805 if (isInputMethodTarget()) {
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001806 dc.computeImeTarget(true /* updateImeTarget */);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001807 }
1808
1809 final int type = mAttrs.type;
1810 if (WindowManagerService.excludeWindowTypeFromTapOutTask(type)) {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07001811 dc.mTapExcludedWindows.remove(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001812 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001813 if (mTapExcludeRegionHolder != null) {
1814 // If a tap exclude region container was initialized for this window, then it should've
1815 // also been registered in display.
1816 dc.mTapExcludeProvidingWindows.remove(this);
1817 }
Tiger Huang7c610aa2018-10-27 00:01:01 +08001818 dc.getDisplayPolicy().removeWindowLw(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001819
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001820 disposeInputChannel();
Craig Mautner164d4bb2012-11-26 13:51:23 -08001821
Craig Mautner96868332012-12-04 14:29:11 -08001822 mWinAnimator.destroyDeferredSurfaceLocked();
1823 mWinAnimator.destroySurfaceLocked();
Wale Ogunwale943002b2017-02-15 19:34:01 -08001824 mSession.windowRemovedLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001825 try {
1826 mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
1827 } catch (RuntimeException e) {
1828 // Ignore if it has already been removed (usually because
1829 // we are doing this as part of processing a death note.)
1830 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07001831
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001832 mWmService.postWindowRemoveCleanupLocked(this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08001833 }
Jeff Browncc4f7db2011-08-30 20:34:48 -07001834
Wale Ogunwale571771c2016-08-26 13:18:50 -07001835 @Override
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001836 void removeIfPossible() {
Wale Ogunwale571771c2016-08-26 13:18:50 -07001837 super.removeIfPossible();
Wale Ogunwale92fc3722016-08-05 12:19:08 -07001838 removeIfPossible(false /*keepVisibleDeadWindow*/);
1839 }
1840
Wale Ogunwale571771c2016-08-26 13:18:50 -07001841 private void removeIfPossible(boolean keepVisibleDeadWindow) {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001842 mWindowRemovalAllowed = true;
1843 if (DEBUG_ADD_REMOVE) Slog.v(TAG,
1844 "removeIfPossible: " + this + " callers=" + Debug.getCallers(5));
1845
1846 final boolean startingWindow = mAttrs.type == TYPE_APPLICATION_STARTING;
1847 if (startingWindow && DEBUG_STARTING_WINDOW) Slog.d(TAG_WM,
1848 "Starting window removed " + this);
1849
Tiger Huang1e5b10a2018-07-30 20:19:51 +08001850 if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && isFocused())
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001851 Slog.v(TAG_WM, "Remove " + this + " client="
1852 + Integer.toHexString(System.identityHashCode(mClient.asBinder()))
1853 + ", surfaceController=" + mWinAnimator.mSurfaceController + " Callers="
1854 + Debug.getCallers(5));
1855
1856 final long origId = Binder.clearCallingIdentity();
1857
Peter Visontay3556a3b2017-11-01 17:23:17 +00001858 try {
1859 disposeInputChannel();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001860
Peter Visontay3556a3b2017-11-01 17:23:17 +00001861 if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Remove " + this
1862 + ": mSurfaceController=" + mWinAnimator.mSurfaceController
1863 + " mAnimatingExit=" + mAnimatingExit
1864 + " mRemoveOnExit=" + mRemoveOnExit
1865 + " mHasSurface=" + mHasSurface
1866 + " surfaceShowing=" + mWinAnimator.getShown()
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001867 + " animating=" + isAnimating()
Peter Visontay3556a3b2017-11-01 17:23:17 +00001868 + " app-animation="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001869 + (mAppToken != null ? mAppToken.isSelfAnimating() : "false")
Peter Visontay3556a3b2017-11-01 17:23:17 +00001870 + " mWillReplaceWindow=" + mWillReplaceWindow
1871 + " inPendingTransaction="
1872 + (mAppToken != null ? mAppToken.inPendingTransaction : false)
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001873 + " mDisplayFrozen=" + mWmService.mDisplayFrozen
Peter Visontay3556a3b2017-11-01 17:23:17 +00001874 + " callers=" + Debug.getCallers(6));
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001875
Peter Visontay3556a3b2017-11-01 17:23:17 +00001876 // Visibility of the removed window. Will be used later to update orientation later on.
1877 boolean wasVisible = false;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001878
Peter Visontay3556a3b2017-11-01 17:23:17 +00001879 final int displayId = getDisplayId();
Andrii Kulian5406e7a2016-10-21 11:55:23 -07001880
Peter Visontay3556a3b2017-11-01 17:23:17 +00001881 // First, see if we need to run an animation. If we do, we have to hold off on removing the
1882 // window until the animation is done. If the display is frozen, just remove immediately,
1883 // since the animation wouldn't be seen.
1884 if (mHasSurface && mToken.okToAnimate()) {
1885 if (mWillReplaceWindow) {
1886 // This window is going to be replaced. We need to keep it around until the new one
1887 // gets added, then we will get rid of this one.
1888 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1889 "Preserving " + this + " until the new one is " + "added");
1890 // TODO: We are overloading mAnimatingExit flag to prevent the window state from
1891 // been removed. We probably need another flag to indicate that window removal
1892 // should be deffered vs. overloading the flag that says we are playing an exit
1893 // animation.
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001894 mAnimatingExit = true;
Peter Visontay3556a3b2017-11-01 17:23:17 +00001895 mReplacingRemoveRequested = true;
1896 return;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001897 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001898
Peter Visontay3556a3b2017-11-01 17:23:17 +00001899 // If we are not currently running the exit animation, we need to see about starting one
1900 wasVisible = isWinVisibleLw();
1901
1902 if (keepVisibleDeadWindow) {
1903 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1904 "Not removing " + this + " because app died while it's visible");
1905
1906 mAppDied = true;
1907 setDisplayLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001908 mWmService.mWindowPlacerLocked.performSurfacePlacement();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001909
1910 // Set up a replacement input channel since the app is now dead.
1911 // We need to catch tapping on the dead window to restart the app.
1912 openInputChannel(null);
Arthur Hung95b38a92018-07-20 18:56:12 +08001913 getDisplayContent().getInputMonitor().updateInputWindowsLw(true /*force*/);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001914 return;
1915 }
1916
1917 if (wasVisible) {
1918 final int transit = (!startingWindow) ? TRANSIT_EXIT : TRANSIT_PREVIEW_DONE;
1919
1920 // Try starting an animation.
1921 if (mWinAnimator.applyAnimationLocked(transit, false)) {
1922 mAnimatingExit = true;
Jorim Jaggif41e8822018-04-06 17:22:03 +02001923
1924 // mAnimatingExit affects canAffectSystemUiFlags(). Run layout such that
1925 // any change from that is performed immediately.
1926 setDisplayLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001927 mWmService.requestTraversal();
Peter Visontay3556a3b2017-11-01 17:23:17 +00001928 }
Rhed Jao02655dc2018-10-30 20:44:52 +08001929 if (mWmService.mAccessibilityController != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001930 mWmService.mAccessibilityController.onWindowTransitionLocked(this, transit);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001931 }
1932 }
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02001933 final boolean isAnimating = isAnimating()
Jorim Jaggif5f9e122017-10-24 18:21:09 +02001934 && (mAppToken == null || !mAppToken.isWaitingForTransitionStart());
Peter Visontay3556a3b2017-11-01 17:23:17 +00001935 final boolean lastWindowIsStartingWindow = startingWindow && mAppToken != null
1936 && mAppToken.isLastWindow(this);
1937 // We delay the removal of a window if it has a showing surface that can be used to run
1938 // exit animation and it is marked as exiting.
1939 // Also, If isn't the an animating starting window that is the last window in the app.
1940 // We allow the removal of the non-animating starting window now as there is no
1941 // additional window or animation that will trigger its removal.
1942 if (mWinAnimator.getShown() && mAnimatingExit
1943 && (!lastWindowIsStartingWindow || isAnimating)) {
1944 // The exit animation is running or should run... wait for it!
1945 if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
1946 "Not removing " + this + " due to exit animation ");
1947 setupWindowForRemoveOnExit();
1948 if (mAppToken != null) {
1949 mAppToken.updateReportedVisibilityLocked();
1950 }
1951 return;
1952 }
1953 }
1954
1955 removeImmediately();
1956 // Removing a visible window will effect the computed orientation
1957 // So just update orientation if needed.
Riddle Hsu4e611772018-10-31 18:58:28 +08001958 if (wasVisible) {
1959 final DisplayContent displayContent = getDisplayContent();
1960 if (displayContent.updateOrientationFromAppTokens()) {
1961 displayContent.sendNewConfiguration();
1962 }
Peter Visontay3556a3b2017-11-01 17:23:17 +00001963 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001964 mWmService.updateFocusedWindowLocked(isFocused()
Tiger Huang8af6ba42018-06-07 19:24:09 +08001965 ? UPDATE_FOCUS_REMOVING_FOCUS
1966 : UPDATE_FOCUS_NORMAL,
1967 true /*updateInputWindows*/);
Peter Visontay3556a3b2017-11-01 17:23:17 +00001968 } finally {
1969 Binder.restoreCallingIdentity(origId);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001970 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001971 }
1972
1973 private void setupWindowForRemoveOnExit() {
1974 mRemoveOnExit = true;
1975 setDisplayLayoutNeeded();
1976 // Request a focus update as this window's input channel is already gone. Otherwise
1977 // we could have no focused window in input manager.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001978 final boolean focusChanged = mWmService.updateFocusedWindowLocked(
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001979 UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08001980 mWmService.mWindowPlacerLocked.performSurfacePlacement();
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001981 if (focusChanged) {
Arthur Hung95b38a92018-07-20 18:56:12 +08001982 getDisplayContent().getInputMonitor().updateInputWindowsLw(false /*force*/);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07001983 }
1984 }
1985
Filip Gruszczynski10a80e02015-11-06 09:21:17 -08001986 void setHasSurface(boolean hasSurface) {
1987 mHasSurface = hasSurface;
1988 }
1989
Wale Ogunwale6213caa2016-12-02 16:47:15 +00001990 boolean canBeImeTarget() {
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08001991 if (mIsImWindow) {
1992 // IME windows can't be IME targets. IME targets are required to be below the IME
1993 // windows and that wouldn't be possible if the IME window is its own target...silly.
1994 return false;
1995 }
1996
Winson Chung3d0a74a2017-07-12 12:37:19 -07001997 final boolean windowsAreFocusable = mAppToken == null || mAppToken.windowsAreFocusable();
Winson Chungb1549342017-07-11 09:59:56 -07001998 if (!windowsAreFocusable) {
1999 // This window can't be an IME target if the app's windows should not be focusable.
2000 return false;
2001 }
2002
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002003 final int fl = mAttrs.flags & (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM);
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002004 final int type = mAttrs.type;
2005
Wale Ogunwale805d9ec2016-12-07 12:22:08 -08002006 // Can only be an IME target if both FLAG_NOT_FOCUSABLE and FLAG_ALT_FOCUSABLE_IM are set or
2007 // both are cleared...and not a starting window.
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002008 if (fl != 0 && fl != (FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM)
2009 && type != TYPE_APPLICATION_STARTING) {
2010 return false;
2011 }
2012
2013 if (DEBUG_INPUT_METHOD) {
2014 Slog.i(TAG_WM, "isVisibleOrAdding " + this + ": " + isVisibleOrAdding());
2015 if (!isVisibleOrAdding()) {
2016 Slog.i(TAG_WM, " mSurfaceController=" + mWinAnimator.mSurfaceController
2017 + " relayoutCalled=" + mRelayoutCalled
2018 + " viewVis=" + mViewVisibility
2019 + " policyVis=" + mPolicyVisibility
2020 + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim
2021 + " parentHidden=" + isParentWindowHidden()
2022 + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
2023 if (mAppToken != null) {
2024 Slog.i(TAG_WM, " mAppToken.hiddenRequested=" + mAppToken.hiddenRequested);
2025 }
2026 }
2027 }
2028 return isVisibleOrAdding();
2029 }
2030
Chong Zhangacf11402015-11-04 16:23:10 -08002031 private final class DeadWindowEventReceiver extends InputEventReceiver {
2032 DeadWindowEventReceiver(InputChannel inputChannel) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002033 super(inputChannel, mWmService.mH.getLooper());
Chong Zhangacf11402015-11-04 16:23:10 -08002034 }
2035 @Override
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08002036 public void onInputEvent(InputEvent event) {
Chong Zhangacf11402015-11-04 16:23:10 -08002037 finishInputEvent(event, true);
2038 }
2039 }
2040 /**
2041 * Dummy event receiver for windows that died visible.
2042 */
2043 private DeadWindowEventReceiver mDeadWindowEventReceiver;
2044
Chong Zhang112eb8c2015-11-02 11:17:00 -08002045 void openInputChannel(InputChannel outInputChannel) {
Jeff Browncc4f7db2011-08-30 20:34:48 -07002046 if (mInputChannel != null) {
2047 throw new IllegalStateException("Window already has an input channel.");
2048 }
Wale Ogunwale9adfe572016-09-08 20:43:58 -07002049 String name = getName();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002050 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
2051 mInputChannel = inputChannels[0];
2052 mClientChannel = inputChannels[1];
Robert Carreadae822018-10-11 19:07:03 -07002053 mInputWindowHandle.token = mClient.asBinder();
Chong Zhang112eb8c2015-11-02 11:17:00 -08002054 if (outInputChannel != null) {
2055 mClientChannel.transferTo(outInputChannel);
2056 mClientChannel.dispose();
2057 mClientChannel = null;
Chong Zhangacf11402015-11-04 16:23:10 -08002058 } else {
2059 // If the window died visible, we setup a dummy input channel, so that taps
2060 // can still detected by input monitor channel, and we can relaunch the app.
2061 // Create dummy event receiver that simply reports all events as handled.
2062 mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
Chong Zhang112eb8c2015-11-02 11:17:00 -08002063 }
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002064 mWmService.mInputManager.registerInputChannel(mInputChannel, mClient.asBinder());
Jeff Browncc4f7db2011-08-30 20:34:48 -07002065 }
2066
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002067 void disposeInputChannel() {
Chong Zhangacf11402015-11-04 16:23:10 -08002068 if (mDeadWindowEventReceiver != null) {
2069 mDeadWindowEventReceiver.dispose();
2070 mDeadWindowEventReceiver = null;
2071 }
2072
2073 // unregister server channel first otherwise it complains about broken channel
2074 if (mInputChannel != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002075 mWmService.mInputManager.unregisterInputChannel(mInputChannel);
Robert Carre0a353c2018-08-02 16:38:04 -07002076
Chong Zhangacf11402015-11-04 16:23:10 -08002077 mInputChannel.dispose();
2078 mInputChannel = null;
2079 }
Chong Zhang112eb8c2015-11-02 11:17:00 -08002080 if (mClientChannel != null) {
2081 mClientChannel.dispose();
2082 mClientChannel = null;
2083 }
Robert Carreadae822018-10-11 19:07:03 -07002084 mInputWindowHandle.token = null;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002085 }
2086
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002087 /** Returns true if the replacement window was removed. */
2088 boolean removeReplacedWindowIfNeeded(WindowState replacement) {
2089 if (mWillReplaceWindow && mReplacementWindow == replacement && replacement.hasDrawnLw()) {
2090 replacement.mSkipEnterAnimationForSeamlessReplacement = false;
2091 removeReplacedWindow();
2092 return true;
2093 }
2094
2095 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002096 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002097 if (c.removeReplacedWindowIfNeeded(replacement)) {
2098 return true;
2099 }
2100 }
2101 return false;
2102 }
2103
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002104 private void removeReplacedWindow() {
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002105 if (DEBUG_ADD_REMOVE) Slog.d(TAG, "Removing replaced window: " + this);
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002106 mWillReplaceWindow = false;
2107 mAnimateReplacingWindow = false;
2108 mReplacingRemoveRequested = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002109 mReplacementWindow = null;
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002110 if (mAnimatingExit || !mAnimateReplacingWindow) {
Wale Ogunwale571771c2016-08-26 13:18:50 -07002111 removeImmediately();
Filip Gruszczynski76cc44f2015-09-03 16:03:10 -07002112 }
2113 }
2114
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002115 boolean setReplacementWindowIfNeeded(WindowState replacementCandidate) {
2116 boolean replacementSet = false;
2117
2118 if (mWillReplaceWindow && mReplacementWindow == null
2119 && getWindowTag().toString().equals(replacementCandidate.getWindowTag().toString())) {
2120
2121 mReplacementWindow = replacementCandidate;
2122 replacementCandidate.mSkipEnterAnimationForSeamlessReplacement = !mAnimateReplacingWindow;
2123 replacementSet = true;
2124 }
2125
2126 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002127 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002128 replacementSet |= c.setReplacementWindowIfNeeded(replacementCandidate);
2129 }
2130
2131 return replacementSet;
2132 }
2133
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002134 void setDisplayLayoutNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002135 final DisplayContent dc = getDisplayContent();
2136 if (dc != null) {
2137 dc.setLayoutNeeded();
Filip Gruszczynskie92179d2015-09-26 16:12:30 -07002138 }
2139 }
2140
Chong Zhang5117e272016-05-03 12:47:34 -07002141 void applyAdjustForImeIfNeeded() {
2142 final Task task = getTask();
2143 if (task != null && task.mStack != null && task.mStack.isAdjustedForIme()) {
2144 task.mStack.applyAdjustForImeIfNeeded(task);
2145 }
2146 }
2147
Wale Ogunwale6213caa2016-12-02 16:47:15 +00002148 @Override
2149 void switchUser() {
2150 super.switchUser();
2151 if (isHiddenFromUserLocked()) {
2152 if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
2153 + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
2154 hideLw(false);
2155 }
2156 }
2157
Riddle Hsuff03df52018-12-05 21:43:02 +08002158 int getSurfaceTouchableRegion(Region region, int flags) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002159 final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
Riddle Hsub398da32019-01-21 21:48:16 +08002160 if (mAppToken != null && !mAppToken.getResolvedOverrideBounds().isEmpty()) {
2161 // There may have touchable letterboxes around the activity, so in order to let the
2162 // letterboxes are able to receive touch event and slip to activity, the activity with
2163 // compatibility bounds cannot occupy full screen touchable region.
2164 if (modal) {
2165 // A modal window uses the whole compatibility bounds.
2166 flags |= FLAG_NOT_TOUCH_MODAL;
2167 mTmpRect.set(mAppToken.getResolvedOverrideBounds());
Riddle Hsub398da32019-01-21 21:48:16 +08002168 } else {
2169 // Non-modal uses the application based frame.
2170 mTmpRect.set(mWindowFrames.mCompatFrame);
2171 }
2172 // The offset of compatibility bounds is applied to surface of {@link #AppWindowToken}
2173 // and frame, so it is unnecessary to translate twice in surface based coordinates.
2174 final int surfaceOffsetX = mAppToken.inSizeCompatMode()
2175 ? mAppToken.getBounds().left : 0;
2176 mTmpRect.offset(surfaceOffsetX - mWindowFrames.mFrame.left, -mWindowFrames.mFrame.top);
2177 region.set(mTmpRect);
2178 return flags;
2179 }
2180
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002181 if (modal && mAppToken != null) {
2182 // Limit the outer touch to the activity stack region.
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002183 flags |= FLAG_NOT_TOUCH_MODAL;
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002184 // If this is a modal window we need to dismiss it if it's not full screen and the
2185 // touch happens outside of the frame that displays the content. This means we
2186 // need to intercept touches outside of that window. The dim layer user
2187 // associated with the window (task or stack) will give us the good bounds, as
2188 // they would be used to display the dim layer.
Robert Carrf59b8dd2017-10-02 18:58:36 -07002189 final Task task = getTask();
2190 if (task != null) {
2191 task.getDimBounds(mTmpRect);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002192 } else {
Robert Carrf59b8dd2017-10-02 18:58:36 -07002193 getStack().getDimBounds(mTmpRect);
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002194 }
Wale Ogunwale44f036f2017-09-29 05:09:09 -07002195 if (inFreeformWindowingMode()) {
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002196 // For freeform windows we the touch region to include the whole surface for the
2197 // shadows.
Chong Zhang4c9ba52a2015-11-10 18:36:33 -08002198 final DisplayMetrics displayMetrics = getDisplayContent().getDisplayMetrics();
2199 final int delta = WindowManagerService.dipToPixel(
2200 RESIZE_HANDLE_WIDTH_IN_DP, displayMetrics);
2201 mTmpRect.inset(-delta, -delta);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002202 }
2203 region.set(mTmpRect);
Riddle Hsub5e960f2018-12-07 14:51:26 +08002204 cropRegionToStackBoundsIfNeeded(region);
Tiger Huang04dc4cc2019-01-17 18:41:41 +08002205 subtractTouchExcludeRegionIfNeeded(region);
2206 } else if (modal && mTapExcludeRegionHolder != null) {
2207 final Region touchExcludeRegion = Region.obtain();
2208 amendTapExcludeRegion(touchExcludeRegion);
2209 if (!touchExcludeRegion.isEmpty()) {
2210 // Remove touch modal because there are some areas that cannot be touched.
2211 flags |= FLAG_NOT_TOUCH_MODAL;
2212 // Give it a large touchable region at first because it was touch modal. The window
2213 // might be moved on the display, so the touchable region should be large enough to
2214 // ensure it covers the whole display, no matter where it is moved.
2215 getDisplayContent().getBounds(mTmpRect);
2216 final int dw = mTmpRect.width();
2217 final int dh = mTmpRect.height();
2218 region.set(-dw, -dh, dw + dw, dh + dh);
2219 // Subtract the area that cannot be touched.
2220 region.op(touchExcludeRegion, Region.Op.DIFFERENCE);
2221 }
2222 touchExcludeRegion.recycle();
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002223 } else {
2224 // Not modal or full screen modal
Riddle Hsub5e960f2018-12-07 14:51:26 +08002225 getTouchableRegion(region);
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002226 }
Riddle Hsub5e960f2018-12-07 14:51:26 +08002227 // Translate to surface based coordinates.
2228 region.translate(-mWindowFrames.mFrame.left, -mWindowFrames.mFrame.top);
Robert Carra80ad042018-08-14 12:54:20 -07002229
Filip Gruszczynski9cac3b42015-10-30 14:20:37 -07002230 return flags;
2231 }
2232
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002233 void checkPolicyVisibilityChange() {
2234 if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
2235 if (DEBUG_VISIBILITY) {
2236 Slog.v(TAG, "Policy visibility changing after anim in " +
2237 mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
2238 }
2239 mPolicyVisibility = mPolicyVisibilityAfterAnim;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002240 if (!mPolicyVisibility) {
Jorim Jaggi2e05af22017-12-28 15:15:11 +01002241 mWinAnimator.hide("checkPolicyVisibilityChange");
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002242 if (isFocused()) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002243 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
2244 "setAnimationLocked: setting mFocusMayChange true");
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002245 mWmService.mFocusMayChange = true;
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002246 }
Tetsutoki Shiozawa64c5f0c2018-05-18 10:55:01 +09002247 setDisplayLayoutNeeded();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002248 // Window is no longer visible -- make sure if we were waiting
2249 // for it to be displayed before enabling the display, that
2250 // we allow the display to be enabled now.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002251 mWmService.enableScreenIfNeededLocked();
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002252 }
2253 }
2254 }
2255
2256 void setRequestedSize(int requestedWidth, int requestedHeight) {
2257 if ((mRequestedWidth != requestedWidth || mRequestedHeight != requestedHeight)) {
2258 mLayoutNeeded = true;
2259 mRequestedWidth = requestedWidth;
2260 mRequestedHeight = requestedHeight;
2261 }
2262 }
2263
Bryce Leef858b572017-06-29 14:03:33 -07002264 void prepareWindowToDisplayDuringRelayout(boolean wasVisible) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002265 // We need to turn on screen regardless of visibility.
chaviw40234662018-02-07 09:37:16 -08002266 boolean hasTurnScreenOnFlag = (mAttrs.flags & FLAG_TURN_SCREEN_ON) != 0;
2267 boolean allowTheaterMode =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002268 mWmService.mAllowTheaterModeWakeFromLayout || Settings.Global.getInt(
2269 mWmService.mContext.getContentResolver(), Settings.Global.THEATER_MODE_ON, 0)
chaviw40234662018-02-07 09:37:16 -08002270 == 0;
2271 boolean canTurnScreenOn = mAppToken == null || mAppToken.canTurnScreenOn();
2272
2273 // The screen will turn on if the following conditions are met
2274 // 1. The window has the flag FLAG_TURN_SCREEN_ON
2275 // 2. The WMS allows theater mode.
2276 // 3. No AWT or the AWT allows the screen to be turned on. This should only be true once
2277 // per resume to prevent the screen getting getting turned on for each relayout. Set
2278 // canTurnScreenOn will be set to false so the window doesn't turn the screen on again
2279 // during this resume.
2280 // 4. When the screen is not interactive. This is because when the screen is already
2281 // interactive, the value may persist until the next animation, which could potentially
2282 // be occurring while turning off the screen. This would lead to the screen incorrectly
2283 // turning back on.
chaviw474093d2018-03-07 15:03:38 -08002284 if (hasTurnScreenOnFlag) {
2285 if (allowTheaterMode && canTurnScreenOn && !mPowerManagerWrapper.isInteractive()) {
2286 if (DEBUG_VISIBILITY || DEBUG_POWER) {
2287 Slog.v(TAG, "Relayout window turning screen on: " + this);
2288 }
2289 mPowerManagerWrapper.wakeUp(SystemClock.uptimeMillis(),
Michael Wrighte3001042019-02-05 00:13:14 +00002290 PowerManager.WAKE_REASON_APPLICATION, "android.server.wm:SCREEN_ON_FLAG");
chaviw40234662018-02-07 09:37:16 -08002291 }
chaviwb28de1f2018-03-02 10:42:36 -08002292
2293 if (mAppToken != null) {
2294 mAppToken.setCanTurnScreenOn(false);
2295 }
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002296 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002297
2298 // If we were already visible, skip rest of preparation.
2299 if (wasVisible) {
2300 if (DEBUG_VISIBILITY) Slog.v(TAG,
2301 "Already visible and does not turn on screen, skip preparing: " + this);
2302 return;
2303 }
2304
2305 if ((mAttrs.softInputMode & SOFT_INPUT_MASK_ADJUST)
2306 == SOFT_INPUT_ADJUST_RESIZE) {
2307 mLayoutNeeded = true;
2308 }
2309
David Stevens9440dc82017-03-16 19:00:20 -07002310 if (isDrawnLw() && mToken.okToAnimate()) {
Bryce Leeae73ba42017-05-05 09:58:25 -07002311 mWinAnimator.applyEnterAnimationLocked();
2312 }
Bryce Leef858b572017-06-29 14:03:33 -07002313 }
Bryce Leeae73ba42017-05-05 09:58:25 -07002314
Yunfan Chen75157d72018-07-27 14:47:21 +09002315 private Configuration getProcessGlobalConfiguration() {
2316 // For child windows we want to use the pid for the parent window in case the the child
2317 // window was added from another process.
Yunfan Chen79b96062018-10-17 12:45:23 -07002318 final int pid = getParentWindow() != null ? getParentWindow().mSession.mPid : mSession.mPid;
Yunfan Chenc2ff6cf2018-12-04 16:56:21 -08002319 final Configuration processConfig =
2320 mWmService.mAtmService.getGlobalConfigurationForPid(pid);
2321 mTempConfiguration.setTo(processConfig == null
2322 ? mWmService.mRoot.getConfiguration() : processConfig);
Yunfan Chen75157d72018-07-27 14:47:21 +09002323 return mTempConfiguration;
2324 }
2325
Bryce Leef858b572017-06-29 14:03:33 -07002326 void getMergedConfiguration(MergedConfiguration outConfiguration) {
Yunfan Chen75157d72018-07-27 14:47:21 +09002327 final Configuration globalConfig = getProcessGlobalConfiguration();
Bryce Leef858b572017-06-29 14:03:33 -07002328 final Configuration overrideConfig = getMergedOverrideConfiguration();
2329 outConfiguration.setConfiguration(globalConfig, overrideConfig);
2330 }
2331
Bryce Lee2b17afd2017-09-21 10:38:20 -07002332 void setLastReportedMergedConfiguration(MergedConfiguration config) {
2333 mLastReportedConfiguration.setTo(config);
2334 }
2335
2336 void getLastReportedMergedConfiguration(MergedConfiguration config) {
2337 config.setTo(mLastReportedConfiguration);
2338 }
2339
2340 private Configuration getLastReportedConfiguration() {
2341 return mLastReportedConfiguration.getMergedConfiguration();
Filip Gruszczynski84cc5e32015-11-03 18:05:47 -08002342 }
2343
2344 void adjustStartingWindowFlags() {
2345 if (mAttrs.type == TYPE_BASE_APPLICATION && mAppToken != null
2346 && mAppToken.startingWindow != null) {
2347 // Special handling of starting window over the base
2348 // window of the app: propagate lock screen flags to it,
2349 // to provide the correct semantics while starting.
2350 final int mask = FLAG_SHOW_WHEN_LOCKED | FLAG_DISMISS_KEYGUARD
2351 | FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
2352 WindowManager.LayoutParams sa = mAppToken.startingWindow.mAttrs;
2353 sa.flags = (sa.flags & ~mask) | (mAttrs.flags & mask);
2354 }
2355 }
2356
2357 void setWindowScale(int requestedWidth, int requestedHeight) {
2358 final boolean scaledWindow = (mAttrs.flags & FLAG_SCALED) != 0;
2359
2360 if (scaledWindow) {
2361 // requested{Width|Height} Surface's physical size
2362 // attrs.{width|height} Size on screen
2363 // TODO: We don't check if attrs != null here. Is it implicitly checked?
2364 mHScale = (mAttrs.width != requestedWidth) ?
2365 (mAttrs.width / (float)requestedWidth) : 1.0f;
2366 mVScale = (mAttrs.height != requestedHeight) ?
2367 (mAttrs.height / (float)requestedHeight) : 1.0f;
2368 } else {
2369 mHScale = mVScale = 1;
2370 }
2371 }
2372
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002373 private class DeathRecipient implements IBinder.DeathRecipient {
Craig Mautnere8552142012-11-07 13:55:47 -08002374 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002375 public void binderDied() {
2376 try {
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002377 boolean resetSplitScreenResizing = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002378 synchronized (mWmService.mGlobalLock) {
2379 final WindowState win = mWmService
2380 .windowForClientLocked(mSession, mClient, false);
Craig Mautnerd87946b2012-03-29 18:00:19 -07002381 Slog.i(TAG, "WIN DEATH: " + win);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002382 if (win != null) {
Wale Ogunwale1666e312016-12-16 11:27:18 -08002383 final DisplayContent dc = getDisplayContent();
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002384 if (win.mAppToken != null && win.mAppToken.findMainWindow() == win) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002385 mWmService.mTaskSnapshotController.onAppDied(win.mAppToken);
Jorim Jaggi10abe2f2017-01-03 16:44:46 +01002386 }
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07002387 win.removeIfPossible(shouldKeepVisibleDeadAppWindow());
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002388 if (win.mAttrs.type == TYPE_DOCK_DIVIDER) {
2389 // The owner of the docked divider died :( We reset the docked stack,
Jorim Jaggidcb68142016-02-09 21:51:30 -08002390 // just in case they have the divider at an unstable position. Better
2391 // also reset drag resizing state, because the owner can't do it
2392 // anymore.
Wale Ogunwale61911492017-10-11 08:50:50 -07002393 final TaskStack stack =
Matthew Ng64e77cf2017-10-31 14:01:31 -07002394 dc.getSplitScreenPrimaryStackIgnoringVisibility();
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002395 if (stack != null) {
2396 stack.resetDockedStackToMiddle();
2397 }
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002398 resetSplitScreenResizing = true;
Wale Ogunwalea9f9b372016-02-04 18:04:39 -08002399 }
Craig Mautnerb3b36ba2013-05-20 13:21:10 -07002400 } else if (mHasSurface) {
Craig Mautnera99764e2013-03-06 10:22:16 -08002401 Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
Wale Ogunwale92fc3722016-08-05 12:19:08 -07002402 WindowState.this.removeIfPossible();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002403 }
2404 }
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002405 if (resetSplitScreenResizing) {
2406 try {
2407 // Note: this calls into ActivityManager, so we must *not* hold the window
2408 // manager lock while calling this.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002409 mWmService.mActivityTaskManager.setSplitScreenResizing(false);
Adrian Roosa6d6aab2018-04-19 18:58:22 +02002410 } catch (RemoteException e) {
2411 // Local call, shouldn't return RemoteException.
2412 throw e.rethrowAsRuntimeException();
2413 }
2414 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002415 } catch (IllegalArgumentException ex) {
Wale Ogunwalee42d0e12016-05-02 16:40:59 -07002416 // This will happen if the window has already been removed.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002417 }
2418 }
2419 }
2420
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002421 /**
2422 * Returns true if this window is visible and belongs to a dead app and shouldn't be removed,
2423 * because we want to preserve its location on screen to be re-activated later when the user
2424 * interacts with it.
2425 */
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002426 private boolean shouldKeepVisibleDeadAppWindow() {
Wale Ogunwale89973222017-04-23 18:39:45 -07002427 if (!isWinVisibleLw() || mAppToken == null || mAppToken.isClientHidden()) {
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002428 // Not a visible app window or the app isn't dead.
2429 return false;
2430 }
2431
Wale Ogunwale51d1d912016-05-04 13:27:18 -07002432 if (mAttrs.token != mClient.asBinder()) {
2433 // The window was add by a client using another client's app token. We don't want to
2434 // keep the dead window around for this case since this is meant for 'real' apps.
2435 return false;
2436 }
2437
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002438 if (mAttrs.type == TYPE_APPLICATION_STARTING) {
2439 // We don't keep starting windows since they were added by the window manager before
2440 // the app even launched.
2441 return false;
2442 }
2443
Wale Ogunwale3382ab12017-07-27 08:55:03 -07002444 return getWindowConfiguration().keepVisibleDeadAppWindowOnScreen();
Wale Ogunwale3fd20fe2016-01-23 17:41:28 -08002445 }
2446
Tiger Huang513d5e12018-07-16 21:49:50 +08002447 @Override
2448 public boolean canReceiveKeys() {
Craig Mautner58106812012-12-28 12:27:40 -08002449 return isVisibleOrAdding()
Chong Zhange292eb32016-05-21 09:23:55 -07002450 && (mViewVisibility == View.VISIBLE) && !mRemoveOnExit
Wale Ogunwaled045c822015-12-02 09:14:28 -08002451 && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0)
Jorim Jaggib72c9ad2016-04-11 18:27:58 -07002452 && (mAppToken == null || mAppToken.windowsAreFocusable())
Robert Carrebdf8582018-09-04 14:50:15 -07002453 && !cantReceiveTouchInput();
Matthew Nge15352e2016-12-20 15:36:29 -08002454 }
2455
lumark31e4f8e2019-01-10 20:48:18 +08002456 @Override
2457 public boolean canShowWhenLocked() {
2458 final boolean showBecauseOfActivity =
2459 mAppToken != null && mAppToken.mActivityRecord.canShowWhenLocked();
2460 final boolean showBecauseOfWindow = (getAttrs().flags & FLAG_SHOW_WHEN_LOCKED) != 0;
2461 return showBecauseOfActivity || showBecauseOfWindow;
2462 }
2463
Robert Carrebdf8582018-09-04 14:50:15 -07002464 /** @return false if this window desires touch events. */
2465 boolean cantReceiveTouchInput() {
Bryce Lee6d410262017-02-28 15:30:17 -08002466 return mAppToken != null && mAppToken.getTask() != null
Arthur Hung0b650ba2019-01-30 19:23:53 +08002467 && (mAppToken.getTask().mStack.shouldIgnoreInput() || mAppToken.hiddenRequested);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002468 }
2469
Craig Mautner749a7bb2012-04-02 13:49:53 -07002470 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002471 public boolean hasDrawnLw() {
Craig Mautner749a7bb2012-04-02 13:49:53 -07002472 return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002473 }
2474
Craig Mautner749a7bb2012-04-02 13:49:53 -07002475 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002476 public boolean showLw(boolean doAnimation) {
2477 return showLw(doAnimation, true);
2478 }
2479
2480 boolean showLw(boolean doAnimation, boolean requestAnim) {
Craig Mautner5962b122012-10-05 14:45:52 -07002481 if (isHiddenFromUserLocked()) {
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002482 return false;
2483 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002484 if (!mAppOpVisibility) {
2485 // Being hidden due to app op request.
2486 return false;
2487 }
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002488 if (mPermanentlyHidden) {
2489 // Permanently hidden until the app exists as apps aren't prepared
2490 // to handle their windows being removed from under them.
2491 return false;
2492 }
Suprabh Shukla69c71422018-04-02 18:39:01 -07002493 if (mHiddenWhileSuspended) {
2494 // Being hidden due to owner package being suspended.
2495 return false;
2496 }
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002497 if (mForceHideNonSystemOverlayWindow) {
2498 // This is an alert window that is currently force hidden.
2499 return false;
2500 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002501 if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002502 // Already showing.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002503 return false;
2504 }
Craig Mautnerd87946b2012-03-29 18:00:19 -07002505 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002506 if (doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002507 if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02002508 + mPolicyVisibility + " animating=" + isAnimating());
David Stevens9440dc82017-03-16 19:00:20 -07002509 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002510 doAnimation = false;
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02002511 } else if (mPolicyVisibility && !isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002512 // Check for the case where we are currently visible and
2513 // not animating; we do not want to do animation at such a
2514 // point to become visible when we already are.
2515 doAnimation = false;
2516 }
2517 }
2518 mPolicyVisibility = true;
2519 mPolicyVisibilityAfterAnim = true;
2520 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002521 mWinAnimator.applyAnimationLocked(TRANSIT_ENTER, true);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002522 }
2523 if (requestAnim) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002524 mWmService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002525 }
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002526 if ((mAttrs.flags & FLAG_NOT_FOCUSABLE) == 0) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002527 mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002528 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002529 return true;
2530 }
2531
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002532 @Override
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002533 public boolean hideLw(boolean doAnimation) {
2534 return hideLw(doAnimation, true);
2535 }
2536
2537 boolean hideLw(boolean doAnimation, boolean requestAnim) {
2538 if (doAnimation) {
David Stevens9440dc82017-03-16 19:00:20 -07002539 if (!mToken.okToAnimate()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002540 doAnimation = false;
2541 }
2542 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002543 boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002544 if (!current) {
Craig Mautnere32c3072012-03-12 15:25:35 -07002545 // Already hiding.
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002546 return false;
2547 }
2548 if (doAnimation) {
Adrian Roose99bc052017-11-20 17:55:31 +01002549 mWinAnimator.applyAnimationLocked(TRANSIT_EXIT, false);
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02002550 if (!isAnimating()) {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002551 doAnimation = false;
2552 }
2553 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002554 mPolicyVisibilityAfterAnim = false;
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002555 final boolean isFocused = isFocused();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002556 if (!doAnimation) {
Craig Mautnerd87946b2012-03-29 18:00:19 -07002557 if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002558 mPolicyVisibility = false;
2559 // Window is no longer visible -- make sure if we were waiting
2560 // for it to be displayed before enabling the display, that
2561 // we allow the display to be enabled now.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002562 mWmService.enableScreenIfNeededLocked();
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002563 if (isFocused) {
Filip Gruszczynski14b4e572015-11-03 15:53:55 -08002564 if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
Craig Mautner58458122013-09-14 14:59:50 -07002565 "WindowState.hideLw: setting mFocusMayChange true");
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002566 mWmService.mFocusMayChange = true;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002567 }
2568 }
2569 if (requestAnim) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002570 mWmService.scheduleAnimationLocked();
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002571 }
Tiger Huang1e5b10a2018-07-30 20:19:51 +08002572 if (isFocused) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002573 mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, false /* updateImWindows */);
Jorim Jaggic8c4a8e2017-04-04 15:09:51 +02002574 }
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002575 return true;
2576 }
2577
Wale Ogunwale01ad4342017-06-30 07:07:01 -07002578 void setForceHideNonSystemOverlayWindowIfNeeded(boolean forceHide) {
2579 if (mOwnerCanAddInternalSystemWindow
2580 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2581 return;
2582 }
2583 if (mForceHideNonSystemOverlayWindow == forceHide) {
2584 return;
2585 }
2586 mForceHideNonSystemOverlayWindow = forceHide;
2587 if (forceHide) {
2588 hideLw(true /* doAnimation */, true /* requestAnim */);
2589 } else {
2590 showLw(true /* doAnimation */, true /* requestAnim */);
2591 }
2592 }
2593
Suprabh Shukla69c71422018-04-02 18:39:01 -07002594 void setHiddenWhileSuspended(boolean hide) {
2595 if (mOwnerCanAddInternalSystemWindow
2596 || (!isSystemAlertWindowType(mAttrs.type) && mAttrs.type != TYPE_TOAST)) {
2597 return;
2598 }
2599 if (mHiddenWhileSuspended == hide) {
2600 return;
2601 }
2602 mHiddenWhileSuspended = hide;
2603 if (hide) {
2604 hideLw(true, true);
2605 } else {
2606 showLw(true, true);
2607 }
2608 }
2609
Svet Ganovf7b47252018-02-26 11:11:27 -08002610 private void setAppOpVisibilityLw(boolean state) {
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002611 if (mAppOpVisibility != state) {
2612 mAppOpVisibility = state;
2613 if (state) {
2614 // If the policy visibility had last been to hide, then this
2615 // will incorrectly show at this point since we lost that
2616 // information. Not a big deal -- for the windows that have app
2617 // ops modifies they should only be hidden by policy due to the
2618 // lock screen, and the user won't be changing this if locked.
2619 // Plus it will quickly be fixed the next time we do a layout.
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002620 showLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002621 } else {
Craig Mautnerfb32c6e2013-02-12 15:08:44 -08002622 hideLw(true, true);
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002623 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002624 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08002625 }
2626
Svet Ganovf7b47252018-02-26 11:11:27 -08002627 void initAppOpsState() {
2628 if (mAppOp == OP_NONE || !mAppOpVisibility) {
2629 return;
2630 }
2631 // If the app op was MODE_DEFAULT we would have checked the permission
2632 // and add the window only if the permission was granted. Therefore, if
2633 // the mode is MODE_DEFAULT we want the op to succeed as the window is
2634 // shown.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002635 final int mode = mWmService.mAppOps.startOpNoThrow(mAppOp,
Svet Ganovf7b47252018-02-26 11:11:27 -08002636 getOwningUid(), getOwningPackage(), true);
2637 if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) {
2638 setAppOpVisibilityLw(false);
2639 }
2640 }
2641
2642 void resetAppOpsState() {
2643 if (mAppOp != OP_NONE && mAppOpVisibility) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002644 mWmService.mAppOps.finishOp(mAppOp, getOwningUid(), getOwningPackage());
Svet Ganovf7b47252018-02-26 11:11:27 -08002645 }
2646 }
2647
2648 void updateAppOpsState() {
2649 if (mAppOp == OP_NONE) {
2650 return;
2651 }
2652 final int uid = getOwningUid();
2653 final String packageName = getOwningPackage();
2654 if (mAppOpVisibility) {
2655 // There is a race between the check and the finish calls but this is fine
2656 // as this would mean we will get another change callback and will reconcile.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002657 int mode = mWmService.mAppOps.checkOpNoThrow(mAppOp, uid, packageName);
Svet Ganovf7b47252018-02-26 11:11:27 -08002658 if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002659 mWmService.mAppOps.finishOp(mAppOp, uid, packageName);
Svet Ganovf7b47252018-02-26 11:11:27 -08002660 setAppOpVisibilityLw(false);
2661 }
2662 } else {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002663 final int mode = mWmService.mAppOps.startOpNoThrow(mAppOp, uid, packageName, true);
Svet Ganovf7b47252018-02-26 11:11:27 -08002664 if (mode == MODE_ALLOWED || mode == MODE_DEFAULT) {
2665 setAppOpVisibilityLw(true);
2666 }
2667 }
2668 }
2669
Svetoslav Ganovaa076532016-08-01 19:16:43 -07002670 public void hidePermanentlyLw() {
2671 if (!mPermanentlyHidden) {
2672 mPermanentlyHidden = true;
2673 hideLw(true, true);
2674 }
2675 }
2676
Jeff Brownc2932a12014-11-20 18:04:05 -08002677 public void pokeDrawLockLw(long timeout) {
2678 if (isVisibleOrAdding()) {
2679 if (mDrawLock == null) {
2680 // We want the tag name to be somewhat stable so that it is easier to correlate
2681 // in wake lock statistics. So in particular, we don't want to include the
2682 // window's hash code as in toString().
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002683 final CharSequence tag = getWindowTag();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002684 mDrawLock = mWmService.mPowerManager.newWakeLock(DRAW_WAKE_LOCK, "Window:" + tag);
Jeff Brownc2932a12014-11-20 18:04:05 -08002685 mDrawLock.setReferenceCounted(false);
2686 mDrawLock.setWorkSource(new WorkSource(mOwnerUid, mAttrs.packageName));
2687 }
2688 // Each call to acquire resets the timeout.
2689 if (DEBUG_POWER) {
2690 Slog.d(TAG, "pokeDrawLock: poking draw lock on behalf of visible window owned by "
2691 + mAttrs.packageName);
2692 }
2693 mDrawLock.acquire(timeout);
2694 } else if (DEBUG_POWER) {
2695 Slog.d(TAG, "pokeDrawLock: suppressed draw lock request for invisible window "
2696 + "owned by " + mAttrs.packageName);
2697 }
2698 }
2699
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002700 @Override
2701 public boolean isAlive() {
2702 return mClient.asBinder().isBinderAlive();
2703 }
2704
Craig Mautnera987d432012-10-11 14:07:58 -07002705 boolean isClosing() {
chaviw4ad54912018-05-30 11:05:44 -07002706 return mAnimatingExit || (mAppToken != null && mAppToken.isClosingOrEnteringPip());
Craig Mautnera987d432012-10-11 14:07:58 -07002707 }
2708
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002709 void addWinAnimatorToList(ArrayList<WindowStateAnimator> animators) {
2710 animators.add(mWinAnimator);
2711
2712 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002713 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002714 c.addWinAnimatorToList(animators);
2715 }
2716 }
2717
Wale Ogunwaled1c37912016-08-16 03:19:39 -07002718 void sendAppVisibilityToClients() {
2719 super.sendAppVisibilityToClients();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002720
Wale Ogunwale89973222017-04-23 18:39:45 -07002721 final boolean clientHidden = mAppToken.isClientHidden();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002722 if (mAttrs.type == TYPE_APPLICATION_STARTING && clientHidden) {
2723 // Don't hide the starting window.
2724 return;
2725 }
2726
Wale Ogunwale89973222017-04-23 18:39:45 -07002727 if (clientHidden) {
2728 // Once we are notifying the client that it's visibility has changed, we need to prevent
2729 // it from destroying child surfaces until the animation has finished. We do this by
2730 // detaching any surface control the client added from the client.
2731 for (int i = mChildren.size() - 1; i >= 0; --i) {
2732 final WindowState c = mChildren.get(i);
2733 c.mWinAnimator.detachChildren();
2734 }
2735
2736 mWinAnimator.detachChildren();
2737 }
2738
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002739 try {
2740 if (DEBUG_VISIBILITY) Slog.v(TAG,
2741 "Setting visibility of " + this + ": " + (!clientHidden));
2742 mClient.dispatchAppVisibility(!clientHidden);
2743 } catch (RemoteException e) {
2744 }
Chong Zhang8e4bda92016-05-04 15:08:18 -07002745 }
2746
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002747 void onStartFreezingScreen() {
2748 mAppFreezing = true;
2749 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002750 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002751 c.onStartFreezingScreen();
2752 }
2753 }
2754
2755 boolean onStopFreezingScreen() {
2756 boolean unfrozeWindows = false;
2757 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07002758 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002759 unfrozeWindows |= c.onStopFreezingScreen();
2760 }
2761
2762 if (!mAppFreezing) {
2763 return unfrozeWindows;
2764 }
2765
Wale Ogunwale953171d2016-09-30 09:17:30 -07002766 mAppFreezing = false;
2767
Bryce Lee8c3cf382017-07-06 19:47:10 -07002768 if (mHasSurface && !getOrientationChanging()
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002769 && mWmService.mWindowsFreezingScreen != WINDOWS_FREEZING_SCREENS_TIMEOUT) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002770 if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "set mOrientationChanging of " + this);
Bryce Lee8c3cf382017-07-06 19:47:10 -07002771 setOrientationChanging(true);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002772 mWmService.mRoot.mOrientationChangeComplete = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002773 }
2774 mLastFreezeDuration = 0;
2775 setDisplayLayoutNeeded();
2776 return true;
2777 }
2778
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002779 boolean destroySurface(boolean cleanupOnResume, boolean appStopped) {
2780 boolean destroyedSomething = false;
Jorim Jaggi59f3e922018-01-05 15:40:32 +01002781
2782 // Copying to a different list as multiple children can be removed.
2783 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
2784 for (int i = childWindows.size() - 1; i >= 0; --i) {
2785 final WindowState c = childWindows.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002786 destroyedSomething |= c.destroySurface(cleanupOnResume, appStopped);
2787 }
2788
Robert Carrdb2f6e62017-03-01 20:17:58 -08002789 if (!(appStopped || mWindowRemovalAllowed || cleanupOnResume)) {
2790 return destroyedSomething;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002791 }
Robert Carrdb2f6e62017-03-01 20:17:58 -08002792
2793 if (appStopped || mWindowRemovalAllowed) {
2794 mWinAnimator.destroyPreservedSurfaceLocked();
2795 }
2796
2797 if (mDestroying) {
2798 if (DEBUG_ADD_REMOVE) Slog.e(TAG_WM, "win=" + this
2799 + " destroySurfaces: appStopped=" + appStopped
2800 + " win.mWindowRemovalAllowed=" + mWindowRemovalAllowed
2801 + " win.mRemoveOnExit=" + mRemoveOnExit);
2802 if (!cleanupOnResume || mRemoveOnExit) {
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002803 destroySurfaceUnchecked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08002804 }
2805 if (mRemoveOnExit) {
2806 removeImmediately();
2807 }
2808 if (cleanupOnResume) {
2809 requestUpdateWallpaperIfNeeded();
2810 }
2811 mDestroying = false;
2812 destroyedSomething = true;
2813 }
2814
Wale Ogunwale9bc47732016-08-10 14:44:22 -07002815 return destroyedSomething;
2816 }
Chris Craik3131bde2016-05-06 13:39:08 -07002817
Robert Carr89a28ab2017-04-24 15:33:11 -07002818 // Destroy or save the application surface without checking
2819 // various indicators of whether the client has released the surface.
2820 // This is in general unsafe, and most callers should use {@link #destroySurface}
Jorim Jaggie7d2b852017-08-28 17:55:15 +02002821 void destroySurfaceUnchecked() {
2822 mWinAnimator.destroySurfaceLocked();
Chong Zhangeb22e8e2016-01-20 19:52:22 -08002823
Chong Zhang92147042016-05-09 12:47:11 -07002824 // Clear animating flags now, since the surface is now gone. (Note this is true even
2825 // if the surface is saved, to outside world the surface is still NO_SURFACE.)
2826 mAnimatingExit = false;
Robert Carr13f7be9e2015-12-02 18:39:45 -08002827 }
Chong Zhangdb20b5f2015-10-23 14:01:43 -07002828
Craig Mautner69b08182012-09-05 13:07:13 -07002829 @Override
2830 public boolean isDefaultDisplay() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002831 final DisplayContent displayContent = getDisplayContent();
2832 if (displayContent == null) {
2833 // Only a window that was on a non-default display can be detached from it.
2834 return false;
2835 }
Winson Chung47a3e652014-05-21 16:03:42 -07002836 return displayContent.isDefaultDisplay;
Craig Mautner69b08182012-09-05 13:07:13 -07002837 }
2838
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002839 void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
Craig Mautner88400d32012-09-30 12:35:45 -07002840 mShowToOwnerOnly = showToOwnerOnly;
2841 }
2842
Wale Ogunwaleea92d972016-12-08 07:33:13 -08002843 private boolean isHiddenFromUserLocked() {
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07002844 // Child windows are evaluated based on their parent window.
2845 final WindowState win = getTopParentWindow();
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07002846 if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
Wale Ogunwale72919d22016-12-08 18:58:50 -08002847 && win.mAppToken != null && win.mAppToken.mShowForAllUsers) {
Jorim Jaggidbe44ac2016-04-22 19:50:13 -07002848
2849 // All window frames that are fullscreen extend above status bar, but some don't extend
2850 // below navigation bar. Thus, check for display frame for top/left and stable frame for
2851 // bottom right.
chaviw492139a2018-07-16 16:07:35 -07002852 if (win.getFrameLw().left <= win.getDisplayFrameLw().left
2853 && win.getFrameLw().top <= win.getDisplayFrameLw().top
2854 && win.getFrameLw().right >= win.getStableFrameLw().right
2855 && win.getFrameLw().bottom >= win.getStableFrameLw().bottom) {
Craig Mautner5962b122012-10-05 14:45:52 -07002856 // Is a fullscreen window, like the clock alarm. Show to everyone.
2857 return false;
2858 }
2859 }
2860
Craig Mautner341220f2012-10-16 15:20:09 -07002861 return win.mShowToOwnerOnly
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002862 && !mWmService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid));
Craig Mautner9dc52bc2012-08-06 14:15:42 -07002863 }
2864
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002865 private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
2866 outRegion.set(
2867 frame.left + inset.left, frame.top + inset.top,
2868 frame.right - inset.right, frame.bottom - inset.bottom);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002869 }
2870
Riddle Hsuff03df52018-12-05 21:43:02 +08002871 /** Get the touchable region in global coordinates. */
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002872 void getTouchableRegion(Region outRegion) {
chaviw492139a2018-07-16 16:07:35 -07002873 final Rect frame = mWindowFrames.mFrame;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002874 switch (mTouchableInsets) {
2875 default:
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002876 case TOUCHABLE_INSETS_FRAME:
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002877 outRegion.set(frame);
2878 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002879 case TOUCHABLE_INSETS_CONTENT:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002880 applyInsets(outRegion, frame, mGivenContentInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002881 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002882 case TOUCHABLE_INSETS_VISIBLE:
Dianne Hackbornffb3d932011-05-17 17:44:51 -07002883 applyInsets(outRegion, frame, mGivenVisibleInsets);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002884 break;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002885 case TOUCHABLE_INSETS_REGION: {
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002886 outRegion.set(mGivenTouchableRegion);
Riddle Hsub5e960f2018-12-07 14:51:26 +08002887 outRegion.translate(frame.left, frame.top);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002888 break;
2889 }
2890 }
Vishnu Nairb9246322018-12-06 13:54:02 -08002891 cropRegionToStackBoundsIfNeeded(outRegion);
Tiger Huang04dc4cc2019-01-17 18:41:41 +08002892 subtractTouchExcludeRegionIfNeeded(outRegion);
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002893 }
2894
Wale Ogunwaleae9adbf2016-10-18 15:17:06 -07002895 private void cropRegionToStackBoundsIfNeeded(Region region) {
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002896 final Task task = getTask();
2897 if (task == null || !task.cropWindowsToStackBounds()) {
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002898 return;
2899 }
2900
Wale Ogunwaleb1faf602016-01-27 09:12:31 -08002901 final TaskStack stack = task.mStack;
Wale Ogunwale053c8e42015-11-16 14:27:21 -08002902 if (stack == null) {
2903 return;
2904 }
2905
2906 stack.getDimBounds(mTmpRect);
2907 region.op(mTmpRect, Region.Op.INTERSECT);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08002908 }
2909
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002910 /**
Tiger Huang04dc4cc2019-01-17 18:41:41 +08002911 * If this window has areas that cannot be touched, we subtract those areas from its touchable
2912 * region.
2913 */
2914 private void subtractTouchExcludeRegionIfNeeded(Region touchableRegion) {
2915 if (mTapExcludeRegionHolder == null) {
2916 return;
2917 }
2918 final Region touchExcludeRegion = Region.obtain();
2919 amendTapExcludeRegion(touchExcludeRegion);
2920 if (!touchExcludeRegion.isEmpty()) {
2921 touchableRegion.op(touchExcludeRegion, Region.Op.DIFFERENCE);
2922 }
2923 touchExcludeRegion.recycle();
2924 }
2925
2926 /**
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002927 * Report a focus change. Must be called with no locks held, and consistently
2928 * from the same serialized thread (such as dispatched from a handler).
2929 */
Tiger Huang51c5a1d2018-12-11 20:24:51 +08002930 void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002931 try {
Tiger Huang51c5a1d2018-12-11 20:24:51 +08002932 mClient.windowFocusChanged(focused, inTouchMode);
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002933 } catch (RemoteException e) {
2934 }
Tiger Huang51c5a1d2018-12-11 20:24:51 +08002935 if (mFocusCallbacks != null) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08002936 final int N = mFocusCallbacks.beginBroadcast();
2937 for (int i=0; i<N; i++) {
2938 IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
2939 try {
2940 if (focused) {
2941 obs.focusGained(mWindowId.asBinder());
2942 } else {
2943 obs.focusLost(mWindowId.asBinder());
2944 }
2945 } catch (RemoteException e) {
2946 }
2947 }
2948 mFocusCallbacks.finishBroadcast();
2949 }
2950 }
2951
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002952 @Override
2953 public Configuration getConfiguration() {
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002954 if (mAppToken != null && mAppToken.mFrozenMergedConfig.size() > 0) {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002955 return mAppToken.mFrozenMergedConfig.peek();
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002956 }
Andrii Kulian9d91ca62016-09-29 22:28:09 -07002957
Yunfan Chen75157d72018-07-27 14:47:21 +09002958 // We use the process config this window is associated with as the based global config since
2959 // the process can override it config, but isn't part of the window hierarchy.
2960 final Configuration config = getProcessGlobalConfiguration();
2961 config.updateFrom(getMergedOverrideConfiguration());
2962 return config;
Jorim Jaggi26c8c422016-05-09 19:57:25 -07002963 }
2964
Craig Mautnerdf88d732014-01-27 09:21:32 -08002965 void reportResized() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07002966 Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "wm.reportResized_" + getWindowTag());
Craig Mautnerdf88d732014-01-27 09:21:32 -08002967 try {
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002968 if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
chaviw9c81e632018-07-31 11:17:52 -07002969 + ": " + mWindowFrames.mCompatFrame);
Bryce Leef858b572017-06-29 14:03:33 -07002970 final MergedConfiguration mergedConfiguration =
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002971 new MergedConfiguration(mWmService.mRoot.getConfiguration(),
Bryce Leef858b572017-06-29 14:03:33 -07002972 getMergedOverrideConfiguration());
2973
Bryce Lee2b17afd2017-09-21 10:38:20 -07002974 setLastReportedMergedConfiguration(mergedConfiguration);
Bryce Leef858b572017-06-29 14:03:33 -07002975
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002976 if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
Craig Mautnerd1c2c542014-02-06 10:31:41 -08002977 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
2978
Riddle Hsub398da32019-01-21 21:48:16 +08002979 final Rect frame = mWindowFrames.mCompatFrame;
chaviw9c81e632018-07-31 11:17:52 -07002980 final Rect overscanInsets = mWindowFrames.mLastOverscanInsets;
2981 final Rect contentInsets = mWindowFrames.mLastContentInsets;
2982 final Rect visibleInsets = mWindowFrames.mLastVisibleInsets;
2983 final Rect stableInsets = mWindowFrames.mLastStableInsets;
2984 final Rect outsets = mWindowFrames.mLastOutsets;
Wale Ogunwale19e452e2016-10-12 12:36:29 -07002985 final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
Andrii Kulianb2e37802017-01-11 00:36:44 -08002986 final boolean reportOrientation = mReportOrientationChanged;
Andrii Kulianb047b8b2017-02-08 18:38:26 -08002987 final int displayId = getDisplayId();
chaviwcdba9a42018-07-19 11:36:42 -07002988 final DisplayCutout displayCutout = getWmDisplayCutout().getDisplayCutout();
Chet Haase8eb48d22014-09-24 07:31:29 -07002989 if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
2990 && mClient instanceof IWindow.Stub) {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002991 // To prevent deadlock simulate one-way call if win.mClient is a local object.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08002992 mWmService.mH.post(new Runnable() {
Craig Mautnerdf88d732014-01-27 09:21:32 -08002993 @Override
2994 public void run() {
2995 try {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01002996 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets,
Andrii Kulian44607962017-03-16 11:06:24 -07002997 stableInsets, outsets, reportDraw, mergedConfiguration,
Adrian Roos5c6b6222017-11-07 17:36:10 +01002998 reportOrientation, displayId, displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08002999 } catch (RemoteException e) {
3000 // Not a remote call, RemoteException won't be raised.
3001 }
3002 }
3003 });
3004 } else {
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003005 dispatchResized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003006 outsets, reportDraw, mergedConfiguration, reportOrientation, displayId,
3007 displayCutout);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003008 }
Svetoslav4604abc2014-06-10 18:59:30 -07003009
3010 //TODO (multidisplay): Accessibility supported only for the default display.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003011 if (mWmService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
3012 mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Svetoslav4604abc2014-06-10 18:59:30 -07003013 }
3014
chaviw9c81e632018-07-31 11:17:52 -07003015 mWindowFrames.resetInsetsChanged();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003016 mWinAnimator.mSurfaceResized = false;
Andrii Kulianb2e37802017-01-11 00:36:44 -08003017 mReportOrientationChanged = false;
Craig Mautnerdf88d732014-01-27 09:21:32 -08003018 } catch (RemoteException e) {
Bryce Lee8c3cf382017-07-06 19:47:10 -07003019 setOrientationChanging(false);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003020 mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003021 - mWmService.mDisplayFreezeTime);
tiger_huang950ee772014-07-11 18:41:48 +08003022 // We are assuming the hosting process is dead or in a zombie state.
3023 Slog.w(TAG, "Failed to report 'resized' to the client of " + this
3024 + ", removing this window.");
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003025 mWmService.mPendingRemove.add(this);
3026 mWmService.mWindowPlacerLocked.requestTraversal();
Craig Mautnerdf88d732014-01-27 09:21:32 -08003027 }
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003028 Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
Craig Mautnerdf88d732014-01-27 09:21:32 -08003029 }
3030
Jorim Jaggif96c90a2018-09-26 16:55:15 +02003031 /**
3032 * Called when the insets state changed.
3033 */
3034 void notifyInsetsChanged() {
3035 try {
3036 mClient.insetsChanged(
3037 getDisplayContent().getInsetsStateController().getInsetsForDispatch(this));
3038 } catch (RemoteException e) {
3039 Slog.w(TAG, "Failed to deliver inset state change", e);
3040 }
3041 }
3042
Jorim Jaggib6030952018-10-23 18:31:52 +02003043 void notifyInsetsControlChanged() {
3044 final InsetsStateController stateController =
3045 getDisplayContent().getInsetsStateController();
3046 try {
3047 mClient.insetsControlChanged(stateController.getInsetsForDispatch(this),
3048 stateController.getControlsForDispatch(this));
3049 } catch (RemoteException e) {
3050 Slog.w(TAG, "Failed to deliver inset state change", e);
3051 }
3052 }
3053
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003054 Rect getBackdropFrame(Rect frame) {
Chong Zhangd153c4f2015-11-06 20:26:40 -08003055 // When the task is docked, we send fullscreen sized backDropFrame as soon as resizing
3056 // start even if we haven't received the relayout window, so that the client requests
3057 // the relayout sooner. When dragging stops, backDropFrame needs to stay fullscreen
3058 // until the window to small size, otherwise the multithread renderer will shift last
3059 // one or more frame to wrong offset. So here we send fullscreen backdrop if either
3060 // isDragResizing() or isDragResizeChanged() is true.
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003061 boolean resizing = isDragResizing() || isDragResizeChanged();
Wale Ogunwale3382ab12017-07-27 08:55:03 -07003062 if (getWindowConfiguration().useWindowFrameForBackdrop() || !resizing) {
Garfield Tanfbd8ea62018-10-16 17:09:49 -07003063 // Surface position is now inherited from parent, and BackdropFrameRenderer uses
3064 // backdrop frame to position content. Thus we just keep the size of backdrop frame, and
3065 // remove the offset to avoid double offset from display origin.
3066 mTmpRect.set(frame);
3067 mTmpRect.offsetTo(0, 0);
3068 return mTmpRect;
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003069 }
Wale Ogunwaleb0f3b832016-10-17 10:13:07 -07003070 final DisplayInfo displayInfo = getDisplayInfo();
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003071 mTmpRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003072 return mTmpRect;
3073 }
3074
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003075 private int getStackId() {
Filip Gruszczynski84fa3352016-01-25 16:28:49 -08003076 final TaskStack stack = getStack();
3077 if (stack == null) {
3078 return INVALID_STACK_ID;
3079 }
3080 return stack.mStackId;
Jorim Jaggi2e95a482016-01-14 17:36:55 -08003081 }
3082
3083 private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
3084 Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003085 MergedConfiguration mergedConfiguration, boolean reportOrientation, int displayId,
3086 DisplayCutout displayCutout)
Andrii Kulianb047b8b2017-02-08 18:38:26 -08003087 throws RemoteException {
Robert Carr09286c92018-02-15 13:52:31 -08003088 final boolean forceRelayout = isDragResizeChanged() || reportOrientation;
Chong Zhangedaf3052016-04-22 15:04:31 -07003089
Jorim Jaggidc249c42015-12-15 14:57:31 -08003090 mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, stableInsets, outsets,
Andrii Kulian44607962017-03-16 11:06:24 -07003091 reportDraw, mergedConfiguration, getBackdropFrame(frame), forceRelayout,
Tiger Huang7c610aa2018-10-27 00:01:01 +08003092 getDisplayContent().getDisplayPolicy().isNavBarForcedShownLw(this), displayId,
Adrian Roos5c6b6222017-11-07 17:36:10 +01003093 new DisplayCutout.ParcelableWrapper(displayCutout));
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003094 mDragResizingChangeReported = true;
Jorim Jaggi253a20f2015-11-03 12:38:42 +01003095 }
3096
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003097 public void registerFocusObserver(IWindowFocusObserver observer) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003098 synchronized (mWmService.mGlobalLock) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003099 if (mFocusCallbacks == null) {
3100 mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
3101 }
3102 mFocusCallbacks.register(observer);
3103 }
3104 }
3105
3106 public void unregisterFocusObserver(IWindowFocusObserver observer) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003107 synchronized (mWmService.mGlobalLock) {
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003108 if (mFocusCallbacks != null) {
3109 mFocusCallbacks.unregister(observer);
3110 }
3111 }
3112 }
3113
Tiger Huang1e5b10a2018-07-30 20:19:51 +08003114 boolean isFocused() {
3115 return getDisplayContent().mCurrentFocus == this;
Dianne Hackborne3f23a32013-03-01 13:25:35 -08003116 }
3117
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003118 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -07003119 public boolean isInMultiWindowMode() {
Wale Ogunwale9185fb02016-03-11 18:06:14 -08003120 final Task task = getTask();
3121 return task != null && !task.isFullscreen();
3122 }
3123
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003124 /** Is this window in a container that takes up the entire screen space? */
3125 private boolean inFullscreenContainer() {
Bryce Leef3c6a472017-11-14 14:53:06 -08003126 return mAppToken == null || (mAppToken.matchParentBounds() && !isInMultiWindowMode());
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003127 }
3128
Andrii Kulian283acd22017-08-03 04:03:51 -07003129 /** @return true when the window is in fullscreen task, but has non-fullscreen bounds set. */
3130 boolean isLetterboxedAppWindow() {
Adrian Roos865c70f2018-01-10 17:32:27 +01003131 return !isInMultiWindowMode() && mAppToken != null && !mAppToken.matchParentBounds()
3132 || isLetterboxedForDisplayCutoutLw();
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003133 }
3134
Adrian Roos865c70f2018-01-10 17:32:27 +01003135 @Override
3136 public boolean isLetterboxedForDisplayCutoutLw() {
3137 if (mAppToken == null) {
3138 // Only windows with an AppWindowToken are letterboxed.
3139 return false;
3140 }
chaviwcdba9a42018-07-19 11:36:42 -07003141 if (!mWindowFrames.parentFrameWasClippedByDisplayCutout()) {
Adrian Roos5ed644f2018-03-19 17:01:05 +01003142 // Cutout didn't make a difference, no letterbox
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003143 return false;
3144 }
Adrian Roosfa02da62018-01-15 16:01:18 +01003145 if (mAttrs.layoutInDisplayCutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS) {
Adrian Roos4d18a2e2017-12-19 19:08:05 +01003146 // Layout in cutout, no letterbox.
3147 return false;
3148 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003149 if (!mAttrs.isFullscreen()) {
3150 // Not filling the parent frame, no letterbox
3151 return false;
Adrian Roosfa02da62018-01-15 16:01:18 +01003152 }
Adrian Roos5ed644f2018-03-19 17:01:05 +01003153 // Otherwise we need a letterbox if the layout was smaller than the app window token allowed
3154 // it to be.
3155 return !frameCoversEntireAppTokenBounds();
3156 }
3157
3158 /**
3159 * @return true if this window covers the entire bounds of its app window token
3160 * @throws NullPointerException if there is no app window token for this window
3161 */
3162 private boolean frameCoversEntireAppTokenBounds() {
3163 mTmpRect.set(mAppToken.getBounds());
chaviw492139a2018-07-16 16:07:35 -07003164 mTmpRect.intersectUnchecked(mWindowFrames.mFrame);
Adrian Roos5ed644f2018-03-19 17:01:05 +01003165 return mAppToken.getBounds().equals(mTmpRect);
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003166 }
3167
Adrian Roos23df3a32018-03-15 15:41:13 +01003168 @Override
3169 public boolean isLetterboxedOverlappingWith(Rect rect) {
3170 return mAppToken != null && mAppToken.isLetterboxOverlappingWith(rect);
3171 }
3172
Chong Zhang3005e752015-09-18 18:46:28 -07003173 boolean isDragResizeChanged() {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003174 return mDragResizing != computeDragResizing();
3175 }
3176
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003177 @Override
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003178 void setWaitingForDrawnIfResizingChanged() {
3179 if (isDragResizeChanged()) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003180 mWmService.mWaitingForDrawn.add(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003181 }
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003182 super.setWaitingForDrawnIfResizingChanged();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003183 }
3184
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003185 /**
3186 * @return Whether we reported a drag resize change to the application or not already.
3187 */
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003188 private boolean isDragResizingChangeReported() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003189 return mDragResizingChangeReported;
3190 }
3191
3192 /**
3193 * Resets the state whether we reported a drag resize change to the app.
3194 */
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003195 @Override
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003196 void resetDragResizingChangeReported() {
3197 mDragResizingChangeReported = false;
Wale Ogunwaled1c37912016-08-16 03:19:39 -07003198 super.resetDragResizingChangeReported();
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003199 }
3200
Jorim Jaggidcf467c2015-11-05 13:59:32 +01003201 int getResizeMode() {
3202 return mResizeMode;
3203 }
3204
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003205 private boolean computeDragResizing() {
Wale Ogunwale5a2f2cb2015-09-17 12:31:55 -07003206 final Task task = getTask();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003207 if (task == null) {
3208 return false;
3209 }
Tomasz Mikolajewskiaf20b8d2017-11-20 16:11:33 +09003210 if (!inSplitScreenWindowingMode() && !inFreeformWindowingMode()) {
Winson Chung2af04b32017-01-24 16:21:13 -08003211 return false;
3212 }
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003213 if (mAttrs.width != MATCH_PARENT || mAttrs.height != MATCH_PARENT) {
Jorim Jaggidd6e4c12016-02-17 22:13:43 -08003214 // Floating windows never enter drag resize mode.
3215 return false;
3216 }
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -07003217 if (task.isDragResizing()) {
3218 return true;
3219 }
Jorim Jaggi0429f352015-12-22 16:29:16 +01003220
3221 // If the bounds are currently frozen, it means that the layout size that the app sees
3222 // and the bounds we clip this window to might be different. In order to avoid holes, we
3223 // simulate that we are still resizing so the app fills the hole with the resizing
3224 // background.
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003225 return (getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0429f352015-12-22 16:29:16 +01003226 || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003227 !task.inFreeformWindowingMode() && !isGoneForLayoutLw();
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003228
Chong Zhang3005e752015-09-18 18:46:28 -07003229 }
3230
3231 void setDragResizing() {
Jorim Jaggic662d8e2016-02-05 16:54:54 -08003232 final boolean resizing = computeDragResizing();
3233 if (resizing == mDragResizing) {
3234 return;
3235 }
3236 mDragResizing = resizing;
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003237 final Task task = getTask();
3238 if (task != null && task.isDragResizing()) {
3239 mResizeMode = task.getDragResizeMode();
3240 } else {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003241 mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
Jorim Jaggi0b46f3c2016-03-14 12:21:37 +01003242 ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
3243 : DRAG_RESIZE_MODE_FREEFORM;
3244 }
Chong Zhang3005e752015-09-18 18:46:28 -07003245 }
3246
3247 boolean isDragResizing() {
3248 return mDragResizing;
Skuhnef932e562015-08-20 12:07:30 -07003249 }
3250
Robert Carr2487ce72016-04-07 15:18:45 -07003251 boolean isDockedResizing() {
Robert Carrfbbde852016-10-18 11:02:28 -07003252 return (mDragResizing && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER)
3253 || (isChildWindow() && getParentWindow().isDockedResizing());
Robert Carr2487ce72016-04-07 15:18:45 -07003254 }
3255
Wale Ogunwale0d5609b2017-09-13 05:55:07 -07003256 @CallSuper
3257 @Override
Nataniel Borges023ecb52019-01-16 14:15:43 -08003258 public void writeToProto(ProtoOutputStream proto, long fieldId,
3259 @WindowTraceLogLevel int logLevel) {
3260 boolean isVisible = isVisible();
3261 if (logLevel == WindowTraceLogLevel.CRITICAL && !isVisible) {
3262 return;
3263 }
3264
Steven Timotiusaf03df62017-07-18 16:56:43 -07003265 final long token = proto.start(fieldId);
Nataniel Borges023ecb52019-01-16 14:15:43 -08003266 super.writeToProto(proto, WINDOW_CONTAINER, logLevel);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003267 writeIdentifierToProto(proto, IDENTIFIER);
3268 proto.write(DISPLAY_ID, getDisplayId());
3269 proto.write(STACK_ID, getStackId());
3270 mAttrs.writeToProto(proto, ATTRIBUTES);
3271 mGivenContentInsets.writeToProto(proto, GIVEN_CONTENT_INSETS);
chaviw553b0212018-07-12 13:37:01 -07003272 mWindowFrames.writeToProto(proto, WINDOW_FRAMES);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003273 mAttrs.surfaceInsets.writeToProto(proto, SURFACE_INSETS);
Jorim Jaggi45be1c4c2017-12-15 18:44:43 +01003274 mSurfacePosition.writeToProto(proto, SURFACE_POSITION);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003275 mWinAnimator.writeToProto(proto, ANIMATOR);
3276 proto.write(ANIMATING_EXIT, mAnimatingExit);
3277 for (int i = 0; i < mChildren.size(); i++) {
Nataniel Borges023ecb52019-01-16 14:15:43 -08003278 mChildren.get(i).writeToProto(proto, CHILD_WINDOWS, logLevel);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003279 }
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003280 proto.write(REQUESTED_WIDTH, mRequestedWidth);
3281 proto.write(REQUESTED_HEIGHT, mRequestedHeight);
3282 proto.write(VIEW_VISIBILITY, mViewVisibility);
3283 proto.write(SYSTEM_UI_VISIBILITY, mSystemUiVisibility);
3284 proto.write(HAS_SURFACE, mHasSurface);
3285 proto.write(IS_READY_FOR_DISPLAY, isReadyForDisplay());
Vishnu Nair1d0fa072018-01-04 07:53:00 -08003286 proto.write(REMOVE_ON_EXIT, mRemoveOnExit);
3287 proto.write(DESTROYING, mDestroying);
3288 proto.write(REMOVED, mRemoved);
3289 proto.write(IS_ON_SCREEN, isOnScreen());
Nataniel Borges023ecb52019-01-16 14:15:43 -08003290 proto.write(IS_VISIBLE, isVisible);
Vishnu Nairddd80742018-08-21 14:12:46 -07003291 proto.write(PENDING_SEAMLESS_ROTATION, mPendingSeamlessRotate != null);
3292 proto.write(FINISHED_SEAMLESS_ROTATION_FRAME, mFinishSeamlessRotateFrameNumber);
3293 proto.write(FORCE_SEAMLESS_ROTATION, mForceSeamlesslyRotate);
Steven Timotiusaf03df62017-07-18 16:56:43 -07003294 proto.end(token);
3295 }
3296
Vishnu Nair9a3e4062018-01-11 08:42:54 -08003297 @Override
3298 public void writeIdentifierToProto(ProtoOutputStream proto, long fieldId) {
Steven Timotiusaf03df62017-07-18 16:56:43 -07003299 final long token = proto.start(fieldId);
3300 proto.write(HASH_CODE, System.identityHashCode(this));
3301 proto.write(USER_ID, UserHandle.getUserId(mOwnerUid));
3302 final CharSequence title = getWindowTag();
3303 if (title != null) {
3304 proto.write(TITLE, title.toString());
3305 }
3306 proto.end(token);
3307 }
3308
Jorim Jaggia5e10572017-11-15 14:36:26 +01003309 @Override
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003310 void dump(PrintWriter pw, String prefix, boolean dumpAll) {
Wale Ogunwale30cc7bf2015-02-04 16:47:57 -08003311 final TaskStack stack = getStack();
chaviwc65fa582018-08-09 15:33:13 -07003312 pw.print(prefix + "mDisplayId=" + getDisplayId());
3313 if (stack != null) {
3314 pw.print(" stackId=" + stack.mStackId);
3315 }
3316 pw.println(" mSession=" + mSession
3317 + " mClient=" + mClient.asBinder());
3318 pw.println(prefix + "mOwnerUid=" + mOwnerUid
3319 + " mShowToOwnerOnly=" + mShowToOwnerOnly
3320 + " package=" + mAttrs.packageName
3321 + " appop=" + AppOpsManager.opToName(mAppOp));
3322 pw.println(prefix + "mAttrs=" + mAttrs.toString(prefix));
3323 pw.println(prefix + "Requested w=" + mRequestedWidth
3324 + " h=" + mRequestedHeight
3325 + " mLayoutSeq=" + mLayoutSeq);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003326 if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
chaviwc65fa582018-08-09 15:33:13 -07003327 pw.println(prefix + "LastRequested w=" + mLastRequestedWidth
3328 + " h=" + mLastRequestedHeight);
Dianne Hackborn1743b642012-03-12 17:04:43 -07003329 }
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003330 if (mIsChildWindow || mLayoutAttached) {
chaviwc65fa582018-08-09 15:33:13 -07003331 pw.println(prefix + "mParentWindow=" + getParentWindow()
3332 + " mLayoutAttached=" + mLayoutAttached);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003333 }
3334 if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
chaviwc65fa582018-08-09 15:33:13 -07003335 pw.println(prefix + "mIsImWindow=" + mIsImWindow
3336 + " mIsWallpaper=" + mIsWallpaper
3337 + " mIsFloatingLayer=" + mIsFloatingLayer
3338 + " mWallpaperVisible=" + mWallpaperVisible);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003339 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003340 if (dumpAll) {
Jorim Jaggi35d328a2018-08-14 17:00:20 +02003341 pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
3342 pw.print(" mSubLayer="); pw.print(mSubLayer);
Dianne Hackborn6d05fd32011-11-19 14:36:15 -08003343 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003344 if (dumpAll) {
chaviwc65fa582018-08-09 15:33:13 -07003345 pw.println(prefix + "mToken=" + mToken);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003346 if (mAppToken != null) {
chaviwc65fa582018-08-09 15:33:13 -07003347 pw.println(prefix + "mAppToken=" + mAppToken);
3348 pw.print(prefix + "mAppDied=" + mAppDied);
3349 pw.print(prefix + "drawnStateEvaluated=" + getDrawnStateEvaluated());
3350 pw.println(prefix + "mightAffectAllDrawn=" + mightAffectAllDrawn());
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003351 }
chaviwc65fa582018-08-09 15:33:13 -07003352 pw.println(prefix + "mViewVisibility=0x" + Integer.toHexString(mViewVisibility)
3353 + " mHaveFrame=" + mHaveFrame
3354 + " mObscured=" + mObscured);
3355 pw.println(prefix + "mSeq=" + mSeq
3356 + " mSystemUiVisibility=0x" + Integer.toHexString(mSystemUiVisibility));
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003357 }
Dianne Hackbornb6b23ec2013-02-11 19:29:06 -08003358 if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
chaviwc65fa582018-08-09 15:33:13 -07003359 || isParentWindowHidden() || mPermanentlyHidden || mForceHideNonSystemOverlayWindow
Suprabh Shukla69c71422018-04-02 18:39:01 -07003360 || mHiddenWhileSuspended) {
chaviwc65fa582018-08-09 15:33:13 -07003361 pw.println(prefix + "mPolicyVisibility=" + mPolicyVisibility
3362 + " mPolicyVisibilityAfterAnim=" + mPolicyVisibilityAfterAnim
3363 + " mAppOpVisibility=" + mAppOpVisibility
3364 + " parentHidden=" + isParentWindowHidden()
3365 + " mPermanentlyHidden=" + mPermanentlyHidden
3366 + " mHiddenWhileSuspended=" + mHiddenWhileSuspended
3367 + " mForceHideNonSystemOverlayWindow=" + mForceHideNonSystemOverlayWindow);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003368 }
Dianne Hackbornb7ff51b2012-01-23 19:15:27 -08003369 if (!mRelayoutCalled || mLayoutNeeded) {
chaviwc65fa582018-08-09 15:33:13 -07003370 pw.println(prefix + "mRelayoutCalled=" + mRelayoutCalled
3371 + " mLayoutNeeded=" + mLayoutNeeded);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003372 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003373 if (dumpAll) {
chaviwc65fa582018-08-09 15:33:13 -07003374 pw.println(prefix + "mGivenContentInsets=" + mGivenContentInsets.toShortString(sTmpSB)
3375 + " mGivenVisibleInsets=" + mGivenVisibleInsets.toShortString(sTmpSB));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003376 if (mTouchableInsets != 0 || mGivenInsetsPending) {
chaviwc65fa582018-08-09 15:33:13 -07003377 pw.println(prefix + "mTouchableInsets=" + mTouchableInsets
3378 + " mGivenInsetsPending=" + mGivenInsetsPending);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003379 Region region = new Region();
3380 getTouchableRegion(region);
chaviwc65fa582018-08-09 15:33:13 -07003381 pw.println(prefix + "touchable region=" + region);
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003382 }
chaviwc65fa582018-08-09 15:33:13 -07003383 pw.println(prefix + "mFullConfiguration=" + getConfiguration());
3384 pw.println(prefix + "mLastReportedConfiguration=" + getLastReportedConfiguration());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003385 }
chaviwc65fa582018-08-09 15:33:13 -07003386 pw.println(prefix + "mHasSurface=" + mHasSurface
3387 + " isReadyForDisplay()=" + isReadyForDisplay()
3388 + " mWindowRemovalAllowed=" + mWindowRemovalAllowed);
Riddle Hsub398da32019-01-21 21:48:16 +08003389 if (inSizeCompatMode()) {
chaviw9c81e632018-07-31 11:17:52 -07003390 pw.println(prefix + "mCompatFrame=" + mWindowFrames.mCompatFrame.toShortString(sTmpSB));
Dianne Hackbornffb3d932011-05-17 17:44:51 -07003391 }
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003392 if (dumpAll) {
chaviw553b0212018-07-12 13:37:01 -07003393 mWindowFrames.dump(pw, prefix);
chaviw9c81e632018-07-31 11:17:52 -07003394 pw.println(prefix + " surface=" + mAttrs.surfaceInsets.toShortString(sTmpSB));
Dianne Hackborna44abeb2011-08-08 19:24:01 -07003395 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01003396 super.dump(pw, prefix, dumpAll);
chaviwc65fa582018-08-09 15:33:13 -07003397 pw.println(prefix + mWinAnimator + ":");
Dianne Hackborn529e7442012-11-01 14:22:28 -07003398 mWinAnimator.dump(pw, prefix + " ", dumpAll);
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003399 if (mAnimatingExit || mRemoveOnExit || mDestroying || mRemoved) {
chaviwc65fa582018-08-09 15:33:13 -07003400 pw.println(prefix + "mAnimatingExit=" + mAnimatingExit
3401 + " mRemoveOnExit=" + mRemoveOnExit
3402 + " mDestroying=" + mDestroying
3403 + " mRemoved=" + mRemoved);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003404 }
chaviw40234662018-02-07 09:37:16 -08003405 if (getOrientationChanging() || mAppFreezing || mReportOrientationChanged) {
chaviwc65fa582018-08-09 15:33:13 -07003406 pw.println(prefix + "mOrientationChanging=" + mOrientationChanging
3407 + " configOrientationChanging="
3408 + (getLastReportedConfiguration().orientation != getConfiguration().orientation)
3409 + " mAppFreezing=" + mAppFreezing
3410 + " mReportOrientationChanged=" + mReportOrientationChanged);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003411 }
Dianne Hackborna57c6952013-03-29 14:46:40 -07003412 if (mLastFreezeDuration != 0) {
chaviwc65fa582018-08-09 15:33:13 -07003413 pw.print(prefix + "mLastFreezeDuration=");
3414 TimeUtils.formatDuration(mLastFreezeDuration, pw);
3415 pw.println();
Dianne Hackborna57c6952013-03-29 14:46:40 -07003416 }
chaviwc65fa582018-08-09 15:33:13 -07003417 pw.print(prefix + "mForceSeamlesslyRotate=" + mForceSeamlesslyRotate
3418 + " seamlesslyRotate: pending=");
Vishnu Nairddd80742018-08-21 14:12:46 -07003419 if (mPendingSeamlessRotate != null) {
3420 mPendingSeamlessRotate.dump(pw);
3421 } else {
3422 pw.print("null");
Adrian Roos27a90d22018-07-06 02:39:54 -07003423 }
chaviwc65fa582018-08-09 15:33:13 -07003424 pw.println(" finishedFrameNumber=" + mFinishSeamlessRotateFrameNumber);
Vishnu Nairddd80742018-08-21 14:12:46 -07003425
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003426 if (mHScale != 1 || mVScale != 1) {
chaviwc65fa582018-08-09 15:33:13 -07003427 pw.println(prefix + "mHScale=" + mHScale
3428 + " mVScale=" + mVScale);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003429 }
3430 if (mWallpaperX != -1 || mWallpaperY != -1) {
chaviwc65fa582018-08-09 15:33:13 -07003431 pw.println(prefix + "mWallpaperX=" + mWallpaperX
3432 + " mWallpaperY=" + mWallpaperY);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003433 }
3434 if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
chaviwc65fa582018-08-09 15:33:13 -07003435 pw.println(prefix + "mWallpaperXStep=" + mWallpaperXStep
3436 + " mWallpaperYStep=" + mWallpaperYStep);
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003437 }
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003438 if (mWallpaperDisplayOffsetX != Integer.MIN_VALUE
3439 || mWallpaperDisplayOffsetY != Integer.MIN_VALUE) {
chaviwc65fa582018-08-09 15:33:13 -07003440 pw.println(prefix + "mWallpaperDisplayOffsetX=" + mWallpaperDisplayOffsetX
3441 + " mWallpaperDisplayOffsetY=" + mWallpaperDisplayOffsetY);
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003442 }
Jeff Brownc2932a12014-11-20 18:04:05 -08003443 if (mDrawLock != null) {
chaviwc65fa582018-08-09 15:33:13 -07003444 pw.println(prefix + "mDrawLock=" + mDrawLock);
Jeff Brownc2932a12014-11-20 18:04:05 -08003445 }
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003446 if (isDragResizing()) {
chaviwc65fa582018-08-09 15:33:13 -07003447 pw.println(prefix + "isDragResizing=" + isDragResizing());
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003448 }
3449 if (computeDragResizing()) {
chaviwc65fa582018-08-09 15:33:13 -07003450 pw.println(prefix + "computeDragResizing=" + computeDragResizing());
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08003451 }
chaviwc65fa582018-08-09 15:33:13 -07003452 pw.println(prefix + "isOnScreen=" + isOnScreen());
3453 pw.println(prefix + "isVisible=" + isVisible());
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003454 }
Craig Mautner164d4bb2012-11-26 13:51:23 -08003455
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003456 @Override
3457 String getName() {
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003458 return Integer.toHexString(System.identityHashCode(this))
Jorim Jaggia5e10572017-11-15 14:36:26 +01003459 + " " + getWindowTag();
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003460 }
3461
Robert Carra1eb4392015-12-10 12:43:51 -08003462 CharSequence getWindowTag() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003463 CharSequence tag = mAttrs.getTitle();
3464 if (tag == null || tag.length() <= 0) {
3465 tag = mAttrs.packageName;
3466 }
3467 return tag;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003468 }
3469
3470 @Override
3471 public String toString() {
Wale Ogunwalecad05a02015-09-25 10:41:44 -07003472 final CharSequence title = getWindowTag();
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003473 if (mStringNameCache == null || mLastTitle != title || mWasExiting != mAnimatingExit) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08003474 mLastTitle = title;
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003475 mWasExiting = mAnimatingExit;
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003476 mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003477 + " u" + UserHandle.getUserId(mOwnerUid)
Wale Ogunwalec48a3542016-02-19 15:18:45 -08003478 + " " + mLastTitle + (mAnimatingExit ? " EXITING}" : "}");
Dianne Hackborn6e1eb762011-02-17 16:07:28 -08003479 }
3480 return mStringNameCache;
3481 }
Robert Carr58f29132015-10-29 14:19:05 -07003482
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003483 void transformClipRectFromScreenToSurfaceSpace(Rect clipRect) {
Robert Carr58f29132015-10-29 14:19:05 -07003484 if (mHScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003485 clipRect.left = (int) (clipRect.left / mHScale);
3486 clipRect.right = (int) Math.ceil(clipRect.right / mHScale);
Robert Carr58f29132015-10-29 14:19:05 -07003487 }
3488 if (mVScale >= 0) {
Chia-I Wue6bcaf12016-05-27 10:58:48 +08003489 clipRect.top = (int) (clipRect.top / mVScale);
3490 clipRect.bottom = (int) Math.ceil(clipRect.bottom / mVScale);
Robert Carr58f29132015-10-29 14:19:05 -07003491 }
3492 }
Robert Carr31e28482015-12-02 16:53:18 -08003493
chaviw9c81e632018-07-31 11:17:52 -07003494 private void applyGravityAndUpdateFrame(Rect containingFrame, Rect displayFrame) {
Jorim Jaggif5834272016-04-04 20:25:41 -07003495 final int pw = containingFrame.width();
3496 final int ph = containingFrame.height();
Robert Carr31e28482015-12-02 16:53:18 -08003497 final Task task = getTask();
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003498 final boolean inNonFullscreenContainer = !inFullscreenContainer();
Jorim Jaggi5f23a572016-04-22 15:05:50 -07003499 final boolean noLimits = (mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) != 0;
3500
3501 // We need to fit it to the display if either
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003502 // a) The window is in a fullscreen container, or we don't have a task (we assume fullscreen
3503 // for the taskless windows)
Robert Carr6f44db12016-07-21 14:54:43 -07003504 // 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 -07003505 // FLAG_LAYOUT_NO_LIMITS is set. This is so we place Popups, dialogs, and similar windows on
3506 // screen, but SurfaceViews want to be always at a specific location so we don't fit it to
3507 // the display.
3508 final boolean fitToDisplay = (task == null || !inNonFullscreenContainer)
Robert Carr6f44db12016-07-21 14:54:43 -07003509 || ((mAttrs.type != TYPE_BASE_APPLICATION) && !noLimits);
Robert Carr31e28482015-12-02 16:53:18 -08003510 float x, y;
3511 int w,h;
3512
Riddle Hsub398da32019-01-21 21:48:16 +08003513 final boolean inSizeCompatMode = inSizeCompatMode();
Robert Carr31e28482015-12-02 16:53:18 -08003514 if ((mAttrs.flags & FLAG_SCALED) != 0) {
3515 if (mAttrs.width < 0) {
3516 w = pw;
Riddle Hsub398da32019-01-21 21:48:16 +08003517 } else if (inSizeCompatMode) {
Robert Carr31e28482015-12-02 16:53:18 -08003518 w = (int)(mAttrs.width * mGlobalScale + .5f);
3519 } else {
3520 w = mAttrs.width;
3521 }
3522 if (mAttrs.height < 0) {
3523 h = ph;
Riddle Hsub398da32019-01-21 21:48:16 +08003524 } else if (inSizeCompatMode) {
Robert Carr31e28482015-12-02 16:53:18 -08003525 h = (int)(mAttrs.height * mGlobalScale + .5f);
3526 } else {
3527 h = mAttrs.height;
3528 }
3529 } else {
3530 if (mAttrs.width == MATCH_PARENT) {
3531 w = pw;
Riddle Hsub398da32019-01-21 21:48:16 +08003532 } else if (inSizeCompatMode) {
Robert Carr31e28482015-12-02 16:53:18 -08003533 w = (int)(mRequestedWidth * mGlobalScale + .5f);
3534 } else {
3535 w = mRequestedWidth;
3536 }
3537 if (mAttrs.height == MATCH_PARENT) {
3538 h = ph;
Riddle Hsub398da32019-01-21 21:48:16 +08003539 } else if (inSizeCompatMode) {
Robert Carr31e28482015-12-02 16:53:18 -08003540 h = (int)(mRequestedHeight * mGlobalScale + .5f);
3541 } else {
3542 h = mRequestedHeight;
3543 }
3544 }
3545
Riddle Hsub398da32019-01-21 21:48:16 +08003546 if (inSizeCompatMode) {
Robert Carr31e28482015-12-02 16:53:18 -08003547 x = mAttrs.x * mGlobalScale;
3548 y = mAttrs.y * mGlobalScale;
3549 } else {
3550 x = mAttrs.x;
3551 y = mAttrs.y;
3552 }
3553
Wale Ogunwale55ddf8f2017-03-20 08:56:38 -07003554 if (inNonFullscreenContainer && !layoutInParentFrame()) {
Wale Ogunwale79f268d2015-12-18 08:25:47 -08003555 // Make sure window fits in containing frame since it is in a non-fullscreen task as
Robert Carr31e28482015-12-02 16:53:18 -08003556 // required by {@link Gravity#apply} call.
3557 w = Math.min(w, pw);
3558 h = Math.min(h, ph);
3559 }
3560
3561 // Set mFrame
Jorim Jaggif5834272016-04-04 20:25:41 -07003562 Gravity.apply(mAttrs.gravity, w, h, containingFrame,
Robert Carr31e28482015-12-02 16:53:18 -08003563 (int) (x + mAttrs.horizontalMargin * pw),
chaviw492139a2018-07-16 16:07:35 -07003564 (int) (y + mAttrs.verticalMargin * ph), mWindowFrames.mFrame);
Robert Carr31e28482015-12-02 16:53:18 -08003565
3566 // Now make sure the window fits in the overall display frame.
Robert Carre6275582016-02-29 15:45:45 -08003567 if (fitToDisplay) {
chaviw492139a2018-07-16 16:07:35 -07003568 Gravity.applyDisplay(mAttrs.gravity, displayFrame, mWindowFrames.mFrame);
Robert Carre6275582016-02-29 15:45:45 -08003569 }
Robert Carr6e18c5e2016-02-29 15:57:13 -08003570
3571 // We need to make sure we update the CompatFrame as it is used for
3572 // cropping decisions, etc, on systems where we lack a decor layer.
chaviw9c81e632018-07-31 11:17:52 -07003573 mWindowFrames.mCompatFrame.set(mWindowFrames.mFrame);
Riddle Hsub398da32019-01-21 21:48:16 +08003574 if (inSizeCompatMode) {
Robert Carr6e18c5e2016-02-29 15:57:13 -08003575 // See comparable block in computeFrameLw.
chaviw9c81e632018-07-31 11:17:52 -07003576 mWindowFrames.mCompatFrame.scale(mInvGlobalScale);
Robert Carr6e18c5e2016-02-29 15:57:13 -08003577 }
Robert Carr31e28482015-12-02 16:53:18 -08003578 }
Robert Carr51a1b872015-12-08 14:03:13 -08003579
3580 boolean isChildWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003581 return mIsChildWindow;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003582 }
3583
Robert Carrf3b72c72016-03-21 18:16:39 -07003584 boolean layoutInParentFrame() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003585 return mIsChildWindow
3586 && (mAttrs.privateFlags & PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME) != 0;
Robert Carrf3b72c72016-03-21 18:16:39 -07003587 }
3588
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003589 /**
3590 * Returns true if any window added by an application process that if of type
3591 * {@link android.view.WindowManager.LayoutParams#TYPE_TOAST} or that requires that requires
3592 * {@link android.app.AppOpsManager#OP_SYSTEM_ALERT_WINDOW} permission should be hidden when
3593 * this window is visible.
3594 */
3595 boolean hideNonSystemOverlayWindowsWhenVisible() {
Philip P. Moltmann66ce2382018-10-09 13:46:11 -07003596 return (mAttrs.privateFlags & SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != 0
Wale Ogunwale01ad4342017-06-30 07:07:01 -07003597 && mSession.mCanHideNonSystemOverlayWindows;
3598 }
3599
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003600 /** Returns the parent window if this is a child of another window, else null. */
3601 WindowState getParentWindow() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003602 // NOTE: We are not calling getParent() directly as the WindowState might be a child of a
3603 // WindowContainer that isn't a WindowState.
3604 return (mIsChildWindow) ? ((WindowState) super.getParent()) : null;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003605 }
3606
3607 /** Returns the topmost parent window if this is a child of another window, else this. */
3608 WindowState getTopParentWindow() {
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003609 WindowState current = this;
3610 WindowState topParent = current;
3611 while (current != null && current.mIsChildWindow) {
3612 current = current.getParentWindow();
3613 // Parent window can be null if the child is detached from it's parent already, but
3614 // someone still has a reference to access it. So, we return the top parent value we
3615 // already have instead of null.
3616 if (current != null) {
3617 topParent = current;
3618 }
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003619 }
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003620 return topParent;
Wale Ogunwalecaa53af2016-07-17 14:50:26 -07003621 }
3622
Wale Ogunwale9d147902016-07-16 11:58:55 -07003623 boolean isParentWindowHidden() {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003624 final WindowState parent = getParentWindow();
Wale Ogunwaleea92d972016-12-08 07:33:13 -08003625 return parent != null && parent.mHidden;
Wale Ogunwale9d147902016-07-16 11:58:55 -07003626 }
3627
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003628 void setWillReplaceWindow(boolean animate) {
3629 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003630 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003631 c.setWillReplaceWindow(animate);
3632 }
3633
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003634 if ((mAttrs.privateFlags & PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH) != 0
3635 || mAttrs.type == TYPE_APPLICATION_STARTING) {
3636 // We don't set replacing on starting windows since they are added by window manager and
3637 // not the client so won't be replaced by the client.
3638 return;
Robert Carra1eb4392015-12-10 12:43:51 -08003639 }
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003640
3641 mWillReplaceWindow = true;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003642 mReplacementWindow = null;
Wale Ogunwale6d8e06b2016-01-05 10:43:25 -08003643 mAnimateReplacingWindow = animate;
Robert Carra1eb4392015-12-10 12:43:51 -08003644 }
Chong Zhangf596cd52016-01-05 13:42:44 -08003645
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003646 void clearWillReplaceWindow() {
Chong Zhangf596cd52016-01-05 13:42:44 -08003647 mWillReplaceWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003648 mReplacementWindow = null;
Chong Zhangf596cd52016-01-05 13:42:44 -08003649 mAnimateReplacingWindow = false;
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003650
3651 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003652 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003653 c.clearWillReplaceWindow();
3654 }
3655 }
3656
3657 boolean waitingForReplacement() {
3658 if (mWillReplaceWindow) {
3659 return true;
3660 }
3661
3662 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003663 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003664 if (c.waitingForReplacement()) {
3665 return true;
3666 }
3667 }
3668 return false;
Chong Zhangf596cd52016-01-05 13:42:44 -08003669 }
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003670
Chong Zhang4d7369a2016-04-25 16:09:14 -07003671 void requestUpdateWallpaperIfNeeded() {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003672 final DisplayContent dc = getDisplayContent();
3673 if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
3674 dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
3675 dc.setLayoutNeeded();
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003676 mWmService.mWindowPlacerLocked.requestTraversal();
Chong Zhang4d7369a2016-04-25 16:09:14 -07003677 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003678
3679 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003680 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003681 c.requestUpdateWallpaperIfNeeded();
3682 }
Chong Zhang4d7369a2016-04-25 16:09:14 -07003683 }
3684
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003685 float translateToWindowX(float x) {
chaviw492139a2018-07-16 16:07:35 -07003686 float winX = x - mWindowFrames.mFrame.left;
Riddle Hsub398da32019-01-21 21:48:16 +08003687 if (inSizeCompatMode()) {
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003688 winX *= mGlobalScale;
3689 }
3690 return winX;
3691 }
3692
3693 float translateToWindowY(float y) {
chaviw492139a2018-07-16 16:07:35 -07003694 float winY = y - mWindowFrames.mFrame.top;
Riddle Hsub398da32019-01-21 21:48:16 +08003695 if (inSizeCompatMode()) {
Vladislav Kaznacheev989b58a2016-02-10 12:19:33 -08003696 winY *= mGlobalScale;
3697 }
3698 return winY;
3699 }
Robert Carrd1a010f2016-04-07 22:36:22 -07003700
3701 // During activity relaunch due to resize, we sometimes use window replacement
3702 // for only child windows (as the main window is handled by window preservation)
3703 // and the big surface.
3704 //
Chong Zhangfea963e2016-08-15 17:14:16 -07003705 // Though windows of TYPE_APPLICATION or TYPE_DRAWN_APPLICATION (as opposed to
3706 // TYPE_BASE_APPLICATION) are not children in the sense of an attached window,
3707 // we also want to replace them at such phases, as they won't be covered by window
3708 // preservation, and in general we expect them to return following relaunch.
Robert Carrd1a010f2016-04-07 22:36:22 -07003709 boolean shouldBeReplacedWithChildren() {
Chong Zhang921f8e32016-08-17 14:26:57 -07003710 return mIsChildWindow || mAttrs.type == TYPE_APPLICATION
Chong Zhangfea963e2016-08-15 17:14:16 -07003711 || mAttrs.type == TYPE_DRAWN_APPLICATION;
Robert Carrd1a010f2016-04-07 22:36:22 -07003712 }
Robert Carrfd10cd12016-06-29 16:41:50 -07003713
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003714 void setWillReplaceChildWindows() {
3715 if (shouldBeReplacedWithChildren()) {
3716 setWillReplaceWindow(false /* animate */);
3717 }
3718 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003719 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003720 c.setWillReplaceChildWindows();
3721 }
3722 }
3723
3724 WindowState getReplacingWindow() {
3725 if (mAnimatingExit && mWillReplaceWindow && mAnimateReplacingWindow) {
3726 return this;
3727 }
3728 for (int i = mChildren.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003729 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07003730 final WindowState replacing = c.getReplacingWindow();
3731 if (replacing != null) {
3732 return replacing;
3733 }
3734 }
3735 return null;
3736 }
3737
Jorim Jaggife762342016-10-13 14:33:27 +02003738 @Override
Robert Carrfd10cd12016-06-29 16:41:50 -07003739 public int getRotationAnimationHint() {
3740 if (mAppToken != null) {
3741 return mAppToken.mRotationAnimationHint;
3742 } else {
3743 return -1;
3744 }
3745 }
Wale Ogunwale9d147902016-07-16 11:58:55 -07003746
Jorim Jaggife762342016-10-13 14:33:27 +02003747 @Override
3748 public boolean isInputMethodWindow() {
3749 return mIsImWindow;
3750 }
3751
Wale Ogunwale9d147902016-07-16 11:58:55 -07003752 // This must be called while inside a transaction.
3753 boolean performShowLocked() {
3754 if (isHiddenFromUserLocked()) {
3755 if (DEBUG_VISIBILITY) Slog.w(TAG, "hiding " + this + ", belonging to " + mOwnerUid);
3756 hideLw(false);
3757 return false;
3758 }
3759
3760 logPerformShow("performShow on ");
3761
Jorim Jaggia50da602016-12-29 11:51:42 +01003762 final int drawState = mWinAnimator.mDrawState;
3763 if ((drawState == HAS_DRAWN || drawState == READY_TO_SHOW)
3764 && mAttrs.type != TYPE_APPLICATION_STARTING && mAppToken != null) {
3765 mAppToken.onFirstWindowDrawn(this, mWinAnimator);
3766 }
3767
Jorim Jaggib0d27342016-11-01 16:10:42 -07003768 if (mWinAnimator.mDrawState != READY_TO_SHOW || !isReadyForDisplay()) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003769 return false;
3770 }
3771
3772 logPerformShow("Showing ");
3773
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003774 mWmService.enableScreenIfNeededLocked();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003775 mWinAnimator.applyEnterAnimationLocked();
3776
3777 // Force the show in the next prepareSurfaceLocked() call.
3778 mWinAnimator.mLastAlpha = -1;
Robert Carre13b58e2017-08-31 14:50:44 -07003779 if (DEBUG_ANIM) Slog.v(TAG,
Wale Ogunwale9d147902016-07-16 11:58:55 -07003780 "performShowLocked: mDrawState=HAS_DRAWN in " + this);
3781 mWinAnimator.mDrawState = HAS_DRAWN;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08003782 mWmService.scheduleAnimationLocked();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003783
3784 if (mHidden) {
3785 mHidden = false;
3786 final DisplayContent displayContent = getDisplayContent();
3787
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003788 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003789 final WindowState c = mChildren.get(i);
Wale Ogunwale9d147902016-07-16 11:58:55 -07003790 if (c.mWinAnimator.mSurfaceController != null) {
3791 c.performShowLocked();
3792 // It hadn't been shown, which means layout not performed on it, so now we
3793 // want to make sure to do a layout. If called from within the transaction
3794 // loop, this will cause it to restart with a new layout.
3795 if (displayContent != null) {
Wale Ogunwale2b06bfc2016-09-28 14:17:05 -07003796 displayContent.setLayoutNeeded();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003797 }
3798 }
3799 }
3800 }
3801
Wale Ogunwale9d147902016-07-16 11:58:55 -07003802 if (mAttrs.type == TYPE_INPUT_METHOD) {
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003803 getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
Wale Ogunwale9d147902016-07-16 11:58:55 -07003804 }
3805
3806 return true;
3807 }
3808
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003809 private void logPerformShow(String prefix) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003810 if (DEBUG_VISIBILITY
Jorim Jaggie4b0f282017-05-17 15:10:29 +02003811 || (DEBUG_STARTING_WINDOW_VERBOSE && mAttrs.type == TYPE_APPLICATION_STARTING)) {
Wale Ogunwale9d147902016-07-16 11:58:55 -07003812 Slog.v(TAG, prefix + this
3813 + ": mDrawState=" + mWinAnimator.drawStateToString()
Jorim Jaggib0d27342016-11-01 16:10:42 -07003814 + " readyForDisplay=" + isReadyForDisplay()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003815 + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
3816 + " during animation: policyVis=" + mPolicyVisibility
3817 + " parentHidden=" + isParentWindowHidden()
3818 + " tok.hiddenRequested="
Wale Ogunwale360a8bc2016-10-10 13:25:26 -07003819 + (mAppToken != null && mAppToken.hiddenRequested)
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003820 + " tok.hidden=" + (mAppToken != null && mAppToken.isHidden())
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02003821 + " animating=" + isAnimating()
Wale Ogunwale9d147902016-07-16 11:58:55 -07003822 + " tok animating="
Jorim Jaggif5f9e122017-10-24 18:21:09 +02003823 + (mAppToken != null && mAppToken.isSelfAnimating())
Wale Ogunwale9d147902016-07-16 11:58:55 -07003824 + " Callers=" + Debug.getCallers(4));
3825 }
3826 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003827
3828 WindowInfo getWindowInfo() {
3829 WindowInfo windowInfo = WindowInfo.obtain();
3830 windowInfo.type = mAttrs.type;
3831 windowInfo.layer = mLayer;
3832 windowInfo.token = mClient.asBinder();
Phil Weaver5dc3ebc2017-08-16 13:04:20 -07003833 if (mAppToken != null) {
3834 windowInfo.activityToken = mAppToken.appToken.asBinder();
3835 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003836 windowInfo.title = mAttrs.accessibilityTitle;
Phil Weaverbb2f28a2017-12-22 09:44:28 -08003837 // Panel windows have no public way to set the a11y title directly. Use the
3838 // regular title as a fallback.
Phil Weaver568cf662018-04-24 17:09:26 -07003839 final boolean isPanelWindow = (mAttrs.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW)
3840 && (mAttrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW);
3841 // Accessibility overlays should have titles that work for accessibility, and can't set
3842 // the a11y title themselves.
3843 final boolean isAccessibilityOverlay =
3844 windowInfo.type == WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
3845 if (TextUtils.isEmpty(windowInfo.title) && (isPanelWindow || isAccessibilityOverlay)) {
Jackal Guo25a33cbd2018-08-01 16:08:45 +08003846 final CharSequence title = mAttrs.getTitle();
3847 windowInfo.title = TextUtils.isEmpty(title) ? null : title;
Phil Weaverbb2f28a2017-12-22 09:44:28 -08003848 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003849 windowInfo.accessibilityIdOfAnchor = mAttrs.accessibilityIdOfAnchor;
3850 windowInfo.focused = isFocused();
Phil Weaverf00cd142017-03-03 13:44:00 -08003851 Task task = getTask();
Wale Ogunwale44f036f2017-09-29 05:09:09 -07003852 windowInfo.inPictureInPicture = (task != null) && task.inPinnedWindowingMode();
Jackal Guoac2b62e2018-08-22 18:28:46 +08003853 windowInfo.hasFlagWatchOutsideTouch =
3854 (mAttrs.flags & WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH) != 0;
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003855
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003856 if (mIsChildWindow) {
3857 windowInfo.parentToken = getParentWindow().mClient.asBinder();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003858 }
3859
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003860 final int childCount = mChildren.size();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003861 if (childCount > 0) {
3862 if (windowInfo.childTokens == null) {
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07003863 windowInfo.childTokens = new ArrayList(childCount);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003864 }
3865 for (int j = 0; j < childCount; j++) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07003866 final WindowState child = mChildren.get(j);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003867 windowInfo.childTokens.add(child.mClient.asBinder());
3868 }
3869 }
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07003870 return windowInfo;
3871 }
3872
Wale Ogunwale9adfe572016-09-08 20:43:58 -07003873 @Override
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003874 boolean forAllWindows(ToBooleanFunction<WindowState> callback, boolean traverseTopToBottom) {
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003875 if (mChildren.isEmpty()) {
3876 // The window has no children so we just return it.
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003877 return applyInOrderWithImeWindows(callback, traverseTopToBottom);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003878 }
3879
3880 if (traverseTopToBottom) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003881 return forAllWindowTopToBottom(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003882 } else {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003883 return forAllWindowBottomToTop(callback);
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003884 }
3885 }
3886
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003887 private boolean forAllWindowBottomToTop(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003888 // We want to consume the negative sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003889 // below the parent, then this window (the parent), and then the positive sublayer children
3890 // because they need to appear above the parent.
3891 int i = 0;
3892 final int count = mChildren.size();
3893 WindowState child = mChildren.get(i);
3894
3895 while (i < count && child.mSubLayer < 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003896 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003897 return true;
3898 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003899 i++;
3900 if (i >= count) {
3901 break;
3902 }
3903 child = mChildren.get(i);
3904 }
3905
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003906 if (applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003907 return true;
3908 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003909
3910 while (i < count) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003911 if (child.applyInOrderWithImeWindows(callback, false /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003912 return true;
3913 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003914 i++;
3915 if (i >= count) {
3916 break;
3917 }
3918 child = mChildren.get(i);
3919 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003920
3921 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003922 }
3923
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003924 private boolean forAllWindowTopToBottom(ToBooleanFunction<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003925 // We want to consume the positive sublayer children first because they need to appear
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003926 // above the parent, then this window (the parent), and then the negative sublayer children
3927 // because they need to appear above the parent.
3928 int i = mChildren.size() - 1;
3929 WindowState child = mChildren.get(i);
3930
3931 while (i >= 0 && child.mSubLayer >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003932 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003933 return true;
3934 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003935 --i;
3936 if (i < 0) {
3937 break;
3938 }
3939 child = mChildren.get(i);
3940 }
3941
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003942 if (applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003943 return true;
3944 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003945
3946 while (i >= 0) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003947 if (child.applyInOrderWithImeWindows(callback, true /* traverseTopToBottom */)) {
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003948 return true;
3949 }
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003950 --i;
3951 if (i < 0) {
3952 break;
3953 }
3954 child = mChildren.get(i);
3955 }
Wale Ogunwalef4ebe2e2016-11-09 13:24:43 -08003956
3957 return false;
Wale Ogunwaleb783fd82016-11-04 09:51:54 -07003958 }
3959
Robert Carr9785cf32018-04-25 15:06:07 -07003960 private boolean applyImeWindowsIfNeeded(ToBooleanFunction<WindowState> callback,
3961 boolean traverseTopToBottom) {
3962 // If this window is the current IME target, so we need to process the IME windows
3963 // directly above it. The exception is if we are in split screen
3964 // in which case we process the IME at the DisplayContent level to
3965 // ensure it is above the docked divider.
3966 if (isInputMethodTarget() && !inSplitScreenWindowingMode()) {
3967 if (getDisplayContent().forAllImeWindows(callback, traverseTopToBottom)) {
3968 return true;
3969 }
3970 }
3971 return false;
3972 }
3973
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003974 private boolean applyInOrderWithImeWindows(ToBooleanFunction<WindowState> callback,
3975 boolean traverseTopToBottom) {
3976 if (traverseTopToBottom) {
Robert Carr9785cf32018-04-25 15:06:07 -07003977 if (applyImeWindowsIfNeeded(callback, traverseTopToBottom)
3978 || callback.apply(this)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003979 return true;
3980 }
3981 } else {
Robert Carr9785cf32018-04-25 15:06:07 -07003982 if (callback.apply(this)
3983 || applyImeWindowsIfNeeded(callback, traverseTopToBottom)) {
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003984 return true;
3985 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003986 }
Wale Ogunwale3c1170d2016-12-02 14:44:52 -08003987 return false;
3988 }
3989
Wale Ogunwaled1880962016-11-08 10:31:59 -08003990 WindowState getWindow(Predicate<WindowState> callback) {
Wale Ogunwale34247952017-02-19 11:57:53 -08003991 if (mChildren.isEmpty()) {
3992 return callback.test(this) ? this : null;
3993 }
3994
3995 // We want to consume the positive sublayer children first because they need to appear
3996 // above the parent, then this window (the parent), and then the negative sublayer children
3997 // because they need to appear above the parent.
3998 int i = mChildren.size() - 1;
3999 WindowState child = mChildren.get(i);
4000
4001 while (i >= 0 && child.mSubLayer >= 0) {
4002 if (callback.test(child)) {
4003 return child;
4004 }
4005 --i;
4006 if (i < 0) {
4007 break;
4008 }
4009 child = mChildren.get(i);
4010 }
4011
Wale Ogunwaled1880962016-11-08 10:31:59 -08004012 if (callback.test(this)) {
4013 return this;
4014 }
Wale Ogunwale34247952017-02-19 11:57:53 -08004015
4016 while (i >= 0) {
4017 if (callback.test(child)) {
4018 return child;
4019 }
4020 --i;
4021 if (i < 0) {
4022 break;
4023 }
4024 child = mChildren.get(i);
4025 }
4026
4027 return null;
Wale Ogunwaled1880962016-11-08 10:31:59 -08004028 }
4029
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01004030 /**
4031 * @return True if we our one of our ancestors has {@link #mAnimatingExit} set to true, false
4032 * otherwise.
4033 */
4034 @VisibleForTesting
4035 boolean isSelfOrAncestorWindowAnimatingExit() {
4036 WindowState window = this;
4037 do {
4038 if (window.mAnimatingExit) {
4039 return true;
4040 }
4041 window = window.getParentWindow();
4042 } while (window != null);
4043 return false;
4044 }
4045
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004046 void onExitAnimationDone() {
4047 if (DEBUG_ANIM) Slog.v(TAG, "onExitAnimationDone in " + this
4048 + ": exiting=" + mAnimatingExit + " remove=" + mRemoveOnExit
Jorim Jaggia5e10572017-11-15 14:36:26 +01004049 + " selfAnimating=" + isSelfAnimating());
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004050
Wale Ogunwalee4343ef2016-07-19 08:00:46 -07004051 if (!mChildren.isEmpty()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004052 // Copying to a different list as multiple children can be removed.
Jorim Jaggi59f3e922018-01-05 15:40:32 +01004053 final ArrayList<WindowState> childWindows = new ArrayList<>(mChildren);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004054 for (int i = childWindows.size() - 1; i >= 0; i--) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004055 childWindows.get(i).onExitAnimationDone();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004056 }
4057 }
4058
4059 if (mWinAnimator.mEnteringAnimation) {
4060 mWinAnimator.mEnteringAnimation = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004061 mWmService.requestTraversal();
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004062 // System windows don't have an activity and an app token as a result, but need a way
4063 // to be informed about their entrance animation end.
4064 if (mAppToken == null) {
4065 try {
4066 mClient.dispatchWindowShown();
4067 } catch (RemoteException e) {
4068 }
4069 }
4070 }
4071
Jorim Jaggia5e10572017-11-15 14:36:26 +01004072 if (isSelfAnimating()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004073 return;
4074 }
4075
Jorim Jaggia5e10572017-11-15 14:36:26 +01004076 //TODO (multidisplay): Accessibility is supported only for the default display.
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004077 if (mWmService.mAccessibilityController != null && getDisplayId() == DEFAULT_DISPLAY) {
4078 mWmService.mAccessibilityController.onSomeWindowResizedOrMovedLocked();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004079 }
4080
Jorim Jaggi4876b4a2018-01-11 15:43:49 +01004081 if (!isSelfOrAncestorWindowAnimatingExit()) {
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004082 return;
4083 }
4084
Wale Ogunwale9f25bee2016-08-02 07:23:47 -07004085 if (localLOGV || DEBUG_ADD_REMOVE) Slog.v(TAG,
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004086 "Exit animation finished in " + this + ": remove=" + mRemoveOnExit);
4087
4088 mDestroying = true;
4089
4090 final boolean hasSurface = mWinAnimator.hasSurface();
Jorim Jaggi50575902018-04-10 17:49:30 +02004091
4092 // Use pendingTransaction here so hide is done the same transaction as the other
4093 // animations when exiting
4094 mWinAnimator.hide(getPendingTransaction(), "onExitAnimationDone");
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004095
4096 // If we have an app token, we ask it to destroy the surface for us, so that it can take
4097 // care to ensure the activity has actually stopped and the surface is not still in use.
4098 // Otherwise we add the service to mDestroySurface and allow it to be processed in our next
4099 // transaction.
4100 if (mAppToken != null) {
4101 mAppToken.destroySurfaces();
4102 } else {
4103 if (hasSurface) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004104 mWmService.mDestroySurface.add(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004105 }
4106 if (mRemoveOnExit) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004107 mWmService.mPendingRemove.add(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004108 mRemoveOnExit = false;
4109 }
4110 }
4111 mAnimatingExit = false;
Wale Ogunwale0303c572016-10-20 10:16:29 -07004112 getDisplayContent().mWallpaperController.hideWallpapers(this);
Wale Ogunwaleadde52e2016-07-16 13:11:55 -07004113 }
Dan Willemsen117197f2016-07-30 13:02:59 -07004114
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004115 boolean clearAnimatingFlags() {
4116 boolean didSomething = false;
4117 // We don't want to clear it out for windows that get replaced, because the
4118 // animation depends on the flag to remove the replaced window.
4119 //
4120 // We also don't clear the mAnimatingExit flag for windows which have the
4121 // mRemoveOnExit flag. This indicates an explicit remove request has been issued
4122 // by the client. We should let animation proceed and not clear this flag or
4123 // they won't eventually be removed by WindowStateAnimator#finishExit.
4124 if (!mWillReplaceWindow && !mRemoveOnExit) {
4125 // Clear mAnimating flag together with mAnimatingExit. When animation
4126 // changes from exiting to entering, we need to clear this flag until the
4127 // new animation gets applied, so that isAnimationStarting() becomes true
4128 // until then.
4129 // Otherwise applySurfaceChangesTransaction will fail to skip surface
4130 // placement for this window during this period, one or more frame will
4131 // show up with wrong position or scale.
4132 if (mAnimatingExit) {
4133 mAnimatingExit = false;
4134 didSomething = true;
4135 }
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004136 if (mDestroying) {
4137 mDestroying = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004138 mWmService.mDestroySurface.remove(this);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004139 didSomething = true;
4140 }
4141 }
4142
4143 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004144 didSomething |= (mChildren.get(i)).clearAnimatingFlags();
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004145 }
4146
4147 return didSomething;
4148 }
4149
Winson4b4ba902016-07-27 19:45:52 -07004150 public boolean isRtl() {
Andrii Kulian9d91ca62016-09-29 22:28:09 -07004151 return getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
Winson4b4ba902016-07-27 19:45:52 -07004152 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004153
4154 void hideWallpaperWindow(boolean wasDeferred, String reason) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004155 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004156 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004157 c.hideWallpaperWindow(wasDeferred, reason);
4158 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004159 if (!mWinAnimator.mLastHidden || wasDeferred) {
4160 mWinAnimator.hide(reason);
Tiger Huang50d45462018-05-25 22:57:52 +08004161 getDisplayContent().mWallpaperController.mDeferredHideWallpaper = null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004162 dispatchWallpaperVisibility(false);
4163 final DisplayContent displayContent = getDisplayContent();
4164 if (displayContent != null) {
4165 displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
Tiger Huang50d45462018-05-25 22:57:52 +08004166 if (DEBUG_LAYOUT_REPEATS) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004167 mWmService.mWindowPlacerLocked.debugLayoutRepeats("hideWallpaperWindow " + this,
Tiger Huang50d45462018-05-25 22:57:52 +08004168 displayContent.pendingLayoutChanges);
4169 }
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004170 }
4171 }
4172 }
4173
4174 /**
4175 * Check wallpaper window for visibility change and notify window if so.
4176 * @param visible Current visibility.
4177 */
4178 void dispatchWallpaperVisibility(final boolean visible) {
4179 final boolean hideAllowed =
Wale Ogunwale0303c572016-10-20 10:16:29 -07004180 getDisplayContent().mWallpaperController.mDeferredHideWallpaper == null;
Wale Ogunwalee4da0c12016-07-29 12:47:02 -07004181
4182 // Only send notification if the visibility actually changed and we are not trying to hide
4183 // the wallpaper when we are deferring hiding of the wallpaper.
4184 if (mWallpaperVisible != visible && (hideAllowed || visible)) {
4185 mWallpaperVisible = visible;
4186 try {
4187 if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
4188 "Updating vis of wallpaper " + this
4189 + ": " + visible + " from:\n" + Debug.getCallers(4, " "));
4190 mClient.dispatchAppVisibility(visible);
4191 } catch (RemoteException e) {
4192 }
4193 }
4194 }
4195
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004196 boolean hasVisibleNotDrawnWallpaper() {
4197 if (mWallpaperVisible && !isDrawnLw()) {
4198 return true;
4199 }
4200 for (int j = mChildren.size() - 1; j >= 0; --j) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004201 final WindowState c = mChildren.get(j);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004202 if (c.hasVisibleNotDrawnWallpaper()) {
4203 return true;
4204 }
4205 }
4206 return false;
4207 }
4208
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004209 void updateReportedVisibility(UpdateReportedVisibilityResults results) {
4210 for (int i = mChildren.size() - 1; i >= 0; --i) {
Wale Ogunwaled90546a2016-09-09 23:28:03 -07004211 final WindowState c = mChildren.get(i);
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004212 c.updateReportedVisibility(results);
4213 }
4214
4215 if (mAppFreezing || mViewVisibility != View.VISIBLE
4216 || mAttrs.type == TYPE_APPLICATION_STARTING
4217 || mDestroying) {
4218 return;
4219 }
4220 if (DEBUG_VISIBILITY) {
4221 Slog.v(TAG, "Win " + this + ": isDrawn=" + isDrawnLw()
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02004222 + ", animating=" + isAnimating());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004223 if (!isDrawnLw()) {
4224 Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
4225 + " pv=" + mPolicyVisibility
4226 + " mDrawState=" + mWinAnimator.mDrawState
4227 + " ph=" + isParentWindowHidden()
4228 + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02004229 + " a=" + isAnimating());
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004230 }
4231 }
4232
4233 results.numInteresting++;
4234 if (isDrawnLw()) {
4235 results.numDrawn++;
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02004236 if (!isAnimating()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004237 results.numVisible++;
4238 }
4239 results.nowGone = false;
Jorim Jaggi5bdccba2018-08-13 16:40:49 +02004240 } else if (isAnimating()) {
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004241 results.nowGone = false;
4242 }
4243 }
4244
Robert Carr683e05d2018-04-18 15:11:04 -07004245 private boolean skipDecorCrop() {
4246 // The decor frame is used to specify the region not covered by the system
4247 // decorations (nav bar, status bar). In case this is empty, for example with
4248 // FLAG_TRANSLUCENT_NAVIGATION, we don't need to do any cropping.
chaviw553b0212018-07-12 13:37:01 -07004249 if (mWindowFrames.mDecorFrame.isEmpty()) {
Robert Carr683e05d2018-04-18 15:11:04 -07004250 return true;
4251 }
4252
4253 // But if we have a frame, and are an application window, then we must be cropped.
4254 if (mAppToken != null) {
4255 return false;
4256 }
4257
4258 // For non application windows, we may be allowed to extend over the decor bars
4259 // depending on our type and permissions assosciated with our token.
4260 return mToken.canLayerAboveSystemBars();
4261 }
4262
Robert Carrfbbde852016-10-18 11:02:28 -07004263 /**
4264 * Calculate the window crop according to system decor policy. In general this is
4265 * the system decor rect (see #calculateSystemDecorRect), but we also have some
4266 * special cases. This rectangle is in screen space.
4267 */
4268 void calculatePolicyCrop(Rect policyCrop) {
4269 final DisplayContent displayContent = getDisplayContent();
Robert Carrfbbde852016-10-18 11:02:28 -07004270
Riddle Hsub398da32019-01-21 21:48:16 +08004271 if (!displayContent.isDefaultDisplay && !displayContent.supportsSystemDecorations()) {
Robert Carrfbbde852016-10-18 11:02:28 -07004272 // On a different display there is no system decor. Crop the window
4273 // by the screen boundaries.
Riddle Hsub398da32019-01-21 21:48:16 +08004274 final DisplayInfo displayInfo = displayContent.getDisplayInfo();
chaviw9c81e632018-07-31 11:17:52 -07004275 policyCrop.set(0, 0, mWindowFrames.mCompatFrame.width(),
4276 mWindowFrames.mCompatFrame.height());
4277 policyCrop.intersect(-mWindowFrames.mCompatFrame.left, -mWindowFrames.mCompatFrame.top,
4278 displayInfo.logicalWidth - mWindowFrames.mCompatFrame.left,
4279 displayInfo.logicalHeight - mWindowFrames.mCompatFrame.top);
Robert Carr683e05d2018-04-18 15:11:04 -07004280 } else if (skipDecorCrop()) {
Robert Carrfbbde852016-10-18 11:02:28 -07004281 // Windows without policy decor aren't cropped.
chaviw9c81e632018-07-31 11:17:52 -07004282 policyCrop.set(0, 0, mWindowFrames.mCompatFrame.width(),
4283 mWindowFrames.mCompatFrame.height());
Robert Carrfbbde852016-10-18 11:02:28 -07004284 } else {
4285 // Crop to the system decor specified by policy.
4286 calculateSystemDecorRect(policyCrop);
4287 }
4288 }
4289
4290 /**
4291 * The system decor rect is the region of the window which is not covered
4292 * by system decorations.
4293 */
4294 private void calculateSystemDecorRect(Rect systemDecorRect) {
chaviw553b0212018-07-12 13:37:01 -07004295 final Rect decorRect = mWindowFrames.mDecorFrame;
chaviw492139a2018-07-16 16:07:35 -07004296 final int width = mWindowFrames.mFrame.width();
4297 final int height = mWindowFrames.mFrame.height();
Robert Carrfbbde852016-10-18 11:02:28 -07004298
chaviw492139a2018-07-16 16:07:35 -07004299 final int left = mWindowFrames.mFrame.left;
4300 final int top = mWindowFrames.mFrame.top;
Robert Carrfbbde852016-10-18 11:02:28 -07004301
4302 // Initialize the decor rect to the entire frame.
4303 if (isDockedResizing()) {
4304 // If we are resizing with the divider, the task bounds might be smaller than the
4305 // stack bounds. The system decor is used to clip to the task bounds, which we don't
4306 // want in this case in order to avoid holes.
4307 //
4308 // We take care to not shrink the width, for surfaces which are larger than
4309 // the display region. Of course this area will not eventually be visible
4310 // but if we truncate the width now, we will calculate incorrectly
4311 // when adjusting to the stack bounds.
4312 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
4313 systemDecorRect.set(0, 0,
4314 Math.max(width, displayInfo.logicalWidth),
4315 Math.max(height, displayInfo.logicalHeight));
4316 } else {
4317 systemDecorRect.set(0, 0, width, height);
4318 }
4319
4320 // If a freeform window is animating from a position where it would be cutoff, it would be
4321 // cutoff during the animation. We don't want that, so for the duration of the animation
4322 // we ignore the decor cropping and depend on layering to position windows correctly.
chaviw95136622018-04-09 15:20:06 -07004323
4324 // We also ignore cropping when the window is currently being drag resized in split screen
4325 // to prevent issues with the crop for screenshot.
4326 final boolean cropToDecor =
4327 !(inFreeformWindowingMode() && isAnimatingLw()) && !isDockedResizing();
Robert Carrfbbde852016-10-18 11:02:28 -07004328 if (cropToDecor) {
4329 // Intersect with the decor rect, offsetted by window position.
4330 systemDecorRect.intersect(decorRect.left - left, decorRect.top - top,
4331 decorRect.right - left, decorRect.bottom - top);
4332 }
4333
4334 // If size compatibility is being applied to the window, the
4335 // surface is scaled relative to the screen. Also apply this
4336 // scaling to the crop rect. We aren't using the standard rect
4337 // scale function because we want to round things to make the crop
4338 // always round to a larger rect to ensure we don't crop too
4339 // much and hide part of the window that should be seen.
Riddle Hsub398da32019-01-21 21:48:16 +08004340 if (inSizeCompatMode() && mInvGlobalScale != 1.0f) {
Robert Carrfbbde852016-10-18 11:02:28 -07004341 final float scale = mInvGlobalScale;
4342 systemDecorRect.left = (int) (systemDecorRect.left * scale - 0.5f);
4343 systemDecorRect.top = (int) (systemDecorRect.top * scale - 0.5f);
4344 systemDecorRect.right = (int) ((systemDecorRect.right + 1) * scale - 0.5f);
4345 systemDecorRect.bottom = (int) ((systemDecorRect.bottom + 1) * scale - 0.5f);
4346 }
4347
4348 }
4349
4350 /**
4351 * Expand the given rectangle by this windows surface insets. This
4352 * takes you from the 'window size' to the 'surface size'.
4353 * The surface insets are positive in each direction, so we inset by
4354 * the inverse.
4355 */
4356 void expandForSurfaceInsets(Rect r) {
4357 r.inset(-mAttrs.surfaceInsets.left,
4358 -mAttrs.surfaceInsets.top,
4359 -mAttrs.surfaceInsets.right,
4360 -mAttrs.surfaceInsets.bottom);
4361 }
4362
Robert Carrc91d1c32017-02-15 19:37:46 -08004363 boolean surfaceInsetsChanging() {
4364 return !mLastSurfaceInsets.equals(mAttrs.surfaceInsets);
4365 }
4366
Bryce Leef858b572017-06-29 14:03:33 -07004367 int relayoutVisibleWindow(int result, int attrChanges, int oldVisibility) {
Robert Carrecc06b32017-04-18 14:25:10 -07004368 final boolean wasVisible = isVisibleLw();
4369
4370 result |= (!wasVisible || !isDrawnLw()) ? RELAYOUT_RES_FIRST_TIME : 0;
Robert Carr7b3d11d2018-03-15 14:34:45 -07004371
Robert Carrc91d1c32017-02-15 19:37:46 -08004372 if (mAnimatingExit) {
4373 Slog.d(TAG, "relayoutVisibleWindow: " + this + " mAnimatingExit=true, mRemoveOnExit="
4374 + mRemoveOnExit + ", mDestroying=" + mDestroying);
4375
Riddle Hsub8d704b2019-02-22 12:44:12 +08004376 // Cancel the existing exit animation for the next enter animation.
4377 if (isSelfAnimating()) {
4378 cancelAnimation();
4379 destroySurfaceUnchecked();
4380 }
Robert Carrc91d1c32017-02-15 19:37:46 -08004381 mAnimatingExit = false;
4382 }
4383 if (mDestroying) {
4384 mDestroying = false;
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004385 mWmService.mDestroySurface.remove(this);
Robert Carrc91d1c32017-02-15 19:37:46 -08004386 }
4387 if (oldVisibility == View.GONE) {
4388 mWinAnimator.mEnterAnimationPending = true;
4389 }
4390
Andrii Kulian8ee72852017-03-10 10:36:45 -08004391 mLastVisibleLayoutRotation = getDisplayContent().getRotation();
Robert Carrc91d1c32017-02-15 19:37:46 -08004392
4393 mWinAnimator.mEnteringAnimation = true;
Bryce Leeae73ba42017-05-05 09:58:25 -07004394
Bryce Leef858b572017-06-29 14:03:33 -07004395 prepareWindowToDisplayDuringRelayout(wasVisible);
Bryce Leeae73ba42017-05-05 09:58:25 -07004396
Robert Carrc91d1c32017-02-15 19:37:46 -08004397 if ((attrChanges & FORMAT_CHANGED) != 0) {
4398 // If the format can't be changed in place, preserve the old surface until the app draws
4399 // on the new one. This prevents blinking when we change elevation of freeform and
4400 // pinned windows.
4401 if (!mWinAnimator.tryChangeFormatInPlaceLocked()) {
4402 mWinAnimator.preserveSurfaceLocked();
4403 result |= RELAYOUT_RES_SURFACE_CHANGED
4404 | RELAYOUT_RES_FIRST_TIME;
4405 }
4406 }
4407
4408 // When we change the Surface size, in scenarios which may require changing
4409 // the surface position in sync with the resize, we use a preserved surface
4410 // so we can freeze it while waiting for the client to report draw on the newly
Robert Carrc6d5af52018-02-26 17:46:00 -08004411 // sized surface. At the moment this logic is only in place for switching
4412 // in and out of the big surface for split screen resize.
4413 if (isDragResizeChanged()) {
Robert Carrc91d1c32017-02-15 19:37:46 -08004414 setDragResizing();
Robert Carrc91d1c32017-02-15 19:37:46 -08004415 // We can only change top level windows to the full-screen surface when
4416 // resizing (as we only have one full-screen surface). So there is no need
4417 // to preserve and destroy windows which are attached to another, they
4418 // will keep their surface and its size may change over time.
4419 if (mHasSurface && !isChildWindow()) {
4420 mWinAnimator.preserveSurfaceLocked();
Robert Carrdb2f6e62017-03-01 20:17:58 -08004421 result |= RELAYOUT_RES_SURFACE_CHANGED |
4422 RELAYOUT_RES_FIRST_TIME;
Robert Carrc91d1c32017-02-15 19:37:46 -08004423 }
4424 }
4425 final boolean freeformResizing = isDragResizing()
4426 && getResizeMode() == DRAG_RESIZE_MODE_FREEFORM;
4427 final boolean dockedResizing = isDragResizing()
4428 && getResizeMode() == DRAG_RESIZE_MODE_DOCKED_DIVIDER;
4429 result |= freeformResizing ? RELAYOUT_RES_DRAG_RESIZING_FREEFORM : 0;
4430 result |= dockedResizing ? RELAYOUT_RES_DRAG_RESIZING_DOCKED : 0;
Robert Carrc91d1c32017-02-15 19:37:46 -08004431 return result;
4432 }
4433
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004434 /**
4435 * @return True if this window has been laid out at least once; false otherwise.
4436 */
4437 boolean isLaidOut() {
4438 return mLayoutSeq != -1;
4439 }
4440
4441 /**
4442 * Updates the last inset values to the current ones.
4443 */
4444 void updateLastInsetValues() {
chaviw9c81e632018-07-31 11:17:52 -07004445 mWindowFrames.updateLastInsetValues();
Jorim Jaggidc9385a2017-05-13 02:00:31 +02004446 }
4447
Jorim Jaggia5e10572017-11-15 14:36:26 +01004448 void startAnimation(Animation anim) {
Jorim Jaggia2759b22019-01-24 13:21:40 +01004449
4450 // If we are an inset provider, all our animations are driven by the inset client.
4451 if (mInsetProvider != null && mInsetProvider.isControllable()) {
4452 return;
4453 }
4454
Jorim Jaggia5e10572017-11-15 14:36:26 +01004455 final DisplayInfo displayInfo = getDisplayContent().getDisplayInfo();
chaviw492139a2018-07-16 16:07:35 -07004456 anim.initialize(mWindowFrames.mFrame.width(), mWindowFrames.mFrame.height(),
Jorim Jaggia5e10572017-11-15 14:36:26 +01004457 displayInfo.appWidth, displayInfo.appHeight);
4458 anim.restrictDuration(MAX_ANIMATION_DURATION);
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004459 anim.scaleCurrentDuration(mWmService.getWindowAnimationScaleLocked());
Jorim Jaggia5e10572017-11-15 14:36:26 +01004460 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi2e3c31d2017-11-20 19:49:00 +01004461 new WindowAnimationSpec(anim, mSurfacePosition, false /* canSkipFirstFrame */),
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004462 mWmService.mSurfaceAnimationRunner);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004463 startAnimation(mPendingTransaction, adapter);
4464 commitPendingTransaction();
4465 }
4466
chaviw161ea3e2018-01-31 12:01:12 -08004467 private void startMoveAnimation(int left, int top) {
Jorim Jaggia2759b22019-01-24 13:21:40 +01004468
4469 // If we are an inset provider, all our animations are driven by the inset client.
4470 if (mInsetProvider != null && mInsetProvider.isControllable()) {
4471 return;
4472 }
4473
Jorim Jaggia5e10572017-11-15 14:36:26 +01004474 if (DEBUG_ANIM) Slog.v(TAG, "Setting move animation on " + this);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004475 final Point oldPosition = new Point();
4476 final Point newPosition = new Point();
chaviw492139a2018-07-16 16:07:35 -07004477 transformFrameToSurfacePosition(mWindowFrames.mLastFrame.left, mWindowFrames.mLastFrame.top,
4478 oldPosition);
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004479 transformFrameToSurfacePosition(left, top, newPosition);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004480 final AnimationAdapter adapter = new LocalAnimationAdapter(
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004481 new MoveAnimationSpec(oldPosition.x, oldPosition.y, newPosition.x, newPosition.y),
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004482 mWmService.mSurfaceAnimationRunner);
chaviw161ea3e2018-01-31 12:01:12 -08004483 startAnimation(getPendingTransaction(), adapter);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004484 }
4485
4486 private void startAnimation(Transaction t, AnimationAdapter adapter) {
4487 startAnimation(t, adapter, mWinAnimator.mLastHidden);
4488 }
4489
4490 @Override
4491 protected void onAnimationFinished() {
4492 mWinAnimator.onAnimationFinished();
4493 }
4494
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004495 /**
4496 * Retrieves the current transformation matrix of the window, relative to the display.
4497 *
4498 * @param float9 A temporary array of 9 floats.
4499 * @param outMatrix Matrix to fill in the transformation.
4500 */
4501 void getTransformationMatrix(float[] float9, Matrix outMatrix) {
4502 float9[Matrix.MSCALE_X] = mWinAnimator.mDsDx;
4503 float9[Matrix.MSKEW_Y] = mWinAnimator.mDtDx;
4504 float9[Matrix.MSKEW_X] = mWinAnimator.mDtDy;
4505 float9[Matrix.MSCALE_Y] = mWinAnimator.mDsDy;
Robert Carr217e7cc2018-01-31 18:08:39 -08004506 int x = mSurfacePosition.x;
4507 int y = mSurfacePosition.y;
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004508
4509 // If changed, also adjust transformFrameToSurfacePosition
4510 final WindowContainer parent = getParent();
4511 if (isChildWindow()) {
4512 final WindowState parentWindow = getParentWindow();
chaviw492139a2018-07-16 16:07:35 -07004513 x += parentWindow.mWindowFrames.mFrame.left - parentWindow.mAttrs.surfaceInsets.left;
4514 y += parentWindow.mWindowFrames.mFrame.top - parentWindow.mAttrs.surfaceInsets.top;
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004515 } else if (parent != null) {
4516 final Rect parentBounds = parent.getBounds();
4517 x += parentBounds.left;
4518 y += parentBounds.top;
4519 }
4520 float9[Matrix.MTRANS_X] = x;
4521 float9[Matrix.MTRANS_Y] = y;
Jorim Jaggieb0d3bc2017-12-15 14:56:19 +01004522 float9[Matrix.MPERSP_0] = 0;
4523 float9[Matrix.MPERSP_1] = 0;
4524 float9[Matrix.MPERSP_2] = 1;
4525 outMatrix.setValues(float9);
4526 }
4527
Wale Ogunwale9bc47732016-08-10 14:44:22 -07004528 // TODO: Hack to work around the number of states AppWindowToken needs to access without having
4529 // access to its windows children. Need to investigate re-writing
4530 // {@link AppWindowToken#updateReportedVisibilityLocked} so this can be removed.
4531 static final class UpdateReportedVisibilityResults {
4532 int numInteresting;
4533 int numVisible;
4534 int numDrawn;
4535 boolean nowGone = true;
4536
4537 void reset() {
4538 numInteresting = 0;
4539 numVisible = 0;
4540 numDrawn = 0;
4541 nowGone = true;
4542 }
4543 }
Robert Carraf422a82017-04-10 18:34:33 -07004544
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004545 private static final class WindowId extends IWindowId.Stub {
4546 private final WeakReference<WindowState> mOuter;
4547
4548 private WindowId(WindowState outer) {
4549
4550 // Use a weak reference for the outer class. This is important to prevent the following
4551 // leak: Since we send this class to the client process, binder will keep it alive as
4552 // long as the client keeps it alive. Now, if the window is removed, we need to clear
4553 // out our reference so even though this class is kept alive we don't leak WindowState,
4554 // which can keep a whole lot of classes alive.
4555 mOuter = new WeakReference<>(outer);
4556 }
4557
4558 @Override
4559 public void registerFocusObserver(IWindowFocusObserver observer) {
4560 final WindowState outer = mOuter.get();
4561 if (outer != null) {
4562 outer.registerFocusObserver(observer);
4563 }
4564 }
4565 @Override
4566 public void unregisterFocusObserver(IWindowFocusObserver observer) {
4567 final WindowState outer = mOuter.get();
4568 if (outer != null) {
4569 outer.unregisterFocusObserver(observer);
4570 }
4571 }
4572 @Override
4573 public boolean isFocused() {
4574 final WindowState outer = mOuter.get();
Tiger Huang1e5b10a2018-07-30 20:19:51 +08004575 if (outer != null) {
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004576 synchronized (outer.mWmService.mGlobalLock) {
Tiger Huang1e5b10a2018-07-30 20:19:51 +08004577 return outer.isFocused();
4578 }
4579 }
4580 return false;
Jorim Jaggi4448e1e2017-05-16 22:26:02 +02004581 }
4582 }
4583
Robert Carrb1579c82017-09-05 14:54:47 -07004584
4585 @Override
4586 boolean shouldMagnify() {
4587 if (mAttrs.type == TYPE_INPUT_METHOD ||
Robert Carree4d4b92017-11-22 12:21:46 -08004588 mAttrs.type == TYPE_INPUT_METHOD_DIALOG ||
4589 mAttrs.type == TYPE_MAGNIFICATION_OVERLAY ||
4590 mAttrs.type == TYPE_NAVIGATION_BAR ||
4591 // It's tempting to wonder: Have we forgotten the rounded corners overlay?
4592 // worry not: it's a fake TYPE_NAVIGATION_BAR_PANEL
Eugene Susla9552b262018-03-13 12:24:50 -07004593 mAttrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Robert Carrb1579c82017-09-05 14:54:47 -07004594 return false;
4595 }
4596 return true;
4597 }
4598
4599 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004600 SurfaceSession getSession() {
4601 if (mSession.mSurfaceSession != null) {
4602 return mSession.mSurfaceSession;
4603 } else {
4604 return getParent().getSession();
4605 }
4606 }
4607
4608 @Override
4609 boolean needsZBoost() {
lumarkff0ab692018-11-05 20:32:30 +08004610 final WindowState inputMethodTarget = getDisplayContent().mInputMethodTarget;
4611 if (mIsImWindow && inputMethodTarget != null) {
4612 final AppWindowToken appToken = inputMethodTarget.mAppToken;
Jorim Jaggib0fc8172017-11-23 17:04:08 +00004613 if (appToken != null) {
4614 return appToken.needsZBoost();
4615 }
4616 }
4617 return mWillReplaceWindow;
Robert Carrb1579c82017-09-05 14:54:47 -07004618 }
4619
Robert Carrf07ef9e2017-11-21 12:12:49 -08004620 private void applyDims(Dimmer dimmer) {
Robert Carrf59b8dd2017-10-02 18:58:36 -07004621 if (!mAnimatingExit && mAppDied) {
4622 mIsDimming = true;
chaviw2fb06bc2018-01-19 17:09:15 -08004623 dimmer.dimAbove(getPendingTransaction(), this, DEFAULT_DIM_AMOUNT_DEAD_WINDOW);
chaviwebcbc342018-02-07 13:19:00 -08004624 } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0 && isVisibleNow() && !mHidden) {
chaviw14076152018-02-02 14:51:20 -08004625 // Only show a dim behind when the following is satisfied:
4626 // 1. The window has the flag FLAG_DIM_BEHIND
4627 // 2. The WindowToken is not hidden so dims aren't shown when the window is exiting.
4628 // 3. The WS is considered visible according to the isVisible() method
chaviwebcbc342018-02-07 13:19:00 -08004629 // 4. The WS is not hidden.
Robert Carrf59b8dd2017-10-02 18:58:36 -07004630 mIsDimming = true;
chaviw2fb06bc2018-01-19 17:09:15 -08004631 dimmer.dimBelow(getPendingTransaction(), this, mAttrs.dimAmount);
Robert Carrf59b8dd2017-10-02 18:58:36 -07004632 }
Robert Carrf07ef9e2017-11-21 12:12:49 -08004633 }
4634
4635 @Override
4636 void prepareSurfaces() {
4637 final Dimmer dimmer = getDimmer();
4638 mIsDimming = false;
4639 if (dimmer != null) {
4640 applyDims(dimmer);
4641 }
chaviw2f0567b2018-01-29 16:22:02 -08004642 updateSurfacePosition();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004643
Robert Carrb1579c82017-09-05 14:54:47 -07004644 mWinAnimator.prepareSurfaceLocked(true);
4645 super.prepareSurfaces();
4646 }
4647
4648 @Override
Jorim Jaggia5e10572017-11-15 14:36:26 +01004649 public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
4650 super.onAnimationLeashCreated(t, leash);
4651
4652 // Leash is now responsible for position, so set our position to 0.
4653 t.setPosition(mSurfaceControl, 0, 0);
chaviw3e751af2018-01-11 11:22:39 -08004654 mLastSurfacePosition.set(0, 0);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004655 }
4656
4657 @Override
4658 public void onAnimationLeashDestroyed(Transaction t) {
4659 super.onAnimationLeashDestroyed(t);
4660 updateSurfacePosition(t);
4661 }
4662
chaviwe07246a2017-12-12 16:18:29 -08004663 @Override
chaviw2f0567b2018-01-29 16:22:02 -08004664 void updateSurfacePosition() {
4665 updateSurfacePosition(getPendingTransaction());
4666 }
4667
Vishnu Naird8c664b2018-09-24 12:52:35 -07004668 @VisibleForTesting
4669 void updateSurfacePosition(Transaction t) {
Jorim Jaggia5e10572017-11-15 14:36:26 +01004670 if (mSurfaceControl == null) {
4671 return;
4672 }
4673
chaviw492139a2018-07-16 16:07:35 -07004674 transformFrameToSurfacePosition(mWindowFrames.mFrame.left, mWindowFrames.mFrame.top,
4675 mSurfacePosition);
Robert Carrc6d5af52018-02-26 17:46:00 -08004676
Vishnu Nair83537a72018-07-19 21:27:48 -07004677 // Freeze position while we're unrotated, so the surface remains at the position it was
4678 // prior to the rotation.
Vishnu Nairddd80742018-08-21 14:12:46 -07004679 if (!mSurfaceAnimator.hasLeash() && mPendingSeamlessRotate == null
4680 && !mLastSurfacePosition.equals(mSurfacePosition)) {
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004681 t.setPosition(mSurfaceControl, mSurfacePosition.x, mSurfacePosition.y);
chaviw3e751af2018-01-11 11:22:39 -08004682 mLastSurfacePosition.set(mSurfacePosition.x, mSurfacePosition.y);
Robert Carrc6d5af52018-02-26 17:46:00 -08004683 if (surfaceInsetsChanging() && mWinAnimator.hasSurface()) {
4684 mLastSurfaceInsets.set(mAttrs.surfaceInsets);
4685 t.deferTransactionUntil(mSurfaceControl,
4686 mWinAnimator.mSurfaceController.mSurfaceControl.getHandle(),
chaviwbe43ac82018-04-04 15:14:49 -07004687 getFrameNumber());
Robert Carrc6d5af52018-02-26 17:46:00 -08004688 }
Jorim Jaggi313d7e02017-12-14 14:40:48 +01004689 }
4690 }
4691
4692 private void transformFrameToSurfacePosition(int left, int top, Point outPoint) {
4693 outPoint.set(left, top);
Jorim Jaggi72d4dee2017-12-28 13:49:21 +01004694
4695 // If changed, also adjust getTransformationMatrix
chaviwe07246a2017-12-12 16:18:29 -08004696 final WindowContainer parentWindowContainer = getParent();
Jorim Jaggia5e10572017-11-15 14:36:26 +01004697 if (isChildWindow()) {
4698 // TODO: This probably falls apart at some point and we should
4699 // actually compute relative coordinates.
Jorim Jaggi50d3f8f2017-12-27 17:41:25 +01004700
4701 // Since the parent was outset by its surface insets, we need to undo the outsetting
4702 // with insetting by the same amount.
Jorim Jaggia5e10572017-11-15 14:36:26 +01004703 final WindowState parent = getParentWindow();
Riddle Hsub398da32019-01-21 21:48:16 +08004704 transformSurfaceInsetsPosition(mTmpPoint, parent.mAttrs.surfaceInsets);
4705 outPoint.offset(-parent.mWindowFrames.mFrame.left + mTmpPoint.x,
4706 -parent.mWindowFrames.mFrame.top + mTmpPoint.y);
chaviwe07246a2017-12-12 16:18:29 -08004707 } else if (parentWindowContainer != null) {
Evan Roskyed6767f2018-10-26 17:21:06 -07004708 final Rect parentBounds = parentWindowContainer.getDisplayedBounds();
chaviwe07246a2017-12-12 16:18:29 -08004709 outPoint.offset(-parentBounds.left, -parentBounds.top);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004710 }
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004711
Robert Carr32bcb102018-01-29 15:03:23 -08004712 TaskStack stack = getStack();
4713
4714 // If we have stack outsets, that means the top-left
4715 // will be outset, and we need to inset ourselves
4716 // to account for it. If we actually have shadows we will
4717 // then un-inset ourselves by the surfaceInsets.
4718 if (stack != null) {
4719 final int outset = stack.getStackOutset();
4720 outPoint.offset(outset, outset);
4721 }
4722
Jorim Jaggi9af095b2017-12-12 17:18:57 +01004723 // Expand for surface insets. See WindowState.expandForSurfaceInsets.
Riddle Hsub398da32019-01-21 21:48:16 +08004724 transformSurfaceInsetsPosition(mTmpPoint, mAttrs.surfaceInsets);
4725 outPoint.offset(-mTmpPoint.x, -mTmpPoint.y);
4726 }
4727
4728 /**
4729 * The surface insets from layout parameter are in application coordinate. If the window is
4730 * scaled, the insets also need to be scaled for surface position in global coordinate.
4731 */
4732 private void transformSurfaceInsetsPosition(Point outPos, Rect surfaceInsets) {
4733 if (!inSizeCompatMode()) {
4734 outPos.x = surfaceInsets.left;
4735 outPos.y = surfaceInsets.top;
4736 return;
4737 }
4738 outPos.x = (int) (surfaceInsets.left * mGlobalScale + 0.5f);
4739 outPos.y = (int) (surfaceInsets.top * mGlobalScale + 0.5f);
Jorim Jaggia5e10572017-11-15 14:36:26 +01004740 }
4741
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004742 boolean needsRelativeLayeringToIme() {
4743 // We only use the relative layering mode in split screen, as part of elevating the IME
4744 // and windows above it's target above the docked divider.
4745 if (!inSplitScreenWindowingMode()) {
4746 return false;
4747 }
4748
4749 if (isChildWindow()) {
4750 // If we are a child of the input method target we need this promotion.
4751 if (getParentWindow().isInputMethodTarget()) {
4752 return true;
4753 }
4754 } else if (mAppToken != null) {
4755 // Likewise if we share a token with the Input method target and are ordered
4756 // above it but not necessarily a child (e.g. a Dialog) then we also need
4757 // this promotion.
lumarkff0ab692018-11-05 20:32:30 +08004758 final WindowState imeTarget = getDisplayContent().mInputMethodTarget;
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004759 boolean inTokenWithAndAboveImeTarget = imeTarget != null && imeTarget != this
4760 && imeTarget.mToken == mToken && imeTarget.compareTo(this) <= 0;
4761 return inTokenWithAndAboveImeTarget;
4762 }
4763 return false;
4764 }
4765
Jorim Jaggia5e10572017-11-15 14:36:26 +01004766 @Override
Robert Carrb1579c82017-09-05 14:54:47 -07004767 void assignLayer(Transaction t, int layer) {
4768 // See comment in assignRelativeLayerForImeTargetChild
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004769 if (needsRelativeLayeringToIme()) {
4770 getDisplayContent().assignRelativeLayerForImeTargetChild(t, this);
Robert Carrb1579c82017-09-05 14:54:47 -07004771 return;
4772 }
Robert Carr4a1cdbd2018-04-16 11:09:22 -07004773 super.assignLayer(t, layer);
Robert Carrb1579c82017-09-05 14:54:47 -07004774 }
Robert Carrf59b8dd2017-10-02 18:58:36 -07004775
4776 @Override
4777 public boolean isDimming() {
4778 return mIsDimming;
4779 }
Robert Carr0eff1872017-12-01 14:27:04 -08004780
4781 // TODO(b/70040778): We should aim to eliminate the last user of TYPE_APPLICATION_MEDIA
4782 // then we can drop all negative layering on the windowing side and simply inherit
4783 // the default implementation here.
4784 public void assignChildLayers(Transaction t) {
Tiger Huang9c8ee262019-02-19 20:44:27 +08004785 // The surface of the main window might be preserved. So the child window on top of the main
4786 // window should be also on top of the preserved surface.
4787 int layer = PRESERVED_SURFACE_LAYER + 1;
Robert Carr0eff1872017-12-01 14:27:04 -08004788 for (int i = 0; i < mChildren.size(); i++) {
4789 final WindowState w = mChildren.get(i);
4790
4791 // APPLICATION_MEDIA_OVERLAY needs to go above APPLICATION_MEDIA
4792 // while they both need to go below the main window. However the
4793 // relative layering of multiple APPLICATION_MEDIA/OVERLAY has never
4794 // been defined and so we can use static layers and leave it that way.
4795 if (w.mAttrs.type == TYPE_APPLICATION_MEDIA) {
4796 w.assignLayer(t, -2);
4797 } else if (w.mAttrs.type == TYPE_APPLICATION_MEDIA_OVERLAY) {
4798 w.assignLayer(t, -1);
4799 } else {
4800 w.assignLayer(t, layer);
4801 }
4802 w.assignChildLayers(t);
4803 layer++;
4804 }
4805 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01004806
Andrii Kulian4b6599e2018-01-15 17:24:08 -08004807 /**
4808 * Update a tap exclude region with a rectangular area identified by provided id. The requested
4809 * area will be clipped to the window bounds.
4810 */
4811 void updateTapExcludeRegion(int regionId, int left, int top, int width, int height) {
4812 final DisplayContent currentDisplay = getDisplayContent();
4813 if (currentDisplay == null) {
4814 throw new IllegalStateException("Trying to update window not attached to any display.");
4815 }
4816
4817 if (mTapExcludeRegionHolder == null) {
4818 mTapExcludeRegionHolder = new TapExcludeRegionHolder();
4819
4820 // Make sure that this window is registered as one that provides a tap exclude region
4821 // for its containing display.
4822 currentDisplay.mTapExcludeProvidingWindows.add(this);
4823 }
4824
4825 mTapExcludeRegionHolder.updateRegion(regionId, left, top, width, height);
4826 // Trigger touch exclude region update on current display.
Tiger Huang1e5b10a2018-07-30 20:19:51 +08004827 currentDisplay.updateTouchExcludeRegion();
Tiger Huang04dc4cc2019-01-17 18:41:41 +08004828 // Trigger touchable region update for this window.
4829 currentDisplay.getInputMonitor().updateInputWindowsLw(true /* force */);
Andrii Kulian4b6599e2018-01-15 17:24:08 -08004830 }
4831
Tiger Huang04dc4cc2019-01-17 18:41:41 +08004832 /**
4833 * Union the region with current tap exclude region that this window provides.
4834 *
4835 * @param region The region to be amended. It is on the screen coordinates.
4836 */
Andrii Kulian4b6599e2018-01-15 17:24:08 -08004837 void amendTapExcludeRegion(Region region) {
Tiger Huang04dc4cc2019-01-17 18:41:41 +08004838 final Region tempRegion = Region.obtain();
4839 mTmpRect.set(mWindowFrames.mFrame);
4840 mTmpRect.offsetTo(0, 0);
4841 mTapExcludeRegionHolder.amendRegion(tempRegion, mTmpRect);
4842 // The region held by the holder is on the window coordinates. We need to translate it to
4843 // the screen coordinates.
4844 tempRegion.translate(mWindowFrames.mFrame.left, mWindowFrames.mFrame.top);
4845 region.op(tempRegion, Region.Op.UNION);
4846 tempRegion.recycle();
Andrii Kulian4b6599e2018-01-15 17:24:08 -08004847 }
4848
Robert Carr825581a2018-03-30 14:00:53 -07004849 @Override
4850 public boolean isInputMethodTarget() {
lumarkff0ab692018-11-05 20:32:30 +08004851 return getDisplayContent().mInputMethodTarget == this;
Robert Carr825581a2018-03-30 14:00:53 -07004852 }
4853
chaviwbe43ac82018-04-04 15:14:49 -07004854 long getFrameNumber() {
4855 return mFrameNumber;
4856 }
4857
4858 void setFrameNumber(long frameNumber) {
4859 mFrameNumber = frameNumber;
4860 }
4861
chaviw553b0212018-07-12 13:37:01 -07004862 public void getMaxVisibleBounds(Rect out) {
4863 if (out.isEmpty()) {
4864 out.set(mWindowFrames.mVisibleFrame);
4865 return;
4866 }
4867
4868 if (mWindowFrames.mVisibleFrame.left < out.left) {
4869 out.left = mWindowFrames.mVisibleFrame.left;
4870 }
4871 if (mWindowFrames.mVisibleFrame.top < out.top) {
4872 out.top = mWindowFrames.mVisibleFrame.top;
4873 }
4874 if (mWindowFrames.mVisibleFrame.right > out.right) {
4875 out.right = mWindowFrames.mVisibleFrame.right;
4876 }
4877 if (mWindowFrames.mVisibleFrame.bottom > out.bottom) {
4878 out.bottom = mWindowFrames.mVisibleFrame.bottom;
4879 }
4880 }
4881
chaviw9c81e632018-07-31 11:17:52 -07004882 /**
4883 * Copy the inset values over so they can be sent back to the client when a relayout occurs.
4884 */
4885 void getInsetsForRelayout(Rect outOverscanInsets, Rect outContentInsets, Rect outVisibleInsets,
4886 Rect outStableInsets, Rect outOutsets) {
4887 outOverscanInsets.set(mWindowFrames.mOverscanInsets);
4888 outContentInsets.set(mWindowFrames.mContentInsets);
4889 outVisibleInsets.set(mWindowFrames.mVisibleInsets);
4890 outStableInsets.set(mWindowFrames.mStableInsets);
4891 outOutsets.set(mWindowFrames.mOutsets);
4892
4893 mLastRelayoutContentInsets.set(mWindowFrames.mContentInsets);
4894 }
4895
4896 void getContentInsets(Rect outContentInsets) {
4897 outContentInsets.set(mWindowFrames.mContentInsets);
4898 }
4899
4900 Rect getContentInsets() {
4901 return mWindowFrames.mContentInsets;
4902 }
4903
4904 void getStableInsets(Rect outStableInsets) {
4905 outStableInsets.set(mWindowFrames.mStableInsets);
4906 }
4907
4908 Rect getStableInsets() {
4909 return mWindowFrames.mStableInsets;
4910 }
4911
4912 void resetLastContentInsets() {
4913 mWindowFrames.resetLastContentInsets();
4914 }
4915
4916 Rect getVisibleInsets() {
4917 return mWindowFrames.mVisibleInsets;
4918 }
4919
chaviw1454b392018-08-06 09:54:04 -07004920 @Override
4921 public WindowFrames getWindowFrames() {
4922 return mWindowFrames;
4923 }
4924
4925 void resetContentChanged() {
4926 mWindowFrames.setContentChanged(false);
4927 }
4928
Jorim Jaggif96c90a2018-09-26 16:55:15 +02004929 void setInsetProvider(InsetsSourceProvider insetProvider) {
4930 mInsetProvider = insetProvider;
4931 }
4932
4933 InsetsSourceProvider getInsetProvider() {
4934 return mInsetProvider;
4935 }
4936
Jorim Jaggia5e10572017-11-15 14:36:26 +01004937 private final class MoveAnimationSpec implements AnimationSpec {
4938
4939 private final long mDuration;
4940 private Interpolator mInterpolator;
4941 private Point mFrom = new Point();
4942 private Point mTo = new Point();
4943
4944 private MoveAnimationSpec(int fromX, int fromY, int toX, int toY) {
4945 final Animation anim = AnimationUtils.loadAnimation(mContext,
4946 com.android.internal.R.anim.window_move_from_decor);
Jorim Jaggi08f75cf2018-01-08 14:38:53 +01004947 mDuration = (long)
Wale Ogunwale8b19de92018-11-29 19:58:26 -08004948 (anim.computeDurationHint() * mWmService.getWindowAnimationScaleLocked());
Jorim Jaggia5e10572017-11-15 14:36:26 +01004949 mInterpolator = anim.getInterpolator();
4950 mFrom.set(fromX, fromY);
4951 mTo.set(toX, toY);
4952 }
4953
4954 @Override
4955 public long getDuration() {
4956 return mDuration;
4957 }
4958
4959 @Override
4960 public void apply(Transaction t, SurfaceControl leash, long currentPlayTime) {
4961 final float fraction = (float) currentPlayTime / getDuration();
4962 final float v = mInterpolator.getInterpolation(fraction);
4963 t.setPosition(leash, mFrom.x + (mTo.x - mFrom.x) * v,
4964 mFrom.y + (mTo.y - mFrom.y) * v);
4965 }
Jorim Jaggif75d1612018-02-27 15:05:21 +01004966
4967 @Override
4968 public void dump(PrintWriter pw, String prefix) {
chaviwc65fa582018-08-09 15:33:13 -07004969 pw.println(prefix + "from=" + mFrom
4970 + " to=" + mTo
4971 + " duration=" + mDuration);
Jorim Jaggif75d1612018-02-27 15:05:21 +01004972 }
4973
4974 @Override
4975 public void writeToProtoInner(ProtoOutputStream proto) {
4976 final long token = proto.start(MOVE);
4977 mFrom.writeToProto(proto, FROM);
4978 mTo.writeToProto(proto, TO);
Kweku Adams21b8d262018-03-30 12:19:58 -07004979 proto.write(DURATION_MS, mDuration);
Jorim Jaggif75d1612018-02-27 15:05:21 +01004980 proto.end(token);
4981 }
Jorim Jaggia5e10572017-11-15 14:36:26 +01004982 }
satokcef37fb2011-10-24 21:49:38 +09004983}